示例#1
0
    def test_workflow_without_auth(self):
        cfg.CONF.set_default('auth_enable', False, group='pecan')

        wf = workflows.create_workflows(WORKFLOW_LIST)[0]

        triggers.create_cron_trigger(
            'trigger-%s' % utils.generate_unicode_uuid(), wf.name, {}, {},
            '* * * * * */1', None, None, None)

        next_triggers = triggers.get_next_cron_triggers()

        self.assertEqual(1, len(next_triggers))

        next_trigger = next_triggers[0]
        next_execution_time_before = next_trigger.next_execution_time
        ts_before = datetime.datetime.utcnow()

        periodic.process_cron_triggers_v2(None, None)
        self._await(lambda: triggers.get_next_cron_triggers(),
                    fail_message="No triggers were found")

        next_triggers = triggers.get_next_cron_triggers()

        self.assertEqual(1, len(next_triggers))

        next_trigger = next_triggers[0]
        next_execution_time_after = next_trigger.next_execution_time

        self.assertGreater(next_execution_time_after, ts_before)

        self.assertNotEqual(next_execution_time_before,
                            next_execution_time_after)
示例#2
0
    def test_workflow_without_auth(self):
        cfg.CONF.set_default('auth_enable', False, group='pecan')

        wf = workflows.create_workflows(WORKFLOW_LIST)[0]

        triggers.create_cron_trigger(
            'trigger-%s' % utils.generate_unicode_uuid(), wf.name, {}, {},
            '* * * * * */1', None, None, None)

        next_triggers = triggers.get_next_cron_triggers()

        self.assertEqual(1, len(next_triggers))

        next_trigger = next_triggers[0]
        next_execution_time_before = next_trigger.next_execution_time

        periodic.MistralPeriodicTasks(cfg.CONF).process_cron_triggers_v2(None)

        next_triggers = triggers.get_next_cron_triggers()

        self.assertEqual(1, len(next_triggers))

        next_trigger = next_triggers[0]
        next_execution_time_after = next_trigger.next_execution_time

        self.assertNotEqual(next_execution_time_before,
                            next_execution_time_after)
示例#3
0
    def test_create_delete_trust_in_trigger(self, create_ctx, delete_trust):
        create_ctx.return_value = self.ctx
        cfg.CONF.set_default('auth_enable', True, group='pecan')
        trigger_thread = periodic.setup()
        self.addCleanup(trigger_thread.stop)
        self.addCleanup(
            cfg.CONF.set_default, 'auth_enable',
            False, group='pecan'
        )

        t_s.create_cron_trigger(
            'trigger-%s' % utils.generate_unicode_uuid(),
            self.wf.name,
            {},
            {},
            '* * * * * *',
            None,
            1,
            datetime.datetime(2010, 8, 25)
        )

        self._await(
            lambda: delete_trust.call_count == 1, timeout=10
        )
        self.assertEqual('my_trust_id', delete_trust.mock_calls[0][1][0])
