Exemplo n.º 1
0
    def test_filter_by_goal(self):
        cfg.CONF.set_override('goals', {
            "DUMMY": "DUMMY",
            "BASIC": "BASIC"
        },
                              group='watcher_goals',
                              enforce_type=True)

        for id_ in range(2):
            obj_utils.create_test_audit_template(
                self.context,
                id=id_,
                uuid=utils.generate_uuid(),
                name='My Audit Template {0}'.format(id_),
                goal="DUMMY")

        for id_ in range(2, 5):
            obj_utils.create_test_audit_template(
                self.context,
                id=id_,
                uuid=utils.generate_uuid(),
                name='My Audit Template {0}'.format(id_),
                goal="BASIC")

        response = self.get_json('/audit_templates?goal=BASIC')
        self.assertEqual(3, len(response['audit_templates']))
Exemplo n.º 2
0
 def setUp(self):
     super(TestPost, self).setUp()
     obj_utils.create_test_audit_template(self.context)
     p = mock.patch.object(db_api.BaseConnection, 'create_audit')
     self.mock_create_audit = p.start()
     self.mock_create_audit.side_effect = (self._simulate_rpc_audit_create)
     self.addCleanup(p.stop)
Exemplo n.º 3
0
 def prepare_audit_template_strategy_with_parameter(self):
     fake_spec = {
         "properties": {
             "fake1": {
                 "description": "number parameter example",
                 "type": "number",
                 "default": 3.2,
                 "minimum": 1.0,
                 "maximum": 10.2,
             }
         }
     }
     template_uuid = 'e74c40e0-d825-11e2-a28f-0800200c9a67'
     strategy_uuid = 'e74c40e0-d825-11e2-a28f-0800200c9a68'
     template_name = 'my template'
     strategy_name = 'my strategy'
     strategy_id = 3
     strategy = db_utils.get_test_strategy(parameters_spec=fake_spec,
                                           id=strategy_id,
                                           uuid=strategy_uuid,
                                           name=strategy_name)
     obj_utils.create_test_strategy(self.context,
                                    parameters_spec=fake_spec,
                                    id=strategy_id,
                                    uuid=strategy_uuid,
                                    name=strategy_name)
     obj_utils.create_test_audit_template(self.context,
                                          strategy_id=strategy_id,
                                          uuid=template_uuid,
                                          name='name')
     audit_template = db_utils.get_test_audit_template(
         strategy_id=strategy['id'], uuid=template_uuid, name=template_name)
     return audit_template
Exemplo n.º 4
0
    def setUp(self):
        super(TestDefaultPlanner, self).setUp()
        self.planner = pbase.WorkloadStabilizationPlanner(mock.Mock())
        self.planner.config.weights = {
            'nop': 0,
            'sleep': 1,
            'change_nova_service_state': 2,
            'migrate': 3
        }

        self.goal = obj_utils.create_test_goal(self.context)
        self.strategy = obj_utils.create_test_strategy(self.context,
                                                       goal_id=self.goal.id)
        obj_utils.create_test_audit_template(self.context,
                                             goal_id=self.goal.id,
                                             strategy_id=self.strategy.id)

        p = mock.patch.object(db_api.BaseConnection, 'create_action_plan')
        self.mock_create_action_plan = p.start()
        self.mock_create_action_plan.side_effect = (
            self._simulate_action_plan_create)
        self.addCleanup(p.stop)

        q = mock.patch.object(db_api.BaseConnection, 'create_action')
        self.mock_create_action = q.start()
        self.mock_create_action.side_effect = (self._simulate_action_create)
        self.addCleanup(q.stop)
Exemplo n.º 5
0
    def _data_setup(self):
        # All the 1's are soft_deleted and are expired
        # All the 2's are soft_deleted but are not expired
        # All the 3's are *not* soft_deleted

        # Number of days we want to keep in DB (no purge for them)
        self.cmd.age_in_days = 10
        self.cmd.max_number = None
        self.cmd.orphans = True
        gen_name = lambda: "Audit Template %s" % uuid.uuid4()
        self.audit_template1_name = gen_name()
        self.audit_template2_name = gen_name()
        self.audit_template3_name = gen_name()

        with freezegun.freeze_time(self.expired_date):
            self.audit_template1 = obj_utils.create_test_audit_template(
                self.context, name=self.audit_template1_name,
                id=self._generate_id(), uuid=None)
            self.audit_template2 = obj_utils.create_test_audit_template(
                self.context, name=self.audit_template2_name,
                id=self._generate_id(), uuid=None)
            self.audit_template3 = obj_utils.create_test_audit_template(
                self.context, name=self.audit_template3_name,
                id=self._generate_id(), uuid=None)
            self.audit_template1.soft_delete()

        with freezegun.freeze_time(self.expired_date):
            self.audit1 = obj_utils.create_test_audit(
                self.context, audit_template_id=self.audit_template1.id,
                id=self._generate_id(), uuid=None)
            self.audit2 = obj_utils.create_test_audit(
                self.context, audit_template_id=self.audit_template2.id,
                id=self._generate_id(), uuid=None)
            self.audit3 = obj_utils.create_test_audit(
                self.context, audit_template_id=self.audit_template3.id,
                id=self._generate_id(), uuid=None)
            self.audit1.soft_delete()

        with freezegun.freeze_time(self.expired_date):
            self.action_plan1 = obj_utils.create_test_action_plan(
                self.context, audit_id=self.audit1.id,
                id=self._generate_id(), uuid=None)
            self.action_plan2 = obj_utils.create_test_action_plan(
                self.context, audit_id=self.audit2.id,
                id=self._generate_id(), uuid=None)
            self.action_plan3 = obj_utils.create_test_action_plan(
                self.context, audit_id=self.audit3.id,
                id=self._generate_id(), uuid=None)

            self.action1 = obj_utils.create_test_action(
                self.context, action_plan_id=self.action_plan1.id,
                id=self._generate_id(), uuid=None)
            self.action2 = obj_utils.create_test_action(
                self.context, action_plan_id=self.action_plan2.id,
                id=self._generate_id(), uuid=None)
            self.action3 = obj_utils.create_test_action(
                self.context, action_plan_id=self.action_plan3.id,
                id=self._generate_id(), uuid=None)
            self.action_plan1.soft_delete()
