Esempio n. 1
0
    def test_execute_with_exception(self, m_send_update, m_execution,
                                    m_get_actionplan, m_get_strategy):
        m_get_actionplan.return_value = obj_utils.get_test_action_plan(
            self.context, id=0)
        m_get_strategy.return_value = obj_utils.get_test_strategy(
            self.context, id=1)
        actions = []

        third = self.create_action("no_exist", {'message': 'next'})
        second = self.create_action("sleep", {'duration': 0.0})
        first = self.create_action("nop", {'message': 'hello'})

        self.check_action_state(first, objects.action.State.PENDING)
        self.check_action_state(second, objects.action.State.PENDING)
        self.check_action_state(third, objects.action.State.PENDING)

        actions.append(first)
        actions.append(second)
        actions.append(third)

        self.engine.execute(actions)

        self.check_action_state(first, objects.action.State.SUCCEEDED)
        self.check_action_state(second, objects.action.State.SUCCEEDED)
        self.check_action_state(third, objects.action.State.FAILED)
Esempio n. 2
0
    def test_send_invalid_action_plan(self):
        action_plan = utils.get_test_action_plan(
            mock.Mock(), state='DOESNOTMATTER', audit_id=1)

        self.assertRaises(
            exception.InvalidActionPlan,
            notifications.action_plan.send_update,
            mock.MagicMock(), action_plan, host='node0')
Esempio n. 3
0
    def test_execute_with_action_failed(self, m_make_action, m_send_update,
                                        m_send_execution, m_get_actionplan,
                                        m_get_strategy):
        m_get_actionplan.return_value = obj_utils.get_test_action_plan(
            self.context, id=0)
        m_get_strategy.return_value = obj_utils.get_test_strategy(
            self.context, id=1)
        actions = [self.create_action("fake_action", {})]
        m_make_action.return_value = FakeAction(mock.Mock())

        self.engine.execute(actions)
        self.check_action_state(actions[0], objects.action.State.FAILED)
    def test_execute_with_one_action(self, mock_send_update,
                                     mock_execution_notification,
                                     m_get_actionplan):
        m_get_actionplan.return_value = obj_utils.get_test_action_plan(
            self.context, id=0)
        actions = [self.create_action("nop", {'message': 'test'})]
        try:
            self.engine.execute(actions)
            self.check_actions_state(actions, objects.action.State.SUCCEEDED)

        except Exception as exc:
            self.fail(exc)
Esempio n. 5
0
    def test_execute_with_action_exception(self, m_make_action, m_send_update,
                                           m_send_execution, m_get_actionplan):
        m_get_actionplan.return_value = obj_utils.get_test_action_plan(
            self.context, id=0)
        actions = [self.create_action("fake_action", {})]
        m_make_action.return_value = FakeAction(mock.Mock())

        exc = self.assertRaises(exception.WorkflowExecutionException,
                                self.engine.execute, actions)

        self.assertIsInstance(exc.kwargs['error'], ExpectedException)
        self.check_action_state(actions[0], objects.action.State.FAILED)
    def test_execute_with_two_actions(self, m_send_update, m_execution,
                                      m_get_actionplan):
        m_get_actionplan.return_value = obj_utils.get_test_action_plan(
            self.context, id=0)
        actions = []
        second = self.create_action("sleep", {'duration': 0.0})
        first = self.create_action("nop", {'message': 'test'})

        actions.append(first)
        actions.append(second)

        try:
            self.engine.execute(actions)
            self.check_actions_state(actions, objects.action.State.SUCCEEDED)

        except Exception as exc:
            self.fail(exc)
    def test_execute_nop_sleep(self, mock_send_update,
                               mock_execution_notification, m_get_actionplan):
        m_get_actionplan.return_value = obj_utils.get_test_action_plan(
            self.context, id=0)
        actions = []
        first_nop = self.create_action("nop", {'message': 'test'})
        second_nop = self.create_action("nop", {'message': 'second test'})
        sleep = self.create_action("sleep", {'duration': 0.0},
                                   parents=[first_nop.uuid, second_nop.uuid])
        actions.extend([first_nop, second_nop, sleep])

        try:
            self.engine.execute(actions)
            self.check_actions_state(actions, objects.action.State.SUCCEEDED)

        except Exception as exc:
            self.fail(exc)
