weave 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  Vagrant::Config.run do |config|
2
2
  def apply_common_config_options(c)
3
- c.vm.box = "lucid64"
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
@@ -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 command.
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] ||= DEFAULT_THREAD_POOL_SIZE
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, options[:num_threads]) do |host, mutex|
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
- Weave.with_thread_pool(host_list, options[:num_threads]) do |host, mutex|
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
@@ -1,3 +1,3 @@
1
1
  module Weave
2
- VERSION = "0.2.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -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
- class SanityTest < Scope::TestCase
7
- TEST_HOSTS = [1, 2].map { |i| "weave#{i}" }
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
- setup_once do
12
- # Make sure the machines are up.
13
- vagrant_status = `/usr/bin/vagrant status`
14
- unless $?.to_i.zero? && TEST_HOSTS.each { |host| vagrant_status =~ /#{host}\w+running/ }
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
- config = Net::SSH::Config.load("~/.ssh/config", host)
21
- unless config["hostname"] == "127.0.0.1"
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
- context "executing some commands" do
29
- should "run some simple commands" do
30
- output = Hash.new { |h, k| h[k] = [] }
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
- should "raise an exception when a command exits with non-zero exit status." do
41
- assert_raises(Weave::Error) do
42
- Weave.connect(SINGLE_TEST_HOST) { run("cd noexist", :output => :capture) }
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
- context "in serial" do
53
- should "run some commands in the expected order" do
54
- output = ""
55
- Weave.connect(ROOT_AT_TEST_HOSTS, :serial => true) do
56
- command = (host == "weave1") ? "sleep 0.2; echo 'delayed'" : "echo 'on time'"
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
- context "in parallel" do
64
- should "run some commands in the expected order" do
65
- output = ""
66
- Weave.connect(ROOT_AT_TEST_HOSTS) do
67
- command = (host == "weave1") ? "sleep 0.2; echo 'delayed'" : "echo 'on time'"
68
- result = run(command, :output => :capture)
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
- context "on a connection pool" do
76
- should "run basic commands" do
77
- output = Hash.new { |h, k| h[k] = [] }
78
- Weave.connect(ROOT_AT_TEST_HOSTS).execute do
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
- context "with a different host list" do
89
- should "run only on the listed hosts" do
90
- output = ""
91
- Weave::ConnectionPool.new.execute_with(SINGLE_TEST_HOST) do
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
@@ -1,4 +1,3 @@
1
1
  $:.unshift File.join(File.dirname(__FILE__), "../lib")
2
2
 
3
- require "scope"
4
3
  require "minitest/autorun"
@@ -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 "scope"
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.2.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-05-31 00:00:00.000000000 Z
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: scope
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: 2.0.0
135
+ rubygems_version: 1.8.23
124
136
  signing_key:
125
- specification_version: 4
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