Exemplo n.º 6
0
 def setUp(self):
     super(TestDelete, self).setUp()
     obj_utils.create_test_audit_template(self.context)
     self.audit = obj_utils.create_test_audit(self.context)
     p = mock.patch.object(db_api.BaseConnection, 'update_audit')
     self.mock_audit_update = p.start()
     self.mock_audit_update.side_effect = self._simulate_rpc_audit_update
     self.addCleanup(p.stop)
Exemplo n.º 7
0
 def setUp(self):
     super(TestPost, self).setUp()
     obj_utils.create_test_audit_template(self.context)
     p = mock.patch.object(db_api.BaseConnection, 'create_audit')
     self.mock_create_audit = p.start()
     self.mock_create_audit.side_effect = (
         self._simulate_rpc_audit_create)
     self.addCleanup(p.stop)
Exemplo n.º 8
0
 def setUp(self):
     super(TestDelete, self).setUp()
     obj_utils.create_test_audit_template(self.context)
     self.audit = obj_utils.create_test_audit(self.context)
     p = mock.patch.object(db_api.BaseConnection, 'update_audit')
     self.mock_audit_update = p.start()
     self.mock_audit_update.side_effect = self._simulate_rpc_audit_update
     self.addCleanup(p.stop)
Exemplo n.º 9
0
    def test_find_deleted_and_nonexpired_related_entries(self):
        with freezegun.freeze_time(self.fake_today):
            # orphan audit template
            audit_template4 = obj_utils.create_test_audit_template(
                self.context, goal_id=404,  # Does not exist
                name=self.generate_unique_name(prefix="Audit Template 4 "),
                strategy_id=None, id=self._generate_id(), uuid=None)
            audit4 = obj_utils.create_test_audit(
                self.context, audit_template_id=audit_template4.id,
                id=self._generate_id(), uuid=None)
            action_plan4 = obj_utils.create_test_action_plan(
                self.context, audit_id=audit4.id,
                id=self._generate_id(), uuid=None)
            action4 = obj_utils.create_test_action(
                self.context, action_plan_id=action_plan4.id,
                id=self._generate_id(), uuid=None)

            audit_template5 = obj_utils.create_test_audit_template(
                self.context, goal_id=self.goal1.id,
                name=self.generate_unique_name(prefix="Audit Template 5 "),
                strategy_id=None, id=self._generate_id(), uuid=None)
            audit5 = obj_utils.create_test_audit(
                self.context, audit_template_id=audit_template5.id,
                id=self._generate_id(), uuid=None)
            action_plan5 = obj_utils.create_test_action_plan(
                self.context, audit_id=audit5.id,
                id=self._generate_id(), uuid=None)
            action5 = obj_utils.create_test_action(
                self.context, action_plan_id=action_plan5.id,
                id=self._generate_id(), uuid=None)

            self.goal2.soft_delete()
            self.strategy2.soft_delete()
            self.audit_template2.soft_delete()
            self.audit2.soft_delete()
            self.action_plan2.soft_delete()

            # All the 4's should be purged as well because they are orphans
            # even though they were not deleted

            # All the 5's should be purged as well even though they are not
            # expired because their related audit template is itself expired
            audit_template5.soft_delete()
            audit5.soft_delete()
            action_plan5.soft_delete()

        with freezegun.freeze_time(self.fake_today):
            objects_map = self.cmd.find_objects_to_delete()

        self.assertEqual(len(objects_map.goals), 1)
        self.assertEqual(len(objects_map.strategies), 1)
        self.assertEqual(len(objects_map.audit_templates), 3)
        self.assertEqual(len(objects_map.audits), 3)
        self.assertEqual(len(objects_map.action_plans), 3)
        self.assertEqual(len(objects_map.actions), 3)
        self.assertEqual(
            set([self.action1.id, action4.id, action5.id]),
            set([entry.id for entry in objects_map.actions]))
Exemplo n.º 10
0
    def test_collection_links(self):
        for id_ in range(5):
            obj_utils.create_test_audit_template(
                self.context, id=id_, uuid=utils.generate_uuid(),
                name='My Audit Template {0}'.format(id_))
        response = self.get_json('/audit_templates/?limit=3')
        self.assertEqual(3, len(response['audit_templates']))

        next_marker = response['audit_templates'][-1]['uuid']
        self.assertIn(next_marker, response['next'])
Exemplo n.º 11
0
    def test_collection_links(self):
        for id_ in range(5):
            obj_utils.create_test_audit_template(
                self.context, id=id_, uuid=utils.generate_uuid(),
                name='My Audit Template {0}'.format(id_))
        response = self.get_json('/audit_templates/?limit=3')
        self.assertEqual(3, len(response['audit_templates']))

        next_marker = response['audit_templates'][-1]['uuid']
        self.assertIn(next_marker, response['next'])
