big_brother 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/big_brother.rb CHANGED
@@ -35,7 +35,6 @@ module BigBrother
35
35
  def self.configure(filename)
36
36
  @config_file = filename
37
37
  @clusters = BigBrother::Configuration.evaluate(filename)
38
- BigBrother::Configuration.synchronize_with_ipvs(@clusters, BigBrother.ipvs.running_configuration)
39
38
  end
40
39
 
41
40
  def self.start_ticker!
@@ -5,9 +5,11 @@ module BigBrother
5
5
  set :raise_errors, false
6
6
 
7
7
  get "/" do
8
- BigBrother.clusters.map do |name, cluster|
8
+ clusters = BigBrother.clusters.map do |name, cluster|
9
9
  "#{cluster}: #{cluster.monitored? ? "running" : "not running"}"
10
- end.join("\n") + "\n"
10
+ end.join("\n")
11
+
12
+ [200, "Big Brother: #{BigBrother::VERSION}\n\n#{clusters}\n"]
11
13
  end
12
14
 
13
15
  before "/cluster/:name" do |name|
@@ -16,10 +18,12 @@ module BigBrother
16
18
  end
17
19
 
18
20
  get "/cluster/:name" do |name|
21
+ @cluster.synchronize! unless @cluster.monitored?
19
22
  [200, "Running: #{@cluster.monitored?}"]
20
23
  end
21
24
 
22
25
  put "/cluster/:name" do |name|
26
+ @cluster.synchronize!
23
27
  halt 304 if @cluster.monitored?
24
28
  @cluster.start_monitoring!
25
29
  [200, "OK"]
@@ -41,14 +41,27 @@ module BigBrother
41
41
  @monitored = true
42
42
  end
43
43
 
44
+ def synchronize!
45
+ ipvs_state = BigBrother.ipvs.running_configuration
46
+ if ipvs_state.has_key?(fwmark.to_s)
47
+ resume_monitoring!
48
+
49
+ running_nodes = ipvs_state[fwmark.to_s]
50
+ cluster_nodes = nodes.map(&:address)
51
+
52
+ _remove_nodes(running_nodes - cluster_nodes)
53
+ _add_nodes(cluster_nodes - running_nodes)
54
+ end
55
+ end
56
+
44
57
  def needs_check?
45
58
  return false unless monitored?
46
59
  @last_check + @check_interval < Time.now
47
60
  end
48
61
 
49
62
  def monitor_nodes
50
- @nodes.each { |node| node.monitor(self) }
51
63
  @last_check = Time.now
64
+ @nodes.each { |node| node.monitor(self) }
52
65
  end
53
66
 
54
67
  def to_s
@@ -62,5 +75,19 @@ module BigBrother
62
75
  def down_file_exists?
63
76
  @down_file.exists?
64
77
  end
78
+
79
+ def _add_nodes(addresses)
80
+ addresses.each do |address|
81
+ BigBrother.logger.info "adding #{address} to cluster #{self}"
82
+ BigBrother.ipvs.start_node(fwmark, address, 100)
83
+ end
84
+ end
85
+
86
+ def _remove_nodes(addresses)
87
+ addresses.each do |address|
88
+ BigBrother.logger.info "removing #{address} to cluster #{self}"
89
+ BigBrother.ipvs.stop_node(fwmark, address)
90
+ end
91
+ end
65
92
  end
66
93
  end
@@ -10,39 +10,10 @@ module BigBrother
10
10
  Hash[assoc_array]
11
11
  end
12
12
 
13
- def self.synchronize_with_ipvs(clusters, ipvs_state)
14
- clusters.values.each do |cluster|
15
- if ipvs_state.has_key?(cluster.fwmark.to_s)
16
- cluster.resume_monitoring!
17
-
18
- running_nodes = ipvs_state[cluster.fwmark.to_s]
19
- cluster_nodes = cluster.nodes.map(&:address)
20
-
21
- _remove_nodes(cluster, running_nodes - cluster_nodes)
22
- _add_nodes(cluster, cluster_nodes - running_nodes)
23
- end
24
- end
25
- end
26
-
27
- def self._add_nodes(cluster, addresses)
28
- addresses.each do |address|
29
- BigBrother.logger.info "adding #{address} to cluster #{cluster}"
30
- BigBrother.ipvs.start_node(cluster.fwmark, address, 100)
31
- end
32
- end
33
-
34
- def self._remove_nodes(cluster, addresses)
35
- addresses.each do |address|
36
- BigBrother.logger.info "removing #{address} to cluster #{cluster}"
37
- BigBrother.ipvs.stop_node(cluster.fwmark, address)
38
- end
39
- end
40
-
41
13
  def self._parse_nodes(nodes)
