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
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Remote::Cpu do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
14
+ context 'with metal' do
15
+ let(:host) do
16
+ Kanrisuru::Remote::Host.new(
17
+ host: 'metal-host',
18
+ username: 'ubuntu',
19
+ keys: ['id_rsa']
20
+ )
21
+ end
22
+
23
+ before do
24
+ StubNetwork.stub_command!(:lscpu) do |_args|
25
+ struct = Kanrisuru::Core::System::CPUArchitecture.new
26
+ struct.architecture = 'x86_64'
27
+ struct.cores = 48
28
+ struct.byte_order = 'Little Endian'
29
+ struct.address_sizes = ['46 bits physical', '48 bits virtual']
30
+ struct.operation_modes = %w[32-bit 64-bit]
31
+ struct.online_cpus = 0
32
+ struct.threads_per_core = 2
33
+ struct.cores_per_socket = 12
34
+ struct.sockets = 2
35
+ struct.numa_mode = nil
36
+ struct.vendor_id = 'GenuineIntel'
37
+ struct.cpu_family = 6
38
+ struct.model = 63
39
+ struct.model_name = 'Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz'
40
+ struct.stepping = 2
41
+ struct.cpu_mhz = 1200.16
42
+ struct.cpu_max_mhz = 3300.0
43
+ struct.cpu_min_mhz = 1200.0
44
+ struct.bogo_mips = nil
45
+ struct.virtualization = 'VT-x'
46
+ struct.hypervisor_vendor = nil
47
+ struct.virtualization_type = nil
48
+ struct.l1d_cache = '768 KiB'
49
+ struct.l1i_cache = '768 KiB'
50
+ struct.l2_cache = '6 MiB'
51
+ struct.l3_cache = '60 MiB'
52
+ struct.numa_nodes = 2
53
+ struct.vulnerabilities = [
54
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Itlb multihit',
55
+ 'KVM: Mitigation: Split huge pages'),
56
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('L1tf',
57
+ 'Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable'),
58
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Mds',
59
+ 'Mitigation; Clear CPU buffers; SMT vulnerable'),
60
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Meltdown', 'Mitigation; PTI'),
61
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Spec store bypass',
62
+ 'Mitigation; Speculative Store Bypass disabled via prctl and seccomp'),
63
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Spectre v1',
64
+ 'Mitigation; usercopy/swapgs barriers and __user pointer sanitization'),
65
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Spectre v2',
66
+ 'Mitigation; Full generic retpoline, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling'),
67
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Srbds', 'Not affected'),
68
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Tsx async abort', 'Not affected')
69
+ ]
70
+ struct.flags = %w[fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge
71
+ mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti intel_ppin ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm xsaveopt cqm_llc cqm_occup_llc dtherm ida arat pln pts md_clear flush_l1d]
72
+ struct
73
+ end
74
+ end
75
+
76
+ after do
77
+ StubNetwork.unstub_command!(:lscpu)
78
+ end
79
+
80
+ it 'gets host cpu attributes' do
81
+ expect(host.cpu.architecture).to eq('x86_64')
82
+ expect(host.cpu.cores).to eq(48)
83
+ expect(host.cpu.byte_order).to eq('Little Endian')
84
+ expect(host.cpu.address_sizes).to eq(['46 bits physical', '48 bits virtual'])
85
+ expect(host.cpu.threads_per_core).to eq(2)
86
+ expect(host.cpu.cores_per_socket).to eq(12)
87
+ expect(host.cpu.sockets).to eq(2)
88
+ expect(host.cpu.vendor_id).to eq('GenuineIntel')
89
+ expect(host.cpu.cpu_family).to eq(6)
90
+ expect(host.cpu.model).to eq(63)
91
+ expect(host.cpu.model_name).to eq('Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz')
92
+ expect(host.cpu.cpu_mhz).to eq(1200.16)
93
+ expect(host.cpu.cpu_max_mhz).to eq(3300.0)
94
+ expect(host.cpu.cpu_min_mhz).to eq(1200.0)
95
+ expect(host.cpu.hypervisor).to be_nil
96
+ expect(host.cpu.virtualization_type).to be_nil
97
+ # expect(host.cpu.l1d_cache).to eq("768 KiB")
98
+ # expect(host.cpu.l1i_cache).to eq("768 KiB")
99
+ # expect(host.cpu.l2_cache).to eq("6 MiB")
100
+ # expect(host.cpu.l3_cache).to eq("60 MiB")
101
+ expect(host.cpu.numa_nodes).to eq(2)
102
+ end
103
+ end
104
+ end
@@ -3,13 +3,12 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Remote::Env do
6
-
7
- let (:env) { Kanrisuru::Remote::Env.new }
6
+ let(:env) { described_class.new }
8
7
 
