Ejemplo n.º 1
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'])
Ejemplo n.º 2
0
    def test_filter_by_audit_uuid(self):
        audit = obj_utils.create_test_audit(self.context,
                                            uuid=utils.generate_uuid())
        action_plan_1 = obj_utils.create_test_action_plan(
            self.context,
            uuid=utils.generate_uuid(),
            audit_id=audit.id)
        action_list = []

        for id_ in range(3):
            action = obj_utils.create_test_action(
                self.context, id=id_,
                action_plan_id=action_plan_1.id,
                uuid=utils.generate_uuid())
            action_list.append(action.uuid)

        audit2 = obj_utils.create_test_audit(self.context,
                                             uuid=utils.generate_uuid())
        action_plan_2 = obj_utils.create_test_action_plan(
            self.context,
            uuid=utils.generate_uuid(),
            audit_id=audit2.id)

        for id_ in range(4, 5, 6):
            obj_utils.create_test_action(
                self.context, id=id_,
                action_plan_id=action_plan_2.id,
                uuid=utils.generate_uuid())

        response = self.get_json('/actions?audit_uuid=%s' % audit.uuid)
        self.assertEqual(len(action_list), len(response['actions']))
        for action in response['actions']:
            self.assertEqual(action_plan_1.uuid, action['action_plan_uuid'])
Ejemplo n.º 3
0
    def test_many_with_soft_deleted_audit_uuid(self):
        action_plan_list = []
        audit1 = obj_utils.create_test_audit(self.context,
                                             id=1,
                                             uuid=utils.generate_uuid())
        audit2 = obj_utils.create_test_audit(self.context,
                                             id=2,
                                             uuid=utils.generate_uuid())

        for id_ in range(0, 2):
            action_plan = obj_utils.create_test_action_plan(
                self.context, id=id_, uuid=utils.generate_uuid(),
                audit_id=audit1.id)
            action_plan_list.append(action_plan.uuid)

        for id_ in range(2, 4):
            action_plan = obj_utils.create_test_action_plan(
                self.context, id=id_, uuid=utils.generate_uuid(),
                audit_id=audit2.id)
            action_plan_list.append(action_plan.uuid)

        self.delete('/audits/%s' % audit1.uuid)

        response = self.get_json('/action_plans')

        self.assertEqual(len(action_plan_list), len(response['action_plans']))

        for id_ in range(0, 2):
            action_plan = response['action_plans'][id_]
            self.assertIsNone(action_plan['audit_uuid'])

        for id_ in range(2, 4):
            action_plan = response['action_plans'][id_]
            self.assertEqual(audit2.uuid, action_plan['audit_uuid'])
Ejemplo n.º 4
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()
Ejemplo n.º 5
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]))
Ejemplo n.º 6
0
    def test_collection_links(self):
        for id_ in range(5):
            obj_utils.create_test_audit(self.context, id=id_,
                                        uuid=utils.generate_uuid())
        response = self.get_json('/audits/?limit=3')
        self.assertEqual(3, len(response['audits']))

        next_marker = response['audits'][-1]['uuid']
        self.assertIn(next_marker, response['next'])
