Beispiel #1
0
    def test_policy_get_diff_project(self):
        data = self.new_policy_data()
        policy = db_api.policy_create(self.ctx, data)

        new_ctx = utils.dummy_context(project='a-different-project')
        res = db_api.policy_get(new_ctx, policy.id)
        self.assertIsNone(res)
        res = db_api.policy_get(new_ctx, policy.id, project_safe=False)
        self.assertIsNotNone(res)
        self.assertEqual(policy.id, res.id)
Beispiel #2
0
    def test_policy_get_diff_project(self):
        data = self.new_policy_data()
        policy = db_api.policy_create(self.ctx, data)

        new_ctx = utils.dummy_context(project='a-different-project')
        res = db_api.policy_get(new_ctx, policy.id)
        self.assertIsNone(res)
        res = db_api.policy_get(new_ctx, policy.id, project_safe=False)
        self.assertIsNotNone(res)
        self.assertEqual(policy.id, res.id)
Beispiel #3
0
    def test_policy_get_admin_context(self):
        data = self.new_policy_data()
        policy = db_api.policy_create(self.ctx, data)

        admin_ctx = utils.dummy_context(project='a-different-project',
                                        is_admin=True)
        res = db_api.policy_get(admin_ctx, policy.id, project_safe=True)
        self.assertIsNone(res)
        res = db_api.policy_get(admin_ctx, policy.id, project_safe=False)
        self.assertIsNotNone(res)
Beispiel #4
0
    def test_policy_get_by_short_id(self):
        policy_ids = ['same-part-unique-part', 'same-part-part-unique']

        for pid in policy_ids:
            data = self.new_policy_data(id=pid)
            db_api.policy_create(self.ctx, data)

            # verify creation with set ID
            policy = db_api.policy_get(self.ctx, pid)
            self.assertIsNotNone(policy)
            self.assertEqual(pid, policy.id)

        # too short -> multiple choices
        for x in range(len('same-part-')):
            self.assertRaises(exception.MultipleChoices,
                              db_api.policy_get_by_short_id, self.ctx,
                              policy_ids[0][:x])

        # ids are unique
        policy = db_api.policy_get_by_short_id(self.ctx, policy_ids[0][:11])
        self.assertEqual(policy_ids[0], policy.id)
        policy = db_api.policy_get_by_short_id(self.ctx, policy_ids[1][:11])
        self.assertEqual(policy_ids[1], policy.id)

        # bad ids
        res = db_api.policy_get_by_short_id(self.ctx, 'non-existent')
        self.assertIsNone(res)
Beispiel #5
0
    def test_policy_get_by_short_id(self):
        policy_ids = ['same-part-unique-part',
                      'same-part-part-unique']

        for pid in policy_ids:
            data = self.new_policy_data(id=pid)
            db_api.policy_create(self.ctx, data)

            # verify creation with set ID
            policy = db_api.policy_get(self.ctx, pid)
            self.assertIsNotNone(policy)
            self.assertEqual(pid, policy.id)

        # too short -> multiple choices
        for x in range(len('same-part-')):
            self.assertRaises(exception.MultipleChoices,
                              db_api.policy_get_by_short_id,
                              self.ctx, policy_ids[0][:x])

        # ids are unique
        policy = db_api.policy_get_by_short_id(self.ctx, policy_ids[0][:11])
        self.assertEqual(policy_ids[0], policy.id)
        policy = db_api.policy_get_by_short_id(self.ctx, policy_ids[1][:11])
        self.assertEqual(policy_ids[1], policy.id)

        # bad ids
        res = db_api.policy_get_by_short_id(self.ctx, 'non-existent')
        self.assertIsNone(res)
Beispiel #6
0
    def test_policy_get_admin_context(self):
        data = self.new_policy_data()
        policy = db_api.policy_create(self.ctx, data)

        admin_ctx = utils.dummy_context(project='a-different-project',
                                        is_admin=True)
        res = db_api.policy_get(admin_ctx, policy.id, project_safe=True)
        self.assertIsNotNone(res)
