kanrisuru 0.3.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -186,7 +186,7 @@ module Kanrisuru
186
186
  model: 'open_source',
187
187
  state: 'current',
188
188
  type: 'distribution'
189
- },
189
+ }
190
190
  }
191
191
 
192
192
  def self.family_include_distribution?(family, dist)
@@ -136,7 +136,7 @@ module Kanrisuru
136
136
  def self.[](signal)
137
137
  return unless valid?(signal)
138
138
 
139
- if key.instance_of?(Integer)
139
+ if signal.instance_of?(Integer)
140
140
  @linux_inverted[signal]
141
141
  else
142
142
  @linux[translate(signal)]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanrisuru
4
- VERSION = '0.3.1'
4
+ VERSION = '0.5.0'
5
5
  end
@@ -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
- describe 'apt install' do
22
- it 'installs package' do
23
- case os_name
24
- when 'debian', 'ubuntu'
25
- host.su('root')
26
- result = host.apt('install', packages: %w[ffmpeg curl])
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'))
38
- end
39
- end
40
- end
41
-
42
- describe 'apt remove' do
43
- it 'removes installed packages' do
44
- case os_name
45
- when 'debian', 'ubuntu'
46
- host.su('root')
47
- result = host.apt('remove', packages: ['ffmpeg'])
48
- expect(result).to be_success
49
- end
50
- end
51
-
52
- it 'purges installed packages' do
53
- case os_name
54
- when 'debian', 'ubuntu'
55
- host.su('root')
56
- result = host.apt('purge', packages: ['ffmpeg'])
57
- expect(result).to be_success
58
- end
59
- end
60
- end
61
-
62
- describe 'apt autoremove' do
63
- it 'removes unused packages' do
64
- case os_name
65
- when 'debian', 'ubuntu'
66
- host.su('root')
67
- result = host.apt('autoremove')
68
- expect(result).to be_success
69
- end
70
- end
71
- end
72
-
73
- describe 'apt clean' do
74
- it 'cleans packages' do
75
- case os_name
76
- when 'debian', 'ubuntu'
77
- host.su('root')
78
- result = host.apt('clean')
79
- expect(result).to be_success
80
- end
81
- end
82
-
83
- it 'autocleans packages' do
84
- case os_name
85
- when 'debian', 'ubuntu'
86
- host.su('root')
87
- result = host.apt('autoclean')
88
- expect(result).to be_success
89
- end
90
- end
91
- end
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
-
104
- describe 'apt upgrade' do
105
- it 'upgrades packages' do
106
- case os_name
107
- when 'debian', 'ubuntu'
108
- host.su('root')
109
- result = host.apt('upgrade')
110
- expect(result).to be_success
111
- end
112
- end
113
-
114
- it 'fully upgrades packages' do
115
- case os_name
116
- when 'debian', 'ubuntu'
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.success?).to eq(true)
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.success?).to eq(true)
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-2.txt~' }
264
- expect(backup.path).to eq('remote-file-copied-2.txt~')
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
@@ -69,6 +69,27 @@ RSpec.describe Kanrisuru::Core::System do
69
69
  expect(process).to be_empty
70
70
  end
71
71
 
72
+ it 'gets kernel statistics' do
73
+ result = host.kernel_statistics
74
+ expect(result).to be_success
75
+
76
+ expect(result.data).to respond_to(
77
+ :cpu_total,
78
+ :cpus,
79
+ :interrupt_total,
80
+ :interrupts,
81
+ :ctxt,
82
+ :btime,
83
+ :processes,
84
+ :procs_running,
85
+ :procs_blocked,
86
+ :softirq_total,
87
+ :softirqs
88
+ )
89
+
90
+ expect(result.cpus.length).to eq(host.cpu.cores)
91
+ end
92
+
72
93
  it 'gets process details' do
73
94
  result = host.ps
74
95
 
@@ -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
- 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
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
- 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
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
- case os_name
58
- when 'centos', 'rhel', 'fedora'
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
- case os_name
66
- when 'centos', 'rhel', 'fedora'
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
- case os_name
74
- when 'centos', 'rhel', 'fedora'
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
- case os_name
82
- when 'centos', 'rhel', 'fedora'
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
- 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
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
- 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
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
- 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
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
- 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
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
- 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
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
- 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
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
- 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
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
- 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
112
+ host.su('root')
113
+ result = host.yum('autoremove')
114
+ expect(result).to be_success
157
115
  end
158
116
  end
159
117
  end