Exemplo n.º 12
0
 def test_links(self):
     uuid = utils.generate_uuid()
     obj_utils.create_test_audit_template(self.context, id=1, uuid=uuid)
     response = self.get_json('/audit_templates/%s' % uuid)
     self.assertIn('links', response.keys())
     self.assertEqual(2, len(response['links']))
     self.assertIn(uuid, response['links'][0]['href'])
     for l in response['links']:
         bookmark = l['rel'] == 'bookmark'
         self.assertTrue(self.validate_link(l['href'], bookmark=bookmark))
Exemplo n.º 13
0
 def test_links(self):
     uuid = utils.generate_uuid()
     obj_utils.create_test_audit_template(self.context, id=1, uuid=uuid)
     response = self.get_json('/audit_templates/%s' % uuid)
     self.assertIn('links', response.keys())
     self.assertEqual(2, len(response['links']))
     self.assertIn(uuid, response['links'][0]['href'])
     for l in response['links']:
         bookmark = l['rel'] == 'bookmark'
         self.assertTrue(self.validate_link(l['href'], bookmark=bookmark))
Exemplo n.º 14
0
    def test_collection_links_default_limit(self):
        cfg.CONF.set_override('max_limit', 3, 'api')
        for id_ in range(5):
            obj_utils.create_test_audit_template(
                self.context, id=id_, uuid=utils.generate_uuid(),
                name='My Audit Template {0}'.format(id_))
        response = self.get_json('/audit_templates')
        self.assertEqual(3, len(response['audit_templates']))

        next_marker = response['audit_templates'][-1]['uuid']
        self.assertIn(next_marker, response['next'])
Exemplo n.º 15
0
 def setUp(self):
     super(TestPatchStateTransitionOk, self).setUp()
     obj_utils.create_test_goal(self.context)
     obj_utils.create_test_strategy(self.context)
     obj_utils.create_test_audit_template(self.context)
     self.audit = obj_utils.create_test_audit(self.context,
                                              state=self.original_state)
     p = mock.patch.object(db_api.BaseConnection, 'update_audit')
     self.mock_audit_update = p.start()
     self.mock_audit_update.side_effect = self._simulate_rpc_audit_update
     self.addCleanup(p.stop)
Exemplo n.º 16
0
    def test_filter_by_strategy_name(self):
        for id_, strategy_id in enumerate(itertools.chain.from_iterable([
                itertools.repeat(self.fake_strategy1.id, 3),
                itertools.repeat(self.fake_strategy2.id, 2)]), 1):
            obj_utils.create_test_audit_template(
                self.context, id=id_, uuid=utils.generate_uuid(),
                name='My Audit Template {0}'.format(id_),
                strategy_id=strategy_id)

        response = self.get_json(
            '/audit_templates?strategy=%s' % self.fake_strategy2.name)
        self.assertEqual(2, len(response['audit_templates']))
Exemplo n.º 17
0
    def test_filter_by_strategy_name(self):
        for id_, strategy_id in enumerate(itertools.chain.from_iterable([
                itertools.repeat(self.fake_strategy1.id, 3),
                itertools.repeat(self.fake_strategy2.id, 2)]), 1):
            obj_utils.create_test_audit_template(
                self.context, id=id_, uuid=utils.generate_uuid(),
                name='My Audit Template {0}'.format(id_),
                strategy_id=strategy_id)

        response = self.get_json(
            '/audit_templates?strategy=%s' % self.fake_strategy2.name)
        self.assertEqual(2, len(response['audit_templates']))
Exemplo n.º 18
0
    def test_collection_links_default_limit(self):
        cfg.CONF.set_override('max_limit', 3, 'api',
                              enforce_type=True)
        for id_ in range(5):
            obj_utils.create_test_audit_template(
                self.context, id=id_, uuid=utils.generate_uuid(),
                name='My Audit Template {0}'.format(id_))
        response = self.get_json('/audit_templates')
        self.assertEqual(3, len(response['audit_templates']))

        next_marker = response['audit_templates'][-1]['uuid']
        self.assertIn(next_marker, response['next'])
Exemplo n.º 19
0
    def setUp(self):
        super(TestDefaultPlanner, self).setUp()
        self.default_planner = pbase.DefaultPlanner()
        obj_utils.create_test_audit_template(self.context)

        p = mock.patch.object(db_api.BaseConnection, "create_action_plan")
        self.mock_create_action_plan = p.start()
        self.mock_create_action_plan.side_effect = self._simulate_action_plan_create
        self.addCleanup(p.stop)

        q = mock.patch.object(db_api.BaseConnection, "create_action")
        self.mock_create_action = q.start()
        self.mock_create_action.side_effect = self._simulate_action_create
        self.addCleanup(q.stop)
Exemplo n.º 20
0
    def setUp(self):
        super(TestDefaultPlanner, self).setUp()
        self.default_planner = pbase.DefaultPlanner()
        obj_utils.create_test_audit_template(self.context)

        p = mock.patch.object(db_api.BaseConnection, 'create_action_plan')
        self.mock_create_action_plan = p.start()
        self.mock_create_action_plan.side_effect = (
            self._simulate_action_plan_create)
        self.addCleanup(p.stop)

        q = mock.patch.object(db_api.BaseConnection, 'create_action')
        self.mock_create_action = q.start()
        self.mock_create_action.side_effect = (self._simulate_action_create)
        self.addCleanup(q.stop)
