Merge lp:~sseman/juju-chaos-monkey/description into lp:juju-chaos-monkey
- description
- Merge into trunk
Proposed by
Seman
Status: | Merged |
---|---|
Merged at revision: | 9 |
Proposed branch: | lp:~sseman/juju-chaos-monkey/description |
Merge into: | lp:juju-chaos-monkey |
Prerequisite: | lp:~sseman/juju-chaos-monkey/add-state-server |
Diff against target: |
260 lines (+52/-29) 7 files modified
chaos/kill.py (+4/-2) chaos/net.py (+14/-9) chaos_monkey.py (+12/-0) chaos_monkey_base.py (+2/-1) tests/test_chaos_monkey.py (+15/-13) tests/test_net.py (+4/-3) tests/test_runner.py (+1/-1) |
To merge this branch: | bzr merge lp:~sseman/juju-chaos-monkey/description |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
John George (community) | Approve | ||
Review via email: mp+258583@code.launchpad.net |
Commit message
Description of the change
Added a detailed description for each Chaos Monkey command.
To post a comment you must log in.
Revision history for this message
John George (jog) wrote : | # |
Revision history for this message
Seman (sseman) wrote : | # |
Thank John for your review. I made updates to all of your suggestions.
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-04-30 22:19:31 +0000 | |||
3 | +++ chaos/kill.py 2015-05-10 22:05:29 +0000 | |||
4 | @@ -56,13 +56,15 @@ | |||
5 | 56 | enable=self.kill_jujud, | 56 | enable=self.kill_jujud, |
6 | 57 | disable=None, | 57 | disable=None, |
7 | 58 | group=self.group, | 58 | group=self.group, |
9 | 59 | command_str='jujud')) | 59 | command_str='jujud', |
10 | 60 | description='Jujud process has been killed.')) | ||
11 | 60 | chaos.append( | 61 | chaos.append( |
12 | 61 | Chaos( | 62 | Chaos( |
13 | 62 | enable=self.kill_jujud, | 63 | enable=self.kill_jujud, |
14 | 63 | disable=None, | 64 | disable=None, |
15 | 64 | group=self.group, | 65 | group=self.group, |
17 | 65 | command_str='mongod')) | 66 | command_str='mongod', |
18 | 67 | description='Mongod process has been killed.')) | ||
19 | 66 | return chaos | 68 | return chaos |
20 | 67 | 69 | ||
21 | 68 | def shutdown(self): | 70 | def shutdown(self): |
22 | 69 | 71 | ||
23 | === modified file 'chaos/net.py' | |||
24 | --- chaos/net.py 2015-05-07 22:44:14 +0000 | |||
25 | +++ chaos/net.py 2015-05-10 22:05:29 +0000 | |||
26 | @@ -116,32 +116,37 @@ | |||
27 | 116 | chaos.append( | 116 | chaos.append( |
28 | 117 | self.create_chaos( | 117 | self.create_chaos( |
29 | 118 | self.deny_all_incoming_and_outgoing_except_ssh, | 118 | self.deny_all_incoming_and_outgoing_except_ssh, |
31 | 119 | self.allow_all_incoming_and_outgoing, 'deny-all')) | 119 | self.allow_all_incoming_and_outgoing, 'deny-all', |
32 | 120 | 'Deny all incoming and outgoing network traffic except ssh.')) | ||
33 | 120 | chaos.append( | 121 | chaos.append( |
34 | 121 | self.create_chaos( | 122 | self.create_chaos( |
35 | 122 | self.deny_all_incoming_except_ssh, self.allow_all_incoming, | 123 | self.deny_all_incoming_except_ssh, self.allow_all_incoming, |
37 | 123 | 'deny-incoming')) | 124 | 'deny-incoming', |
38 | 125 | 'Deny all incoming network traffic except ssh.')) | ||
39 | 124 | chaos.append( | 126 | chaos.append( |
40 | 125 | self.create_chaos( | 127 | self.create_chaos( |
41 | 126 | self.deny_all_outgoing_except_ssh, self.allow_all_outgoing, | 128 | self.deny_all_outgoing_except_ssh, self.allow_all_outgoing, |
44 | 127 | 'deny-outgoing')) | 129 | 'deny-outgoing', |
45 | 128 | chaos.append(self.create_chaos(self.allow_ssh, None, 'allow-ssh')) | 130 | 'Deny all outgoing network traffic except ssh.')) |
46 | 129 | chaos.append( | 131 | chaos.append( |
47 | 130 | self.create_chaos( | 132 | self.create_chaos( |
48 | 131 | self.deny_state_server, self.allow_state_server, | 133 | self.deny_state_server, self.allow_state_server, |
50 | 132 | 'deny-state-server')) | 134 | 'deny-state-server', |
51 | 135 | 'Deny network traffic to the Juju State-Server')) | ||
52 | 133 | chaos.append( | 136 | chaos.append( |
53 | 134 | self.create_chaos( | 137 | self.create_chaos( |
54 | 135 | self.deny_api_server, self.allow_api_server, | 138 | self.deny_api_server, self.allow_api_server, |
56 | 136 | 'deny-api-server')) | 139 | 'deny-api-server', |
57 | 140 | 'Deny network traffic to the Juju API Server.')) | ||
58 | 137 | chaos.append( | 141 | chaos.append( |
59 | 138 | self.create_chaos( | 142 | self.create_chaos( |
61 | 139 | self.deny_sys_log, self.allow_sys_log, 'deny-sys-log')) | 143 | self.deny_sys_log, self.allow_sys_log, 'deny-sys-log', |
62 | 144 | 'Deny network traffic to the Juju SysLog.')) | ||
63 | 140 | return chaos | 145 | return chaos |
64 | 141 | 146 | ||
66 | 142 | def create_chaos(self, enable, disable, command_str): | 147 | def create_chaos(self, enable, disable, command_str, description): |
67 | 143 | return Chaos(enable=enable, disable=disable, group=self.group, | 148 | return Chaos(enable=enable, disable=disable, group=self.group, |
69 | 144 | command_str=command_str) | 149 | command_str=command_str, description=description) |
70 | 145 | 150 | ||
71 | 146 | def shutdown(self): | 151 | def shutdown(self): |
72 | 147 | self.reset() | 152 | self.reset() |
73 | 148 | 153 | ||
74 | === modified file 'chaos_monkey.py' | |||
75 | --- chaos_monkey.py 2015-05-05 19:09:12 +0000 | |||
76 | +++ chaos_monkey.py 2015-05-10 22:05:29 +0000 | |||
77 | @@ -1,3 +1,4 @@ | |||
78 | 1 | import logging | ||
79 | 1 | import random | 2 | import random |
80 | 2 | from time import sleep | 3 | from time import sleep |
81 | 3 | 4 | ||
82 | @@ -22,6 +23,14 @@ | |||
83 | 22 | all_chaos, factory_obj = ChaosMonkey.get_all_chaos() | 23 | all_chaos, factory_obj = ChaosMonkey.get_all_chaos() |
84 | 23 | return cls([], factory_obj) | 24 | return cls([], factory_obj) |
85 | 24 | 25 | ||
86 | 26 | @property | ||
87 | 27 | def command_tag(self): | ||
88 | 28 | return ":CHAOS_CMD:" | ||
89 | 29 | |||
90 | 30 | @property | ||
91 | 31 | def description_tag(self): | ||
92 | 32 | return ":CHAOS_DSCR:" | ||
93 | 33 | |||
94 | 25 | @staticmethod | 34 | @staticmethod |
95 | 26 | def get_all_chaos(): | 35 | def get_all_chaos(): |
96 | 27 | all_chaos = [] | 36 | all_chaos = [] |
97 | @@ -89,6 +98,9 @@ | |||
98 | 89 | group, command_str)) | 98 | group, command_str)) |
99 | 90 | 99 | ||
100 | 91 | def _run_command(self, chaos, timeout=2): | 100 | def _run_command(self, chaos, timeout=2): |
101 | 101 | logging.info("%s %s %s %s" % ( | ||
102 | 102 | self.command_tag, chaos.command_str, self.description_tag, | ||
103 | 103 | chaos.description)) | ||
104 | 92 | chaos.enable() | 104 | chaos.enable() |
105 | 93 | sleep(timeout) | 105 | sleep(timeout) |
106 | 94 | if chaos.disable: | 106 | if chaos.disable: |
107 | 95 | 107 | ||
108 | === modified file 'chaos_monkey_base.py' | |||
109 | --- chaos_monkey_base.py 2015-05-04 07:03:50 +0000 | |||
110 | +++ chaos_monkey_base.py 2015-05-10 22:05:29 +0000 | |||
111 | @@ -20,11 +20,12 @@ | |||
112 | 20 | 20 | ||
113 | 21 | class Chaos: | 21 | class Chaos: |
114 | 22 | 22 | ||
116 | 23 | def __init__(self, enable, disable, group, command_str): | 23 | def __init__(self, enable, disable, group, command_str, description): |
117 | 24 | self.enable = enable | 24 | self.enable = enable |
118 | 25 | self.disable = disable | 25 | self.disable = disable |
119 | 26 | self.group = group | 26 | self.group = group |
120 | 27 | self.command_str = command_str | 27 | self.command_str = command_str |
121 | 28 | self.description = description | ||
122 | 28 | 29 | ||
123 | 29 | def __eq__(self, other): | 30 | def __eq__(self, other): |
124 | 30 | return self.command_str == other.command_str | 31 | return self.command_str == other.command_str |
125 | 31 | 32 | ||
126 | === modified file 'tests/test_chaos_monkey.py' | |||
127 | --- tests/test_chaos_monkey.py 2015-05-07 22:44:14 +0000 | |||
128 | +++ tests/test_chaos_monkey.py 2015-05-10 22:05:29 +0000 | |||
129 | @@ -44,15 +44,17 @@ | |||
130 | 44 | cm = ChaosMonkey.factory() | 44 | cm = ChaosMonkey.factory() |
131 | 45 | cm.include_group('all') | 45 | cm.include_group('all') |
132 | 46 | with patch('utility.check_output', autospec=True) as mock: | 46 | with patch('utility.check_output', autospec=True) as mock: |
135 | 47 | cm.run_chaos('net', 'allow-ssh', timeout=0) | 47 | cm.run_chaos('net', 'deny-state-server', timeout=0) |
136 | 48 | mock.assert_called_once_with(['ufw', 'allow', 'ssh']) | 48 | self.assertEqual(mock.mock_calls, |
137 | 49 | [call(['ufw', 'deny', '37017']), | ||
138 | 50 | call(['ufw', 'delete', 'deny', '37017'])]) | ||
139 | 49 | 51 | ||
140 | 50 | def test_run_chaos_passes_timeout(self): | 52 | def test_run_chaos_passes_timeout(self): |
141 | 51 | cm = ChaosMonkey.factory() | 53 | cm = ChaosMonkey.factory() |
142 | 52 | cm.include_group('all') | 54 | cm.include_group('all') |
143 | 53 | with patch('chaos_monkey.ChaosMonkey._run_command', | 55 | with patch('chaos_monkey.ChaosMonkey._run_command', |
144 | 54 | autospec=True) as mock: | 56 | autospec=True) as mock: |
146 | 55 | cm.run_chaos('net', 'allow-ssh', timeout=0) | 57 | cm.run_chaos('net', 'deny-all', timeout=0) |
147 | 56 | self.assertEqual(0, mock.call_args_list[0][1]['timeout']) | 58 | self.assertEqual(0, mock.call_args_list[0][1]['timeout']) |
148 | 57 | 59 | ||
149 | 58 | def test_run_chaos_raises_for_command_str(self): | 60 | def test_run_chaos_raises_for_command_str(self): |
150 | @@ -70,14 +72,14 @@ | |||
151 | 70 | with patch('utility.check_output', autospec=True): | 72 | with patch('utility.check_output', autospec=True): |
152 | 71 | with self.assertRaisesRegexp( | 73 | with self.assertRaisesRegexp( |
153 | 72 | NotFound, | 74 | NotFound, |
156 | 73 | "Command not found: group: bar command_str:allow-ssh"): | 75 | "Command not found: group: bar command_str:deny-all"): |
157 | 74 | cm.run_chaos('bar', 'allow-ssh', timeout=0) | 76 | cm.run_chaos('bar', 'deny-all', timeout=0) |
158 | 75 | 77 | ||
159 | 76 | def test_run_command(self): | 78 | def test_run_command(self): |
160 | 77 | cm = ChaosMonkey.factory() | 79 | cm = ChaosMonkey.factory() |
161 | 78 | net = Net() | 80 | net = Net() |
162 | 79 | chaos = Chaos(enable=net.deny_ssh, disable=net.allow_ssh, | 81 | chaos = Chaos(enable=net.deny_ssh, disable=net.allow_ssh, |
164 | 80 | group='net', command_str='deny-ssh') | 82 | group='net', command_str='deny-ssh', description='fake') |
165 | 81 | with patch('utility.check_output', autospec=True) as mock: | 83 | with patch('utility.check_output', autospec=True) as mock: |
166 | 82 | cm._run_command(chaos, timeout=0) | 84 | cm._run_command(chaos, timeout=0) |
167 | 83 | self.assertEqual(mock.mock_calls, [ | 85 | self.assertEqual(mock.mock_calls, [ |
168 | @@ -173,7 +175,7 @@ | |||
169 | 173 | all(c.command_str == 'deny-incoming' for c in cm.chaos)) | 175 | all(c.command_str == 'deny-incoming' for c in cm.chaos)) |
170 | 174 | 176 | ||
171 | 175 | def test_include_command_multiple_commands(self): | 177 | def test_include_command_multiple_commands(self): |
173 | 176 | commands = ['deny-incoming', 'allow-ssh'] | 178 | commands = ['deny-incoming', 'deny-all'] |
174 | 177 | cm = ChaosMonkey.factory() | 179 | cm = ChaosMonkey.factory() |
175 | 178 | cm.include_command(commands) | 180 | cm.include_command(commands) |
176 | 179 | self.assertEqual(len(cm.chaos), 2) | 181 | self.assertEqual(len(cm.chaos), 2) |
177 | @@ -186,15 +188,15 @@ | |||
178 | 186 | self.assertEqual(cm.chaos, []) | 188 | self.assertEqual(cm.chaos, []) |
179 | 187 | 189 | ||
180 | 188 | def test_exclude_command(self): | 190 | def test_exclude_command(self): |
182 | 189 | commands = ['allow-ssh'] | 191 | commands = ['deny-all'] |
183 | 190 | cm = ChaosMonkey.factory() | 192 | cm = ChaosMonkey.factory() |
184 | 191 | cm.include_group('all') | 193 | cm.include_group('all') |
185 | 192 | cm.exclude_command(commands) | 194 | cm.exclude_command(commands) |
186 | 193 | self.assertGreaterEqual(len(cm.chaos), 1) | 195 | self.assertGreaterEqual(len(cm.chaos), 1) |
188 | 194 | self.assertTrue(all(c.command_str != 'allow-ssh' for c in cm.chaos)) | 196 | self.assertTrue(all(c.command_str != 'deny-all' for c in cm.chaos)) |
189 | 195 | 197 | ||
190 | 196 | def test_exclude_commands(self): | 198 | def test_exclude_commands(self): |
192 | 197 | commands = ['allow-ssh', 'jujud'] | 199 | commands = ['deny-all', 'jujud'] |
193 | 198 | cm = ChaosMonkey.factory() | 200 | cm = ChaosMonkey.factory() |
194 | 199 | cm.include_group('all') | 201 | cm.include_group('all') |
195 | 200 | cm.exclude_command(commands) | 202 | cm.exclude_command(commands) |
196 | @@ -202,7 +204,7 @@ | |||
197 | 202 | self.assertTrue(all(c.command_str not in commands for c in cm.chaos)) | 204 | self.assertTrue(all(c.command_str not in commands for c in cm.chaos)) |
198 | 203 | 205 | ||
199 | 204 | def test_include_and_exclude_commands(self): | 206 | def test_include_and_exclude_commands(self): |
201 | 205 | commands = ['allow-ssh', 'jujud'] | 207 | commands = ['deny-all', 'jujud'] |
202 | 206 | cm = ChaosMonkey.factory() | 208 | cm = ChaosMonkey.factory() |
203 | 207 | cm.include_command(commands) | 209 | cm.include_command(commands) |
204 | 208 | self.assertGreaterEqual(len(cm.chaos), 1) | 210 | self.assertGreaterEqual(len(cm.chaos), 1) |
205 | @@ -250,7 +252,7 @@ | |||
206 | 250 | 252 | ||
207 | 251 | def test_exclude_group_and_include_command(self): | 253 | def test_exclude_group_and_include_command(self): |
208 | 252 | groups = ['net'] | 254 | groups = ['net'] |
210 | 253 | commands = ['allow-ssh'] | 255 | commands = ['deny-all'] |
211 | 254 | cm = ChaosMonkey.factory() | 256 | cm = ChaosMonkey.factory() |
212 | 255 | cm.include_group('all') | 257 | cm.include_group('all') |
213 | 256 | cm.exclude_group(groups) | 258 | cm.exclude_group(groups) |
214 | @@ -258,7 +260,7 @@ | |||
215 | 258 | self.assertTrue(all(c.group != 'net' for c in cm.chaos)) | 260 | self.assertTrue(all(c.group != 'net' for c in cm.chaos)) |
216 | 259 | cm.include_command(commands) | 261 | cm.include_command(commands) |
217 | 260 | self.assertGreaterEqual(len(cm.chaos), 1) | 262 | self.assertGreaterEqual(len(cm.chaos), 1) |
219 | 261 | self.assertTrue(any(c.command_str == 'allow-ssh' for c in cm.chaos)) | 263 | self.assertTrue(any(c.command_str == 'deny-all' for c in cm.chaos)) |
220 | 262 | self.assertTrue(any(c.group == 'net' for c in cm.chaos)) | 264 | self.assertTrue(any(c.group == 'net' for c in cm.chaos)) |
221 | 263 | 265 | ||
222 | 264 | def test_find_command(self): | 266 | def test_find_command(self): |
223 | 265 | 267 | ||
224 | === modified file 'tests/test_net.py' | |||
225 | --- tests/test_net.py 2015-05-08 18:29:03 +0000 | |||
226 | +++ tests/test_net.py 2015-05-10 22:05:29 +0000 | |||
227 | @@ -105,12 +105,13 @@ | |||
228 | 105 | 105 | ||
229 | 106 | def test_create_chaos(self): | 106 | def test_create_chaos(self): |
230 | 107 | net = Net() | 107 | net = Net() |
232 | 108 | chaos = net.create_chaos('enable', 'disable', 'command') | 108 | chaos = net.create_chaos('enable', 'disable', 'command', 'description') |
233 | 109 | self.assertIs(type(chaos), Chaos) | 109 | self.assertIs(type(chaos), Chaos) |
234 | 110 | self.assertEqual(chaos.enable, 'enable') | 110 | self.assertEqual(chaos.enable, 'enable') |
235 | 111 | self.assertEqual(chaos.disable, 'disable') | 111 | self.assertEqual(chaos.disable, 'disable') |
236 | 112 | self.assertEqual(chaos.group, 'net') | 112 | self.assertEqual(chaos.group, 'net') |
237 | 113 | self.assertEqual(chaos.command_str, 'command') | 113 | self.assertEqual(chaos.command_str, 'command') |
238 | 114 | self.assertEqual(chaos.description, 'description') | ||
239 | 114 | 115 | ||
240 | 115 | def test_shutdown(self): | 116 | def test_shutdown(self): |
241 | 116 | self._run_test('reset', ['ufw', 'reset']) | 117 | self._run_test('reset', ['ufw', 'reset']) |
242 | @@ -126,5 +127,5 @@ | |||
243 | 126 | 127 | ||
244 | 127 | 128 | ||
245 | 128 | def get_all_net_commands(): | 129 | def get_all_net_commands(): |
248 | 129 | return ['deny-all', 'deny-incoming', 'deny-outgoing', 'allow-ssh', | 130 | return ['deny-all', 'deny-incoming', 'deny-outgoing', 'deny-state-server', |
249 | 130 | 'deny-state-server', 'deny-api-server', 'deny-sys-log'] | 131 | 'deny-api-server', 'deny-sys-log'] |
250 | 131 | 132 | ||
251 | === modified file 'tests/test_runner.py' | |||
252 | --- tests/test_runner.py 2015-05-05 19:09:12 +0000 | |||
253 | +++ tests/test_runner.py 2015-05-10 22:05:29 +0000 | |||
254 | @@ -258,5 +258,5 @@ | |||
255 | 258 | 258 | ||
256 | 259 | 259 | ||
257 | 260 | def add_fake_group(chaos_monkey): | 260 | def add_fake_group(chaos_monkey): |
259 | 261 | chaos = Chaos(None, None, 'fake_group', 'fake_command_str') | 261 | chaos = Chaos(None, None, 'fake_group', 'fake_command_str', 'description') |
260 | 262 | chaos_monkey.append(chaos) | 262 | chaos_monkey.append(chaos) |
I think this branch should include printing the new descriptions to the log. _run_command.
We talked about that being done from ChaosMonkey.
I left some minor in-line comments related to formating and punctuation of the description strings.