kanrisuru 0.4.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +89 -0
- data/README.md +5 -0
- data/kanrisuru.gemspec +2 -1
- data/lib/kanrisuru/core.rb +6 -0
- data/lib/kanrisuru/core/apt.rb +6 -6
- data/lib/kanrisuru/core/dmi.rb +533 -0
- data/lib/kanrisuru/core/socket.rb +4 -4
- data/lib/kanrisuru/core/system.rb +90 -17
- data/lib/kanrisuru/core/yum.rb +8 -8
- data/lib/kanrisuru/core/zypper.rb +1094 -0
- data/lib/kanrisuru/remote/fstab.rb +3 -3
- data/lib/kanrisuru/util.rb +1 -0
- data/lib/kanrisuru/util/bits.rb +3 -3
- data/lib/kanrisuru/util/dmi_type.rb +1366 -0
- data/lib/kanrisuru/version.rb +1 -1
- data/spec/functional/core/apt_spec.rb +97 -158
- data/spec/functional/core/dmi_spec.rb +37 -0
- data/spec/functional/core/file_spec.rb +5 -12
- data/spec/functional/core/system_spec.rb +10 -4
- data/spec/functional/core/yum_spec.rb +38 -80
- data/spec/functional/core/zypper_spec.rb +193 -0
- data/spec/functional/remote/fstab_spec.rb +1 -1
- data/spec/helper/test_hosts.rb +7 -1
- data/spec/unit/core/apt_spec.rb +42 -0
- data/spec/unit/core/archive_spec.rb +11 -0
- data/spec/unit/core/disk_spec.rb +21 -0
- data/spec/unit/core/dmi_spec.rb +271 -0
- data/spec/unit/core/file_spec.rb +9 -0
- data/spec/unit/core/find_spec.rb +9 -0
- data/spec/unit/core/group_spec.rb +10 -0
- data/spec/unit/core/ip_spec.rb +59 -0
- data/spec/unit/core/path_spec.rb +16 -0
- data/spec/unit/core/socket_spec.rb +38 -0
- data/spec/unit/core/stat_spec.rb +14 -0
- data/spec/unit/core/system_spec.rb +90 -0
- data/spec/unit/core/transfer_spec.rb +15 -0
- data/spec/unit/core/user_spec.rb +11 -0
- data/spec/unit/core/yum_spec.rb +47 -0
- data/spec/unit/core/zypper_spec.rb +121 -0
- data/spec/unit/util_spec.rb +224 -0
- metadata +24 -2
data/lib/kanrisuru/version.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe Kanrisuru::Core::Apt do
|
6
|
-
TestHosts.each_os do |os_name|
|
6
|
+
TestHosts.each_os(only: %w[debian ubuntu]) do |os_name|
|
7
7
|
context "with #{os_name}" do
|
8
8
|
let(:host_json) { TestHosts.host(os_name) }
|
9
9
|
let(:host) do
|
@@ -18,163 +18,102 @@ RSpec.describe Kanrisuru::Core::Apt do
|
|
18
18
|
host.disconnect
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
host.su('root')
|
118
|
-
result = host.apt('full-upgrade')
|
119
|
-
expect(result).to be_success
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
describe 'apt show' do
|
125
|
-
it 'shows details of listed packages' do
|
126
|
-
case os_name
|
127
|
-
when 'debian', 'ubuntu'
|
128
|
-
result = host.apt('show', packages: %w[wget curl git sudo])
|
129
|
-
expect(result).to be_success
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
describe 'apt list' do
|
135
|
-
it 'lists all packages' do
|
136
|
-
case os_name
|
137
|
-
when 'debian', 'ubuntu'
|
138
|
-
host.su('root')
|
139
|
-
result = host.apt('list')
|
140
|
-
expect(result).to be_success
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
it 'lists installed packages' do
|
145
|
-
case os_name
|
146
|
-
when 'debian', 'ubuntu'
|
147
|
-
host.su('root')
|
148
|
-
result = host.apt('list', installed: true)
|
149
|
-
expect(result).to be_success
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
it 'lists upgradable packages' do
|
154
|
-
case os_name
|
155
|
-
when 'debian', 'ubuntu'
|
156
|
-
host.su('root')
|
157
|
-
result = host.apt('list', upgradable: true)
|
158
|
-
expect(result).to be_success
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'lists all versions for packages' do
|
163
|
-
case os_name
|
164
|
-
when 'debian', 'ubuntu'
|
165
|
-
host.su('root')
|
166
|
-
result = host.apt('list', all_versions: true)
|
167
|
-
expect(result).to be_success
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
it 'searches packages' do
|
172
|
-
case os_name
|
173
|
-
when 'debian', 'ubuntu'
|
174
|
-
result = host.apt('search', query: 'wget')
|
175
|
-
expect(result).to be_success
|
176
|
-
end
|
177
|
-
end
|
21
|
+
it 'installs package' do
|
22
|
+
host.su('root')
|
23
|
+
result = host.apt('install', packages: %w[ffmpeg curl])
|
24
|
+
expect(result).to be_success
|
25
|
+
|
26
|
+
result = host.which('ffmpeg')
|
27
|
+
expect(result).to be_success
|
28
|
+
paths = result.map(&:path)
|
29
|
+
expect(paths).to include(match('ffmpeg'))
|
30
|
+
|
31
|
+
result = host.which('curl')
|
32
|
+
expect(result).to be_success
|
33
|
+
paths = result.map(&:path)
|
34
|
+
expect(paths).to include(match('curl'))
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'removes installed packages' do
|
38
|
+
host.su('root')
|
39
|
+
result = host.apt('remove', packages: ['ffmpeg'])
|
40
|
+
expect(result).to be_success
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'purges installed packages' do
|
44
|
+
host.su('root')
|
45
|
+
result = host.apt('purge', packages: ['ffmpeg'])
|
46
|
+
expect(result).to be_success
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'removes unused packages' do
|
50
|
+
host.su('root')
|
51
|
+
result = host.apt('autoremove')
|
52
|
+
expect(result).to be_success
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'cleans packages' do
|
56
|
+
host.su('root')
|
57
|
+
result = host.apt('clean')
|
58
|
+
expect(result).to be_success
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'autocleans packages' do
|
62
|
+
host.su('root')
|
63
|
+
result = host.apt('autoclean')
|
64
|
+
expect(result).to be_success
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'updates packages' do
|
68
|
+
host.su('root')
|
69
|
+
result = host.apt('update')
|
70
|
+
expect(result).to be_success
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'upgrades packages' do
|
74
|
+
host.su('root')
|
75
|
+
result = host.apt('upgrade')
|
76
|
+
expect(result).to be_success
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'fully upgrades packages' do
|
80
|
+
host.su('root')
|
81
|
+
result = host.apt('full-upgrade')
|
82
|
+
expect(result).to be_success
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'shows details of listed packages' do
|
86
|
+
result = host.apt('show', packages: %w[wget curl git sudo])
|
87
|
+
expect(result).to be_success
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'lists all packages' do
|
91
|
+
host.su('root')
|
92
|
+
result = host.apt('list')
|
93
|
+
expect(result).to be_success
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'lists installed packages' do
|
97
|
+
host.su('root')
|
98
|
+
result = host.apt('list', installed: true)
|
99
|
+
expect(result).to be_success
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'lists upgradable packages' do
|
103
|
+
host.su('root')
|
104
|
+
result = host.apt('list', upgradable: true)
|
105
|
+
expect(result).to be_success
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'lists all versions for packages' do
|
109
|
+
host.su('root')
|
110
|
+
result = host.apt('list', all_versions: true)
|
111
|
+
expect(result).to be_success
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'searches packages' do
|
115
|
+
result = host.apt('search', query: 'wget')
|
116
|
+
expect(result).to be_success
|
178
117
|
end
|
179
118
|
end
|
180
119
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Kanrisuru::Core::Dmi do
|
6
|
+
TestHosts.each_os do |os_name|
|
7
|
+
context "with #{os_name}" do
|
8
|
+
let(:host_json) { TestHosts.host(os_name) }
|
9
|
+
let(:host) do
|
10
|
+
Kanrisuru::Remote::Host.new(
|
11
|
+
host: host_json['hostname'],
|
12
|
+
username: host_json['username'],
|
13
|
+
keys: [host_json['ssh_key']]
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
after do
|
18
|
+
host.disconnect
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'parses dmi values' do
|
22
|
+
host.su('root')
|
23
|
+
result = host.dmi
|
24
|
+
expect(result).to be_success
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'parses dmi values with types' do
|
28
|
+
host.su('root')
|
29
|
+
result = host.dmi(types: ['System', 3])
|
30
|
+
expect(result).to be_success
|
31
|
+
|
32
|
+
expect(result.find { |i| i.dmi_type == 'System' }).to be_instance_of(Kanrisuru::Core::Dmi::System)
|
33
|
+
expect(result.find { |i| i.dmi_type == 'Chassis' }).to be_instance_of(Kanrisuru::Core::Dmi::Chassis)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -167,16 +167,9 @@ RSpec.describe Kanrisuru::Core::File do
|
|
167
167
|
path = "#{spec_dir}/test-dir/"
|
168
168
|
result = host.mkdir(path)
|
169
169
|
|
170
|
-
expect(result
|
170
|
+
expect(result).to be_success
|
171
171
|
expect(result.path).to eq(path)
|
172
|
-
|
173
|
-
case os_name
|
174
|
-
when 'fedora', 'rhel', 'centos'
|
175
|
-
expect(result.mode.numeric).to eq('775')
|
176
|
-
else
|
177
|
-
expect(result.mode.numeric).to eq('755')
|
178
|
-
end
|
179
|
-
|
172
|
+
expect(result.mode.numeric).to eq('755')
|
180
173
|
expect(result.file_type).to eq('directory')
|
181
174
|
expect(result.uid).to eq(1000)
|
182
175
|
expect(result.user).to eq(host_json['username'])
|
@@ -250,7 +243,7 @@ RSpec.describe Kanrisuru::Core::File do
|
|
250
243
|
end
|
251
244
|
|
252
245
|
result = host.cp(path, copied_path)
|
253
|
-
expect(result
|
246
|
+
expect(result).to be_success
|
254
247
|
|
255
248
|
file.append do |f|
|
256
249
|
f << 'New Content'
|
@@ -260,8 +253,8 @@ RSpec.describe Kanrisuru::Core::File do
|
|
260
253
|
expect(result.success?).to eq(true)
|
261
254
|
|
262
255
|
result = host.ls(path: spec_dir)
|
263
|
-
backup = result.find { |f| f.path == 'remote-file-copied-
|
264
|
-
expect(backup.path).to eq('remote-file-copied-
|
256
|
+
backup = result.find { |f| f.path == 'remote-file-copied-with-backup.txt~' }
|
257
|
+
expect(backup.path).to eq('remote-file-copied-with-backup.txt~')
|
265
258
|
end
|
266
259
|
|
267
260
|
it 'moves files' do
|
@@ -26,14 +26,20 @@ RSpec.describe Kanrisuru::Core::System do
|
|
26
26
|
|
27
27
|
it 'gets environment variables' do
|
28
28
|
result = host.load_env
|
29
|
-
|
30
|
-
expect(result.success?).to be(true)
|
29
|
+
expect(result).to be_success
|
31
30
|
expect(result.data).to be_instance_of(Hash)
|
32
31
|
end
|
33
32
|
|
33
|
+
it 'gets open files' do
|
34
|
+
host.su('root')
|
35
|
+
result = host.lsof
|
36
|
+
expect(result).to be_success
|
37
|
+
expect(result.data).to be_instance_of(Array)
|
38
|
+
end
|
39
|
+
|
34
40
|
it 'gets uptime' do
|
35
41
|
result = host.uptime
|
36
|
-
expect(result
|
42
|
+
expect(result).to be_success
|
37
43
|
|
38
44
|
expect(result).to respond_to(
|
39
45
|
:boot_time, :uptime, :seconds,
|
@@ -84,7 +90,7 @@ RSpec.describe Kanrisuru::Core::System do
|
|
84
90
|
:procs_running,
|
85
91
|
:procs_blocked,
|
86
92
|
:softirq_total,
|
87
|
-
:softirqs
|
93
|
+
:softirqs
|
88
94
|
)
|
89
95
|
|
90
96
|
expect(result.cpus.length).to eq(host.cpu.cores)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
RSpec.describe Kanrisuru::Core::Yum do
|
6
|
-
TestHosts.each_os do |os_name|
|
6
|
+
TestHosts.each_os(only: %w[fedora rhel centos]) do |os_name|
|
7
7
|
context "with #{os_name}" do
|
8
8
|
let(:host_json) { TestHosts.host(os_name) }
|
9
9
|
let(:host) do
|
@@ -19,21 +19,15 @@ RSpec.describe Kanrisuru::Core::Yum do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'upgrades packages' do
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
result = host.yum('upgrade')
|
26
|
-
expect(result).to be_success
|
27
|
-
end
|
22
|
+
host.su('root')
|
23
|
+
result = host.yum('upgrade')
|
24
|
+
expect(result).to be_success
|
28
25
|
end
|
29
26
|
|
30
27
|
it 'updates packages' do
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
result = host.yum('update')
|
35
|
-
expect(result).to be_success
|
36
|
-
end
|
28
|
+
host.su('root')
|
29
|
+
result = host.yum('update')
|
30
|
+
expect(result).to be_success
|
37
31
|
end
|
38
32
|
|
39
33
|
it 'installs local package from RPM' do
|
@@ -54,106 +48,70 @@ RSpec.describe Kanrisuru::Core::Yum do
|
|
54
48
|
end
|
55
49
|
|
56
50
|
it 'lists installed packages' do
|
57
|
-
|
58
|
-
|
59
|
-
result = host.yum('list', installed: true)
|
60
|
-
expect(result).to be_success
|
61
|
-
end
|
51
|
+
result = host.yum('list', installed: true)
|
52
|
+
expect(result).to be_success
|
62
53
|
end
|
63
54
|
|
64
55
|
it 'lists repos' do
|
65
|
-
|
66
|
-
|
67
|
-
result = host.yum('repolist')
|
68
|
-
expect(result).to be_success
|
69
|
-
end
|
56
|
+
result = host.yum('repolist')
|
57
|
+
expect(result).to be_success
|
70
58
|
end
|
71
59
|
|
72
60
|
it 'lists installed repos' do
|
73
|
-
|
74
|
-
|
75
|
-
result = host.yum('repolist', repos: 'updates')
|
76
|
-
expect(result).to be_success
|
77
|
-
end
|
61
|
+
result = host.yum('repolist', repos: 'updates')
|
62
|
+
expect(result).to be_success
|
78
63
|
end
|
79
64
|
|
80
65
|
it 'searches a single package' do
|
81
|
-
|
82
|
-
|
83
|
-
result = host.yum('search', packages: 'curl')
|
84
|
-
expect(result).to be_success
|
85
|
-
end
|
66
|
+
result = host.yum('search', packages: 'curl')
|
67
|
+
expect(result).to be_success
|
86
68
|
end
|
87
69
|
|
88
70
|
it 'searches all packages' do
|
89
|
-
|
90
|
-
|
91
|
-
result = host.yum('search', all: true, packages: %w[curl ffmpeg])
|
92
|
-
expect(result).to be_success
|
93
|
-
end
|
71
|
+
result = host.yum('search', all: true, packages: %w[curl ffmpeg])
|
72
|
+
expect(result).to be_success
|
94
73
|
end
|
95
74
|
|
96
75
|
it 'installs a package' do
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
result = host.yum('install', packages: %(ffmpeg curl))
|
101
|
-
expect(result).to be_success
|
102
|
-
end
|
76
|
+
host.su('root')
|
77
|
+
result = host.yum('install', packages: %(ffmpeg curl))
|
78
|
+
expect(result).to be_success
|
103
79
|
end
|
104
80
|
|
105
81
|
it 'removes installed packages' do
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
result = host.yum('remove', packages: ['ffmpeg'])
|
110
|
-
expect(result).to be_success
|
111
|
-
end
|
82
|
+
host.su('root')
|
83
|
+
result = host.yum('remove', packages: ['ffmpeg'])
|
84
|
+
expect(result).to be_success
|
112
85
|
end
|
113
86
|
|
114
87
|
it 'purges installed packages' do
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
result = host.yum('erase', packages: ['ffmpeg'])
|
119
|
-
expect(result).to be_success
|
120
|
-
end
|
88
|
+
host.su('root')
|
89
|
+
result = host.yum('erase', packages: ['ffmpeg'])
|
90
|
+
expect(result).to be_success
|
121
91
|
end
|
122
92
|
|
123
93
|
it 'gets info for one package' do
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
result = host.yum('info', packages: 'yum')
|
128
|
-
expect(result).to be_success
|
129
|
-
end
|
94
|
+
host.su('root')
|
95
|
+
result = host.yum('info', packages: 'yum')
|
96
|
+
expect(result).to be_success
|
130
97
|
end
|
131
98
|
|
132
99
|
it 'gets info for installed packages' do
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
result = host.yum('info', installed: true)
|
137
|
-
expect(result).to be_success
|
138
|
-
end
|
100
|
+
host.su('root')
|
101
|
+
result = host.yum('info', installed: true)
|
102
|
+
expect(result).to be_success
|
139
103
|
end
|
140
104
|
|
141
105
|
it 'cleans packages' do
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
result = host.yum('clean', all: true)
|
146
|
-
expect(result).to be_success
|
147
|
-
end
|
106
|
+
host.su('root')
|
107
|
+
result = host.yum('clean', all: true)
|
108
|
+
expect(result).to be_success
|
148
109
|
end
|
149
110
|
|
150
111
|
it 'autoremoves packages' do
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
result = host.yum('autoremove')
|
155
|
-
expect(result).to be_success
|
156
|
-
end
|
112
|
+
host.su('root')
|
113
|
+
result = host.yum('autoremove')
|
114
|
+
expect(result).to be_success
|
157
115
|
end
|
158
116
|
end
|
159
117
|
end
|