コード例 #1
0
ファイル: test_actions.py プロジェクト: XroLLla/watcher
    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'])
コード例 #2
0
ファイル: test_purge.py プロジェクト: Jean-Emile/watcher
    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()
コード例 #3
0
ファイル: test_purge.py プロジェクト: Oliverlyn/watcher
    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]))
コード例 #4
0
ファイル: test_actions.py プロジェクト: XroLLla/watcher
 def test_links(self):
     uuid = utils.generate_uuid()
     obj_utils.create_test_action(self.context, id=1, uuid=uuid)
     response = self.get_json('/actions/%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))
コード例 #5
0
ファイル: test_actions.py プロジェクト: XroLLla/watcher
    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_action(self.context, id=id_,
                                         uuid=utils.generate_uuid())
        response = self.get_json('/actions')
        self.assertEqual(3, len(response['actions']))

        next_marker = response['actions'][-1]['uuid']
        self.assertIn(next_marker, response['next'])
コード例 #6
0
ファイル: test_purge.py プロジェクト: Jean-Emile/watcher
    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)
コード例 #7
0
ファイル: test_actions.py プロジェクト: XroLLla/watcher
 def test_many_without_soft_deleted(self):
     action_list = []
     for id_ in [1, 2, 3]:
         action = obj_utils.create_test_action(self.context, id=id_,
                                               uuid=utils.generate_uuid())
         action_list.append(action.uuid)
     for id_ in [4, 5]:
         action = obj_utils.create_test_action(self.context, id=id_,
                                               uuid=utils.generate_uuid())
         action.soft_delete()
     response = self.get_json('/actions')
     self.assertEqual(3, len(response['actions']))
     uuids = [s['uuid'] for s in response['actions']]
     self.assertEqual(sorted(action_list), sorted(uuids))
コード例 #8
0
ファイル: test_actions.py プロジェクト: XroLLla/watcher
 def test_get_one(self):
     action = obj_utils.create_test_action(self.context, next=None)
     response = self.get_json('/actions/%s' % action['uuid'])
     self.assertEqual(action.uuid, response['uuid'])
     self.assertEqual(action.action_type, response['action_type'])
     self.assertEqual(action.input_parameters, response['input_parameters'])
     self._assert_action_fields(response)
コード例 #9
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)
コード例 #10
0
ファイル: test_actions.py プロジェクト: XroLLla/watcher
 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)
コード例 #11
0
ファイル: test_actions.py プロジェクト: XroLLla/watcher
    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]))
コード例 #12
0
ファイル: test_actions.py プロジェクト: XroLLla/watcher
 def test_many(self):
     action_list = []
     for id_ in range(5):
         action = obj_utils.create_test_action(self.context, id=id_,
                                               uuid=utils.generate_uuid())
         action_list.append(action.uuid)
     response = self.get_json('/actions')
     self.assertEqual(len(action_list), len(response['actions']))
     uuids = [s['uuid'] for s in response['actions']]
     self.assertEqual(sorted(action_list), sorted(uuids))
コード例 #13
0
ファイル: test_actions.py プロジェクト: crowdy/watcher
 def test_collection_links(self):
     parents = None
     for id_ in range(5):
         action = obj_utils.create_test_action(self.context,
                                               id=id_,
                                               uuid=utils.generate_uuid(),
                                               parents=parents)
         parents = [action.id]
     response = self.get_json('/actions/?limit=3')
     self.assertEqual(3, len(response['actions']))
コード例 #14
0
ファイル: test_actions.py プロジェクト: crowdy/watcher
    def test_one_soft_deleted(self):
        action = obj_utils.create_test_action(self.context, parents=None)
        action.soft_delete()
        response = self.get_json('/actions',
                                 headers={'X-Show-Deleted': 'True'})
        self.assertEqual(action.uuid, response['actions'][0]["uuid"])
        self._assert_action_fields(response['actions'][0])

        response = self.get_json('/actions')
        self.assertEqual([], response['actions'])