42
14
  nodes.map do |values|
43
15
  Node.new(values['address'], values['port'], values['path'])
44
16
  end
45
17
  end
46
-
47
18
  end
48
19
  end
@@ -1,3 +1,3 @@
1
1
  module BigBrother
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -16,6 +16,7 @@ module BigBrother
16
16
 
17
17
  get "/"
18
18
  last_response.status.should == 200
19
+ last_response.body.should include("Big Brother: #{BigBrother::VERSION}")
19
20
  last_response.body.should include("one (1): not running")
20
21
  last_response.body.should include("two (2): not running")
21
22
  last_response.body.should include("three (3): running")
@@ -43,6 +44,23 @@ module BigBrother
43
44
  last_response.body.should == "Running: true"
44
45
  end
45
46
 
47
+ it "attempts to synchronize the node if it is not running" do
48
+ @stub_executor.add_response("ipvsadm --save --numeric", <<-OUTPUT, 0)
49
+ -A -f 1 -s wrr
50
+ -a -f 1 -r 10.0.1.223:80 -i -w 1
51
+ -a -f 1 -r 10.0.1.224:80 -i -w 1
52
+ -A -f 2 -s wrr
53
+ -a -f 2 -r 10.0.1.225:80 -i -w 1
54
+ OUTPUT
55
+ BigBrother.configure(TEST_CONFIG)
56
+ BigBrother.clusters['test'] = Factory.cluster(:name => 'test', :fwmark => 1)
57
+
58
+ get "/cluster/test"
59
+
60
+ last_response.status.should == 200
61
+ last_response.body.should == "Running: true"
62
+ end
63
+
46
64
  it "returns a 404 http status when the cluster is not found" do
47
65
  get "/cluster/not_found"
48
66
 
@@ -88,9 +106,31 @@ module BigBrother
88
106
  last_response.status.should == 200
89
107
  last_response.body.should == "OK"
90
108
  BigBrother.clusters['test'].should be_monitored
91
- @recording_executor.commands.first.should == "ipvsadm --add-service --fwmark-service 100 --scheduler wrr"
92
- @recording_executor.commands.should include("ipvsadm --add-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 100")
93
- @recording_executor.commands.should include("ipvsadm --add-server --fwmark-service 100 --real-server 127.0.0.2 --ipip --weight 100")
109
+ @stub_executor.commands.should include("ipvsadm --add-service --fwmark-service 100 --scheduler wrr")
110
+ @stub_executor.commands.should include("ipvsadm --add-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 100")
111
+ @stub_executor.commands.should include("ipvsadm --add-server --fwmark-service 100 --real-server 127.0.0.2 --ipip --weight 100")
112
+ end
113
+
114
+ it "attempts to synchronize the nodes in the cluster" do
115
+ @stub_executor.add_response("ipvsadm --save --numeric", <<-OUTPUT, 0)
116
+ -A -f 100 -s wrr
117
+ -a -f 100 -r 127.0.1.223:80 -i -w 1
118
+ -a -f 100 -r 127.0.1.224:80 -i -w 1
119
+ -A -f 2 -s wrr
120
+ -a -f 2 -r 10.0.1.225:80 -i -w 1
121
+ OUTPUT
122
+ BigBrother.configure(TEST_CONFIG)
123
+ first = Factory.node(:address => '127.0.1.223')
124
+ second = Factory.node(:address => '127.0.1.225')
125
+ BigBrother.clusters['test'] = Factory.cluster(:name => 'test', :fwmark => 100, :scheduler => 'wrr', :nodes => [first, second])
126
+
127
+ put "/cluster/test"
128
+
129
+ last_response.status.should == 304
130
+ last_response.body.should == ""
131
+ BigBrother.clusters['test'].should be_monitored
132
+ @stub_executor.commands.should include("ipvsadm --add-server --fwmark-service 100 --real-server 127.0.1.225 --ipip --weight 100")
133
+ @stub_executor.commands.should include("ipvsadm --delete-server --fwmark-service 100 --real-server 127.0.1.224")
94
134
  end
