Ejemplo n.º 1
0
 def test_create_audit_already_exists(self):
     uuid = w_utils.generate_uuid()
     utils.create_test_audit(id=1, uuid=uuid)
     self.assertRaises(exception.AuditAlreadyExists,
                       utils.create_test_audit,
                       id=2,
                       uuid=uuid)
Ejemplo n.º 2
0
    def _data_setup(self):
        self.audit_template_name = "Audit Template"

        self.audit_template = utils.create_test_audit_template(
            name=self.audit_template_name, id=1, uuid=None)

        with freezegun.freeze_time(self.FAKE_TODAY):
            self.audit1 = utils.create_test_audit(
                audit_template_id=self.audit_template.id, id=1, uuid=None)
        with freezegun.freeze_time(self.FAKE_OLD_DATE):
            self.audit2 = utils.create_test_audit(
                audit_template_id=self.audit_template.id,
                id=2,
                uuid=None,
                state=objects.audit.State.FAILED)
        with freezegun.freeze_time(self.FAKE_OLDER_DATE):
            self.audit3 = utils.create_test_audit(
                audit_template_id=self.audit_template.id,
                id=3,
                uuid=None,
                state=objects.audit.State.CANCELLED)
        with freezegun.freeze_time(self.FAKE_OLDER_DATE):
            self.audit4 = utils.create_test_audit(
                audit_template_id=self.audit_template.id,
                id=4,
                uuid=None,
                state=objects.audit.State.SUSPENDED)
Ejemplo n.º 3
0
    def test_get_audit_list_with_filters(self):
        goal = utils.create_test_goal(name='DUMMY')

        audit1 = utils.create_test_audit(
            id=1,
            audit_type=objects.audit.AuditType.ONESHOT.value,
            uuid=w_utils.generate_uuid(),
            name='My Audit {0}'.format(1),
            state=objects.audit.State.ONGOING,
            goal_id=goal['id'])
        audit2 = utils.create_test_audit(
            id=2,
            audit_type=objects.audit.AuditType.CONTINUOUS.value,
            uuid=w_utils.generate_uuid(),
            name='My Audit {0}'.format(2),
            state=objects.audit.State.PENDING,
            goal_id=goal['id'])
        audit3 = utils.create_test_audit(
            id=3,
            audit_type=objects.audit.AuditType.CONTINUOUS.value,
            uuid=w_utils.generate_uuid(),
            name='My Audit {0}'.format(3),
            state=objects.audit.State.ONGOING,
            goal_id=goal['id'])

        self.dbapi.soft_delete_audit(audit3['uuid'])

        res = self.dbapi.get_audit_list(
            self.context,
            filters={'audit_type': objects.audit.AuditType.ONESHOT.value})
        self.assertEqual([audit1['id']], [r.id for r in res])

        res = self.dbapi.get_audit_list(self.context,
                                        filters={'audit_type': 'bad-type'})
        self.assertEqual([], [r.id for r in res])

        res = self.dbapi.get_audit_list(
            self.context, filters={'state': objects.audit.State.ONGOING})
        self.assertEqual([audit1['id']], [r.id for r in res])

        res = self.dbapi.get_audit_list(
            self.context, filters={'state': objects.audit.State.PENDING})
        self.assertEqual([audit2['id']], [r.id for r in res])

        res = self.dbapi.get_audit_list(self.context,
                                        filters={'goal_name': 'DUMMY'})
        self.assertEqual(sorted([audit1['id'], audit2['id']]),
                         sorted([r.id for r in res]))

        temp_context = self.context
        temp_context.show_deleted = True
        res = self.dbapi.get_audit_list(temp_context,
                                        filters={'goal_name': 'DUMMY'})
        self.assertEqual(sorted([audit1['id'], audit2['id'], audit3['id']]),
                         sorted([r.id for r in res]))
Ejemplo n.º 4
0
    def _data_setup(self):
        self.audit_template_name = "Audit Template"

        self.audit_template = utils.create_test_audit_template(
            name=self.audit_template_name, id=1, uuid=None)

        with freezegun.freeze_time(self.FAKE_TODAY):
            self.audit1 = utils.create_test_audit(
                audit_template_id=self.audit_template.id, id=1, uuid=None)
        with freezegun.freeze_time(self.FAKE_OLD_DATE):
            self.audit2 = utils.create_test_audit(
                audit_template_id=self.audit_template.id, id=2, uuid=None)
        with freezegun.freeze_time(self.FAKE_OLDER_DATE):
            self.audit3 = utils.create_test_audit(
                audit_template_id=self.audit_template.id, id=3, uuid=None)
