Пример #1
0
    def _data_setup(self):
        strategy1_name = "STRATEGY_ID_1"
        strategy2_name = "STRATEGY_ID_2"
        strategy3_name = "STRATEGY_ID_3"

        self.goal1 = utils.create_test_goal(
            id=1, uuid=w_utils.generate_uuid(),
            name="GOAL_ID", display_name="Goal")
        self.goal2 = utils.create_test_goal(
            id=2, uuid=w_utils.generate_uuid(),
            name="DUMMY", display_name="Dummy")

        with freezegun.freeze_time(self.FAKE_TODAY):
            self.strategy1 = utils.create_test_strategy(
                id=1, uuid=w_utils.generate_uuid(),
                name=strategy1_name, display_name="Strategy 1",
                goal_id=self.goal1.id)
        with freezegun.freeze_time(self.FAKE_OLD_DATE):
            self.strategy2 = utils.create_test_strategy(
                id=2, uuid=w_utils.generate_uuid(),
                name=strategy2_name, display_name="Strategy 2",
                goal_id=self.goal1.id)
        with freezegun.freeze_time(self.FAKE_OLDER_DATE):
            self.strategy3 = utils.create_test_strategy(
                id=3, uuid=w_utils.generate_uuid(),
                name=strategy3_name, display_name="Strategy 3",
                goal_id=self.goal2.id)
Пример #2
0
    def _data_setup(self):
        strategy1_name = "STRATEGY_ID_1"
        strategy2_name = "STRATEGY_ID_2"
        strategy3_name = "STRATEGY_ID_3"

        self.goal1 = utils.create_test_goal(id=1,
                                            uuid=w_utils.generate_uuid(),
                                            name="GOAL_ID",
                                            display_name="Goal")
        self.goal2 = utils.create_test_goal(id=2,
                                            uuid=w_utils.generate_uuid(),
                                            name="DUMMY",
                                            display_name="Dummy")

        with freezegun.freeze_time(self.FAKE_TODAY):
            self.strategy1 = utils.create_test_strategy(
                id=1,
                uuid=w_utils.generate_uuid(),
                name=strategy1_name,
                display_name="Strategy 1",
                goal_id=self.goal1.id)
        with freezegun.freeze_time(self.FAKE_OLD_DATE):
            self.strategy2 = utils.create_test_strategy(
                id=2,
                uuid=w_utils.generate_uuid(),
                name=strategy2_name,
                display_name="Strategy 2",
                goal_id=self.goal1.id)
        with freezegun.freeze_time(self.FAKE_OLDER_DATE):
            self.strategy3 = utils.create_test_strategy(
                id=3,
                uuid=w_utils.generate_uuid(),
                name=strategy3_name,
                display_name="Strategy 3",
                goal_id=self.goal2.id)
 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,
                   }))
Пример #4
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())
Пример #5
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())
Пример #6
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())
Пример #7
0
    def test_get_strategy_list_with_filters(self):
        # NOTE(erakli): we don't create goal in database but links to
        # goal_id = 1. There is no error in dbapi.create_strategy() method.
        # Is it right behaviour?
        strategy1 = utils.create_test_strategy(
            id=1,
            uuid=w_utils.generate_uuid(),
            name="STRATEGY_ID_1",
            display_name='Strategy 1',
        )
        strategy2 = utils.create_test_strategy(
            id=2,
            uuid=w_utils.generate_uuid(),
            name="STRATEGY_ID_2",
            display_name='Strategy 2',
        )
        strategy3 = utils.create_test_strategy(
            id=3,
            uuid=w_utils.generate_uuid(),
            name="STRATEGY_ID_3",
            display_name='Strategy 3',
        )

        self.dbapi.soft_delete_strategy(strategy3['uuid'])

        res = self.dbapi.get_strategy_list(
            self.context, filters={'display_name': 'Strategy 1'})
        self.assertEqual([strategy1['uuid']], [r.uuid for r in res])

        res = self.dbapi.get_strategy_list(
            self.context, filters={'display_name': 'Strategy 3'})
        self.assertEqual([], [r.uuid for r in res])

        res = self.dbapi.get_strategy_list(self.context,
                                           filters={'goal_id': 1})
        self.assertEqual([strategy1['uuid'], strategy2['uuid']],
                         [r.uuid for r in res])

        res = self.dbapi.get_strategy_list(
            self.context, filters={'display_name': 'Strategy 2'})
        self.assertEqual([strategy2['uuid']], [r.uuid for r in res])
Пример #8
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")
Пример #9
0
 def test_get_strategy_list(self):
     ids = []
     for i in range(1, 6):
         strategy = utils.create_test_strategy(
             id=i,
             uuid=w_utils.generate_uuid(),
             name="STRATEGY_ID_%s" % i,
             display_name='My Strategy {0}'.format(i))
         ids.append(six.text_type(strategy['uuid']))
     res = self.dbapi.get_strategy_list(self.context)
     res_ids = [r.display_name for r in res]
     self.assertEqual(ids.sort(), res_ids.sort())
