Esempio n. 1
0
    def test_many_with_audit_uuid_filter(self):
        action_plan_list1 = []
        audit1 = obj_utils.create_test_audit(self.context,
                                             id=2,
                                             uuid=utils.generate_uuid(),
                                             name='My Audit {0}'.format(2))
        for id_ in range(2, 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,
                                             id=3,
                                             uuid=utils.generate_uuid(),
                                             name='My Audit {0}'.format(3))
        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'])
Esempio 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'])
Esempio n. 3
0
    def test_filter_by_action_plan_uuid(self):
        action_plan_1 = obj_utils.create_test_action_plan(
            self.context, uuid=utils.generate_uuid(), audit_id=self.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)

        action_plan_2 = obj_utils.create_test_action_plan(
            self.context, uuid=utils.generate_uuid(), audit_id=self.audit.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?action_plan_uuid=%s' %
                                 action_plan_1.uuid)
        self.assertEqual(len(action_list), len(response['actions']))
        for action in response['actions']:
            self.assertEqual(action_plan_1.uuid, action['action_plan_uuid'])

        response = self.get_json('/actions?action_plan_uuid=%s' %
                                 action_plan_2.uuid)
        for action in response['actions']:
            self.assertEqual(action_plan_2.uuid, action['action_plan_uuid'])
Esempio n. 4
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,
     )
Esempio n. 5
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'])
Esempio n. 6
0
    def test_many_with_sort_key_action_plan_uuid(self):
        action_plan_1 = obj_utils.create_test_action_plan(
            self.context, uuid=utils.generate_uuid(), audit_id=self.audit.id)

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

        action_plans_uuid_list = []
        for id_, action_plan_id in enumerate(
                itertools.chain.from_iterable([
                    itertools.repeat(action_plan_1.id, 3),
                    itertools.repeat(action_plan_2.id, 2)
                ]), 1):
            action = obj_utils.create_test_action(
                self.context,
                id=id_,
                action_plan_id=action_plan_id,
                uuid=utils.generate_uuid())
            action_plans_uuid_list.append(action.action_plan.uuid)

        for direction in ['asc', 'desc']:
            response = self.get_json(
                '/actions?sort_key={0}&sort_dir={1}'.format(
                    'action_plan_uuid', direction))

            action_plan_uuids = \
                [s['action_plan_uuid'] for s in response['actions']]

            self.assertEqual(sorted(action_plans_uuid_list,
                                    reverse=(direction == 'desc')),
                             action_plan_uuids,
                             message='Failed on %s direction' % direction)
Esempio n. 7
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()
Esempio n. 8
0
 def setUp(self):
     super(TestDelete, self).setUp()
     obj_utils.create_test_action_plan(self.context)
     self.action = obj_utils.create_test_action(self.context, next=None)
     p = mock.patch.object(db_api.BaseConnection, 'update_action')
     self.mock_action_update = p.start()
     self.mock_action_update.side_effect = self._simulate_rpc_action_update
     self.addCleanup(p.stop)
Esempio n. 9
0
 def setUp(self):
     super(TestDelete, self).setUp()
     obj_utils.create_test_action_plan(self.context)
     self.action = obj_utils.create_test_action(self.context, next=None)
     p = mock.patch.object(db_api.BaseConnection, 'update_action')
     self.mock_action_update = p.start()
     self.mock_action_update.side_effect = self._simulate_rpc_action_update
     self.addCleanup(p.stop)
Esempio n. 10
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]))
Esempio n. 11
0
    def test_collection_links(self):
        for id_ in range(5):
            obj_utils.create_test_action_plan(
                self.context, id=id_, uuid=utils.generate_uuid())
        response = self.get_json('/action_plans/?limit=3')
        self.assertEqual(3, len(response['action_plans']))

        next_marker = response['action_plans'][-1]['uuid']
        self.assertIn(next_marker, response['next'])
Esempio n. 12
0
    def test_find_deleted_and_nonexpired_related_entries(self):
        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):
            objects_map = self.cmd.find_objects_to_delete()

        self.assertEqual(len(objects_map.audit_templates), 1)
        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]))
Esempio n. 13
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_action_plan(
                self.context, id=id_, uuid=utils.generate_uuid())
        response = self.get_json('/action_plans')
        self.assertEqual(3, len(response['action_plans']))

        next_marker = response['action_plans'][-1]['uuid']
        self.assertIn(next_marker, response['next'])
