示例#1
0
 def test_action_raise_suppressed_by_setting_for_write(self):
     mock_data.make_action_db(
         act_on_value=TEST_APP_LABEL,
         act_on_attribute=models.ChaosActionDB.attr_default,
         enabled=True,
         verb=models.verb_raise,
         probability=100,
     )
     self.router.db_for_write(TestModel)
 def test_list_with_kv_stderr_empty(self):
     key = models.ChaosKV.get_random_key()
     mock_data.make_action_db(config={key: "bar"})
     mock_data.make_action_response(config={key: "bar"})
     self.assertEqual(2, models.ChaosKV.objects.all().count())
     for model in models.model_choices:
         self._test_output_equals(self.err, "", "--models", model)
         self._test_output_not_equals(self.out, "", "--models", model)
         call_command("chaos", "list", stdout=self.out, stderr=self.err)
示例#3
0
 def test_action_slow_is_performed_for_write(self, _sleep):
     mock_data.make_action_db(
         act_on_value=TEST_APP_LABEL,
         act_on_attribute=models.ChaosActionDB.attr_default,
         enabled=True,
         verb=models.verb_slow,
         probability=100,
     )
     self.router.db_for_write(TestModel)
     self.assertEqual(1, _sleep.call_count)
示例#4
0
 def _test_do_chaos_is_called_for_read(self, attr, _chaos):
     model = TestModel
     mock_data.make_action_db(
         act_on_attribute=attr,
         act_on_value=attrgetter(attr)(model),
         probability=100,
         enabled=True,
     )
     self.router.db_for_write(model)
     self.assertEqual(1, _chaos.call_count)
示例#5
0
 def _test_action_raise_is_performed_for_write(self, config):
     model = TestModel
     attr = config["attribute"]
     mock_data.make_action_db(
         verb=models.verb_raise,
         act_on_attribute=attr,
         act_on_value=attrgetter(attr)(model),
         probability=100,
         enabled=True,
     )
     with self.assertRaises(models.ChaosActionDB.default_exception):
         self.router.db_for_write(TestModel)
 def test_storm_actions(self):
     mock_data.make_action_response()
     mock_data.make_action_db()
     mock_data.make_action_response(config={STORM_KEY: STORM_VALUE})
     mock_data.make_action_db(config={STORM_KEY: STORM_VALUE})
     call_command("chaos",
                  "storm",
                  "--end",
                  stdout=self.out,
                  stderr=self.err)
     actions = self.cls.objects.all()
     # As we only count one action class, only one object should exist
     self.assertEqual(1, len(actions))
 def test_dump_db(self, _dump):
     key = models.ChaosKV.get_random_key()
     action = mock_data.make_action_db(config={key: "bar"})
     call_command("chaos",
                  "dump",
                  "db",
                  action.id,
                  stdout=self.out,
                  stderr=self.err)
     self.assertEqual(1, _dump.call_count)
示例#8
0
    def storm_start(self, users, groups, probability=None):
        """
        Create some wildcard actions with relatively low probability.

        The assumption is that every page does 30 db queries on average, and
        that we want a failure for every 10th response.

        With NV being the number of verbs of the action we want:

        - For db router actions: 0.333%
        - For middleware actions: 10%

        All actions created here get a KV object associated with them to make
        it possible to delete them easily.
        """
        if users and groups:
            raise CommandError("--user and --group can not be used together")

        users = User.objects.filter(username__in=users)
        groups = Group.objects.filter(name__in=groups)
        if not users and not groups:
            raise CommandError("Could not find any matching users/groups by given names")

        probability = probability or 10 / len(
            models.ChaosActionResponse.verb_choices_str
        )
        for verb in models.ChaosActionResponse.verb_choices_str:
            action = mock_data.make_action_response(
                verb=verb,
                act_on_url_name="",
                for_users=users,
                for_groups=groups,
                probability=probability,
                config={STORM_KEY: STORM_VALUE},
            )
            self.stdout.write("Created response action\t{}".format(action))

        probability = probability or 1 / 30 / len(
            models.ChaosActionResponse.verb_choices_str
        )
        for verb in models.ChaosActionDB.verb_choices_str:
            action = mock_data.make_action_db(
                verb=verb,
                act_on_attribute=models.attr_choices_db["attr_app_label"]["attribute"],
                act_on_value="",
                for_users=users,
                for_groups=groups,
                probability=probability,
                config={STORM_KEY: STORM_VALUE},
            )
            self.stdout.write("Created dbroute action\t{}".format(action))
 def test_list_output_one_of_each_action(self):
     mock_data.make_action_db()
     mock_data.make_action_response()
     self._test_output_equals(self.err, "")
     self._test_output_not_equals(self.out, "")
 def test_list_by_model_stderr_empty(self):
     mock_data.make_action_db()
     mock_data.make_action_response()
     for model in models.model_choices:
         self._test_output_equals(self.err, "", "--models", model)
         self._test_output_not_equals(self.out, "", "--models", model)