Ejemplo n.º 7
0
 def test_links(self):
     uuid = utils.generate_uuid()
     obj_utils.create_test_audit(self.context, id=1, uuid=uuid)
     response = self.get_json('/audits/%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))
Ejemplo n.º 8
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(self.context, id=id_,
                                        uuid=utils.generate_uuid())
        response = self.get_json('/audits')
        self.assertEqual(3, len(response['audits']))

        next_marker = response['audits'][-1]['uuid']
        self.assertIn(next_marker, response['next'])
Ejemplo n.º 9
0
    def test_purge_command_with_nonexpired_related_entries(
            self, m_destroy_audit_template, m_destroy_audit,
            m_destroy_action_plan, m_destroy_action):
        with freezegun.freeze_time(self.fake_today):
            # orphan audit
            audit4 = obj_utils.create_test_audit(
                self.context, audit_template_id=404,  # Does not exist
                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)

            audit5 = obj_utils.create_test_audit(
                self.context, audit_template_id=self.audit_template1.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.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
            audit5.soft_delete()
            action_plan5.soft_delete()

        with freezegun.freeze_time(self.fake_today):
            self.cmd.execute()

        self.assertEqual(m_destroy_audit_template.call_count, 1)
        self.assertEqual(m_destroy_audit.call_count, 3)
        self.assertEqual(m_destroy_action_plan.call_count, 3)
        self.assertEqual(m_destroy_action.call_count, 3)

        m_destroy_audit_template.assert_any_call(self.audit_template1.uuid)
        m_destroy_audit.assert_any_call(self.audit1.uuid)
        m_destroy_audit.assert_any_call(audit4.uuid)
        m_destroy_action_plan.assert_any_call(self.action_plan1.uuid)
        m_destroy_action_plan.assert_any_call(action_plan4.uuid)
        m_destroy_action_plan.assert_any_call(action_plan5.uuid)
        m_destroy_action.assert_any_call(self.action1.uuid)
        m_destroy_action.assert_any_call(action4.uuid)
        m_destroy_action.assert_any_call(action5.uuid)
Ejemplo n.º 10
0
 def test_many_without_soft_deleted(self):
     audit_list = []
     for id_ in [1, 2, 3]:
         audit = obj_utils.create_test_audit(self.context, id=id_,
                                             uuid=utils.generate_uuid())
         audit_list.append(audit.uuid)
     for id_ in [4, 5]:
         audit = obj_utils.create_test_audit(self.context, id=id_,
                                             uuid=utils.generate_uuid())
         audit.soft_delete()
     response = self.get_json('/audits')
     self.assertEqual(3, len(response['audits']))
     uuids = [s['uuid'] for s in response['audits']]
     self.assertEqual(sorted(audit_list), sorted(uuids))
 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)
Ejemplo n.º 12
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)
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
 def test_policy_disallow_update(self):
     audit = obj_utils.create_test_audit(self.context)
     self._common_policy_check(
         "audit:update", self.patch_json,
         '/audits/%s' % audit.uuid,
         [{'path': '/state', 'value': 'SUBMITTED', 'op': 'replace'}],
         expect_errors=True)
Ejemplo n.º 15
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)
Ejemplo n.º 16
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)
Ejemplo n.º 17
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)
 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)
Ejemplo n.º 19
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)
Ejemplo n.º 20
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'])
Ejemplo n.º 21
0
 def test_many(self):
     audit_list = []
     for id_ in range(5):
         audit = obj_utils.create_test_audit(self.context, id=id_,
                                             uuid=utils.generate_uuid())
         audit_list.append(audit.uuid)
     response = self.get_json('/audits')
     self.assertEqual(len(audit_list), len(response['audits']))
     uuids = [s['uuid'] for s in response['audits']]
     self.assertEqual(sorted(audit_list), sorted(uuids))
Ejemplo n.º 22
0
    def test_one_soft_deleted(self):
        audit = obj_utils.create_test_audit(self.context)
        audit.soft_delete()
        response = self.get_json('/audits',
                                 headers={'X-Show-Deleted': 'True'})
        self.assertEqual(audit.uuid, response['audits'][0]["uuid"])
        self._assert_audit_fields(response['audits'][0])

        response = self.get_json('/audits')
        self.assertEqual([], response['audits'])
Ejemplo n.º 23
0
    def test_get_one_soft_deleted(self):
        audit = obj_utils.create_test_audit(self.context)
        audit.soft_delete()
        response = self.get_json('/audits/%s' % audit['uuid'],
                                 headers={'X-Show-Deleted': 'True'})
        self.assertEqual(audit.uuid, response['uuid'])
        self._assert_audit_fields(response)

        response = self.get_json('/audits/%s' % audit['uuid'],
                                 expect_errors=True)
        self.assertEqual(404, response.status_int)
Ejemplo n.º 24
0
 def test_filter_by_action_plan_and_audit_uuids(self):
     audit = obj_utils.create_test_audit(
         self.context, uuid=utils.generate_uuid())
     action_plan = obj_utils.create_test_action_plan(
         self.context,
         uuid=utils.generate_uuid(),
         audit_id=audit.id)
     url = '/actions?action_plan_uuid=%s&audit_uuid=%s' % (
         action_plan.uuid, audit.uuid)
     response = self.get_json(url, expect_errors=True)
     self.assertEqual(400, response.status_int)
