Ejemplo n.º 1
0
    def test_cluster_policy_detach(self, notify):
        cluster_id = self.cluster['id']
        policy_id = self.policy['id']

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.cluster_policy_detach, self.ctx,
                               self.cluster['id'], self.policy['id'])
        self.assertEqual(exception.PolicyBindingNotFound, ex.exc_info[0])
        self.assertEqual(
            ("The policy (%(policy)s) is not found attached to "
             "the specified cluster (%(cluster)s)." %
             dict(policy=self.policy['id'], cluster=self.cluster['id'])),
            six.text_type(ex.exc_info[1]))

        values = {'priority': 50, 'level': 50, 'cooldown': 0, 'enabled': True}
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy_id, values)
        action = self.eng.cluster_policy_detach(self.ctx, cluster_id,
                                                policy_id)

        action_id = action['action']
        action = db_api.action_get(self.ctx, action_id)
        self.assertIsNotNone(action)
        self._verify_action(action,
                            'CLUSTER_DETACH_POLICY',
                            'detach_policy_%s' % cluster_id[:8],
                            cluster_id,
                            cause=action_mod.CAUSE_RPC,
                            inputs={'policy_id': policy_id})
        notify.assert_called_with(action_id=action_id)

        # called twice: attach and detach
        self.assertEqual(1, notify.call_count)
Ejemplo n.º 2
0
    def test_cluster_policy_update(self, notify):
        cluster_id = self.cluster['id']
        policy_id = self.policy['id']
        values = {
            'priority': 50,
            'level': 50,
            'cooldown': 0,
            'enabled': True
        }
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy_id, values)

        action = self.eng.cluster_policy_update(
            self.ctx, cluster_id, policy_id,
            priority=100, level=10, cooldown=60, enabled=False)

        action_id = action['action']
        action = db_api.action_get(self.ctx, action_id)
        self.assertIsNotNone(action)
        self._verify_action(action, 'CLUSTER_UPDATE_POLICY',
                            'update_policy_%s' % cluster_id[:8],
                            cluster_id, cause=action_mod.CAUSE_RPC,
                            inputs={
                                'policy_id': policy_id,
                                'priority': 100,
                                'level': 10,
                                'cooldown': 60,
                                'enabled': False})
        notify.assert_called_once_with(action_id=action_id)
Ejemplo n.º 3
0
    def test_cluster_policy_update(self, notify):
        cluster_id = self.cluster['id']
        policy_id = self.policy['id']
        values = {'priority': 50, 'level': 50, 'cooldown': 0, 'enabled': True}
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy_id, values)

        action = self.eng.cluster_policy_update(self.ctx,
                                                cluster_id,
                                                policy_id,
                                                priority=100,
                                                level=10,
                                                cooldown=60,
                                                enabled=False)

        action_id = action['action']
        action = db_api.action_get(self.ctx, action_id)
        self.assertIsNotNone(action)
        self._verify_action(action,
                            'CLUSTER_UPDATE_POLICY',
                            'update_policy_%s' % cluster_id[:8],
                            cluster_id,
                            cause=action_mod.CAUSE_RPC,
                            inputs={
                                'policy_id': policy_id,
                                'priority': 100,
                                'level': 10,
                                'cooldown': 60,
                                'enabled': False
                            })
        notify.assert_called_once_with(action_id=action_id)
Ejemplo n.º 4
0
    def test_cluster_policy_detach(self, notify):
        cluster_id = self.cluster['id']
        policy_id = self.policy['id']

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.cluster_policy_detach,
                               self.ctx, self.cluster['id'], self.policy['id'])
        self.assertEqual(exception.PolicyBindingNotFound, ex.exc_info[0])
        self.assertEqual(("The policy (%(policy)s) is not found attached to "
                          "the specified cluster (%(cluster)s)." %
                          dict(policy=self.policy['id'],
                               cluster=self.cluster['id'])),
                         six.text_type(ex.exc_info[1]))

        values = {
            'priority': 50,
            'level': 50,
            'cooldown': 0,
            'enabled': True
        }
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy_id, values)
        action = self.eng.cluster_policy_detach(self.ctx, cluster_id,
                                                policy_id)

        action_id = action['action']
        action = db_api.action_get(self.ctx, action_id)
        self.assertIsNotNone(action)
        self._verify_action(action, 'CLUSTER_DETACH_POLICY',
                            'detach_policy_%s' % cluster_id[:8],
                            cluster_id, cause=action_mod.CAUSE_RPC,
                            inputs={'policy_id': policy_id})
        notify.assert_called_with(action_id=action_id)

        # called twice: attach and detach
        self.assertEqual(1, notify.call_count)
