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
=== modified file 'chaos/kill.py'
--- chaos/kill.py 2015-04-30 22:19:31 +0000
+++ chaos/kill.py 2015-05-10 22:05:29 +0000
@@ -56,13 +56,15 @@
56 enable=self.kill_jujud,56 enable=self.kill_jujud,
57 disable=None,57 disable=None,
58 group=self.group,58 group=self.group,
59 command_str='jujud'))59 command_str='jujud',
60 description='Jujud process has been killed.'))
60 chaos.append(61 chaos.append(
61 Chaos(62 Chaos(
62 enable=self.kill_jujud,63 enable=self.kill_jujud,
63 disable=None,64 disable=None,
64 group=self.group,65 group=self.group,
65 command_str='mongod'))66 command_str='mongod',
67 description='Mongod process has been killed.'))
66 return chaos68 return chaos
6769
68 def shutdown(self):70 def shutdown(self):
6971
=== modified file 'chaos/net.py'
--- chaos/net.py 2015-05-07 22:44:14 +0000
+++ chaos/net.py 2015-05-10 22:05:29 +0000
@@ -116,32 +116,37 @@
116 chaos.append(116 chaos.append(
117 self.create_chaos(117 self.create_chaos(
118 self.deny_all_incoming_and_outgoing_except_ssh,118 self.deny_all_incoming_and_outgoing_except_ssh,
119 self.allow_all_incoming_and_outgoing, 'deny-all'))119 self.allow_all_incoming_and_outgoing, 'deny-all',
120 'Deny all incoming and outgoing network traffic except ssh.'))
120 chaos.append(121 chaos.append(
121 self.create_chaos(122 self.create_chaos(
122 self.deny_all_incoming_except_ssh, self.allow_all_incoming,123 self.deny_all_incoming_except_ssh, self.allow_all_incoming,
123 'deny-incoming'))124 'deny-incoming',
125 'Deny all incoming network traffic except ssh.'))
124 chaos.append(126 chaos.append(
125 self.create_chaos(127 self.create_chaos(
126 self.deny_all_outgoing_except_ssh, self.allow_all_outgoing,128 self.deny_all_outgoing_except_ssh, self.allow_all_outgoing,
127 'deny-outgoing'))129 'deny-outgoing',
128 chaos.append(self.create_chaos(self.allow_ssh, None, 'allow-ssh'))130 'Deny all outgoing network traffic except ssh.'))
129 chaos.append(131 chaos.append(
130 self.create_chaos(132 self.create_chaos(
131 self.deny_state_server, self.allow_state_server,133 self.deny_state_server, self.allow_state_server,
132 'deny-state-server'))134 'deny-state-server',
135 'Deny network traffic to the Juju State-Server'))
133 chaos.append(136 chaos.append(
134 self.create_chaos(137 self.create_chaos(
135 self.deny_api_server, self.allow_api_server,138 self.deny_api_server, self.allow_api_server,
136 'deny-api-server'))139 'deny-api-server',
140 'Deny network traffic to the Juju API Server.'))
137 chaos.append(141 chaos.append(
138 self.create_chaos(142 self.create_chaos(
139 self.deny_sys_log, self.allow_sys_log, 'deny-sys-log'))143 self.deny_sys_log, self.allow_sys_log, 'deny-sys-log',
144 'Deny network traffic to the Juju SysLog.'))
140 return chaos145 return chaos
141146
142 def create_chaos(self, enable, disable, command_str):147 def create_chaos(self, enable, disable, command_str, description):
143 return Chaos(enable=enable, disable=disable, group=self.group,148 return Chaos(enable=enable, disable=disable, group=self.group,
144 command_str=command_str)149 command_str=command_str, description=description)
145150
146 def shutdown(self):151 def shutdown(self):
147 self.reset()152 self.reset()
148153
=== modified file 'chaos_monkey.py'
--- chaos_monkey.py 2015-05-05 19:09:12 +0000
+++ chaos_monkey.py 2015-05-10 22:05:29 +0000
@@ -1,3 +1,4 @@
1import logging
1import random2import random
2from time import sleep3from time import sleep
34
@@ -22,6 +23,14 @@
22 all_chaos, factory_obj = ChaosMonkey.get_all_chaos()23 all_chaos, factory_obj = ChaosMonkey.get_all_chaos()
23 return cls([], factory_obj)24 return cls([], factory_obj)
2425
26 @property
27 def command_tag(self):
28 return ":CHAOS_CMD:"
29
30 @property
31 def description_tag(self):
32 return ":CHAOS_DSCR:"
33
25 @staticmethod34 @staticmethod
26 def get_all_chaos():35 def get_all_chaos():
27 all_chaos = []36 all_chaos = []
@@ -89,6 +98,9 @@
89 group, command_str))98 group, command_str))
9099
91 def _run_command(self, chaos, timeout=2):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))
92 chaos.enable()104 chaos.enable()
93 sleep(timeout)105 sleep(timeout)
94 if chaos.disable:106 if chaos.disable:
95107
=== modified file 'chaos_monkey_base.py'
--- chaos_monkey_base.py 2015-05-04 07:03:50 +0000
+++ chaos_monkey_base.py 2015-05-10 22:05:29 +0000
@@ -20,11 +20,12 @@
2020
21class Chaos:21class Chaos:
2222
23 def __init__(self, enable, disable, group, command_str):23 def __init__(self, enable, disable, group, command_str, description):
24 self.enable = enable24 self.enable = enable
25 self.disable = disable25 self.disable = disable
26 self.group = group26 self.group = group
27 self.command_str = command_str27 self.command_str = command_str
28 self.description = description
2829
29 def __eq__(self, other):30 def __eq__(self, other):
30 return self.command_str == other.command_str31 return self.command_str == other.command_str
3132
=== modified file 'tests/test_chaos_monkey.py'
--- tests/test_chaos_monkey.py 2015-05-07 22:44:14 +0000
+++ tests/test_chaos_monkey.py 2015-05-10 22:05:29 +0000
@@ -44,15 +44,17 @@
44 cm = ChaosMonkey.factory()44 cm = ChaosMonkey.factory()
45 cm.include_group('all')45 cm.include_group('all')
46 with patch('utility.check_output', autospec=True) as mock:46 with patch('utility.check_output', autospec=True) as mock:
47 cm.run_chaos('net', 'allow-ssh', timeout=0)47 cm.run_chaos('net', 'deny-state-server', timeout=0)
48 mock.assert_called_once_with(['ufw', 'allow', 'ssh'])48 self.assertEqual(mock.mock_calls,
49 [call(['ufw', 'deny', '37017']),
50 call(['ufw', 'delete', 'deny', '37017'])])
4951
50 def test_run_chaos_passes_timeout(self):52 def test_run_chaos_passes_timeout(self):
51 cm = ChaosMonkey.factory()53 cm = ChaosMonkey.factory()
52 cm.include_group('all')54 cm.include_group('all')
53 with patch('chaos_monkey.ChaosMonkey._run_command',55 with patch('chaos_monkey.ChaosMonkey._run_command',
54 autospec=True) as mock:56 autospec=True) as mock:
55 cm.run_chaos('net', 'allow-ssh', timeout=0)57 cm.run_chaos('net', 'deny-all', timeout=0)
56 self.assertEqual(0, mock.call_args_list[0][1]['timeout'])58 self.assertEqual(0, mock.call_args_list[0][1]['timeout'])
5759
58 def test_run_chaos_raises_for_command_str(self):60 def test_run_chaos_raises_for_command_str(self):
@@ -70,14 +72,14 @@
70 with patch('utility.check_output', autospec=True):72 with patch('utility.check_output', autospec=True):
71 with self.assertRaisesRegexp(73 with self.assertRaisesRegexp(
72 NotFound,74 NotFound,
73 "Command not found: group: bar command_str:allow-ssh"):75 "Command not found: group: bar command_str:deny-all"):
74 cm.run_chaos('bar', 'allow-ssh', timeout=0)76 cm.run_chaos('bar', 'deny-all', timeout=0)
7577
76 def test_run_command(self):78 def test_run_command(self):
77 cm = ChaosMonkey.factory()79 cm = ChaosMonkey.factory()
78 net = Net()80 net = Net()
79 chaos = Chaos(enable=net.deny_ssh, disable=net.allow_ssh,81 chaos = Chaos(enable=net.deny_ssh, disable=net.allow_ssh,
80 group='net', command_str='deny-ssh')82 group='net', command_str='deny-ssh', description='fake')
81 with patch('utility.check_output', autospec=True) as mock:83 with patch('utility.check_output', autospec=True) as mock:
82 cm._run_command(chaos, timeout=0)84 cm._run_command(chaos, timeout=0)
83 self.assertEqual(mock.mock_calls, [85 self.assertEqual(mock.mock_calls, [
@@ -173,7 +175,7 @@
173 all(c.command_str == 'deny-incoming' for c in cm.chaos))175 all(c.command_str == 'deny-incoming' for c in cm.chaos))
174176
175 def test_include_command_multiple_commands(self):177 def test_include_command_multiple_commands(self):
176 commands = ['deny-incoming', 'allow-ssh']178 commands = ['deny-incoming', 'deny-all']
177 cm = ChaosMonkey.factory()179 cm = ChaosMonkey.factory()
178 cm.include_command(commands)180 cm.include_command(commands)
179 self.assertEqual(len(cm.chaos), 2)181 self.assertEqual(len(cm.chaos), 2)
@@ -186,15 +188,15 @@
186 self.assertEqual(cm.chaos, [])188 self.assertEqual(cm.chaos, [])
187189
188 def test_exclude_command(self):190 def test_exclude_command(self):
189 commands = ['allow-ssh']191 commands = ['deny-all']
190 cm = ChaosMonkey.factory()192 cm = ChaosMonkey.factory()
191 cm.include_group('all')193 cm.include_group('all')
192 cm.exclude_command(commands)194 cm.exclude_command(commands)
193 self.assertGreaterEqual(len(cm.chaos), 1)195 self.assertGreaterEqual(len(cm.chaos), 1)
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))
195197
196 def test_exclude_commands(self):198 def test_exclude_commands(self):
197 commands = ['allow-ssh', 'jujud']199 commands = ['deny-all', 'jujud']
198 cm = ChaosMonkey.factory()200 cm = ChaosMonkey.factory()
199 cm.include_group('all')201 cm.include_group('all')
200 cm.exclude_command(commands)202 cm.exclude_command(commands)
@@ -202,7 +204,7 @@
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))
203205
204 def test_include_and_exclude_commands(self):206 def test_include_and_exclude_commands(self):
205 commands = ['allow-ssh', 'jujud']207 commands = ['deny-all', 'jujud']
206 cm = ChaosMonkey.factory()208 cm = ChaosMonkey.factory()
207 cm.include_command(commands)209 cm.include_command(commands)
208 self.assertGreaterEqual(len(cm.chaos), 1)210 self.assertGreaterEqual(len(cm.chaos), 1)
@@ -250,7 +252,7 @@
250252
251 def test_exclude_group_and_include_command(self):253 def test_exclude_group_and_include_command(self):
252 groups = ['net']254 groups = ['net']
253 commands = ['allow-ssh']255 commands = ['deny-all']
254 cm = ChaosMonkey.factory()256 cm = ChaosMonkey.factory()
255 cm.include_group('all')257 cm.include_group('all')
256 cm.exclude_group(groups)258 cm.exclude_group(groups)
@@ -258,7 +260,7 @@
258 self.assertTrue(all(c.group != 'net' for c in cm.chaos))260 self.assertTrue(all(c.group != 'net' for c in cm.chaos))
259 cm.include_command(commands)261 cm.include_command(commands)
260 self.assertGreaterEqual(len(cm.chaos), 1)262 self.assertGreaterEqual(len(cm.chaos), 1)
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))
262 self.assertTrue(any(c.group == 'net' for c in cm.chaos))264 self.assertTrue(any(c.group == 'net' for c in cm.chaos))
263265
264 def test_find_command(self):266 def test_find_command(self):
265267
=== modified file 'tests/test_net.py'
--- tests/test_net.py 2015-05-08 18:29:03 +0000
+++ tests/test_net.py 2015-05-10 22:05:29 +0000
@@ -105,12 +105,13 @@
105105
106 def test_create_chaos(self):106 def test_create_chaos(self):
107 net = Net()107 net = Net()
108 chaos = net.create_chaos('enable', 'disable', 'command')108 chaos = net.create_chaos('enable', 'disable', 'command', 'description')
109 self.assertIs(type(chaos), Chaos)109 self.assertIs(type(chaos), Chaos)
110 self.assertEqual(chaos.enable, 'enable')110 self.assertEqual(chaos.enable, 'enable')
111 self.assertEqual(chaos.disable, 'disable')111 self.assertEqual(chaos.disable, 'disable')
112 self.assertEqual(chaos.group, 'net')112 self.assertEqual(chaos.group, 'net')
113 self.assertEqual(chaos.command_str, 'command')113 self.assertEqual(chaos.command_str, 'command')
114 self.assertEqual(chaos.description, 'description')
114115
115 def test_shutdown(self):116 def test_shutdown(self):
116 self._run_test('reset', ['ufw', 'reset'])117 self._run_test('reset', ['ufw', 'reset'])
@@ -126,5 +127,5 @@
126127
127128
128def get_all_net_commands():129def get_all_net_commands():
129 return ['deny-all', 'deny-incoming', 'deny-outgoing', 'allow-ssh',130 return ['deny-all', 'deny-incoming', 'deny-outgoing', 'deny-state-server',
130 'deny-state-server', 'deny-api-server', 'deny-sys-log']131 'deny-api-server', 'deny-sys-log']
131132
=== modified file 'tests/test_runner.py'
--- tests/test_runner.py 2015-05-05 19:09:12 +0000
+++ tests/test_runner.py 2015-05-10 22:05:29 +0000
@@ -258,5 +258,5 @@
258258
259259
260def add_fake_group(chaos_monkey):260def add_fake_group(chaos_monkey):
261 chaos = Chaos(None, None, 'fake_group', 'fake_command_str')261 chaos = Chaos(None, None, 'fake_group', 'fake_command_str', 'description')
262 chaos_monkey.append(chaos)262 chaos_monkey.append(chaos)

Subscribers

People subscribed via source and target branches