本文整理汇总了Python中chaos_monkey.ChaosMonkey类的典型用法代码示例。如果您正苦于以下问题:Python ChaosMonkey类的具体用法?Python ChaosMonkey怎么用?Python ChaosMonkey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ChaosMonkey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: filter_commands
def filter_commands(self, include_group=None, exclude_group=None,
include_command=None, exclude_command=None):
"""Perform command selection and exclusion.
See random_chaos() for the description of the parameters.
"""
all_groups = ChaosMonkey.get_all_groups()
all_commands = ChaosMonkey.get_all_commands()
self.chaos_monkey.reset_command_selection()
# If any groups and any commands are not included, assume the intent
# is to include all groups and all commands.
if not include_group and not include_command:
self.chaos_monkey.include_group('all')
if include_group:
include_group = self._validate(include_group, all_groups)
self.chaos_monkey.include_group(include_group)
if exclude_group:
exclude_group = self._validate(exclude_group, all_groups)
self.chaos_monkey.exclude_group(exclude_group)
if include_command:
include_command = self._validate(
include_command, all_commands)
self.chaos_monkey.include_command(include_command)
if exclude_command:
exclude_command = self._validate(
exclude_command, all_commands)
self.chaos_monkey.exclude_command(exclude_command)
示例2: test_list_all_commands
def test_list_all_commands(self):
cmd = Runner.list_all_commands()
self.assertItemsEqual(cmd.keys(), ChaosMonkey.get_all_groups())
all_commands = []
for commands in cmd.values():
for command in commands:
all_commands.extend(command)
self._assert_from_list(ChaosMonkey.get_all_commands(), all_commands)
示例3: list_all_commands
def list_all_commands():
"""List all available commands."""
all_chaos, _ = ChaosMonkey.get_all_chaos()
all_groups = ChaosMonkey.get_all_groups()
commands = {}
for group in all_groups:
commands[group] = [[c.command_str, c.description]
for c in all_chaos if c.group == group]
return commands
示例4: test_filter_commands_exclude_incorrect_group
def test_filter_commands_exclude_incorrect_group(self):
exclude_group = 'net,killl'
with temp_dir() as directory:
runner = Runner(directory, ChaosMonkey.factory())
with self.assertRaisesRegexp(
BadRequest, "Invalid value given on command line: killl"):
runner.filter_commands(exclude_group=exclude_group)
示例5: test_include_command
def test_include_command(self):
command = ['deny-incoming']
cm = ChaosMonkey.factory()
cm.include_command(command)
self.assertGreaterEqual(len(cm.chaos), 1)
self.assertTrue(
all(c.command_str == 'deny-incoming' for c in cm.chaos))
示例6: test_filter_command_include_command
def test_filter_command_include_command(self):
include_command = 'deny-all'
with temp_dir() as directory:
runner = Runner(directory, ChaosMonkey.factory())
runner.filter_commands(include_command=include_command)
self.assertEqual(len(runner.chaos_monkey.chaos), 1)
self.assertEqual(runner.chaos_monkey.chaos[0].command_str, 'deny-all')
示例7: test_exclude_commands
def test_exclude_commands(self):
commands = ['deny-all', Kill.jujud_cmd]
cm = ChaosMonkey.factory()
cm.include_group('all')
cm.exclude_command(commands)
self.assertGreaterEqual(len(cm.chaos), 1)
self.assertTrue(all(c.command_str not in commands for c in cm.chaos))
示例8: test_exclude_group
def test_exclude_group(self):
group = ['net']
cm = ChaosMonkey.factory()
cm.include_group('all')
cm.exclude_group(group)
self.assertGreaterEqual(len(cm.chaos), 1)
self.assertTrue(all(c.group != 'net' for c in cm.chaos))
示例9: test_exclude_group_multiple_groups
def test_exclude_group_multiple_groups(self):
group = ['net', 'kill']
cm = ChaosMonkey.factory()
cm.include_group('all')
cm.exclude_group(group)
self.assertTrue(all(c.group != 'net' for c in cm.chaos))
self.assertTrue(all(c.group != 'kill' for c in cm.chaos))
示例10: test_random_assert_run_command_method_called
def test_random_assert_run_command_method_called(self):
with patch('utility.check_output', autospec=True):
with patch('runner.Runner._run_command', autospec=True) as cm_mock:
with temp_dir() as directory:
runner = Runner(directory, ChaosMonkey.factory())
runner.random_chaos(run_timeout=1, enablement_timeout=1)
cm_mock.assert_called_with(runner, 1)
示例11: test_random_enablement_zero
def test_random_enablement_zero(self):
with patch('utility.check_output', autospec=True) as mock:
with temp_dir() as directory:
runner = Runner(directory, ChaosMonkey.factory())
runner.random_chaos(run_timeout=1, enablement_timeout=0,
exclude_command=Kill.restart_cmd)
self.assertEqual(mock.called, True)
示例12: test_filter_command_exclude_incorrect_command
def test_filter_command_exclude_incorrect_command(self):
exclude_command = 'deny-all,deny-net,{}'.format(Kill.jujud_cmd)
with temp_dir() as directory:
runner = Runner(directory, ChaosMonkey.factory())
with self.assertRaisesRegexp(
BadRequest,
"Invalid value given on command line: deny-net"):
runner.filter_commands(exclude_command=exclude_command)
示例13: test_filter_command_include_incorrect_command
def test_filter_command_include_incorrect_command(self):
include_command = 'deny-all,deny-net'
with temp_dir() as directory:
runner = Runner(directory, ChaosMonkey.factory())
with self.assertRaisesRegexp(
BadRequest,
"Invalid value given on command line: deny-net"):
runner.filter_commands(include_command=include_command)
示例14: test_filter_command_exclude_command
def test_filter_command_exclude_command(self):
exclude_command = Kill.jujud_cmd
with temp_dir() as directory:
runner = Runner(directory, ChaosMonkey.factory())
runner.filter_commands(exclude_command=exclude_command)
self.assertGreaterEqual(len(runner.chaos_monkey.chaos), 1)
self.assertTrue(all(c.command_str != Kill.jujud_cmd
for c in runner.chaos_monkey.chaos))
示例15: test_filter_commands_exclude_group
def test_filter_commands_exclude_group(self):
exclude_group = 'net'
with temp_dir() as directory:
runner = Runner(directory, ChaosMonkey.factory())
runner.filter_commands(exclude_group=exclude_group)
self.assertGreaterEqual(len(runner.chaos_monkey.chaos), 2)
self.assertTrue(all(c.group != 'net'
for c in runner.chaos_monkey.chaos))