Ejemplo n.º 5
0
    def test_cluster_delete_policy_attached(self, notify):
        c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
        cid = c['id']
        db_api.cluster_policy_attach(self.ctx, cid, self.policy['id'], {})

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.cluster_delete, self.ctx, cid)
        self.assertEqual(exception.SenlinBadRequest, ex.exc_info[0])
        self.assertEqual(_('The request is malformed: Cluster %(id)s is not '
                           'allowed to be deleted without detaching all '
                           'policies.') % {'id': cid},
                         six.text_type(ex.exc_info[1]))
Ejemplo n.º 6
0
    def test_cluster_delete_policy_attached(self, notify):
        c = self.eng.cluster_create(self.ctx, 'c-1', 0, self.profile['id'])
        cid = c['id']
        db_api.cluster_policy_attach(self.ctx, cid, self.policy['id'], {})

        ex = self.assertRaises(rpc.ExpectedException, self.eng.cluster_delete,
                               self.ctx, cid)
        self.assertEqual(exception.SenlinBadRequest, ex.exc_info[0])
        self.assertEqual(
            _('The request is malformed: Cluster %(id)s is not '
              'allowed to be deleted without detaching all '
              'policies.') % {'id': cid}, six.text_type(ex.exc_info[1]))
Ejemplo n.º 7
0
    def test_cluster_policy_list_default_sort(self):
        cluster_id = self.cluster['id']
        policy1 = self._prepare_policy('p-1', 'Type1')
        policy2 = self._prepare_policy('p-2', 'Type2')

        v = {'priority': 50}
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy1['id'], v)
        v = {'priority': 40}
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy2['id'], v)

        result = self.eng.cluster_policy_list(self.ctx, cluster_id)
        policy_ids = [b['policy_id'] for b in result]
        self.assertEqual(policy1['id'], policy_ids[0])
        self.assertEqual(policy2['id'], policy_ids[1])
Ejemplo n.º 8
0
    def test_cluster_policy_list_default_sort(self):
        cluster_id = self.cluster['id']
        policy1 = self._prepare_policy('p-1', 'Type1')
        policy2 = self._prepare_policy('p-2', 'Type2')

        v = {'priority': 50}
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy1['id'], v)
        v = {'priority': 40}
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy2['id'], v)

        result = self.eng.cluster_policy_list(self.ctx, cluster_id)
        policy_ids = [b['policy_id'] for b in result]
        self.assertEqual(policy1['id'], policy_ids[0])
        self.assertEqual(policy2['id'], policy_ids[1])
Ejemplo n.º 9
0
    def test_cluster_policy_list(self):
        cluster_id = self.cluster['id']
        policy1 = self._prepare_policy('p-1', 'Type1')
        policy2 = self._prepare_policy('p-2', 'Type2')
        v = {'priority': 50, 'level': 50, 'cooldown': 0, 'enabled': True}
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy1['id'], v)
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy2['id'], v)

        result = self.eng.cluster_policy_list(self.ctx, cluster_id)
        self.assertIsInstance(result, list)
        self.assertEqual(2, len(result))
        policy_ids = [b['policy_id'] for b in result]
        self.assertIn(policy1['id'], policy_ids)
        self.assertIn(policy2['id'], policy_ids)