コード例 #15
0
ファイル: test_actions.py プロジェクト: XroLLla/watcher
    def test_one_soft_deleted(self):
        action = obj_utils.create_test_action(self.context, next=None)
        action.soft_delete()
        response = self.get_json('/actions',
                                 headers={'X-Show-Deleted': 'True'})
        self.assertEqual(action.uuid, response['actions'][0]["uuid"])
        self._assert_action_fields(response['actions'][0])

        response = self.get_json('/actions')
        self.assertEqual([], response['actions'])
コード例 #16
0
    def test_send_action_plan_create(self):
        action = utils.create_test_action(mock.Mock(),
                                          state=objects.action.State.PENDING,
                                          action_type='nop',
                                          input_parameters={
                                              'param1': 1,
                                              'param2': 2
                                          },
                                          parents=[],
                                          action_plan_id=self.action_plan.id)
        notifications.action.send_create(mock.MagicMock(),
                                         action,
                                         host='node0')

        self.assertEqual(4, 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.0',
                'watcher_object.name': 'ActionCreatePayload',
                'watcher_object.data': {
                    'uuid': '10a47dd1-4874-4298-91cf-eff046dbdb8d',
                    'input_parameters': {
                        'param2': 2,
                        'param1': 1
                    },
                    'created_at': '2016-10-18T09:52:05Z',
                    'updated_at': None,
                    'state': 'PENDING',
                    'action_plan': {
                        'watcher_object.namespace': 'watcher',
                        'watcher_object.version': '1.0',
                        'watcher_object.name': 'TerseActionPlanPayload',
                        'watcher_object.data': {
                            'uuid': '76be87bd-3422-43f9-93a0-e85a577e3061',
                            'global_efficacy': {},
                            'created_at': '2016-10-18T09:52:05Z',
                            'updated_at': None,
                            'state': 'ONGOING',
                            'audit_uuid': '10a47dd1-4874-4298'
                            '-91cf-eff046dbdb8d',
                            'strategy_uuid': 'cb3d0b58-4415-4d90'
                            '-b75b-1e96878730e3',
                            'deleted_at': None
                        }
                    },
                    'parents': [],
                    'action_type': 'nop',
                    'deleted_at': None
                }
            }, payload)
コード例 #17
0
 def test_many(self):
     action_list = []
     for id_ in range(5):
         action = obj_utils.create_test_action(self.context,
                                               id=id_,
                                               uuid=utils.generate_uuid())
         action_list.append(action.uuid)
     response = self.get_json('/actions')
     self.assertEqual(len(action_list), len(response['actions']))
     uuids = [s['uuid'] for s in response['actions']]
     self.assertEqual(sorted(action_list), sorted(uuids))
コード例 #18
0
    def test_get_one_soft_deleted(self):
        action = obj_utils.create_test_action(self.context, parents=None)
        action.soft_delete()
        response = self.get_json('/actions/%s' % action['uuid'],
                                 headers={'X-Show-Deleted': 'True'})
        self.assertEqual(action.uuid, response['uuid'])
        self._assert_action_fields(response)

        response = self.get_json('/actions/%s' % action['uuid'],
                                 expect_errors=True)
        self.assertEqual(404, response.status_int)
コード例 #19
0
 def setUp(self):
     super(TestDelete, 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)
     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)
コード例 #20
0
ファイル: test_actions.py プロジェクト: XroLLla/watcher
    def test_get_one_soft_deleted(self):
        action = obj_utils.create_test_action(self.context, next=None)
        action.soft_delete()
        response = self.get_json('/actions/%s' % action['uuid'],
                                 headers={'X-Show-Deleted': 'True'})
        self.assertEqual(action.uuid, response['uuid'])
        self._assert_action_fields(response)

        response = self.get_json('/actions/%s' % action['uuid'],
                                 expect_errors=True)
        self.assertEqual(404, response.status_int)
コード例 #21
0
 def test_many_with_parents(self):
     action_list = []
     for id_ in range(5):
         if id_ > 0:
             action = obj_utils.create_test_action(
                 self.context,
                 id=id_,
                 uuid=utils.generate_uuid(),
                 parents=[action_list[id_ - 1]])
         else:
             action = obj_utils.create_test_action(
                 self.context,
                 id=id_,
                 uuid=utils.generate_uuid(),
                 parents=[])
         action_list.append(action.uuid)
     response = self.get_json('/actions')
     response_actions = response['actions']
     for id_ in range(4):
         self.assertEqual(response_actions[id_]['uuid'],
                          response_actions[id_ + 1]['parents'][0])