示例#4
0
    def _dtw_last_minute_scheduling(self, ctx):

        for d in dtw.get_unscheduled_delay_tolerant_workload():
            LOG.debug("Processing delay tolerant workload: %s" % d)

            # Setup admin context before schedule triggers.
            ctx = security.create_context(d.trust_id, d.project_id)

            auth_ctx.set_ctx(ctx)

            LOG.debug("Delay tolerant workload security context: %s" % ctx)

            # calculate last time for running this - deadline less the
            # duration of the work
            # TODO(murp): check the status of the security context on this
            # TODO(murp): convert job_duration to timedelta
            start_time = d.deadline - datetime.timedelta(seconds=d.job_duration)
            
            triggers.create_cron_trigger(d.name, d.workflow_name, 
                                         d.workflow_input,
                                         workflow_params=d.workflow_params, 
                                         count=1, 
                                         first_time=start_time,
                                         start_time=start_time, 
                                         workflow_id=d.workflow_id)
    def test_single_execution_with_multiple_processes(self, start_wf_mock):
        def stop_thread_groups():
            print('Killing cron trigger threads...')
            [tg.stop() for tg in self.trigger_threads]

        self.trigger_threads = [
            periodic.setup(),
            periodic.setup(),
            periodic.setup()
        ]
        self.addCleanup(stop_thread_groups)

        trigger_count = 5
        t_s.create_cron_trigger(
            'ct1',
            self.wf.name,
            {},
            {},
            '* * * * * */1',  # Every second
            None,
            trigger_count,
            datetime.datetime(2010, 8, 25))

        # Wait until there are 'trigger_count' executions.
        self._await(
            lambda: self._wait_for_single_execution_with_multiple_processes(
                trigger_count, start_wf_mock))

        # Wait some more and make sure there are no more than 'trigger_count'
        # executions.
        eventlet.sleep(5)

        self.assertEqual(trigger_count, start_wf_mock.call_count)
    def test_single_execution_with_multiple_processes(self, start_wf_mock):
        def stop_thread_groups():
            [tg.stop() for tg in self.triggers]

        self.triggers = [periodic.setup(), periodic.setup(), periodic.setup()]
        self.addCleanup(stop_thread_groups)

        trigger_count = 5
        t_s.create_cron_trigger(
            'ct1',
            self.wf.name,
            {},
            {},
            '* * * * * */1',  # Every second
            None,
            trigger_count,
            datetime.datetime(2010, 8, 25)
        )

        # Wait until there are 'trigger_count' executions.
        self._await(
            lambda: self._wait_for_single_execution_with_multiple_processes(
                trigger_count,
                start_wf_mock
            )
        )

        # Wait some more and make sure there are no more than 'trigger_count'
        # executions.
        eventlet.sleep(5)

        self.assertEqual(trigger_count, start_wf_mock.call_count)
    def test_get_trigger_in_correct_orders(self):
        t1_name = 'trigger-%s' % utils.generate_unicode_uuid()

        t_s.create_cron_trigger(t1_name,
                                self.wf.name, {},
                                pattern='*/5 * * * *',
                                start_time=datetime.datetime(2010, 8, 25))

        t2_name = 'trigger-%s' % utils.generate_unicode_uuid()

        t_s.create_cron_trigger(t2_name,
                                self.wf.name, {},
                                pattern='*/1 * * * *',
                                start_time=datetime.datetime(2010, 8, 22))

        t3_name = 'trigger-%s' % utils.generate_unicode_uuid()

        t_s.create_cron_trigger(t3_name,
                                self.wf.name, {},
                                pattern='*/2 * * * *',
                                start_time=datetime.datetime(2010, 9, 21))

        t4_name = 'trigger-%s' % utils.generate_unicode_uuid()

        t_s.create_cron_trigger(t4_name,
                                self.wf.name, {},
                                pattern='*/3 * * * *',
                                start_time=datetime.datetime.utcnow() +
                                datetime.timedelta(0, 50))

        trigger_names = [t.name for t in t_s.get_next_cron_triggers()]

        self.assertEqual([t2_name, t1_name, t3_name], trigger_names)
示例#8
0
    def test_start_workflow(self, rpc_mock):

        cfg.CONF.set_default('auth_enable', True, group='pecan')

        wf = workflows.create_workflows(WORKFLOW_LIST)[0]

        t = triggers.create_cron_trigger(
            'trigger-%s' % utils.generate_unicode_uuid(), wf.name, {}, {},
            '* * * * * */1', None, None, None)

        self.assertEqual('my_trust_id', t.trust_id)

        cfg.CONF.set_default('auth_enable', False, group='pecan')

        next_trigger = triggers.get_next_cron_triggers()[0]
        next_execution_time_before = next_trigger.next_execution_time

        periodic.MistralPeriodicTasks(cfg.CONF).process_cron_triggers_v2(None)

        start_workflow_mock = rpc_mock.return_value.start_workflow
        start_workflow_mock.assert_called_once()
        self.assertIn(t.id,
                      start_workflow_mock.mock_calls[0][2]['description'])

        next_triggers = triggers.get_next_cron_triggers()

        self.assertEqual(1, len(next_triggers))

        next_trigger = next_triggers[0]
        next_execution_time_after = next_trigger.next_execution_time

        # Checking the workflow was executed, by
        # verifying that the next execution time changed.
        self.assertNotEqual(next_execution_time_before,
                            next_execution_time_after)