Esempio n. 14
0
 def test_links(self):
     uuid = utils.generate_uuid()
     obj_utils.create_test_action_plan(self.context, id=1, uuid=uuid)
     response = self.get_json('/action_plans/%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))
Esempio n. 15
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)
Esempio n. 16
0
 def setUp(self):
     super(TestPatch, 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)
     self.action = obj_utils.create_test_action(self.context, parents=None)
     p = mock.patch.object(db_api.BaseConnection, 'update_action')
     self.mock_action_update = p.start()
     self.mock_action_update.side_effect = self._simulate_rpc_action_update
     self.addCleanup(p.stop)
Esempio n. 17
0
 def test_many_without_soft_deleted(self):
     action_plan_list = []
     for id_ in [1, 2, 3]:
         action_plan = obj_utils.create_test_action_plan(
             self.context, id=id_, uuid=utils.generate_uuid())
         action_plan_list.append(action_plan.uuid)
     for id_ in [4, 5]:
         action_plan = obj_utils.create_test_action_plan(
             self.context, id=id_, uuid=utils.generate_uuid())
         action_plan.soft_delete()
     response = self.get_json('/action_plans')
     self.assertEqual(3, len(response['action_plans']))
     uuids = [s['uuid'] for s in response['action_plans']]
     self.assertEqual(sorted(action_plan_list), sorted(uuids))
Esempio n. 18
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)
Esempio n. 19
0
 def test_get_one_with_first_action(self):
     action_plan = obj_utils.create_test_action_plan(self.context)
     action = obj_utils.create_test_action(self.context, id=1)
     response = self.get_json('/action_plans/%s' % action_plan['uuid'])
     self.assertEqual(action_plan.uuid, response['uuid'])
     self.assertEqual(action.uuid, response['first_action_uuid'])
     self._assert_action_plans_fields(response)
Esempio n. 20
0
 def test_detail(self):
     action_plan = obj_utils.create_test_action_plan(self.context,
                                                     audit_id=None)
     response = self.get_json('/action_plans/detail')
     self.assertEqual(action_plan.uuid,
                      response['action_plans'][0]["uuid"])
     self._assert_action_plans_fields(response['action_plans'][0])
Esempio n. 21
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")
Esempio n. 22
0
    def test_execute_with_failed(self):
        nova_util = nova_helper.NovaHelper()
        instance = "31b9dd5c-b1fd-4f61-9b68-a47096326dac"
        nova_util.nova.servers.get.return_value = instance
        action_plan = obj_utils.create_test_action_plan(
            self.context,
            audit_id=self.audit.id,
            strategy_id=self.strategy.id,
            state=objects.action.State.ONGOING)

        action = obj_utils.create_test_action(
            self.context,
            action_plan_id=action_plan.id,
            state=objects.action.State.ONGOING,
            action_type='migrate',
            input_parameters={
                "resource_id": instance,
                "migration_type": "live",
                "destination_node": "host2",
                "source_node": "host1"
            })
        action_container = tflow.TaskFlowActionContainer(db_action=action,
                                                         engine=self.engine)

        result = action_container.execute()
        self.assertFalse(result)

        self.assertTrue(action.state, objects.action.State.FAILED)
Esempio n. 23
0
 def test_filter_by_action_plan_and_audit_uuids(self):
     action_plan = obj_utils.create_test_action_plan(
         self.context, uuid=utils.generate_uuid(), audit_id=self.audit.id)
     url = '/actions?action_plan_uuid=%s&audit_uuid=%s' % (action_plan.uuid,
                                                           self.audit.uuid)
     response = self.get_json(url, expect_errors=True)
     self.assertEqual(400, response.status_int)
Esempio n. 24
0
 def test_policy_disallow_update(self):
     action_plan = obj_utils.create_test_action_plan(self.context)
     self._common_policy_check(
         "action_plan:update", self.patch_json,
         '/action_plans/%s' % action_plan.uuid,
         [{'path': '/state', 'value': 'DELETED', 'op': 'replace'}],
         expect_errors=True)
Esempio n. 25
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)
Esempio n. 26
0
 def test_get_one_with_first_action(self):
     action_plan = obj_utils.create_test_action_plan(self.context)
     action = obj_utils.create_test_action(self.context, id=1)
     response = self.get_json('/action_plans/%s' % action_plan['uuid'])
     self.assertEqual(action_plan.uuid, response['uuid'])
     self.assertEqual(action.uuid, response['first_action_uuid'])
     self._assert_action_plans_fields(response)