Exemplo n.º 21
0
 def test_one(self):
     audit_template = obj_utils.create_test_audit_template(
         self.context, strategy_id=self.fake_strategy1.id)
     response = self.get_json('/audit_templates')
     self.assertEqual(audit_template.uuid,
                      response['audit_templates'][0]["uuid"])
     self._assert_audit_template_fields(response['audit_templates'][0])
Exemplo n.º 22
0
 def setUp(self):
     super(TestAuditEndpoint, self).setUp()
     self.audit_template = obj_utils.create_test_audit_template(
         self.context)
     self.audit = obj_utils.create_test_audit(
         self.context,
         audit_template_id=self.audit_template.id)
Exemplo n.º 23
0
 def test_many_without_soft_deleted(self):
     audit_template_list = []
     for id_ in [1, 2, 3]:
         audit_template = obj_utils.create_test_audit_template(
             self.context, id=id_, uuid=utils.generate_uuid(),
             name='My Audit Template {0}'.format(id_))
         audit_template_list.append(audit_template.uuid)
     for id_ in [4, 5]:
         audit_template = obj_utils.create_test_audit_template(
             self.context, id=id_, uuid=utils.generate_uuid(),
             name='My Audit Template {0}'.format(id_))
         audit_template.soft_delete()
     response = self.get_json('/audit_templates')
     self.assertEqual(3, len(response['audit_templates']))
     uuids = [s['uuid'] for s in response['audit_templates']]
     self.assertEqual(sorted(audit_template_list), sorted(uuids))
Exemplo n.º 24
0
    def test_filter_by_audit_template_name(self):
        audit_template_uuid = utils.generate_uuid()
        audit_template_name = 'My_Audit_Template'

        audit_template = obj_utils.create_test_audit_template(
            self.context, uuid=audit_template_uuid, name=audit_template_name)

        number_of_audits_with_audit_template_id = 5
        for id_ in range(number_of_audits_with_audit_template_id):
            obj_utils.create_test_audit(self.context,
                                        id=id_,
                                        uuid=utils.generate_uuid(),
                                        audit_template_id=audit_template.id)
        for id_ in range(6, 8):
            obj_utils.create_test_audit(self.context,
                                        id=id_,
                                        uuid=utils.generate_uuid())

        response = self.get_json('/audits/?audit_template=%s' %
                                 audit_template_name)

        audits = response['audits']
        self.assertEqual(5, len(audits))
        for audit in audits:
            self.assertEqual(audit_template_uuid, audit['audit_template_uuid'])
Exemplo n.º 25
0
 def test_one(self):
     audit_template = obj_utils.create_test_audit_template(
         self.context, strategy_id=self.fake_strategy1.id)
     response = self.get_json('/audit_templates')
     self.assertEqual(audit_template.uuid,
                      response['audit_templates'][0]["uuid"])
     self._assert_audit_template_fields(response['audit_templates'][0])
Exemplo n.º 26
0
 def test_policy_disallow_delete(self):
     obj_utils.create_test_goal(self.context)
     audit_template = obj_utils.create_test_audit_template(self.context)
     self._common_policy_check("audit_template:delete",
                               self.delete,
                               '/audit_templates/%s' % audit_template.uuid,
                               expect_errors=True)
Exemplo n.º 27
0
    def setUp(self):
        super(TestCancelOngoingActionPlans, self).setUp()
        p_audit_notifications = mock.patch.object(
            notifications, 'audit', autospec=True)
        self.m_audit_notifications = p_audit_notifications.start()
        self.addCleanup(p_audit_notifications.stop)

        self.goal = obj_utils.create_test_goal(
            self.context, id=1, name=dummy_strategy.DummyStrategy.get_name())
        self.strategy = obj_utils.create_test_strategy(
            self.context, name=dummy_strategy.DummyStrategy.get_name(),
            goal_id=self.goal.id)
        audit_template = obj_utils.create_test_audit_template(
            self.context, strategy_id=self.strategy.id)
        self.audit = obj_utils.create_test_audit(
            self.context,
            id=999,
            name='My Audit 999',
            uuid=uuidutils.generate_uuid(),
            audit_template_id=audit_template.id,
            goal_id=self.goal.id,
            audit_type=objects.audit.AuditType.ONESHOT.value,
            goal=self.goal,
            hostname='hostname1',
            state=objects.audit.State.ONGOING)
        self.actionplan = obj_utils.create_test_action_plan(
            self.context,
            state=objects.action_plan.State.ONGOING,
            audit_id=999,
            hostname='hostname1')
        self.action = obj_utils.create_test_action(
            self.context,
            action_plan_id=1,
            state=objects.action.State.PENDING)
        cfg.CONF.set_override("host", "hostname1")
