net-ssh-multi 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +13 -0
- data/Manifest +23 -0
- data/README.rdoc +87 -0
- data/Rakefile +28 -0
- data/lib/net/ssh/multi.rb +71 -0
- data/lib/net/ssh/multi/channel.rb +216 -0
- data/lib/net/ssh/multi/channel_proxy.rb +50 -0
- data/lib/net/ssh/multi/dynamic_server.rb +71 -0
- data/lib/net/ssh/multi/pending_connection.rb +112 -0
- data/lib/net/ssh/multi/server.rb +229 -0
- data/lib/net/ssh/multi/server_list.rb +80 -0
- data/lib/net/ssh/multi/session.rb +546 -0
- data/lib/net/ssh/multi/session_actions.rb +153 -0
- data/lib/net/ssh/multi/subsession.rb +48 -0
- data/lib/net/ssh/multi/version.rb +21 -0
- data/net-ssh-multi.gemspec +59 -0
- data/setup.rb +1585 -0
- data/test/channel_test.rb +152 -0
- data/test/common.rb +2 -0
- data/test/multi_test.rb +20 -0
- data/test/server_test.rb +256 -0
- data/test/session_actions_test.rb +128 -0
- data/test/session_test.rb +201 -0
- data/test/test_all.rb +3 -0
- metadata +93 -0
@@ -0,0 +1,201 @@
|
|
1
|
+
require 'common'
|
2
|
+
require 'net/ssh/multi/session'
|
3
|
+
|
4
|
+
class SessionTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@session = Net::SSH::Multi::Session.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_group_should_fail_when_given_both_mapping_and_block
|
10
|
+
assert_raises(ArgumentError) do
|
11
|
+
@session.group(:app => mock('server')) { |s| }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_group_with_block_should_use_groups_within_block_and_restore_on_exit
|
16
|
+
@session.open_groups.concat([:first, :second])
|
17
|
+
assert_equal [:first, :second], @session.open_groups
|
18
|
+
yielded = nil
|
19
|
+
@session.group(:third, :fourth) do |s|
|
20
|
+
yielded = s
|
21
|
+
assert_equal [:first, :second, :third, :fourth], @session.open_groups
|
22
|
+
end
|
23
|
+
assert_equal [:first, :second], @session.open_groups
|
24
|
+
assert_equal @session, yielded
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_group_with_mapping_should_append_new_servers_to_specified_and_open_groups
|
28
|
+
s1, s2, s3, s4 = @session.use('h1', 'h2', 'h3', 'h4')
|
29
|
+
@session.group :second => s1
|
30
|
+
@session.open_groups.concat([:first, :second])
|
31
|
+
@session.group %w(third fourth) => [s2, s3], :fifth => s1, :sixth => [s4]
|
32
|
+
assert_equal [s1, s2, s3, s4], @session.groups[:first].sort
|
33
|
+
assert_equal [s1, s2, s3, s4], @session.groups[:second].sort
|
34
|
+
assert_equal [s2, s3], @session.groups[:third].sort
|
35
|
+
assert_equal [s2, s3], @session.groups[:fourth].sort
|
36
|
+
assert_equal [s1], @session.groups[:fifth].sort
|
37
|
+
assert_equal [s4], @session.groups[:sixth].sort
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_via_should_instantiate_and_set_default_gateway
|
41
|
+
Net::SSH::Gateway.expects(:new).with('host', 'user', :a => :b).returns(:gateway)
|
42
|
+
assert_equal @session, @session.via('host', 'user', :a => :b)
|
43
|
+
assert_equal :gateway, @session.default_gateway
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_use_should_add_new_server_to_server_list
|
47
|
+
@session.open_groups.concat([:first, :second])
|
48
|
+
server = @session.use('user@host', :a => :b)
|
49
|
+
assert_equal [server], @session.servers
|
50
|
+
assert_equal 'host', server.host
|
51
|
+
assert_equal 'user', server.user
|
52
|
+
assert_equal({:a => :b}, server.options)
|
53
|
+
assert_nil server.gateway
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_use_with_open_groups_should_add_new_server_to_server_list_and_groups
|
57
|
+
@session.open_groups.concat([:first, :second])
|
58
|
+
server = @session.use('host')
|
59
|
+
assert_equal [server], @session.groups[:first].sort
|
60
|
+
assert_equal [server], @session.groups[:second].sort
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_use_with_default_gateway_should_set_gateway_on_server
|
64
|
+
Net::SSH::Gateway.expects(:new).with('host', 'user', {}).returns(:gateway)
|
65
|
+
@session.via('host', 'user')
|
66
|
+
server = @session.use('host2')
|
67
|
+
assert_equal :gateway, server.gateway
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_use_with_duplicate_server_will_not_add_server_twice
|
71
|
+
s1, s2 = @session.use('host', 'host')
|
72
|
+
assert_equal 1, @session.servers.length
|
73
|
+
assert_equal s1.object_id, s2.object_id
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_with_should_yield_new_subsession_with_servers_for_criteria
|
77
|
+
yielded = nil
|
78
|
+
@session.expects(:servers_for).with(:app, :web).returns([:servers])
|
79
|
+
result = @session.with(:app, :web) do |s|
|
80
|
+
yielded = s
|
81
|
+
end
|
82
|
+
assert_equal result, yielded
|
83
|
+
assert_equal [:servers], yielded.servers
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_servers_for_with_unknown_constraint_should_raise_error
|
87
|
+
assert_raises(ArgumentError) do
|
88
|
+
@session.servers_for(:app => { :all => :foo })
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_with_with_constraints_should_build_subsession_with_matching_servers
|
93
|
+
conditions = { :app => { :only => { :primary => true }, :except => { :backup => true } } }
|
94
|
+
@session.expects(:servers_for).with(conditions).returns([:servers])
|
95
|
+
assert_equal [:servers], @session.with(conditions).servers
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_on_should_return_subsession_containing_only_the_given_servers
|
99
|
+
s1, s2 = @session.use('h1', 'h2')
|
100
|
+
subsession = @session.on(s1, s2)
|
101
|
+
assert_equal [s1, s2], subsession.servers
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_on_should_yield_subsession_if_block_is_given
|
105
|
+
s1 = @session.use('h1')
|
106
|
+
yielded = nil
|
107
|
+
result = @session.on(s1) do |s|
|
108
|
+
yielded = s
|
109
|
+
assert_equal [s1], s.servers
|
110
|
+
end
|
111
|
+
assert_equal result, yielded
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_servers_for_should_return_all_servers_if_no_arguments
|
115
|
+
srv1, srv2, srv3 = @session.use('h1', 'h2', 'h3')
|
116
|
+
assert_equal [srv1, srv2, srv3], @session.servers_for.sort
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_servers_for_should_return_servers_only_for_given_group
|
120
|
+
srv1, srv2, srv3 = @session.use('h1', 'h2', 'h3')
|
121
|
+
@session.group :app => [srv1, srv2], :db => [srv3]
|
122
|
+
assert_equal [srv1, srv2], @session.servers_for(:app).sort
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_servers_for_should_not_return_duplicate_servers
|
126
|
+
srv1, srv2, srv3 = @session.use('h1', 'h2', 'h3')
|
127
|
+
@session.group :app => [srv1, srv2], :db => [srv2, srv3]
|
128
|
+
assert_equal [srv1, srv2, srv3], @session.servers_for(:app, :db).sort
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_servers_for_should_correctly_apply_only_and_except_constraints
|
132
|
+
srv1, srv2, srv3 = @session.use('h1', :properties => {:a => 1}), @session.use('h2', :properties => {:a => 1, :b => 2}), @session.use('h3')
|
133
|
+
@session.group :app => [srv1, srv2, srv3]
|
134
|
+
assert_equal [srv1], @session.servers_for(:app => {:only => {:a => 1}, :except => {:b => 2}})
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_close_should_close_server_sessions
|
138
|
+
srv1, srv2 = @session.use('h1', 'h2')
|
139
|
+
srv1.expects(:close_channels)
|
140
|
+
srv2.expects(:close_channels)
|
141
|
+
srv1.expects(:close)
|
142
|
+
srv2.expects(:close)
|
143
|
+
@session.close
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_close_should_shutdown_default_gateway
|
147
|
+
gateway = mock('gateway')
|
148
|
+
gateway.expects(:shutdown!)
|
149
|
+
Net::SSH::Gateway.expects(:new).returns(gateway)
|
150
|
+
@session.via('host', 'user')
|
151
|
+
@session.close
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_loop_should_loop_until_process_is_false
|
155
|
+
@session.expects(:process).with(5).times(4).returns(true,true,true,false).yields
|
156
|
+
yielded = false
|
157
|
+
@session.loop(5) { yielded = true }
|
158
|
+
assert yielded
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_preprocess_should_immediately_return_false_if_block_returns_false
|
162
|
+
srv = @session.use('h1')
|
163
|
+
srv.expects(:preprocess).never
|
164
|
+
assert_equal false, @session.preprocess { false }
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_preprocess_should_call_preprocess_on_component_servers
|
168
|
+
srv = @session.use('h1')
|
169
|
+
srv.expects(:preprocess)
|
170
|
+
assert_equal :hello, @session.preprocess { :hello }
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_preprocess_should_succeed_even_without_block
|
174
|
+
srv = @session.use('h1')
|
175
|
+
srv.expects(:preprocess)
|
176
|
+
assert_equal true, @session.preprocess
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_postprocess_should_call_postprocess_on_component_servers
|
180
|
+
srv = @session.use('h1')
|
181
|
+
srv.expects(:postprocess).with([:a], [:b])
|
182
|
+
assert_equal true, @session.postprocess([:a], [:b])
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_process_should_return_false_if_preprocess_returns_false
|
186
|
+
assert_equal false, @session.process { false }
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_process_should_call_select_on_combined_readers_and_writers_from_all_servers
|
190
|
+
@session.expects(:postprocess).with([:b, :c], [:a, :c])
|
191
|
+
srv1, srv2, srv3 = @session.use('h1', 'h2', 'h3')
|
192
|
+
srv1.expects(:readers).returns([:a])
|
193
|
+
srv1.expects(:writers).returns([:a])
|
194
|
+
srv2.expects(:readers).returns([])
|
195
|
+
srv2.expects(:writers).returns([])
|
196
|
+
srv3.expects(:readers).returns([:b, :c])
|
197
|
+
srv3.expects(:writers).returns([:c])
|
198
|
+
IO.expects(:select).with([:a, :b, :c], [:a, :c], nil, 5).returns([[:b, :c], [:a, :c]])
|
199
|
+
@session.process(5)
|
200
|
+
end
|
201
|
+
end
|
data/test/test_all.rb
ADDED
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: net-ssh-multi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jamis Buck
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-05-01 00:00:00 -06:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: net-ssh
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.99.2
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: net-ssh-gateway
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 0.99.0
|
32
|
+
version:
|
33
|
+
description: Control multiple Net::SSH connections via a single interface
|
34
|
+
email: jamis@jamisbuck.org
|
35
|
+
executables: []
|
36
|
+
|
37
|
+
extensions: []
|
38
|
+
|
39
|
+
extra_rdoc_files: []
|
40
|
+
|
41
|
+
files:
|
42
|
+
- CHANGELOG.rdoc
|
43
|
+
- lib/net/ssh/multi/channel.rb
|
44
|
+
- lib/net/ssh/multi/channel_proxy.rb
|
45
|
+
- lib/net/ssh/multi/dynamic_server.rb
|
46
|
+
- lib/net/ssh/multi/pending_connection.rb
|
47
|
+
- lib/net/ssh/multi/server.rb
|
48
|
+
- lib/net/ssh/multi/server_list.rb
|
49
|
+
- lib/net/ssh/multi/session.rb
|
50
|
+
- lib/net/ssh/multi/session_actions.rb
|
51
|
+
- lib/net/ssh/multi/subsession.rb
|
52
|
+
- lib/net/ssh/multi/version.rb
|
53
|
+
- lib/net/ssh/multi.rb
|
54
|
+
- Manifest
|
55
|
+
- Rakefile
|
56
|
+
- README.rdoc
|
57
|
+
- setup.rb
|
58
|
+
- test/channel_test.rb
|
59
|
+
- test/common.rb
|
60
|
+
- test/multi_test.rb
|
61
|
+
- test/server_test.rb
|
62
|
+
- test/session_actions_test.rb
|
63
|
+
- test/session_test.rb
|
64
|
+
- test/test_all.rb
|
65
|
+
- net-ssh-multi.gemspec
|
66
|
+
has_rdoc: true
|
67
|
+
homepage: http://net-ssh.rubyforge.org/multi
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
version:
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project: net-ssh-multi
|
88
|
+
rubygems_version: 1.1.1
|
89
|
+
signing_key:
|
90
|
+
specification_version: 2
|
91
|
+
summary: Control multiple Net::SSH connections via a single interface
|
92
|
+
test_files:
|
93
|
+
- test/test_all.rb
|