Ejemplo n.º 5
0
    def _data_setup(self):
        self.audit_template_name = "Audit Template"

        self.audit_template = utils.create_test_audit_template(
            name=self.audit_template_name, id=1, uuid=None)

        with freezegun.freeze_time(self.FAKE_TODAY):
            self.audit1 = utils.create_test_audit(
                audit_template_id=self.audit_template.id, id=1, uuid=None)
        with freezegun.freeze_time(self.FAKE_OLD_DATE):
            self.audit2 = utils.create_test_audit(
                audit_template_id=self.audit_template.id, id=2, uuid=None)
        with freezegun.freeze_time(self.FAKE_OLDER_DATE):
            self.audit3 = utils.create_test_audit(
                audit_template_id=self.audit_template.id, id=3, uuid=None)
Ejemplo n.º 6
0
    def test_schedule_two_actions(self):
        default_planner = pbase.DefaultPlanner(mock.Mock())
        audit = db_utils.create_test_audit(uuid=utils.generate_uuid())
        solution = dsol.DefaultSolution(
            goal=mock.Mock(), strategy=mock.Mock())

        parameters = {
            "src_uuid_hypervisor": "server1",
            "dst_uuid_hypervisor": "server2",
        }
        solution.add_action(action_type="migrate",
                            resource_id="b199db0c-1408-4d52-b5a5-5ca14de0ff36",
                            input_parameters=parameters)

        solution.add_action(action_type="nop",
                            resource_id="",
                            input_parameters={})

        with mock.patch.object(
                pbase.DefaultPlanner, "create_action",
                wraps=default_planner.create_action) as m_create_action:
            action_plan = default_planner.schedule(
                self.context, audit.id, solution
            )
        self.assertIsNotNone(action_plan.uuid)
        self.assertEqual(2, m_create_action.call_count)
        # check order
        filters = {'action_plan_id': action_plan.id}
        actions = objects.Action.dbapi.get_action_list(self.context, filters)
        self.assertEqual("nop", actions[0].action_type)
        self.assertEqual("migrate", actions[1].action_type)
Ejemplo n.º 7
0
    def test_get_audit_list_with_filter_by_uuid(self):
        audit = utils.create_test_audit()
        res = self.dbapi.get_audit_list(self.context,
                                        filters={'uuid': audit["uuid"]})

        self.assertEqual(len(res), 1)
        self.assertEqual(audit['uuid'], res[0].uuid)
Ejemplo n.º 8
0
 def setUp(self):
     super(TestCreateDeleteActionObject, self).setUp()
     self.fake_strategy = utils.create_test_strategy(name="DUMMY")
     self.fake_audit = utils.create_test_audit()
     self.fake_action_plan = utils.create_test_action_plan()
     self.fake_action = utils.get_test_action(
         created_at=datetime.datetime.utcnow())
Ejemplo n.º 9
0
    def test_schedule_actions_with_unknown_action(self):
        default_planner = pbase.DefaultPlanner(mock.Mock())
        audit = db_utils.create_test_audit(uuid=utils.generate_uuid())
        solution = dsol.DefaultSolution(
            goal=mock.Mock(), strategy=mock.Mock())

        parameters = {
            "src_uuid_hypervisor": "server1",
            "dst_uuid_hypervisor": "server2",
        }
        solution.add_action(action_type="migrate",
                            resource_id="b199db0c-1408-4d52-b5a5-5ca14de0ff36",
                            input_parameters=parameters)

        solution.add_action(action_type="new_action_type",
                            resource_id="",
                            input_parameters={})

        with mock.patch.object(
                pbase.DefaultPlanner, "create_action",
                wraps=default_planner.create_action) as m_create_action:
            default_planner.config.weights = {'migrate': 0}
            self.assertRaises(KeyError, default_planner.schedule,
                              self.context, audit.id, solution)
        self.assertEqual(2, m_create_action.call_count)