Exemplo n.º 28
0
 def setUp(self):
     super(TestAutoTriggerActionPlan, self).setUp()
     self.goal = obj_utils.create_test_goal(
         self.context, id=1, name=dummy_strategy.DummyStrategy.get_name())
     self.strategy = obj_utils.create_test_strategy(
         self.context,
         name=dummy_strategy.DummyStrategy.get_name(),
         goal_id=self.goal.id)
     audit_template = obj_utils.create_test_audit_template(self.context)
     self.audit = obj_utils.create_test_audit(
         self.context,
         id=0,
         uuid=uuidutils.generate_uuid(),
         audit_template_id=audit_template.id,
         goal_id=self.goal.id,
         audit_type=objects.audit.AuditType.CONTINUOUS.value,
         goal=self.goal,
         auto_trigger=True)
     self.ongoing_action_plan = obj_utils.create_test_action_plan(
         self.context,
         uuid=uuidutils.generate_uuid(),
         audit_id=self.audit.id,
         strategy_id=self.strategy.id,
         audit=self.audit,
         strategy=self.strategy,
     )
     self.recommended_action_plan = obj_utils.create_test_action_plan(
         self.context,
         uuid=uuidutils.generate_uuid(),
         state=objects.action_plan.State.ONGOING,
         audit_id=self.audit.id,
         strategy_id=self.strategy.id,
         audit=self.audit,
         strategy=self.strategy,
     )
Exemplo n.º 29
0
 def setUp(self):
     super(TestAuditEndpoint, self).setUp()
     self.goal = obj_utils.create_test_goal(self.context)
     self.audit_template = obj_utils.create_test_audit_template(
         self.context)
     self.audit = obj_utils.create_test_audit(
         self.context, audit_template_id=self.audit_template.id)
Exemplo n.º 30
0
    def test_execute_force_dummy(self):
        obj_utils.create_test_goal(self.context, id=50,
                                   uuid=utils.generate_uuid(),
                                   name="my_goal")

        strategy = obj_utils.create_test_strategy(self.context,
                                                  id=42,
                                                  uuid=utils.generate_uuid(),
                                                  name="dummy")

        audit_template = obj_utils.create_test_audit_template(
            self.context,
            uuid=utils.generate_uuid(),
            strategy_id=strategy.id,
            name="my_template")

        audit = obj_utils.create_test_audit(
            self.context,
            audit_template_id=audit_template.id,
            uuid=utils.generate_uuid(),
        )

        solution = self.strategy_context.execute_strategy(
            audit.uuid, self.context)

        self.assertEqual(len(solution.actions), 3)
Exemplo n.º 31
0
    def test_execute_force_basic(self, mock_call):
        expected_strategy = "basic"
        mock_call.return_value = expected_strategy

        obj_utils.create_test_goal(self.context, id=50,
                                   uuid=utils.generate_uuid(),
                                   name="my_goal")

        strategy = obj_utils.create_test_strategy(self.context,
                                                  id=42,
                                                  uuid=utils.generate_uuid(),
                                                  name=expected_strategy)

        audit_template = obj_utils.create_test_audit_template(
            self.context,
            uuid=utils.generate_uuid(),
            strategy_id=strategy.id,
            name="my_template")

        audit = obj_utils.create_test_audit(
            self.context,
            audit_template_id=audit_template.id,
            uuid=utils.generate_uuid(),
        )

        solution = self.strategy_context.execute_strategy(
            audit.uuid, self.context)

        self.assertEqual(solution, expected_strategy)
Exemplo n.º 32
0
 def test_policy_disallow_update(self):
     audit_template = obj_utils.create_test_audit_template(self.context)
     self._common_policy_check(
         "audit_template:update", self.patch_json,
         '/audit_templates/%s' % audit_template.uuid,
         [{'path': '/state', 'value': 'SUBMITTED', 'op': 'replace'}],
         expect_errors=True)
Exemplo n.º 33
0
 def setUp(self):
     super(TestStrategyContext, self).setUp()
     obj_utils.create_test_goal(self.context, id=1, name="DUMMY")
     audit_template = obj_utils.create_test_audit_template(
         self.context, uuid=utils.generate_uuid())
     self.audit = obj_utils.create_test_audit(
         self.context, audit_template_id=audit_template.id)
 def setUp(self):
     super(TestDefaultAuditHandler, self).setUp()
     self.audit_template = obj_utils.create_test_audit_template(
         self.context)
     self.audit = obj_utils.create_test_audit(
         self.context,
         audit_template_id=self.audit_template.id)
Exemplo n.º 35
0
    def test_filter_by_audit_template_name(self):
        audit_template_uuid = utils.generate_uuid()
        audit_template_name = 'My_Audit_Template'

        audit_template = obj_utils.create_test_audit_template(
            self.context,
            uuid=audit_template_uuid,
            name=audit_template_name)

        number_of_audits_with_audit_template_id = 5
        for id_ in range(number_of_audits_with_audit_template_id):
            obj_utils.create_test_audit(self.context, id=id_,
                                        uuid=utils.generate_uuid(),
                                        audit_template_id=audit_template.id)
        for id_ in range(6, 8):
            obj_utils.create_test_audit(self.context, id=id_,
                                        uuid=utils.generate_uuid())

        response = self.get_json('/audits/?audit_template=%s'
                                 % audit_template_name)

        audits = response['audits']
        self.assertEqual(5, len(audits))
        for audit in audits:
            self.assertEqual(audit_template_uuid,
                             audit['audit_template_uuid'])
Exemplo n.º 36
0
 def setUp(self):
     super(TestStrategyContext, self).setUp()
     obj_utils.create_test_goal(self.context, id=1, name="DUMMY")
     audit_template = obj_utils.create_test_audit_template(
         self.context, uuid=utils.generate_uuid())
     self.audit = obj_utils.create_test_audit(
         self.context, audit_template_id=audit_template.id)