Ejemplo n.º 10
0
    def test_cluster_policy_update_parameter_invalid(self):
        cluster_id = self.cluster['id']
        policy_id = self.policy['id']
        values = {'priority': 50, 'level': 50, 'cooldown': 0, 'enabled': True}
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy_id, values)

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.cluster_policy_update,
                               self.ctx,
                               cluster_id,
                               policy_id,
                               priority='High')

        self.assertEqual(exception.InvalidParameter, ex.exc_info[0])
        self.assertEqual("Invalid value 'High' specified for 'priority'",
                         six.text_type(ex.exc_info[1]))

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.cluster_policy_update,
                               self.ctx,
                               cluster_id,
                               policy_id,
                               cooldown='Long')

        self.assertEqual(exception.InvalidParameter, ex.exc_info[0])
        self.assertEqual("Invalid value 'Long' specified for 'cooldown'",
                         six.text_type(ex.exc_info[1]))

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.cluster_policy_update,
                               self.ctx,
                               cluster_id,
                               policy_id,
                               level='Warning')

        self.assertEqual(exception.InvalidParameter, ex.exc_info[0])
        self.assertEqual("Invalid value 'Warning' specified for 'level'",
                         six.text_type(ex.exc_info[1]))

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.cluster_policy_update,
                               self.ctx,
                               cluster_id,
                               policy_id,
                               enabled='No')

        self.assertEqual(exception.InvalidParameter, ex.exc_info[0])
        self.assertEqual("Invalid value 'No' specified for 'enabled'",
                         six.text_type(ex.exc_info[1]))
Ejemplo n.º 11
0
    def test_cluster_policy_get(self):
        cluster_id = self.cluster['id']
        policy_id = self.policy['id']
        values = {'priority': 50, 'level': 50, 'cooldown': 0, 'enabled': True}
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy_id, values)

        result = self.eng.cluster_policy_get(self.ctx, cluster_id, policy_id)
        self.assertEqual(cluster_id, result['cluster_id'])
        self.assertEqual(policy_id, result['policy_id'])
        self.assertEqual(self.cluster['name'], result['cluster_name'])
        self.assertEqual(self.policy['type'], result['policy_type'])
        self.assertEqual(self.policy['name'], result['policy_name'])
        self.assertEqual(50, result['priority'])
        self.assertEqual(50, result['level'])
        self.assertEqual(0, result['cooldown'])
        self.assertTrue(result['enabled'])
Ejemplo n.º 12
0
    def test_cluster_policy_update_parameter_invalid(self):
        cluster_id = self.cluster['id']
        policy_id = self.policy['id']
        values = {
            'priority': 50,
            'level': 50,
            'cooldown': 0,
            'enabled': True
        }
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy_id, values)

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.cluster_policy_update,
                               self.ctx, cluster_id, policy_id,
                               priority='High')

        self.assertEqual(exception.InvalidParameter, ex.exc_info[0])
        self.assertEqual("Invalid value 'High' specified for 'priority'",
                         six.text_type(ex.exc_info[1]))

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.cluster_policy_update,
                               self.ctx, cluster_id, policy_id,
                               cooldown='Long')

        self.assertEqual(exception.InvalidParameter, ex.exc_info[0])
        self.assertEqual("Invalid value 'Long' specified for 'cooldown'",
                         six.text_type(ex.exc_info[1]))

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.cluster_policy_update,
                               self.ctx, cluster_id, policy_id,
                               level='Warning')

        self.assertEqual(exception.InvalidParameter, ex.exc_info[0])
        self.assertEqual("Invalid value 'Warning' specified for 'level'",
                         six.text_type(ex.exc_info[1]))

        ex = self.assertRaises(rpc.ExpectedException,
                               self.eng.cluster_policy_update,
                               self.ctx, cluster_id, policy_id,
                               enabled='No')

        self.assertEqual(exception.InvalidParameter, ex.exc_info[0])
        self.assertEqual("Invalid value 'No' specified for 'enabled'",
                         six.text_type(ex.exc_info[1]))
Ejemplo n.º 13
0
    def test_cluster_policy_list(self):
        cluster_id = self.cluster['id']
        policy1 = self._prepare_policy('p-1', 'Type1')
        policy2 = self._prepare_policy('p-2', 'Type2')
        v = {
            'priority': 50,
            'level': 50,
            'cooldown': 0,
            'enabled': True
        }
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy1['id'], v)
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy2['id'], v)

        result = self.eng.cluster_policy_list(self.ctx, cluster_id)
        self.assertIsInstance(result, list)
        self.assertEqual(2, len(result))
        policy_ids = [b['policy_id'] for b in result]
        self.assertIn(policy1['id'], policy_ids)
        self.assertIn(policy2['id'], policy_ids)