9
8
  it 'adds a environment variable' do
10
9
  env['VAR1'] = 'hello'
11
10
  expect(env.count).to eq(1)
12
- expect(env.to_h).to eq({'VAR1' => 'hello'})
11
+ expect(env.to_h).to eq({ 'VAR1' => 'hello' })
13
12
  expect(env.to_s).to eq('export VAR1=hello;')
14
13
  expect(env['VAR1']).to eq('hello')
15
14
  end
@@ -19,7 +18,7 @@ RSpec.describe Kanrisuru::Remote::Env do
19
18
  env['var2'] = 'world'
20
19
 
21
20
  expect(env.count).to eq(2)
22
- expect(env.to_h).to eq({'VAR1' => 'hello', 'VAR2' => 'world'})
21
+ expect(env.to_h).to eq({ 'VAR1' => 'hello', 'VAR2' => 'world' })
23
22
  expect(env.to_s).to eq('export VAR1=hello; export VAR2=world;')
24
23
  expect(env['VAR1']).to eq('hello')
25
24
  expect(env['VAR2']).to eq('world')
@@ -46,5 +45,4 @@ RSpec.describe Kanrisuru::Remote::Env do
46
45
 
47
46
  expect(env.count).to eq(0)
48
47
  end
49
-
50
48
  end
@@ -17,7 +17,7 @@ class StubNetwork
17
17
 
18
18
  unless Kanrisuru::Remote::Os.instance_methods(false).include?(:initialize_alias)
19
19
  Kanrisuru::Remote::Os.class_eval do
20
- alias_method :initialize_alias, :initialize
20
+ alias_method :initialize_alias, :initialize
21
21
  define_method :initialize do |host|
22
22
  @host = host
23
23
 
@@ -32,25 +32,46 @@ class StubNetwork
32
32
  end
33
33
  end
34
34
 
35
- unless Kanrisuru::Result.instance_methods(false).include?(:initialize_alias)
36
- Kanrisuru::Result.class_eval do
37
- alias_method :initialize_alias, :initialize
38
- def initialize(command)
39
- @command = command
40
- @data = nil
35
+ return if Kanrisuru::Result.instance_methods(false).include?(:initialize_alias)
41
36
 
42
- @error = @command.to_a if @command.failure?
37
+ Kanrisuru::Result.class_eval do
38
+ alias_method :initialize_alias, :initialize
39
+ def initialize(command, parse_result = false, &block)
40
+ @command = command
41
+ @data = nil
42
+
43
+ @data = block.call(@command) if @command.success? && block_given? && parse_result
44
+ @error = @command.to_a if @command.failure?
45
+
46
+ ## Define getter methods on result that maps to
47
+ ## the same methods of a data struct.
48
+ return unless @command.success? && Kanrisuru::Util.present?(@data) && @data.class.ancestors.include?(Struct)
49
+
50
+ method_names = @data.members
51
+ self.class.class_eval do
52
+ method_names.each do |method_name|
53
+ define_method method_name do
54
+ @data[method_name]
55
+ end
56
+ end
43
57
  end
44
58
  end
45
59
  end
46
60
  end
47
61
 
48
- def stub_command!(method, &block)
62
+ def stub_command!(method, opts = {}, &block)
49
63
  Kanrisuru::Remote::Host.class_eval do
50
64
  alias_method "#{method}_alias", method
51
65
 
52
66
  define_method(method) do |*args|
53
- block.call(args)
67
+ command = Kanrisuru::Command.new(method.to_s)
68
+
69
+ status = opts[:status] || 0
70
+ command.handle_status(status)
71
+
72
+ Kanrisuru::Result.new(command, true) do |_cmd|
73
+ block.call(args)
74
+ end
54
75
  end
55
76
  end
56
77
  end