Exemplo n.º 37
0
 def test_policy_disallow_update(self):
     obj_utils.create_test_goal(self.context)
     audit_template = obj_utils.create_test_audit_template(self.context)
     self._common_policy_check(
         "audit_template:update", self.patch_json,
         '/audit_templates/%s' % audit_template.uuid,
         [{'path': '/state', 'value': objects.audit.State.SUCCEEDED,
           'op': 'replace'}], expect_errors=True)
Exemplo n.º 38
0
    def test_many_by_soft_deleted_audit_template(self):
        audit_list = []
        audit_template1 = obj_utils.create_test_audit_template(
            self.context,
            uuid=utils.generate_uuid(),
            name='at1',
            id=3,
        )

        audit_template2 = obj_utils.create_test_audit_template(
            self.context,
            uuid=utils.generate_uuid(),
            name='at2',
            id=4,
        )

        for id_ in range(0, 2):
            audit = obj_utils.create_test_audit(
                self.context,
                id=id_,
                uuid=utils.generate_uuid(),
                audit_template_id=audit_template1.id)
            audit_list.append(audit.uuid)

        for id_ in range(2, 4):
            audit = obj_utils.create_test_audit(
                self.context,
                id=id_,
                uuid=utils.generate_uuid(),
                audit_template_id=audit_template2.id)
            audit_list.append(audit.uuid)

        self.delete('/audit_templates/%s' % audit_template1.uuid)

        response = self.get_json('/audits')

        self.assertEqual(len(audit_list), len(response['audits']))

        for id_ in range(0, 2):
            audit = response['audits'][id_]
            self.assertEqual(None, audit['audit_template_uuid'])

        for id_ in range(2, 4):
            audit = response['audits'][id_]
            self.assertEqual(audit_template2.uuid,
                             audit['audit_template_uuid'])
 def setUp(self):
     super(TestDefaultAuditHandler, self).setUp()
     obj_utils.create_test_goal(self.context, id=1, name="dummy")
     audit_template = obj_utils.create_test_audit_template(
         self.context)
     self.audit = obj_utils.create_test_audit(
         self.context,
         audit_template_id=audit_template.id)
Exemplo n.º 40
0
    def test_filter_by_goal(self):
        cfg.CONF.set_override('goals', {"DUMMY": "DUMMY", "BASIC": "BASIC"},
                              group='watcher_goals', enforce_type=True)

        for id_ in range(2):
            obj_utils.create_test_audit_template(
                self.context, id=id_, uuid=utils.generate_uuid(),
                name='My Audit Template {0}'.format(id_),
                goal="DUMMY")

        for id_ in range(2, 5):
            obj_utils.create_test_audit_template(
                self.context, id=id_, uuid=utils.generate_uuid(),
                name='My Audit Template {0}'.format(id_),
                goal="BASIC")

        response = self.get_json('/audit_templates?goal=BASIC')
        self.assertEqual(3, len(response['audit_templates']))
Exemplo n.º 41
0
    def test_many_by_soft_deleted_audit_template(self):
        audit_list = []
        audit_template1 = obj_utils.create_test_audit_template(
            self.context,
            uuid=utils.generate_uuid(),
            name='at1',
            id=3,
        )

        audit_template2 = obj_utils.create_test_audit_template(
            self.context,
            uuid=utils.generate_uuid(),
            name='at2',
            id=4,
        )

        for id_ in range(0, 2):
            audit = obj_utils.create_test_audit(
                self.context, id=id_,
                uuid=utils.generate_uuid(),
                audit_template_id=audit_template1.id)
            audit_list.append(audit.uuid)

        for id_ in range(2, 4):
            audit = obj_utils.create_test_audit(
                self.context, id=id_,
                uuid=utils.generate_uuid(),
                audit_template_id=audit_template2.id)
            audit_list.append(audit.uuid)

        self.delete('/audit_templates/%s' % audit_template1.uuid)

        response = self.get_json('/audits')

        self.assertEqual(len(audit_list), len(response['audits']))

        for id_ in range(0, 2):
            audit = response['audits'][id_]
            self.assertIsNone(audit['audit_template_uuid'])

        for id_ in range(2, 4):
            audit = response['audits'][id_]
            self.assertEqual(audit_template2.uuid,
                             audit['audit_template_uuid'])
Exemplo n.º 42
0
 def setUp(self):
     super(TestPatch, self).setUp()
     self.audit_template = obj_utils.create_test_audit_template(
         self.context)
     p = mock.patch.object(db_api.BaseConnection, 'update_audit_template')
     self.mock_audit_template_update = p.start()
     self.mock_audit_template_update.side_effect = \
         self._simulate_rpc_audit_template_update
     cfg.CONF.set_override('goals', {"DUMMY": "DUMMY", "BASIC": "BASIC"},
                           group='watcher_goals', enforce_type=True)
     self.addCleanup(p.stop)
Exemplo n.º 43
0
 def test_many_without_soft_deleted(self):
     audit_template_list = []
     for id_ in [1, 2, 3]:
         audit_template = obj_utils.create_test_audit_template(
             self.context,
             id=id_,
             uuid=utils.generate_uuid(),
             name='My Audit Template {0}'.format(id_))
         audit_template_list.append(audit_template.uuid)
     for id_ in [4, 5]:
         audit_template = obj_utils.create_test_audit_template(
             self.context,
             id=id_,
             uuid=utils.generate_uuid(),
             name='My Audit Template {0}'.format(id_))
         audit_template.soft_delete()
     response = self.get_json('/audit_templates')
     self.assertEqual(3, len(response['audit_templates']))
     uuids = [s['uuid'] for s in response['audit_templates']]
     self.assertEqual(sorted(audit_template_list), sorted(uuids))
