weave 0.2.0 → 1.0.0
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.
- data/Vagrantfile +2 -1
- data/lib/weave.rb +7 -5
- data/lib/weave/version.rb +1 -1
- data/test/integrations/sanity_test.rb +61 -72
- data/test/test_helper.rb +0 -1
- data/weave.gemspec +1 -1
- metadata +30 -18
- checksums.yaml +0 -7
data/Vagrantfile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
Vagrant::Config.run do |config|
|
2
2
|
def apply_common_config_options(c)
|
3
|
-
c.vm.box = "
|
3
|
+
c.vm.box = "precise64"
|
4
|
+
c.vm.box_url = "http://files.vagrantup.com/precise64.box"
|
4
5
|
c.vm.provision :shell, :inline =>
|
5
6
|
"sudo mkdir -p /root/.ssh && sudo cp /home/vagrant/.ssh/authorized_keys /root/.ssh/"
|
6
7
|
end
|
data/lib/weave.rb
CHANGED
@@ -69,8 +69,8 @@ module Weave
|
|
69
69
|
#
|
70
70
|
# @param [Hash] options the various knobs
|
71
71
|
# @option options [Array] :args the arguments to pass through to the block when it runs.
|
72
|
-
# @option options [Fixnum] :num_threads the number of concurrent threads to use to process this
|
73
|
-
# Defaults to `DEFAULT_THREAD_POOL_SIZE`.
|
72
|
+
# @option options [Fixnum or Symbol] :num_threads the number of concurrent threads to use to process this
|
73
|
+
# command, or :unlimited to use a thread for every host. Defaults to `DEFAULT_THREAD_POOL_SIZE`.
|
74
74
|
# @option options [Boolean] :serial whether to process the command for each connection one at a time.
|
75
75
|
# @option options [Fixnum] :batch_by if set, group the connections into batches of no more than this value
|
76
76
|
# and fully process each batch before starting the next one.
|
@@ -83,17 +83,19 @@ module Weave
|
|
83
83
|
def execute_with(host_list, options = {}, &block)
|
84
84
|
host_list.each { |host| @connections[host] ||= LazyConnection.new(host) }
|
85
85
|
args = options[:args] || []
|
86
|
-
options[:num_threads]
|
86
|
+
num_threads = options[:num_threads] || DEFAULT_THREAD_POOL_SIZE
|
87
87
|
if options[:serial]
|
88
88
|
host_list.each { |host| @connections[host].self_eval args, &block }
|
89
89
|
elsif options[:batch_by]
|
90
|
+
num_threads = options[:batch_by] if num_threads == :unlimited
|
90
91
|
host_list.each_slice(options[:batch_by]) do |batch|
|
91
|
-
Weave.with_thread_pool(batch,
|
92
|
+
Weave.with_thread_pool(batch, num_threads) do |host, mutex|
|
92
93
|
@connections[host].self_eval args, mutex, &block
|
93
94
|
end
|
94
95
|
end
|
95
96
|
else
|
96
|
-
|
97
|
+
num_threads = host_list.size if num_threads == :unlimited
|
98
|
+
Weave.with_thread_pool(host_list, num_threads) do |host, mutex|
|
97
99
|
@connections[host].self_eval args, mutex, &block
|
98
100
|
end
|
99
101
|
end
|
data/lib/weave/version.rb
CHANGED
@@ -3,96 +3,85 @@ require File.expand_path(File.join(File.dirname(__FILE__), "../test_helper"))
|
|
3
3
|
require "net/ssh"
|
4
4
|
require "weave"
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
TEST_HOSTS = [1, 2].map { |i| "weave#{i}" }
|
7
|
+
|
8
|
+
# Make sure the machines are up.
|
9
|
+
vagrant_status = `vagrant status`
|
10
|
+
unless $?.to_i.zero? && TEST_HOSTS.each { |host| vagrant_status =~ /#{host}\w+running/ }
|
11
|
+
abort "You need to set up the test vagrant virtual machines to run the sanity test." \
|
12
|
+
"Run 'vagrant up'."
|
13
|
+
end
|
14
|
+
# Make sure the user's ssh config has weave entries.
|
15
|
+
TEST_HOSTS.each do |host|
|
16
|
+
config = Net::SSH::Config.load("~/.ssh/config", host)
|
17
|
+
unless config["hostname"] == "127.0.0.1"
|
18
|
+
abort "You need to add weave{1,2} to your ~/.ssh/config." \
|
19
|
+
"You can use the output of 'vagrant ssh-config weave1'"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class SanityTest < Minitest::Test
|
8
24
|
ROOT_AT_TEST_HOSTS = TEST_HOSTS.map { |host| "root@#{host}" }
|
9
25
|
SINGLE_TEST_HOST = ["root@#{TEST_HOSTS[0]}"]
|
10
26
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
abort "You need to set up the test vagrant virtual machines to run the sanity test." \
|
16
|
-
"Run 'vagrant up'."
|
27
|
+
def test_executing_commands_simple
|
28
|
+
output = Hash.new { |h, k| h[k] = [] }
|
29
|
+
Weave.connect(ROOT_AT_TEST_HOSTS) do
|
30
|
+
output[host] = run("echo 'hello'", :output => :capture)
|
17
31
|
end
|
18
|
-
# Make sure the user's ssh config has weave entries.
|
19
32
|
TEST_HOSTS.each do |host|
|
20
|
-
|
21
|
-
|
22
|
-
abort "You need to add weave{1,2} to your ~/.ssh/config." \
|
23
|
-
"You can use the output of 'vagrant ssh-config weave1'"
|
24
|
-
end
|
33
|
+
assert_empty output[host][:stderr]
|
34
|
+
assert_equal "hello\n", output[host][:stdout]
|
25
35
|
end
|
26
36
|
end
|
27
37
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
Weave.connect(ROOT_AT_TEST_HOSTS) do
|
32
|
-
output[host] = run("echo 'hello'", :output => :capture)
|
33
|
-
end
|
34
|
-
TEST_HOSTS.each do |host|
|
35
|
-
assert_empty output[host][:stderr]
|
36
|
-
assert_equal "hello\n", output[host][:stdout]
|
37
|
-
end
|
38
|
+
def test_executing_commands_raises_exception_with_non_zero_exit
|
39
|
+
assert_raises(Weave::Error) do
|
40
|
+
Weave.connect(SINGLE_TEST_HOST) { run("cd noexist", :output => :capture) }
|
38
41
|
end
|
39
42
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
results = {}
|
46
|
-
Weave.connect(SINGLE_TEST_HOST) do
|
47
|
-
results = run("exit 123", :output => :capture, :continue_on_failure => true)
|
48
|
-
end
|
49
|
-
assert_equal 123, results[:exit_code]
|
43
|
+
results = {}
|
44
|
+
Weave.connect(SINGLE_TEST_HOST) do
|
45
|
+
results = run("exit 123", :output => :capture, :continue_on_failure => true)
|
50
46
|
end
|
47
|
+
assert_equal 123, results[:exit_code]
|
48
|
+
end
|
51
49
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
output += run(command, :output => :capture)[:stdout]
|
58
|
-
end
|
59
|
-
assert_equal "delayed\non time\n", output
|
60
|
-
end
|
50
|
+
def test_in_serial_commands_run_in_expected_order
|
51
|
+
output = ""
|
52
|
+
Weave.connect(ROOT_AT_TEST_HOSTS, :serial => true) do
|
53
|
+
command = (host == "weave1") ? "sleep 0.2; echo 'delayed'" : "echo 'on time'"
|
54
|
+
output += run(command, :output => :capture)[:stdout]
|
61
55
|
end
|
56
|
+
assert_equal "delayed\non time\n", output
|
57
|
+
end
|
62
58
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
output += result[:stdout]
|
70
|
-
end
|
71
|
-
assert_equal "on time\ndelayed\n", output
|
72
|
-
end
|
59
|
+
def test_in_parallel_commands_run_in_expected_order
|
60
|
+
output = ""
|
61
|
+
Weave.connect(ROOT_AT_TEST_HOSTS) do
|
62
|
+
command = (host == "weave1") ? "sleep 0.2; echo 'delayed'" : "echo 'on time'"
|
63
|
+
result = run(command, :output => :capture)
|
64
|
+
output += result[:stdout]
|
73
65
|
end
|
66
|
+
assert_equal "on time\ndelayed\n", output
|
67
|
+
end
|
74
68
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
output[host] = run("echo 'hello'", :output => :capture)
|
80
|
-
end
|
81
|
-
TEST_HOSTS.each do |host|
|
82
|
-
assert_empty output[host][:stderr]
|
83
|
-
assert_equal "hello\n", output[host][:stdout]
|
84
|
-
end
|
85
|
-
end
|
69
|
+
def test_on_a_connection_pool_basic_commands_should_run
|
70
|
+
output = Hash.new { |h, k| h[k] = [] }
|
71
|
+
Weave.connect(ROOT_AT_TEST_HOSTS).execute do
|
72
|
+
output[host] = run("echo 'hello'", :output => :capture)
|
86
73
|
end
|
74
|
+
TEST_HOSTS.each do |host|
|
75
|
+
assert_empty output[host][:stderr]
|
76
|
+
assert_equal "hello\n", output[host][:stdout]
|
77
|
+
end
|
78
|
+
end
|
87
79
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
output += run("echo 'hello'", :output => :capture)[:stdout]
|
93
|
-
end
|
94
|
-
assert_equal "hello\n", output
|
95
|
-
end
|
80
|
+
def test_with_a_different_host_list_only_run_on_listed_hosts
|
81
|
+
output = ""
|
82
|
+
Weave::ConnectionPool.new.execute_with(SINGLE_TEST_HOST) do
|
83
|
+
output += run("echo 'hello'", :output => :capture)[:stdout]
|
96
84
|
end
|
85
|
+
assert_equal "hello\n", output
|
97
86
|
end
|
98
87
|
end
|
data/test/test_helper.rb
CHANGED
data/weave.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.add_dependency "net-ssh", ">= 2.2.0"
|
19
19
|
|
20
20
|
# For running integration tests.
|
21
|
-
gem.add_development_dependency "
|
21
|
+
gem.add_development_dependency "minitest"
|
22
22
|
gem.add_development_dependency "rake"
|
23
23
|
# For generating the docs
|
24
24
|
gem.add_development_dependency "yard"
|
metadata
CHANGED
@@ -1,83 +1,94 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weave
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Caleb Spare
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2013-
|
12
|
+
date: 2013-09-27 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: net-ssh
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
|
-
- - '>='
|
19
|
+
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: 2.2.0
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
|
-
- - '>='
|
27
|
+
- - ! '>='
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 2.2.0
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
31
|
+
name: minitest
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
|
-
- - '>='
|
35
|
+
- - ! '>='
|
32
36
|
- !ruby/object:Gem::Version
|
33
37
|
version: '0'
|
34
38
|
type: :development
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
|
-
- - '>='
|
43
|
+
- - ! '>='
|
39
44
|
- !ruby/object:Gem::Version
|
40
45
|
version: '0'
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: rake
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
|
-
- - '>='
|
51
|
+
- - ! '>='
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: '0'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
|
-
- - '>='
|
59
|
+
- - ! '>='
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: '0'
|
55
62
|
- !ruby/object:Gem::Dependency
|
56
63
|
name: yard
|
57
64
|
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
58
66
|
requirements:
|
59
|
-
- - '>='
|
67
|
+
- - ! '>='
|
60
68
|
- !ruby/object:Gem::Version
|
61
69
|
version: '0'
|
62
70
|
type: :development
|
63
71
|
prerelease: false
|
64
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
65
74
|
requirements:
|
66
|
-
- - '>='
|
75
|
+
- - ! '>='
|
67
76
|
- !ruby/object:Gem::Version
|
68
77
|
version: '0'
|
69
78
|
- !ruby/object:Gem::Dependency
|
70
79
|
name: redcarpet
|
71
80
|
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
72
82
|
requirements:
|
73
|
-
- - '>='
|
83
|
+
- - ! '>='
|
74
84
|
- !ruby/object:Gem::Version
|
75
85
|
version: '0'
|
76
86
|
type: :development
|
77
87
|
prerelease: false
|
78
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
79
90
|
requirements:
|
80
|
-
- - '>='
|
91
|
+
- - ! '>='
|
81
92
|
- !ruby/object:Gem::Version
|
82
93
|
version: '0'
|
83
94
|
description: Simple parallel ssh.
|
@@ -103,26 +114,27 @@ files:
|
|
103
114
|
- weave.gemspec
|
104
115
|
homepage: https://github.com/cespare/weave
|
105
116
|
licenses: []
|
106
|
-
metadata: {}
|
107
117
|
post_install_message:
|
108
118
|
rdoc_options: []
|
109
119
|
require_paths:
|
110
120
|
- lib
|
111
121
|
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
112
123
|
requirements:
|
113
|
-
- - '>='
|
124
|
+
- - ! '>='
|
114
125
|
- !ruby/object:Gem::Version
|
115
126
|
version: '0'
|
116
127
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
117
129
|
requirements:
|
118
|
-
- - '>='
|
130
|
+
- - ! '>='
|
119
131
|
- !ruby/object:Gem::Version
|
120
132
|
version: '0'
|
121
133
|
requirements: []
|
122
134
|
rubyforge_project:
|
123
|
-
rubygems_version:
|
135
|
+
rubygems_version: 1.8.23
|
124
136
|
signing_key:
|
125
|
-
specification_version:
|
137
|
+
specification_version: 3
|
126
138
|
summary: Simple parallel ssh.
|
127
139
|
test_files:
|
128
140
|
- test/integrations/sanity_test.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: a59144545dbba7f902dae6c32554a3f2743861e1
|
4
|
-
data.tar.gz: 495f658b7d46a8dd442e299f1b2e6b5f18974238
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: ca9f0be174aa7bae005d03c9937944539e1826c680dda6cf6c8fdc5fcf3d36abefb4649ee3344d65d6b5a585f093fee8dee017c3112a3f704d4e87e9feb7db6e
|
7
|
-
data.tar.gz: 226c169a961c1cb2f40238c10be1ce68ce881d3bc1d67e447e9c32785b3f46317e0721d34dfc33bd17e0871904defee92fb1c170bb2a8bfb56151a377fbae4c6
|