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)
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)
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)
def test_get_all_commands(self): all_commands = ChaosMonkey.get_all_commands() self.assertItemsEqual(all_commands, self._get_all_command_strings())
def test_display_all_commands(self): cmd = display_all_commands() self._assert_from_list(ChaosMonkey.get_all_groups(), cmd) self._assert_from_list(ChaosMonkey.get_all_commands(), cmd)
def test_validate_incorrect_command(self): commands = "deny-all,monogd,deny-api-server" all_commands = ChaosMonkey.get_all_commands() with self.assertRaisesRegexp( BadRequest, "Invalid value given on command line: monogd"): Runner._validate(commands, all_commands)
def test_validate_commands(self): commands = "deny-all,{},deny-api-server".format(Kill.jujud_cmd) all_commands = ChaosMonkey.get_all_commands() commands = Runner._validate(commands, all_commands) self.assertItemsEqual( commands, ['deny-all', Kill.jujud_cmd, 'deny-api-server'])
def test_validate_command(self): commands = "deny-all" all_commands = ChaosMonkey.get_all_commands() commands = Runner._validate(commands, all_commands) self.assertItemsEqual(commands, ['deny-all'])