Exemplo n.º 44
0
 def setUp(self):
     super(TestContinuousAuditHandler, self).setUp()
     obj_utils.create_test_goal(self.context, id=1, name="DUMMY")
     audit_template = obj_utils.create_test_audit_template(
         self.context)
     self.audits = [obj_utils.create_test_audit(
         self.context,
         uuid=uuid.uuid4(),
         audit_template_id=audit_template.id,
         audit_type=audit_objects.AuditType.CONTINUOUS.value)
         for i in range(2)]
Exemplo n.º 45
0
 def setUp(self):
     super(TestOneShotAuditHandler, self).setUp()
     obj_utils.create_test_goal(self.context, id=1, name="dummy")
     self.strategy = obj_utils.create_test_strategy(self.context,
                                                    name='dummy')
     audit_template = obj_utils.create_test_audit_template(
         self.context, strategy_id=self.strategy.id)
     self.audit = obj_utils.create_test_audit(
         self.context,
         strategy_id=self.strategy.id,
         audit_template_id=audit_template.id)
Exemplo n.º 46
0
    def test_one_soft_deleted(self):
        audit_template = obj_utils.create_test_audit_template(self.context)
        audit_template.soft_delete()
        response = self.get_json('/audit_templates',
                                 headers={'X-Show-Deleted': 'True'})
        self.assertEqual(audit_template.uuid,
                         response['audit_templates'][0]["uuid"])
        self._assert_audit_template_fields(response['audit_templates'][0])

        response = self.get_json('/audit_templates')
        self.assertEqual([], response['audit_templates'])
Exemplo n.º 47
0
    def test_get_one_soft_deleted_ok(self):
        audit_template = obj_utils.create_test_audit_template(self.context)
        audit_template.soft_delete()
        response = self.get_json('/audit_templates',
                                 headers={'X-Show-Deleted': 'True'})
        self.assertEqual(audit_template.uuid,
                         response['audit_templates'][0]["uuid"])
        self._assert_audit_template_fields(response['audit_templates'][0])

        response = self.get_json('/audit_templates')
        self.assertEqual([], response['audit_templates'])
Exemplo n.º 48
0
    def setUp(self):
        super(TestDefaultPlanner, self).setUp()
        self.planner = pbase.NodeResourceConsolidationPlanner(mock.Mock())

        self.goal = obj_utils.create_test_goal(self.context)
        self.strategy = obj_utils.create_test_strategy(self.context,
                                                       goal_id=self.goal.id)
        obj_utils.create_test_audit_template(self.context,
                                             goal_id=self.goal.id,
                                             strategy_id=self.strategy.id)

        p = mock.patch.object(db_api.BaseConnection, 'create_action_plan')
        self.mock_create_action_plan = p.start()
        self.mock_create_action_plan.side_effect = (
            self._simulate_action_plan_create)
        self.addCleanup(p.stop)

        q = mock.patch.object(db_api.BaseConnection, 'create_action')
        self.mock_create_action = q.start()
        self.mock_create_action.side_effect = (self._simulate_action_create)
        self.addCleanup(q.stop)
Exemplo n.º 49
0
 def setUp(self):
     super(TestContinuousAuditHandler, self).setUp()
     obj_utils.create_test_goal(self.context, id=1, name="dummy")
     audit_template = obj_utils.create_test_audit_template(self.context)
     self.audits = [
         obj_utils.create_test_audit(
             self.context,
             uuid=uuid.uuid4(),
             audit_template_id=audit_template.id,
             audit_type=audit_objects.AuditType.CONTINUOUS.value)
         for i in range(2)
     ]
Exemplo n.º 50
0
 def test_many(self):
     audit_template_list = []
     for id_ in range(5):
         audit_template = obj_utils.create_test_audit_template(
             self.context, id=id_,
             uuid=utils.generate_uuid(),
             name='My Audit Template {0}'.format(id_))
         audit_template_list.append(audit_template.uuid)
     response = self.get_json('/audit_templates')
     self.assertEqual(len(audit_template_list),
                      len(response['audit_templates']))
     uuids = [s['uuid'] for s in response['audit_templates']]
     self.assertEqual(sorted(audit_template_list), sorted(uuids))
Exemplo n.º 51
0
    def test_get_one_soft_deleted(self):
        audit_template = obj_utils.create_test_audit_template(self.context)
        audit_template.soft_delete()
        response = self.get_json('/audit_templates/%s' %
                                 audit_template['uuid'],
                                 headers={'X-Show-Deleted': 'True'})
        self.assertEqual(audit_template.uuid, response['uuid'])
        self._assert_audit_template_fields(response)

        response = self.get_json('/audit_templates/%s' %
                                 audit_template['uuid'],
                                 expect_errors=True)
        self.assertEqual(404, response.status_int)
Exemplo n.º 52
0
    def test_get_one_soft_deleted(self):
        audit_template = obj_utils.create_test_audit_template(self.context)
        audit_template.soft_delete()
        response = self.get_json(
            '/audit_templates/%s' % audit_template['uuid'],
            headers={'X-Show-Deleted': 'True'})
        self.assertEqual(audit_template.uuid, response['uuid'])
        self._assert_audit_template_fields(response)

        response = self.get_json(
            '/audit_templates/%s' % audit_template['uuid'],
            expect_errors=True)
        self.assertEqual(404, response.status_int)
