kanrisuru 0.12.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/lib/kanrisuru/version.rb +1 -1
  4. data/spec/functional/result_spec.rb +150 -0
  5. data/spec/{hosts.json → helper/hosts.json} +0 -0
  6. data/spec/helper/simplecov.rb +21 -0
  7. data/spec/helper/test_hosts.rb +1 -1
  8. data/spec/integration/core/apt/debian_spec.rb +9 -0
  9. data/spec/integration/core/apt/ubuntu_spec.rb +9 -0
  10. data/spec/integration/core/archive/centos_spec.rb +9 -0
  11. data/spec/integration/core/archive/debian_spec.rb +9 -0
  12. data/spec/integration/core/archive/fedora_spec.rb +9 -0
  13. data/spec/integration/core/archive/opensuse_spec.rb +9 -0
  14. data/spec/integration/core/archive/rhel_spec.rb +9 -0
  15. data/spec/integration/core/archive/sles_spec.rb +9 -0
  16. data/spec/integration/core/archive/ubuntu_spec.rb +9 -0
  17. data/spec/integration/core/disk/centos_spec.rb +9 -0
  18. data/spec/integration/core/disk/debian_spec.rb +9 -0
  19. data/spec/integration/core/disk/fedora_spec.rb +9 -0
  20. data/spec/integration/core/disk/opensuse_spec.rb +9 -0
  21. data/spec/integration/core/disk/rhel_spec.rb +9 -0
  22. data/spec/integration/core/disk/sles_spec.rb +9 -0
  23. data/spec/integration/core/disk/ubuntu_spec.rb +9 -0
  24. data/spec/integration/core/dmi/centos_spec.rb +9 -0
  25. data/spec/integration/core/dmi/debian_spec.rb +9 -0
  26. data/spec/integration/core/dmi/fedora_spec.rb +9 -0
  27. data/spec/integration/core/dmi/opensuse_spec.rb +9 -0
  28. data/spec/integration/core/dmi/rhel_spec.rb +9 -0
  29. data/spec/integration/core/dmi/sles_spec.rb +9 -0
  30. data/spec/integration/core/dmi/ubuntu_spec.rb +9 -0
  31. data/spec/integration/core/file/centos_spec.rb +9 -0
  32. data/spec/integration/core/file/debian_spec.rb +9 -0
  33. data/spec/integration/core/file/fedora_spec.rb +9 -0
  34. data/spec/integration/core/file/opensuse_spec.rb +9 -0
  35. data/spec/integration/core/file/rhel_spec.rb +9 -0
  36. data/spec/integration/core/file/sles_spec.rb +9 -0
  37. data/spec/integration/core/file/ubuntu_spec.rb +9 -0
  38. data/spec/integration/core/find/centos_spec.rb +9 -0
  39. data/spec/integration/core/find/debian_spec.rb +9 -0
  40. data/spec/integration/core/find/fedora_spec.rb +9 -0
  41. data/spec/integration/core/find/opensuse_spec.rb +9 -0
  42. data/spec/integration/core/find/rhel_spec.rb +9 -0
  43. data/spec/integration/core/find/sles_spec.rb +9 -0
  44. data/spec/integration/core/find/ubuntu_spec.rb +9 -0
  45. data/spec/integration/core/group/centos_spec.rb +9 -0
  46. data/spec/integration/core/group/debian_spec.rb +9 -0
  47. data/spec/integration/core/group/fedora_spec.rb +9 -0
  48. data/spec/integration/core/group/opensuse_spec.rb +9 -0
  49. data/spec/integration/core/group/rhel_spec.rb +9 -0
  50. data/spec/integration/core/group/sles_spec.rb +9 -0
  51. data/spec/integration/core/group/ubuntu_spec.rb +9 -0
  52. data/spec/integration/core/ip/centos_spec.rb +9 -0
  53. data/spec/integration/core/ip/debian_spec.rb +9 -0
  54. data/spec/integration/core/ip/fedora_spec.rb +9 -0
  55. data/spec/integration/core/ip/opensuse_spec.rb +9 -0
  56. data/spec/integration/core/ip/rhel_spec.rb +9 -0
  57. data/spec/integration/core/ip/sles_spec.rb +9 -0
  58. data/spec/integration/core/ip/ubuntu_spec.rb +9 -0
  59. data/spec/integration/core/path/centos_spec.rb +9 -0
  60. data/spec/integration/core/path/debian_spec.rb +9 -0
  61. data/spec/integration/core/path/fedora_spec.rb +9 -0
  62. data/spec/integration/core/path/opensuse_spec.rb +9 -0
  63. data/spec/integration/core/path/rhel_spec.rb +9 -0
  64. data/spec/integration/core/path/sles_spec.rb +9 -0
  65. data/spec/integration/core/path/ubuntu_spec.rb +9 -0
  66. data/spec/integration/core/socket/centos_spec.rb +9 -0
  67. data/spec/integration/core/socket/debian_spec.rb +9 -0
  68. data/spec/integration/core/socket/fedora_spec.rb +9 -0
  69. data/spec/integration/core/socket/opensuse_spec.rb +9 -0
  70. data/spec/integration/core/socket/rhel_spec.rb +9 -0
  71. data/spec/integration/core/socket/sles_spec.rb +9 -0
  72. data/spec/integration/core/socket/ubuntu_spec.rb +9 -0
  73. data/spec/integration/core/stat/centos_spec.rb +9 -0
  74. data/spec/integration/core/stat/debian_spec.rb +9 -0
  75. data/spec/integration/core/stat/fedora_spec.rb +9 -0
  76. data/spec/integration/core/stat/opensuse_spec.rb +9 -0
  77. data/spec/integration/core/stat/rhel_spec.rb +9 -0
  78. data/spec/integration/core/stat/sles_spec.rb +9 -0
  79. data/spec/integration/core/stat/ubuntu_spec.rb +9 -0
  80. data/spec/integration/core/stream/centos_spec.rb +9 -0
  81. data/spec/integration/core/stream/debian_spec.rb +9 -0
  82. data/spec/integration/core/stream/fedora_spec.rb +9 -0
  83. data/spec/integration/core/stream/opensuse_spec.rb +9 -0
  84. data/spec/integration/core/stream/rhel_spec.rb +9 -0
  85. data/spec/integration/core/stream/sles_spec.rb +9 -0
  86. data/spec/integration/core/stream/ubuntu_spec.rb +9 -0
  87. data/spec/integration/core/system/centos_spec.rb +9 -0
  88. data/spec/integration/core/system/debian_spec.rb +9 -0
  89. data/spec/integration/core/system/fedora_spec.rb +9 -0
  90. data/spec/integration/core/system/opensuse_spec.rb +9 -0
  91. data/spec/integration/core/system/rhel_spec.rb +9 -0
  92. data/spec/integration/core/system/sles_spec.rb +9 -0
  93. data/spec/integration/core/system/ubuntu_spec.rb +9 -0
  94. data/spec/integration/core/transfer/centos_spec.rb +9 -0
  95. data/spec/integration/core/transfer/debian_spec.rb +9 -0
  96. data/spec/integration/core/transfer/fedora_spec.rb +9 -0
  97. data/spec/integration/core/transfer/opensuse_spec.rb +9 -0
  98. data/spec/integration/core/transfer/rhel_spec.rb +9 -0
  99. data/spec/integration/core/transfer/sles_spec.rb +9 -0
  100. data/spec/integration/core/transfer/ubuntu_spec.rb +9 -0
  101. data/spec/integration/core/user/centos_spec.rb +9 -0
  102. data/spec/integration/core/user/debian_spec.rb +9 -0
  103. data/spec/integration/core/user/fedora_spec.rb +9 -0
  104. data/spec/integration/core/user/opensuse_spec.rb +9 -0
  105. data/spec/integration/core/user/rhel_spec.rb +9 -0
  106. data/spec/integration/core/user/sles_spec.rb +9 -0
  107. data/spec/integration/core/user/ubuntu_spec.rb +9 -0
  108. data/spec/integration/core/yum/centos_spec.rb +9 -0
  109. data/spec/integration/core/yum/fedora_spec.rb +9 -0
  110. data/spec/integration/core/yum/rhel_spec.rb +9 -0
  111. data/spec/integration/core/zypper/opensuse_spec.rb +9 -0
  112. data/spec/integration/core/zypper/sles_spec.rb +9 -0
  113. data/spec/integration/remote/cluster/ubuntu_spec.rb +9 -0
  114. data/spec/integration/remote/cpu/centos_spec.rb +9 -0
  115. data/spec/integration/remote/cpu/debian_spec.rb +9 -0
  116. data/spec/integration/remote/cpu/fedora_spec.rb +9 -0
  117. data/spec/integration/remote/cpu/opensuse_spec.rb +9 -0
  118. data/spec/integration/remote/cpu/rhel_spec.rb +9 -0
  119. data/spec/integration/remote/cpu/sles_spec.rb +9 -0
  120. data/spec/integration/remote/cpu/ubuntu_spec.rb +9 -0
  121. data/spec/integration/remote/env/centos_spec.rb +9 -0
  122. data/spec/integration/remote/env/debian_spec.rb +9 -0
  123. data/spec/integration/remote/env/fedora_spec.rb +9 -0
  124. data/spec/integration/remote/env/opensuse_spec.rb +9 -0
  125. data/spec/integration/remote/env/rhel_spec.rb +9 -0
  126. data/spec/integration/remote/env/sles_spec.rb +9 -0
  127. data/spec/integration/remote/env/ubuntu_spec.rb +9 -0
  128. data/spec/integration/remote/fstab/centos_spec.rb +9 -0
  129. data/spec/integration/remote/fstab/debian_spec.rb +9 -0
  130. data/spec/integration/remote/fstab/fedora_spec.rb +9 -0
  131. data/spec/integration/remote/fstab/opensuse_spec.rb +9 -0
  132. data/spec/integration/remote/fstab/rhel_spec.rb +9 -0
  133. data/spec/integration/remote/fstab/sles_spec.rb +9 -0
  134. data/spec/integration/remote/fstab/ubuntu_spec.rb +9 -0
  135. data/spec/integration/remote/host/centos_spec.rb +9 -0
  136. data/spec/integration/remote/host/debian_spec.rb +9 -0
  137. data/spec/integration/remote/host/fedora_spec.rb +9 -0
  138. data/spec/integration/remote/host/opensuse_spec.rb +9 -0
  139. data/spec/integration/remote/host/rhel_spec.rb +9 -0
  140. data/spec/integration/remote/host/sles_spec.rb +9 -0
  141. data/spec/integration/remote/host/ubuntu_spec.rb +9 -0
  142. data/spec/integration/remote/memory/centos_spec.rb +9 -0
  143. data/spec/integration/remote/memory/debian_spec.rb +9 -0
  144. data/spec/integration/remote/memory/fedora_spec.rb +9 -0
  145. data/spec/integration/remote/memory/opensuse_spec.rb +9 -0
  146. data/spec/integration/remote/memory/rhel_spec.rb +9 -0
  147. data/spec/integration/remote/memory/sles_spec.rb +9 -0
  148. data/spec/integration/remote/memory/ubuntu_spec.rb +9 -0
  149. data/spec/integration/remote/os/centos_spec.rb +9 -0
  150. data/spec/integration/remote/os/debian_spec.rb +9 -0
  151. data/spec/integration/remote/os/fedora_spec.rb +9 -0
  152. data/spec/integration/remote/os/opensuse_spec.rb +9 -0
  153. data/spec/integration/remote/os/rhel_spec.rb +9 -0
  154. data/spec/integration/remote/os/sles_spec.rb +9 -0
  155. data/spec/integration/remote/os/ubuntu_spec.rb +9 -0
  156. data/spec/integration/remote/remote_file/centos_spec.rb +9 -0
  157. data/spec/integration/remote/remote_file/debian_spec.rb +9 -0
  158. data/spec/integration/remote/remote_file/fedora_spec.rb +9 -0
  159. data/spec/integration/remote/remote_file/opensuse_spec.rb +9 -0
  160. data/spec/integration/remote/remote_file/rhel_spec.rb +9 -0
  161. data/spec/integration/remote/remote_file/sles_spec.rb +9 -0
  162. data/spec/integration/remote/remote_file/ubuntu_spec.rb +9 -0
  163. data/spec/spec_helper.rb +2 -11
  164. data/spec/support/shared_examples/integration/core/apt.rb +117 -0
  165. data/spec/support/shared_examples/integration/core/archive.rb +221 -0
  166. data/spec/support/shared_examples/integration/core/disk.rb +91 -0
  167. data/spec/support/shared_examples/integration/core/dmi.rb +34 -0
  168. data/spec/support/shared_examples/integration/core/file.rb +357 -0
  169. data/spec/support/shared_examples/integration/core/find.rb +50 -0
  170. data/spec/support/shared_examples/integration/core/group.rb +62 -0
  171. data/spec/support/shared_examples/integration/core/ip.rb +68 -0
  172. data/spec/support/shared_examples/integration/core/path.rb +90 -0
  173. data/spec/support/shared_examples/integration/core/socket.rb +27 -0
  174. data/spec/support/shared_examples/integration/core/stat.rb +95 -0
  175. data/spec/support/shared_examples/integration/core/stream.rb +112 -0
  176. data/spec/support/shared_examples/integration/core/system.rb +155 -0
  177. data/spec/support/shared_examples/integration/core/transfer.rb +101 -0
  178. data/spec/support/shared_examples/integration/core/user.rb +72 -0
  179. data/spec/support/shared_examples/integration/core/yum.rb +115 -0
  180. data/spec/support/shared_examples/integration/core/zypper.rb +196 -0
  181. data/spec/{integration/remote/cluster_spec.rb → support/shared_examples/integration/remote/cluster.rb} +2 -2
  182. data/spec/support/shared_examples/integration/remote/cpu.rb +38 -0
  183. data/spec/support/shared_examples/integration/remote/env_spec.rb +33 -0
  184. data/spec/support/shared_examples/integration/remote/fstab.rb +89 -0
  185. data/spec/support/shared_examples/integration/remote/host.rb +65 -0
  186. data/spec/support/shared_examples/integration/remote/memory.rb +27 -0
  187. data/spec/support/shared_examples/integration/remote/os.rb +60 -0
  188. data/spec/support/shared_examples/integration/remote/remote_file.rb +172 -0
  189. metadata +185 -29
  190. data/spec/integration/core/apt_spec.rb +0 -119
  191. data/spec/integration/core/archive_spec.rb +0 -223
  192. data/spec/integration/core/disk_spec.rb +0 -93
  193. data/spec/integration/core/dmi_spec.rb +0 -36
  194. data/spec/integration/core/file_spec.rb +0 -359
  195. data/spec/integration/core/find_spec.rb +0 -52
  196. data/spec/integration/core/group_spec.rb +0 -64
  197. data/spec/integration/core/ip_spec.rb +0 -70
  198. data/spec/integration/core/path_spec.rb +0 -92
  199. data/spec/integration/core/socket_spec.rb +0 -29
  200. data/spec/integration/core/stat_spec.rb +0 -97
  201. data/spec/integration/core/stream_spec.rb +0 -114
  202. data/spec/integration/core/system_spec.rb +0 -142
  203. data/spec/integration/core/transfer_spec.rb +0 -103
  204. data/spec/integration/core/user_spec.rb +0 -74
  205. data/spec/integration/core/yum_spec.rb +0 -117
  206. data/spec/integration/core/zypper_spec.rb +0 -198
  207. data/spec/integration/remote/cpu_spec.rb +0 -40
  208. data/spec/integration/remote/env_spec.rb +0 -35
  209. data/spec/integration/remote/fstab_spec.rb +0 -91
  210. data/spec/integration/remote/host_spec.rb +0 -67
  211. data/spec/integration/remote/memory_spec.rb +0 -29
  212. data/spec/integration/remote/os_spec.rb +0 -62
  213. data/spec/integration/remote/remote_file_spec.rb +0 -174
  214. data/spec/zz_reboot_spec.rb +0 -46