示例#9
0
    def test_create_cron_trigger_with_pattern_and_first_time(
            self, validate_mock):
        cfg.CONF.set_default('auth_enable', False, group='pecan')

        wf = workflows.create_workflows(WORKFLOW_LIST)[0]

        # Make the first_time 1 sec later than current time, in order to make
        # it executed by next cron-trigger task.
        first_time = datetime.datetime.utcnow() + datetime.timedelta(0, 1)

        # Creates a cron-trigger with pattern and first time, ensure the
        # cron-trigger can be executed more than once, and cron-trigger will
        # not be deleted.
        trigger_name = 'trigger-%s' % utils.generate_unicode_uuid()

        cron_trigger = triggers.create_cron_trigger(trigger_name, wf.name, {},
                                                    {}, '*/1 * * * *',
                                                    first_time, None, None)

        self.assertEqual(first_time, cron_trigger.next_execution_time)

        periodic.MistralPeriodicTasks(cfg.CONF).process_cron_triggers_v2(None)

        next_time = triggers.get_next_execution_time(
            cron_trigger.pattern, cron_trigger.next_execution_time)

        cron_trigger_db = db_api.get_cron_trigger(trigger_name)

        self.assertIsNotNone(cron_trigger_db)
        self.assertEqual(next_time, cron_trigger_db.next_execution_time)
示例#10
0
    def test_start_workflow(self):
        cfg.CONF.set_default('auth_enable', True, group='pecan')
        wf = workflows.create_workflows(WORKFLOW_LIST)[0]
        t = t_s.create_cron_trigger(
            'test',
            wf.name,
            {},
            {},
            '* * * * * */1',
            None,
            None,
            None
        )

        self.assertEqual('my_trust_id', t.trust_id)

        cfg.CONF.set_default('auth_enable', False, group='pecan')
        m_p_t = periodic.MistralPeriodicTasks(cfg.CONF)
        next_cron_trigger = t_s.get_next_cron_triggers()[0]
        next_execution_before = next_cron_trigger.next_execution_time

        m_p_t.process_cron_triggers_v2(None)

        next_cron_trigger = t_s.get_next_cron_triggers()[0]
        next_execution_after = next_cron_trigger.next_execution_time

        # Checking the workflow was executed, by
        # verifying that the next execution time changed.
        self.assertNotEqual(next_execution_before, next_execution_after)
示例#11
0
    def test_start_workflow(self):
        cfg.CONF.set_default('auth_enable', True, group='pecan')

        wf = workflows.create_workflows(WORKFLOW_LIST)[0]

        t = triggers.create_cron_trigger(
            'test',
            wf.name,
            {},
            {},
            '* * * * * */1',
            None,
            None,
            None
        )

        self.assertEqual('my_trust_id', t.trust_id)

        cfg.CONF.set_default('auth_enable', False, group='pecan')

        next_trigger = triggers.get_next_cron_triggers()[0]
        next_execution_time_before = next_trigger.next_execution_time

        periodic.MistralPeriodicTasks(cfg.CONF).process_cron_triggers_v2(None)

        next_trigger = triggers.get_next_cron_triggers()[0]
        next_execution_time_after = next_trigger.next_execution_time

        # Checking the workflow was executed, by
        # verifying that the next execution time changed.
        self.assertNotEqual(
            next_execution_time_before,
            next_execution_time_after
        )
示例#12
0
    def test_oneshot_trigger_create(self):
        trigger = t_s.create_cron_trigger(
            'trigger-%s' % utils.generate_unicode_uuid(), self.wf.name, {}, {},
            None, "4242-12-25 13:37", None, datetime.datetime(2010, 8, 25))

        self.assertEqual(datetime.datetime(4242, 12, 25, 13, 37),
                         trigger.next_execution_time)
