nat-monitor 1.0.0 → 1.0.1
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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/bin/nat-monitor +0 -0
- data/lib/nat-monitor.rb +6 -2
- data/lib/nat-monitor/version.rb +1 -1
- data/spec/lib/nat-monitor_spec.rb +28 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 536dfbc820599ad1fe2c10cfeffb86da7dcac84a
|
4
|
+
data.tar.gz: 045f897aec8ddd8bb83a58a540dbabab4812458f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0726a3d02e59a92ac2775d0da561eb95490037ce89e3aeb33d99aff93f3fc5337ec4ec5148d86ed2fc23e19886e7962d2115f70de88f82cdf5934c6949c9229
|
7
|
+
data.tar.gz: 601a1532fc1707059f20bde496e5329694884d6cfa18a68ce64415d0a395b38234baaf8265d710a5cf78ce53eb164cdfd89af74ad350d659c9d35fc087f43eef
|
data/README.md
CHANGED
data/bin/nat-monitor
CHANGED
File without changes
|
data/lib/nat-monitor.rb
CHANGED
@@ -6,8 +6,11 @@ module EtTools
|
|
6
6
|
require 'yaml'
|
7
7
|
|
8
8
|
def initialize(conf_file = nil)
|
9
|
-
@conf =
|
10
|
-
|
9
|
+
@conf = defaults.merge load_conf(conf_file)
|
10
|
+
end
|
11
|
+
|
12
|
+
def load_conf(conf_file = nil)
|
13
|
+
YAML.load_file(conf_file || '/etc/nat_monitor.yml')
|
11
14
|
end
|
12
15
|
|
13
16
|
def run
|
@@ -58,6 +61,7 @@ module EtTools
|
|
58
61
|
def steal_route
|
59
62
|
output 'Stealing route 0.0.0.0/0 on route table ' \
|
60
63
|
"#{@conf['route_table_id']}"
|
64
|
+
return if @conf['mocking']
|
61
65
|
connection.replace_route(
|
62
66
|
@conf['route_table_id'],
|
63
67
|
'0.0.0.0/0',
|
data/lib/nat-monitor/version.rb
CHANGED
@@ -16,8 +16,9 @@ describe EtTools::NatMonitor do
|
|
16
16
|
).merge(@other_nodes) }
|
17
17
|
|
18
18
|
filepath = 'bogus_filename.yml'
|
19
|
-
|
20
|
-
|
19
|
+
|
20
|
+
allow_any_instance_of(EtTools::NatMonitor).to receive(:load_conf)
|
21
|
+
.with(filepath).and_return(@yaml_conf)
|
21
22
|
|
22
23
|
@nat_monitor = EtTools::NatMonitor.new(filepath)
|
23
24
|
|
@@ -26,7 +27,6 @@ describe EtTools::NatMonitor do
|
|
26
27
|
'heartbeat_interval' => 10 }
|
27
28
|
|
28
29
|
allow(@nat_monitor).to receive(:my_instance_id).and_return(@my_instance_id)
|
29
|
-
allow(@nat_monitor).to receive(:steal_route).and_return(true)
|
30
30
|
end
|
31
31
|
|
32
32
|
context 'fewer than 3 nodes are specified' do
|
@@ -48,9 +48,8 @@ describe EtTools::NatMonitor do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
context 'invalid route is specified' do
|
51
|
-
# connection.route_tables.map(&:id).include? route_id
|
52
51
|
before do
|
53
|
-
|
52
|
+
expect(@nat_monitor.connection).to receive(:route_tables)
|
54
53
|
.and_return [
|
55
54
|
double('route_tables',
|
56
55
|
id: 'rtb-99999999')
|
@@ -58,8 +57,6 @@ describe EtTools::NatMonitor do
|
|
58
57
|
end
|
59
58
|
|
60
59
|
it 'exits with status 2' do
|
61
|
-
expect(@nat_monitor).to receive(:route_exists?).with(@route_table_id)
|
62
|
-
.and_return false
|
63
60
|
expect(@nat_monitor).to receive(:exit).with(2)
|
64
61
|
@nat_monitor.validate!
|
65
62
|
end
|
@@ -129,8 +126,6 @@ describe EtTools::NatMonitor do
|
|
129
126
|
end
|
130
127
|
|
131
128
|
it 'counts unreachable nodes correctly' do
|
132
|
-
allow(@nat_monitor).to receive(:other_nodes)
|
133
|
-
.and_return(@other_nodes)
|
134
129
|
expect(@nat_monitor).to receive(:unreachable_nodes)
|
135
130
|
.and_return(@other_nodes)
|
136
131
|
@nat_monitor.heartbeat
|
@@ -144,35 +139,53 @@ describe EtTools::NatMonitor do
|
|
144
139
|
end
|
145
140
|
end
|
146
141
|
|
147
|
-
context 'and can\'t ping the master' do
|
142
|
+
context 'and only can\'t ping the master' do
|
148
143
|
before do
|
149
144
|
allow(@nat_monitor).to receive(:pingable?).with('1.1.1.2')
|
150
145
|
.and_return false
|
151
146
|
allow(@nat_monitor).to receive(:pingable?).with('1.1.1.3')
|
152
147
|
.and_return true
|
153
|
-
allow_any_instance_of(Fog::Compute::AWS).to receive(:replace_route)
|
154
|
-
.with(@route_table_id, '0.0.0.0', @my_instance_id)
|
155
|
-
.and_return true
|
156
148
|
end
|
157
149
|
|
158
150
|
it 'computes the list of other nodes correctly' do
|
151
|
+
allow(@nat_monitor).to receive(:steal_route).and_return true
|
159
152
|
expect(@nat_monitor).to receive(:other_nodes)
|
160
153
|
.exactly(2).times.and_return(@other_nodes)
|
161
154
|
@nat_monitor.heartbeat
|
162
155
|
end
|
163
156
|
|
164
157
|
it 'finds i-00000002 unreachable' do
|
158
|
+
allow(@nat_monitor).to receive(:steal_route).and_return true
|
165
159
|
expect(@nat_monitor).to receive(:unreachable_nodes)
|
166
160
|
.and_return('i-00000002' => '1.1.1.2')
|
167
161
|
@nat_monitor.heartbeat
|
168
162
|
end
|
169
163
|
|
170
164
|
it 'tries to steal the route' do
|
171
|
-
allow(@nat_monitor).to receive(:other_nodes)
|
172
|
-
.and_return(@other_nodes)
|
173
165
|
expect(@nat_monitor).to receive(:steal_route)
|
174
166
|
@nat_monitor.heartbeat
|
175
167
|
end
|
168
|
+
|
169
|
+
it 'sends correct replace route command' do
|
170
|
+
expect(@nat_monitor.connection).to receive(:replace_route)
|
171
|
+
.with(@route_table_id, '0.0.0.0/0', @my_instance_id)
|
172
|
+
.and_return true
|
173
|
+
@nat_monitor.heartbeat
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context 'mocking and can\'t ping the master' do
|
178
|
+
before do
|
179
|
+
@nat_monitor.instance_variable_set(
|
180
|
+
:@conf,
|
181
|
+
@yaml_conf.merge('mocking' => true).merge(@defaults)
|
182
|
+
)
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'does not steal the route when mocking is enabled' do
|
186
|
+
expect(@nat_monitor.connection).to_not receive(:replace_route)
|
187
|
+
@nat_monitor.heartbeat
|
188
|
+
end
|
176
189
|
end
|
177
190
|
end
|
178
191
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nat-monitor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Herot
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|