95
135
  end
96
136
 
@@ -13,7 +13,7 @@ describe BigBrother::Cluster do
13
13
  cluster = Factory.cluster(:fwmark => 100, :scheduler => 'wrr')
14
14
 
15
15
  cluster.start_monitoring!
16
- @recording_executor.commands.should include('ipvsadm --add-service --fwmark-service 100 --scheduler wrr')
16
+ @stub_executor.commands.should include('ipvsadm --add-service --fwmark-service 100 --scheduler wrr')
17
17
  end
18
18
  end
19
19
 
@@ -26,7 +26,7 @@ describe BigBrother::Cluster do
26
26
 
27
27
  cluster.stop_monitoring!
28
28
  cluster.should_not be_monitored
29
- @recording_executor.commands.should include("ipvsadm --delete-service --fwmark-service 100")
29
+ @stub_executor.commands.should include("ipvsadm --delete-service --fwmark-service 100")
30
30
  end
31
31
 
32
32
  it "invalidates recorded weights, so it properly updates after a stop/start" do
@@ -42,7 +42,7 @@ describe BigBrother::Cluster do
42
42
  cluster.start_monitoring!
43
43
  cluster.monitor_nodes
44
44
 
45
- @recording_executor.commands.last.should == "ipvsadm --edit-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 10"
45
+ @stub_executor.commands.last.should == "ipvsadm --edit-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 10"
46
46
  end
47
47
  end
48
48
 
@@ -89,6 +89,53 @@ describe BigBrother::Cluster do
89
89
  end
90
90
  end
91
91
 
92
+ describe "synchronize!" do
93
+ it "monitors clusters that were already monitored" do
94
+ BigBrother.ipvs.stub(:running_configuration).and_return('1' => ['127.0.0.1'])
95
+ cluster = Factory.cluster(:fwmark => 1)
96
+
97
+ cluster.synchronize!
98
+
99
+ cluster.should be_monitored
100
+ end
101
+
102
+ it "does not monitor clusters that were already monitored" do
103
+ BigBrother.ipvs.stub(:running_configuration).and_return({})
104
+ cluster = Factory.cluster(:fwmark => 1)
105
+
106
+ cluster.synchronize!
107
+
108
+ cluster.should_not be_monitored
109
+ end
110
+
111
+ it "does not attempt to re-add the services it was monitoring" do
112
+ BigBrother.ipvs.stub(:running_configuration).and_return({'1' => ['127.0.0.1']})
113
+ cluster = Factory.cluster(:fwmark => 1, :nodes => [Factory.node(:address => '127.0.0.1')])
114
+
115
+ cluster.synchronize!
116
+
117
+ @stub_executor.commands.should be_empty
118
+ end
119
+
120
+ it "removes nodes that are no longer part of the cluster" do
121
+ BigBrother.ipvs.stub(:running_configuration).and_return({'1' => ['127.0.0.1', '127.0.1.1']})
122
+ cluster = Factory.cluster(:fwmark => 1, :nodes => [Factory.node(:address => '127.0.0.1')])
123
+
124
+ cluster.synchronize!
125
+
126
+ @stub_executor.commands.last.should == "ipvsadm --delete-server --fwmark-service 1 --real-server 127.0.1.1"
127
+ end
128
+
129
+ it "adds new nodes to the cluster" do
130
+ BigBrother.ipvs.stub(:running_configuration).and_return({'1' => ['127.0.0.1']})
131
+ cluster = Factory.cluster(:fwmark => 1, :nodes => [Factory.node(:address => '127.0.0.1'), Factory.node(:address => "127.0.1.1")])
132
+
133
+ cluster.synchronize!
134
+
135
+ @stub_executor.commands.should include("ipvsadm --add-server --fwmark-service 1 --real-server 127.0.1.1 --ipip --weight 100")
136
+ end
137
+ end
138
+
92
139
  describe "#to_s" do