示例#13
0
    def test_create_delete_trust_in_trigger(self, delete_trust, create_ctx):
        create_ctx.return_value = self.ctx
        cfg.CONF.set_default('auth_enable', True, group='pecan')
        trigger_thread = periodic.setup()
        self.addCleanup(trigger_thread.stop)
        self.addCleanup(cfg.CONF.set_default,
                        'auth_enable',
                        False,
                        group='pecan')

        t_s.create_cron_trigger('trigger-%s' % utils.generate_unicode_uuid(),
                                self.wf.name, {}, {}, '* * * * * *', None, 1,
                                datetime.datetime(2010, 8, 25))

        eventlet.sleep(1)
        self.assertEqual(0, delete_trust.call_count)
    def test_get_trigger_in_correct_orders(self):
        t1_name = 'trigger-%s' % utils.generate_unicode_uuid()

        t_s.create_cron_trigger(
            t1_name,
            self.wf.name,
            {},
            {},
            '*/5 * * * *',
            None,
            None,
            datetime.datetime(2010, 8, 25)
        )

        t2_name = 'trigger-%s' % utils.generate_unicode_uuid()

        t_s.create_cron_trigger(
            t2_name,
            self.wf.name,
            {},
            {},
            '*/1 * * * *',
            None,
            None,
            datetime.datetime(2010, 8, 22)
        )

        t3_name = 'trigger-%s' % utils.generate_unicode_uuid()

        t_s.create_cron_trigger(
            t3_name,
            self.wf.name,
            {},
            {},
            '*/2 * * * *',
            None,
            None,
            datetime.datetime(2010, 9, 21)
        )

        t4_name = 'trigger-%s' % utils.generate_unicode_uuid()

        t_s.create_cron_trigger(
            t4_name,
            self.wf.name,
            {},
            {},
            '*/3 * * * *',
            None,
            None,
            datetime.datetime.now() + datetime.timedelta(0, 50)
        )

        trigger_names = [t.name for t in t_s.get_next_cron_triggers()]

        self.assertEqual([t2_name, t1_name, t3_name], trigger_names)
示例#15
0
    def test_workflow_without_auth(self):
        cfg.CONF.set_default('auth_enable', False, group='pecan')

        wf = workflows.create_workflows(WORKFLOW_LIST)[0]

        triggers.create_cron_trigger(
            'trigger-%s' % utils.generate_unicode_uuid(),
            wf.name,
            {},
            {},
            '* * * * * */1',
            None,
            None,
            None
        )

        next_triggers = triggers.get_next_cron_triggers()

        self.assertEqual(1, len(next_triggers))

        next_trigger = next_triggers[0]
        next_execution_time_before = next_trigger.next_execution_time
        ts_before = datetime.datetime.utcnow()

        periodic.process_cron_triggers_v2(None, None)
        self._await(
            lambda: triggers.get_next_cron_triggers(),
            fail_message="No triggers were found"
        )

        next_triggers = triggers.get_next_cron_triggers()

        self.assertEqual(1, len(next_triggers))

        next_trigger = next_triggers[0]
        next_execution_time_after = next_trigger.next_execution_time

        self.assertGreater(
            next_execution_time_after,
            ts_before
        )

        self.assertNotEqual(
            next_execution_time_before,
            next_execution_time_after
        )
示例#16
0
    def test_trigger_create_with_wf_id(self):
        trigger = t_s.create_cron_trigger('test',
                                          None, {}, {},
                                          '*/5 * * * *',
                                          None,
                                          None,
                                          datetime.datetime(2010, 8, 25),
                                          workflow_id=self.wf.id)

        self.assertEqual(self.wf.name, trigger.workflow_name)
示例#17
0
    def test_start_workflow(self, get_engine_client_mock):
        cfg.CONF.set_default('auth_enable', True, group='pecan')

        wf = workflows.create_workflows(WORKFLOW_LIST)[0]

        t = triggers.create_cron_trigger(
            'trigger-%s' % utils.generate_unicode_uuid(),
            wf.name,
            {},
            {},
            '* * * * * */1',
            None,
            None,
            None
        )

        self.assertEqual('my_trust_id', t.trust_id)

        cfg.CONF.set_default('auth_enable', False, group='pecan')

        next_trigger = triggers.get_next_cron_triggers()[0]
        next_execution_time_before = next_trigger.next_execution_time

        periodic.process_cron_triggers_v2(None, None)
        start_wf_mock = get_engine_client_mock.return_value.start_workflow

        start_wf_mock.assert_called_once()

        # Check actual parameters of the call.
        self.assertEqual(
            ('my_wf', '', None, {}),
            start_wf_mock.mock_calls[0][1]
        )
        self.assertIn(
            t.id,
            start_wf_mock.mock_calls[0][2]['description']
        )

        self._await(
            lambda: triggers.get_next_cron_triggers(),
            fail_message="No triggers were found"
        )

        next_triggers = triggers.get_next_cron_triggers()
        self.assertEqual(1, len(next_triggers))

        next_trigger = next_triggers[0]
        next_execution_time_after = next_trigger.next_execution_time

        # Checking the workflow was executed, by
        # verifying that the next execution time changed.
        self.assertNotEqual(
            next_execution_time_before,
            next_execution_time_after
        )