Ejemplo n.º 25
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)]
Ejemplo n.º 26
0
 def test_many_with_audit_uuid(self):
     action_plan_list = []
     audit = obj_utils.create_test_audit(self.context,
                                         uuid=utils.generate_uuid())
     for id_ in range(5):
         action_plan = obj_utils.create_test_action_plan(
             self.context, id=id_, uuid=utils.generate_uuid(),
             audit_id=audit.id)
         action_plan_list.append(action_plan.uuid)
     response = self.get_json('/action_plans')
     self.assertEqual(len(action_plan_list), len(response['action_plans']))
     for action in response['action_plans']:
         self.assertEqual(audit.uuid, action['audit_uuid'])
Ejemplo n.º 27
0
    def test_many_with_audit_uuid_filter(self):
        action_plan_list1 = []
        audit1 = obj_utils.create_test_audit(self.context,
                                             uuid=utils.generate_uuid())
        for id_ in range(5):
            action_plan = obj_utils.create_test_action_plan(
                self.context, id=id_, uuid=utils.generate_uuid(),
                audit_id=audit1.id)
            action_plan_list1.append(action_plan.uuid)

        audit2 = obj_utils.create_test_audit(self.context,
                                             uuid=utils.generate_uuid())
        action_plan_list2 = []
        for id_ in [5, 6, 7]:
            action_plan = obj_utils.create_test_action_plan(
                self.context, id=id_, uuid=utils.generate_uuid(),
                audit_id=audit2.id)
            action_plan_list2.append(action_plan.uuid)

        response = self.get_json('/action_plans?audit_uuid=%s' % audit2.uuid)
        self.assertEqual(len(action_plan_list2), len(response['action_plans']))
        for action in response['action_plans']:
            self.assertEqual(audit2.uuid, action['audit_uuid'])
Ejemplo n.º 28
0
    def test_many_with_sort_key_audit_uuid(self):
        audit_list = []
        for id_ in range(5):
            audit = obj_utils.create_test_audit(self.context,
                                                uuid=utils.generate_uuid())
            obj_utils.create_test_action_plan(
                self.context, id=id_, uuid=utils.generate_uuid(),
                audit_id=audit.id)
            audit_list.append(audit.uuid)

        response = self.get_json('/action_plans/?sort_key=audit_uuid')

        self.assertEqual(5, len(response['action_plans']))
        uuids = [s['audit_uuid'] for s in response['action_plans']]
        self.assertEqual(sorted(audit_list), uuids)
Ejemplo n.º 29
0
    def test_details_and_filter_by_audit_uuid(self):
        audit = obj_utils.create_test_audit(self.context,
                                            uuid=utils.generate_uuid())
        action_plan = obj_utils.create_test_action_plan(
            self.context,
            uuid=utils.generate_uuid(),
            audit_id=audit.id)

        for id_ in range(3):
            action = obj_utils.create_test_action(
                self.context, id=id_,
                action_plan_id=action_plan.id,
                uuid=utils.generate_uuid())

        response = self.get_json(
            '/actions/detail?audit_uuid=%s' % audit.uuid)
        for action in response['actions']:
            self.assertEqual(action_plan.uuid, action['action_plan_uuid'])