93
140
  it "is the clusters name and fwmark" do
94
141
  cluster = Factory.cluster(:name => 'name', :fwmark => 100)
@@ -32,50 +32,4 @@ describe BigBrother::Configuration do
32
32
  clusters['test1'].nodes[1].path == '/test/valid'
33
33
  end
34
34
  end
35
-
36
- describe '.synchronize_with_ipvs' do
37
- it "monitors clusters that were already monitored" do
38
- clusters = {}
39
- clusters['one'] = Factory.cluster(:fwmark => 1)
40
- clusters['two'] = Factory.cluster(:fwmark => 2)
41
- clusters['three'] = Factory.cluster(:fwmark => 3)
42
-
43
- ipvs_state = {}
44
- ipvs_state['1'] = ['127.0.0.1']
45
- ipvs_state['3'] = ['127.0.0.1']
46
-
47
- BigBrother::Configuration.synchronize_with_ipvs(clusters, ipvs_state)
48
-
49
- clusters['one'].should be_monitored
50
- clusters['two'].should_not be_monitored
51
- clusters['three'].should be_monitored
52
- end
53
-
54
- it "does not attempt to re-add the services it was monitoring" do
55
- clusters = { 'one' => Factory.cluster(:fwmark => 1, :nodes => [Factory.node(:address => '127.0.0.1')]) }
56
- ipvs_state = { '1' => ['127.0.0.1'] }
57
-
58
- BigBrother::Configuration.synchronize_with_ipvs(clusters, ipvs_state)
59
-
60
- @recording_executor.commands.should be_empty
61
- end
62
-
63
- it "removes nodes that are no longer part of the cluster" do
64
- clusters = { 'one' => Factory.cluster(:fwmark => 1, :nodes => [Factory.node(:address => '127.0.0.1')]) }
65
- ipvs_state = { '1' => ['127.0.1.1', '127.0.0.1'] }
66
-
67
- BigBrother::Configuration.synchronize_with_ipvs(clusters, ipvs_state)
68
-
69
- @recording_executor.commands.last.should == "ipvsadm --delete-server --fwmark-service 1 --real-server 127.0.1.1"
70
- end
71
-
72
- it "adds new nodes to the cluster" do
73
- clusters = { 'one' => Factory.cluster(:fwmark => 1, :nodes => [Factory.node(:address => '127.0.0.1'), Factory.node(:address => "127.0.1.1")]) }
74
- ipvs_state = { '1' => ['127.0.0.1'] }
75
-
76
- BigBrother::Configuration.synchronize_with_ipvs(clusters, ipvs_state)
77
-
78
- @recording_executor.commands.should include("ipvsadm --add-server --fwmark-service 1 --real-server 127.0.1.1 --ipip --weight 100")
79
- end
80
- end
81
35
  end
@@ -3,8 +3,8 @@ require 'spec_helper'
3
3
  describe BigBrother::IPVS do
4
4
  describe "#running_configuration" do
5
5
  it "returns a parsed version of the running config" do
6
- playback = PlaybackExecutor.new
7
- playback.add_response(<<-OUTPUT, 0)
6
+ executor = StubExecutor.new
7
+ executor.add_response("ipvsadm --save --numeric", <<-OUTPUT, 0)
8
8
  -A -f 3 -s wrr
9
9
  -a -f 3 -r 10.0.1.220:80 -i -w 1
10
10
  -a -f 3 -r 10.0.1.221:80 -i -w 1
@@ -15,7 +15,7 @@ describe BigBrother::IPVS do
15
15
  -A -f 2 -s wrr
16
16
  -a -f 2 -r 10.0.1.225:80 -i -w 1
17
17
  OUTPUT
18
- config = BigBrother::IPVS.new(playback).running_configuration
18
+ config = BigBrother::IPVS.new(executor).running_configuration
19
19
 
20
20
  config.size.should == 3
21
21
  config['3'].should == ['10.0.1.220', '10.0.1.221', '10.0.1.222']