コード例 #22
0
ファイル: test_actions.py プロジェクト: XroLLla/watcher
    def test_collection_links(self):
        next = -1
        for id_ in range(5):
            action = obj_utils.create_test_action(self.context, id=id_,
                                                  uuid=utils.generate_uuid(),
                                                  next=next)
            next = action.id
        response = self.get_json('/actions/?limit=3')
        self.assertEqual(3, len(response['actions']))

        next_marker = response['actions'][-1]['uuid']
        self.assertIn(next_marker, response['next'])
コード例 #23
0
ファイル: test_actions.py プロジェクト: XroLLla/watcher
 def test_many_with_next_uuid(self):
     action_list = []
     for id_ in range(5):
         action = obj_utils.create_test_action(self.context, id=id_,
                                               uuid=utils.generate_uuid(),
                                               next=id_ + 1)
         action_list.append(action.uuid)
     response = self.get_json('/actions')
     response_actions = response['actions']
     for id in [0, 1, 2, 3]:
         self.assertEqual(response_actions[id]['next_uuid'],
                          response_actions[id + 1]['uuid'])
コード例 #24
0
ファイル: test_actions.py プロジェクト: icclab/watcher
 def test_many_with_next_uuid(self):
     action_list = []
     for id_ in range(5):
         action = obj_utils.create_test_action(self.context,
                                               id=id_,
                                               uuid=utils.generate_uuid(),
                                               next=id_ + 1)
         action_list.append(action.uuid)
     response = self.get_json('/actions')
     response_actions = response['actions']
     for id in [0, 1, 2, 3]:
         self.assertEqual(response_actions[id]['next_uuid'],
                          response_actions[id + 1]['uuid'])
コード例 #25
0
 def test_start_action_plan(self, mock_policy):
     mock_policy.return_value = True
     action = obj_utils.create_test_action(self.context, id=1)
     self.action_plan.state = objects.action_plan.State.SUCCEEDED
     response = self.post('/v1/action_plans/%s/%s/' %
                          (self.action_plan.uuid, 'start'),
                          expect_errors=True)
     self.assertEqual(200, response.status_int)
     act_response = self.get_json('/actions/%s' % action.uuid,
                                  expect_errors=True)
     self.assertEqual(200, act_response.status_int)
     self.assertEqual('PENDING', act_response.json['state'])
     self.assertEqual('application/json', act_response.content_type)
コード例 #26
0
ファイル: test_actions.py プロジェクト: icclab/watcher
    def test_many_with_sort_key_next_uuid(self):
        for id_ in range(5):
            obj_utils.create_test_action(self.context,
                                         id=id_,
                                         uuid=utils.generate_uuid(),
                                         next=id_ + 1)
        response = self.get_json('/actions/')
        reference_uuids = [s.get('next_uuid', '') for s in response['actions']]

        response = self.get_json('/actions/?sort_key=next_uuid')

        self.assertEqual(5, len(response['actions']))
        uuids = [(s['next_uuid'] if 'next_uuid' in s else '')
                 for s in response['actions']]
        self.assertEqual(sorted(reference_uuids), uuids)

        response = self.get_json('/actions/?sort_key=next_uuid&sort_dir=desc')

        self.assertEqual(5, len(response['actions']))
        uuids = [(s['next_uuid'] if 'next_uuid' in s else '')
                 for s in response['actions']]
        self.assertEqual(sorted(reference_uuids, reverse=True), uuids)
コード例 #27
0
ファイル: test_actions.py プロジェクト: icclab/watcher
    def test_collection_links(self):
        next = -1
        for id_ in range(5):
            action = obj_utils.create_test_action(self.context,
                                                  id=id_,
                                                  uuid=utils.generate_uuid(),
                                                  next=next)
            next = action.id
        response = self.get_json('/actions/?limit=3')
        self.assertEqual(3, len(response['actions']))

        next_marker = response['actions'][-1]['uuid']
        self.assertIn(next_marker, response['next'])
