kanrisuru 0.10.0 → 0.12.1

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.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CONTRIBUTING.md +9 -9
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +7 -8
  4. data/.rspec +1 -1
  5. data/CHANGELOG.md +127 -102
  6. data/CODE_OF_CONDUCT.md +10 -10
  7. data/README.md +19 -90
  8. data/kanrisuru.gemspec +2 -1
  9. data/lib/kanrisuru/command.rb +7 -0
  10. data/lib/kanrisuru/core/archive.rb +11 -35
  11. data/lib/kanrisuru/core/disk.rb +0 -3
  12. data/lib/kanrisuru/core/dmi.rb +1 -1
  13. data/lib/kanrisuru/core/file.rb +4 -11
  14. data/lib/kanrisuru/core/find.rb +6 -11
  15. data/lib/kanrisuru/core/mount.rb +14 -15
  16. data/lib/kanrisuru/core/socket.rb +2 -1
  17. data/lib/kanrisuru/core/stream.rb +1 -2
  18. data/lib/kanrisuru/core/zypper.rb +6 -23
  19. data/lib/kanrisuru/os_package/collection.rb +58 -0
  20. data/lib/kanrisuru/os_package/define.rb +34 -0
  21. data/lib/kanrisuru/os_package/include.rb +163 -0
  22. data/lib/kanrisuru/os_package.rb +3 -245
  23. data/lib/kanrisuru/remote/cpu.rb +5 -1
  24. data/lib/kanrisuru/remote/fstab.rb +5 -5
  25. data/lib/kanrisuru/result.rb +5 -4
  26. data/lib/kanrisuru/util.rb +1 -1
  27. data/lib/kanrisuru/version.rb +1 -1
  28. data/spec/functional/core/apt_spec.rb +22 -30
  29. data/spec/functional/core/archive_spec.rb +96 -120
  30. data/spec/functional/core/find_spec.rb +94 -113
  31. data/spec/functional/core/mount_spec.rb +121 -0
  32. data/spec/functional/core/socket_spec.rb +23 -28
  33. data/spec/functional/core/stream_spec.rb +12 -12
  34. data/spec/functional/core/transfer_spec.rb +108 -131
  35. data/spec/functional/core/yum_spec.rb +58 -83
  36. data/spec/functional/remote/cluster_spec.rb +11 -2
  37. data/spec/functional/remote/cpu_spec.rb +104 -0
  38. data/spec/functional/remote/env_spec.rb +3 -5
  39. data/spec/helper/stub_network.rb +35 -16
  40. data/spec/helper/test_hosts.rb +11 -1
  41. data/spec/integration/core/apt_spec.rb +2 -3
  42. data/spec/integration/core/archive_spec.rb +8 -13
  43. data/spec/integration/core/disk_spec.rb +2 -3
  44. data/spec/integration/core/dmi_spec.rb +2 -3
  45. data/spec/integration/core/file_spec.rb +4 -14
  46. data/spec/integration/core/find_spec.rb +3 -3
  47. data/spec/integration/core/group_spec.rb +2 -3
  48. data/spec/integration/core/ip_spec.rb +2 -3
  49. data/spec/integration/core/path_spec.rb +2 -3
  50. data/spec/integration/core/socket_spec.rb +2 -4
  51. data/spec/integration/core/stat_spec.rb +2 -3
  52. data/spec/integration/core/stream_spec.rb +6 -9
  53. data/spec/integration/core/system_spec.rb +2 -4
  54. data/spec/integration/core/transfer_spec.rb +4 -9
  55. data/spec/integration/core/user_spec.rb +2 -4
  56. data/spec/integration/core/yum_spec.rb +2 -3
  57. data/spec/integration/core/zypper_spec.rb +5 -6
  58. data/spec/integration/remote/cpu_spec.rb +2 -3
  59. data/spec/integration/remote/env_spec.rb +2 -3
  60. data/spec/integration/remote/fstab_spec.rb +2 -3
  61. data/spec/integration/remote/host_spec.rb +2 -3
  62. data/spec/integration/remote/memory_spec.rb +2 -2
  63. data/spec/integration/remote/os_spec.rb +2 -3
  64. data/spec/integration/remote/remote_file_spec.rb +9 -15
  65. data/spec/spec_helper.rb +12 -3
  66. data/spec/unit/command_spec.rb +19 -1
  67. data/spec/unit/core/find_spec.rb +1 -1
  68. data/spec/unit/core/yum_spec.rb +1 -1
  69. data/spec/unit/mode_spec.rb +2 -2
  70. data/spec/unit/remote/cluster_spec.rb +3 -1
  71. data/spec/unit/remote/cpu_spec.rb +1 -2
  72. data/spec/unit/remote/env_spec.rb +1 -3
  73. data/spec/unit/util_spec.rb +13 -0
  74. metadata +23 -4
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::Yum do
6
- TestHosts.each_os(only: %w[fedora rhel centos]) do |os_name|
5
+ TestHosts.each_os(only: %w[fedora rhel centos]) do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::Yum do
7
7
  context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