@@ -8,11 +8,11 @@ describe BigBrother::Node do
8
8
  node = Factory.node(:address => '127.0.0.1')
9
9
  cluster = Factory.cluster(:fwmark => 100, :nodes => [node])
10
10
  cluster.start_monitoring!
11
- @recording_executor.commands.clear
11
+ @stub_executor.commands.clear
12
12
 
13
13
  node.monitor(cluster)
14
14
 
15
- @recording_executor.commands.should include("ipvsadm --edit-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 56")
15
+ @stub_executor.commands.should include("ipvsadm --edit-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 56")
16
16
  end
17
17
 
18
18
  it "sets the weight to 100 for each node if an up file exists" do
@@ -20,13 +20,13 @@ describe BigBrother::Node do
20
20
  node = Factory.node(:address => '127.0.0.1')
21
21
  cluster = Factory.cluster(:fwmark => 100, :nodes => [node])
22
22
  cluster.start_monitoring!
23
- @recording_executor.commands.clear
23
+ @stub_executor.commands.clear
24
24
 
25
25
  BigBrother::StatusFile.new('up', 'test').create('Up for testing')
26
26
 
27
27
  node.monitor(cluster)
28
28
 
29
- @recording_executor.commands.should include("ipvsadm --edit-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 100")
29
+ @stub_executor.commands.should include("ipvsadm --edit-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 100")
30
30
  end
31
31
 
32
32
  it "sets the weight to 0 for each node if a down file exists" do
@@ -34,13 +34,13 @@ describe BigBrother::Node do
34
34
  node = Factory.node(:address => '127.0.0.1')
35
35
  cluster = Factory.cluster(:fwmark => 100, :nodes => [node])
36
36
  cluster.start_monitoring!
37
- @recording_executor.commands.clear
37
+ @stub_executor.commands.clear
38
38
 
39
39
  BigBrother::StatusFile.new('down', 'test').create('Down for testing')
40
40
 
41
41
  node.monitor(cluster)
42
42
 
43
- @recording_executor.commands.should include("ipvsadm --edit-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 0")
43
+ @stub_executor.commands.should include("ipvsadm --edit-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 0")
44
44
  end
45
45
 
46
46
  it "does not run multiple ipvsadm commands if the health does not change" do
@@ -48,12 +48,12 @@ describe BigBrother::Node do
48
48
  node = Factory.node(:address => '127.0.0.1')
49
49
  cluster = Factory.cluster(:fwmark => 100, :nodes => [node])
50
50
  cluster.start_monitoring!
51
- @recording_executor.commands.clear
51
+ @stub_executor.commands.clear
52
52
 
53
53
  node.monitor(cluster)
54
54
  node.monitor(cluster)
55
55
 
56
- @recording_executor.commands.should == ["ipvsadm --edit-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 56"]
56
+ @stub_executor.commands.should == ["ipvsadm --edit-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 56"]
57
57
  end
58
58
 
59
59
  it "will run multiple ipvsadm commands if the health does change" do
@@ -61,14 +61,14 @@ describe BigBrother::Node do
61
61
  node = Factory.node(:address => '127.0.0.1')
62
62
  cluster = Factory.cluster(:fwmark => 100, :nodes => [node])
63
63
  cluster.start_monitoring!
64
- @recording_executor.commands.clear
64
+ @stub_executor.commands.clear
65
65
 
66
66
  node.monitor(cluster)
67
67
  node.monitor(cluster)
68
68
  BigBrother::HealthFetcher.stub(:current_health).and_return(41)
69
69
  node.monitor(cluster)
70
70
 
71
- @recording_executor.commands.should == [
71
+ @stub_executor.commands.should == [
72
72
  "ipvsadm --edit-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 56",
73
73
  "ipvsadm --edit-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 41"
74
74
  ]
@@ -80,10 +80,10 @@ describe BigBrother::Node do
80
80
  cluster = Factory.cluster(:fwmark => 100, :nodes => [node])
81
81
  cluster.stop_monitoring!
82
82
 
83
- @recording_executor.commands.clear
83
+ @stub_executor.commands.clear
84
84
  node.monitor(cluster)
85
85
 
86
- @recording_executor.commands.should == []
86
+ @stub_executor.commands.should == []
87
87
  end
88
88
  end
89
89
  end
@@ -24,12 +24,12 @@ describe BigBrother::Ticker do
24
24
  ]
