kanrisuru 0.16.9 → 0.16.13
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/LICENSE.txt +1 -1
- data/README.md +108 -32
- data/lib/kanrisuru/command.rb +1 -0
- data/lib/kanrisuru/core/find/commands/find.rb +3 -1
- data/lib/kanrisuru/core/group/commands/create_group.rb +2 -0
- data/lib/kanrisuru/remote/cluster.rb +13 -2
- data/lib/kanrisuru/version.rb +1 -1
- data/lib/kanrisuru.rb +1 -1
- data/spec/functional/core/find_spec.rb +12 -0
- data/spec/functional/core/group_spec.rb +8 -1
- data/spec/functional/remote/cluster_spec.rb +149 -0
- data/spec/support/shared_examples/integration/remote/cluster.rb +26 -1
- data/spec/unit/kanrisuru_spec.rb +4 -0
- 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: 247c662cf0cedccfd41d702e372cc536958fbfd16c583643201e13e528c3c049
|
4
|
+
data.tar.gz: 8d6256b6b5dfcf84793851432e0dfedfd352222bebb04bc530bb15bc9cdcd0d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31bde2ec4894d4e6962ff99b438b67502687446918d59180693d11275e25944c1af1e22ad923e799c4208e7fff62ad93e9867082765b956d213b12eb5a950092
|
7
|
+
data.tar.gz: b69992182e95c7f3cf3061cd4f25d875ff6095ee7e18580a39f24a6be8c6978401d9023e55be01bbb0aac92b74ec904a016abdf60a4302c9fc1cfdd32df276b2
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## Kanrisuru 0.16.13 (January 01, 2022) ##
|
2
|
+
* Add `non_unique` and `system` opts to `create_group` command
|
3
|
+
|
4
|
+
## Kanrisuru 0.16.12 (January 01, 2022) ##
|
5
|
+
* Update date ranges for 2022 on license files.
|
6
|
+
* Add unit test case for `Kanrisuru::Logger`.
|
7
|
+
|
8
|
+
## Kanrisuru 0.16.11 (December 28, 2021) ##
|
9
|
+
* Add functional and integration test cases for the `Kanrisuru::Remote::Cluster` class.
|
10
|
+
* Allow for passing a command instance into `execute` and `execute_shell` on a cluster instance, by deep copying a command object.
|
11
|
+
|
12
|
+
## Kanrisuru 0.16.10 (December 28, 2021) ##
|
13
|
+
* Add `iname` and `iregex` params to `find` command.
|
14
|
+
|
1
15
|
## Kanrisuru 0.16.9 (December 27, 2021) ##
|
2
16
|
* Use cp intead of mv for recurisive dir overwrite on upload command.
|
3
17
|
|
data/LICENSE.txt
CHANGED
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
@@ -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])*$/)
|
@@ -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
data/lib/kanrisuru.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',
|
@@ -21,7 +21,14 @@ RSpec.describe Kanrisuru::Core::Group do
|
|
21
21
|
|
22
22
|
it 'prepares create_group command' do
|
23
23
|
expect_command(host.create_group('admin'), 'groupadd admin')
|
24
|
-
expect_command(host.create_group('admin',
|
24
|
+
expect_command(host.create_group('admin',
|
25
|
+
gid: 9000,
|
26
|
+
non_unique: true
|
27
|
+
),
|
28
|
+
'groupadd admin -g 9000 -o'
|
29
|
+
)
|
30
|
+
|
31
|
+
expect_command(host.create_group('admin', gid: 12, system: true), 'groupadd admin -g 12 -r')
|
25
32
|
end
|
26
33
|
|
27
34
|
it 'prepares delete_group command' do
|
@@ -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
|
data/spec/unit/kanrisuru_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.16.
|
4
|
+
version: 0.16.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Mammina
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parallel_tests
|