Esempio n. 27
0
    def test_many_with_soft_deleted_action_plan_uuid(self):
        action_plan1 = obj_utils.create_test_action_plan(
            self.context, id=2, uuid=utils.generate_uuid(), audit_id=1)
        action_plan2 = obj_utils.create_test_action_plan(
            self.context, id=3, uuid=utils.generate_uuid(), audit_id=1)

        ap1_action_list = []
        ap2_action_list = []

        for id_ in range(0, 2):
            action = obj_utils.create_test_action(
                self.context,
                id=id_,
                action_plan_id=action_plan1.id,
                uuid=utils.generate_uuid())
            ap1_action_list.append(action)

        for id_ in range(2, 4):
            action = obj_utils.create_test_action(
                self.context,
                id=id_,
                action_plan_id=action_plan2.id,
                uuid=utils.generate_uuid())
            ap2_action_list.append(action)

        action_plan1.state = objects.action_plan.State.CANCELLED
        action_plan1.save()
        self.delete('/action_plans/%s' % action_plan1.uuid)

        response = self.get_json('/actions')
        # We deleted the actions from the 1st action plan so we've got 2 left
        self.assertEqual(len(ap2_action_list), len(response['actions']))

        # We deleted them so that's normal
        self.assertEqual([], [
            act for act in response['actions']
            if act['action_plan_uuid'] == action_plan1.uuid
        ])

        # Here are the 2 actions left
        self.assertEqual(
            set([act.as_dict()['uuid'] for act in ap2_action_list]),
            set([
                act['uuid'] for act in response['actions']
                if act['action_plan_uuid'] == action_plan2.uuid
            ]))
Esempio n. 28
0
    def test_many_with_soft_deleted_action_plan_uuid(self):
        action_plan1 = obj_utils.create_test_action_plan(
            self.context,
            id=2,
            uuid=utils.generate_uuid(),
            audit_id=1)
        action_plan2 = obj_utils.create_test_action_plan(
            self.context,
            id=3,
            uuid=utils.generate_uuid(),
            audit_id=1)

        ap1_action_list = []
        ap2_action_list = []

        for id_ in range(0, 2):
            action = obj_utils.create_test_action(
                self.context, id=id_,
                action_plan_id=action_plan1.id,
                uuid=utils.generate_uuid())
            ap1_action_list.append(action)

        for id_ in range(2, 4):
            action = obj_utils.create_test_action(
                self.context, id=id_,
                action_plan_id=action_plan2.id,
                uuid=utils.generate_uuid())
            ap2_action_list.append(action)

        self.delete('/action_plans/%s' % action_plan1.uuid)

        response = self.get_json('/actions')
        # We deleted the actions from the 1st action plan so we've got 2 left
        self.assertEqual(len(ap2_action_list), len(response['actions']))

        # We deleted them so that's normal
        self.assertEqual(
            [act for act in response['actions']
             if act['action_plan_uuid'] == action_plan1.uuid],
            [])

        # Here are the 2 actions left
        self.assertEqual(
            set([act['uuid'] for act in response['actions']
                 if act['action_plan_uuid'] == action_plan2.uuid]),
            set([act.as_dict()['uuid'] for act in ap2_action_list]))
Esempio n. 29
0
    def test_many_with_soft_deleted_audit_uuid(self):
        action_plan_list = []
        audit1 = obj_utils.create_test_audit(self.context,
                                             id=2,
                                             uuid=utils.generate_uuid(),
                                             name='My Audit {0}'.format(2))
        audit2 = obj_utils.create_test_audit(self.context,
                                             id=3,
                                             uuid=utils.generate_uuid(),
                                             name='My Audit {0}'.format(3))

        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)

        new_state = objects.audit.State.CANCELLED
        self.patch_json('/audits/%s' % audit1.uuid, [{
            'path': '/state',
            'value': new_state,
            'op': 'replace'
        }])
        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'])
Esempio n. 30
0
 def setUp(self):
     super(TestDelete, self).setUp()
     self.action_plan = obj_utils.create_test_action_plan(self.context)
     p = mock.patch.object(db_api.BaseConnection, 'destroy_action_plan')
     self.mock_action_plan_delete = p.start()
     self.mock_action_plan_delete.side_effect = \
         self._simulate_rpc_action_plan_delete
     self.addCleanup(p.stop)