25
25
  )
26
26
  BigBrother.clusters['test'].start_monitoring!
27
- @recording_executor.commands.clear
27
+ @stub_executor.commands.clear
28
28
 
29
29
  BigBrother::Ticker.tick
30
30
 
31
- @recording_executor.commands.should include("ipvsadm --edit-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 74")
32
- @recording_executor.commands.should include("ipvsadm --edit-server --fwmark-service 100 --real-server #{public_ip_address} --ipip --weight 76")
31
+ @stub_executor.commands.should include("ipvsadm --edit-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 74")
32
+ @stub_executor.commands.should include("ipvsadm --edit-server --fwmark-service 100 --real-server #{public_ip_address} --ipip --weight 76")
33
33
  end
34
34
 
35
35
  it "only monitors a cluster once in the given interval" do
@@ -38,12 +38,12 @@ describe BigBrother::Ticker do
38
38
  :nodes => [Factory.node(:address => '127.0.0.1', :port => 8081)]
39
39
  )
40
40
  BigBrother.clusters['test'].start_monitoring!
41
- @recording_executor.commands.clear
41
+ @stub_executor.commands.clear
42
42
 
43
43
  BigBrother::Ticker.tick
44
44
  BigBrother::Ticker.tick
45
45
 
46
- @recording_executor.commands.should == ["ipvsadm --edit-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 74"]
46
+ @stub_executor.commands.should == ["ipvsadm --edit-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 74"]
47
47
  end
48
48
  end
49
49
 
@@ -6,22 +6,6 @@ describe BigBrother do
6
6
  BigBrother.configure(TEST_CONFIG)
7
7
  BigBrother.clusters.size.should == 3
8
8
  end
9
-
10
- it "synchronizes the configuration with the current state of IPVS" do
11
- playback = PlaybackExecutor.new
12
- playback.add_response(<<-OUTPUT, 0)
13
- -A -f 1 -s wrr
14
- -a -f 1 -r 10.0.1.223:80 -i -w 1
15
- -a -f 1 -r 10.0.1.224:80 -i -w 1
16
- -A -f 2 -s wrr
17
- -a -f 2 -r 10.0.1.225:80 -i -w 1
18
- OUTPUT
19
- BigBrother.ipvs = BigBrother::IPVS.new(playback)
20
- BigBrother.configure(TEST_CONFIG)
21
-
22
- BigBrother.clusters['test1'].should be_monitored
23
- BigBrother.clusters['test2'].should be_monitored
24
- end
25
9
  end
26
10
 
27
11
  describe '.reconfigure' do
@@ -90,7 +74,7 @@ EOF
90
74
  end
91
75
  BigBrother.configure(config_file)
92
76
  BigBrother.clusters['test1'].start_monitoring!
93
- @recording_executor.commands.clear
77
+ @stub_executor.commands.clear
94
78
 
95
79
  BigBrother.start_ticker!
96
80
 
@@ -112,8 +96,7 @@ EOF
112
96
  BigBrother.reconfigure
113
97
  BigBrother.clusters['test1'].nodes.first.path.should == "/test/another/path"
114
98
 
115
- @recording_executor.commands.first.should include("--weight 50")
116
- @recording_executor.commands.last.should == "ipvsadm --save --numeric"
99
+ @stub_executor.commands.first.should include("--weight 50")
117
100
  end
118
101
  end
119
102
  end
data/spec/spec_helper.rb CHANGED
@@ -13,8 +13,8 @@ RSpec.configure do |config|
13
13
 
14
14
  config.around(:each) do |spec|
15
15
  ipvs = BigBrother.ipvs
16
- @recording_executor = RecordingExecutor.new
17
- BigBrother.ipvs = BigBrother::IPVS.new(@recording_executor)
16
+ @stub_executor = StubExecutor.new
17
+ BigBrother.ipvs = BigBrother::IPVS.new(@stub_executor)
18
18
  spec.run
19
19
  BigBrother.ipvs = ipvs
20
20
  end