Beispiel #7
0
    def test_policy_get(self):
        data = self.new_policy_data()
        policy = db_api.policy_create(self.ctx, data)

        retobj = db_api.policy_get(self.ctx, policy.id)
        self.assertIsNotNone(retobj)
        self.assertEqual(data['name'], retobj.name)
        self.assertEqual(data['type'], retobj.type)
        self.assertEqual(data['spec'], retobj.spec)
        self.assertEqual(10, retobj.spec['max_size'])
        self.assertIsNone(retobj.data)
Beispiel #8
0
    def test_policy_get(self):
        data = self.new_policy_data()
        policy = db_api.policy_create(self.ctx, data)

        retobj = db_api.policy_get(self.ctx, policy.id)
        self.assertIsNotNone(retobj)
        self.assertEqual(data['name'], retobj.name)
        self.assertEqual(data['type'], retobj.type)
        self.assertEqual(data['spec'], retobj.spec)
        self.assertEqual(10, retobj.spec['max_size'])
        self.assertIsNone(retobj.data)
Beispiel #9
0
    def test_policy_delete(self):
        policy = db_api.policy_create(self.ctx, self.new_policy_data())
        self.assertIsNotNone(policy)

        policy_id = policy.id
        db_api.policy_delete(self.ctx, policy_id)

        policy = db_api.policy_get(self.ctx, policy_id)
        self.assertIsNone(policy)

        # not found in delete is okay
        res = db_api.policy_delete(self.ctx, policy_id)
        self.assertIsNone(res)
Beispiel #10
0
    def test_policy_get_show_deleted(self):
        data = self.new_policy_data()
        policy_id = db_api.policy_create(self.ctx, data).id

        # check created
        policy = db_api.policy_get(self.ctx, policy_id)
        self.assertIsNotNone(policy)

        db_api.policy_delete(self.ctx, policy_id)

        # default equivalent to false
        policy = db_api.policy_get(self.ctx, policy_id)
        self.assertIsNone(policy)

        # explicit false
        policy = db_api.policy_get(self.ctx, policy_id, show_deleted=False)
        self.assertIsNone(policy)

        # explicit true
        policy = db_api.policy_get(self.ctx, policy_id, show_deleted=True)
        self.assertIsNotNone(policy)
        self.assertEqual(policy_id, policy.id)
Beispiel #11
0
    def test_policy_delete(self):
        policy = db_api.policy_create(self.ctx, self.new_policy_data())
        self.assertIsNotNone(policy)

        policy_id = policy.id
        db_api.policy_delete(self.ctx, policy_id)

        policy = db_api.policy_get(self.ctx, policy_id)
        self.assertIsNone(policy)

        # not found in delete is okay
        res = db_api.policy_delete(self.ctx, policy_id)
        self.assertIsNone(res)
Beispiel #12
0
    def test_policy_get_show_deleted(self):
        data = self.new_policy_data()
        policy_id = db_api.policy_create(self.ctx, data).id

        # check created
        policy = db_api.policy_get(self.ctx, policy_id)
        self.assertIsNotNone(policy)

        db_api.policy_delete(self.ctx, policy_id)

        # default equivalent to false
        policy = db_api.policy_get(self.ctx, policy_id)
        self.assertIsNone(policy)

        # explicit false
        policy = db_api.policy_get(self.ctx, policy_id, show_deleted=False)
        self.assertIsNone(policy)

        # explicit true
        policy = db_api.policy_get(self.ctx, policy_id, show_deleted=True)
        self.assertIsNotNone(policy)
        self.assertEqual(policy_id, policy.id)