示例#18
0
    def test_create_trust_in_trigger(self):
        cfg.CONF.set_default('auth_enable', True, group='pecan')
        self.addCleanup(cfg.CONF.set_default,
                        'auth_enable',
                        False,
                        group='pecan')

        trigger = t_s.create_cron_trigger(
            'trigger-%s' % utils.generate_unicode_uuid(), self.wf.name, {}, {},
            '*/2 * * * *', None, None, datetime.datetime(2010, 8, 25))

        self.assertEqual('my_trust_id', trigger.trust_id)
示例#19
0
    def test_trigger_create(self):
        trigger = t_s.create_cron_trigger(
            'trigger-%s' % utils.generate_unicode_uuid(), self.wf.name, {}, {},
            '*/5 * * * *', None, None, datetime.datetime(2010, 8, 25))

        self.assertEqual(datetime.datetime(2010, 8, 25, 0, 5),
                         trigger.next_execution_time)

        next_time = t_s.get_next_execution_time(trigger['pattern'],
                                                trigger.next_execution_time)

        self.assertEqual(datetime.datetime(2010, 8, 25, 0, 10), next_time)
示例#20
0
    def test_trigger_create_the_same_first_time_or_count(self):
        t_s.create_cron_trigger('trigger-%s' % utils.generate_unicode_uuid(),
                                self.wf.name, {}, {}, '*/5 * * * *',
                                "4242-12-25 13:37", 2,
                                datetime.datetime(2010, 8, 25))

        t_s.create_cron_trigger('trigger-%s' % utils.generate_unicode_uuid(),
                                self.wf.name, {}, {}, '*/5 * * * *',
                                "4242-12-25 13:37", 4,
                                datetime.datetime(2010, 8, 25))

        t_s.create_cron_trigger('trigger-%s' % utils.generate_unicode_uuid(),
                                self.wf.name, {}, {}, '*/5 * * * *',
                                "5353-12-25 13:37", 2,
                                datetime.datetime(2010, 8, 25))

        # Creations above should be ok.

        # But creation with the same count and first time
        # simultaneously leads to error.
        self.assertRaises(exc.DBDuplicateEntryException,
                          t_s.create_cron_trigger,
                          'trigger-%s' % utils.generate_unicode_uuid(),
                          self.wf.name, {}, {}, '*/5 * * * *',
                          "4242-12-25 13:37", 2, None)
示例#21
0
    def test_get_trigger_in_correct_orders(self):
        t_s.create_cron_trigger(
            'test1',
            self.wf.name,
            {},
            {},
            '*/5 * * * *',
            None,
            None,
            datetime.datetime(2010, 8, 25)
        )

        t_s.create_cron_trigger(
            'test2',
            self.wf.name,
            {},
            {},
            '*/1 * * * *',
            None,
            None,
            datetime.datetime(2010, 8, 22)
        )

        t_s.create_cron_trigger(
            'test3',
            self.wf.name,
            {},
            {},
            '*/2 * * * *',
            None,
            None,
            datetime.datetime(2010, 9, 21)
        )

        t_s.create_cron_trigger(
            'test4',
            self.wf.name,
            {},
            {},
            '*/3 * * * *',
            None,
            None,
            datetime.datetime.now() + datetime.timedelta(0, 50)
        )

        trigger_names = [t.name for t in t_s.get_next_cron_triggers()]

        self.assertEqual(trigger_names, ['test2', 'test1', 'test3'])