コード例 #28
0
ファイル: test_actions.py プロジェクト: XroLLla/watcher
    def test_many_with_sort_key_next_uuid(self):
        for id_ in range(5):
            obj_utils.create_test_action(self.context, id=id_,
                                         uuid=utils.generate_uuid(),
                                         next=id_ + 1)
        response = self.get_json('/actions/')
        reference_uuids = [
            s.get('next_uuid', '') for s in response['actions']
        ]

        response = self.get_json('/actions/?sort_key=next_uuid')

        self.assertEqual(5, len(response['actions']))
        uuids = [(s['next_uuid'] if 'next_uuid' in s else '')
                 for s in response['actions']]
        self.assertEqual(sorted(reference_uuids), uuids)

        response = self.get_json('/actions/?sort_key=next_uuid&sort_dir=desc')

        self.assertEqual(5, len(response['actions']))
        uuids = [(s['next_uuid'] if 'next_uuid' in s else '')
                 for s in response['actions']]
        self.assertEqual(sorted(reference_uuids, reverse=True), uuids)
コード例 #29
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'])
コード例 #30
0
    def test_execute_with_action_plan_cancel(self, m_get_actionplan):
        obj_utils.create_test_goal(self.context)
        strategy = obj_utils.create_test_strategy(self.context)
        audit = obj_utils.create_test_audit(
            self.context, strategy_id=strategy.id)
        action_plan = obj_utils.create_test_action_plan(
            self.context, audit_id=audit.id,
            strategy_id=strategy.id,
            state=objects.action_plan.State.CANCELLING)
        action1 = obj_utils.create_test_action(
            self.context, action_plan_id=action_plan.id,
            action_type='nop', state=objects.action.State.SUCCEEDED,
            input_parameters={'message': 'hello World'})
        action2 = obj_utils.create_test_action(
            self.context, action_plan_id=action_plan.id,
            action_type='nop', state=objects.action.State.ONGOING,
            uuid='9eb51e14-936d-4d12-a500-6ba0f5e0bb1c',
            input_parameters={'message': 'hello World'})
        action3 = obj_utils.create_test_action(
            self.context, action_plan_id=action_plan.id,
            action_type='nop', state=objects.action.State.PENDING,
            uuid='bc7eee5c-4fbe-4def-9744-b539be55aa19',
            input_parameters={'message': 'hello World'})
        m_get_actionplan.return_value = action_plan
        actions = []
        actions.append(action1)
        actions.append(action2)
        actions.append(action3)
        self.assertRaises(exception.ActionPlanCancelled,
                          self.engine.execute, actions)
        try:
            self.check_action_state(action1, objects.action.State.SUCCEEDED)
            self.check_action_state(action2, objects.action.State.CANCELLED)
            self.check_action_state(action3, objects.action.State.CANCELLED)

        except Exception as exc:
            self.fail(exc)
コード例 #31
0
    def test_details_and_filter_by_audit_uuid(self):
        action_plan = obj_utils.create_test_action_plan(
            self.context, uuid=utils.generate_uuid(), audit_id=self.audit.id)

        for id_ in range(1, 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' %
                                 self.audit.uuid)
        for action in response['actions']:
            self.assertEqual(action_plan.uuid, action['action_plan_uuid'])
コード例 #32
0
    def test_many_with_sort_key_uuid(self):
        action_plan = obj_utils.create_test_action_plan(
            self.context, uuid=utils.generate_uuid(), audit_id=self.audit.id)

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

        response = self.get_json('/actions?sort_key=%s' % 'uuid')
        names = [s['uuid'] for s in response['actions']]

        self.assertEqual(sorted([a.uuid for a in actions_list]), names)
コード例 #33
0
ファイル: test_actions.py プロジェクト: XroLLla/watcher
 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'])
コード例 #34
0
ファイル: test_actions.py プロジェクト: XroLLla/watcher
    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'])