Ejemplo n.º 30
0
    def test_send_audit_action_with_error(self):
        audit = utils.create_test_audit(mock.Mock(),
                                        interval=None,
                                        state=objects.audit.State.ONGOING,
                                        goal_id=self.goal.id,
                                        strategy_id=self.strategy.id,
                                        goal=self.goal,
                                        strategy=self.strategy)

        try:
            # This is to load the exception in sys.exc_info()
            raise exception.WatcherException("TEST")
        except exception.WatcherException:
            notifications.audit.send_action_notification(mock.MagicMock(),
                                                         audit,
                                                         host='node0',
                                                         action='strategy',
                                                         priority='error',
                                                         phase='error')

        self.assertEqual(1, self.m_notifier.error.call_count)
        notification = self.m_notifier.error.call_args[1]
        self.assertEqual("infra-optim:node0", self.m_notifier.publisher_id)
        self.assertDictEqual(
            {
                "event_type": "audit.strategy.error",
                "payload": {
                    "watcher_object.data": {
                        "audit_type": "ONESHOT",
                        "created_at": "2016-10-18T09:52:05Z",
                        "deleted_at": None,
                        "fault": {
                            "watcher_object.data": {
                                "exception":
                                "WatcherException",
                                "exception_message":
                                "TEST",
                                "function_name":
                                ("test_send_audit_action_with_error"),
                                "module_name":
                                "watcher.tests.notifications."
                                "test_audit_notification"
                            },
                            "watcher_object.name": "ExceptionPayload",
                            "watcher_object.namespace": "watcher",
                            "watcher_object.version": "1.0"
                        },
                        "goal_uuid": "f7ad87ae-4298-91cf-93a0-f35a852e3652",
                        "goal": {
                            "watcher_object.data": {
                                "created_at": "2016-10-18T09:52:05Z",
                                "deleted_at": None,
                                "display_name": "test goal",
                                "efficacy_specification": [],
                                "name": "TEST",
                                "updated_at": None,
                                "uuid": "f7ad87ae-4298-91cf-93a0-f35a852e3652"
                            },
                            "watcher_object.name": "GoalPayload",
                            "watcher_object.namespace": "watcher",
                            "watcher_object.version": "1.0"
                        },
                        "interval": None,
                        "next_run_time": None,
                        "auto_trigger": False,
                        "parameters": {},
                        "scope": [],
                        "state": "ONGOING",
                        "strategy_uuid":
                        ("cb3d0b58-4415-4d90-b75b-1e96878730e3"),
                        "strategy": {
                            "watcher_object.data": {
                                "created_at": "2016-10-18T09:52:05Z",
                                "deleted_at": None,
                                "display_name": "test strategy",
                                "name": "TEST",
                                "parameters_spec": {},
                                "updated_at": None,
                                "uuid": "cb3d0b58-4415-4d90-b75b-1e96878730e3"
                            },
                            "watcher_object.name": "StrategyPayload",
                            "watcher_object.namespace": "watcher",
                            "watcher_object.version": "1.0"
                        },
                        "updated_at": None,
                        "uuid": "10a47dd1-4874-4298-91cf-eff046dbdb8d"
                    },
                    "watcher_object.name": "AuditActionPayload",
                    "watcher_object.namespace": "watcher",
                    "watcher_object.version": "1.1"
                }
            }, notification)
Ejemplo n.º 31
0
 def setUp(self):
     super(TestListActionPlan, self).setUp()
     obj_utils.create_test_goal(self.context)
     obj_utils.create_test_strategy(self.context)
     obj_utils.create_test_audit(self.context)
Ejemplo n.º 32
0
    def test_purge_command_with_nonexpired_related_entries(
            self, m_destroy_goal, m_destroy_strategy, m_destroy_audit_template,
            m_destroy_audit, m_destroy_action_plan, m_destroy_action):
        with freezegun.freeze_time(self.fake_today):
            # orphan audit template
            audit_template4 = obj_utils.create_test_audit_template(
                self.context,
                goal_id=self.goal2.id,
                name=self.generate_unique_name(prefix="Audit Template 4 "),
                strategy_id=None,
                id=self._generate_id(),
                uuid=utils.generate_uuid())
            audit4 = obj_utils.create_test_audit(
                self.context,
                id=self._generate_id(),
                uuid=utils.generate_uuid(),
                audit_template_id=audit_template4.id,
                name=self.generate_unique_name(prefix="Audit 4 "))
            action_plan4 = obj_utils.create_test_action_plan(
                self.context,
                id=self._generate_id(),
                uuid=utils.generate_uuid(),
                audit_id=audit4.id,
                strategy_id=self.strategy1.id)
            action4 = obj_utils.create_test_action(
                self.context,
                action_plan_id=action_plan4.id,
                id=self._generate_id(),
                uuid=utils.generate_uuid())

            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=utils.generate_uuid())
            audit5 = obj_utils.create_test_audit(
                self.context,
                audit_template_id=audit_template5.id,
                strategy_id=self.strategy1.id,
                id=self._generate_id(),
                uuid=utils.generate_uuid(),
                name=self.generate_unique_name(prefix="Audit 5 "))
            action_plan5 = obj_utils.create_test_action_plan(
                self.context,
                id=self._generate_id(),
                uuid=utils.generate_uuid(),
                audit_id=audit5.id,
                strategy_id=self.strategy1.id)
            action5 = obj_utils.create_test_action(
                self.context,
                action_plan_id=action_plan5.id,
                id=self._generate_id(),
                uuid=utils.generate_uuid())

            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):
            self.cmd.execute()

        self.assertEqual(m_destroy_goal.call_count, 1)
        self.assertEqual(m_destroy_strategy.call_count, 1)
        self.assertEqual(m_destroy_audit_template.call_count, 3)
        self.assertEqual(m_destroy_audit.call_count, 3)
        self.assertEqual(m_destroy_action_plan.call_count, 3)
        self.assertEqual(m_destroy_action.call_count, 3)

        m_destroy_audit_template.assert_any_call(self.audit_template1.uuid)
        m_destroy_audit.assert_any_call(self.audit1.uuid)
        m_destroy_audit.assert_any_call(audit4.uuid)
        m_destroy_action_plan.assert_any_call(self.action_plan1.uuid)
        m_destroy_action_plan.assert_any_call(action_plan4.uuid)
        m_destroy_action_plan.assert_any_call(action_plan5.uuid)
        m_destroy_action.assert_any_call(self.action1.uuid)
        m_destroy_action.assert_any_call(action4.uuid)
        m_destroy_action.assert_any_call(action5.uuid)