@@ -0,0 +1,18 @@
1
+ class StubExecutor
2
+ attr_reader :commands
3
+
4
+ def initialize
5
+ @responses = {}
6
+ @commands = []
7
+ end
8
+
9
+ def invoke(command)
10
+ @commands << command
11
+ @responses.fetch(command, [["", 0]]).pop
12
+ end
13
+
14
+ def add_response(command, output, status)
15
+ @responses[command] ||= []
16
+ @responses[command].push [output, status]
17
+ end
18
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: big_brother
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-24 00:00:00.000000000 Z
12
+ date: 2012-07-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thin
16
- requirement: &70211323894240 !ruby/object:Gem::Requirement
16
+ requirement: &70318446355800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.3.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70211323894240
24
+ version_requirements: *70318446355800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: async-rack
27
- requirement: &70211323893680 !ruby/object:Gem::Requirement
27
+ requirement: &70318446354760 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.5.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70211323893680
35
+ version_requirements: *70318446354760
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sinatra
38
- requirement: &70211323893120 !ruby/object:Gem::Requirement
38
+ requirement: &70318446354160 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '1.0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70211323893120
46
+ version_requirements: *70318446354160
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rack-fiber_pool
49
- requirement: &70211323892400 !ruby/object:Gem::Requirement
49
+ requirement: &70318446353320 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0.9'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70211323892400
57
+ version_requirements: *70318446353320
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: eventmachine
60
- requirement: &70211323891660 !ruby/object:Gem::Requirement
60
+ requirement: &70318446352480 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>'
@@ -68,10 +68,10 @@ dependencies:
68
68
  version: 1.0.0.beta.100
69
69
  type: :runtime
70
70
  prerelease: false
71
- version_requirements: *70211323891660
71
+ version_requirements: *70318446352480
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: em-http-request
74
- requirement: &70211323890380 !ruby/object:Gem::Requirement
74
+ requirement: &70318446351200 !ruby/object:Gem::Requirement
75
75
  none: false
76
76
  requirements:
77
77
  - - ~>
@@ -79,10 +79,10 @@ dependencies:
79
79
  version: '1.0'
80
80
  type: :runtime
81
81
  prerelease: false
82
- version_requirements: *70211323890380
82
+ version_requirements: *70318446351200
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: em-synchrony
85
- requirement: &70211323889400 !ruby/object:Gem::Requirement
85
+ requirement: &70318446350420 !ruby/object:Gem::Requirement
86
86
  none: false
87
87
  requirements:
88
88
  - - ~>
@@ -90,10 +90,10 @@ dependencies:
90
90
  version: '1.0'
91
91
  type: :runtime
92
92
  prerelease: false
93
- version_requirements: *70211323889400
93
+ version_requirements: *70318446350420
94
94
  - !ruby/object:Gem::Dependency
95
95
  name: em-resolv-replace
96
- requirement: &70211323888420 !ruby/object:Gem::Requirement
96
+ requirement: &70318446349600 !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
99
  - - ~>
@@ -101,10 +101,10 @@ dependencies:
101
101
  version: '1.1'
102
102
  type: :runtime
103
103
  prerelease: false
104
- version_requirements: *70211323888420
104
+ version_requirements: *70318446349600
105
105
  - !ruby/object:Gem::Dependency
106
106
  name: em-syslog
107
- requirement: &70211323887380 !ruby/object:Gem::Requirement
107
+ requirement: &70318446348120 !ruby/object:Gem::Requirement
108
108
  none: false
109
109
  requirements:
110
110
  - - ~>
@@ -112,10 +112,10 @@ dependencies:
112
112
  version: 0.0.2
113
113
  type: :runtime
114
114
  prerelease: false
115
- version_requirements: *70211323887380
115
+ version_requirements: *70318446348120
116
116
  - !ruby/object:Gem::Dependency
117
117
  name: rspec
118
- requirement: &70211323886900 !ruby/object:Gem::Requirement
118
+ requirement: &70318446375200 !ruby/object:Gem::Requirement
119
119
  none: false
120
120
  requirements:
121
121
  - - ~>
@@ -123,10 +123,10 @@ dependencies:
123
123
  version: 2.9.0
