Example #1
0
    def test_cluster_policy_store(self):
        cluster = self._create_cluster('fake-cluster')
        policy = self._create_policy('fake-policy')
        values = {
            'priority': 12,
            'cooldown': 34,
            'level': 56,
            'enabled': True,
        }
        cp = cpm.ClusterPolicy(cluster.id, policy.id, **values)
        self.assertIsNone(cp.id)
        cp_id = cp.store(self.context)
        self.assertIsNotNone(cp_id)

        result = db_api.cluster_policy_get(self.context, 'fake-cluster',
                                           'fake-policy')

        self.assertIsNotNone(result)
        self.assertEqual(12, result.priority)
        self.assertEqual(34, result.cooldown)
        self.assertEqual(56, result.level)
        self.assertTrue(result.enabled)
        self.assertEqual({}, result.data)
        self.assertIsNone(result.last_op)

        # do an update
        cp.cooldown = 60
        cp.priority = 60
        cp.level = 40
        cp.enabled = False
        cp.data = {'foo': 'bar'}
        timestamp = timeutils.utcnow()
        cp.last_op = timestamp

        new_id = cp.store(self.context)
        self.assertEqual(cp_id, new_id)

        result = db_api.cluster_policy_get(self.context, 'fake-cluster',
                                           'fake-policy')

        self.assertIsNotNone(result)
        self.assertEqual(60, result.cooldown)
        self.assertEqual(60, result.priority)
        self.assertEqual(40, result.level)
        self.assertFalse(result.enabled)
        self.assertEqual({'foo': 'bar'}, result.data)
        self.assertEqual(timestamp, result.last_op)
    def test_cluster_policy_get(self):
        policy = self.create_policy()

        db_api.cluster_policy_attach(self.ctx, self.cluster.id, policy.id, {})

        binding = db_api.cluster_policy_get(self.ctx, self.cluster.id,
                                            policy.id)
        self.assertIsNotNone(binding)
        self.assertEqual(self.cluster.id, binding.cluster_id)
        self.assertEqual(policy.id, binding.policy_id)
Example #3
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)
Example #4
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)