Ejemplo n.º 33
0
 def test_get_one(self):
     audit = obj_utils.create_test_audit(self.context)
     response = self.get_json('/audits/%s' % audit['uuid'])
     self.assertEqual(audit.uuid, response['uuid'])
     self._assert_audit_fields(response)
Ejemplo n.º 34
0
 def setUp(self):
     super(TestActionPolicyEnforcement, self).setUp()
     obj_utils.create_test_goal(self.context)
     obj_utils.create_test_strategy(self.context)
     obj_utils.create_test_audit(self.context)
     obj_utils.create_test_action_plan(self.context)
Ejemplo n.º 35
0
 def setUp(self):
     super(TestListAction, self).setUp()
     self.goal = obj_utils.create_test_goal(self.context)
     self.strategy = obj_utils.create_test_strategy(self.context)
     self.audit = obj_utils.create_test_audit(self.context)
     self.action_plan = obj_utils.create_test_action_plan(self.context)
Ejemplo n.º 36
0
    def test_send_audit_update_with_strategy(self):
        audit = utils.create_test_audit(mock.Mock(),
                                        interval=None,
                                        state=objects.audit.State.ONGOING,
                                        goal_id=self.goal.id,
                                        strategy_id=self.strategy.id,
                                        goal=self.goal,
                                        strategy=self.strategy)
        notifications.audit.send_update(mock.MagicMock(),
                                        audit,
                                        host='node0',
                                        old_state=objects.audit.State.PENDING)

        # The 1st notification is because we created the object.
        self.assertEqual(2, self.m_notifier.info.call_count)
        notification = self.m_notifier.info.call_args[1]
        payload = notification['payload']

        self.assertEqual("infra-optim:node0", self.m_notifier.publisher_id)
        self.assertDictEqual(
            {
                "watcher_object.namespace": "watcher",
                "watcher_object.version": "1.1",
                "watcher_object.data": {
                    "interval": None,
                    "next_run_time": None,
                    "auto_trigger": False,
                    "strategy_uuid": "cb3d0b58-4415-4d90-b75b-1e96878730e3",
                    "strategy": {
                        "watcher_object.namespace": "watcher",
                        "watcher_object.version": "1.0",
                        "watcher_object.data": {
                            "updated_at": None,
                            "uuid": "cb3d0b58-4415-4d90-b75b-1e96878730e3",
                            "name": "TEST",
                            "parameters_spec": {},
                            "created_at": "2016-10-18T09:52:05Z",
                            "display_name": "test strategy",
                            "deleted_at": None
                        },
                        "watcher_object.name": "StrategyPayload"
                    },
                    "parameters": {},
                    "uuid": "10a47dd1-4874-4298-91cf-eff046dbdb8d",
                    "goal_uuid": "f7ad87ae-4298-91cf-93a0-f35a852e3652",
                    "goal": {
                        "watcher_object.namespace": "watcher",
                        "watcher_object.version": "1.0",
                        "watcher_object.data": {
                            "updated_at": None,
                            "uuid": "f7ad87ae-4298-91cf-93a0-f35a852e3652",
                            "name": "TEST",
                            "efficacy_specification": [],
                            "created_at": "2016-10-18T09:52:05Z",
                            "display_name": "test goal",
                            "deleted_at": None
                        },
                        "watcher_object.name": "GoalPayload"
                    },
                    "deleted_at": None,
                    "scope": [],
                    "state": "ONGOING",
                    "updated_at": None,
                    "created_at": "2016-10-18T09:52:05Z",
                    "state_update": {
                        "watcher_object.namespace": "watcher",
                        "watcher_object.version": "1.0",
                        "watcher_object.data": {
                            "old_state": "PENDING",
                            "state": "ONGOING"
                        },
                        "watcher_object.name": "AuditStateUpdatePayload"
                    },
                    "audit_type": "ONESHOT"
                },
                "watcher_object.name": "AuditUpdatePayload"
            }, payload)