@@ -67,11 +88,11 @@ class StubNetwork
67
88
  end
68
89
 
69
90
  Kanrisuru::Remote::Os.class_eval do
70
- alias_method :initialize, :initialize_alias
91
+ alias_method :initialize, :initialize_alias
71
92
  end
72
93
 
73
94
  Kanrisuru::Result.class_eval do
74
- alias_method :initialize, :initialize_alias
95
+ alias_method :initialize, :initialize_alias
75
96
  end
76
97
  end
77
98
 
@@ -106,13 +127,11 @@ class StubNetwork
106
127
  hardware_platform: 'x86_64',
107
128
  processor: 'x86_64',
108
129
  release: 'opensuse-leap',
109
- version:15.2
130
+ version: 15.2
110
131
  }
111
132
  }
112
133
 
113
- defaults[name].key?(property) ?
114
- defaults[name][property] : nil
134
+ defaults[name][property] if defaults[name].key?(property)
115
135
  end
116
-
117
136
  end
118
137
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'securerandom'
4
+
3
5
  class TestHosts
4
6
  class << self
5
7
  def each_os(opts = {}, &block)
@@ -7,7 +9,10 @@ class TestHosts
7
9
  next unless test?(os_name)
8
10
  next if opts[:only] && !only?(opts, os_name)
9
11
 
10
- block.call(os_name)
12
+ host_json = TestHosts.host(os_name)
13
+ spec_dir = spec_dir(host_json)
14
+
15
+ block.call(os_name, host_json, spec_dir)
11
16
  end
12
17
  end
13
18
 
@@ -15,6 +20,11 @@ class TestHosts
15
20
  hosts(name)
16
21
  end
17
22
 
23
+ def spec_dir(host_json)
24
+ random_string = SecureRandom.hex
25
+ "#{host_json['home']}/.kanrisuru_spec_files_#{random_string[0..5]}"
26
+ end
27
+
18
28
  def only?(opts, name)
19
29
  ((opts[:only].instance_of?(Array) && opts[:only].include?(name)) ||
20
30
  (opts[:only].instance_of?(String) && opts[:only] == name))
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::Apt do
6
- TestHosts.each_os(only: %w[debian ubuntu]) do |os_name|
5
+ TestHosts.each_os(only: %w[debian ubuntu]) do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::Apt 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,22 +2,20 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::Archive do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json, spec_dir|
6
+ RSpec.describe Kanrisuru::Core::Archive do
7
7
  context "with #{os_name}" do
8
8
  before(:all) do
9
- host_json = TestHosts.host(os_name)
10
9
  host = Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
12
11
  username: host_json['username'],
13
12
  keys: [host_json['ssh_key']]
14
13
  )
15
14
 
16
- host.mkdir("#{host_json['home']}/.kanrisuru_spec_files", silent: true)
15
+ host.mkdir(spec_dir, silent: true)
17
16
  host.disconnect
18
17
  end
19
18
 
20
- let(:host_json) { TestHosts.host(os_name) }
21
19
  let(:host) do
22
20
  Kanrisuru::Remote::Host.new(
23
21
  host: host_json['hostname'],
@@ -26,22 +24,19 @@ RSpec.describe Kanrisuru::Core::Archive do
26
24
  )
27
25
  end
28
26
 
29
- let(:spec_dir) { "#{host_json['home']}/.kanrisuru_spec_files" }
30
-
31
27
  after do
32
28
  host.disconnect
33
29
  end
34
30
 
35
31
  after(:all) do
36
- host_json = TestHosts.host(os_name)
37
32
  host = Kanrisuru::Remote::Host.new(
38
33
  host: host_json['hostname'],
39
34
  username: host_json['username'],
40
35
  keys: [host_json['ssh_key']]
41
36
  )
42
37
 
43
- host.rmdir("#{host_json['home']}/.kanrisuru_spec_files")
44
- host.rmdir("#{host_json['home']}/extract-tar-files") if host.dir?("#{host_json['home']}/extract-tar-files")
38
+ host.rmdir(spec_dir)
39
+ host.rmdir("#{spec_dir}/extract-tar-files") if host.dir?("#{spec_dir}/extract-tar-files")
45
40
  host.disconnect
46
41
  end
47
42
 