8
  let(:host) do
10
9
  Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::Zypper do
6
- TestHosts.each_os(only: %w[sles opensuse]) do |os_name|
5
+ TestHosts.each_os(only: %w[sles opensuse]) do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::Zypper do
7
7
  context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
8
  let(:host) do
10
9
  Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
@@ -30,19 +29,19 @@ RSpec.describe Kanrisuru::Core::Zypper do
30
29
 
31
30
  it 'installs a package' do
32
31
  host.su('root')
33
- result = host.zypper('install', packages: 'ffmpeg')
32
+ result = host.zypper('install', packages: 'nginx')
34
33
  expect(result).to be_success
35
34
  end
36
35
 
37
36
  it 'installs multiple packages' do
38
37
  host.su('root')
39
- result = host.zypper('install', packages: %w[curl ffmpeg])
38
+ result = host.zypper('install', packages: %w[curl nginx])
40
39
  expect(result).to be_success
41
40
  end
42
41
 
43
42
  it 'removes a package' do
44
43
  host.su('root')
45
- result = host.zypper('remove', packages: ['ffmpeg'])
44
+ result = host.zypper('remove', packages: ['nginx'])
46
45
  expect(result).to be_success
47
46
  end
48
47
 
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Remote::Cpu do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Remote::Cpu do
7
7
  context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
8
  let(:host) do
10
9
  Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Remote::Env do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Remote::Env do
7
7
  context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
8
  let(:host) do
10
9
  Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
@@ -1,9 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe Kanrisuru::Remote::Fstab do
4
- TestHosts.each_os do |os_name|
3
+ TestHosts.each_os do |os_name, host_json|
4
+ RSpec.describe Kanrisuru::Remote::Fstab do
5
5
  context "with #{os_name}" do
6
- let(:host_json) { TestHosts.host(os_name) }
7
6
  let(:host) do