Ejemplo n.º 37
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=self.goal2.id,
                name=self.generate_unique_name(prefix="Audit Template 4 "),
                strategy_id=self.strategy1.id,
                id=self._generate_id(),
                uuid=utils.generate_uuid())
            audit4 = obj_utils.create_test_audit(
                self.context,
                audit_template_id=audit_template4.id,
                strategy_id=self.strategy1.id,
                id=self._generate_id(),
                uuid=utils.generate_uuid(),
                name=self.generate_unique_name(prefix="Audit 4 "))
            action_plan4 = obj_utils.create_test_action_plan(
                self.context,
                id=self._generate_id(),
                uuid=utils.generate_uuid(),
                audit_id=audit4.id,
                strategy_id=self.strategy1.id)
            action4 = obj_utils.create_test_action(
                self.context,
                action_plan_id=action_plan4.id,
                id=self._generate_id(),
                uuid=utils.generate_uuid())

            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=utils.generate_uuid())
            audit5 = obj_utils.create_test_audit(
                self.context,
                audit_template_id=audit_template5.id,
                strategy_id=self.strategy1.id,
                id=self._generate_id(),
                uuid=utils.generate_uuid(),
                name=self.generate_unique_name(prefix="Audit 5 "))
            action_plan5 = obj_utils.create_test_action_plan(
                self.context,
                id=self._generate_id(),
                uuid=utils.generate_uuid(),
                audit_id=audit5.id,
                strategy_id=self.strategy1.id)
            action5 = obj_utils.create_test_action(
                self.context,
                action_plan_id=action_plan5.id,
                id=self._generate_id(),
                uuid=utils.generate_uuid())

            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]))
Ejemplo n.º 38
0
 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)
Ejemplo n.º 39
0
 def test_policy_disallow_delete(self):
     audit = obj_utils.create_test_audit(self.context)
     self._common_policy_check(
         "audit:delete", self.delete,
         '/audits/%s' % audit.uuid, expect_errors=True)
Ejemplo n.º 40
0
 def test_detail_against_single(self):
     audit = obj_utils.create_test_audit(self.context)
     response = self.get_json('/audits/%s/detail' % audit['uuid'],
                              expect_errors=True)
     self.assertEqual(404, response.status_int)
Ejemplo n.º 41
0
 def test_get_one(self):
     audit = obj_utils.create_test_audit(self.context)
     response = self.get_json('/audits/%s' % audit['uuid'])
     self.assertEqual(audit.uuid, response['uuid'])
     self._assert_audit_fields(response)