Ejemplo n.º 10
0
    def _data_setup(self):
        self.audit_template_name = "Audit Template"

        self.audit_template = utils.create_test_audit_template(
            name=self.audit_template_name, id=1, uuid=None)
        self.audit = utils.create_test_audit(
            audit_template_id=self.audit_template.id, id=1, uuid=None)
        self.action_plan = utils.create_test_action_plan(
            audit_id=self.audit.id, id=1, uuid=None)

        with freezegun.freeze_time(self.FAKE_TODAY):
            self.efficacy_indicator1 = utils.create_test_efficacy_indicator(
                action_plan_id=self.action_plan.id,
                id=1,
                uuid=None,
                name="efficacy_indicator1",
                description="Test Indicator 1")
        with freezegun.freeze_time(self.FAKE_OLD_DATE):
            self.efficacy_indicator2 = utils.create_test_efficacy_indicator(
                action_plan_id=self.action_plan.id,
                id=2,
                uuid=None,
                name="efficacy_indicator2",
                description="Test Indicator 2")
        with freezegun.freeze_time(self.FAKE_OLDER_DATE):
            self.efficacy_indicator3 = utils.create_test_efficacy_indicator(
                action_plan_id=self.action_plan.id,
                id=3,
                uuid=None,
                name="efficacy_indicator3",
                description="Test Indicator 3")
Ejemplo n.º 11
0
    def test_schedule_two_actions(self):
        default_planner = pbase.DefaultPlanner()
        audit = db_utils.create_test_audit(uuid=utils.generate_uuid())
        solution = dsol.DefaultSolution()

        parameters = {
            "src_uuid_hypervisor": "server1",
            "dst_uuid_hypervisor": "server2",
        }
        solution.add_action(action_type="migrate",
                            resource_id="b199db0c-1408-4d52-b5a5-5ca14de0ff36",
                            input_parameters=parameters)

        solution.add_action(action_type="nop",
                            resource_id="",
                            input_parameters={})

        with mock.patch.object(
                pbase.DefaultPlanner,
                "create_action",
                wraps=default_planner.create_action) as m_create_action:
            action_plan = default_planner.schedule(self.context, audit.id,
                                                   solution)
        self.assertIsNotNone(action_plan.uuid)
        self.assertEqual(2, m_create_action.call_count)
        # check order
        filters = {'action_plan_id': action_plan.id}
        actions = objects.Action.dbapi.get_action_list(self.context, filters)
        self.assertEqual("nop", actions[0].action_type)
        self.assertEqual("migrate", actions[1].action_type)
 def setUp(self):
     super(TestActionScheduling, self).setUp()
     self.goal = db_utils.create_test_goal(name="dummy")
     self.strategy = db_utils.create_test_strategy(name="dummy")
     self.audit = db_utils.create_test_audit(uuid=utils.generate_uuid(),
                                             strategy_id=self.strategy.id)
     self.planner = pbase.WeightPlanner(
         mock.Mock(weights={
             'turn_host_to_acpi_s3_state': 10,
             'resize': 20,
             'migrate': 30,
             'sleep': 40,
             'change_nova_service_state': 50,
             'nop': 60,
             'new_action_type': 70,
         },
                   parallelization={
                       'turn_host_to_acpi_s3_state': 2,
                       'resize': 2,
                       'migrate': 2,
                       'sleep': 1,
                       'change_nova_service_state': 1,
                       'nop': 1,
                       'new_action_type': 70,
                   }))
Ejemplo n.º 13
0
 def test_scheduler_warning_empty_action_plan(self, m_get_by_name):
     m_get_by_name.return_value = self.strategy
     audit = db_utils.create_test_audit(uuid=utils.generate_uuid())
     fake_solution = SolutionFaker.build()
     action_plan = self.default_planner.schedule(self.context, audit.id,
                                                 fake_solution)
     self.assertIsNotNone(action_plan.uuid)
Ejemplo n.º 14
0
 def test_get_audit_list(self):
     uuids = []
     for _ in range(1, 6):
         audit = utils.create_test_audit(uuid=w_utils.generate_uuid())
         uuids.append(six.text_type(audit['uuid']))
     res = self.dbapi.get_audit_list(self.context)
     res_uuids = [r.uuid for r in res]
     self.assertEqual(uuids.sort(), res_uuids.sort())
Ejemplo n.º 15
0
 def test_create_same_name_audit(self):
     audit = utils.create_test_audit(uuid=w_utils.generate_uuid(),
                                     name='my_audit')
     self.assertEqual(audit['uuid'], audit.uuid)
     self.assertRaises(exception.AuditAlreadyExists,
                       utils.create_test_audit,
                       uuid=w_utils.generate_uuid(),
                       name='my_audit')
Ejemplo n.º 16
0
 def test_destroy_audit_by_uuid(self):
     audit = utils.create_test_audit()
     self.assertIsNotNone(
         self.dbapi.get_audit_by_uuid(self.context, audit['uuid']))
     self.dbapi.destroy_audit(audit['uuid'])
     self.assertRaises(exception.AuditNotFound,
                       self.dbapi.get_audit_by_uuid, self.context,
                       audit['uuid'])