Ejemplo n.º 14
0
    def test_cluster_policy_get(self):
        cluster_id = self.cluster['id']
        policy_id = self.policy['id']
        values = {
            'priority': 50,
            'level': 50,
            'cooldown': 0,
            'enabled': True
        }
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy_id, values)

        result = self.eng.cluster_policy_get(self.ctx, cluster_id, policy_id)
        self.assertEqual(cluster_id, result['cluster_id'])
        self.assertEqual(policy_id, result['policy_id'])
        self.assertEqual(self.cluster['name'], result['cluster_name'])
        self.assertEqual(self.policy['type'], result['policy_type'])
        self.assertEqual(self.policy['name'], result['policy_name'])
        self.assertEqual(50, result['priority'])
        self.assertEqual(50, result['level'])
        self.assertEqual(0, result['cooldown'])
        self.assertTrue(result['enabled'])
Ejemplo n.º 15
0
    def do_attach_policy(self, cluster, policy_data):
        '''Attach policy to the cluster.
        '''
        policy_id = self.inputs.get('policy_id', None)
        if not policy_id:
            raise exception.PolicyNotSpecified()

        policy = policy_mod.Policy.load(self.context, policy_id)
        # Check if policy has already been attached
        all = db_api.cluster_policy_get_all(self.context, cluster.id)
        for existing in all:
            # Policy already attached
            if existing.policy_id == policy_id:
                return self.RES_OK, 'Policy already attached'

            # Detect policy type conflicts
            curr = policy_mod.Policy.load(self.context, existing.policy_id)
            if curr.type == policy.type:
                raise exception.PolicyExists(policy_type=policy.type)

        res = policy.attach(self.context, cluster, policy_data)
        if not res:
            return self.RES_ERROR, 'Failed attaching policy'

        values = {
            'cooldown': self.inputs.get('cooldown', policy.cooldown),
            'level': self.inputs.get('level', policy.level),
            'priority': self.inputs.get('priority', 50),
            'enabled': self.inputs.get('enabled', True),
        }

        db_api.cluster_policy_attach(self.context, cluster.id, policy_id,
                                     values)

        cluster.attach(policy)
        return self.RES_OK, 'Policy attached'
Ejemplo n.º 16
0
    def test_cluster_policy_list_sort_keys_and_dir(self):
        cluster_id = self.cluster['id']
        policy1 = self._prepare_policy('p-1', 'Type1')
        policy2 = self._prepare_policy('p-2', 'Type2')
        policy3 = self._prepare_policy('p-3', 'Type3')

        v = {'priority': 50, 'level': 30, 'cooldown': 60, 'enabled': True}
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy1['id'], v)
        v = {'priority': 40, 'level': 40, 'cooldown': 60, 'enabled': False}
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy2['id'], v)
        v = {'priority': 30, 'level': 40, 'cooldown': 0, 'enabled': False}
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy3['id'], v)

        # sort by level
        result = self.eng.cluster_policy_list(self.ctx,
                                              cluster_id,
                                              sort_keys=['level'])
        policy_ids = [b['policy_id'] for b in result]
        self.assertIn(policy1['id'], policy_ids[0])

        # sort by cooldown
        result = self.eng.cluster_policy_list(self.ctx,
                                              cluster_id,
                                              sort_keys=['cooldown'])
        policy_ids = [b['policy_id'] for b in result]
        self.assertIn(policy3['id'], policy_ids[0])

        # sort by enabled
        result = self.eng.cluster_policy_list(self.ctx,
                                              cluster_id,
                                              sort_keys=['enabled'])
        policy_ids = [b['policy_id'] for b in result]
        self.assertIn(policy1['id'], policy_ids[2])

        # sort by cooldown and enabled
        result = self.eng.cluster_policy_list(
            self.ctx, cluster_id, sort_keys=['cooldown', 'enabled'])
        policy_ids = [b['policy_id'] for b in result]
        self.assertIn(policy3['id'], policy_ids[0])
        self.assertIn(policy2['id'], policy_ids[1])
        self.assertIn(policy1['id'], policy_ids[2])

        # sort by cooldown and level, descending
        result = self.eng.cluster_policy_list(self.ctx,
                                              cluster_id,
                                              sort_keys=['cooldown', 'level'],
                                              sort_dir='desc')
        policy_ids = [b['policy_id'] for b in result]
        self.assertIn(policy2['id'], policy_ids[0])
        self.assertIn(policy1['id'], policy_ids[1])
        self.assertIn(policy3['id'], policy_ids[2])