Exemplo n.º 53
0
    def setUp(self):
        super(TestDefaultPlanner, self).setUp()
        self.default_planner = pbase.DefaultPlanner(mock.Mock())
        self.default_planner.config.weights = {
            'nop': 0,
            'sleep': 1,
            'change_nova_service_state': 2,
            'migrate': 3
        }

        obj_utils.create_test_audit_template(self.context)

        p = mock.patch.object(db_api.BaseConnection, 'create_action_plan')
        self.mock_create_action_plan = p.start()
        self.mock_create_action_plan.side_effect = (
            self._simulate_action_plan_create)
        self.addCleanup(p.stop)

        q = mock.patch.object(db_api.BaseConnection, 'create_action')
        self.mock_create_action = q.start()
        self.mock_create_action.side_effect = (
            self._simulate_action_create)
        self.addCleanup(q.stop)
Exemplo n.º 54
0
 def test_many(self):
     audit_template_list = []
     for id_ in range(5):
         audit_template = obj_utils.create_test_audit_template(
             self.context,
             id=id_,
             uuid=utils.generate_uuid(),
             name='My Audit Template {0}'.format(id_))
         audit_template_list.append(audit_template.uuid)
     response = self.get_json('/audit_templates')
     self.assertEqual(len(audit_template_list),
                      len(response['audit_templates']))
     uuids = [s['uuid'] for s in response['audit_templates']]
     self.assertEqual(sorted(audit_template_list), sorted(uuids))
Exemplo n.º 55
0
    def test_remove_strategy(self):
        audit_template = obj_utils.create_test_audit_template(
            self.context, uuid=utils.generate_uuid(),
            name="AT_%s" % utils.generate_uuid(),
            goal_id=self.fake_goal1.id,
            strategy_id=self.fake_strategy1.id)
        response = self.get_json(
            '/audit_templates/%s' % audit_template.uuid)
        self.assertIsNotNone(response['strategy_uuid'])

        response = self.patch_json(
            '/audit_templates/%s' % self.audit_template.uuid,
            [{'path': '/strategy', 'op': 'remove'}])
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(200, response.status_code)
Exemplo n.º 56
0
 def setUp(self):
     super(TestContinuousAuditHandler, self).setUp()
     self.goal = obj_utils.create_test_goal(
         self.context, id=1, name=dummy_strategy.DummyStrategy.get_name())
     audit_template = obj_utils.create_test_audit_template(self.context)
     self.audits = [
         obj_utils.create_test_audit(
             self.context,
             id=id_,
             uuid=uuidutils.generate_uuid(),
             audit_template_id=audit_template.id,
             goal_id=self.goal.id,
             audit_type=objects.audit.AuditType.CONTINUOUS.value,
             goal=self.goal) for id_ in range(2, 4)
     ]
Exemplo n.º 57
0
    def test_remove_strategy(self):
        audit_template = obj_utils.create_test_audit_template(
            self.context, uuid=utils.generate_uuid(),
            name="AT_%s" % utils.generate_uuid(),
            goal_id=self.fake_goal1.id,
            strategy_id=self.fake_strategy1.id)
        response = self.get_json(
            '/audit_templates/%s' % audit_template.uuid)
        self.assertIsNotNone(response['strategy_uuid'])

        response = self.patch_json(
            '/audit_templates/%s' % self.audit_template.uuid,
            [{'path': '/strategy', 'op': 'remove'}])
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(200, response.status_code)
Exemplo n.º 58
0
 def setUp(self):
     super(TestPatch, self).setUp()
     self.audit_template = obj_utils.create_test_audit_template(
         self.context)
     p = mock.patch.object(db_api.BaseConnection, 'update_audit_template')
     self.mock_audit_template_update = p.start()
     self.mock_audit_template_update.side_effect = \
         self._simulate_rpc_audit_template_update
     cfg.CONF.set_override('goals', {
         "DUMMY": "DUMMY",
         "BASIC": "BASIC"
     },
                           group='watcher_goals',
                           enforce_type=True)
     self.addCleanup(p.stop)
Exemplo n.º 59
0
    def test_many_with_sort_key_audit_template_uuid(self):
        audit_template_list = []
        for id_ in range(5):
            audit_template = obj_utils.create_test_audit_template(
                self.context,
                name='at{0}'.format(id_),
                uuid=utils.generate_uuid())
            obj_utils.create_test_audit(
                self.context, id=id_, uuid=utils.generate_uuid(),
                audit_template_id=audit_template.id)
            audit_template_list.append(audit_template.uuid)

        response = self.get_json('/audits/?sort_key=audit_template_uuid')

        self.assertEqual(5, len(response['audits']))
        uuids = [s['audit_template_uuid'] for s in response['audits']]
        self.assertEqual(sorted(audit_template_list), uuids)
Exemplo n.º 60
0
    def test_many_without_soft_deleted(self):
        audit_template_list = []
        for id_ in range(1, 6):
            audit_template = obj_utils.create_test_audit_template(
                self.context, id=id_, uuid=utils.generate_uuid(),
                name='My Audit Template {0}'.format(id_))
            audit_template_list.append(audit_template)

        # We soft delete the ones with ID 4 and 5
        [at.soft_delete() for at in audit_template_list[3:]]

        response = self.get_json('/audit_templates')
        self.assertEqual(3, len(response['audit_templates']))
        uuids = [s['uuid'] for s in response['audit_templates']]
        self.assertEqual(
            sorted([at.uuid for at in audit_template_list[:3]]),
            sorted(uuids))