コード例 #35
0
    def test_execute(self):
        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='nop',
            input_parameters={'message': 'hello World'})
        action_container = tflow.TaskFlowActionContainer(db_action=action,
                                                         engine=self.engine)
        action_container.execute()

        self.assertTrue(action.state, objects.action.State.SUCCEEDED)
コード例 #36
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)
        self.strategy = obj_utils.create_test_strategy(self.context)
        self.audit = obj_utils.create_test_audit(
            self.context, strategy_id=self.strategy.id)
        self.action_plan = obj_utils.create_test_action_plan(
            self.context, audit_id=self.audit.id,
            strategy_id=self.strategy.id)
        self.action = obj_utils.create_test_action(
            self.context, action_plan_id=self.action_plan.id,
            action_type='nop',
            input_parameters={'message': 'hello World'})
コード例 #37
0
ファイル: test_actions_plans.py プロジェクト: sue-fly/watcher
    def test_delete_action_plan_with_action(self):
        action = obj_utils.create_test_action(self.context, id=1)

        self.delete('/action_plans/%s' % self.action_plan.uuid)
        ap_response = self.get_json('/action_plans/%s' % self.action_plan.uuid,
                                    expect_errors=True)
        acts_response = self.get_json('/actions/?action_plan_uuid=%s' %
                                      self.action_plan.uuid)
        act_response = self.get_json('/actions/%s' % action.uuid,
                                     expect_errors=True)

        # The action plan does not exist anymore
        self.assertEqual(404, ap_response.status_int)
        self.assertEqual('application/json', ap_response.content_type)
        self.assertTrue(ap_response.json['error_message'])

        # Nor does the action
        self.assertEqual(0, len(acts_response['actions']))
        self.assertEqual(404, act_response.status_int)
        self.assertEqual('application/json', act_response.content_type)
        self.assertTrue(act_response.json['error_message'])
コード例 #38
0
    def test_delete_action_plan_with_action(self):
        action = obj_utils.create_test_action(
            self.context, id=self.action_plan.first_action_id)

        self.delete('/action_plans/%s' % self.action_plan.uuid)
        ap_response = self.get_json('/action_plans/%s' % self.action_plan.uuid,
                                    expect_errors=True)
        acts_response = self.get_json(
            '/actions/?action_plan_uuid=%s' % self.action_plan.uuid)
        act_response = self.get_json(
            '/actions/%s' % action.uuid,
            expect_errors=True)

        # The action plan does not exist anymore
        self.assertEqual(404, ap_response.status_int)
        self.assertEqual('application/json', ap_response.content_type)
        self.assertTrue(ap_response.json['error_message'])

        # Nor does the action
        self.assertEqual(0, len(acts_response['actions']))
        self.assertEqual(404, act_response.status_int)
        self.assertEqual('application/json', act_response.content_type)
        self.assertTrue(act_response.json['error_message'])
コード例 #39
0
    def test_execute_with_cancel_action_plan(self, mock_eventlet_spawn):
        action_plan = obj_utils.create_test_action_plan(
            self.context,
            audit_id=self.audit.id,
            strategy_id=self.strategy.id,
            state=objects.action_plan.State.CANCELLING)

        action = obj_utils.create_test_action(
            self.context,
            action_plan_id=action_plan.id,
            state=objects.action.State.ONGOING,
            action_type='nop',
            input_parameters={'message': 'hello World'})
        action_container = tflow.TaskFlowActionContainer(db_action=action,
                                                         engine=self.engine)

        def empty_test():
            pass

        et = eventlet.spawn(empty_test)
        mock_eventlet_spawn.return_value = et
        action_container.execute()
        et.kill.assert_called_with()
コード例 #40
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()
コード例 #41
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)
コード例 #42
0
ファイル: test_actions.py プロジェクト: Oliverlyn/watcher
 def test_policy_disallow_get_one(self):
     action = obj_utils.create_test_action(self.context)
     self._common_policy_check(
         "action:get", self.get_json,
         '/actions/%s' % action.uuid,
         expect_errors=True)