Пример #10
0
 def test_get_strategy_list(self):
     ids = []
     for i in range(1, 6):
         strategy = utils.create_test_strategy(
             id=i,
             uuid=w_utils.generate_uuid(),
             name="STRATEGY_ID_%s" % i,
             display_name='My Strategy {0}'.format(i))
         ids.append(six.text_type(strategy['uuid']))
     res = self.dbapi.get_strategy_list(self.context)
     res_ids = [r.display_name for r in res]
     self.assertEqual(ids.sort(), res_ids.sort())
Пример #11
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())
Пример #12
0
 def test_get_strategy_list(self):
     uuids = []
     for i in range(1, 4):
         strategy = utils.create_test_strategy(
             id=i,
             uuid=w_utils.generate_uuid(),
             name="STRATEGY_ID_%s" % i,
             display_name='My Strategy {0}'.format(i))
         uuids.append(six.text_type(strategy['uuid']))
     strategies = self.dbapi.get_strategy_list(self.context)
     strategy_uuids = [s.uuid for s in strategies]
     self.assertEqual(sorted(uuids), sorted(strategy_uuids))
     for strategy in strategies:
         self.assertIsNone(strategy.goal)
Пример #13
0
    def setUp(self):
        super(TestAuditObjectSendNotifications, self).setUp()
        goal_id = 1
        self.fake_goal = utils.create_test_goal(id=goal_id, name="DUMMY")
        self.fake_strategy = utils.create_test_strategy(
            id=goal_id, name="DUMMY")
        self.fake_audit = utils.get_test_audit(
            goal_id=goal_id, goal=utils.get_test_goal(id=goal_id),
            strategy_id=self.fake_strategy.id, strategy=self.fake_strategy)

        p_get_notifier = mock.patch.object(rpc, 'get_notifier')
        self.m_get_notifier = p_get_notifier.start()
        self.m_get_notifier.return_value = mock.Mock(name='m_notifier')
        self.m_notifier = self.m_get_notifier.return_value
        self.addCleanup(p_get_notifier.stop)
Пример #14
0
 def test_get_strategy_list_eager(self):
     _goal = utils.get_test_goal()
     goal = self.dbapi.create_goal(_goal)
     uuids = []
     for i in range(1, 4):
         strategy = utils.create_test_strategy(
             id=i,
             uuid=w_utils.generate_uuid(),
             name="STRATEGY_ID_%s" % i,
             display_name='My Strategy {0}'.format(i),
             goal_id=goal.id)
         uuids.append(six.text_type(strategy['uuid']))
     strategys = self.dbapi.get_strategy_list(self.context, eager=True)
     strategy_map = {a.uuid: a for a in strategys}
     self.assertEqual(sorted(uuids), sorted(strategy_map.keys()))
     eager_strategy = strategy_map[strategy.uuid]
     self.assertEqual(goal.as_dict(), eager_strategy.goal.as_dict())
Пример #15
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)
Пример #16
0
 def test_get_strategy_by_uuid(self):
     created_strategy = utils.create_test_strategy()
     strategy = self.dbapi.get_strategy_by_uuid(self.context,
                                                created_strategy['uuid'])
     self.assertEqual(strategy.uuid, created_strategy['uuid'])
Пример #17
0
 def test_update_strategy(self):
     strategy = utils.create_test_strategy()
     res = self.dbapi.update_strategy(strategy['uuid'],
                                      {'display_name': 'updated-model'})
     self.assertEqual('updated-model', res.display_name)
Пример #18
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())
Пример #19
0
 def test_update_goal_id(self):
     strategy = utils.create_test_strategy()
     self.assertRaises(exception.Invalid, self.dbapi.update_strategy,
                       strategy['uuid'], {'uuid': 'new_strategy_id'})
Пример #20
0
 def test_destroy_strategy(self):
     strategy = utils.create_test_strategy()
     self.dbapi.destroy_strategy(strategy['uuid'])
     self.assertRaises(exception.StrategyNotFound,
                       self.dbapi.get_strategy_by_id, self.context,
                       strategy['uuid'])
Пример #21
0
 def test_get_strategy_by_name(self):
     created_strategy = utils.create_test_strategy()
     strategy = self.dbapi.get_strategy_by_name(self.context,
                                                created_strategy['name'])
     self.assertEqual(strategy.name, created_strategy['name'])
Пример #22
0
 def test_create_strategy_already_exists(self):
     strategy_id = "STRATEGY_ID"
     utils.create_test_strategy(name=strategy_id)
     self.assertRaises(exception.StrategyAlreadyExists,
                       utils.create_test_strategy,
                       name=strategy_id)