Esempio n. 31
0
 def test_policy_disallow_update(self):
     action_plan = obj_utils.create_test_action_plan(self.context)
     self._common_policy_check(
         "action_plan:update", self.patch_json,
         '/action_plans/%s' % action_plan.uuid,
         [{'path': '/state',
           'value': objects.action_plan.State.DELETED,
           'op': 'replace'}],
         expect_errors=True)
Esempio n. 32
0
    def test_replace_state_pending_not_found(self):
        action_plan = obj_utils.create_test_action_plan(
            self.context, state=objects.action_plan.State.DELETED)

        response = self.get_json('/action_plans/%s' % action_plan.uuid,
                                 expect_errors=True)
        self.assertEqual(404, response.status_code)
        self.assertEqual('application/json', response.content_type)
        self.assertTrue(response.json['error_message'])
Esempio n. 33
0
 def setUp(self):
     super(TestPatch, self).setUp()
     self.action_plan = obj_utils.create_test_action_plan(
         self.context, state=objects.action_plan.State.RECOMMENDED)
     p = mock.patch.object(db_api.BaseConnection, 'update_action_plan')
     self.mock_action_plan_update = p.start()
     self.mock_action_plan_update.side_effect = \
         self._simulate_rpc_action_plan_update
     self.addCleanup(p.stop)
Esempio n. 34
0
    def test_detail_soft_deleted(self):
        action_plan = obj_utils.create_test_action_plan(self.context)
        action_plan.soft_delete()
        response = self.get_json('/action_plans/detail',
                                 headers={'X-Show-Deleted': 'True'})
        self.assertEqual(action_plan.uuid, response['action_plans'][0]["uuid"])
        self._assert_action_plans_fields(response['action_plans'][0])

        response = self.get_json('/action_plans/detail')
        self.assertEqual([], response['action_plans'])
Esempio n. 35
0
 def test_many(self):
     action_plan_list = []
     for id_ in range(5):
         action_plan = obj_utils.create_test_action_plan(
             self.context, id=id_, uuid=utils.generate_uuid())
         action_plan_list.append(action_plan.uuid)
     response = self.get_json('/action_plans')
     self.assertEqual(len(action_plan_list), len(response['action_plans']))
     uuids = [s['uuid'] for s in response['action_plans']]
     self.assertEqual(sorted(action_plan_list), sorted(uuids))
Esempio n. 36
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)
Esempio n. 37
0
    def test_get_one_soft_deleted(self):
        action_plan = obj_utils.create_test_action_plan(self.context)
        action_plan.soft_delete()
        response = self.get_json('/action_plans/%s' % action_plan['uuid'],
                                 headers={'X-Show-Deleted': 'True'})
        self.assertEqual(action_plan.uuid, response['uuid'])
        self._assert_action_plans_fields(response)

        response = self.get_json('/action_plans/%s' % action_plan['uuid'],
                                 expect_errors=True)
        self.assertEqual(404, response.status_int)
Esempio n. 38
0
    def test_many_with_soft_deleted_audit_uuid(self):
        action_plan_list = []
        audit1 = obj_utils.create_test_audit(self.context,
                                             id=2,
                                             uuid=utils.generate_uuid(),
                                             name='My Audit {0}'.format(2))
        audit2 = obj_utils.create_test_audit(self.context,
                                             id=3,
                                             uuid=utils.generate_uuid(),
                                             name='My Audit {0}'.format(3))

        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'])
Esempio n. 39
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'])
Esempio n. 40
0
 def test_get_one_ok(self):
     action_plan = obj_utils.create_test_action_plan(self.context)
     obj_utils.create_test_efficacy_indicator(
         self.context, action_plan_id=action_plan['id'])
     response = self.get_json('/action_plans/%s' % action_plan['uuid'])
     self.assertEqual(action_plan.uuid, response['uuid'])
     self._assert_action_plans_fields(response)
     self.assertEqual([{
         'description': 'Test indicator',
         'name': 'test_indicator',
         'value': 0.0,
         'unit': '%'
     }], response['efficacy_indicators'])
Esempio n. 41
0
 def test_get_one_ok(self):
     action_plan = obj_utils.create_test_action_plan(self.context)
     obj_utils.create_test_efficacy_indicator(
         self.context, action_plan_id=action_plan['id'])
     response = self.get_json('/action_plans/%s' % action_plan['uuid'])
     self.assertEqual(action_plan.uuid, response['uuid'])
     self._assert_action_plans_fields(response)
     self.assertEqual(
         [{'description': 'Test indicator',
           'name': 'test_indicator',
           'value': 0.0,
           'unit': '%'}],
         response['efficacy_indicators'])
