kanrisuru 0.16.7 → 0.16.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +108 -32
- data/lib/kanrisuru/command.rb +1 -0
- data/lib/kanrisuru/core/dmi/parsers/dmi.rb +9 -9
- data/lib/kanrisuru/core/find/commands/find.rb +3 -1
- data/lib/kanrisuru/core/transfer/commands/upload.rb +11 -2
- data/lib/kanrisuru/remote/cluster.rb +13 -2
- data/lib/kanrisuru/version.rb +1 -1
- data/spec/functional/core/find_spec.rb +12 -0
- data/spec/functional/remote/cluster_spec.rb +149 -0
- data/spec/support/shared_examples/integration/core/transfer.rb +1 -1
- data/spec/support/shared_examples/integration/remote/cluster.rb +26 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7e691e6227ba9b1c056be999461a641fd28a425a4d75cb02af41265b724b0af
|
4
|
+
data.tar.gz: a44f3470adab298c100ada9e954e775df42a38f933bf6533f6f54de096158745
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 631d251e1833edc36568eb00907850a45f39bf623e85b4bc2f45806800ce71de97f1f60e129d4f452d7696f265de1aaa9a8228a67c013edadbd3bdcee94c1f85
|
7
|
+
data.tar.gz: fee6dcab58110f2addc66c93394b679d6dcc5ac0b83fb619102dd3aed1556a3a4a224f34ad87cda7be79cc8e0d39fd3248e2c7340bc50b64ec5130b79ee640fe
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## Kanrisuru 0.16.11 (December 28, 2021) ##
|
2
|
+
* Add functional and integration test cases for the `Kanrisuru::Remote::Cluster` class.
|
3
|
+
* Allow for passing a command instance into `execute` and `execute_shell` on a cluster instance, by deep copying a command object.
|
4
|
+
|
5
|
+
## Kanrisuru 0.16.10 (December 28, 2021) ##
|
6
|
+
* Add `iname` and `iregex` params to `find` command.
|
7
|
+
|
8
|
+
## Kanrisuru 0.16.9 (December 27, 2021) ##
|
9
|
+
* Use cp intead of mv for recurisive dir overwrite on upload command.
|
10
|
+
|
11
|
+
## Kanrisuru 0.16.8 (December 27, 2021) ##
|
12
|
+
* Fix return value of field for dmi parser.
|
13
|
+
* Fix upload command to copy contents of directory when transfering directories from tmp location.
|
14
|
+
|
1
15
|
## Kanrisuru 0.16.7 (December 27, 2021) ##
|
2
16
|
* Update homepage to docs website.
|
3
17
|
|
data/README.md
CHANGED
@@ -15,15 +15,11 @@
|
|
15
15
|
<img src="https://img.shields.io/codeclimate/maintainability/avamia/kanrisuru?style=flat-square" alt="Code Climate maintainability" />
|
16
16
|
</p>
|
17
17
|
|
18
|
-
Kanrisuru
|
18
|
+
Kanrisuru manages remote infrastructure with plain ruby objects. The goal with Kanrisuru is to provide a clean objected oriented wrapper over the most commonly used linux commands, with a clean command interface, and with any usable output, present that as parsed structured data. Kanrisuru doesn't use remote agents to run commands on hosts, nor does the project rely on a large complex set of dependencies.
|
19
19
|
|
20
|
-
|
20
|
+
## Getting Started
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
If you want to dynamically interact with a host, eg: If you need to dynamically scale your infrastructure by continually monitoring specific stats from a centralized system, Kanrisuru can help you accomplish this.
|
25
|
-
|
26
|
-
## Installation
|
22
|
+
Kanrisuru requires ruby `2.5.0` at a minimum.
|
27
23
|
|
28
24
|
Add this line to your application's Gemfile:
|
29
25
|
|
@@ -43,48 +39,128 @@ Or install it yourself as:
|
|
43
39
|
$ gem install kanrisuru
|
44
40
|
```
|
45
41
|
|
46
|
-
##
|
47
|
-
|
42
|
+
## Documentation
|
43
|
+
You can find the official documentation https://kanrisuru.com
|
48
44
|
|
45
|
+
## Usage Guide
|
49
46
|
### Host
|
47
|
+
To connect with Kanrisuru to a remote host, provide the login credentials to instantiate a `Kanrisuru::Remote::Host` instance.
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
host = Kanrisuru::Remote::Host.new(
|
51
|
+
host: 'remote-host-name',
|
52
|
+
username: 'ubuntu',
|
53
|
+
keys: ['~/.ssh/id_rsa']
|
54
|
+
)
|
55
|
+
```
|
56
|
+
|
57
|
+
#### run a simple echo command on the remote host
|
58
|
+
```ruby
|
59
|
+
host.env['VAR'] = 'world'
|
60
|
+
result = host.echo('hello $VAR')
|
61
|
+
result.success?
|
62
|
+
true
|
63
|
+
|
64
|
+
result.to_s
|
65
|
+
'hello world'
|
66
|
+
```
|
67
|
+
|
68
|
+
#### build a custom command
|
69
|
+
```ruby
|
70
|
+
command = Kanrisuru::Command.new('wc')
|
71
|
+
command << '/home/ubuntu/file1.txt'
|
72
|
+
|
73
|
+
host.execute_shell(command)
|
74
|
+
result = Kanrisuru::Result.new(command) do |cmd|
|
75
|
+
items = cmd.to_s.split
|
76
|
+
|
77
|
+
struct = Kanrisuru::Core::File::FileCount.new
|
78
|
+
struct.lines = items[0]
|
79
|
+
struct.words = items[1]
|
80
|
+
struct.characters = items[2]
|
81
|
+
struct
|
82
|
+
end
|
83
|
+
```
|
84
|
+
The `Kanrisuru::Result` class will only run the parsing block if the command run on the remote host was succeful. The final line will be used to build the result object to be read easily. This instance will also dynamically add getter methods to read the underlying data struct for easier querying capabiltiies.
|
85
|
+
|
50
86
|
```ruby
|
51
|
-
|
52
|
-
|
53
|
-
result.to_s # => 'ubuntu'
|
87
|
+
result.success?
|
88
|
+
true
|
54
89
|
|
55
|
-
result
|
56
|
-
|
90
|
+
result.lines
|
91
|
+
8
|
92
|
+
|
93
|
+
result.characters
|
94
|
+
150
|
95
|
+
|
96
|
+
result.words
|
97
|
+
85
|
57
98
|
```
|
58
99
|
|
59
|
-
### Cluster
|
100
|
+
### Cluster
|
101
|
+
Kanrisuru can manage multiple hosts at the same time with the `Kanrisuru::Remote::Cluster`.
|
102
|
+
|
103
|
+
#### To instantiate a cluster, add 1 or more hosts:
|
60
104
|
```ruby
|
61
105
|
cluster = Kanrisuru::Remote::Cluster.new({
|
62
|
-
host: '
|
106
|
+
host: 'remote-host-1',
|
107
|
+
username: 'ubuntu',
|
108
|
+
keys: ['~/.ssh/remote_1_id_rsa']
|
109
|
+
}, {
|
110
|
+
host: 'remote-host-2',
|
111
|
+
username: 'centos',
|
112
|
+
keys: ['~/.ssh/remote_2_id_rsa']
|
63
113
|
}, {
|
64
|
-
host: '
|
114
|
+
host: 'remote-host-3',
|
115
|
+
username: 'opensuse',
|
116
|
+
keys: ['~/.ssh/remote_3_id_rsa']
|
65
117
|
})
|
66
|
-
|
67
|
-
cluster.whoami # => {host: 'host1', result: 'ubuntu'}, {host: 'host2', result: 'alice'}
|
68
|
-
cluster.pwd # => {host: 'host1', result: '/home/ubuntu'}, {host: 'host2', result: '/home/alice'}
|
69
|
-
|
70
|
-
cluster.each do |host|
|
71
|
-
host.pwd.path # => /home/ubuntu
|
72
|
-
end
|
73
118
|
```
|
74
119
|
|
75
|
-
|
120
|
+
#### You can also add a host to a cluster that's already been created
|
76
121
|
```ruby
|
77
|
-
host = Kanrisuru::Remote::Host.new(host: '
|
122
|
+
host = Kanrisuru::Remote::Host.new(host: 'remote-host-4', username: 'rhel', keys: ['~/.ssh/remote_4_id_rsa'])
|
78
123
|
|
79
|
-
|
80
|
-
|
124
|
+
cluster << host
|
125
|
+
```
|
81
126
|
|
82
|
-
|
83
|
-
command.to_s #=> Linux
|
127
|
+
Kanrisuru at this point only runs commands sequentially. We plan on creating a parallel run mode in a future release.
|
84
128
|
|
85
|
-
|
129
|
+
#### To run across all hosts with a single command, cluster will return a array of result hashes
|
130
|
+
```ruby
|
131
|
+
cluster.whoami
|
132
|
+
[
|
133
|
+
{
|
134
|
+
:host => "remote-host-1",
|
135
|
+
:result => #<Kanrisuru::Result:0x640 @status=0 @data=#<struct Kanrisuru::Core::Path::UserName user="ubuntu"> @command=sudo -u ubuntu /bin/bash -c "whoami">
|
136
|
+
},
|
137
|
+
{
|
138
|
+
:host => "remote-host-2",
|
139
|
+
:result => #<Kanrisuru::Result:0x700 @status=0 @data=#<struct Kanrisuru::Core::Path::UserName user="centos"> @command=sudo -u centos /bin/bash -c "whoami">
|
140
|
+
},
|
141
|
+
{
|
142
|
+
:host => "remote-host-3",
|
143
|
+
:result => #<Kanrisuru::Result:0x760 @status=0 @data=#<struct Kanrisuru::Core::Path::UserName user="opensuse"> @command=sudo -u opensuse /bin/bash -c "whoami">
|
144
|
+
},
|
145
|
+
{
|
146
|
+
:host => "remote-host-4",
|
147
|
+
:result => #<Kanrisuru::Result:0x820 @status=0 @data=#<struct Kanrisuru::Core::Path::UserName user="rhel"> @command=sudo -u rhel /bin/bash -c "whoami">
|
148
|
+
}
|
149
|
+
]
|
150
|
+
```
|
86
151
|
|
87
|
-
|
152
|
+
#### You can also access each host individually to run a command conditionaly within an iterable block
|
153
|
+
```ruby
|
154
|
+
cluster.each do |host|
|
155
|
+
case host.os.release
|
156
|
+
when 'ubuntu', 'debian'
|
157
|
+
host.apt('update')
|
158
|
+
when 'centos', 'redhat', 'fedora'
|
159
|
+
host.yum('update')
|
160
|
+
when 'opensuse_leap', 'sles'
|
161
|
+
host.zypper('update')
|
162
|
+
end
|
163
|
+
end
|
88
164
|
```
|
89
165
|
|
90
166
|
## Development
|
data/lib/kanrisuru/command.rb
CHANGED
@@ -94,40 +94,40 @@ module Kanrisuru
|
|
94
94
|
|
95
95
|
def dmi_field_translate(struct, field)
|
96
96
|
field = dmi_scrub_field(field)
|
97
|
-
|
98
97
|
case struct.dmi_type
|
99
98
|
when 'Memory Device'
|
100
99
|
case field
|
101
100
|
when 'size'
|
102
|
-
'mem_size'
|
101
|
+
field = 'mem_size'
|
103
102
|
end
|
104
103
|
when 'System Slots'
|
105
104
|
case field
|
106
105
|
when 'length'
|
107
|
-
'slot_length'
|
106
|
+
field = 'slot_length'
|
108
107
|
end
|
109
108
|
when 'OEM Strings'
|
110
109
|
case field
|
111
110
|
when /^string/
|
112
|
-
'strings'
|
111
|
+
field = 'strings'
|
113
112
|
end
|
114
113
|
when 'Boot Integrity Services'
|
115
114
|
case field
|
116
115
|
when '16_bit_entry_point_address'
|
117
|
-
'sixteen_bit_entry_point_address'
|
116
|
+
field = 'sixteen_bit_entry_point_address'
|
118
117
|
when '32_bit_entry_point_address'
|
119
|
-
'thirty_two_bit_entry_point_address'
|
118
|
+
field = 'thirty_two_bit_entry_point_address'
|
120
119
|
end
|
121
|
-
else
|
122
|
-
field
|
123
120
|
end
|
121
|
+
|
122
|
+
field
|
124
123
|
end
|
125
124
|
|
126
125
|
def dmi_scrub_field(field)
|
127
126
|
field = field.downcase
|
128
127
|
field = field.gsub(/\s/, '_')
|
129
128
|
field = field.gsub('-', '_')
|
130
|
-
field.gsub(':', '')
|
129
|
+
field = field.gsub(':', '')
|
130
|
+
field
|
131
131
|
end
|
132
132
|
|
133
133
|
def dmi_type_to_struct(type)
|
@@ -36,6 +36,7 @@ module Kanrisuru
|
|
36
36
|
|
37
37
|
command.append_arg('-path', opts[:path])
|
38
38
|
command.append_arg('-name', opts[:name])
|
39
|
+
command.append_arg('-iname', opts[:iname])
|
39
40
|
command.append_arg('-gid', opts[:gid])
|
40
41
|
command.append_arg('-uid', opts[:uid])
|
41
42
|
command.append_arg('-user', opts[:user])
|
@@ -58,7 +59,8 @@ module Kanrisuru
|
|
58
59
|
command.append_arg('-regextype', opts[:regex_type])
|
59
60
|
end
|
60
61
|
|
61
|
-
command.append_arg('-regex', "'#{regex}'") if Kanrisuru::Util.present?(regex)
|
62
|
+
command.append_arg('-regex', "'#{opts[:regex]}'") if Kanrisuru::Util.present?(opts[:regex])
|
63
|
+
command.append_arg('-iregex', "'#{opts[:iregex]}'") if Kanrisuru::Util.present?(opts[:iregex])
|
62
64
|
|
63
65
|
if size.instance_of?(String)
|
64
66
|
regex = Regexp.new(/^([-+])?(\d+)([bcwkMG])*$/)
|
@@ -10,9 +10,18 @@ module Kanrisuru
|
|
10
10
|
result = ssh.scp.upload!(local_path, tmp_path, opts)
|
11
11
|
raise 'Unable to upload file' unless result
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
## Need to copy internal dir contents, not the tmp dir itself
|
14
|
+
if opts[:recursive]
|
15
|
+
unless dir?(remote_path)
|
16
|
+
mkdir(remote_path, silent: true)
|
17
|
+
end
|
15
18
|
|
19
|
+
result = cp("#{tmp_path}/*", remote_path, recursive: true)
|
20
|
+
else
|
21
|
+
result = mv(tmp_path, remote_path)
|
22
|
+
end
|
23
|
+
|
24
|
+
raise "Unable to move file to remote path - #{result.command.raw_result}" unless result.success?
|
16
25
|
stat(remote_path)
|
17
26
|
ensure
|
18
27
|
rm(tmp_path, force: true) if inode?(tmp_path)
|
@@ -32,7 +32,7 @@ module Kanrisuru
|
|
32
32
|
def execute(command)
|
33
33
|
@hosts.map do |host_addr, host|
|
34
34
|
## Need to evaluate each host independently for the command.
|
35
|
-
cmd =
|
35
|
+
cmd = create_command(command)
|
36
36
|
|
37
37
|
{ host: host_addr, result: host.execute(cmd) }
|
38
38
|
end
|
@@ -41,7 +41,7 @@ module Kanrisuru
|
|
41
41
|
def execute_shell(command)
|
42
42
|
@hosts.map do |host_addr, host|
|
43
43
|
## Need to evaluate each host independently for the command.
|
44
|
-
cmd =
|
44
|
+
cmd = create_command(command)
|
45
45
|
|
46
46
|
{ host: host_addr, result: host.execute_shell(cmd) }
|
47
47
|
end
|
@@ -83,6 +83,17 @@ module Kanrisuru
|
|
83
83
|
|
84
84
|
private
|
85
85
|
|
86
|
+
def create_command(command)
|
87
|
+
case command
|
88
|
+
when String
|
89
|
+
Kanrisuru::Command.new(command)
|
90
|
+
when Kanrisuru::Command
|
91
|
+
command.clone
|
92
|
+
else
|
93
|
+
raise ArgumentError, 'Invalid command type'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
86
97
|
def map_host_results(action)
|
87
98
|
@hosts.map do |host_addr, host|
|
88
99
|
{ host: host_addr, result: host.send(action) }
|
data/lib/kanrisuru/version.rb
CHANGED
@@ -64,12 +64,24 @@ RSpec.describe Kanrisuru::Core::Find do
|
|
64
64
|
mmin: '300'),
|
65
65
|
'find /var/log -atime +1 -ctime +2 -mtime +3 -amin 100 -cmin 200 -mmin 300')
|
66
66
|
|
67
|
+
expect_command(host.find(
|
68
|
+
paths: '/dev',
|
69
|
+
iname: 'tty*'
|
70
|
+
),
|
71
|
+
"find /dev -iname tty*")
|
72
|
+
|
67
73
|
expect_command(host.find(
|
68
74
|
paths: '/dev',
|
69
75
|
regex: '/dev/tty[0-9]*'
|
70
76
|
),
|
71
77
|
"find /dev -regex '/dev/tty[0-9]*'")
|
72
78
|
|
79
|
+
expect_command(host.find(
|
80
|
+
paths: '/dev',
|
81
|
+
iregex: '/dev/tty[0-9]*'
|
82
|
+
),
|
83
|
+
"find /dev -iregex '/dev/tty[0-9]*'")
|
84
|
+
|
73
85
|
expect_command(host.find(
|
74
86
|
paths: '/dev',
|
75
87
|
regex_type: 'posix-egrep',
|
@@ -40,6 +40,19 @@ RSpec.describe Kanrisuru::Remote::Cluster do
|
|
40
40
|
expect(cluster[host2.host]).to eq(host2)
|
41
41
|
expect(cluster.hosts).to include(host1)
|
42
42
|
expect(cluster.hosts).to include(host2)
|
43
|
+
|
44
|
+
cluster << {
|
45
|
+
host: 'centos-host',
|
46
|
+
username: 'centos',
|
47
|
+
keys: ['id_rsa']
|
48
|
+
}
|
49
|
+
|
50
|
+
expect(cluster.hosts.length).to eq(3)
|
51
|
+
expect(cluster.count).to eq(3)
|
52
|
+
expect(cluster.count).to eq(3)
|
53
|
+
expect(cluster['centos-host'].username).to eq('centos')
|
54
|
+
expect(cluster.hosts).to include(host1)
|
55
|
+
expect(cluster.hosts).to include(host2)
|
43
56
|
end
|
44
57
|
|
45
58
|
it 'fails to add host to a cluster' do
|
@@ -51,6 +64,62 @@ RSpec.describe Kanrisuru::Remote::Cluster do
|
|
51
64
|
expect(cluster.count).to eq(0)
|
52
65
|
end
|
53
66
|
|
67
|
+
it 'creates a new command instance' do
|
68
|
+
cluster = described_class.new
|
69
|
+
cluster << host1
|
70
|
+
cluster << host2
|
71
|
+
|
72
|
+
expect(cluster.send(:create_command, 'hello')).to be_instance_of(Kanrisuru::Command)
|
73
|
+
|
74
|
+
command = Kanrisuru::Command.new('ls')
|
75
|
+
command.remote_user = 'root'
|
76
|
+
command.remote_shell = '/bin/bash'
|
77
|
+
cloned_command = cluster.send(:create_command, command)
|
78
|
+
|
79
|
+
expect(cloned_command).to be_instance_of(Kanrisuru::Command)
|
80
|
+
expect(cloned_command.object_id).not_to eq(command.object_id)
|
81
|
+
|
82
|
+
expect(command.raw_command).to eq('ls')
|
83
|
+
expect(cloned_command.raw_command).to eq('ls')
|
84
|
+
|
85
|
+
expect(command.prepared_command).to eq('sudo -u root /bin/bash -c "ls"')
|
86
|
+
expect(cloned_command.prepared_command).to eq('sudo -u root /bin/bash -c "ls"')
|
87
|
+
|
88
|
+
expect {
|
89
|
+
cluster.send(:create_command, 1)
|
90
|
+
}.to raise_error(ArgumentError)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'runs execute for a command on a cluster' do
|
94
|
+
cluster = described_class.new
|
95
|
+
cluster << host1
|
96
|
+
cluster << host2
|
97
|
+
|
98
|
+
command = Kanrisuru::Command.new('pwd')
|
99
|
+
|
100
|
+
results = cluster.execute(command)
|
101
|
+
results.each do |result|
|
102
|
+
expect(result).to have_key(:host)
|
103
|
+
expect(result).to have_key(:result)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'runs execute_shell for a command on a cluster' do
|
108
|
+
cluster = described_class.new
|
109
|
+
cluster << host1
|
110
|
+
cluster << host2
|
111
|
+
|
112
|
+
command = Kanrisuru::Command.new('pwd')
|
113
|
+
command.remote_user = 'root'
|
114
|
+
command.remote_shell = '/bin/zsh'
|
115
|
+
|
116
|
+
results = cluster.execute_shell(command)
|
117
|
+
results.each do |result|
|
118
|
+
expect(result).to have_key(:host)
|
119
|
+
expect(result).to have_key(:result)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
54
123
|
it 'removes a host from a cluster' do
|
55
124
|
cluster = described_class.new(host1, host2)
|
56
125
|
expect(cluster.count).to eq(2)
|
@@ -63,4 +132,84 @@ RSpec.describe Kanrisuru::Remote::Cluster do
|
|
63
132
|
expect(cluster.count).to eq(0)
|
64
133
|
expect(cluster.hosts).not_to include(host1)
|
65
134
|
end
|
135
|
+
|
136
|
+
it 'fetches the hostname for each host in a cluster' do
|
137
|
+
allow_any_instance_of(Kanrisuru::Remote::Host).to receive(:hostname).and_return('ubuntu')
|
138
|
+
cluster = described_class.new(host1, host2)
|
139
|
+
|
140
|
+
results = cluster.hostname
|
141
|
+
results.each do |result|
|
142
|
+
expect(result).to have_key(:host)
|
143
|
+
expect(result).to have_key(:result)
|
144
|
+
expect(result[:result]).to eq('ubuntu')
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'pings the host for each host in a cluster' do
|
149
|
+
allow_any_instance_of(Kanrisuru::Remote::Host).to receive(:ping?).and_return(true)
|
150
|
+
cluster = described_class.new(host1, host2)
|
151
|
+
|
152
|
+
results = cluster.ping?
|
153
|
+
results.each do |result|
|
154
|
+
expect(result).to have_key(:host)
|
155
|
+
expect(result).to have_key(:result)
|
156
|
+
expect(result[:result]).to eq(true)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'switches user for each host in a cluster' do
|
161
|
+
cluster = described_class.new(host1, host2)
|
162
|
+
|
163
|
+
cluster.su('root')
|
164
|
+
cluster.each do |host|
|
165
|
+
expect(host.remote_user).to eq('root')
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'changes current working directory for each host in a cluster' do
|
170
|
+
cluster = described_class.new(host1, host2)
|
171
|
+
|
172
|
+
StubNetwork.stub_command!(:pwd) do
|
173
|
+
Kanrisuru::Core::Path::FilePath.new('/etc')
|
174
|
+
end
|
175
|
+
StubNetwork.stub_command!(:realpath) do
|
176
|
+
Kanrisuru::Core::Path::FilePath.new('/etc')
|
177
|
+
end
|
178
|
+
|
179
|
+
cluster.cd('/etc')
|
180
|
+
cluster.each do |host|
|
181
|
+
expect(host.instance_variable_get(:@current_dir)).to eq('/etc')
|
182
|
+
end
|
183
|
+
|
184
|
+
StubNetwork.unstub_command!(:pwd)
|
185
|
+
StubNetwork.unstub_command!(:realpath)
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'changes current working directory for each host in a cluster' do
|
189
|
+
cluster = described_class.new(host1, host2)
|
190
|
+
|
191
|
+
StubNetwork.stub_command!(:pwd) do
|
192
|
+
Kanrisuru::Core::Path::FilePath.new('/etc')
|
193
|
+
end
|
194
|
+
|
195
|
+
StubNetwork.stub_command!(:realpath) do
|
196
|
+
Kanrisuru::Core::Path::FilePath.new('/etc')
|
197
|
+
end
|
198
|
+
|
199
|
+
cluster.chdir('/etc')
|
200
|
+
cluster.each do |host|
|
201
|
+
expect(host.instance_variable_get(:@current_dir)).to eq('/etc')
|
202
|
+
end
|
203
|
+
|
204
|
+
StubNetwork.unstub_command!(:pwd)
|
205
|
+
StubNetwork.unstub_command!(:realpath)
|
206
|
+
end
|
207
|
+
|
208
|
+
it 'fails to remove a host from a cluster' do
|
209
|
+
cluster = described_class.new(host1, host2)
|
210
|
+
|
211
|
+
expect {
|
212
|
+
cluster.delete(1)
|
213
|
+
}.to raise_error(ArgumentError)
|
214
|
+
end
|
66
215
|
end
|
@@ -2,8 +2,24 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
RSpec.shared_examples 'cluster' do |os_name,
|
5
|
+
RSpec.shared_examples 'cluster' do |os_name, host_json, spec_dir|
|
6
6
|
context "with #{os_name}" do
|
7
|
+
let(:host1) do
|
8
|
+
Kanrisuru::Remote::Host.new(
|
9
|
+
host: host_json['hostname'],
|
10
|
+
username: host_json['username'],
|
11
|
+
keys: [host_json['ssh_key']]
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:host2) do
|
16
|
+
Kanrisuru::Remote::Host.new(
|
17
|
+
host: 'localhost',
|
18
|
+
username: 'ubuntu',
|
19
|
+
keys: ['~/.ssh/id_rsa']
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
7
23
|
it 'gets hostname for cluster' do
|
8
24
|
cluster = described_class.new({
|
9
25
|
host: 'localhost',
|
@@ -41,5 +57,14 @@ RSpec.shared_examples 'cluster' do |os_name, _host_json, _spec_dir|
|
|
41
57
|
|
42
58
|
cluster.disconnect
|
43
59
|
end
|
60
|
+
|
61
|
+
it 'disconnects all hosts' do
|
62
|
+
cluster = described_class.new(host1, host2)
|
63
|
+
cluster.disconnect
|
64
|
+
|
65
|
+
cluster.each do |host|
|
66
|
+
expect(host.ssh.closed).to be_truthy
|
67
|
+
end
|
68
|
+
end
|
44
69
|
end
|
45
70
|
end
|
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.16.
|
4
|
+
version: 0.16.11
|
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-
|
11
|
+
date: 2021-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parallel_tests
|