8
7
  Kanrisuru::Remote::Host.new(
9
8
  host: host_json['hostname'],
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Remote::Host do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Remote::Host do
7
7
  context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
8
  let(:host) do
10
9
  described_class.new(
11
10
  host: host_json['hostname'],
@@ -2,8 +2,8 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Remote::Memory do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name|
6
+ RSpec.describe Kanrisuru::Remote::Memory do
7
7
  context "with #{os_name}" do
8
8
  let(:host_json) { TestHosts.host(os_name) }
9
9
  let(:host) do
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Remote::Os do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Remote::Os do
7
7
  context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
8
  let(:host) do
10
9
  Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
@@ -1,29 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe Kanrisuru::Remote::File do
4
- module Kanrisuru
5
- module Remote
6
- Class.new(File) do
7
- READ_FILE_SIZE = 25_000
8
- end
3
+ module Kanrisuru
4
+ module Remote
5
+ Class.new(File) do
6
+ READ_FILE_SIZE = 25_000
9
7
  end
10
8
  end
9
+ end
11
10
 
12
- TestHosts.each_os do |os_name|
11
+ TestHosts.each_os do |os_name, host_json, spec_dir|
12
+ RSpec.describe Kanrisuru::Remote::File do
13
13
  context "with #{os_name}" do
14
14
  before(:all) do
15
- host_json = TestHosts.host(os_name)
16
15
  host = Kanrisuru::Remote::Host.new(
17
16
  host: host_json['hostname'],
18
17
  username: host_json['username'],
19
18
  keys: [host_json['ssh_key']]
20
19
  )
21
20
 
22
- host.mkdir("#{host_json['home']}/.kanrisuru_spec_files", silent: true)
21
+ host.mkdir(spec_dir, silent: true)
23
22
  host.disconnect
24
23
  end
25
24
 
26
- let(:host_json) { TestHosts.host(os_name) }
27
25
  let(:host) do
28
26
  Kanrisuru::Remote::Host.new(
29
27
  host: host_json['hostname'],
@@ -32,22 +30,18 @@ RSpec.describe Kanrisuru::Remote::File do
32
30
  )
33
31
  end
34
32
 
35
- let(:spec_dir) { "#{host_json['home']}/.kanrisuru_spec_files" }
36
-
37
33
  after do
38
34
  host.disconnect
39
35
  end
40
36
 
41
37
  after(:all) do
42
- host_json = TestHosts.host(os_name)
43
38
  host = Kanrisuru::Remote::Host.new(
44
39
  host: host_json['hostname'],
45
40
  username: host_json['username'],
46
41
  keys: [host_json['ssh_key']]
47
42
  )
48
43
 
49
- host.rmdir("#{host_json['home']}/.kanrisuru_spec_files")
50
- host.rmdir("#{host_json['home']}/extract-tar-files") if host.dir?("#{host_json['home']}/extract-tar-files")
44
+ host.rmdir(spec_dir)
51
45
  host.disconnect
52
46
  end
53
47
 
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'simplecov'
4
- SimpleCov.start
5
-
6
4
  require 'simplecov-cobertura'
7
- SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
5
+
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ SimpleCov::Formatter::CoberturaFormatter
9
+ ])
10
+
11
+ SimpleCov.use_merging true
12
+ SimpleCov.command_name("kanrisuru-tests" + (ENV['TEST_ENV_NUMBER'] || ''))
13
+
14
+ SimpleCov.start
8
15
 
9
16
  require 'kanrisuru'
10
17
 
@@ -21,6 +28,8 @@ RSpec.configure do |config|
21
28
  # Disable RSpec exposing methods globally on `Module` and `main`
22
29
  config.disable_monkey_patching!
23
30
 
31
+ config.silence_filter_announcements = true if ENV['TEST_ENV_NUMBER']
32
+
24
33
  config.expect_with :rspec do |c|
25
34
  c.syntax = :expect
26
35
  end
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Command do
6
6
  it 'responds to methods' do
7
- command = Kanrisuru::Command.new('ls')
7
+ command = described_class.new('ls')
8
8
  expect(command).to respond_to(:exit_status)
9
9
  expect(command).to respond_to(:raw_result)
10
10
  expect(command).to respond_to(:program)
@@ -28,4 +28,22 @@ RSpec.describe Kanrisuru::Command do
28
28
  expect(command).to respond_to(:append_flag)
29
29
  expect(command).to respond_to(:append_valid_exit_code)
30
30
  end
31
+
32
+ it 'does not append nil array values' do
33
+ command = described_class.new('hello')
34
+ command.append_array(nil)
35
+ expect(command.raw_command).to eq('hello')
36
+ end
37
+
38
+ it 'appends string array values' do
39
+ command = described_class.new('ls')
40
+ command.append_array('/etc')
41
+ expect(command.raw_command).to eq('ls /etc')
42
+ end
43
+
44
+ it 'appends array values' do
45
+ command = described_class.new('ls')
46
+ command.append_array(['/proc/', '/etc', '/var', '/dev'])
47
+ expect(command.raw_command).to eq('ls /proc/ /etc /var /dev')
48
+ end
31
49
  end