@@ -1,97 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- TestHosts.each_os do |os_name, host_json|
6
- RSpec.describe Kanrisuru::Core::Stat do
7
- context "with #{os_name}" do
8
- let(:host) do
9
- Kanrisuru::Remote::Host.new(
10
- host: host_json['hostname'],
11
- username: host_json['username'],
12
- keys: [host_json['ssh_key']]
13
- )
14
- end
15
-
16
- after do
17
- host.disconnect
18
- end
19
-
20
- it 'checks file type correctly' do
21
- expect(host.dir?('/')).to eq(true)
22
- expect(host.file?('/etc/hosts')).to eq(true)
23
-
24
- case os_name
25
- when 'sles'
26
- expect(host.block_device?('/dev/xvda')).to eq(true)
27
- else
28
- expect(host.block_device?('/dev/vda')).to eq(true)
29
- end
30
-
31
- expect(host.char_device?('/dev/tty')).to eq(true)
32
- expect(host.symlink?('/etc/mtab')).to eq(true)
33
- expect(host.inode?('/proc/uptime')).to eq(true)
34
- end
35
-
36
- it 'gets file stat' do
37
- result = host.stat(host_json['home'])
38
-
39
- expect(result.mode).to be_instance_of(Kanrisuru::Mode)
40
- expect(result.mode.directory?).to eq(true)
41
-
42
- case os_name
43
- when 'centos', 'rhel', 'fedora'
44
- expect(result.mode.numeric).to eq('700')
45
- expect(result.mode.to_i).to eq(0o700)
46
-
47
- expect(result.mode.group.read?).to eq(false)
48
- expect(result.mode.group.write?).to eq(false)
49
- expect(result.mode.group.execute?).to eq(false)
50
-
51
- expect(result.mode.other.read?).to eq(false)
52
- expect(result.mode.other.write?).to eq(false)
53
- expect(result.mode.other.execute?).to eq(false)
54
-
55
- expect(result.mode.owner.read?).to eq(true)
56
- expect(result.mode.owner.write?).to eq(true)
57
- expect(result.mode.owner.execute?).to eq(true)
58
-
59
- expect(result.mode.symbolic).to eq('drwx------')
60
- else
61
- expect(result.mode.numeric).to eq('755')
62
- expect(result.mode.to_i).to eq(0o755)
63
-
64
- expect(result.mode.group.read?).to eq(true)
65
- expect(result.mode.group.write?).to eq(false)
66
- expect(result.mode.group.execute?).to eq(true)
67
-
68
- expect(result.mode.other.read?).to eq(true)
69
- expect(result.mode.other.write?).to eq(false)
70
- expect(result.mode.other.execute?).to eq(true)
71
-
72
- expect(result.mode.owner.read?).to eq(true)
73
- expect(result.mode.owner.write?).to eq(true)
74
- expect(result.mode.owner.execute?).to eq(true)
75
-
76
- expect(result.mode.symbolic).to eq('drwxr-xr-x')
77
- end
78
-
79
- expect(result.file_type).to eq('directory')
80
-
81
- case os_name
82
- when 'opensuse', 'sles'
83
- expect(result.gid).to eq(100)
84
- expect(result.group).to eq('users')
85
- else
86
- expect(result.gid).to eq(1000)
87
- expect(result.group).to eq(host_json['username'])
88
- end
89
-
90
- expect(result.uid).to eq(1000)
91
- expect(result.user).to eq(host_json['username'])
92
-
93
- expect(result.fsize).to be >= 0
94
- end
95
- end
96
- end
97
- end
@@ -1,114 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- TestHosts.each_os do |os_name, host_json, spec_dir|
6
- RSpec.describe Kanrisuru::Core::Stream do
7
- context "with #{os_name}" do
8
- before(:all) do
9
- host = Kanrisuru::Remote::Host.new(
10
- host: host_json['hostname'],
11
- username: host_json['username'],
12
- keys: [host_json['ssh_key']]
13
- )
14
-
15
- host.mkdir(spec_dir, silent: true)
16
- host.disconnect
17
- end
18
-
19
- let(:host) do
20
- Kanrisuru::Remote::Host.new(
21
- host: host_json['hostname'],
22
- username: host_json['username'],
23
- keys: [host_json['ssh_key']]
24
- )
25
- end
26
-
27
- after do
28
- host.disconnect
29
- end
30
-
31
- after(:all) do
32
- host = Kanrisuru::Remote::Host.new(
33
- host: host_json['hostname'],
34
- username: host_json['username'],
35
- keys: [host_json['ssh_key']]
36
- )
37
-
38
- host.rmdir(spec_dir)
39
- host.disconnect
40
- end
41
-
42
- it 'outputs beginning of a file' do
43
- file = host.file("#{spec_dir}/test-file.txt")
44
- file.touch
45
- file.append do |f|
46
- f << 'This'
47
- f << 'is'
48
- f << 'a'
49
- f << 'file!'
50
- end
51
-
52
- result = host.head("#{spec_dir}/test-file.txt", lines: 2)
53
- expect(result).to be_success
54
- expect(result.data.length).to eq(2)
55
- expect(result.data).to eq(%w[This is])
56
- end
57
-
58
- it 'outputs end of a file' do
59
- file = host.file("#{spec_dir}/test-file.txt")
60
- file.touch
61
- file.append do |f|
62
- f << 'This'
63
- f << 'is'
64
- f << 'a'
65
- f << 'file!'
66
- end
67
-
68
- result = host.tail("#{spec_dir}/test-file.txt", lines: 2)
69
- expect(result).to be_success
70
- expect(result.data.length).to eq(2)
71
- expect(result.data).to eq(['a', 'file!'])
72
- end
73
-
74
- it 'reads a chunk of text from a file' do
75
- file = host.file("#{spec_dir}/test-file-chunk.txt")
76
- file.touch
77
- file.append do |f|
78
- f << 'This'
79
- f << 'is'
80
- f << 'is'
81
- f << 'a'
82
- f << 'file'
83
- f << 'forever...'
84
- end
85
-
86
- result = host.read_file_chunk("#{spec_dir}/test-file-chunk.txt", 2, 4)
87
- expect(result).to be_success
88
- expect(result.data.length).to eq(3)
89
- expect(result.data).to eq(%w[is is a])
90
- end
91
-
92
- it 'cats a file' do
93
- result = host.cat('/etc/group')
94
- expect(result.success?).to eq(true)
95
- expect(result.data.include?('root:x:0:')).to eq(true)
96
- end
97
-
98
- it 'echoes to stdout' do
99
- result = host.echo('Hello world')
100
- expect(result.data).to eq('Hello world')
101
- end
102
-
103
- it 'seds file to stdout' do
104
- path = "#{spec_dir}/test-file.txt"
105
- result = host.echo("Hello world, this is a Cat test file.\nCat\nCat\nDog", new_file: path, mode: 'write')
106
- expect(result).to be_success
107
-
108
- result = host.sed(path, 'Cat', 'Dog')
109
- expect(result).to be_success
110
- expect(result.data).to eq("Hello world, this is a Dog test file.\nDog\nDog\nDog")
111
- end
112
- end
113
- end
114
- end
@@ -1,142 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- TestHosts.each_os do |os_name, host_json|
6
- RSpec.describe Kanrisuru::Core::System do
7
- context "with #{os_name}" do
8
- let(:host) do
9
- Kanrisuru::Remote::Host.new(
10
- host: host_json['hostname'],
11
- username: host_json['username'],
12
- keys: [host_json['ssh_key']]
13
- )
14
- end
15
-
16
- after do
17
- host.disconnect
18
- end
19
-
20
- it 'gets cpu details' do
21
- result = host.lscpu
22
- expect(result).to be_success
23
- expect(result.data).to be_instance_of(Kanrisuru::Core::System::CPUArchitecture)
24
- end
25
-
26
- it 'gets environment variables' do
27
- result = host.load_env
28
- expect(result).to be_success
29
- expect(result.data).to be_instance_of(Hash)
30
- end
31
-
32
- it 'gets open files' do
33
- host.su('root')
34
- result = host.lsof
35
- expect(result).to be_success
36
- expect(result.data).to be_instance_of(Array)
37
- end
38
-
39
- it 'gets uptime' do
40
- result = host.uptime
41
- expect(result).to be_success
42
-
43
- expect(result).to respond_to(
44
- :boot_time, :uptime, :seconds,
45
- :hours, :minutes, :days
46
- )
47
-
48
- expect(result.seconds).to be > 0
49
- expect(result.minutes).to be >= 0
50
- expect(result.hours).to be >= 0
51
- expect(result.days).to be >= 0
52
- end
53
-
54
- it 'kills pids' do
55
- command = 'sleep 100000 > /dev/null 2>&1 &'
56
-
57
- host.execute_shell("nohup #{command}")
58
- result = host.ps(user: host_json['username'])
59
- expect(result.success?).to eq(true)
60
-
61
- process = result.select do |proc|
62
- proc.command == 'sleep 100000'
63
- end
64
-
65
- pids = process.map(&:pid)
66
- result = host.kill('SIGKILL', pids)
67
- expect(result.success?).to eq(true)
68
-
69
- result = host.ps(user: host_json['username'])
70
- process = result.select do |proc|
71
- proc.command == 'sleep 100000'
72
- end
73
-
74
- expect(process).to be_empty
75
- end
76
-
77
- it 'gets kernel statistics' do
78
- result = host.kernel_statistics
79
- expect(result).to be_success
80
-
81
- expect(result.data).to respond_to(
82
- :cpu_total,
83
- :cpus,
84
- :interrupt_total,
85
- :interrupts,
86
- :ctxt,
87
- :btime,
88
- :processes,
89
- :procs_running,
90
- :procs_blocked,
91
- :softirq_total,
92
- :softirqs
93
- )
94
-
95
- expect(result.cpus.length).to eq(host.cpu.cores)
96
- end
97
-
98
- it 'gets login details' do
99
- host.su('root')
100
-
101
- result = host.last
102
- expect(result).to be_success
103
- end
104
-
105
- it 'gets failed login attempts' do
106
- host.su('root')
107
-
108
- result = host.last(failed_attempts: true)
109
- expect(result).to be_success
110
- end
111
-
112
- it 'gets process details' do
113
- result = host.ps
114
-
115
- expect(result.data).to be_instance_of(Array)
116
- process = result[0]
117
-
118
- expect(process).to respond_to(
119
- :uid, :user, :gid, :group,
120
- :pid, :ppid, :cpu_usage, :memory_usage,
121
- :stat, :priority, :flags, :policy_abbr, :policy,
122
- :cpu_time, :command
123
- )
124
-
125
- result = host.ps(user: [host_json['username']])
126
-
127
- expect(result.data).to be_instance_of(Array)
128
-
129
- process = result.find do |proc|
130
- proc.command == result.command.raw_command
131
- end
132
-
133
- expect(process.command).to eq(result.command.raw_command)
134
- end
135
-
136
- it 'gets information for users' do
137
- result = host.who
138
- expect(result.success?).to eq(true)
139
- end
140
- end
141
- end
142
- end
@@ -1,103 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- TestHosts.each_os do |os_name, host_json, spec_dir|
6
- RSpec.describe Kanrisuru::Core::File do
7
- context "with #{os_name}" do
8
- before(:all) do
9
- host = Kanrisuru::Remote::Host.new(
10
- host: host_json['hostname'],
11
- username: host_json['username'],
12
- keys: [host_json['ssh_key']]
13
- )
14
-
15
- host.mkdir(spec_dir, silent: true)
16
- host.disconnect
17
- end
18
-
19
- let(:host) do
20
- Kanrisuru::Remote::Host.new(
21
- host: host_json['hostname'],
22
- username: host_json['username'],
23
- keys: [host_json['ssh_key']]
24
- )
25
- end
26
-
27
- after do
28
- host.disconnect
29
- end
30
-
31
- after(:all) do
32
- host = Kanrisuru::Remote::Host.new(
33
- host: host_json['hostname'],
34
- username: host_json['username'],
35
- keys: [host_json['ssh_key']]
36
- )
37
-
38
- host.rmdir(spec_dir)
39
- host.disconnect
40
- end
41
-
42
- it 'uploads a template file' do
43
- path = '../templates/test.conf.erb'
44
- dest_path = "#{spec_dir}/test.conf"
45
-
46
- template = Kanrisuru::Template.new(path, array: %w[this is an array])
47
- result = host.upload(template.read, dest_path)
48
-
49
- expect(result).to be_success
50
- expect(result.mode.numeric).to eq('640')
51
- expect(result.user).to eq(host_json['username'])
52
-
53
- case os_name
54
- when 'sles', 'opensuse'
55
- expect(result.gid).to eq(100)
56
- expect(result.group).to eq('users')
57
- else
58
- expect(result.gid).to eq(1000)
59
- expect(result.group).to eq(host_json['username'])
60
- end
61
-
62
- expect(host.cat(dest_path).to_a).to eq([
63
- '<h1>Hello World</h1>',
64
- 'this',
65
- 'is',
66
- 'an',
67
- 'array'
68
- ])
69
- end
70
-
71
- it 'uploads a dir' do
72
- path = '../meta/'
73
- dest_path = "#{spec_dir}/meta"
74
-
75
- result = host.upload(path, dest_path, recursive: true)
76
- expect(result).to be_success
77
- end
78
-
79
- it 'downloads a file to local fs' do
80
- path = '../hosts-file'
81
- src_path = '/etc/hosts'
82
-
83
- result = host.download(src_path, path)
84
- expect(result).to eq(path)
85
- FileUtils.rm(path)
86
- end
87
-
88
- it 'downloads a file directly' do
89
- src_path = '/etc/hosts'
90
-
91
- result = host.download(src_path)
92
- expect(result).to be_instance_of(String)
93
- lines = result.split("\n")
94
- expect(lines.length).to be >= 1
95
- end
96
-
97
- it 'wgets url' do
98
- result = host.wget('https://example.com', directory_prefix: spec_dir)
99
- expect(result).to be_success
100
- end
101
- end
102
- end
103
- end
@@ -1,74 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- TestHosts.each_os do |os_name, host_json|
6
- RSpec.describe Kanrisuru::Core::User do
7
- context "with #{os_name}" do
8
- let(:host) do
9
- Kanrisuru::Remote::Host.new(
10
- host: host_json['hostname'],
11
- username: host_json['username'],
12
- keys: [host_json['ssh_key']]
13
- )
14
- end
15
-
16
- after do
17
- host.disconnect
18
- end
19
-
20
- after(:all) do
21
- host = Kanrisuru::Remote::Host.new(
22
- host: host_json['hostname'],
23
- username: host_json['username'],
24
- keys: [host_json['ssh_key']]
25
- )
26
-
27
- host.su('root')
28
- host.user?('rails')
29
- host.delete_user('rails').inspect if host.user?('rails')
30
- host.rmdir('/home/rails') if host.dir?('/home/rails')
31
- host.disconnect
32
- end
33
-
34
- it 'gets uid for user' do
35
- expect(host.get_uid(host_json['uername']).to_i).to eq(1000)
36
- expect(host.get_uid('asdf').to_i).to eq(nil)
37
- end
38
-
39
- it 'gets a user details' do
40
- result = host.get_user(host_json['username'])
41
- expect(result.uid).to eq(1000)
42
- expect(result.name).to eq(host_json['username'])
43
- expect(result.home.path).to eq(host_json['home'])
44
-
45
- case os_name
46
- when 'opensuse', 'sles'
47
- expect(result.groups[0]).to have_attributes(gid: 100, name: 'users')
48
- else
49
- expect(result.groups[0]).to have_attributes(gid: 1000, name: host_json['username'])
50
- end
51
- end
52
-
53
- it 'manages a user' do
54
- ## Need priviledge escalation to manage group
55
- host.su('root')
56
-
57
- result = host.create_user('rails', password: '123456', groups: %w[mail tty])
58
- expect(result.success?).to eq(true)
59
- expect(result.uid).to eq(1001)
60
- expect(result.groups.length).to eq(3)
61
- expect(result.shell.path).to eq('/bin/false')
62
- expect(result.home.path).to eq('/home/rails')
63
-
64
- result = host.update_user('rails', uid: 1002, shell: '/bin/bash', groups: ['audio'], append: true)
65
-
66
- expect(result.uid).to eq(1002)
67
- expect(result.shell.path).to eq('/bin/bash')
68
- expect(result.groups.length).to eq(4)
69
-
70
- expect(host.delete_user('rails').success?).to eq(true) if host.user?('rails')
71
- end
72
- end
73
- end
74
- end
@@ -1,117 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
-
5
- TestHosts.each_os(only: %w[fedora rhel centos]) do |os_name, host_json|
6
- RSpec.describe Kanrisuru::Core::Yum do
7
- context "with #{os_name}" do
8
- let(:host) do
9
- Kanrisuru::Remote::Host.new(
10
- host: host_json['hostname'],
11
- username: host_json['username'],
12
- keys: [host_json['ssh_key']]
13
- )
14
- end
15
-
16
- after do
17
- host.disconnect
18
- end
19
-
20
- it 'upgrades packages' do
21
- host.su('root')
22
- result = host.yum('upgrade')
23
- expect(result).to be_success
24
- end
25
-
26
- it 'updates packages' do
27
- host.su('root')
28
- result = host.yum('update')
29
- expect(result).to be_success
30
- end
31
-
32
- it 'installs local package from RPM' do
33
- case os_name
34
- when 'fedora'
35
- package = 'rpmfusion-free-release-32.noarch.rpm'
36
- url = "https://download1.rpmfusion.org/free/fedora/#{package}"
37
-
38
- result = host.wget(url)
39
- expect(result).to be_success
40
- file = host.file("~/#{package}")
41
- expect(file).to be_exists
42
-
43
- host.su('root')
44
- result = host.yum('localinstall', repos: file.expand_path)
45
- expect(result).to be_success
46
- end
47
- end
48
-
49
- it 'lists installed packages' do
50
- result = host.yum('list', installed: true)
51
- expect(result).to be_success
52
- end
53
-
54
- it 'lists repos' do
55
- result = host.yum('repolist')
56
- expect(result).to be_success
57
- end
58
-
59
- it 'lists installed repos' do
60
- result = host.yum('repolist', repos: 'updates')
61
- expect(result).to be_success
62
- end
63
-
64
- it 'searches a single package' do
65
- result = host.yum('search', packages: 'curl')
66
- expect(result).to be_success
67
- end
68
-
69
- it 'searches all packages' do
70
- result = host.yum('search', all: true, packages: %w[curl ffmpeg])
71
- expect(result).to be_success
72
- end
73
-
74
- it 'installs a package' do
75
- host.su('root')
76
- result = host.yum('install', packages: %(ffmpeg curl))
77
- expect(result).to be_success
78
- end
79
-
80
- it 'removes installed packages' do
81
- host.su('root')
82
- result = host.yum('remove', packages: ['ffmpeg'])
83
- expect(result).to be_success
84
- end
85
-
86
- it 'purges installed packages' do
87
- host.su('root')
88
- result = host.yum('erase', packages: ['ffmpeg'])
89
- expect(result).to be_success
90
- end
91
-
92
- it 'gets info for one package' do
93
- host.su('root')
94
- result = host.yum('info', packages: 'yum')
95
- expect(result).to be_success
96
- end
97
-
98
- it 'gets info for installed packages' do
99
- host.su('root')
100
- result = host.yum('info', installed: true)
101
- expect(result).to be_success
102
- end
103
-
104
- it 'cleans packages' do
105
- host.su('root')
106
- result = host.yum('clean', all: true)
107
- expect(result).to be_success
108
- end
109
-
110
- it 'autoremoves packages' do
111
- host.su('root')
112
- result = host.yum('autoremove')
113
- expect(result).to be_success
114
- end
115
- end
116
- end
117
- end