示例#22
0
    def post(self, cron_trigger):
        """Creates a new cron trigger."""

        LOG.info('Create cron trigger: %s' % cron_trigger)

        values = cron_trigger.to_dict()

        db_model = triggers.create_cron_trigger(
            values['name'], values['workflow_name'],
            values.get('workflow_input'), values.get('workflow_params'),
            values.get('pattern'), values.get('first_execution_time'),
            values.get('remaining_executions'))

        return CronTrigger.from_dict(db_model.to_dict())
    def test_trigger_create_with_wf_id(self):
        trigger = t_s.create_cron_trigger(
            'trigger-%s' % utils.generate_unicode_uuid(),
            None,
            {},
            {},
            '*/5 * * * *',
            None,
            None,
            datetime.datetime(2010, 8, 25),
            workflow_id=self.wf.id
        )

        self.assertEqual(self.wf.name, trigger.workflow_name)
示例#24
0
    def test_workflow_without_auth(self):
        cfg.CONF.set_default('auth_enable', False, group='pecan')

        wf = workflows.create_workflows(WORKFLOW_LIST)[0]

        triggers.create_cron_trigger(
            'test',
            wf.name,
            {},
            {},
            '* * * * * */1',
            None,
            None,
            None
        )

        next_triggers = triggers.get_next_cron_triggers()

        self.assertEqual(1, len(next_triggers))

        next_trigger = next_triggers[0]
        next_execution_time_before = next_trigger.next_execution_time

        periodic.MistralPeriodicTasks(cfg.CONF).process_cron_triggers_v2(None)

        next_triggers = triggers.get_next_cron_triggers()

        self.assertEqual(1, len(next_triggers))

        next_trigger = next_triggers[0]
        next_execution_time_after = next_trigger.next_execution_time

        self.assertNotEqual(
            next_execution_time_before,
            next_execution_time_after
        )
示例#25
0
    def test_get_trigger_in_correct_orders(self):
        t_s.create_cron_trigger('test1', self.wf.name, {}, {}, '*/5 * * * *',
                                None, None, datetime.datetime(2010, 8, 25))

        t_s.create_cron_trigger('test2', self.wf.name, {}, {}, '*/1 * * * *',
                                None, None, datetime.datetime(2010, 8, 22))

        t_s.create_cron_trigger('test3', self.wf.name, {}, {}, '*/2 * * * *',
                                None, None, datetime.datetime(2010, 9, 21))

        t_s.create_cron_trigger(
            'test4', self.wf.name, {}, {}, '*/3 * * * *', None, None,
            datetime.datetime.now() + datetime.timedelta(0, 50))

        trigger_names = [t.name for t in t_s.get_next_cron_triggers()]

        self.assertEqual(trigger_names, ['test2', 'test1', 'test3'])
示例#26
0
    def test_create_cron_trigger_with_pattern_and_first_time(self,
                                                             validate_mock):
        cfg.CONF.set_default('auth_enable', False, group='pecan')

        wf = workflows.create_workflows(WORKFLOW_LIST)[0]

        # Make the first_time 1 sec later than current time, in order to make
        # it executed by next cron-trigger task.
        first_time = datetime.datetime.now() + datetime.timedelta(0, 1)

        # Creates a cron-trigger with pattern and first time, ensure the
        # cron-trigger can be executed more than once, and cron-trigger will
        # not be deleted.
        trigger_name = 'trigger-%s' % utils.generate_unicode_uuid()

        cron_trigger = triggers.create_cron_trigger(
            trigger_name,
            wf.name,
            {},
            {},
            '*/1 * * * *',
            first_time,
            None,
            None
        )

        first_second = time.mktime(first_time.timetuple())
        first_utc_time = datetime.datetime.utcfromtimestamp(first_second)

        self.assertEqual(
            first_utc_time,
            cron_trigger.next_execution_time
        )

        periodic.MistralPeriodicTasks(cfg.CONF).process_cron_triggers_v2(None)

        next_time = triggers.get_next_execution_time(
            cron_trigger.pattern,
            cron_trigger.next_execution_time
        )

        cron_trigger_db = db_api.get_cron_trigger(trigger_name)

        self.assertIsNotNone(cron_trigger_db)
        self.assertEqual(
            next_time,
            cron_trigger_db.next_execution_time
        )
示例#27
0
    def test_oneshot_trigger_create(self):
        trigger = t_s.create_cron_trigger(
            'test',
            self.wf.name,
            {},
            {},
            None,
            "4242-12-25 13:37",
            None,
            datetime.datetime(2010, 8, 25)
        )

        self.assertEqual(
            datetime.datetime(4242, 12, 25, 13, 37),
            trigger.next_execution_time
        )