Esempio n. 42
0
    def setUp(self):
        super(TestDefaultActionPlanHandler, self).setUp()

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

        obj_utils.create_test_goal(self.context)
        obj_utils.create_test_strategy(self.context)
        obj_utils.create_test_audit(self.context)
        self.action_plan = obj_utils.create_test_action_plan(self.context)
Esempio n. 43
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'])
Esempio n. 44
0
 def test_many_without_soft_deleted(self):
     action_plan_list = []
     for id_ in [1, 2, 3]:
         action_plan = obj_utils.create_action_plan_without_audit(
             self.context, id=id_, uuid=utils.generate_uuid())
         action_plan_list.append(action_plan.uuid)
     for id_ in [4, 5]:
         action_plan = obj_utils.create_test_action_plan(
             self.context, id=id_, uuid=utils.generate_uuid())
         action_plan.soft_delete()
     response = self.get_json('/action_plans')
     self.assertEqual(3, len(response['action_plans']))
     uuids = [s['uuid'] for s in response['action_plans']]
     self.assertEqual(sorted(action_plan_list), sorted(uuids))
Esempio n. 45
0
    def test_replace_state_pending_ok(self):
        action_plan = obj_utils.create_test_action_plan(
            self.context, state=self.original_state)

        initial_ap = self.get_json('/action_plans/%s' % action_plan.uuid)

        response = self.patch_json(
            '/action_plans/%s' % action_plan.uuid,
            [{'path': '/state', 'value': self.new_state, 'op': 'replace'}])
        updated_ap = self.get_json('/action_plans/%s' % action_plan.uuid)
        self.assertNotEqual(self.new_state, initial_ap['state'])
        self.assertEqual(self.new_state, updated_ap['state'])
        self.assertEqual('application/json', response.content_type)
        self.assertEqual(200, response.status_code)
Esempio n. 46
0
 def test_many_with_action_plan_uuid(self):
     action_plan = obj_utils.create_test_action_plan(
         self.context, id=2, uuid=utils.generate_uuid(), audit_id=1)
     action_list = []
     for id_ in range(5):
         action = obj_utils.create_test_action(self.context,
                                               id=id_,
                                               action_plan_id=2,
                                               uuid=utils.generate_uuid())
         action_list.append(action.uuid)
     response = self.get_json('/actions')
     self.assertEqual(len(action_list), len(response['actions']))
     for action in response['actions']:
         self.assertEqual(action_plan.uuid, action['action_plan_uuid'])
Esempio n. 47
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'])
Esempio n. 48
0
 def test_policy_disallow_get_one(self):
     action_plan = obj_utils.create_test_action_plan(self.context)
     self._common_policy_check(
         "action_plan:get", self.get_json,
         '/action_plans/%s' % action_plan.uuid,
         expect_errors=True)
Esempio n. 49
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 ")

        with freezegun.freeze_time(self.expired_date):
            self.goal1 = obj_utils.create_test_goal(
                self.context, id=self._generate_id(), uuid=None,
                name=goal1_name, display_name=goal1_name.lower())
            self.goal2 = obj_utils.create_test_goal(
                self.context, id=self._generate_id(), uuid=None,
                name=goal2_name, display_name=goal2_name.lower())
            self.goal3 = obj_utils.create_test_goal(
                self.context, id=self._generate_id(), uuid=None,
                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=None,
                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=None,
                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=None,
                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=None, 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=None, 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=None, 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, 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()
 def setUp(self):
     super(TestDefaultActionPlanHandler, self).setUp()
     self.action_plan = obj_utils.create_test_action_plan(
         self.context)
Esempio n. 51
0
 def test_policy_disallow_delete(self):
     action_plan = obj_utils.create_test_action_plan(self.context)
     self._common_policy_check(
         "action_plan:delete", self.delete,
         '/action_plans/%s' % action_plan.uuid, expect_errors=True)
Esempio n. 52
0
 def test_detail_against_single(self):
     action_plan = obj_utils.create_test_action_plan(self.context)
     response = self.get_json(
         '/action_plan/%s/detail' % action_plan['uuid'],
         expect_errors=True)
     self.assertEqual(404, response.status_int)
Esempio n. 53
0
 def setUp(self):
     super(TestListAction, self).setUp()
     obj_utils.create_test_action_plan(self.context)