Ejemplo n.º 17
0
 def setUp(self):
     super(TestActionScheduling, self).setUp()
     self.goal = db_utils.create_test_goal(name="dummy")
     self.strategy = db_utils.create_test_strategy(name="dummy")
     self.audit = db_utils.create_test_audit(uuid=utils.generate_uuid(),
                                             strategy_id=self.strategy.id)
     self.planner = pbase.WorkloadStabilizationPlanner(mock.Mock())
     self.nova_helper = nova_helper.NovaHelper(mock.Mock())
Ejemplo n.º 18
0
 def test_scheduler_warning_empty_action_plan(self, m_get_by_name):
     m_get_by_name.return_value = self.strategy
     audit = db_utils.create_test_audit(goal_id=self.goal.id,
                                        strategy_id=self.strategy.id)
     fake_solution = mock.MagicMock(efficacy_indicators=[], actions=[])
     action_plan = self.planner.schedule(self.context, audit.id,
                                         fake_solution)
     self.assertIsNotNone(action_plan.uuid)
Ejemplo n.º 19
0
 def setUp(self):
     super(TestActionScheduling, self).setUp()
     self.goal = db_utils.create_test_goal(name="server_consolidation")
     self.strategy = db_utils.create_test_strategy(
         name="node_resource_consolidation")
     self.audit = db_utils.create_test_audit(uuid=utils.generate_uuid(),
                                             strategy_id=self.strategy.id)
     self.planner = pbase.NodeResourceConsolidationPlanner(mock.Mock())
Ejemplo n.º 20
0
 def test_get_audit_list(self):
     uuids = []
     for _ in range(1, 6):
         audit = utils.create_test_audit(uuid=w_utils.generate_uuid())
         uuids.append(six.text_type(audit['uuid']))
     res = self.dbapi.get_audit_list(self.context)
     res_uuids = [r.uuid for r in res]
     self.assertEqual(uuids.sort(), res_uuids.sort())
Ejemplo n.º 21
0
    def test_get_action_list_with_filters(self):
        audit = utils.create_test_audit(uuid=w_utils.generate_uuid())
        action_plan = self._create_test_action_plan(
            id=1,
            uuid=w_utils.generate_uuid(),
            audit_id=audit.id,
            first_action_id=None,
            state='RECOMMENDED')
        action1 = self._create_test_action(
            id=1,
            action_plan_id=1,
            description='description action 1',
            uuid=w_utils.generate_uuid(),
            next=None,
            state='PENDING',
            alarm=None)
        action2 = self._create_test_action(
            id=2,
            action_plan_id=2,
            description='description action 2',
            uuid=w_utils.generate_uuid(),
            next=action1['uuid'],
            state='PENDING',
            alarm=None)
        action3 = self._create_test_action(
            id=3,
            action_plan_id=1,
            description='description action 3',
            uuid=w_utils.generate_uuid(),
            next=action2['uuid'],
            state='ONGOING',
            alarm=None)
        res = self.dbapi.get_action_list(self.context,
                                         filters={'state': 'ONGOING'})
        self.assertEqual([action3['id']], [r.id for r in res])

        res = self.dbapi.get_action_list(self.context,
                                         filters={'state': 'bad-state'})
        self.assertEqual([], [r.id for r in res])

        res = self.dbapi.get_action_list(
            self.context,
            filters={'action_plan_id': 2})
        self.assertEqual([action2['id']], [r.id for r in res])

        res = self.dbapi.get_action_list(
            self.context,
            filters={'action_plan_uuid': action_plan['uuid']})
        self.assertEqual(
            [action1['id'], action3['id']].sort(),
            [r.id for r in res].sort())

        res = self.dbapi.get_action_list(
            self.context,
            filters={'audit_uuid': audit.uuid})
        for action in res:
            self.assertEqual(action_plan['id'], action.action_plan_id)
