kanrisuru 0.16.10 → 0.16.11
Sign up to get free protection for your applications and to get access to all the features.
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,7 @@
|
|
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
|
+
|
1
5
|
## Kanrisuru 0.16.10 (December 28, 2021) ##
|
2
6
|
* Add `iname` and `iregex` params to `find` command.
|
3
7
|
|
data/lib/kanrisuru/command.rb
CHANGED
@@ -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
@@ -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
|