示例#28
0
    def test_create_cron_trigger_with_pattern_and_first_time(self,
                                                             validate_mock):
        cfg.CONF.set_default('auth_enable', False, group='pecan')

        wf = workflows.create_workflows(WORKFLOW_LIST)[0]

        # Make the first_time 1 sec later than current time, in order to make
        # it executed by next cron-trigger task.
        first_time = datetime.datetime.utcnow() + datetime.timedelta(0, 1)

        # Creates a cron-trigger with pattern and first time, ensure the
        # cron-trigger can be executed more than once, and cron-trigger will
        # not be deleted.
        trigger_name = 'trigger-%s' % utils.generate_unicode_uuid()

        cron_trigger = triggers.create_cron_trigger(
            trigger_name,
            wf.name,
            {},
            {},
            '*/1 * * * *',
            first_time,
            None,
            None
        )

        interval = (cron_trigger.next_execution_time - first_time)

        self.assertLessEqual(interval.total_seconds(), 3.0)

        periodic.process_cron_triggers_v2(None, None)

        # After process_triggers context is set to None, need to reset it.
        auth_ctx.set_ctx(self.ctx)

        next_time = triggers.get_next_execution_time(
            cron_trigger.pattern,
            cron_trigger.next_execution_time
        )

        cron_trigger_db = db_api.get_cron_trigger(trigger_name)

        self.assertIsNotNone(cron_trigger_db)

        interval = (cron_trigger_db.next_execution_time - next_time)

        self.assertLessEqual(interval.total_seconds(), 3.0)
示例#29
0
    def post(self, cron_trigger):
        """Creates a new cron trigger."""

        LOG.info('Create cron trigger: %s' % cron_trigger)

        values = cron_trigger.to_dict()

        db_model = triggers.create_cron_trigger(
            values['name'],
            values['workflow_name'],
            values.get('workflow_input'),
            values.get('workflow_params'),
            values.get('pattern'),
            values.get('first_execution_time'),
            values.get('remaining_executions')
        )

        return CronTrigger.from_dict(db_model.to_dict())
示例#30
0
    def post(self, cron_trigger):
        """Creates a new cron trigger."""
        acl.enforce('cron_triggers:create', context.ctx())

        LOG.info('Create cron trigger: %s' % cron_trigger)

        values = cron_trigger.to_dict()

        db_model = triggers.create_cron_trigger(
            values['name'],
            values.get('workflow_name'),
            values.get('workflow_input'),
            values.get('workflow_params'),
            values.get('pattern'),
            values.get('first_execution_time'),
            values.get('remaining_executions'),
            workflow_id=values.get('workflow_id'))

        return resources.CronTrigger.from_dict(db_model.to_dict())
示例#31
0
    def test_create_trust_in_trigger(self):
        cfg.CONF.set_default('auth_enable', True, group='pecan')
        self.addCleanup(
            cfg.CONF.set_default, 'auth_enable',
            False, group='pecan'
        )

        trigger = t_s.create_cron_trigger(
            'test',
            self.wf.name,
            {},
            {},
            '*/2 * * * *',
            None,
            None,
            datetime.datetime(2010, 8, 25)
        )

        self.assertEqual('my_trust_id', trigger.trust_id)
    def test_trigger_create_the_same_first_time_or_count(self):
        t_s.create_cron_trigger(
            'trigger-%s' % utils.generate_unicode_uuid(),
            self.wf.name,
            {},
            {},
            '*/5 * * * *',
            "4242-12-25 13:37",
            2,
            datetime.datetime(2010, 8, 25)
        )

        t_s.create_cron_trigger(
            'trigger-%s' % utils.generate_unicode_uuid(),
            self.wf.name,
            {},
            {},
            '*/5 * * * *',
            "4242-12-25 13:37",
            4,
            datetime.datetime(2010, 8, 25)
        )

        t_s.create_cron_trigger(
            'trigger-%s' % utils.generate_unicode_uuid(),
            self.wf.name,
            {},
            {},
            '*/5 * * * *',
            "5353-12-25 13:37",
            2,
            datetime.datetime(2010, 8, 25)
        )

        # Creations above should be ok.

        # But creation with the same count and first time
        # simultaneously leads to error.
        self.assertRaises(
            exc.DBDuplicateEntryError,
            t_s.create_cron_trigger,
            'trigger-%s' % utils.generate_unicode_uuid(),
            self.wf.name,
            {},
            {},
            '*/5 * * * *',
            "4242-12-25 13:37",
            2,
            None
        )