Beispiel #13
0
    def test_policy_delete_in_use(self):
        policy = db_api.policy_create(self.ctx, self.new_policy_data())
        self.assertIsNotNone(policy)

        fields = {'enabled': True, 'level': 50}
        db_api.cluster_policy_attach(self.ctx, self.cluster.id, policy.id,
                                     fields)
        self.assertRaises(exception.ResourceBusyError, db_api.policy_delete,
                          self.ctx, policy.id)

        db_api.cluster_policy_detach(self.ctx, self.cluster.id, policy.id)
        db_api.policy_delete(self.ctx, policy.id)
        policy = db_api.policy_get(self.ctx, policy.id)
        self.assertIsNone(policy)
Beispiel #14
0
    def test_policy_delete_in_use(self):
        policy = db_api.policy_create(self.ctx, self.new_policy_data())
        self.assertIsNotNone(policy)

        fields = {
            'enabled': True,
        }
        db_api.cluster_policy_attach(self.ctx, self.cluster.id, policy.id,
                                     fields)
        self.assertRaises(exception.ResourceBusyError,
                          db_api.policy_delete,
                          self.ctx, policy.id)

        db_api.cluster_policy_detach(self.ctx, self.cluster.id, policy.id)
        db_api.policy_delete(self.ctx, policy.id)
        policy = db_api.policy_get(self.ctx, policy.id)
        self.assertIsNone(policy)
Beispiel #15
0
    def test_cluster_delete_policies_deleted(self):
        # create cluster
        cluster = shared.create_cluster(self.ctx, self.profile)
        cluster_id = cluster.id

        # create policy
        policy_data = {
            'name': 'test_policy',
            'type': 'ScalingPolicy',
            'user': self.ctx.user,
            'project': self.ctx.project,
            'spec': {'foo': 'bar'},
            'level': 50,
            'cooldown': 60,
            'data': None,
        }
        policy = db_api.policy_create(self.ctx, policy_data)
        self.assertIsNotNone(policy)

        # attach policy
        fields = {
            'enabled': True,
            'priority': 77,
        }
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy.id, fields)
        binding = db_api.cluster_policy_get(self.ctx, cluster_id, policy.id)
        self.assertIsNotNone(binding)

        # now we delete the cluster
        db_api.cluster_delete(self.ctx, cluster_id)

        res = db_api.cluster_get(self.ctx, cluster_id)
        self.assertIsNone(res)

        # we check the cluster-policy binding
        binding = db_api.cluster_policy_get(self.ctx, cluster_id, policy.id)
        self.assertIsNone(binding)

        # but the policy is not deleted
        result = db_api.policy_get(self.ctx, policy.id)
        self.assertIsNotNone(result)
Beispiel #16
0
    def test_cluster_delete_policies_deleted(self):
        # create cluster
        cluster = shared.create_cluster(self.ctx, self.profile)
        cluster_id = cluster.id

        # create policy
        policy_data = {
            'name': 'test_policy',
            'type': 'ScalingPolicy',
            'user': self.ctx.user_id,
            'project': self.ctx.project_id,
            'spec': {
                'foo': 'bar'
            },
            'data': None,
        }
        policy = db_api.policy_create(self.ctx, policy_data)
        self.assertIsNotNone(policy)

        # attach policy
        fields = {
            'enabled': True,
        }
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy.id, fields)
        binding = db_api.cluster_policy_get(self.ctx, cluster_id, policy.id)
        self.assertIsNotNone(binding)

        # now we delete the cluster
        db_api.cluster_delete(self.ctx, cluster_id)

        res = db_api.cluster_get(self.ctx, cluster_id)
        self.assertIsNone(res)

        # we check the cluster-policy binding
        binding = db_api.cluster_policy_get(self.ctx, cluster_id, policy.id)
        self.assertIsNone(binding)

        # but the policy is not deleted
        result = db_api.policy_get(self.ctx, policy.id)
        self.assertIsNotNone(result)
Beispiel #17
0
 def test_policy_get_not_found(self):
     retobj = db_api.policy_get(self.ctx, 'BogusID')
     self.assertIsNone(retobj)
Beispiel #18
0
 def test_policy_get_not_found(self):
     retobj = db_api.policy_get(self.ctx, 'BogusID')
     self.assertIsNone(retobj)