Ejemplo n.º 1
0
    def test_deletion_of_expired_executions_with_batch_size_scenario1(self):
        """scenario1

        This test will use batch_size of 3,
        5 expired executions and different values of "older_than"
        which is 30 and 5 minutes respectively.
        Expected_result: All expired executions are successfully deleted.
        """

        _create_workflow_executions()
        now = datetime.datetime.utcnow()

        _set_expiration_policy_config(
            evaluation_interval=1,
            older_than=30,
            batch_size=3
        )
        expiration_policy.run_execution_expiration_policy(self, ctx)
        execs = db_api.get_expired_executions(now)
        self.assertEqual(2, len(execs))

        _set_expiration_policy_config(evaluation_interval=1, older_than=5)
        expiration_policy.run_execution_expiration_policy(self, ctx)
        execs = db_api.get_expired_executions(now)
        self.assertEqual(0, len(execs))
Ejemplo n.º 2
0
    def test_expiration_policy_for_executions_with_ignored_states(self):
        _create_workflow_executions()
        now = datetime.datetime.utcnow()

        _set_expiration_policy_config(
            evaluation_interval=1,
            older_than=30,
            ignored_states=['SUCCESS']
        )

        expiration_policy.run_execution_expiration_policy(self, ctx)

        execs = db_api.get_expired_executions(now)
        self.assertEqual(1, len(execs))
        self.assertEqual('cancelled_not_expired', execs[0].get('id'))

        _set_expiration_policy_config(
            evaluation_interval=1,
            older_than=30,
            ignored_states=['SUCCESS', 'CANCELLED']
        )

        expiration_policy.run_execution_expiration_policy(self, ctx)

        execs = db_api.get_expired_executions(now)
        self.assertEqual(0, len(execs))
    def test_expiration_policy_for_executions(self):
        # Delete execution uses a secured filtering and we need
        # to verify that admin able to do that for other projects.
        cfg.CONF.set_default('auth_enable', True, group='pecan')

        # Since we are removing other projects execution,
        # we want to load the executions with other project_id.
        _switch_context('non_admin_project', False)

        _load_executions()

        now = datetime.datetime.now()

        # This execution has a parent wf and testing that we are
        # querying only for parent wfs.
        exec_child = db_api.get_execution('654')

        self.assertEqual('789', exec_child.task_execution_id)

        # Call for all expired wfs execs.
        execs = db_api.get_expired_executions(now)

        # Should be only 3, the RUNNING execution shouldn't return,
        # so the child wf (that has parent task id).
        self.assertEqual(3, len(execs))

        # Switch context to Admin since expiration policy running as Admin.
        _switch_context(None, True)

        # TODO(m4dcoder): The expiration policy is changed here to expire
        # executions older than 30 minutes. It was originally 10 minutes.
        # The unit test below expects 1 execution to remain after the policy
        # is applied. However, the unit test fail frequently because the
        # process that deletes the expired executions seem to run late and
        # all executions are deleted. The unit tests seems to run better if
        # the config is changed to 30 minutes. Troubleshoot the expiration
        # policy to identify cause of the delay.
        _set_expiration_policy_config(1, 30)
        expiration_policy.run_execution_expiration_policy(self, ctx)

        # Only non_expired available (update_at < older_than).
        execs = db_api.get_expired_executions(now)

        self.assertEqual(1, len(execs))
        self.assertEqual('987', execs[0].id)

        _set_expiration_policy_config(1, 5)
        expiration_policy.run_execution_expiration_policy(self, ctx)
        execs = db_api.get_expired_executions(now)

        self.assertEqual(0, len(execs))