Ejemplo n.º 22
0
    def test_get_efficacy_indicator_list_with_filters(self):
        audit = utils.create_test_audit(uuid=w_utils.generate_uuid())
        action_plan = utils.create_test_action_plan(
            id=1,
            uuid=w_utils.generate_uuid(),
            audit_id=audit.id,
            first_efficacy_indicator_id=None,
            state=objects.action_plan.State.RECOMMENDED)

        efficacy_indicator1 = utils.create_test_efficacy_indicator(
            id=1,
            name='indicator_1',
            uuid=w_utils.generate_uuid(),
            action_plan_id=action_plan['id'],
            description='Description efficacy indicator 1',
            unit='%')
        efficacy_indicator2 = utils.create_test_efficacy_indicator(
            id=2,
            name='indicator_2',
            uuid=w_utils.generate_uuid(),
            action_plan_id=2,
            description='Description efficacy indicator 2',
            unit='%')
        efficacy_indicator3 = utils.create_test_efficacy_indicator(
            id=3,
            name='indicator_3',
            uuid=w_utils.generate_uuid(),
            action_plan_id=action_plan['id'],
            description='Description efficacy indicator 3',
            unit='%')
        efficacy_indicator4 = utils.create_test_efficacy_indicator(
            id=4,
            name='indicator_4',
            uuid=w_utils.generate_uuid(),
            action_plan_id=action_plan['id'],
            description='Description efficacy indicator 4',
            unit='%')

        self.dbapi.soft_delete_efficacy_indicator(efficacy_indicator4['uuid'])

        res = self.dbapi.get_efficacy_indicator_list(
            self.context, filters={'name': 'indicator_3'})
        self.assertEqual([efficacy_indicator3['id']], [r.id for r in res])

        res = self.dbapi.get_efficacy_indicator_list(self.context,
                                                     filters={'unit': 'kWh'})
        self.assertEqual([], [r.id for r in res])

        res = self.dbapi.get_efficacy_indicator_list(
            self.context, filters={'action_plan_id': 2})
        self.assertEqual([efficacy_indicator2['id']], [r.id for r in res])

        res = self.dbapi.get_efficacy_indicator_list(
            self.context, filters={'action_plan_uuid': action_plan['uuid']})
        self.assertEqual(
            sorted([efficacy_indicator1['id'], efficacy_indicator3['id']]),
            sorted([r.id for r in res]))
Ejemplo n.º 23
0
 def test_get_audit_list(self):
     uuids = []
     for _ in range(1, 4):
         audit = utils.create_test_audit(uuid=w_utils.generate_uuid())
         uuids.append(six.text_type(audit['uuid']))
     audits = self.dbapi.get_audit_list(self.context)
     audit_uuids = [a.uuid for a in audits]
     self.assertEqual(sorted(uuids), sorted(audit_uuids))
     for audit in audits:
         self.assertIsNone(audit.goal)
         self.assertIsNone(audit.strategy)
Ejemplo n.º 24
0
    def setUp(self):
        super(TestActionPlanObject, self).setUp()

        p_action_plan_notifications = mock.patch.object(
            notifications, 'action_plan', autospec=True)
        self.m_action_plan_notifications = p_action_plan_notifications.start()
        self.addCleanup(p_action_plan_notifications.stop)
        self.m_send_update = self.m_action_plan_notifications.send_update

        self.fake_audit = utils.create_test_audit(id=self.audit_id)
        self.fake_strategy = utils.create_test_strategy(
            id=self.strategy_id, name="DUMMY")
Ejemplo n.º 25
0
    def setUp(self):
        super(TestCreateDeleteActionPlanObject, self).setUp()

        p_action_plan_notifications = mock.patch.object(
            notifications, 'action_plan', autospec=True)
        self.m_action_plan_notifications = p_action_plan_notifications.start()
        self.addCleanup(p_action_plan_notifications.stop)
        self.m_send_update = self.m_action_plan_notifications.send_update

        self.fake_strategy = utils.create_test_strategy(name="DUMMY")
        self.fake_audit = utils.create_test_audit()
        self.fake_action_plan = utils.get_test_action_plan(
            created_at=datetime.datetime.utcnow())
Ejemplo n.º 26
0
    def test_get_action_list_with_filters(self):
        audit = utils.create_test_audit(uuid=w_utils.generate_uuid())
        action_plan = self._create_test_action_plan(
            id=1,
            uuid=w_utils.generate_uuid(),
            audit_id=audit.id,
            parents=None,
            state=objects.action_plan.State.RECOMMENDED)
        action1 = self._create_test_action(
            id=1,
            action_plan_id=1,
            description='description action 1',
            uuid=w_utils.generate_uuid(),
            parents=None,
            state=objects.action_plan.State.PENDING)
        action2 = self._create_test_action(
            id=2,
            action_plan_id=2,
            description='description action 2',
            uuid=w_utils.generate_uuid(),
            parents=[action1['uuid']],
            state=objects.action_plan.State.PENDING)
        action3 = self._create_test_action(
            id=3,
            action_plan_id=1,
            description='description action 3',
            uuid=w_utils.generate_uuid(),
            parents=[action2['uuid']],
            state=objects.action_plan.State.ONGOING)
        res = self.dbapi.get_action_list(
            self.context, filters={'state': objects.action_plan.State.ONGOING})
        self.assertEqual([action3['id']], [r.id for r in res])

        res = self.dbapi.get_action_list(self.context,
                                         filters={'state': 'bad-state'})
        self.assertEqual([], [r.id for r in res])

        res = self.dbapi.get_action_list(self.context,
                                         filters={'action_plan_id': 2})
        self.assertEqual([action2['id']], [r.id for r in res])

        res = self.dbapi.get_action_list(
            self.context, filters={'action_plan_uuid': action_plan['uuid']})
        self.assertEqual(sorted([action1['id'], action3['id']]),
                         sorted([r.id for r in res]))

        res = self.dbapi.get_action_list(self.context,
                                         filters={'audit_uuid': audit.uuid})
        for action in res:
            self.assertEqual(action_plan['id'], action.action_plan_id)