124
124
  type: :development
125
125
  prerelease: false
126
- version_requirements: *70211323886900
126
+ version_requirements: *70318446375200
127
127
  - !ruby/object:Gem::Dependency
128
128
  name: rack-test
129
- requirement: &70211323886380 !ruby/object:Gem::Requirement
129
+ requirement: &70318446374620 !ruby/object:Gem::Requirement
130
130
  none: false
131
131
  requirements:
132
132
  - - ~>
@@ -134,10 +134,10 @@ dependencies:
134
134
  version: 0.6.1
135
135
  type: :development
136
136
  prerelease: false
137
- version_requirements: *70211323886380
137
+ version_requirements: *70318446374620
138
138
  - !ruby/object:Gem::Dependency
139
139
  name: rake
140
- requirement: &70211323885760 !ruby/object:Gem::Requirement
140
+ requirement: &70318446374180 !ruby/object:Gem::Requirement
141
141
  none: false
142
142
  requirements:
143
143
  - - ! '>='
@@ -145,10 +145,10 @@ dependencies:
145
145
  version: '0'
146
146
  type: :development
147
147
  prerelease: false
148
- version_requirements: *70211323885760
148
+ version_requirements: *70318446374180
149
149
  - !ruby/object:Gem::Dependency
150
150
  name: rake_commit
151
- requirement: &70211323884900 !ruby/object:Gem::Requirement
151
+ requirement: &70318446373460 !ruby/object:Gem::Requirement
152
152
  none: false
153
153
  requirements:
154
154
  - - ~>
@@ -156,10 +156,10 @@ dependencies:
156
156
  version: '0.13'
157
157
  type: :development
158
158
  prerelease: false
159
- version_requirements: *70211323884900
159
+ version_requirements: *70318446373460
160
160
  - !ruby/object:Gem::Dependency
161
161
  name: vagrant
162
- requirement: &70211323884420 !ruby/object:Gem::Requirement
162
+ requirement: &70318446372760 !ruby/object:Gem::Requirement
163
163
  none: false
164
164
  requirements:
165
165
  - - ! '>='
@@ -167,7 +167,7 @@ dependencies:
167
167
  version: '0'
168
168
  type: :development
169
169
  prerelease: false
170
- version_requirements: *70211323884420
170
+ version_requirements: *70318446372760
171
171
  description: IPVS backend supervisor
172
172
  email:
173
173
  - code@getbraintree.com
@@ -223,8 +223,7 @@ files:
223
223
  - spec/support/ipvsadm
224
224
  - spec/support/mock_session.rb
225
225
  - spec/support/null_logger.rb
226
- - spec/support/playback_executor.rb
227
- - spec/support/recording_executor.rb
226
+ - spec/support/stub_executor.rb
228
227
  - spec/support/stub_server.rb
229
228
  homepage: https://github.com/braintree/big_brother
230
229
  licenses: []
@@ -246,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
245
  version: '0'
247
246
  requirements: []
248
247
  rubyforge_project:
249
- rubygems_version: 1.8.15
248
+ rubygems_version: 1.8.10
250
249
  signing_key:
251
250
  specification_version: 3
252
251
  summary: Process to monitor and update weights for servers in an IPVS pool
@@ -270,6 +269,5 @@ test_files:
270
269
  - spec/support/ipvsadm
271
270
  - spec/support/mock_session.rb
272
271
  - spec/support/null_logger.rb
273
- - spec/support/playback_executor.rb
274
- - spec/support/recording_executor.rb
272
+ - spec/support/stub_executor.rb
275
273
  - spec/support/stub_server.rb
@@ -1,13 +0,0 @@
1
- class PlaybackExecutor
2
- def initialize
3
- @responses = []
4
- end
5
-
6
- def invoke(command)
7
- @responses.pop
8
- end
9
-
10
- def add_response(output, status)
11
- @responses.push [output, status]
12
- end
13
- end
@@ -1,11 +0,0 @@
1
- class RecordingExecutor
2
- attr_reader :commands
3
-
4
- def initialize
5
- @commands = []
6
- end
7
-
8
- def invoke(command)
9
- @commands << command
10
- end
11
- end