kanrisuru 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/kanrisuru.gemspec +7 -7
- data/lib/kanrisuru/core.rb +3 -0
- data/lib/kanrisuru/core/apt.rb +12 -25
- data/lib/kanrisuru/core/file.rb +1 -1
- data/lib/kanrisuru/core/stat.rb +1 -2
- data/lib/kanrisuru/core/system.rb +2 -1
- data/lib/kanrisuru/core/yum.rb +386 -0
- data/lib/kanrisuru/util/bits.rb +19 -0
- data/lib/kanrisuru/util/os_family.rb +5 -0
- data/lib/kanrisuru/version.rb +1 -1
- data/spec/functional/core/apt_spec.rb +21 -0
- data/spec/functional/core/yum_spec.rb +160 -0
- data/spec/unit/template_spec.rb +0 -2
- metadata +18 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0213672a73fb6651ab25d44275fd5965154ceaf2515292adb840e28d0f7fb3fd
|
4
|
+
data.tar.gz: dc43e93139baa11a9c2afe9a242431a25293a0d3fdf21b111aae316a6ac125dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78f991ed867dbdd292568b42d1079a40926334fbdef6396092e0d5a25c03759038ff6b459c28b3005eac02863198b5306c9d54a3f6d8d77041c006d9fc89c7b2
|
7
|
+
data.tar.gz: '0719742cfd38a1e2b7a2e842c28d9b6038500b761661351c1ab4bf67650887fec4251abf93cbacd941cca28c1010fbdf23864622f203d501f44213bf9a1d169d'
|
data/README.md
CHANGED
@@ -146,6 +146,9 @@ cluster.execute('uname') #=> {host: 'host1', result: 'Linux'}, {host: 'host2', r
|
|
146
146
|
| Upload to remote server | upload | scp | core | https://linux.die.net/man/1/scp | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
147
147
|
| Download from remote server | download | scp | core | https://linux.die.net/man/1/scp | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
148
148
|
| Wget | wget | wget | core | https://linux.die.net/man/1/wget | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
|
149
|
+
| **Packages** | | | | | | | | | | | |
|
150
|
+
| Apt | apt | apt | core | https://linux.die.net/man/1/apt | [x] | [x] | | | | | |
|
151
|
+
| Yum | yum | yum | core | https://linux.die.net/man/1/yum | | | [x] | [x] | [x] | | |
|
149
152
|
|
150
153
|
## Development
|
151
154
|
|
data/kanrisuru.gemspec
CHANGED
@@ -14,14 +14,14 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.required_ruby_version = '>= 2.5.0'
|
15
15
|
gem.required_rubygems_version = '>= 1.8.11'
|
16
16
|
|
17
|
-
gem.add_development_dependency 'rspec'
|
18
|
-
gem.add_development_dependency 'rubocop'
|
19
|
-
gem.add_development_dependency 'rubocop-rspec'
|
20
|
-
gem.add_development_dependency 'simplecov'
|
17
|
+
gem.add_development_dependency 'rspec', '>= 3.10.0'
|
18
|
+
gem.add_development_dependency 'rubocop', '>= 1.12.1'
|
19
|
+
gem.add_development_dependency 'rubocop-rspec', '>= 2.2.0'
|
20
|
+
gem.add_development_dependency 'simplecov', '>= 0.21.2'
|
21
21
|
|
22
|
-
gem.add_runtime_dependency 'net-ping'
|
23
|
-
gem.add_runtime_dependency 'net-scp'
|
24
|
-
gem.add_runtime_dependency 'net-ssh'
|
22
|
+
gem.add_runtime_dependency 'net-ping', '>= 2.0.8'
|
23
|
+
gem.add_runtime_dependency 'net-scp', '>= 3.0.0'
|
24
|
+
gem.add_runtime_dependency 'net-ssh', '>= 6.1.0'
|
25
25
|
|
26
26
|
gem.files = `git ls-files`.split("\n")
|
27
27
|
gem.require_paths = ['lib']
|
data/lib/kanrisuru/core.rb
CHANGED
@@ -15,6 +15,7 @@ require_relative 'core/transfer'
|
|
15
15
|
require_relative 'core/ip'
|
16
16
|
require_relative 'core/socket'
|
17
17
|
require_relative 'core/apt'
|
18
|
+
require_relative 'core/yum'
|
18
19
|
|
19
20
|
module Kanrisuru
|
20
21
|
module Remote
|
@@ -34,6 +35,7 @@ module Kanrisuru
|
|
34
35
|
os_include Kanrisuru::Core::IP
|
35
36
|
os_include Kanrisuru::Core::Socket
|
36
37
|
os_include Kanrisuru::Core::Apt
|
38
|
+
os_include Kanrisuru::Core::Yum
|
37
39
|
end
|
38
40
|
|
39
41
|
class Cluster
|
@@ -51,6 +53,7 @@ module Kanrisuru
|
|
51
53
|
os_collection Kanrisuru::Core::IP
|
52
54
|
os_collection Kanrisuru::Core::Socket
|
53
55
|
os_collection Kanrisuru::Core::Apt
|
56
|
+
os_collection Kanrisuru::Core::Yum
|
54
57
|
end
|
55
58
|
end
|
56
59
|
end
|
data/lib/kanrisuru/core/apt.rb
CHANGED
@@ -119,7 +119,7 @@ module Kanrisuru
|
|
119
119
|
lines.shift
|
120
120
|
|
121
121
|
result = []
|
122
|
-
lines.each
|
122
|
+
lines.each do |line|
|
123
123
|
item = parse_apt_line(line)
|
124
124
|
next unless item
|
125
125
|
|
@@ -210,17 +210,17 @@ module Kanrisuru
|
|
210
210
|
rows = []
|
211
211
|
|
212
212
|
current_row = nil
|
213
|
-
|
213
|
+
description = ''
|
214
214
|
|
215
215
|
lines.each do |line|
|
216
216
|
next if line == 'WARNING: apt does not have a stable CLI interface. Use with caution in scripts.'
|
217
|
-
next if [
|
217
|
+
next if ['', nil, '.'].include?(line)
|
218
218
|
|
219
219
|
case line
|
220
220
|
when /^Package:/
|
221
221
|
unless current_row.nil?
|
222
|
-
current_row.
|
223
|
-
|
222
|
+
current_row.description = description.strip
|
223
|
+
description = ''
|
224
224
|
rows << current_row
|
225
225
|
end
|
226
226
|
|
@@ -241,9 +241,11 @@ module Kanrisuru
|
|
241
241
|
when /^Bugs:/
|
242
242
|
current_row.bugs = extract_single_line(line)
|
243
243
|
when /^Installed-Size:/
|
244
|
-
|
244
|
+
size = Kanrisuru::Util::Bits.normalize_size(extract_single_line(line))
|
245
|
+
current_row.install_size = size
|
245
246
|
when /^Download-Size:/
|
246
|
-
|
247
|
+
size = Kanrisuru::Util::Bits.normalize_size(extract_single_line(line))
|
248
|
+
current_row.download_size = size
|
247
249
|
when /^Depends:/
|
248
250
|
current_row.dependencies = parse_comma_values(extract_single_line(line))
|
249
251
|
when /^Provides:/
|
@@ -269,13 +271,13 @@ module Kanrisuru
|
|
269
271
|
when /^APT-Manual-Installed:/
|
270
272
|
current_row.apt_manual_installed = extract_single_line(line) == 'yes'
|
271
273
|
when /^Description:/
|
272
|
-
current_row.
|
274
|
+
current_row.summary = extract_single_line(line)
|
273
275
|
else
|
274
|
-
|
276
|
+
description += " #{line.strip}"
|
275
277
|
end
|
276
278
|
end
|
277
279
|
|
278
|
-
current_row.
|
280
|
+
current_row.description = description.strip
|
279
281
|
rows << current_row
|
280
282
|
rows
|
281
283
|
end
|
@@ -294,21 +296,6 @@ module Kanrisuru
|
|
294
296
|
AptSource.new(url, dist, architecture)
|
295
297
|
end
|
296
298
|
|
297
|
-
def normalize_size(string)
|
298
|
-
size, unit = string.split
|
299
|
-
size = size.to_i
|
300
|
-
case unit.downcase
|
301
|
-
when 'b'
|
302
|
-
Kanrisuru::Util::Bits.convert_bytes(size, :byte, :kilobyte)
|
303
|
-
when 'kb'
|
304
|
-
size
|
305
|
-
when 'mb'
|
306
|
-
Kanrisuru::Util::Bits.convert_from_mb(size, :kilobyte).to_i
|
307
|
-
when 'gb'
|
308
|
-
Kanrisuru::Util::Bits.convert_from_gb(size, :kilobyte).to_i
|
309
|
-
end
|
310
|
-
end
|
311
|
-
|
312
299
|
def parse_apt_line(line)
|
313
300
|
values = line.split('/')
|
314
301
|
return if values.length < 2
|
data/lib/kanrisuru/core/file.rb
CHANGED
data/lib/kanrisuru/core/stat.rb
CHANGED
@@ -15,6 +15,7 @@ module Kanrisuru
|
|
15
15
|
os_define :linux, :kill
|
16
16
|
|
17
17
|
os_define :linux, :uptime
|
18
|
+
|
18
19
|
os_define :linux, :w
|
19
20
|
os_define :linux, :who
|
20
21
|
|
@@ -184,7 +185,7 @@ module Kanrisuru
|
|
184
185
|
|
185
186
|
def w(opts = {})
|
186
187
|
users = opts[:users]
|
187
|
-
command = Kanrisuru::Command.new('w -
|
188
|
+
command = Kanrisuru::Command.new('w -hi')
|
188
189
|
|
189
190
|
command << users if Kanrisuru::Util.present?(users)
|
190
191
|
|
@@ -0,0 +1,386 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
module Kanrisuru
|
6
|
+
module Core
|
7
|
+
module Yum
|
8
|
+
extend OsPackage::Define
|
9
|
+
|
10
|
+
os_define :fedora, :yum
|
11
|
+
|
12
|
+
YumPackageOverview = Struct.new(:package, :architecture, :version, :installed)
|
13
|
+
YumPackageSearchResult = Struct.new(:package, :architecture, :summary)
|
14
|
+
YumPackageDetail = Struct.new(
|
15
|
+
:package,
|
16
|
+
:version,
|
17
|
+
:release,
|
18
|
+
:architecture,
|
19
|
+
:install_size,
|
20
|
+
:source,
|
21
|
+
:yum_id,
|
22
|
+
:repository,
|
23
|
+
:summary,
|
24
|
+
:url,
|
25
|
+
:license,
|
26
|
+
:description
|
27
|
+
)
|
28
|
+
|
29
|
+
YumRepolist = Struct.new(
|
30
|
+
:id,
|
31
|
+
:name,
|
32
|
+
:status,
|
33
|
+
:revision,
|
34
|
+
:packages,
|
35
|
+
:available_packages,
|
36
|
+
:repo_size,
|
37
|
+
:mirrors,
|
38
|
+
:metalink,
|
39
|
+
:updated,
|
40
|
+
:baseurl,
|
41
|
+
:expire,
|
42
|
+
:filters,
|
43
|
+
:filename
|
44
|
+
)
|
45
|
+
|
46
|
+
def yum(action, opts = {})
|
47
|
+
case action
|
48
|
+
when 'install'
|
49
|
+
yum_install(opts)
|
50
|
+
when 'localinstall'
|
51
|
+
yum_localinstall(opts)
|
52
|
+
when 'list'
|
53
|
+
yum_list(opts)
|
54
|
+
when 'search'
|
55
|
+
yum_search(opts)
|
56
|
+
when 'info'
|
57
|
+
yum_info(opts)
|
58
|
+
when 'repolist'
|
59
|
+
yum_repolist(opts)
|
60
|
+
when 'clean'
|
61
|
+
yum_clean(opts)
|
62
|
+
when 'remove'
|
63
|
+
yum_remove(opts)
|
64
|
+
when 'autoremove'
|
65
|
+
yum_autoremove(opts)
|
66
|
+
when 'erase'
|
67
|
+
yum_erase(opts)
|
68
|
+
when 'update'
|
69
|
+
yum_update(opts)
|
70
|
+
when 'upgrade'
|
71
|
+
yum_upgrade(opts)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def yum_install(opts)
|
78
|
+
command = Kanrisuru::Command.new('yum install')
|
79
|
+
command.append_flag('-y')
|
80
|
+
|
81
|
+
packages = Kanrisuru::Util.string_join_array(opts[:packages], ' ')
|
82
|
+
command << packages
|
83
|
+
|
84
|
+
execute_shell(command)
|
85
|
+
Kanrisuru::Result.new(command)
|
86
|
+
end
|
87
|
+
|
88
|
+
def yum_localinstall(opts)
|
89
|
+
command = Kanrisuru::Command.new('yum localinstall')
|
90
|
+
yum_disable_repo(command, opts[:disable_repo])
|
91
|
+
command.append_flag('-y')
|
92
|
+
|
93
|
+
if Kanrisuru::Util.present?(opts[:repos])
|
94
|
+
repos = Kanrisuru::Util.string_join_array(opts[:repos], ' ')
|
95
|
+
command << repos
|
96
|
+
end
|
97
|
+
|
98
|
+
execute_shell(command)
|
99
|
+
|
100
|
+
Kanrisuru::Result.new(command)
|
101
|
+
end
|
102
|
+
|
103
|
+
def yum_list(opts)
|
104
|
+
command = Kanrisuru::Command.new('yum list')
|
105
|
+
|
106
|
+
yum_disable_repo(command, opts[:disable_repo])
|
107
|
+
|
108
|
+
command.append_flag('all', opts[:all])
|
109
|
+
command.append_flag('available', opts[:available])
|
110
|
+
command.append_flag('updates', opts[:updates])
|
111
|
+
command.append_flag('installed', opts[:installed])
|
112
|
+
command.append_flag('extras', opts[:extras])
|
113
|
+
command.append_flag('obsoletes', opts[:obsoletes])
|
114
|
+
|
115
|
+
command << opts[:query] if Kanrisuru::Util.present?(opts[:query])
|
116
|
+
|
117
|
+
pipe_output_newline(command)
|
118
|
+
|
119
|
+
execute_shell(command)
|
120
|
+
|
121
|
+
Kanrisuru::Result.new(command) do |cmd|
|
122
|
+
lines = cmd.to_a
|
123
|
+
result = []
|
124
|
+
lines.each do |line|
|
125
|
+
item = parse_yum_line(line)
|
126
|
+
next unless item
|
127
|
+
|
128
|
+
result << item
|
129
|
+
end
|
130
|
+
|
131
|
+
result
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def yum_remove(opts)
|
136
|
+
command = Kanrisuru::Command.new('yum remove')
|
137
|
+
command.append_flag('-y')
|
138
|
+
|
139
|
+
packages = Kanrisuru::Util.string_join_array(opts[:packages], ' ')
|
140
|
+
raise ArugmentError, "can't remove yum" if packages.include?('yum')
|
141
|
+
|
142
|
+
command << packages
|
143
|
+
|
144
|
+
execute_shell(command)
|
145
|
+
Kanrisuru::Result.new(command)
|
146
|
+
end
|
147
|
+
|
148
|
+
def yum_clean(opts)
|
149
|
+
command = Kanrisuru::Command.new('yum clean')
|
150
|
+
|
151
|
+
command.append_flag('dbcache', opts[:dbcache])
|
152
|
+
command.append_flag('expire-cache', opts[:expire_cache])
|
153
|
+
command.append_flag('metadata', opts[:metadata])
|
154
|
+
command.append_flag('packages', opts[:packages])
|
155
|
+
command.append_flag('headers', opts[:headers])
|
156
|
+
command.append_flag('rpmdb', opts[:rpmdb])
|
157
|
+
command.append_flag('all', opts[:all])
|
158
|
+
|
159
|
+
execute_shell(command)
|
160
|
+
|
161
|
+
Kanrisuru::Result.new(command)
|
162
|
+
end
|
163
|
+
|
164
|
+
def yum_autoremove(_opts)
|
165
|
+
command = Kanrisuru::Command.new('yum autoremove')
|
166
|
+
command.append_flag('-y')
|
167
|
+
execute_shell(command)
|
168
|
+
Kanrisuru::Result.new(command)
|
169
|
+
end
|
170
|
+
|
171
|
+
def yum_erase(opts)
|
172
|
+
command = Kanrisuru::Command.new('yum erase')
|
173
|
+
command.append_flag('-y')
|
174
|
+
|
175
|
+
packages = Kanrisuru::Util.string_join_array(opts[:packages], ' ')
|
176
|
+
raise ArugmentError, "can't erase yum" if packages.include?('yum')
|
177
|
+
|
178
|
+
command << packages
|
179
|
+
|
180
|
+
execute_shell(command)
|
181
|
+
Kanrisuru::Result.new(command)
|
182
|
+
end
|
183
|
+
|
184
|
+
def yum_update(_opts)
|
185
|
+
command = Kanrisuru::Command.new('yum update')
|
186
|
+
command.append_flag('-y')
|
187
|
+
execute_shell(command)
|
188
|
+
Kanrisuru::Result.new(command)
|
189
|
+
end
|
190
|
+
|
191
|
+
def yum_upgrade(_opts)
|
192
|
+
command = Kanrisuru::Command.new('yum upgrade')
|
193
|
+
command.append_flag('-y')
|
194
|
+
execute_shell(command)
|
195
|
+
Kanrisuru::Result.new(command)
|
196
|
+
end
|
197
|
+
|
198
|
+
def yum_search(opts)
|
199
|
+
command = Kanrisuru::Command.new('yum search')
|
200
|
+
command.append_flag('all', opts[:all])
|
201
|
+
command << Kanrisuru::Util.string_join_array(opts[:packages], ' ')
|
202
|
+
|
203
|
+
pipe_output_newline(command)
|
204
|
+
|
205
|
+
execute_shell(command)
|
206
|
+
|
207
|
+
Kanrisuru::Result.new(command) do |cmd|
|
208
|
+
lines = cmd.to_a
|
209
|
+
|
210
|
+
result = []
|
211
|
+
lines.each do |line|
|
212
|
+
line = line.gsub(/\s{2}/, '')
|
213
|
+
values = line.split(' : ')
|
214
|
+
next if values.length != 2
|
215
|
+
|
216
|
+
full_name = values[0]
|
217
|
+
name, architecture = full_name.split('.')
|
218
|
+
summary = values[1]
|
219
|
+
|
220
|
+
result << YumPackageSearchResult.new(name, architecture, summary)
|
221
|
+
end
|
222
|
+
|
223
|
+
result
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
def yum_repolist(opts)
|
228
|
+
command = Kanrisuru::Command.new('yum repolist')
|
229
|
+
command.append_flag('--verbose')
|
230
|
+
|
231
|
+
command << Kanrisuru::Util.string_join_array(opts[:repos], ' ') if opts[:repos]
|
232
|
+
|
233
|
+
execute_shell(command)
|
234
|
+
|
235
|
+
Kanrisuru::Result.new(command) do |cmd|
|
236
|
+
lines = cmd.to_a
|
237
|
+
|
238
|
+
rows = []
|
239
|
+
current_row = nil
|
240
|
+
|
241
|
+
lines.each do |line|
|
242
|
+
case line
|
243
|
+
when /^Repo-id/
|
244
|
+
if current_row
|
245
|
+
rows << current_row
|
246
|
+
current_row = nil
|
247
|
+
end
|
248
|
+
|
249
|
+
current_row = YumRepolist.new
|
250
|
+
current_row.id = extract_single_yum_line(line)
|
251
|
+
when /^Repo-name/
|
252
|
+
current_row.name = extract_single_yum_line(line)
|
253
|
+
when /^Repo-revision/
|
254
|
+
current_row.revision = extract_single_yum_line(line).to_i
|
255
|
+
when /^Repo-updated/, /^Updated/
|
256
|
+
text = extract_single_yum_line(line)
|
257
|
+
current_row.updated = DateTime.parse(text)
|
258
|
+
when /^Repo-pkgs/
|
259
|
+
current_row.packages = extract_single_yum_line(line).to_i
|
260
|
+
when /^Repo-size/
|
261
|
+
size = Kanrisuru::Util::Bits.normalize_size(extract_single_yum_line(line))
|
262
|
+
current_row.repo_size = size
|
263
|
+
when /^Repo-mirrors/
|
264
|
+
current_row.mirrors = extract_single_yum_line(line)
|
265
|
+
when /^Repo-metalink/
|
266
|
+
current_row.metalink = extract_single_yum_line(line)
|
267
|
+
when /^Repo-baseurl/
|
268
|
+
current_row.baseurl = extract_single_yum_line(line).split[0]
|
269
|
+
when /^Repo-expire/
|
270
|
+
current_row.expire = extract_single_yum_line(line)
|
271
|
+
when /^Repo-filename/
|
272
|
+
current_row.filename = extract_single_yum_line(line)
|
273
|
+
when /^Repo-available-pkgs/
|
274
|
+
current_row.available_packages = extract_single_yum_line(line).to_i
|
275
|
+
when /^Filter/
|
276
|
+
current_row.filters = extract_single_yum_line(line)
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
rows << current_row
|
281
|
+
rows
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
def yum_info(opts)
|
286
|
+
command = Kanrisuru::Command.new('yum info')
|
287
|
+
command.append_flag('--quiet')
|
288
|
+
command.append_flag('installed', opts[:installed])
|
289
|
+
|
290
|
+
command << Kanrisuru::Util.string_join_array(opts[:packages], ' ') if opts[:packages]
|
291
|
+
|
292
|
+
execute_shell(command)
|
293
|
+
|
294
|
+
Kanrisuru::Result.new(command) do |cmd|
|
295
|
+
lines = cmd.to_a
|
296
|
+
|
297
|
+
rows = []
|
298
|
+
current_row = nil
|
299
|
+
description = ''
|
300
|
+
|
301
|
+
lines.each do |line|
|
302
|
+
next unless line.include?(': ')
|
303
|
+
|
304
|
+
case line
|
305
|
+
when /^Name/
|
306
|
+
unless current_row.nil?
|
307
|
+
current_row.description = description.strip
|
308
|
+
description = ''
|
309
|
+
rows << current_row
|
310
|
+
end
|
311
|
+
|
312
|
+
current_row = YumPackageDetail.new
|
313
|
+
current_row.package = extract_single_yum_line(line)
|
314
|
+
when /^Arch/, /^Architecture/
|
315
|
+
current_row.architecture = extract_single_yum_line(line)
|
316
|
+
when /^Version/
|
317
|
+
current_row.version = extract_single_yum_line(line)
|
318
|
+
when /^Release/
|
319
|
+
current_row.release = extract_single_yum_line(line)
|
320
|
+
when /^Source/
|
321
|
+
current_row.source = extract_single_yum_line(line)
|
322
|
+
when /^Repository/
|
323
|
+
current_row.repository = extract_single_yum_line(line)
|
324
|
+
when /^Summary/
|
325
|
+
current_row.summary = extract_single_yum_line(line)
|
326
|
+
when /^URL/, /^Url/
|
327
|
+
current_row.url = extract_single_yum_line(line)
|
328
|
+
when /^License/
|
329
|
+
current_row.license = extract_single_yum_line(line)
|
330
|
+
when /^From repo/
|
331
|
+
current_row.yum_id = extract_single_yum_line(line)
|
332
|
+
when /^Size/
|
333
|
+
size = Kanrisuru::Util::Bits.normalize_size(extract_single_yum_line(line))
|
334
|
+
current_row.install_size = size
|
335
|
+
when /^Description/
|
336
|
+
description = extract_single_yum_line(line)
|
337
|
+
else
|
338
|
+
next if line == ''
|
339
|
+
|
340
|
+
description += " #{extract_single_yum_line(line).strip}"
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
current_row.description = description.strip
|
345
|
+
rows << current_row
|
346
|
+
rows
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
def extract_single_yum_line(line)
|
351
|
+
values = line.split(': ', 2)
|
352
|
+
values.length == 2 ? values[1] : ''
|
353
|
+
end
|
354
|
+
|
355
|
+
def parse_yum_line(line)
|
356
|
+
values = line.split
|
357
|
+
return if values.length != 3
|
358
|
+
return unless /^\w+\.\w+$/i.match(values[0])
|
359
|
+
|
360
|
+
full_name = values[0]
|
361
|
+
version = values[1]
|
362
|
+
|
363
|
+
name, architecture = full_name.split('.')
|
364
|
+
|
365
|
+
YumPackageOverview.new(name, architecture, version)
|
366
|
+
end
|
367
|
+
|
368
|
+
## Bug reported on the output of the yum command
|
369
|
+
## https://bugzilla.redhat.com/show_bug.cgi?id=584525
|
370
|
+
## that autowraps text when used in a script beyond 80 chars wide.
|
371
|
+
## Work-around with formatting by
|
372
|
+
## piping through trimming extra newline chars.
|
373
|
+
def pipe_output_newline(command)
|
374
|
+
command | "tr '\\n' '#'"
|
375
|
+
command | "sed -e 's/# / /g'"
|
376
|
+
command | "tr '#' '\\n'"
|
377
|
+
end
|
378
|
+
|
379
|
+
def yum_disable_repo(command, repo)
|
380
|
+
return unless Kanrisuru::Util.present?(repo)
|
381
|
+
|
382
|
+
command.append_flag("--disablerepo=#{repo}")
|
383
|
+
end
|
384
|
+
end
|
385
|
+
end
|
386
|
+
end
|
data/lib/kanrisuru/util/bits.rb
CHANGED
@@ -3,6 +3,25 @@
|
|
3
3
|
module Kanrisuru
|
4
4
|
class Util
|
5
5
|
class Bits
|
6
|
+
def self.normalize_size(string)
|
7
|
+
size, unit = string.split
|
8
|
+
size = size.to_f
|
9
|
+
unit ||= 'b'
|
10
|
+
|
11
|
+
return 0 if size.zero?
|
12
|
+
|
13
|
+
case unit.downcase
|
14
|
+
when 'b'
|
15
|
+
Kanrisuru::Util::Bits.convert_bytes(size, :byte, :kilobyte)
|
16
|
+
when 'kb', 'k'
|
17
|
+
size
|
18
|
+
when 'mb', 'm'
|
19
|
+
Kanrisuru::Util::Bits.convert_from_mb(size, :kilobyte).to_i
|
20
|
+
when 'gb', 'g'
|
21
|
+
Kanrisuru::Util::Bits.convert_from_gb(size, :kilobyte).to_i
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
6
25
|
def self.convert_from_kb(value, metric)
|
7
26
|
convert_bytes(value, :kilobyte, metric)
|
8
27
|
end
|
data/lib/kanrisuru/version.rb
CHANGED
@@ -25,6 +25,16 @@ RSpec.describe Kanrisuru::Core::Apt do
|
|
25
25
|
host.su('root')
|
26
26
|
result = host.apt('install', packages: %w[ffmpeg curl])
|
27
27
|
expect(result).to be_success
|
28
|
+
|
29
|
+
result = host.which('ffmpeg')
|
30
|
+
expect(result).to be_success
|
31
|
+
paths = result.map(&:path)
|
32
|
+
expect(paths).to include(match('ffmpeg'))
|
33
|
+
|
34
|
+
result = host.which('curl')
|
35
|
+
expect(result).to be_success
|
36
|
+
paths = result.map(&:path)
|
37
|
+
expect(paths).to include(match('curl'))
|
28
38
|
end
|
29
39
|
end
|
30
40
|
end
|
@@ -80,6 +90,17 @@ RSpec.describe Kanrisuru::Core::Apt do
|
|
80
90
|
end
|
81
91
|
end
|
82
92
|
|
93
|
+
describe 'apt update' do
|
94
|
+
it 'updates packages' do
|
95
|
+
case os_name
|
96
|
+
when 'debian', 'ubuntu'
|
97
|
+
host.su('root')
|
98
|
+
result = host.apt('update')
|
99
|
+
expect(result).to be_success
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
83
104
|
describe 'apt upgrade' do
|
84
105
|
it 'upgrades packages' do
|
85
106
|
case os_name
|
@@ -0,0 +1,160 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Kanrisuru::Core::Yum 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 'upgrades packages' do
|
22
|
+
case os_name
|
23
|
+
when 'centos', 'rhel', 'fedora'
|
24
|
+
host.su('root')
|
25
|
+
result = host.yum('upgrade')
|
26
|
+
expect(result).to be_success
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'updates packages' do
|
31
|
+
case os_name
|
32
|
+
when 'centos', 'rhel', 'fedora'
|
33
|
+
host.su('root')
|
34
|
+
result = host.yum('update')
|
35
|
+
expect(result).to be_success
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'installs local package from RPM' do
|
40
|
+
case os_name
|
41
|
+
when 'fedora'
|
42
|
+
package = 'rpmfusion-free-release-32.noarch.rpm'
|
43
|
+
url = "https://download1.rpmfusion.org/free/fedora/#{package}"
|
44
|
+
|
45
|
+
result = host.wget(url)
|
46
|
+
expect(result).to be_success
|
47
|
+
file = host.file("~/#{package}")
|
48
|
+
expect(file).to be_exists
|
49
|
+
|
50
|
+
host.su('root')
|
51
|
+
result = host.yum('localinstall', repos: file.expand_path)
|
52
|
+
expect(result).to be_success
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'lists installed packages' do
|
57
|
+
case os_name
|
58
|
+
when 'centos', 'rhel', 'fedora'
|
59
|
+
result = host.yum('list', installed: true)
|
60
|
+
expect(result).to be_success
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'lists repos' do
|
65
|
+
case os_name
|
66
|
+
when 'centos', 'rhel', 'fedora'
|
67
|
+
result = host.yum('repolist')
|
68
|
+
expect(result).to be_success
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'lists installed repos' do
|
73
|
+
case os_name
|
74
|
+
when 'centos', 'rhel', 'fedora'
|
75
|
+
result = host.yum('repolist', repos: 'updates')
|
76
|
+
expect(result).to be_success
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'searches a single package' do
|
81
|
+
case os_name
|
82
|
+
when 'centos', 'rhel', 'fedora'
|
83
|
+
result = host.yum('search', packages: 'curl')
|
84
|
+
expect(result).to be_success
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'searches all packages' do
|
89
|
+
case os_name
|
90
|
+
when 'centos', 'rhel', 'fedora'
|
91
|
+
result = host.yum('search', all: true, packages: %w[curl ffmpeg])
|
92
|
+
expect(result).to be_success
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'installs a package' do
|
97
|
+
case os_name
|
98
|
+
when 'centos', 'rhel', 'fedora'
|
99
|
+
host.su('root')
|
100
|
+
result = host.yum('install', packages: %(ffmpeg curl))
|
101
|
+
expect(result).to be_success
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'removes installed packages' do
|
106
|
+
case os_name
|
107
|
+
when 'centos', 'rhel', 'fedora'
|
108
|
+
host.su('root')
|
109
|
+
result = host.yum('remove', packages: ['ffmpeg'])
|
110
|
+
expect(result).to be_success
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'purges installed packages' do
|
115
|
+
case os_name
|
116
|
+
when 'centos', 'rhel', 'fedora'
|
117
|
+
host.su('root')
|
118
|
+
result = host.yum('erase', packages: ['ffmpeg'])
|
119
|
+
expect(result).to be_success
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'gets info for one package' do
|
124
|
+
case os_name
|
125
|
+
when 'centos', 'rhel', 'fedora'
|
126
|
+
host.su('root')
|
127
|
+
result = host.yum('info', packages: 'yum')
|
128
|
+
expect(result).to be_success
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'gets info for installed packages' do
|
133
|
+
case os_name
|
134
|
+
when 'centos', 'rhel', 'fedora'
|
135
|
+
host.su('root')
|
136
|
+
result = host.yum('info', installed: true)
|
137
|
+
expect(result).to be_success
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'cleans packages' do
|
142
|
+
case os_name
|
143
|
+
when 'centos', 'rhel', 'fedora'
|
144
|
+
host.su('root')
|
145
|
+
result = host.yum('clean', all: true)
|
146
|
+
expect(result).to be_success
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'autoremoves packages' do
|
151
|
+
case os_name
|
152
|
+
when 'centos', 'rhel', 'fedora'
|
153
|
+
host.su('root')
|
154
|
+
result = host.yum('autoremove')
|
155
|
+
expect(result).to be_success
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
data/spec/unit/template_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kanrisuru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Mammina
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -16,98 +16,98 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.10.0
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 3.10.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rubocop
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.12.1
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 1.12.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rubocop-rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 2.2.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 2.2.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: simplecov
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.21.2
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 0.21.2
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: net-ping
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 2.0.8
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 2.0.8
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: net-scp
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 3.0.0
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 3.0.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: net-ssh
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: 6.1.0
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: 6.1.0
|
111
111
|
description:
|
112
112
|
email: ryan@avamia.com
|
113
113
|
executables: []
|
@@ -146,6 +146,7 @@ files:
|
|
146
146
|
- lib/kanrisuru/core/system.rb
|
147
147
|
- lib/kanrisuru/core/transfer.rb
|
148
148
|
- lib/kanrisuru/core/user.rb
|
149
|
+
- lib/kanrisuru/core/yum.rb
|
149
150
|
- lib/kanrisuru/logger.rb
|
150
151
|
- lib/kanrisuru/mode.rb
|
151
152
|
- lib/kanrisuru/os_package.rb
|
@@ -180,6 +181,7 @@ files:
|
|
180
181
|
- spec/functional/core/system_spec.rb
|
181
182
|
- spec/functional/core/transfer_spec.rb
|
182
183
|
- spec/functional/core/user_spec.rb
|
184
|
+
- spec/functional/core/yum_spec.rb
|
183
185
|
- spec/functional/os_package_spec.rb
|
184
186
|
- spec/functional/remote/cluster_spec.rb
|
185
187
|
- spec/functional/remote/cpu_spec.rb
|