Ejemplo n.º 27
0
    def test_get_action_list_with_filters(self):
        audit = utils.create_test_audit(uuid=w_utils.generate_uuid())
        action_plan = self._create_test_action_plan(
            id=1,
            uuid=w_utils.generate_uuid(),
            audit_id=audit.id,
            first_action_id=None,
            state='RECOMMENDED')
        action1 = self._create_test_action(id=1,
                                           action_plan_id=1,
                                           description='description action 1',
                                           uuid=w_utils.generate_uuid(),
                                           next=None,
                                           state='PENDING',
                                           alarm=None)
        action2 = self._create_test_action(id=2,
                                           action_plan_id=2,
                                           description='description action 2',
                                           uuid=w_utils.generate_uuid(),
                                           next=action1['uuid'],
                                           state='PENDING',
                                           alarm=None)
        action3 = self._create_test_action(id=3,
                                           action_plan_id=1,
                                           description='description action 3',
                                           uuid=w_utils.generate_uuid(),
                                           next=action2['uuid'],
                                           state='ONGOING',
                                           alarm=None)
        res = self.dbapi.get_action_list(self.context,
                                         filters={'state': 'ONGOING'})
        self.assertEqual([action3['id']], [r.id for r in res])

        res = self.dbapi.get_action_list(self.context,
                                         filters={'state': 'bad-state'})
        self.assertEqual([], [r.id for r in res])

        res = self.dbapi.get_action_list(self.context,
                                         filters={'action_plan_id': 2})
        self.assertEqual([action2['id']], [r.id for r in res])

        res = self.dbapi.get_action_list(
            self.context, filters={'action_plan_uuid': action_plan['uuid']})
        self.assertEqual([action1['id'], action3['id']].sort(),
                         [r.id for r in res].sort())

        res = self.dbapi.get_action_list(self.context,
                                         filters={'audit_uuid': audit.uuid})
        for action in res:
            self.assertEqual(action_plan['id'], action.action_plan_id)
Ejemplo n.º 28
0
    def test_get_efficacy_indicator_list_with_filters(self):
        audit = utils.create_test_audit(uuid=w_utils.generate_uuid())
        action_plan = self._create_test_action_plan(
            id=1,
            uuid=w_utils.generate_uuid(),
            audit_id=audit.id,
            first_efficacy_indicator_id=None,
            state='RECOMMENDED')
        efficacy_indicator1 = self._create_test_efficacy_indicator(
            id=1,
            name='indicator_1',
            uuid=w_utils.generate_uuid(),
            action_plan_id=1,
            description='Description efficacy indicator 1',
            unit='%')
        efficacy_indicator2 = self._create_test_efficacy_indicator(
            id=2,
            name='indicator_2',
            uuid=w_utils.generate_uuid(),
            action_plan_id=2,
            description='Description efficacy indicator 2',
            unit='%')
        efficacy_indicator3 = self._create_test_efficacy_indicator(
            id=3,
            name='indicator_3',
            uuid=w_utils.generate_uuid(),
            action_plan_id=1,
            description='Description efficacy indicator 3',
            unit='%')
        res = self.dbapi.get_efficacy_indicator_list(
            self.context, filters={'name': 'indicator_3'})
        self.assertEqual([efficacy_indicator3['id']], [r.id for r in res])

        res = self.dbapi.get_efficacy_indicator_list(
            self.context, filters={'unit': 'kWh'})
        self.assertEqual([], [r.id for r in res])

        res = self.dbapi.get_efficacy_indicator_list(
            self.context,
            filters={'action_plan_id': 2})
        self.assertEqual([efficacy_indicator2['id']], [r.id for r in res])

        res = self.dbapi.get_efficacy_indicator_list(
            self.context,
            filters={'action_plan_uuid': action_plan['uuid']})
        self.assertEqual(
            [efficacy_indicator1['id'], efficacy_indicator3['id']].sort(),
            [r.id for r in res].sort())