Ejemplo n.º 17
0
    def store(self, context):
        '''Store the binding record into database table.'''
        values = {
            'enabled': self.enabled,
            'data': self.data,
            'last_op': self.last_op,
            'priority': self.priority
        }

        if self.id:
            db_api.cluster_policy_update(context, self.cluster_id,
                                         self.policy_id, values)
        else:
            binding = db_api.cluster_policy_attach(context, self.cluster_id,
                                                   self.policy_id, values)
            self.cluster_name = binding.cluster.name
            self.policy_name = binding.policy.name
            self.policy_type = binding.policy.type
            self.id = binding.id

        return self.id
Ejemplo n.º 18
0
    def test_cluster_policy_list_sort_keys_and_dir(self):
        cluster_id = self.cluster['id']
        policy1 = self._prepare_policy('p-1', 'Type1')
        policy2 = self._prepare_policy('p-2', 'Type2')
        policy3 = self._prepare_policy('p-3', 'Type3')

        v = {'priority': 50, 'level': 30, 'cooldown': 60, 'enabled': True}
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy1['id'], v)
        v = {'priority': 40, 'level': 40, 'cooldown': 60, 'enabled': False}
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy2['id'], v)
        v = {'priority': 30, 'level': 40, 'cooldown': 0, 'enabled': False}
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy3['id'], v)

        # sort by level
        result = self.eng.cluster_policy_list(self.ctx, cluster_id,
                                              sort_keys=['level'])
        policy_ids = [b['policy_id'] for b in result]
        self.assertIn(policy1['id'], policy_ids[0])

        # sort by cooldown
        result = self.eng.cluster_policy_list(self.ctx, cluster_id,
                                              sort_keys=['cooldown'])
        policy_ids = [b['policy_id'] for b in result]
        self.assertIn(policy3['id'], policy_ids[0])

        # sort by enabled
        result = self.eng.cluster_policy_list(self.ctx, cluster_id,
                                              sort_keys=['enabled'])
        policy_ids = [b['policy_id'] for b in result]
        self.assertIn(policy1['id'], policy_ids[2])

        # sort by cooldown and enabled
        result = self.eng.cluster_policy_list(
            self.ctx, cluster_id, sort_keys=['cooldown', 'enabled'])
        policy_ids = [b['policy_id'] for b in result]
        self.assertIn(policy3['id'], policy_ids[0])
        self.assertIn(policy2['id'], policy_ids[1])
        self.assertIn(policy1['id'], policy_ids[2])

        # sort by cooldown and level, descending
        result = self.eng.cluster_policy_list(
            self.ctx, cluster_id, sort_keys=['cooldown', 'level'],
            sort_dir='desc')
        policy_ids = [b['policy_id'] for b in result]
        self.assertIn(policy2['id'], policy_ids[0])
        self.assertIn(policy1['id'], policy_ids[1])
        self.assertIn(policy3['id'], policy_ids[2])