コード例 #43
0
 def test_one(self):
     action = obj_utils.create_test_action(self.context, parents=None)
     response = self.get_json('/actions')
     self.assertEqual(action.uuid, response['actions'][0]["uuid"])
     self._assert_action_fields(response['actions'][0])
コード例 #44
0
 def test_policy_disallow_get_one(self):
     action = obj_utils.create_test_action(self.context)
     self._common_policy_check("action:get",
                               self.get_json,
                               '/actions/%s' % action.uuid,
                               expect_errors=True)
コード例 #45
0
ファイル: test_actions.py プロジェクト: XroLLla/watcher
 def test_one(self):
     action = obj_utils.create_test_action(self.context, next=None)
     response = self.get_json('/actions')
     self.assertEqual(action.uuid, response['actions'][0]["uuid"])
     self._assert_action_fields(response['actions'][0])
コード例 #46
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)
コード例 #47
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()
コード例 #48
0
 def test_detail_against_single(self):
     action = obj_utils.create_test_action(self.context, parents=None)
     response = self.get_json('/actions/%s/detail' % action['uuid'],
                              expect_errors=True)
     self.assertEqual(404, response.status_int)
コード例 #49
0
    def test_send_action_execution_with_error(self):
        action = utils.create_test_action(mock.Mock(),
                                          state=objects.action.State.FAILED,
                                          action_type='nop',
                                          input_parameters={
                                              'param1': 1,
                                              'param2': 2
                                          },
                                          parents=[],
                                          action_plan_id=self.action_plan.id)

        try:
            # This is to load the exception in sys.exc_info()
            raise exception.WatcherException("TEST")
        except exception.WatcherException:
            notifications.action.send_execution_notification(mock.MagicMock(),
                                                             action,
                                                             'execution',
                                                             phase='error',
                                                             host='node0',
                                                             priority='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': 'action.execution.error',
                'payload': {
                    'watcher_object.namespace': 'watcher',
                    'watcher_object.version': '1.0',
                    'watcher_object.name': 'ActionExecutionPayload',
                    'watcher_object.data': {
                        'uuid': '10a47dd1-4874-4298-91cf-eff046dbdb8d',
                        'input_parameters': {
                            'param2': 2,
                            'param1': 1
                        },
                        'created_at': '2016-10-18T09:52:05Z',
                        'fault': {
                            'watcher_object.data': {
                                'exception':
                                u'WatcherException',
                                'exception_message':
                                u'TEST',
                                'function_name':
                                ('test_send_action_execution_with_error'),
                                'module_name': ('watcher.tests.notifications.'
                                                'test_action_notification')
                            },
                            'watcher_object.name': 'ExceptionPayload',
                            'watcher_object.namespace': 'watcher',
                            'watcher_object.version': '1.0'
                        },
                        'updated_at': None,
                        'state': 'FAILED',
                        'action_plan': {
                            'watcher_object.namespace': 'watcher',
                            'watcher_object.version': '1.0',
                            'watcher_object.name': 'TerseActionPlanPayload',
                            'watcher_object.data': {
                                'uuid': '76be87bd-3422-43f9-93a0-e85a577e3061',
                                'global_efficacy': {},
                                'created_at': '2016-10-18T09:52:05Z',
                                'updated_at': None,
                                'state': 'ONGOING',
                                'audit_uuid': '10a47dd1-4874-4298'
                                '-91cf-eff046dbdb8d',
                                'strategy_uuid': 'cb3d0b58-4415-4d90'
                                '-b75b-1e96878730e3',
                                'deleted_at': None
                            }
                        },
                        'parents': [],
                        'action_type': 'nop',
                        'deleted_at': None
                    }
                }
            }, notification)
コード例 #50
0
ファイル: test_purge.py プロジェクト: Oliverlyn/watcher
    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()
コード例 #51
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]))
コード例 #52
0
ファイル: test_actions.py プロジェクト: XroLLla/watcher
 def test_detail_against_single(self):
     action = obj_utils.create_test_action(self.context, next=None)
     response = self.get_json('/actions/%s/detail' % action['uuid'],
                              expect_errors=True)
     self.assertEqual(404, response.status_int)