Merge lp:~sseman/juju-chaos-monkey/description into lp:juju-chaos-monkey

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
Reviewer Review Type Date Requested Status
John George (community) Approve
Review via email: mp+258583@code.launchpad.net

Description of the change

Added a detailed description for each Chaos Monkey command.

To post a comment you must log in.
7. By Seman

Renamed a method name to test_create_chaos.

Revision history for this message
John George (jog) wrote :

I think this branch should include printing the new descriptions to the log.
We talked about that being done from ChaosMonkey._run_command.

I left some minor in-line comments related to formating and punctuation of the description strings.

Revision history for this message
Seman (sseman) wrote :

Thank John for your review. I made updates to all of your suggestions.

Revision history for this message
John George (jog) wrote :

Thank you.

review: Approve
8. By Seman

Added detailed descriptions for each chaos monkey command.

9. By Seman

Added detailed descriptions for each chaos monkey command.

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 enable=self.kill_jujud,
6 disable=None,
7 group=self.group,
8- command_str='jujud'))
9+ command_str='jujud',
10+ description='Jujud process has been killed.'))
11 chaos.append(
12 Chaos(
13 enable=self.kill_jujud,
14 disable=None,
15 group=self.group,
16- command_str='mongod'))
17+ command_str='mongod',
18+ description='Mongod process has been killed.'))
19 return chaos
20
21 def shutdown(self):
22
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 chaos.append(
28 self.create_chaos(
29 self.deny_all_incoming_and_outgoing_except_ssh,
30- self.allow_all_incoming_and_outgoing, 'deny-all'))
31+ self.allow_all_incoming_and_outgoing, 'deny-all',
32+ 'Deny all incoming and outgoing network traffic except ssh.'))
33 chaos.append(
34 self.create_chaos(
35 self.deny_all_incoming_except_ssh, self.allow_all_incoming,
36- 'deny-incoming'))
37+ 'deny-incoming',
38+ 'Deny all incoming network traffic except ssh.'))
39 chaos.append(
40 self.create_chaos(
41 self.deny_all_outgoing_except_ssh, self.allow_all_outgoing,
42- 'deny-outgoing'))
43- chaos.append(self.create_chaos(self.allow_ssh, None, 'allow-ssh'))
44+ 'deny-outgoing',
45+ 'Deny all outgoing network traffic except ssh.'))
46 chaos.append(
47 self.create_chaos(
48 self.deny_state_server, self.allow_state_server,
49- 'deny-state-server'))
50+ 'deny-state-server',
51+ 'Deny network traffic to the Juju State-Server'))
52 chaos.append(
53 self.create_chaos(
54 self.deny_api_server, self.allow_api_server,
55- 'deny-api-server'))
56+ 'deny-api-server',
57+ 'Deny network traffic to the Juju API Server.'))
58 chaos.append(
59 self.create_chaos(
60- self.deny_sys_log, self.allow_sys_log, 'deny-sys-log'))
61+ self.deny_sys_log, self.allow_sys_log, 'deny-sys-log',
62+ 'Deny network traffic to the Juju SysLog.'))
63 return chaos
64
65- def create_chaos(self, enable, disable, command_str):
66+ def create_chaos(self, enable, disable, command_str, description):
67 return Chaos(enable=enable, disable=disable, group=self.group,
68- command_str=command_str)
69+ command_str=command_str, description=description)
70
71 def shutdown(self):
72 self.reset()
73
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+import logging
79 import random
80 from time import sleep
81
82@@ -22,6 +23,14 @@
83 all_chaos, factory_obj = ChaosMonkey.get_all_chaos()
84 return cls([], factory_obj)
85
86+ @property
87+ def command_tag(self):
88+ return ":CHAOS_CMD:"
89+
90+ @property
91+ def description_tag(self):
92+ return ":CHAOS_DSCR:"
93+
94 @staticmethod
95 def get_all_chaos():
96 all_chaos = []
97@@ -89,6 +98,9 @@
98 group, command_str))
99
100 def _run_command(self, chaos, timeout=2):
101+ logging.info("%s %s %s %s" % (
102+ self.command_tag, chaos.command_str, self.description_tag,
103+ chaos.description))
104 chaos.enable()
105 sleep(timeout)
106 if chaos.disable:
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
113 class Chaos:
114
115- def __init__(self, enable, disable, group, command_str):
116+ def __init__(self, enable, disable, group, command_str, description):
117 self.enable = enable
118 self.disable = disable
119 self.group = group
120 self.command_str = command_str
121+ self.description = description
122
123 def __eq__(self, other):
124 return self.command_str == other.command_str
125
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 cm = ChaosMonkey.factory()
131 cm.include_group('all')
132 with patch('utility.check_output', autospec=True) as mock:
133- cm.run_chaos('net', 'allow-ssh', timeout=0)
134- mock.assert_called_once_with(['ufw', 'allow', 'ssh'])
135+ cm.run_chaos('net', 'deny-state-server', timeout=0)
136+ self.assertEqual(mock.mock_calls,
137+ [call(['ufw', 'deny', '37017']),
138+ call(['ufw', 'delete', 'deny', '37017'])])
139
140 def test_run_chaos_passes_timeout(self):
141 cm = ChaosMonkey.factory()
142 cm.include_group('all')
143 with patch('chaos_monkey.ChaosMonkey._run_command',
144 autospec=True) as mock:
145- cm.run_chaos('net', 'allow-ssh', timeout=0)
146+ cm.run_chaos('net', 'deny-all', timeout=0)
147 self.assertEqual(0, mock.call_args_list[0][1]['timeout'])
148
149 def test_run_chaos_raises_for_command_str(self):
150@@ -70,14 +72,14 @@
151 with patch('utility.check_output', autospec=True):
152 with self.assertRaisesRegexp(
153 NotFound,
154- "Command not found: group: bar command_str:allow-ssh"):
155- cm.run_chaos('bar', 'allow-ssh', timeout=0)
156+ "Command not found: group: bar command_str:deny-all"):
157+ cm.run_chaos('bar', 'deny-all', timeout=0)
158
159 def test_run_command(self):
160 cm = ChaosMonkey.factory()
161 net = Net()
162 chaos = Chaos(enable=net.deny_ssh, disable=net.allow_ssh,
163- group='net', command_str='deny-ssh')
164+ group='net', command_str='deny-ssh', description='fake')
165 with patch('utility.check_output', autospec=True) as mock:
166 cm._run_command(chaos, timeout=0)
167 self.assertEqual(mock.mock_calls, [
168@@ -173,7 +175,7 @@
169 all(c.command_str == 'deny-incoming' for c in cm.chaos))
170
171 def test_include_command_multiple_commands(self):
172- commands = ['deny-incoming', 'allow-ssh']
173+ commands = ['deny-incoming', 'deny-all']
174 cm = ChaosMonkey.factory()
175 cm.include_command(commands)
176 self.assertEqual(len(cm.chaos), 2)
177@@ -186,15 +188,15 @@
178 self.assertEqual(cm.chaos, [])
179
180 def test_exclude_command(self):
181- commands = ['allow-ssh']
182+ commands = ['deny-all']
183 cm = ChaosMonkey.factory()
184 cm.include_group('all')
185 cm.exclude_command(commands)
186 self.assertGreaterEqual(len(cm.chaos), 1)
187- self.assertTrue(all(c.command_str != 'allow-ssh' for c in cm.chaos))
188+ self.assertTrue(all(c.command_str != 'deny-all' for c in cm.chaos))
189
190 def test_exclude_commands(self):
191- commands = ['allow-ssh', 'jujud']
192+ commands = ['deny-all', 'jujud']
193 cm = ChaosMonkey.factory()
194 cm.include_group('all')
195 cm.exclude_command(commands)
196@@ -202,7 +204,7 @@
197 self.assertTrue(all(c.command_str not in commands for c in cm.chaos))
198
199 def test_include_and_exclude_commands(self):
200- commands = ['allow-ssh', 'jujud']
201+ commands = ['deny-all', 'jujud']
202 cm = ChaosMonkey.factory()
203 cm.include_command(commands)
204 self.assertGreaterEqual(len(cm.chaos), 1)
205@@ -250,7 +252,7 @@
206
207 def test_exclude_group_and_include_command(self):
208 groups = ['net']
209- commands = ['allow-ssh']
210+ commands = ['deny-all']
211 cm = ChaosMonkey.factory()
212 cm.include_group('all')
213 cm.exclude_group(groups)
214@@ -258,7 +260,7 @@
215 self.assertTrue(all(c.group != 'net' for c in cm.chaos))
216 cm.include_command(commands)
217 self.assertGreaterEqual(len(cm.chaos), 1)
218- self.assertTrue(any(c.command_str == 'allow-ssh' for c in cm.chaos))
219+ self.assertTrue(any(c.command_str == 'deny-all' for c in cm.chaos))
220 self.assertTrue(any(c.group == 'net' for c in cm.chaos))
221
222 def test_find_command(self):
223
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
229 def test_create_chaos(self):
230 net = Net()
231- chaos = net.create_chaos('enable', 'disable', 'command')
232+ chaos = net.create_chaos('enable', 'disable', 'command', 'description')
233 self.assertIs(type(chaos), Chaos)
234 self.assertEqual(chaos.enable, 'enable')
235 self.assertEqual(chaos.disable, 'disable')
236 self.assertEqual(chaos.group, 'net')
237 self.assertEqual(chaos.command_str, 'command')
238+ self.assertEqual(chaos.description, 'description')
239
240 def test_shutdown(self):
241 self._run_test('reset', ['ufw', 'reset'])
242@@ -126,5 +127,5 @@
243
244
245 def get_all_net_commands():
246- return ['deny-all', 'deny-incoming', 'deny-outgoing', 'allow-ssh',
247- 'deny-state-server', 'deny-api-server', 'deny-sys-log']
248+ return ['deny-all', 'deny-incoming', 'deny-outgoing', 'deny-state-server',
249+ 'deny-api-server', 'deny-sys-log']
250
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
256
257 def add_fake_group(chaos_monkey):
258- chaos = Chaos(None, None, 'fake_group', 'fake_command_str')
259+ chaos = Chaos(None, None, 'fake_group', 'fake_command_str', 'description')
260 chaos_monkey.append(chaos)

Subscribers

People subscribed via source and target branches