Ejemplo n.º 42
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

        goal1_name = "GOAL_1"
        goal2_name = "GOAL_2"
        goal3_name = "GOAL_3"

        strategy1_name = "strategy_1"
        strategy2_name = "strategy_2"
        strategy3_name = "strategy_3"

        self.audit_template1_name = self.generate_unique_name(
            prefix="Audit Template 1 ")
        self.audit_template2_name = self.generate_unique_name(
            prefix="Audit Template 2 ")
        self.audit_template3_name = self.generate_unique_name(
            prefix="Audit Template 3 ")

        self.audit1_name = self.generate_unique_name(prefix="Audit 1 ")
        self.audit2_name = self.generate_unique_name(prefix="Audit 2 ")
        self.audit3_name = self.generate_unique_name(prefix="Audit 3 ")

        with freezegun.freeze_time(self.expired_date):
            self.goal1 = obj_utils.create_test_goal(
                self.context,
                id=self._generate_id(),
                uuid=utils.generate_uuid(),
                name=goal1_name,
                display_name=goal1_name.lower())
            self.goal2 = obj_utils.create_test_goal(
                self.context,
                id=self._generate_id(),
                uuid=utils.generate_uuid(),
                name=goal2_name,
                display_name=goal2_name.lower())
            self.goal3 = obj_utils.create_test_goal(
                self.context,
                id=self._generate_id(),
                uuid=utils.generate_uuid(),
                name=goal3_name,
                display_name=goal3_name.lower())
            self.goal1.soft_delete()

        with freezegun.freeze_time(self.expired_date):
            self.strategy1 = obj_utils.create_test_strategy(
                self.context,
                id=self._generate_id(),
                uuid=utils.generate_uuid(),
                name=strategy1_name,
                display_name=strategy1_name.lower(),
                goal_id=self.goal1.id)
            self.strategy2 = obj_utils.create_test_strategy(
                self.context,
                id=self._generate_id(),
                uuid=utils.generate_uuid(),
                name=strategy2_name,
                display_name=strategy2_name.lower(),
                goal_id=self.goal2.id)
            self.strategy3 = obj_utils.create_test_strategy(
                self.context,
                id=self._generate_id(),
                uuid=utils.generate_uuid(),
                name=strategy3_name,
                display_name=strategy3_name.lower(),
                goal_id=self.goal3.id)
            self.strategy1.soft_delete()

        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=utils.generate_uuid(),
                goal_id=self.goal1.id,
                strategy_id=self.strategy1.id)
            self.audit_template2 = obj_utils.create_test_audit_template(
                self.context,
                name=self.audit_template2_name,
                id=self._generate_id(),
                uuid=utils.generate_uuid(),
                goal_id=self.goal2.id,
                strategy_id=self.strategy2.id)
            self.audit_template3 = obj_utils.create_test_audit_template(
                self.context,
                name=self.audit_template3_name,
                id=self._generate_id(),
                uuid=utils.generate_uuid(),
                goal_id=self.goal3.id,
                strategy_id=self.strategy3.id)
            self.audit_template1.soft_delete()

        with freezegun.freeze_time(self.expired_date):
            self.audit1 = obj_utils.create_test_audit(
                self.context,
                id=self._generate_id(),
                uuid=utils.generate_uuid(),
                name=self.audit1_name,
                goal_id=self.goal1.id,
                strategy_id=self.strategy1.id)
            self.audit2 = obj_utils.create_test_audit(
                self.context,
                id=self._generate_id(),
                uuid=utils.generate_uuid(),
                name=self.audit2_name,
                goal_id=self.goal2.id,
                strategy_id=self.strategy2.id)
            self.audit3 = obj_utils.create_test_audit(
                self.context,
                id=self._generate_id(),
                uuid=utils.generate_uuid(),
                name=self.audit3_name,
                goal_id=self.goal3.id,
                strategy_id=self.strategy3.id)
            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=utils.generate_uuid(),
                strategy_id=self.strategy1.id)
            self.action_plan2 = obj_utils.create_test_action_plan(
                self.context,
                audit_id=self.audit2.id,
                id=self._generate_id(),
                strategy_id=self.strategy2.id,
                uuid=utils.generate_uuid())
            self.action_plan3 = obj_utils.create_test_action_plan(
                self.context,
                audit_id=self.audit3.id,
                id=self._generate_id(),
                uuid=utils.generate_uuid(),
                strategy_id=self.strategy3.id)

            self.action1 = obj_utils.create_test_action(
                self.context,
                action_plan_id=self.action_plan1.id,
                id=self._generate_id(),
                uuid=utils.generate_uuid())
            self.action2 = obj_utils.create_test_action(
                self.context,
                action_plan_id=self.action_plan2.id,
                id=self._generate_id(),
                uuid=utils.generate_uuid())
            self.action3 = obj_utils.create_test_action(
                self.context,
                action_plan_id=self.action_plan3.id,
                id=self._generate_id(),
                uuid=utils.generate_uuid())
            self.action_plan1.soft_delete()
Ejemplo n.º 43
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)
Ejemplo n.º 44
0
 def test_policy_disallow_get_one(self):
     audit = obj_utils.create_test_audit(self.context)
     self._common_policy_check(
         "audit:get", self.get_json,
         '/audits/%s' % audit.uuid,
         expect_errors=True)
Ejemplo n.º 45
0
 def test_one(self):
     audit = obj_utils.create_test_audit(self.context)
     response = self.get_json('/audits')
     self.assertEqual(audit.uuid, response['audits'][0]["uuid"])
     self._assert_audit_fields(response['audits'][0])
Ejemplo n.º 46
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(self.context)