@@ -126,10 +121,10 @@ RSpec.describe Kanrisuru::Core::Archive do
126
121
  paths = result.map(&:path)
127
122
  expect(paths.include?('test2.config')).to eq(false)
128
123
 
129
- host.mkdir("#{host_json['home']}/extract-tar-files", silent: true)
130
- host.tar('extract', 'archive.tar', directory: "#{host_json['home']}/extract-tar-files")
124
+ host.mkdir("#{spec_dir}/extract-tar-files", silent: true)
125
+ host.tar('extract', 'archive.tar', directory: "#{spec_dir}/extract-tar-files")
131
126
 
132
- result = host.ls(path: "#{host_json['home']}/extract-tar-files")
127
+ result = host.ls(path: "#{spec_dir}/extract-tar-files")
133
128
  paths = result.map(&:path)
134
129
 
135
130
  expect(paths.include?('test1.config')).to eq(true)
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::Disk do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::Disk 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::Dmi do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::Dmi 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,22 +2,20 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::File do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json, spec_dir|
6
+ RSpec.describe Kanrisuru::Core::File do
7
7
  context "with #{os_name}" do
8
8
  before(:all) do
9
- host_json = TestHosts.host(os_name)
10
9
  host = Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
12
11
  username: host_json['username'],
13
12
  keys: [host_json['ssh_key']]
14
13
  )
15
14
 
16
- host.mkdir("#{host_json['home']}/.kanrisuru_spec_files", silent: true)
15
+ host.mkdir(spec_dir, silent: true)
17
16
  host.disconnect
18
17
  end
19
18
 
20
- let(:host_json) { TestHosts.host(os_name) }
21
19
  let(:host) do
22
20
  Kanrisuru::Remote::Host.new(
23
21
  host: host_json['hostname'],
@@ -26,25 +24,18 @@ RSpec.describe Kanrisuru::Core::File do
26
24
  )
27
25
  end
28
26
 
29
- let(:spec_dir) { "#{host_json['home']}/.kanrisuru_spec_files" }
30
-
31
27
  after do
32
28
  host.disconnect
33
29
  end
34
30
 
35
31
  after(:all) do
36
- host_json = TestHosts.host(os_name)
37
32
  host = Kanrisuru::Remote::Host.new(
38
33
  host: host_json['hostname'],
39
34
  username: host_json['username'],
40
35
  keys: [host_json['ssh_key']]
41
36
  )
42
37
 
43
- host.rm("#{host_json['home']}/.kanrisuru_spec_files", force: true, recursive: true)
44
- if host.dir?("#{host_json['home']}/extract-tar-files")
45
- host.rm("#{host_json['home']}/extract-tar-files", force: true,
46
- recursive: true)
47
- end
38
+ host.rm(spec_dir, force: true, recursive: true)
48
39
  host.disconnect
49
40
  end
50
41
 
@@ -356,7 +347,6 @@ RSpec.describe Kanrisuru::Core::File do
356
347
  data = host.cat('/etc/hosts').command.raw_result
357
348
  doc = data.map(&:lines).flatten
358
349
 
359
- lines = doc.length
360
350
  words = doc.map(&:split).flatten
361
351
  chars = doc.map(&:length).flatten
362
352
 
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::Find do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::Find 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'],
@@ -19,6 +18,7 @@ RSpec.describe Kanrisuru::Core::Find do
19
18
  end
20
19
 
21
20
  it 'finds home directory' do
21
+ host.su('root')
22
22
  result = host.find(paths: '/home')
23
23
  home = result.find { |item| item.path == host_json['home'] }
24
24
  expect(home.path).to eq(host_json['home'])
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::Group do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::Group 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::IP do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::IP 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::Path do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::Path 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,11 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::Socket do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::Socket do
7
7
  context "with #{os_name}" do
8
- let(:host_json) { TestHosts.host(os_name) }
9
-
10
8
  let(:host) do
