def load(cls, context, cluster_id, policy_id): '''Retrieve a cluster-policy binding from database.''' binding = cpo.ClusterPolicy.get(context, cluster_id, policy_id) if binding is None: raise exception.PolicyNotAttached(policy=policy_id, cluster=cluster_id) return cls._from_object(context, binding)
def load(cls, context, cluster_id, policy_id): '''Retrieve a cluster-policy binding from database.''' binding = db_api.cluster_policy_get(context, cluster_id, policy_id) if binding is None: raise exception.PolicyNotAttached(policy=policy_id, cluster=cluster_id) return cls._from_db_record(context, binding)
def test_cluster_policy_get_binding_not_found(self, mock_load, mock_policy, mock_cluster): mock_cluster.return_value = mock.Mock(id='FAKE_CLUSTER') mock_policy.return_value = mock.Mock(id='FAKE_POLICY') err = exc.PolicyNotAttached(policy='POLICY', cluster='CLUSTER') mock_load.side_effect = err ex = self.assertRaises(rpc.ExpectedException, self.eng.cluster_policy_get, self.ctx, 'CLUSTER', 'POLICY') self.assertEqual(exc.PolicyBindingNotFound, ex.exc_info[0]) self.assertEqual( "The policy (POLICY) is not found attached to " "the specified cluster (CLUSTER).", six.text_type(ex.exc_info[1]))