Ejemplo n.º 4
0
    def test_expiration_policy_for_executions_with_different_project_id(self):
        # Delete execution uses a secured filtering and we need
        # to verify that admin able to do that for other projects.
        cfg.CONF.set_default('auth_enable', True, group='pecan')

        # Since we are removing other projects execution,
        # we want to load the executions with other project_id.
        _switch_context(False, False)

        _create_workflow_executions()

        now = datetime.datetime.utcnow()

        # This execution has a parent wf and testing that we are
        # querying only for parent wfs.
        exec_child = db_api.get_workflow_execution('expired_but_not_a_parent')

        self.assertEqual('running_not_expired', exec_child.task_execution_id)

        # Call for all expired wfs execs.
        execs = db_api.get_expired_executions(now)

        # Should be only 5, the RUNNING execution shouldn't return,
        # so the child wf (that has parent task id).
        self.assertEqual(5, len(execs))

        # Switch context to Admin since expiration policy running as Admin.
        _switch_context(True, True)

        _set_expiration_policy_config(evaluation_interval=1, older_than=30)
        expiration_policy.run_execution_expiration_policy(self, ctx)

        # Only non_expired available (update_at < older_than).
        execs = db_api.get_expired_executions(now)

        self.assertEqual(2, len(execs))
        self.assertListEqual(
            [
                'cancelled_not_expired',
                'success_not_expired'
            ],
            sorted([ex.id for ex in execs])
        )

        _set_expiration_policy_config(evaluation_interval=1, older_than=5)
        expiration_policy.run_execution_expiration_policy(self, ctx)
        execs = db_api.get_expired_executions(now)

        self.assertEqual(0, len(execs))
Ejemplo n.º 5
0
    def test_deletion_of_expired_executions_with_batch_size_scenario2(self):
        """scenario2

        This test will use batch_size of 2, 5 expired executions
        with value of "older_than" that is 5 minutes.
        Expected_result: All expired executions are successfully deleted.
        """

        _create_workflow_executions()
        now = datetime.datetime.utcnow()

        _set_expiration_policy_config(evaluation_interval=1,
                                      older_than=5,
                                      batch_size=2)
        expiration_policy.run_execution_expiration_policy(self, ctx)
        execs = db_api.get_expired_executions(now)
        self.assertEqual(0, len(execs))
Ejemplo n.º 6
0
    def test_deletion_of_expired_executions_with_batch_size_scenario1(self):
        """scenario1

        This test will use batch_size of 3,
        5 expired executions and different values of "older_than"
        which is 30 and 5 minutes respectively.
        Expected_result: All expired executions are successfully deleted.
        """

        cfg.CONF.set_default(
            'batch_size',
            3,
            group='execution_expiration_policy'
        )

        _create_workflow_executions()

        _set_expiration_policy_config(1, 30, None)

        # Call for all expired wfs execs.
        now = datetime.datetime.utcnow()
        execs = db_api.get_executions_to_clean(now)

        # Should be only 5, the RUNNING execution shouldn't return,
        # so the child wf (that has parent task id).
        self.assertEqual(5, len(execs))

        older_than = cfg.CONF.execution_expiration_policy.older_than
        exp_time = (datetime.datetime.utcnow()
                    - datetime.timedelta(minutes=older_than))
        batch_size = cfg.CONF.execution_expiration_policy.batch_size
        mfe = cfg.CONF.execution_expiration_policy.max_finished_executions
        expiration_policy._delete_executions(
            batch_size,
            exp_time,
            mfe
        )
        execs = db_api.get_executions_to_clean(now)
        self.assertEqual(2, len(execs))

        _set_expiration_policy_config(1, 5, None)
        expiration_policy.run_execution_expiration_policy(self, ctx)
        execs = db_api.get_executions_to_clean(now)
        self.assertEqual(0, len(execs))
    def test_expiration_policy_for_executions(self):
        # Delete execution uses a secured filtering and we need
        # to verify that admin able to do that for other projects.
        cfg.CONF.set_default('auth_enable', True, group='pecan')

        # Since we are removing other projects execution,
        # we want to load the executions with other project_id.
        _switch_context('non_admin_project', False)

        _load_executions()

        now = datetime.datetime.now()

        # This execution has a parent wf and testing that we are
        # querying only for parent wfs.
        exec_child = db_api.get_execution('654')

        self.assertEqual('789', exec_child.task_execution_id)

        # Call for all expired wfs execs.
        execs = db_api.get_expired_executions(now)

        # Should be only 3, the RUNNING execution shouldn't return,
        # so the child wf (that has parent task id).
        self.assertEqual(3, len(execs))

        # Switch context to Admin since expiration policy running as Admin.
        _switch_context(None, True)

        _set_expiration_policy_config(1, 30)
        expiration_policy.run_execution_expiration_policy(self, ctx)

        # Only non_expired available (update_at < older_than).
        execs = db_api.get_expired_executions(now)

        self.assertEqual(1, len(execs))
        self.assertEqual('987', execs[0].id)

        _set_expiration_policy_config(1, 5)
        expiration_policy.run_execution_expiration_policy(self, ctx)
        execs = db_api.get_expired_executions(now)

        self.assertEqual(0, len(execs))
    def test_expiration_policy_for_executions(self):
        # Delete execution uses a secured filtering and we need
        # to verify that admin able to do that for other projects.
        cfg.CONF.set_default('auth_enable', True, group='pecan')

        # Since we are removing other projects execution,
        # we want to load the executions with other project_id.
        _switch_context('non_admin_project', False)

        _load_executions()

        now = datetime.datetime.now()

        # This execution has a parent wf and testing that we are
        # querying only for parent wfs.
        exec_child = db_api.get_execution('654')

        self.assertEqual('789', exec_child.task_execution_id)

        # Call for all expired wfs execs.
        execs = db_api.get_expired_executions(now)

        # Should be only 3, the RUNNING execution shouldn't return,
        # so the child wf (that has parent task id).
        self.assertEqual(3, len(execs))

        # Switch context to Admin since expiration policy running as Admin.
        _switch_context(None, True)

        _set_expiration_policy_config(1, 30)
        expiration_policy.run_execution_expiration_policy(self, ctx)

        # Only non_expired available (update_at < older_than).
        execs = db_api.get_expired_executions(now)

        self.assertEqual(1, len(execs))
        self.assertEqual('987', execs[0].id)

        _set_expiration_policy_config(1, 5)
        expiration_policy.run_execution_expiration_policy(self, ctx)
        execs = db_api.get_expired_executions(now)

        self.assertEqual(0, len(execs))