11
9
  Kanrisuru::Remote::Host.new(
12
10
  host: host_json['hostname'],
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::Stat do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::Stat 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,21 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.describe Kanrisuru::Core::Stream do
4
- TestHosts.each_os do |os_name|
3
+ require 'spec_helper'
4
+
5
+ TestHosts.each_os do |os_name, host_json, spec_dir|
6
+ RSpec.describe Kanrisuru::Core::Stream do
5
7
  context "with #{os_name}" do
6
8
  before(:all) do
7
- host_json = TestHosts.host(os_name)
8
9
  host = Kanrisuru::Remote::Host.new(
9
10
  host: host_json['hostname'],
10
11
  username: host_json['username'],
11
12
  keys: [host_json['ssh_key']]
12
13
  )
13
14
 
14
- host.mkdir("#{host_json['home']}/.kanrisuru_spec_files", silent: true)
15
+ host.mkdir(spec_dir, silent: true)
15
16
  host.disconnect
16
17
  end
17
18
 
18
- let(:host_json) { TestHosts.host(os_name) }
19
19
  let(:host) do
20
20
  Kanrisuru::Remote::Host.new(
21
21
  host: host_json['hostname'],
@@ -24,21 +24,18 @@ RSpec.describe Kanrisuru::Core::Stream do
24
24
  )
25
25
  end
26
26
 
27
- let(:spec_dir) { "#{host_json['home']}/.kanrisuru_spec_files" }
28
-
29
27
  after do
30
28
  host.disconnect
31
29
  end
32
30
 
33
31
  after(:all) do
34
- host_json = TestHosts.host(os_name)
35
32
  host = Kanrisuru::Remote::Host.new(
36
33
  host: host_json['hostname'],
37
34
  username: host_json['username'],
38
35
  keys: [host_json['ssh_key']]
39
36
  )
40
37
 
41
- host.rmdir("#{host_json['home']}/.kanrisuru_spec_files")
38
+ host.rmdir(spec_dir)
42
39
  host.disconnect
43
40
  end
44
41
 
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::System do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::System 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'],
@@ -107,7 +106,6 @@ RSpec.describe Kanrisuru::Core::System do
107
106
  host.su('root')
108
107
 
109
108
  result = host.last(failed_attempts: true)
110
- puts result.data
111
109
  expect(result).to be_success
112
110
  end
113
111
 
@@ -2,22 +2,20 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::File do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json, spec_dir|
6
+ RSpec.describe Kanrisuru::Core::File do
7
7
  context "with #{os_name}" do
8
8
  before(:all) do
9
- host_json = TestHosts.host(os_name)
10
9
  host = Kanrisuru::Remote::Host.new(
11
10
  host: host_json['hostname'],
12
11
  username: host_json['username'],
13
12
  keys: [host_json['ssh_key']]
14
13
  )
15
14
 
16
- host.mkdir("#{host_json['home']}/.kanrisuru_spec_files", silent: true)
15
+ host.mkdir(spec_dir, silent: true)
17
16
  host.disconnect
18
17
  end
19
18
 
20
- let(:host_json) { TestHosts.host(os_name) }
21
19
  let(:host) do
22
20
  Kanrisuru::Remote::Host.new(
23
21
  host: host_json['hostname'],
@@ -26,21 +24,18 @@ RSpec.describe Kanrisuru::Core::File do
26
24
  )
27
25
  end
28
26
 
29
- let(:spec_dir) { "#{host_json['home']}/.kanrisuru_spec_files" }
30
-
31
27
  after do
32
28
  host.disconnect
33
29
  end
34
30
 
35
31
  after(:all) do
36
- host_json = TestHosts.host(os_name)
37
32
  host = Kanrisuru::Remote::Host.new(
38
33
  host: host_json['hostname'],
39
34
  username: host_json['username'],
40
35
  keys: [host_json['ssh_key']]
41
36
  )
42
37
 
43
- host.rmdir("#{host_json['home']}/.kanrisuru_spec_files")
38
+ host.rmdir(spec_dir)
44
39
  host.disconnect
45
40
  end
46
41
 
@@ -2,10 +2,9 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- RSpec.describe Kanrisuru::Core::User do
6
- TestHosts.each_os do |os_name|
5
+ TestHosts.each_os do |os_name, host_json|
6
+ RSpec.describe Kanrisuru::Core::User 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'],
@@ -19,7 +18,6 @@ RSpec.describe Kanrisuru::Core::User do
19
18
  end
20
19
 
21
20
  after(:all) do
22
- host_json = TestHosts.host(os_name)
23
21
  host = Kanrisuru::Remote::Host.new(
24
22
  host: host_json['hostname'],
25
23
  username: host_json['username'],