Merge lp:~sseman/juju-chaos-monkey/force-enable into lp:juju-chaos-monkey

Proposed by Seman
Status: Merged
Merged at revision: 14
Proposed branch: lp:~sseman/juju-chaos-monkey/force-enable
Merge into: lp:juju-chaos-monkey
Diff against target: 200 lines (+57/-14)
5 files modified
chaos/kill.py (+3/-3)
chaos/net.py (+2/-2)
tests/test_chaos_monkey.py (+3/-3)
tests/test_kill.py (+44/-3)
tests/test_net.py (+5/-3)
To merge this branch: bzr merge lp:~sseman/juju-chaos-monkey/force-enable
Reviewer Review Type Date Requested Status
John George (community) Approve
Review via email: mp+259186@code.launchpad.net

Description of the change

This branch adds --force when ufw enable and reset commands are executed. It also fixes the issue of killing jujud process instead of mongod process.

To post a comment you must log in.
Revision history for this message
John George (jog) wrote :

Thank you

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'chaos/kill.py'
2--- chaos/kill.py 2015-05-11 08:12:38 +0000
3+++ chaos/kill.py 2015-05-15 00:10:58 +0000
4@@ -24,10 +24,10 @@
5 return cls()
6
7 def get_pids(self, process):
8- pids = run_shell_command('pidof ' + process)
9+ pids = run_shell_command('pidof ' + process, quiet_mode=True)
10 if not pids:
11 return None
12- return pids.split(' ')
13+ return pids.strip().split(' ')
14
15 def kill_jujud(self, quiet_mode=True):
16 pids = self.get_pids('jujud')
17@@ -58,7 +58,7 @@
18 description='Jujud process has been killed.'))
19 chaos.append(
20 Chaos(
21- enable=self.kill_jujud,
22+ enable=self.kill_mongodb,
23 disable=None,
24 group=self.group,
25 command_str='mongod',
26
27=== modified file 'chaos/net.py'
28--- chaos/net.py 2015-05-11 08:12:38 +0000
29+++ chaos/net.py 2015-05-15 00:10:58 +0000
30@@ -45,7 +45,7 @@
31 return 'ufw delete deny out to any'
32
33 def reset(self):
34- cmd = 'ufw reset'
35+ cmd = 'ufw --force reset'
36 self.run_command(cmd)
37
38 def deny_all_incoming_and_outgoing_except_ssh(self):
39@@ -101,7 +101,7 @@
40 self.allow_port(6514)
41
42 def enable_ufw(self):
43- cmd = 'ufw enable'
44+ cmd = 'ufw --force enable'
45 run_shell_command(cmd)
46
47 def disable_ufw(self):
48
49=== modified file 'tests/test_chaos_monkey.py'
50--- tests/test_chaos_monkey.py 2015-05-12 06:06:59 +0000
51+++ tests/test_chaos_monkey.py 2015-05-15 00:10:58 +0000
52@@ -50,7 +50,7 @@
53 cm.run_chaos('net', 'deny-state-server', timeout=0)
54 self.assertEqual(mock.mock_calls, [
55 call(['ufw', 'default', 'allow']),
56- call(['ufw', 'deny', '37017']), call(['ufw', 'enable']),
57+ call(['ufw', 'deny', '37017']), call(['ufw', '--force', 'enable']),
58 call(['ufw', 'delete', 'deny', '37017']),
59 call(['ufw', 'disable'])])
60
61@@ -90,7 +90,7 @@
62 cm._run_command(chaos, timeout=0)
63 self.assertEqual(mock.mock_calls, [
64 call(['ufw', 'default', 'allow']),
65- call(['ufw', 'deny', '37017']), call(['ufw', 'enable']),
66+ call(['ufw', 'deny', '37017']), call(['ufw', '--force', 'enable']),
67 call(['ufw', 'delete', 'deny', '37017']),
68 call(['ufw', 'disable'])])
69
70@@ -98,7 +98,7 @@
71 cm = ChaosMonkey.factory()
72 with patch('utility.check_output', autospec=True) as mock:
73 cm.shutdown()
74- mock.assert_any_call(['ufw', 'reset'])
75+ mock.assert_any_call(['ufw', '--force', 'reset'])
76
77 def test_include_group(self):
78 group = ['net']
79
80=== modified file 'tests/test_kill.py'
81--- tests/test_kill.py 2015-05-12 05:59:22 +0000
82+++ tests/test_kill.py 2015-05-15 00:10:58 +0000
83@@ -1,3 +1,5 @@
84+from subprocess import CalledProcessError
85+
86 from mock import patch, call
87
88 from chaos.kill import Kill
89@@ -12,37 +14,76 @@
90 def test_get_pids(self):
91 kill = Kill()
92 with patch('utility.check_output', autospec=True,
93- return_value='1234 2345') as mock:
94+ return_value='1234 2345\n') as mock:
95 pids = kill.get_pids('jujud')
96 self.assertEqual(pids, ['1234', '2345'])
97 mock.assert_called_once_with(['pidof', 'jujud'])
98
99+ def test_get_pids_no_process(self):
100+ kill = Kill()
101+ with patch('utility.check_output', autospec=True,
102+ side_effect=CalledProcessError(1, 'pidof fake')) as mock:
103+ pids = kill.get_pids('fake')
104+ self.assertEqual(pids, None)
105+ mock.assert_called_once_with(['pidof', 'fake'])
106+
107 def test_kill_jujud(self):
108 kill = Kill()
109 with patch('utility.check_output', autospec=True,
110- return_value='1234 2345') as mock:
111+ return_value='1234 2345\n') as mock:
112 kill.kill_jujud()
113 self.assertEqual(mock.mock_calls, [
114 call(['pidof', 'jujud']),
115 call(['kill', '-s', 'SIGKILL', '1234'])
116 ])
117
118+ def test_kill_jujud_single_process(self):
119+ kill = Kill()
120+ with patch('utility.check_output', autospec=True,
121+ return_value='2345\n') as mock:
122+ kill.kill_jujud()
123+ self.assertEqual(mock.mock_calls, [
124+ call(['pidof', 'jujud']),
125+ call(['kill', '-s', 'SIGKILL', '2345'])
126+ ])
127+
128 def test_kill_mongodb(self):
129 kill = Kill()
130 with patch('utility.check_output', autospec=True,
131- return_value='1234 2345') as mock:
132+ return_value='1234 2345\n') as mock:
133 kill.kill_mongodb()
134 self.assertEqual(mock.mock_calls, [
135 call(['pidof', 'mongod']),
136 call(['kill', '-s', 'SIGKILL', '1234'])
137 ])
138
139+ def test_kill_mongodb_single_process(self):
140+ kill = Kill()
141+ with patch('utility.check_output', autospec=True,
142+ return_value='2345\n') as mock:
143+ kill.kill_mongodb()
144+ self.assertEqual(mock.mock_calls, [
145+ call(['pidof', 'mongod']),
146+ call(['kill', '-s', 'SIGKILL', '2345'])
147+ ])
148+
149 def test_get_chaos(self):
150 kill = Kill()
151 chaos = kill.get_chaos()
152 self.assertItemsEqual(
153 self.get_command_str(chaos), get_all_kill_commands())
154
155+ def test_get_chaos_verify_method_calls(self):
156+ kill = Kill()
157+ chaos = kill.get_chaos()
158+ for c in chaos:
159+ if c.command_str == 'mongod':
160+ self.assertEqual(c.enable, kill.kill_mongodb)
161+ if c.command_str == 'jujud':
162+ self.assertEqual(c.enable, kill.kill_jujud)
163+ self.assertEqual(c.group, 'kill')
164+ self.assertEqual(c.disable, None)
165+
166
167 def get_all_kill_commands():
168 return ['jujud', 'mongod']
169
170=== modified file 'tests/test_net.py'
171--- tests/test_net.py 2015-05-12 05:59:22 +0000
172+++ tests/test_net.py 2015-05-15 00:10:58 +0000
173@@ -13,7 +13,8 @@
174 self.setup_test_logging()
175
176 def test_reset(self):
177- self._assert_mock_calls('shutdown', [call(['ufw', 'reset'])])
178+ self._assert_mock_calls(
179+ 'shutdown', [call(['ufw', '--force', 'reset'])])
180
181 def test_deny_all_incoming_and_outgoing_except_ssh(self):
182 cmd = ['allow_ssh_str', 'default_deny_str', 'deny_out_to_any_str']
183@@ -105,7 +106,8 @@
184 self.assertEqual(chaos.description, 'description')
185
186 def test_shutdown(self):
187- self._assert_mock_calls('shutdown', [call(['ufw', 'reset'])])
188+ self._assert_mock_calls(
189+ 'shutdown', [call(['ufw', '--force', 'reset'])])
190
191 def _assert_mock_calls(self, method_call, call_list, **kwargs):
192 net = Net()
193@@ -121,7 +123,7 @@
194 cmd_calls = [call(getattr(net, attr).split(' ')) for attr in attrs]
195 else:
196 cmd_calls = [call(attrs.split(' '))]
197- enable_call = ([call(['ufw', 'enable'])]
198+ enable_call = ([call(['ufw', '--force', 'enable'])]
199 if enable else [call(['ufw', 'disable'])])
200 return default_allow_call + cmd_calls + enable_call
201

Subscribers

People subscribed via source and target branches