Ejemplo n.º 29
0
    def test_get_action_plan_list_with_filters(self):
        audit = utils.create_test_audit(id=2,
                                        audit_type='ONESHOT',
                                        uuid=w_utils.generate_uuid(),
                                        state=ap_objects.State.ONGOING)

        action_plan1 = utils.create_test_action_plan(
            id=1,
            uuid=w_utils.generate_uuid(),
            audit_id=audit['id'],
            state=ap_objects.State.RECOMMENDED)
        action_plan2 = utils.create_test_action_plan(
            id=2,
            uuid=w_utils.generate_uuid(),
            audit_id=audit['id'],
            state=ap_objects.State.ONGOING)
        action_plan3 = utils.create_test_action_plan(
            id=3,
            uuid=w_utils.generate_uuid(),
            audit_id=audit['id'],
            state=ap_objects.State.RECOMMENDED)

        # check on bug 1761956
        self.dbapi.soft_delete_action_plan(action_plan3['uuid'])

        res = self.dbapi.get_action_plan_list(
            self.context, filters={'state': ap_objects.State.RECOMMENDED})
        self.assertEqual([action_plan1['id']], [r.id for r in res])

        res = self.dbapi.get_action_plan_list(
            self.context, filters={'state': ap_objects.State.ONGOING})
        self.assertEqual([action_plan2['id']], [r.id for r in res])

        res = self.dbapi.get_action_plan_list(
            self.context, filters={'audit_uuid': audit['uuid']})
        self.assertEqual(sorted([action_plan1['id'], action_plan2['id']]),
                         sorted([r.id for r in res]))
        for r in res:
            self.assertEqual(audit['id'], r.audit_id)

        self.dbapi.soft_delete_action_plan(action_plan1['uuid'])
        res = self.dbapi.get_action_plan_list(
            self.context, filters={'audit_uuid': audit['uuid']})

        self.assertEqual([action_plan2['id']], [r.id for r in res])
        self.assertNotEqual([action_plan1['id']], [r.id for r in res])
Ejemplo n.º 30
0
    def test_get_efficacy_indicator_list_with_filters(self):
        audit = utils.create_test_audit(uuid=w_utils.generate_uuid())
        action_plan = self._create_test_action_plan(
            id=1,
            uuid=w_utils.generate_uuid(),
            audit_id=audit.id,
            first_efficacy_indicator_id=None,
            state='RECOMMENDED')
        efficacy_indicator1 = self._create_test_efficacy_indicator(
            id=1,
            name='indicator_1',
            uuid=w_utils.generate_uuid(),
            action_plan_id=1,
            description='Description efficacy indicator 1',
            unit='%')
        efficacy_indicator2 = self._create_test_efficacy_indicator(
            id=2,
            name='indicator_2',
            uuid=w_utils.generate_uuid(),
            action_plan_id=2,
            description='Description efficacy indicator 2',
            unit='%')
        efficacy_indicator3 = self._create_test_efficacy_indicator(
            id=3,
            name='indicator_3',
            uuid=w_utils.generate_uuid(),
            action_plan_id=1,
            description='Description efficacy indicator 3',
            unit='%')
        res = self.dbapi.get_efficacy_indicator_list(
            self.context, filters={'name': 'indicator_3'})
        self.assertEqual([efficacy_indicator3['id']], [r.id for r in res])

        res = self.dbapi.get_efficacy_indicator_list(self.context,
                                                     filters={'unit': 'kWh'})
        self.assertEqual([], [r.id for r in res])

        res = self.dbapi.get_efficacy_indicator_list(
            self.context, filters={'action_plan_id': 2})
        self.assertEqual([efficacy_indicator2['id']], [r.id for r in res])

        res = self.dbapi.get_efficacy_indicator_list(
            self.context, filters={'action_plan_uuid': action_plan['uuid']})
        self.assertEqual(
            [efficacy_indicator1['id'],
             efficacy_indicator3['id']].sort(), [r.id for r in res].sort())
