def test_abort_workflow(self):
        execution_db_help.load_playbook('pauseWorkflowTest')

        workflow = self.app.running_context.execution_db.session.query(
            Workflow).filter_by(name='pauseWorkflow').first()

        result = {"aborted": False}

        @WalkoffEvent.ActionExecutionSuccess.connect
        def y(sender, **kwargs):
            self.act_on_workflow(response['id'], 'abort')

        @WalkoffEvent.WorkflowAborted.connect
        def workflow_aborted_listener(sender, **kwargs):
            result['aborted'] = True

        response = self.post_with_status_check(
            '/api/workflowqueue',
            headers=self.headers,
            status_code=SUCCESS_ASYNC,
            content_type="application/json",
            data=json.dumps({'workflow_id': str(workflow.id)}))

        current_app.running_context.executor.wait_and_reset(1)
        self.assertIn('id', response)
        self.assertTrue(result['aborted'])

        workflow_status = self.app.running_context.execution_db.session.query(
            WorkflowStatus).filter_by(execution_id=response['id']).first()
        self.assertIsNotNone(workflow_status)
        self.assertEqual(workflow_status.status.name, 'aborted')
Пример #2
0
    def test_pause_resume_scheduler_execution(self):
        execution_db_help.load_playbook('testScheduler')

        subs = {
            'controller': [
                event.signal_name for event in WalkoffEvent
                if event.event_type == EventType.controller
            ]
        }
        case_subscription.set_subscriptions({'pauseResume': subs})

        scheduler.start()
        scheduler.pause()
        time.sleep(0.1)
        scheduler.resume()
        time.sleep(0.1)
        scheduler.stop(wait=False)

        pause_resume_event_history = case_database.case_db.session.query(case_database.Case) \
            .filter(case_database.Case.name == 'pauseResume').first().events.all()

        self.assertEqual(
            len(pause_resume_event_history), 4,
            'Incorrect length of event history. '
            'Expected {0}, got {1}'.format(4, len(pause_resume_event_history)))
Пример #3
0
    def test_action_metrics(self):
        playbook = execution_db_help.load_playbook('multiactionError')
        workflow_id = current_app.running_context.execution_db.session.query(
            Workflow).filter(
                and_(Workflow.name == 'multiactionErrorWorkflow',
                     Workflow.playbook_id == playbook.id)).first().id

        current_app.running_context.executor.execute_workflow(workflow_id)

        current_app.running_context.executor.wait_and_reset(1)

        app_metrics = current_app.running_context.execution_db.session.query(
            AppMetric).all()
        self.assertEqual(len(app_metrics), 1)
        app_metric = app_metrics[0]

        self.assertEqual(app_metric.app, 'HelloWorldBounded')
        self.assertEqual(app_metric.count, 3)
        self.assertEqual(len(app_metric.actions), 3)

        action_names = ['repeatBackToMe', 'helloWorld', 'Buggy']
        for action in app_metric.actions:
            self.assertIn(action.action_name, action_names)
            action_names.remove(action.action_name)
            if action.action_name in ['repeatBackToMe', 'helloWorld']:
                self.assertEqual(len(action.action_statuses), 1)
                self.assertEqual(action.action_statuses[0].status, 'success')
                self.assertEqual(action.action_statuses[0].count, 1)
                self.assertGreater(action.action_statuses[0].avg_time, 0)
            elif action.action_name == 'Buggy':
                self.assertEqual(len(action.action_statuses), 1)
                self.assertEqual(action.action_statuses[0].status, 'error')
                self.assertEqual(action.action_statuses[0].count, 1)
                self.assertGreater(action.action_statuses[0].avg_time, 0)
Пример #4
0
    def test_action_metrics(self):
        playbook = execution_db_help.load_playbook('multiactionError')
        workflow_id = current_app.running_context.execution_db.session.query(Workflow).filter(and_(
            Workflow.name == 'multiactionErrorWorkflow', Workflow.playbook_id == playbook.id)).first().id

        current_app.running_context.executor.execute_workflow(workflow_id)

        current_app.running_context.executor.wait_and_reset(1)

        app_metrics = current_app.running_context.execution_db.session.query(AppMetric).all()
        self.assertEqual(len(app_metrics), 1)
        app_metric = app_metrics[0]

        self.assertEqual(app_metric.app, 'HelloWorldBounded')
        self.assertEqual(app_metric.count, 3)
        self.assertEqual(len(app_metric.actions), 3)

        action_names = ['repeatBackToMe', 'helloWorld', 'Buggy']
        for action in app_metric.actions:
            self.assertIn(action.action_name, action_names)
            action_names.remove(action.action_name)
            if action.action_name in ['repeatBackToMe', 'helloWorld']:
                self.assertEqual(len(action.action_statuses), 1)
                self.assertEqual(action.action_statuses[0].status, 'success')
                self.assertEqual(action.action_statuses[0].count, 1)
                self.assertGreater(action.action_statuses[0].avg_time, 0)
            elif action.action_name == 'Buggy':
                self.assertEqual(len(action.action_statuses), 1)
                self.assertEqual(action.action_statuses[0].status, 'error')
                self.assertEqual(action.action_statuses[0].count, 1)
                self.assertGreater(action.action_statuses[0].avg_time, 0)
Пример #5
0
    def test_action_metrics(self):
        playbook = execution_db_help.load_playbook('multiactionError')
        workflow_id = executiondb.execution_db.session.query(Workflow).filter(
            and_(Workflow.name == 'multiactionErrorWorkflow',
                 Workflow.playbook_id == playbook.id)).first().id

        server.running_context.executor.execute_workflow(workflow_id)

        server.running_context.executor.wait_and_reset(1)
        self.assertListEqual(list(metrics.app_metrics.keys()),
                             ['HelloWorldBounded'])
        orderless_list_compare(
            self, list(metrics.app_metrics['HelloWorldBounded'].keys()),
            ['count', 'actions'])
        self.assertEqual(metrics.app_metrics['HelloWorldBounded']['count'], 3)
        orderless_list_compare(
            self,
            list(metrics.app_metrics['HelloWorldBounded']['actions'].keys()),
            ['repeatBackToMe', 'helloWorld', 'Buggy'])
        orderless_list_compare(
            self,
            list(metrics.app_metrics['HelloWorldBounded']['actions']
                 ['repeatBackToMe'].keys()), ['success'])
        for form in ['success']:
            orderless_list_compare(
                self,
                list(metrics.app_metrics['HelloWorldBounded']['actions']
                     ['repeatBackToMe'][form].keys()), ['count', 'avg_time'])
            self.assertEqual(
                metrics.app_metrics['HelloWorldBounded']['actions']
                ['repeatBackToMe'][form]['count'], 1)
        orderless_list_compare(
            self,
            list(metrics.app_metrics['HelloWorldBounded']['actions']
                 ['helloWorld'].keys()), ['success'])
        orderless_list_compare(
            self,
            list(metrics.app_metrics['HelloWorldBounded']['actions']
                 ['helloWorld']['success'].keys()), ['count', 'avg_time'])
        self.assertEqual(
            metrics.app_metrics['HelloWorldBounded']['actions']['helloWorld']
            ['success']['count'], 1)