Ejemplo n.º 19
0
    def test_cluster_policy_list_filters(self):
        cluster_id = self.cluster['id']
        policy1 = self._prepare_policy('p-1', 'Type1')
        policy2 = self._prepare_policy('p-2', 'Type2')
        policy3 = self._prepare_policy('p-3', 'Type3')

        v = {'priority': 50, 'level': 30, 'cooldown': 60, 'enabled': True}
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy1['id'], v)
        v = {'priority': 40, 'level': 40, 'cooldown': 60, 'enabled': False}
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy2['id'], v)
        v = {'priority': 40, 'level': 40, 'cooldown': 0, 'enabled': False}
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy3['id'], v)

        # filter by priority
        result = self.eng.cluster_policy_list(self.ctx,
                                              cluster_id,
                                              filters={'priority': 40})
        policy_ids = [b['policy_id'] for b in result]
        self.assertEqual(2, len(policy_ids))
        self.assertIn(policy2['id'], policy_ids)
        self.assertIn(policy3['id'], policy_ids)

        # filter by level
        result = self.eng.cluster_policy_list(self.ctx,
                                              cluster_id,
                                              filters={'level': 30})
        policy_ids = [b['policy_id'] for b in result]
        self.assertEqual(1, len(policy_ids))
        self.assertIn(policy1['id'], policy_ids)

        # filter by cooldown
        result = self.eng.cluster_policy_list(self.ctx,
                                              cluster_id,
                                              filters={'cooldown': 60})
        policy_ids = [b['policy_id'] for b in result]
        self.assertEqual(2, len(policy_ids))
        self.assertIn(policy1['id'], policy_ids)
        self.assertIn(policy2['id'], policy_ids)

        # filter by enabled
        result = self.eng.cluster_policy_list(self.ctx,
                                              cluster_id,
                                              filters={'enabled': True})
        policy_ids = [b['policy_id'] for b in result]
        self.assertEqual(1, len(policy_ids))
        self.assertIn(policy1['id'], policy_ids)
Ejemplo n.º 20
0
    def test_cluster_policy_list_filters(self):
        cluster_id = self.cluster['id']
        policy1 = self._prepare_policy('p-1', 'Type1')
        policy2 = self._prepare_policy('p-2', 'Type2')
        policy3 = self._prepare_policy('p-3', 'Type3')

        v = {'priority': 50, 'level': 30, 'cooldown': 60, 'enabled': True}
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy1['id'], v)
        v = {'priority': 40, 'level': 40, 'cooldown': 60, 'enabled': False}
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy2['id'], v)
        v = {'priority': 40, 'level': 40, 'cooldown': 0, 'enabled': False}
        db_api.cluster_policy_attach(self.ctx, cluster_id, policy3['id'], v)

        # filter by priority
        result = self.eng.cluster_policy_list(self.ctx, cluster_id,
                                              filters={'priority': 40})
        policy_ids = [b['policy_id'] for b in result]
        self.assertEqual(2, len(policy_ids))
        self.assertIn(policy2['id'], policy_ids)
        self.assertIn(policy3['id'], policy_ids)

        # filter by level
        result = self.eng.cluster_policy_list(self.ctx, cluster_id,
                                              filters={'level': 30})
        policy_ids = [b['policy_id'] for b in result]
        self.assertEqual(1, len(policy_ids))
        self.assertIn(policy1['id'], policy_ids)

        # filter by cooldown
        result = self.eng.cluster_policy_list(self.ctx, cluster_id,
                                              filters={'cooldown': 60})
        policy_ids = [b['policy_id'] for b in result]
        self.assertEqual(2, len(policy_ids))
        self.assertIn(policy1['id'], policy_ids)
        self.assertIn(policy2['id'], policy_ids)

        # filter by enabled
        result = self.eng.cluster_policy_list(self.ctx, cluster_id,
                                              filters={'enabled': True})
        policy_ids = [b['policy_id'] for b in result]
        self.assertEqual(1, len(policy_ids))
        self.assertIn(policy1['id'], policy_ids)
Ejemplo n.º 21
0
 def create(cls, context, cluster_id, policy_id, values):
     obj = db_api.cluster_policy_attach(context, cluster_id, policy_id,
                                        values)
     return cls._from_db_object(context, cls(context), obj)
Ejemplo n.º 22
0
 def create(cls, context, cluster_id, policy_id, values):
     obj = db_api.cluster_policy_attach(context, cluster_id, policy_id,
                                        values)
     return cls._from_db_object(context, cls(context), obj)