Ejemplo n.º 9
0
    def test_expiration_policy_for_executions_with_max_executions_scen2(self):
        """scenario2

        Tests the max_executions logic with:
        max_finished_executions > total completed executions
        """

        _create_workflow_executions()

        now = datetime.datetime.utcnow()

        # Call for all expired wfs execs.
        execs = db_api.get_executions_to_clean(now)

        # Should be only 5, the RUNNING execution shouldn't return,
        # so the child wf (that has parent task id).
        self.assertEqual(5, len(execs))

        _set_expiration_policy_config(1, 30, 100)
        expiration_policy.run_execution_expiration_policy(self, ctx)

        # Assert the two running executions
        # (running_not_expired, running_not_expired2), the sub execution
        # (expired_but_not_a_parent) and the all finished execution
        # (success_not_expired, 'cancelled_not_expired') are there.
        execs = db_api.get_workflow_executions()
        self.assertEqual(5, len(execs))
        self.assertListEqual(
            [
                'cancelled_not_expired',
                'expired_but_not_a_parent',
                'running_not_expired',
                'running_not_expired2',
                'success_not_expired'
            ],
            sorted([ex.id for ex in execs])
        )
Ejemplo n.º 10
0
    def test_expiration_policy_for_executions_with_max_executions_scen2(self):
        """scenario2

        Tests the max_executions logic with:
        max_finished_executions > total completed executions
        """

        _create_workflow_executions()
        _set_expiration_policy_config(evaluation_interval=1,
                                      older_than=30,
                                      mfe=100)
        expiration_policy.run_execution_expiration_policy(self, ctx)

        # Assert the two running executions
        # (running_not_expired, running_not_expired2), the sub execution
        # (expired_but_not_a_parent) and the all finished execution
        # (success_not_expired, 'cancelled_not_expired') are there.
        execs = db_api.get_workflow_executions()
        self.assertEqual(5, len(execs))
        self.assertListEqual([
            'cancelled_not_expired', 'expired_but_not_a_parent',
            'running_not_expired', 'running_not_expired2',
            'success_not_expired'
        ], sorted([ex.id for ex in execs]))
Ejemplo n.º 11
0
    def test_expiration_policy_for_executions_with_max_executions_scen1(self):
        """scenario1

        Tests the max_executions logic with
        max_finished_executions =
        'total not expired and completed executions' - 1
        """

        _create_workflow_executions()
        _set_expiration_policy_config(evaluation_interval=1,
                                      older_than=30,
                                      mfe=1)
        expiration_policy.run_execution_expiration_policy(self, ctx)

        # Assert the two running executions
        # (running_not_expired, running_not_expired2),
        # the sub execution (expired_but_not_a_parent) and the one allowed
        # finished execution (success_not_expired) are there.
        execs = db_api.get_workflow_executions()
        self.assertEqual(4, len(execs))
        self.assertListEqual([
            'expired_but_not_a_parent', 'running_not_expired',
            'running_not_expired2', 'success_not_expired'
        ], sorted([ex.id for ex in execs]))