示例#33
0
    def post(self, cron_trigger):
        """Creates a new cron trigger."""
        acl.enforce('cron_triggers:create', context.ctx())

        LOG.info('Create cron trigger: %s' % cron_trigger)

        values = cron_trigger.to_dict()

        db_model = triggers.create_cron_trigger(
            values['name'],
            values.get('workflow_name'),
            values.get('workflow_input'),
            values.get('workflow_params'),
            values.get('pattern'),
            values.get('first_execution_time'),
            values.get('remaining_executions'),
            workflow_id=values.get('workflow_id')
        )

        return resources.CronTrigger.from_dict(db_model.to_dict())
示例#34
0
    def test_create_cron_trigger_with_pattern_and_first_time(self,
                                                             validate_mock):
        wf = workflows.create_workflows(WORKFLOW_LIST)[0]

        # Make the first_time 1 sec later than current time, in order to make
        # it executed by next cron-trigger task.
        first_time = datetime.datetime.now() + datetime.timedelta(0, 1)

        # Creates a cron-trigger with pattern and first time, ensure the
        # cron-trigger can be executed more than once, and cron-trigger will
        # not be deleted.
        cron_trigger = triggers.create_cron_trigger(
            'test',
            wf.name,
            {},
            {},
            '*/1 * * * *',
            first_time,
            None,
            None
        )

        self.assertEqual(
            first_time,
            cron_trigger.next_execution_time
        )

        periodic.MistralPeriodicTasks(cfg.CONF).process_cron_triggers_v2(None)

        next_time = triggers.get_next_execution_time(
            cron_trigger.pattern,
            cron_trigger.next_execution_time
        )

        cron_trigger_db = db_api.get_cron_trigger('test')

        self.assertIsNotNone(cron_trigger_db)
        self.assertEqual(
            next_time,
            cron_trigger_db.next_execution_time
        )
示例#35
0
    def test_start_workflow(self, get_engine_client_mock):
        cfg.CONF.set_default('auth_enable', True, group='pecan')

        wf = workflows.create_workflows(WORKFLOW_LIST)[0]

        t = triggers.create_cron_trigger(
            'trigger-%s' % utils.generate_unicode_uuid(), wf.name, {}, {},
            '* * * * * */1', None, None, None)

        self.assertEqual('my_trust_id', t.trust_id)

        cfg.CONF.set_default('auth_enable', False, group='pecan')

        next_trigger = triggers.get_next_cron_triggers()[0]
        next_execution_time_before = next_trigger.next_execution_time

        periodic.process_cron_triggers_v2(None, None)
        start_wf_mock = get_engine_client_mock.return_value.start_workflow

        start_wf_mock.assert_called_once()

        # Check actual parameters of the call.
        self.assertEqual(('my_wf', '', None, {}),
                         start_wf_mock.mock_calls[0][1])
        self.assertIn(t.id, start_wf_mock.mock_calls[0][2]['description'])

        self._await(lambda: triggers.get_next_cron_triggers(),
                    fail_message="No triggers were found")

        next_triggers = triggers.get_next_cron_triggers()
        self.assertEqual(1, len(next_triggers))

        next_trigger = next_triggers[0]
        next_execution_time_after = next_trigger.next_execution_time

        # Checking the workflow was executed, by
        # verifying that the next execution time changed.
        self.assertNotEqual(next_execution_time_before,
                            next_execution_time_after)
示例#36
0
    def test_trigger_create(self):
        trigger = t_s.create_cron_trigger(
            'test',
            self.wf.name,
            {},
            {},
            '*/5 * * * *',
            None,
            None,
            datetime.datetime(2010, 8, 25)
        )

        self.assertEqual(
            datetime.datetime(2010, 8, 25, 0, 5),
            trigger.next_execution_time
        )

        next_time = t_s.get_next_execution_time(
            trigger['pattern'],
            trigger.next_execution_time
        )

        self.assertEqual(datetime.datetime(2010, 8, 25, 0, 10), next_time)