@@ -26,7 +26,7 @@ RSpec.describe Kanrisuru::Core::Find do
26
26
  it 'responds to find fields' do
27
27
  expect(Kanrisuru::Core::Find::FilePath.new).to respond_to(:path)
28
28
  expect(Kanrisuru::Core::Find::REGEX_TYPES).to(
29
- eq(['emacs', 'posix-awk', 'posix-basic', 'posix-egrep', 'posix-extended'])
29
+ eq(%w[emacs posix-awk posix-basic posix-egrep posix-extended])
30
30
  )
31
31
  end
32
32
  end
@@ -22,7 +22,7 @@ RSpec.describe Kanrisuru::Core::Yum do
22
22
  it 'responds to methods' do
23
23
  expect(host).to respond_to(:yum)
24
24
  end
25
-
25
+
26
26
  it 'responds to yum fields' do
27
27
  expect(Kanrisuru::Core::Yum::PackageOverview.new).to respond_to(
28
28
  :package, :architecture, :version, :installed
@@ -92,9 +92,9 @@ RSpec.describe Kanrisuru::Mode do
92
92
  expect(mode.other.to_i).to eq(7)
93
93
  expect(mode.other.symbolic).to eq('rwx')
94
94
 
95
- mode = described_class.new("---x--x--x")
95
+ mode = described_class.new('---x--x--x')
96
96
  expect(mode.directory?).to eq(false)
97
- expect(mode.numeric).to eq("111")
97
+ expect(mode.numeric).to eq('111')
98
98
 
99
99
  expect(mode.owner.read?).to eq(false)
100
100
  expect(mode.owner.write?).to eq(false)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe Kanrisuru::Remote::Cluster do
2
4
  before(:all) do
3
5
  StubNetwork.stub!
@@ -16,7 +18,7 @@ RSpec.describe Kanrisuru::Remote::Cluster do
16
18
  end
17
19
 
18
20
  it 'responds to methods' do
19
- cluster = Kanrisuru::Remote::Cluster.new(host1)
21
+ cluster = described_class.new(host1)
20
22
  expect(cluster).to respond_to(:hosts)
21
23
  expect(cluster).to respond_to(:[])
22
24
  expect(cluster).to respond_to(:<<)
@@ -20,8 +20,7 @@ RSpec.describe Kanrisuru::Remote::Cpu do
20
20
  end
21
21
 
22
22
  it 'responds to methods' do
23
- cpu = Kanrisuru::Remote::Cpu.new(host)
24
-
23
+ cpu = described_class.new(host)
25
24
  expect(cpu).to respond_to(:load_average)
26
25
  expect(cpu).to respond_to(:load_average1)
27
26
  expect(cpu).to respond_to(:load_average5)
@@ -3,9 +3,8 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Remote::Env do
6
-
7
6
  it 'responds to methods' do
8
- env = Kanrisuru::Remote::Env.new
7
+ env = described_class.new
9
8
  expect(env).to respond_to(:to_h)
10
9
  expect(env).to respond_to(:to_s)
11
10
  expect(env).to respond_to(:clear)
@@ -15,5 +14,4 @@ RSpec.describe Kanrisuru::Remote::Env do
15
14
  expect(env).to respond_to(:[])
16
15
  expect(env).to respond_to(:[]=)
17
16
  end
18
-
19
17
  end
@@ -84,6 +84,10 @@ RSpec.describe Kanrisuru::Util do
84
84
  expect { Kanrisuru::Util::Bits.convert_bytes(100, :kilobytee, :kilobit) }.to raise_error(ArgumentError)
85
85
  end
86
86
 
87
+ it 'gets invalid signal type' do
88
+ expect { Kanrisuru::Util::Signal[{ 'Hello' => 'World' }] }.to raise_error(ArgumentError)
89
+ end
90
+
87
91
  it 'translates signal from string to numeric' do
88
92
  expect(Kanrisuru::Util::Signal['HUP']).to eq(1)
89
93
  expect(Kanrisuru::Util::Signal['INT']).to eq(2)
@@ -214,6 +218,10 @@ RSpec.describe Kanrisuru::Util do
214
218
  expect(Kanrisuru::Util::Signal[64]).to eq('RTMAX')
215
219
  end
216
220
 
221
+ it 'gets invalid dmi type' do
222
+ expect { Kanrisuru::Util::DmiType[{ 'Hello' => 'World' }] }.to raise_error(ArgumentError)
223
+ end
224
+
217
225
  it 'translates dmi types from string to integer' do
218
226
  expect(Kanrisuru::Util::DmiType['BIOS']).to eq(0)
219
227
  expect(Kanrisuru::Util::DmiType['System']).to eq(1)
@@ -308,6 +316,11 @@ RSpec.describe Kanrisuru::Util do
308
316
  expect(Kanrisuru::Util::DmiType[43]).to eq('TPM Device')
309
317
  end
310
318
 
319
+ it 'gets fs_mount options' do
320
+ expect(Kanrisuru::Util::FsMountOpts.get_device('common')[:async]).to eq('boolean')
321
+ expect(Kanrisuru::Util::FsMountOpts.get_device_opt(:ext4, :acl)).to eq('boolean')
322
+ end
323
+
311
324
  it 'converts power' do
312
325
  expect(Kanrisuru::Util::Bits.convert_power(:deca, :deca)).to eq(0)
313
326
  expect(Kanrisuru::Util::Bits.convert_power(:deca, :kilo)).to eq(-1)
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kanrisuru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.12.1
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-12-03 00:00:00.000000000 Z
11
+ date: 2021-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: parallel_tests
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.7'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rspec
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -123,7 +137,7 @@ dependencies:
123
137
  - !ruby/object:Gem::Version
124
138
  version: '6.1'
125
139
  description: Kanrisuru helps manage remote servers with objected oriented ruby. Results
126
- come back as structured data, parsed, prepared and ready .
140
+ come back as structured data, parsed, prepared and ready.
127
141
  email: ryan@avamia.com
128
142
  executables: []
129
143
  extensions: []
@@ -170,6 +184,9 @@ files:
170
184
  - lib/kanrisuru/logger.rb
171
185
  - lib/kanrisuru/mode.rb
172
186
  - lib/kanrisuru/os_package.rb
187
+ - lib/kanrisuru/os_package/collection.rb
188
+ - lib/kanrisuru/os_package/define.rb
189
+ - lib/kanrisuru/os_package/include.rb
173
190
  - lib/kanrisuru/remote.rb
174
191
  - lib/kanrisuru/remote/cluster.rb
175
192
  - lib/kanrisuru/remote/cpu.rb
@@ -191,6 +208,7 @@ files:
191
208
  - spec/functional/core/apt_spec.rb
192
209
  - spec/functional/core/archive_spec.rb
193
210
  - spec/functional/core/find_spec.rb
211
+ - spec/functional/core/mount_spec.rb
194
212
  - spec/functional/core/path_spec.rb
195
213
  - spec/functional/core/socket_spec.rb
196
214
  - spec/functional/core/stat_spec.rb
@@ -198,6 +216,7 @@ files:
198
216
  - spec/functional/core/transfer_spec.rb
199
217
  - spec/functional/core/yum_spec.rb
200
218
  - spec/functional/remote/cluster_spec.rb
219
+ - spec/functional/remote/cpu_spec.rb
201
220
  - spec/functional/remote/env_spec.rb
202
221
  - spec/helper/expect_helpers.rb
203
222
  - spec/helper/stub_network.rb
@@ -277,7 +296,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
277
296
  - !ruby/object:Gem::Version
278
297
  version: '0'
279
298
  requirements: []
280
- rubygems_version: 3.1.2
299
+ rubygems_version: 3.2.32
281
300
  signing_key:
282
301
  specification_version: 4
283
302
  summary: Manage remote servers over ssh with ruby.