Ejemplo n.º 31
0
    def test_get_audit_list_eager(self):
        _goal = utils.get_test_goal()
        goal = self.dbapi.create_goal(_goal)
        _strategy = utils.get_test_strategy()
        strategy = self.dbapi.create_strategy(_strategy)

        uuids = []
        for i in range(1, 4):
            audit = utils.create_test_audit(id=i,
                                            uuid=w_utils.generate_uuid(),
                                            goal_id=goal.id,
                                            strategy_id=strategy.id)
            uuids.append(six.text_type(audit['uuid']))
        audits = self.dbapi.get_audit_list(self.context, eager=True)
        audit_map = {a.uuid: a for a in audits}
        self.assertEqual(sorted(uuids), sorted(audit_map.keys()))
        eager_audit = audit_map[audit.uuid]
        self.assertEqual(goal.as_dict(), eager_audit.goal.as_dict())
        self.assertEqual(strategy.as_dict(), eager_audit.strategy.as_dict())
Ejemplo n.º 32
0
    def test_check_expired(self):
        CONF.set_default('action_plan_expiry', 0,
                         group='watcher_decision_engine')
        strategy_1 = utils.create_test_strategy(
            uuid=common_utils.generate_uuid())
        audit_1 = utils.create_test_audit(
            uuid=common_utils.generate_uuid())
        action_plan_1 = utils.create_test_action_plan(
            state=objects.action_plan.State.RECOMMENDED,
            uuid=common_utils.generate_uuid(),
            audit_id=audit_1.id,
            strategy_id=strategy_1.id)

        self.state_manager.check_expired(self.context)

        action_plan = objects.action_plan.ActionPlan.get_by_uuid(
            self.context, action_plan_1.uuid)
        self.assertEqual(objects.action_plan.State.SUPERSEDED,
                         action_plan.state)
Ejemplo n.º 33
0
    def _data_setup(self):
        self.audit_template_name = "Audit Template"

        self.audit_template = utils.create_test_audit_template(
            name=self.audit_template_name, id=1, uuid=None)
        self.audit = utils.create_test_audit(
            audit_template_id=self.audit_template.id, id=1, uuid=None)
        self.action_plan = utils.create_test_action_plan(
            audit_id=self.audit.id, id=1, uuid=None)

        with freezegun.freeze_time(self.FAKE_TODAY):
            self.efficacy_indicator1 = utils.create_test_efficacy_indicator(
                action_plan_id=self.action_plan.id, id=1, uuid=None,
                name="efficacy_indicator1", description="Test Indicator 1")
        with freezegun.freeze_time(self.FAKE_OLD_DATE):
            self.efficacy_indicator2 = utils.create_test_efficacy_indicator(
                action_plan_id=self.action_plan.id, id=2, uuid=None,
                name="efficacy_indicator2", description="Test Indicator 2")
        with freezegun.freeze_time(self.FAKE_OLDER_DATE):
            self.efficacy_indicator3 = utils.create_test_efficacy_indicator(
                action_plan_id=self.action_plan.id, id=3, uuid=None,
                name="efficacy_indicator3", description="Test Indicator 3")
Ejemplo n.º 34
0
 def test_update_audit_uuid(self):
     audit = utils.create_test_audit()
     self.assertRaises(exception.Invalid, self.dbapi.update_audit,
                       audit['id'], {'uuid': 'hello'})
Ejemplo n.º 35
0
 def test_destroy_audit_that_referenced_by_action_plans(self):
     audit = utils.create_test_audit()
     action_plan = utils.create_test_action_plan(audit_id=audit['id'])
     self.assertEqual(audit['id'], action_plan.audit_id)
     self.assertRaises(exception.AuditReferenced, self.dbapi.destroy_audit,
                       audit['id'])
Ejemplo n.º 36
0
 def setUp(self):
     super(TestActionScheduling, self).setUp()
     self.strategy = db_utils.create_test_strategy(name="dummy")
     self.audit = db_utils.create_test_audit(uuid=utils.generate_uuid(),
                                             strategy_id=self.strategy.id)
     self.default_planner = pbase.DefaultPlanner(mock.Mock())
Ejemplo n.º 37
0
 def test_scheduler_warning_empty_action_plan(self):
     audit = db_utils.create_test_audit(uuid=utils.generate_uuid())
     fake_solution = SolutionFaker.build()
     action_plan = self.default_planner.schedule(self.context, audit.id, fake_solution)
     self.assertIsNotNone(action_plan.uuid)
Ejemplo n.º 38
0
 def test_scheduler_warning_empty_action_plan(self):
     audit = db_utils.create_test_audit(uuid=utils.generate_uuid())
     fake_solution = SolutionFaker.build()
     action_plan = self.default_planner.schedule(self.context, audit.id,
                                                 fake_solution)
     self.assertIsNotNone(action_plan.uuid)