Esempio n. 8
0
    def test_execute_with_parents(self, mock_send_update,
                                  mock_execution_notification,
                                  m_get_actionplan, m_get_strategy):
        m_get_actionplan.return_value = obj_utils.get_test_action_plan(
            self.context, id=0)
        m_get_strategy.return_value = obj_utils.get_test_strategy(
            self.context, id=1)
        actions = []
        first_nop = self.create_action(
            "nop", {'message': 'test'},
            uuid='bc7eee5c-4fbe-4def-9744-b539be55aa19')
        second_nop = self.create_action(
            "nop", {'message': 'second test'},
            uuid='0565bd5c-aa00-46e5-8d81-2cb5cc1ffa23')
        first_sleep = self.create_action(
            "sleep", {'duration': 0.0}, parents=[first_nop.uuid,
                                                 second_nop.uuid],
            uuid='be436531-0da3-4dad-a9c0-ea1d2aff6496')
        second_sleep = self.create_action(
            "sleep", {'duration': 0.0}, parents=[first_sleep.uuid],
            uuid='9eb51e14-936d-4d12-a500-6ba0f5e0bb1c')
        actions.extend([first_nop, second_nop, first_sleep, second_sleep])

        expected_nodes = [
            {'uuid': 'bc7eee5c-4fbe-4def-9744-b539be55aa19',
             'input_parameters': {u'message': u'test'},
             'action_plan_id': 0, 'state': u'PENDING', 'parents': [],
             'action_type': u'nop', 'id': 1},
            {'uuid': '0565bd5c-aa00-46e5-8d81-2cb5cc1ffa23',
             'input_parameters': {u'message': u'second test'},
             'action_plan_id': 0, 'state': u'PENDING', 'parents': [],
             'action_type': u'nop', 'id': 2},
            {'uuid': 'be436531-0da3-4dad-a9c0-ea1d2aff6496',
             'input_parameters': {u'duration': 0.0},
             'action_plan_id': 0, 'state': u'PENDING',
             'parents': [u'bc7eee5c-4fbe-4def-9744-b539be55aa19',
                         u'0565bd5c-aa00-46e5-8d81-2cb5cc1ffa23'],
             'action_type': u'sleep', 'id': 3},
            {'uuid': '9eb51e14-936d-4d12-a500-6ba0f5e0bb1c',
             'input_parameters': {u'duration': 0.0},
             'action_plan_id': 0, 'state': u'PENDING',
             'parents': [u'be436531-0da3-4dad-a9c0-ea1d2aff6496'],
             'action_type': u'sleep', 'id': 4}]

        expected_edges = [
            ('action_type:nop uuid:0565bd5c-aa00-46e5-8d81-2cb5cc1ffa23',
             'action_type:sleep uuid:be436531-0da3-4dad-a9c0-ea1d2aff6496'),
            ('action_type:nop uuid:bc7eee5c-4fbe-4def-9744-b539be55aa19',
             'action_type:sleep uuid:be436531-0da3-4dad-a9c0-ea1d2aff6496'),
            ('action_type:sleep uuid:be436531-0da3-4dad-a9c0-ea1d2aff6496',
             'action_type:sleep uuid:9eb51e14-936d-4d12-a500-6ba0f5e0bb1c')]

        try:
            flow = self.engine.execute(actions)
            actual_nodes = sorted([x[0]._db_action.as_dict()
                                   for x in flow.iter_nodes()],
                                  key=lambda x: x['id'])
            for expected, actual in zip(expected_nodes, actual_nodes):
                for key in expected.keys():
                    self.assertIn(expected[key], actual.values())
            actual_edges = [(u.name, v.name)
                            for (u, v, _) in flow.iter_links()]

            for edge in expected_edges:
                self.assertIn(edge, actual_edges)

            self.check_actions_state(actions, objects.action.State.SUCCEEDED)

        except Exception as exc:
            self.fail(exc)
Esempio n. 9
0
    def test_send_action_plan_create(self):
        action_plan = utils.get_test_action_plan(
            mock.Mock(), state=objects.action_plan.State.PENDING,
            audit_id=self.audit.id, strategy_id=self.strategy.id,
            audit=self.audit.as_dict(), strategy=self.strategy.as_dict())
        notifications.action_plan.send_create(
            mock.MagicMock(), action_plan, host='node0')

        self.assertEqual(2, self.m_notifier.info.call_count)
        notification = self.m_notifier.info.call_args[1]
        payload = notification['payload']

        self.assertEqual("infra-optim:node0", self.m_notifier.publisher_id)
        self.assertDictEqual(
            {
                "watcher_object.namespace": "watcher",
                "watcher_object.version": "1.1",
                "watcher_object.data": {
                    "global_efficacy": [],
                    "strategy_uuid": "cb3d0b58-4415-4d90-b75b-1e96878730e3",
                    "strategy": {
                        "watcher_object.namespace": "watcher",
                        "watcher_object.version": "1.0",
                        "watcher_object.data": {
                            "updated_at": None,
                            "uuid": "cb3d0b58-4415-4d90-b75b-1e96878730e3",
                            "name": "TEST",
                            "parameters_spec": {},
                            "created_at": "2016-10-18T09:52:05Z",
                            "display_name": "test strategy",
                            "deleted_at": None
                        },
                        "watcher_object.name": "StrategyPayload"
                    },
                    "uuid": "76be87bd-3422-43f9-93a0-e85a577e3061",
                    "audit_uuid": "10a47dd1-4874-4298-91cf-eff046dbdb8d",
                    "audit": {
                        "watcher_object.data": {
                            "interval": None,
                            "next_run_time": None,
                            "auto_trigger": False,
                            "parameters": {},
                            "uuid": "10a47dd1-4874-4298-91cf-eff046dbdb8d",
                            "name": "My Audit",
                            "strategy_uuid": None,
                            "goal_uuid": (
                                "f7ad87ae-4298-91cf-93a0-f35a852e3652"),
                            "deleted_at": None,
                            "scope": [],
                            "state": "PENDING",
                            "updated_at": None,
                            "created_at": "2016-10-18T09:52:05Z",
                            "audit_type": "ONESHOT"
                        },
                        "watcher_object.name": "TerseAuditPayload",
                        "watcher_object.namespace": "watcher",
                        "watcher_object.version": "1.2"
                    },
                    "deleted_at": None,
                    "state": "PENDING",
                    "updated_at": None,
                    "created_at": None,
                },
                "watcher_object.name": "ActionPlanCreatePayload"
            },
            payload
        )