big_brother 0.6.8 → 0.8.7
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/.travis.yml +1 -0
- data/Changelog.md +5 -0
- data/big_brother.gemspec +1 -1
- data/lib/big_brother.rb +4 -0
- data/lib/big_brother/active_active_cluster.rb +157 -0
- data/lib/big_brother/active_passive_cluster.rb +61 -0
- data/lib/big_brother/cluster.rb +28 -13
- data/lib/big_brother/cluster_collection.rb +3 -0
- data/lib/big_brother/cluster_factory.rb +16 -0
- data/lib/big_brother/configuration.rb +21 -3
- data/lib/big_brother/health_fetcher.rb +12 -0
- data/lib/big_brother/node.rb +35 -10
- data/lib/big_brother/version.rb +1 -1
- data/lib/resources/config_schema.yml +92 -0
- data/spec/big_brother/active_active_cluster_spec.rb +437 -0
- data/spec/big_brother/active_passive_cluster_spec.rb +172 -0
- data/spec/big_brother/app_spec.rb +13 -11
- data/spec/big_brother/cluster_collection_spec.rb +26 -0
- data/spec/big_brother/cluster_factory_spec.rb +23 -0
- data/spec/big_brother/cluster_spec.rb +60 -18
- data/spec/big_brother/configuration_spec.rb +72 -27
- data/spec/big_brother/health_fetcher_spec.rb +47 -2
- data/spec/big_brother/node_spec.rb +42 -68
- data/spec/big_brother/ticker_spec.rb +6 -2
- data/spec/big_brother_spec.rb +85 -55
- data/spec/support/example_config.yml +65 -39
- data/spec/support/factories/cluster_factory.rb +9 -1
- data/spec/support/null_logger.rb +9 -0
- metadata +30 -25
@@ -0,0 +1,172 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BigBrother::ActivePassiveCluster do
|
4
|
+
describe "#start_monitoring!" do
|
5
|
+
it "starts only the node with the least priority in IPVS" do
|
6
|
+
cluster = Factory.active_passive_cluster(
|
7
|
+
:fwmark => 100,
|
8
|
+
:scheduler => 'wrr',
|
9
|
+
:nodes => [
|
10
|
+
Factory.node(:priority => 0, :address => "127.0.0.1"),
|
11
|
+
Factory.node(:priority => 1, :address => "127.0.0.2"),
|
12
|
+
],
|
13
|
+
)
|
14
|
+
|
15
|
+
cluster.start_monitoring!
|
16
|
+
@stub_executor.commands.should include('ipvsadm --add-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 1')
|
17
|
+
@stub_executor.commands.should_not include('ipvsadm --add-server --fwmark-service 100 --real-server 127.0.0.2 --ipip --weight 1')
|
18
|
+
end
|
19
|
+
|
20
|
+
it "monitors a node before adding it to ipvs" do
|
21
|
+
cluster = Factory.active_passive_cluster(
|
22
|
+
:fwmark => 100,
|
23
|
+
:scheduler => 'wrr',
|
24
|
+
:nodes => [
|
25
|
+
Factory.node(:priority => 0, :address => "127.0.0.1"),
|
26
|
+
Factory.node(:priority => 1, :address => "127.0.0.2"),
|
27
|
+
],
|
28
|
+
)
|
29
|
+
|
30
|
+
cluster.start_monitoring!
|
31
|
+
@stub_executor.commands.last.should == "ipvsadm --add-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 1"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#monitor_nodes" do
|
36
|
+
it "edit node weight changes in ipvs when the active node is not down" do
|
37
|
+
node1 = Factory.node(:priority => 0, :address => "127.0.0.1", :weight => 90)
|
38
|
+
node3 = Factory.node(:priority => 2, :address => "127.0.0.3", :weight => 88)
|
39
|
+
node2 = Factory.node(:priority => 1, :address => "127.0.0.2", :weight => 87)
|
40
|
+
cluster = Factory.active_passive_cluster(:nodes => [node1, node2, node3], :fwmark => 1)
|
41
|
+
node1.stub(:monitor).and_return(93)
|
42
|
+
node2.stub(:monitor).and_return(92)
|
43
|
+
node3.stub(:monitor).and_return(90)
|
44
|
+
|
45
|
+
cluster.monitor_nodes
|
46
|
+
|
47
|
+
cluster.active_node
|
48
|
+
cluster.active_node.address.should == "127.0.0.1"
|
49
|
+
@stub_executor.commands.should include("ipvsadm --edit-server --fwmark-service 1 --real-server 127.0.0.1 --ipip --weight 93")
|
50
|
+
node1.weight.should == 93
|
51
|
+
end
|
52
|
+
|
53
|
+
it "replaces active node in ipvs with new weight when the active node is down" do
|
54
|
+
node1 = Factory.node(:priority => 0, :address => "127.0.0.1", :weight => 90)
|
55
|
+
node3 = Factory.node(:priority => 2, :address => "127.0.0.3", :weight => 88)
|
56
|
+
node2 = Factory.node(:priority => 1, :address => "127.0.1.1", :weight => 87)
|
57
|
+
cluster = Factory.active_passive_cluster(:nodes => [node1, node2, node3], :fwmark => 1)
|
58
|
+
node1.stub(:monitor).and_return(0)
|
59
|
+
node2.stub(:monitor).and_return(92)
|
60
|
+
node3.stub(:monitor).and_return(90)
|
61
|
+
|
62
|
+
cluster.monitor_nodes
|
63
|
+
|
64
|
+
cluster.monitor_nodes
|
65
|
+
|
66
|
+
cluster.active_node
|
67
|
+
cluster.active_node.address.should == "127.0.1.1"
|
68
|
+
@stub_executor.commands.should include("ipvsadm --delete-server --fwmark-service 1 --real-server 127.0.0.1")
|
69
|
+
@stub_executor.commands.should include("ipvsadm --add-server --fwmark-service 1 --real-server 127.0.1.1 --ipip --weight 92")
|
70
|
+
end
|
71
|
+
|
72
|
+
it "replaces the unhealthy least priority node with the next priority node" do
|
73
|
+
node1 = Factory.node(:priority => 0, :address => "127.0.0.1", :weight => 90)
|
74
|
+
node3 = Factory.node(:priority => 2, :address => "127.0.0.3", :weight => 88)
|
75
|
+
node2 = Factory.node(:priority => 1, :address => "127.0.0.2", :weight => 87)
|
76
|
+
cluster = Factory.active_passive_cluster(:nodes => [node1, node2, node3], :fwmark => 1)
|
77
|
+
node1.stub(:monitor).and_return(0)
|
78
|
+
node2.stub(:monitor).and_return(92)
|
79
|
+
node3.stub(:monitor).and_return(90)
|
80
|
+
|
81
|
+
cluster.monitor_nodes
|
82
|
+
|
83
|
+
cluster.active_node
|
84
|
+
cluster.active_node.address.should == "127.0.0.2"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "sets the weight of the current_active_node to 0 in ipvs if all nodes are down" do
|
88
|
+
node1 = Factory.node(:priority => 0, :address => "127.0.0.1", :weight => 90)
|
89
|
+
node3 = Factory.node(:priority => 2, :address => "127.0.0.3", :weight => 88)
|
90
|
+
node2 = Factory.node(:priority => 1, :address => "127.0.0.2", :weight => 87)
|
91
|
+
cluster = Factory.active_passive_cluster(:nodes => [node1, node2, node3], :fwmark => 1)
|
92
|
+
node1.stub(:monitor).and_return(0)
|
93
|
+
node2.stub(:monitor).and_return(0)
|
94
|
+
node3.stub(:monitor).and_return(0)
|
95
|
+
|
96
|
+
cluster.monitor_nodes
|
97
|
+
|
98
|
+
cluster.active_node
|
99
|
+
cluster.active_node.address.should == "127.0.0.1"
|
100
|
+
@stub_executor.commands.should include("ipvsadm --edit-server --fwmark-service 1 --real-server 127.0.0.1 --ipip --weight 0")
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "#resume_monitoring!" do
|
105
|
+
it "marks the cluster as monitored" do
|
106
|
+
cluster = Factory.cluster
|
107
|
+
|
108
|
+
cluster.monitored?.should be_false
|
109
|
+
cluster.resume_monitoring!
|
110
|
+
cluster.monitored?.should be_true
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "synchronize!" do
|
115
|
+
it "continues to monitor clusters that were already monitored" do
|
116
|
+
BigBrother.ipvs.stub(:running_configuration).and_return({})
|
117
|
+
cluster = Factory.cluster(:fwmark => 1)
|
118
|
+
|
119
|
+
cluster.synchronize!
|
120
|
+
|
121
|
+
cluster.should_not be_monitored
|
122
|
+
end
|
123
|
+
|
124
|
+
it "removes current active node if its priority is no longer the least priority" do
|
125
|
+
BigBrother.ipvs.stub(:running_configuration).and_return({'1' => ['127.0.1.1']})
|
126
|
+
cluster = Factory.active_passive_cluster(
|
127
|
+
:fwmark => 1,
|
128
|
+
:nodes => [
|
129
|
+
Factory.node(:address => '127.0.1.1', :priority => 8, :weight => 55),
|
130
|
+
Factory.node(:address => '127.0.0.1', :priority => 3, :weight => 75),
|
131
|
+
],
|
132
|
+
)
|
133
|
+
|
134
|
+
cluster.synchronize!
|
135
|
+
|
136
|
+
@stub_executor.commands.should include("ipvsadm --delete-server --fwmark-service 1 --real-server 127.0.1.1")
|
137
|
+
@stub_executor.commands.should include("ipvsadm --add-server --fwmark-service 1 --real-server 127.0.0.1 --ipip --weight 75")
|
138
|
+
end
|
139
|
+
|
140
|
+
it "removes current active node if the node no longer exist" do
|
141
|
+
BigBrother.ipvs.stub(:running_configuration).and_return({'1' => ['127.0.1.1']})
|
142
|
+
cluster = Factory.active_passive_cluster(
|
143
|
+
:fwmark => 1,
|
144
|
+
:nodes => [
|
145
|
+
Factory.node(:address => '127.0.1.2', :priority => 2, :weight => 45),
|
146
|
+
Factory.node(:address => '127.0.0.1', :priority => 3, :weight => 55),
|
147
|
+
],
|
148
|
+
)
|
149
|
+
|
150
|
+
cluster.synchronize!
|
151
|
+
|
152
|
+
@stub_executor.commands.should include("ipvsadm --delete-server --fwmark-service 1 --real-server 127.0.1.1")
|
153
|
+
@stub_executor.commands.should include("ipvsadm --add-server --fwmark-service 1 --real-server 127.0.1.2 --ipip --weight 45")
|
154
|
+
end
|
155
|
+
|
156
|
+
it "does not remove current active node if it has the least priority" do
|
157
|
+
BigBrother.ipvs.stub(:running_configuration).and_return({'1' => ['127.0.1.1']})
|
158
|
+
cluster = Factory.active_passive_cluster(
|
159
|
+
:fwmark => 1,
|
160
|
+
:nodes => [
|
161
|
+
Factory.node(:address => '127.0.1.1', :priority => 0),
|
162
|
+
Factory.node(:address => '127.0.0.1', :priority => 1),
|
163
|
+
],
|
164
|
+
)
|
165
|
+
|
166
|
+
cluster.synchronize!
|
167
|
+
|
168
|
+
@stub_executor.commands.should be_empty
|
169
|
+
cluster.active_node.address.should == '127.0.1.1'
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
@@ -8,6 +8,7 @@ module BigBrother
|
|
8
8
|
|
9
9
|
describe "/" do
|
10
10
|
it "returns the list of configured clusters and their status" do
|
11
|
+
BigBrother::HealthFetcher.stub(:current_health).and_return(99)
|
11
12
|
BigBrother.clusters['one'] = Factory.cluster(:name => 'one', :fwmark => 1)
|
12
13
|
BigBrother.clusters['two'] = Factory.cluster(:name => 'two', :fwmark => 2)
|
13
14
|
BigBrother.clusters['three'] = Factory.cluster(
|
@@ -41,9 +42,9 @@ module BigBrother
|
|
41
42
|
BigBrother.clusters['test'] = Factory.cluster(
|
42
43
|
:name => 'test',
|
43
44
|
:nodes => [
|
44
|
-
Factory.node
|
45
|
-
Factory.node
|
46
|
-
Factory.node
|
45
|
+
Factory.node,
|
46
|
+
Factory.node,
|
47
|
+
Factory.node,
|
47
48
|
]
|
48
49
|
)
|
49
50
|
|
@@ -53,7 +54,7 @@ module BigBrother
|
|
53
54
|
last_response.status.should == 200
|
54
55
|
last_response.body.should == <<-RESPONSE_BODY
|
55
56
|
Running: true
|
56
|
-
CombinedWeight:
|
57
|
+
CombinedWeight: 300
|
57
58
|
RESPONSE_BODY
|
58
59
|
end
|
59
60
|
|
@@ -95,9 +96,9 @@ CombinedWeight: 60
|
|
95
96
|
BigBrother.clusters['test'] = Factory.cluster(
|
96
97
|
:name => 'test',
|
97
98
|
:nodes => [
|
98
|
-
Factory.node
|
99
|
-
Factory.node
|
100
|
-
Factory.node
|
99
|
+
Factory.node,
|
100
|
+
Factory.node,
|
101
|
+
Factory.node,
|
101
102
|
]
|
102
103
|
)
|
103
104
|
|
@@ -107,7 +108,7 @@ CombinedWeight: 60
|
|
107
108
|
last_response.status.should == 200
|
108
109
|
last_response.body.should == <<-RESPONSE_BODY
|
109
110
|
Running: true
|
110
|
-
CombinedWeight:
|
111
|
+
CombinedWeight: 300
|
111
112
|
RESPONSE_BODY
|
112
113
|
end
|
113
114
|
|
@@ -169,8 +170,8 @@ CombinedWeight: 60
|
|
169
170
|
last_response.body.should == "OK"
|
170
171
|
BigBrother.clusters['test'].should be_monitored
|
171
172
|
@stub_executor.commands.should include("ipvsadm --add-service --fwmark-service 100 --scheduler wrr")
|
172
|
-
@stub_executor.commands.should include("ipvsadm --add-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight
|
173
|
-
@stub_executor.commands.should include("ipvsadm --add-server --fwmark-service 100 --real-server 127.0.0.2 --ipip --weight
|
173
|
+
@stub_executor.commands.should include("ipvsadm --add-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 1")
|
174
|
+
@stub_executor.commands.should include("ipvsadm --add-server --fwmark-service 100 --real-server 127.0.0.2 --ipip --weight 1")
|
174
175
|
end
|
175
176
|
|
176
177
|
it "attempts to synchronize the nodes in the cluster" do
|
@@ -191,13 +192,14 @@ CombinedWeight: 60
|
|
191
192
|
last_response.status.should == 304
|
192
193
|
last_response.body.should == ""
|
193
194
|
BigBrother.clusters['test'].should be_monitored
|
194
|
-
@stub_executor.commands.should include("ipvsadm --add-server --fwmark-service 100 --real-server 127.0.1.225 --ipip --weight
|
195
|
+
@stub_executor.commands.should include("ipvsadm --add-server --fwmark-service 100 --real-server 127.0.1.225 --ipip --weight 0")
|
195
196
|
@stub_executor.commands.should include("ipvsadm --delete-server --fwmark-service 100 --real-server 127.0.1.224")
|
196
197
|
end
|
197
198
|
end
|
198
199
|
|
199
200
|
describe "DELETE /cluster/:name" do
|
200
201
|
it "marks the cluster as no longer monitored" do
|
202
|
+
BigBrother::HealthFetcher.stub(:current_health)
|
201
203
|
BigBrother.clusters['test'] = Factory.cluster(:name => 'test')
|
202
204
|
BigBrother.clusters['test'].start_monitoring!
|
203
205
|
|
@@ -28,6 +28,30 @@ describe BigBrother::ClusterCollection do
|
|
28
28
|
collection.config({'existing_cluster' => cluster_from_config})
|
29
29
|
end
|
30
30
|
|
31
|
+
it "ensures an active_active_cluster does a proper cleanup if it is transitioning to a different type of cluster" do
|
32
|
+
collection = BigBrother::ClusterCollection.new
|
33
|
+
|
34
|
+
existing_cluster = Factory.active_active_cluster(:name => 'existing_cluster')
|
35
|
+
collection['existing_cluster'] = existing_cluster
|
36
|
+
cluster_from_config = Factory.cluster(:name => 'existing_cluster')
|
37
|
+
|
38
|
+
existing_cluster.should_receive(:stop_relay_fwmark)
|
39
|
+
|
40
|
+
collection.config({'existing_cluster' => cluster_from_config})
|
41
|
+
end
|
42
|
+
|
43
|
+
it "does not make an active_active_cluster do a clean up if it is being updated" do
|
44
|
+
collection = BigBrother::ClusterCollection.new
|
45
|
+
|
46
|
+
existing_cluster = Factory.active_active_cluster(:name => 'existing_cluster')
|
47
|
+
collection['existing_cluster'] = existing_cluster
|
48
|
+
cluster_from_config = Factory.active_active_cluster(:name => 'existing_cluster')
|
49
|
+
|
50
|
+
existing_cluster.should_not_receive(:stop_relay_fwmark)
|
51
|
+
|
52
|
+
collection.config({'existing_cluster' => cluster_from_config})
|
53
|
+
end
|
54
|
+
|
31
55
|
it "stops and removes clusters not included in the next configuration" do
|
32
56
|
test2 = Factory.cluster(:name => 'test2', :fwmark => 102)
|
33
57
|
collection = BigBrother::ClusterCollection.new
|
@@ -48,6 +72,7 @@ describe BigBrother::ClusterCollection do
|
|
48
72
|
|
49
73
|
describe "running" do
|
50
74
|
it "returns the clusters in the collection that are currently running" do
|
75
|
+
BigBrother::HealthFetcher.stub(:current_health)
|
51
76
|
clusters_from_config = {
|
52
77
|
'test1' => Factory.cluster(:name => 'test1', :fwmark => 101),
|
53
78
|
'test2' => Factory.cluster(:name => 'test2', :fwmark => 102),
|
@@ -65,6 +90,7 @@ describe BigBrother::ClusterCollection do
|
|
65
90
|
|
66
91
|
describe "stopped" do
|
67
92
|
it "returns the clusters in the collection that are not running" do
|
93
|
+
BigBrother::HealthFetcher.stub(:current_health)
|
68
94
|
clusters_from_config = {
|
69
95
|
'test1' => Factory.cluster(:name => 'test1', :fwmark => 101),
|
70
96
|
'test2' => Factory.cluster(:name => 'test2', :fwmark => 102),
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BigBrother::ClusterFactory do
|
4
|
+
describe '.create_cluster' do
|
5
|
+
it 'creates a normal cluster' do
|
6
|
+
cluster = BigBrother::ClusterFactory.create_cluster('foo', :fwmark => 100)
|
7
|
+
|
8
|
+
cluster.should be_an_instance_of BigBrother::Cluster
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'creates an active_passive cluster' do
|
12
|
+
cluster = BigBrother::ClusterFactory.create_cluster('foo', :fwmark => 100, :backend_mode => 'active_passive')
|
13
|
+
|
14
|
+
cluster.should be_an_instance_of BigBrother::ActivePassiveCluster
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'creates an active_active cluster' do
|
18
|
+
cluster = BigBrother::ClusterFactory.create_cluster('foo', :fwmark => 100, :backend_mode => 'active_active')
|
19
|
+
|
20
|
+
cluster.should be_an_instance_of BigBrother::ActiveActiveCluster
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe BigBrother::Cluster do
|
4
|
+
before { BigBrother::HealthFetcher.stub(:current_health).and_return(10) }
|
5
|
+
|
4
6
|
describe "#start_monitoring!" do
|
5
7
|
it "marks the cluster as monitored" do
|
6
8
|
cluster = Factory.cluster
|
@@ -32,17 +34,16 @@ describe BigBrother::Cluster do
|
|
32
34
|
it "invalidates recorded weights, so it properly updates after a stop/start" do
|
33
35
|
node = Factory.node(:address => '127.0.0.1')
|
34
36
|
cluster = Factory.cluster(:fwmark => '100', :nodes => [node])
|
35
|
-
|
36
|
-
BigBrother::HealthFetcher.stub(:current_health).and_return(10)
|
37
|
-
|
38
37
|
cluster.start_monitoring!
|
39
38
|
cluster.monitor_nodes
|
40
39
|
|
41
40
|
cluster.stop_monitoring!
|
42
41
|
cluster.start_monitoring!
|
42
|
+
|
43
|
+
BigBrother::HealthFetcher.stub(:current_health).and_return(15)
|
43
44
|
cluster.monitor_nodes
|
44
45
|
|
45
|
-
@stub_executor.commands.
|
46
|
+
@stub_executor.commands.should include("ipvsadm --edit-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 15")
|
46
47
|
end
|
47
48
|
end
|
48
49
|
|
@@ -56,6 +57,46 @@ describe BigBrother::Cluster do
|
|
56
57
|
end
|
57
58
|
|
58
59
|
describe "#monitor_nodes" do
|
60
|
+
it "does not run multiple ipvsadm commands if the health does not change" do
|
61
|
+
node = Factory.node(:address => '127.0.0.1')
|
62
|
+
cluster = Factory.cluster(:fwmark => 100, :nodes => [node])
|
63
|
+
cluster.start_monitoring!
|
64
|
+
@stub_executor.commands.clear
|
65
|
+
BigBrother::HealthFetcher.stub(:current_health).and_return(56)
|
66
|
+
cluster.monitor_nodes
|
67
|
+
|
68
|
+
@stub_executor.commands.should == ["ipvsadm --edit-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 56"]
|
69
|
+
end
|
70
|
+
|
71
|
+
it "will run multiple ipvsadm commands if the health does change" do
|
72
|
+
node = Factory.node(:address => '127.0.0.1')
|
73
|
+
cluster = Factory.cluster(:fwmark => 100, :nodes => [node])
|
74
|
+
cluster.start_monitoring!
|
75
|
+
@stub_executor.commands.clear
|
76
|
+
|
77
|
+
BigBrother::HealthFetcher.stub(:current_health).and_return(56)
|
78
|
+
cluster.monitor_nodes
|
79
|
+
BigBrother::HealthFetcher.stub(:current_health).and_return(41)
|
80
|
+
cluster.monitor_nodes
|
81
|
+
|
82
|
+
@stub_executor.commands.should == [
|
83
|
+
"ipvsadm --edit-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 56",
|
84
|
+
"ipvsadm --edit-server --fwmark-service 100 --real-server 127.0.0.1 --ipip --weight 41"
|
85
|
+
]
|
86
|
+
end
|
87
|
+
|
88
|
+
it "does not update the weight if the cluster is no longer monitored" do
|
89
|
+
BigBrother::HealthFetcher.stub(:current_health).and_return(56)
|
90
|
+
node = Factory.node(:address => '127.0.0.1')
|
91
|
+
cluster = Factory.cluster(:fwmark => 100, :nodes => [node])
|
92
|
+
cluster.stop_monitoring!
|
93
|
+
|
94
|
+
@stub_executor.commands.clear
|
95
|
+
cluster.monitor_nodes
|
96
|
+
|
97
|
+
@stub_executor.commands.should == []
|
98
|
+
end
|
99
|
+
|
59
100
|
it "marks the cluster as no longer requiring monitoring" do
|
60
101
|
cluster = Factory.cluster
|
61
102
|
|
@@ -71,6 +112,7 @@ describe BigBrother::Cluster do
|
|
71
112
|
node1 = Factory.node
|
72
113
|
node2 = Factory.node
|
73
114
|
cluster = Factory.cluster(:nodes => [node1, node2])
|
115
|
+
cluster.start_monitoring!
|
74
116
|
|
75
117
|
node1.should_receive(:monitor).with(cluster)
|
76
118
|
node2.should_receive(:monitor).with(cluster)
|
@@ -112,7 +154,7 @@ describe BigBrother::Cluster do
|
|
112
154
|
cluster.start_monitoring!
|
113
155
|
cluster.monitor_nodes
|
114
156
|
|
115
|
-
@stub_executor.commands.last.should == "ipvsadm --add-server --fwmark-service 1 --real-server
|
157
|
+
@stub_executor.commands.last.should == "ipvsadm --add-server --fwmark-service 1 --real-server 169.254.254.254 --ipip --weight 1"
|
116
158
|
end
|
117
159
|
|
118
160
|
it "removes downpage node from IPVS if it exists and cluster is up" do
|
@@ -137,8 +179,8 @@ describe BigBrother::Cluster do
|
|
137
179
|
node2 = Factory.node(:address => '192.168.0.2')
|
138
180
|
cluster = Factory.cluster(:nodes => [node1, node2], :nagios => {:host => "prod.load", :check => "test1_check", :server => "server.foo"})
|
139
181
|
|
140
|
-
node1.stub(:
|
141
|
-
node2.stub(:
|
182
|
+
node1.stub(:monitor).and_return(0)
|
183
|
+
node2.stub(:monitor).and_return(10)
|
142
184
|
|
143
185
|
cluster.start_monitoring!
|
144
186
|
cluster.monitor_nodes
|
@@ -150,8 +192,8 @@ describe BigBrother::Cluster do
|
|
150
192
|
node2 = Factory.node(:address => '192.168.0.2')
|
151
193
|
cluster = Factory.cluster(:nodes => [node1, node2], :nagios => {:host => "prod.load", :check => "test1_check", :server => "server.foo"})
|
152
194
|
|
153
|
-
node1.stub(:
|
154
|
-
node2.stub(:
|
195
|
+
node1.stub(:monitor).and_return(0)
|
196
|
+
node2.stub(:monitor).and_return(10)
|
155
197
|
|
156
198
|
cluster.start_monitoring!
|
157
199
|
cluster.monitor_nodes
|
@@ -167,9 +209,9 @@ describe BigBrother::Cluster do
|
|
167
209
|
node3 = Factory.node(:address => '192.168.0.3')
|
168
210
|
cluster = Factory.cluster(:nodes => [node1, node2, node3], :nagios => {:host => "prod.load", :check => "test1_check", :server => "server.foo"})
|
169
211
|
|
170
|
-
node1.stub(:
|
171
|
-
node2.stub(:
|
172
|
-
node3.stub(:
|
212
|
+
node1.stub(:monitor).and_return(0)
|
213
|
+
node2.stub(:monitor).and_return(10)
|
214
|
+
node3.stub(:monitor).and_return(10)
|
173
215
|
|
174
216
|
cluster.start_monitoring!
|
175
217
|
cluster.monitor_nodes
|
@@ -180,16 +222,16 @@ describe BigBrother::Cluster do
|
|
180
222
|
node1 = Factory.node(:address => '192.168.0.1')
|
181
223
|
node2 = Factory.node(:address => '192.168.0.2')
|
182
224
|
cluster = Factory.cluster(:nodes => [node1, node2], :nagios => {:host => "prod.load", :check => "test1_check", :server => "server.foo"})
|
183
|
-
node1.stub(:
|
184
|
-
node2.stub(:
|
225
|
+
node1.stub(:monitor).and_return(0)
|
226
|
+
node2.stub(:monitor).and_return(10)
|
185
227
|
|
186
228
|
cluster.start_monitoring!
|
187
229
|
cluster.monitor_nodes
|
188
230
|
@stub_executor.commands.should include("echo 'prod.load,test1_check,2,CRITICAL 50% of nodes are down' | send_nsca -H server.foo -d ,")
|
189
231
|
@stub_executor.clear_commands!
|
190
232
|
|
191
|
-
node1.stub(:
|
192
|
-
node2.stub(:
|
233
|
+
node1.stub(:monitor).and_return(10)
|
234
|
+
node2.stub(:monitor).and_return(10)
|
193
235
|
cluster.monitor_nodes
|
194
236
|
@stub_executor.commands.should include("echo 'prod.load,test1_check,0,OK all nodes up' | send_nsca -H server.foo -d ,")
|
195
237
|
end
|
@@ -208,7 +250,7 @@ describe BigBrother::Cluster do
|
|
208
250
|
end
|
209
251
|
|
210
252
|
describe "synchronize!" do
|
211
|
-
it "
|
253
|
+
it "continues to monitor clusters that were already monitored" do
|
212
254
|
BigBrother.ipvs.stub(:running_configuration).and_return('1' => ['127.0.0.1'])
|
213
255
|
cluster = Factory.cluster(:fwmark => 1)
|
214
256
|
|
@@ -250,7 +292,7 @@ describe BigBrother::Cluster do
|
|
250
292
|
|
251
293
|
cluster.synchronize!
|
252
294
|
|
253
|
-
@stub_executor.commands.should include("ipvsadm --add-server --fwmark-service 1 --real-server 127.0.1.1 --ipip --weight
|
295
|
+
@stub_executor.commands.should include("ipvsadm --add-server --fwmark-service 1 --real-server 127.0.1.1 --ipip --weight 0")
|
254
296
|
end
|
255
297
|
end
|
256
298
|
|