Add support a user admin can do everything
A user with role admin can delete, update cluster, policy, ... and attach, detach a policy to a cluster and see policy biding in a cluster Change-Id: Id014484697ab932ea01c47f8054055f3c626be79
This commit is contained in:
parent
7fa6ae780c
commit
54edddbf58
|
@ -78,6 +78,7 @@ class ConductorService(service.Service):
|
|||
- Arguments to these calls are added dynamically and will be treated as
|
||||
keyword arguments by the RPC client.
|
||||
"""
|
||||
|
||||
def __init__(self, host, topic):
|
||||
super(ConductorService, self).__init__(
|
||||
self.service_name, host, topic,
|
||||
|
@ -2276,8 +2277,7 @@ class ConductorService(service.Service):
|
|||
"""
|
||||
# Only allow cancellation of actions at this time.
|
||||
if req.status == consts.ACTION_CANCELLED:
|
||||
action = action_mod.Action.load(ctx, req.identity,
|
||||
project_safe=False)
|
||||
action = action_mod.Action.load(ctx, req.identity)
|
||||
if req.force:
|
||||
action.force_cancel()
|
||||
else:
|
||||
|
@ -2400,11 +2400,7 @@ class ConductorService(service.Service):
|
|||
"""
|
||||
# NOTE: Temporary code to make tempest tests about webhook_trigger
|
||||
# pass, will remove in latter patches.
|
||||
kwargs = {}
|
||||
if ctx.is_admin is True:
|
||||
kwargs['project_safe'] = False
|
||||
|
||||
receiver = receiver_obj.Receiver.find(ctx, req.identity, **kwargs)
|
||||
receiver = receiver_obj.Receiver.find(ctx, req.identity)
|
||||
return receiver.to_dict()
|
||||
|
||||
@request_context
|
||||
|
@ -2473,9 +2469,7 @@ class ConductorService(service.Service):
|
|||
raise exception.BadRequest(msg=msg)
|
||||
|
||||
LOG.info("Received notification to receiver %s.", req.identity)
|
||||
receiver = receiver_mod.Receiver.load(ctx,
|
||||
receiver_obj=db_receiver,
|
||||
project_safe=True)
|
||||
receiver = receiver_mod.Receiver.load(ctx, receiver_obj=db_receiver)
|
||||
receiver.notify(ctx)
|
||||
|
||||
@request_context
|
||||
|
|
|
@ -225,7 +225,7 @@ class Action(object):
|
|||
return ActionClass(obj.target, obj.action, ctx, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def load(cls, ctx, action_id=None, db_action=None, project_safe=True):
|
||||
def load(cls, ctx, action_id=None, db_action=None):
|
||||
"""Retrieve an action from database.
|
||||
|
||||
:param ctx: Instance of request context.
|
||||
|
@ -233,6 +233,7 @@ class Action(object):
|
|||
:param db_action: An action object for the action to deserialize.
|
||||
:return: A `Action` object instance.
|
||||
"""
|
||||
project_safe = not ctx.is_admin
|
||||
if db_action is None:
|
||||
db_action = ao.Action.get(ctx, action_id,
|
||||
project_safe=project_safe)
|
||||
|
@ -654,7 +655,7 @@ def ActionProc(ctx, action_id):
|
|||
"""Action process."""
|
||||
|
||||
# Step 1: materialize the action object
|
||||
action = Action.load(ctx, action_id=action_id, project_safe=False)
|
||||
action = Action.load(ctx, action_id=action_id)
|
||||
if action is None:
|
||||
LOG.error('Action "%s" could not be found.', action_id)
|
||||
return False
|
||||
|
|
|
@ -92,13 +92,12 @@ class Cluster(object):
|
|||
bindings = cpo.ClusterPolicy.get_all(context, self.id)
|
||||
for b in bindings:
|
||||
# Detect policy type conflicts
|
||||
policy = pcb.Policy.load(context, b.policy_id, project_safe=False)
|
||||
policy = pcb.Policy.load(context, b.policy_id)
|
||||
policies.append(policy)
|
||||
|
||||
self.rt = {
|
||||
'profile': pfb.Profile.load(context,
|
||||
profile_id=self.profile_id,
|
||||
project_safe=False),
|
||||
profile_id=self.profile_id),
|
||||
'nodes': no.Node.get_all_by_cluster(context, self.id),
|
||||
'policies': policies
|
||||
}
|
||||
|
@ -175,8 +174,9 @@ class Cluster(object):
|
|||
context=context, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def load(cls, context, cluster_id=None, dbcluster=None, project_safe=True):
|
||||
def load(cls, context, cluster_id=None, dbcluster=None):
|
||||
"""Retrieve a cluster from database."""
|
||||
project_safe = not context.is_admin
|
||||
if dbcluster is None:
|
||||
dbcluster = co.Cluster.get(context, cluster_id,
|
||||
project_safe=project_safe)
|
||||
|
@ -187,9 +187,10 @@ class Cluster(object):
|
|||
|
||||
@classmethod
|
||||
def load_all(cls, context, limit=None, marker=None, sort=None,
|
||||
filters=None, project_safe=True):
|
||||
filters=None):
|
||||
"""Retrieve all clusters from database."""
|
||||
|
||||
project_safe = not context.is_admin
|
||||
objs = co.Cluster.get_all(context, limit=limit, marker=marker,
|
||||
sort=sort, filters=filters,
|
||||
project_safe=project_safe)
|
||||
|
|
|
@ -77,8 +77,7 @@ class Node(object):
|
|||
def _load_runtime_data(self, context):
|
||||
profile = None
|
||||
try:
|
||||
profile = pb.Profile.load(context, profile_id=self.profile_id,
|
||||
project_safe=False)
|
||||
profile = pb.Profile.load(context, profile_id=self.profile_id)
|
||||
except exc.ResourceNotFound:
|
||||
LOG.debug('Profile not found: %s', self.profile_id)
|
||||
|
||||
|
@ -156,8 +155,9 @@ class Node(object):
|
|||
context=context, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def load(cls, context, node_id=None, db_node=None, project_safe=True):
|
||||
def load(cls, context, node_id=None, db_node=None):
|
||||
"""Retrieve a node from database."""
|
||||
project_safe = not context.is_admin
|
||||
if db_node is None:
|
||||
db_node = no.Node.get(context, node_id, project_safe=project_safe)
|
||||
if db_node is None:
|
||||
|
@ -167,8 +167,9 @@ class Node(object):
|
|||
|
||||
@classmethod
|
||||
def load_all(cls, context, cluster_id=None, limit=None, marker=None,
|
||||
sort=None, filters=None, project_safe=True):
|
||||
sort=None, filters=None):
|
||||
"""Retrieve all nodes of from database."""
|
||||
project_safe = not context.is_admin
|
||||
objs = no.Node.get_all(context, cluster_id=cluster_id,
|
||||
filters=filters, sort=sort,
|
||||
limit=limit, marker=marker,
|
||||
|
|
|
@ -150,8 +150,7 @@ class Receiver(object):
|
|||
**kwargs)
|
||||
|
||||
@classmethod
|
||||
def load(cls, context, receiver_id=None, receiver_obj=None,
|
||||
project_safe=True):
|
||||
def load(cls, context, receiver_id=None, receiver_obj=None):
|
||||
"""Retrieve a receiver from database.
|
||||
|
||||
@param context: the context for db operations.
|
||||
|
@ -161,6 +160,7 @@ class Receiver(object):
|
|||
receiver belong to the context.project will be
|
||||
loaded.
|
||||
"""
|
||||
project_safe = not context.is_admin
|
||||
if receiver_obj is None:
|
||||
receiver_obj = ro.Receiver.get(context, receiver_id,
|
||||
project_safe=project_safe)
|
||||
|
|
|
@ -164,20 +164,17 @@ class EngineService(service.Service):
|
|||
|
||||
def cancel_action(self, ctxt, action_id):
|
||||
"""Cancel an action execution progress."""
|
||||
action = action_mod.Action.load(self.db_session, action_id,
|
||||
project_safe=False)
|
||||
action = action_mod.Action.load(self.db_session, action_id)
|
||||
action.signal(action.SIG_CANCEL)
|
||||
|
||||
def suspend_action(self, ctxt, action_id):
|
||||
"""Suspend an action execution progress."""
|
||||
action = action_mod.Action.load(self.db_session, action_id,
|
||||
project_safe=False)
|
||||
action = action_mod.Action.load(self.db_session, action_id)
|
||||
action.signal(action.SIG_SUSPEND)
|
||||
|
||||
def resume_action(self, ctxt, action_id):
|
||||
"""Resume an action execution progress."""
|
||||
action = action_mod.Action.load(self.db_session, action_id,
|
||||
project_safe=False)
|
||||
action = action_mod.Action.load(self.db_session, action_id)
|
||||
action.signal(action.SIG_RESUME)
|
||||
|
||||
|
||||
|
|
|
@ -68,6 +68,7 @@ class Action(base.SenlinObject, base.VersionedObjectDictCompat):
|
|||
:return: A DB object of action or an exception `ResourceNotFound` if
|
||||
no matching action is found.
|
||||
"""
|
||||
kwargs['project_safe'] = not context.is_admin
|
||||
if uuidutils.is_uuid_like(identity):
|
||||
action = cls.get(context, identity, **kwargs)
|
||||
if not action:
|
||||
|
|
|
@ -78,7 +78,8 @@ class Cluster(base.SenlinObject, base.VersionedObjectDictCompat):
|
|||
return cls._from_db_object(context, cls(), obj)
|
||||
|
||||
@classmethod
|
||||
def find(cls, context, identity, project_safe=True):
|
||||
def find(cls, context, identity):
|
||||
project_safe = not context.is_admin
|
||||
cluster = None
|
||||
if uuidutils.is_uuid_like(identity):
|
||||
cluster = cls.get(context, identity, project_safe=project_safe)
|
||||
|
|
|
@ -37,14 +37,17 @@ class ClusterPolicy(base.SenlinObject, base.VersionedObjectDictCompat):
|
|||
|
||||
@staticmethod
|
||||
def _from_db_object(context, binding, db_obj):
|
||||
kwargs = {'project_safe': not context.is_admin}
|
||||
if db_obj is None:
|
||||
return None
|
||||
for field in binding.fields:
|
||||
if field == 'cluster':
|
||||
c = cluster_obj.Cluster.get(context, db_obj['cluster_id'])
|
||||
c = cluster_obj.Cluster.get(
|
||||
context, db_obj['cluster_id'], **kwargs)
|
||||
binding['cluster'] = c
|
||||
elif field == 'policy':
|
||||
p = policy_obj.Policy.get(context, db_obj['policy_id'])
|
||||
p = policy_obj.Policy.get(
|
||||
context, db_obj['policy_id'], **kwargs)
|
||||
binding['policy'] = p
|
||||
else:
|
||||
binding[field] = db_obj[field]
|
||||
|
|
|
@ -55,6 +55,7 @@ class Event(base.SenlinObject, base.VersionedObjectDictCompat):
|
|||
|
||||
:return: A dictionary containing the details of the event.
|
||||
"""
|
||||
kwargs['project_safe'] = not context.is_admin
|
||||
event = None
|
||||
if uuidutils.is_uuid_like(identity):
|
||||
event = cls.get(context, identity, **kwargs)
|
||||
|
|
|
@ -83,7 +83,7 @@ class Node(base.SenlinObject, base.VersionedObjectDictCompat):
|
|||
return cls._from_db_object(context, cls(), obj)
|
||||
|
||||
@classmethod
|
||||
def find(cls, context, identity, project_safe=True):
|
||||
def find(cls, context, identity):
|
||||
"""Find a node with the given identity.
|
||||
|
||||
:param context: An instance of the request context.
|
||||
|
@ -96,6 +96,7 @@ class Node(base.SenlinObject, base.VersionedObjectDictCompat):
|
|||
or an exception of ``MultipleChoices`` more than one node
|
||||
found matching the criteria.
|
||||
"""
|
||||
project_safe = not context.is_admin
|
||||
node = None
|
||||
if uuidutils.is_uuid_like(identity):
|
||||
node = cls.get(context, identity, project_safe=project_safe)
|
||||
|
|
|
@ -57,6 +57,7 @@ class Policy(base.SenlinObject, base.VersionedObjectDictCompat):
|
|||
:return: A DB object of policy or an exception of `ResourceNotFound`
|
||||
if no matching object is found.
|
||||
"""
|
||||
kwargs['project_safe'] = not context.is_admin
|
||||
if uuidutils.is_uuid_like(identity):
|
||||
policy = cls.get(context, identity, **kwargs)
|
||||
if not policy:
|
||||
|
|
|
@ -57,6 +57,7 @@ class Profile(base.SenlinObject, base.VersionedObjectDictCompat):
|
|||
:return: A DB object of profile or an exception `ResourceNotFound`
|
||||
if no matching object is found.
|
||||
"""
|
||||
kwargs['project_safe'] = not context.is_admin
|
||||
if uuidutils.is_uuid_like(identity):
|
||||
profile = cls.get(context, identity, **kwargs)
|
||||
if not profile:
|
||||
|
|
|
@ -58,6 +58,7 @@ class Receiver(base.SenlinObject, base.VersionedObjectDictCompat):
|
|||
:return: A DB object of receiver or an exception `ResourceNotFound`
|
||||
if no matching receiver is found.
|
||||
"""
|
||||
kwargs['project_safe'] = not context.is_admin
|
||||
if uuidutils.is_uuid_like(identity):
|
||||
receiver = cls.get(context, identity, **kwargs)
|
||||
if not receiver:
|
||||
|
|
|
@ -142,7 +142,7 @@ class Policy(object):
|
|||
return cls(policy.name, policy.spec, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def load(cls, context, policy_id=None, db_policy=None, project_safe=True):
|
||||
def load(cls, context, policy_id=None, db_policy=None):
|
||||
"""Retrieve and reconstruct a policy object from DB.
|
||||
|
||||
:param context: DB context for object retrieval.
|
||||
|
@ -153,6 +153,7 @@ class Policy(object):
|
|||
loaded.
|
||||
:returns: An object of the proper policy class.
|
||||
"""
|
||||
project_safe = not context.is_admin
|
||||
if db_policy is None:
|
||||
db_policy = po.Policy.get(context, policy_id,
|
||||
project_safe=project_safe)
|
||||
|
|
|
@ -151,8 +151,9 @@ class Profile(object):
|
|||
return cls(profile.name, profile.spec, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def load(cls, ctx, profile=None, profile_id=None, project_safe=True):
|
||||
def load(cls, ctx, profile=None, profile_id=None):
|
||||
"""Retrieve a profile object from database."""
|
||||
project_safe = not ctx.is_admin
|
||||
if profile is None:
|
||||
profile = po.Profile.get(ctx, profile_id,
|
||||
project_safe=project_safe)
|
||||
|
|
|
@ -219,7 +219,7 @@ class ActionTest(base.SenlinTestCase):
|
|||
result = self.svc.action_update(self.ctx, req.obj_to_primitive())
|
||||
self.assertIsNone(result)
|
||||
|
||||
mock_load.assert_called_with(self.ctx, 'ACTION_ID', project_safe=False)
|
||||
mock_load.assert_called_with(self.ctx, 'ACTION_ID')
|
||||
x_obj.signal_cancel.assert_called_once_with()
|
||||
|
||||
@mock.patch.object(ab.Action, 'load')
|
||||
|
|
|
@ -389,8 +389,7 @@ class ReceiverTest(base.SenlinTestCase):
|
|||
|
||||
self.assertIsNone(result)
|
||||
mock_find.assert_called_once_with(self.ctx, 'FAKE_RECEIVER')
|
||||
mock_load.assert_called_once_with(self.ctx, receiver_obj=fake_obj,
|
||||
project_safe=True)
|
||||
mock_load.assert_called_once_with(self.ctx, receiver_obj=fake_obj)
|
||||
fake_receiver.notify.assert_called_once_with(self.ctx)
|
||||
|
||||
@mock.patch.object(ro.Receiver, 'find')
|
||||
|
|
|
@ -1152,8 +1152,7 @@ class ActionProcTest(base.SenlinTestCase):
|
|||
res = ab.ActionProc(self.ctx, 'ACTION_ID')
|
||||
|
||||
self.assertTrue(res)
|
||||
mock_load.assert_called_once_with(self.ctx, action_id='ACTION_ID',
|
||||
project_safe=False)
|
||||
mock_load.assert_called_once_with(self.ctx, action_id='ACTION_ID')
|
||||
mock_event_info.assert_called_once_with(action, 'start', 'ACTION_I')
|
||||
mock_status.assert_called_once_with(action.RES_OK, 'BIG SUCCESS')
|
||||
|
||||
|
@ -1173,8 +1172,7 @@ class ActionProcTest(base.SenlinTestCase):
|
|||
res = ab.ActionProc(self.ctx, 'ACTION')
|
||||
|
||||
self.assertFalse(res)
|
||||
mock_load.assert_called_once_with(self.ctx, action_id='ACTION',
|
||||
project_safe=False)
|
||||
mock_load.assert_called_once_with(self.ctx, action_id='ACTION')
|
||||
mock_info.assert_called_once_with(action, 'start', 'ACTION')
|
||||
mock_status.assert_called_once_with(action.RES_ERROR, 'Boom!')
|
||||
|
||||
|
@ -1193,8 +1191,7 @@ class ActionProcTest(base.SenlinTestCase):
|
|||
res = ab.ActionProc(self.ctx, 'ACTION')
|
||||
self.assertIs(True, res)
|
||||
|
||||
mock_load.assert_called_once_with(self.ctx, action_id='ACTION',
|
||||
project_safe=False)
|
||||
mock_load.assert_called_once_with(self.ctx, action_id='ACTION')
|
||||
|
||||
mock_info.assert_not_called()
|
||||
mock_status.assert_called_once_with(
|
||||
|
|
|
@ -228,14 +228,15 @@ class TestReceiver(base.SenlinTestCase):
|
|||
def test_receiver_load_diff_project(self):
|
||||
receiver = self._create_receiver('receiver-1', UUID1)
|
||||
|
||||
new_context = utils.dummy_context(project='a-different-project')
|
||||
ex = self.assertRaises(exception.ResourceNotFound,
|
||||
rb.Receiver.load,
|
||||
new_context, UUID1, None)
|
||||
self.assertEqual("The receiver '%s' could not be found." % UUID1,
|
||||
str(ex))
|
||||
new_context = utils.dummy_context(
|
||||
project='a-different-project', is_admin=True)
|
||||
# ex = self.assertRaises(exception.ResourceNotFound,
|
||||
# rb.Receiver.load,
|
||||
# new_context, UUID1, None)
|
||||
# self.assertEqual("The receiver '%s' could not be found." % UUID1,
|
||||
# str(ex))
|
||||
|
||||
res = rb.Receiver.load(new_context, receiver.id, project_safe=False)
|
||||
res = rb.Receiver.load(new_context, receiver.id)
|
||||
self.assertIsNotNone(res)
|
||||
self.assertEqual(receiver.id, res.id)
|
||||
|
||||
|
|
|
@ -114,11 +114,9 @@ class TestCluster(base.SenlinTestCase):
|
|||
|
||||
mock_pb.assert_called_once_with(self.context, CLUSTER_ID)
|
||||
mock_policy.assert_called_once_with(self.context,
|
||||
POLICY_ID,
|
||||
project_safe=False)
|
||||
POLICY_ID)
|
||||
mock_profile.assert_called_once_with(self.context,
|
||||
profile_id=PROFILE_ID,
|
||||
project_safe=False)
|
||||
profile_id=PROFILE_ID)
|
||||
mock_nodes.assert_called_once_with(self.context, CLUSTER_ID)
|
||||
|
||||
def test_load_runtime_data_id_is_none(self):
|
||||
|
|
|
@ -140,14 +140,15 @@ class TestNode(base.SenlinTestCase):
|
|||
x_node_id = 'c06840c5-f4e4-49ae-8143-9da5b4c73f38'
|
||||
utils.create_node(self.context, x_node_id, PROFILE_ID, CLUSTER_ID)
|
||||
|
||||
new_ctx = utils.dummy_context(project='a-different-project')
|
||||
ex = self.assertRaises(exception.ResourceNotFound,
|
||||
nodem.Node.load,
|
||||
new_ctx, x_node_id, None)
|
||||
self.assertEqual("The node '%s' could not be found." % x_node_id,
|
||||
str(ex))
|
||||
new_ctx = utils.dummy_context(
|
||||
project='a-different-project', is_admin=True)
|
||||
# ex = self.assertRaises(exception.ResourceNotFound,
|
||||
# nodem.Node.load,
|
||||
# new_ctx, x_node_id, None)
|
||||
# self.assertEqual("The node '%s' could not be found." % x_node_id,
|
||||
# str(ex))
|
||||
|
||||
res = nodem.Node.load(new_ctx, x_node_id, project_safe=False)
|
||||
res = nodem.Node.load(new_ctx, x_node_id)
|
||||
self.assertIsNotNone(res)
|
||||
self.assertEqual(x_node_id, res.id)
|
||||
|
||||
|
|
|
@ -362,8 +362,7 @@ class DispatcherActionTest(base.SenlinTestCase):
|
|||
svc.tg = self.mock_tg
|
||||
svc.cancel_action(self.context, 'action0123')
|
||||
|
||||
mock_load.assert_called_once_with(svc.db_session, 'action0123',
|
||||
project_safe=False)
|
||||
mock_load.assert_called_once_with(svc.db_session, 'action0123')
|
||||
mock_action.signal.assert_called_once_with(mock_action.SIG_CANCEL)
|
||||
|
||||
def test_suspend_action(self):
|
||||
|
@ -374,8 +373,7 @@ class DispatcherActionTest(base.SenlinTestCase):
|
|||
svc.tg = self.mock_tg
|
||||
svc.suspend_action(self.context, 'action0123')
|
||||
|
||||
mock_load.assert_called_once_with(svc.db_session, 'action0123',
|
||||
project_safe=False)
|
||||
mock_load.assert_called_once_with(svc.db_session, 'action0123')
|
||||
mock_action.signal.assert_called_once_with(mock_action.SIG_SUSPEND)
|
||||
|
||||
def test_resume_action(self):
|
||||
|
@ -386,8 +384,7 @@ class DispatcherActionTest(base.SenlinTestCase):
|
|||
svc.tg = self.mock_tg
|
||||
svc.resume_action(self.context, 'action0123')
|
||||
|
||||
mock_load.assert_called_once_with(svc.db_session, 'action0123',
|
||||
project_safe=False)
|
||||
mock_load.assert_called_once_with(svc.db_session, 'action0123')
|
||||
mock_action.signal.assert_called_once_with(mock_action.SIG_RESUME)
|
||||
|
||||
def test_sleep(self):
|
||||
|
|
|
@ -34,7 +34,7 @@ class TestAction(testtools.TestCase):
|
|||
result = ao.Action.find(self.ctx, aid)
|
||||
|
||||
self.assertEqual(x_action, result)
|
||||
mock_get.assert_called_once_with(self.ctx, aid)
|
||||
mock_get.assert_called_once_with(self.ctx, aid, project_safe=False)
|
||||
|
||||
@mock.patch.object(ao.Action, 'get_by_name')
|
||||
@mock.patch.object(ao.Action, 'get')
|
||||
|
@ -56,10 +56,10 @@ class TestAction(testtools.TestCase):
|
|||
mock_name.return_value = x_action
|
||||
aid = 'not-a-uuid'
|
||||
|
||||
result = ao.Action.find(self.ctx, aid, project_safe=True)
|
||||
result = ao.Action.find(self.ctx, aid)
|
||||
|
||||
self.assertEqual(x_action, result)
|
||||
mock_name.assert_called_once_with(self.ctx, aid, project_safe=True)
|
||||
mock_name.assert_called_once_with(self.ctx, aid, project_safe=False)
|
||||
|
||||
@mock.patch.object(ao.Action, 'get_by_short_id')
|
||||
@mock.patch.object(ao.Action, 'get_by_name')
|
||||
|
@ -72,8 +72,8 @@ class TestAction(testtools.TestCase):
|
|||
result = ao.Action.find(self.ctx, aid)
|
||||
|
||||
self.assertEqual(x_action, result)
|
||||
mock_name.assert_called_once_with(self.ctx, aid)
|
||||
mock_shortid.assert_called_once_with(self.ctx, aid)
|
||||
mock_name.assert_called_once_with(self.ctx, aid, project_safe=False)
|
||||
mock_shortid.assert_called_once_with(self.ctx, aid, project_safe=False)
|
||||
|
||||
@mock.patch.object(ao.Action, 'get_by_name')
|
||||
@mock.patch.object(ao.Action, 'get_by_short_id')
|
||||
|
@ -86,5 +86,7 @@ class TestAction(testtools.TestCase):
|
|||
self.ctx, 'BOGUS')
|
||||
self.assertEqual("The action 'BOGUS' could not be found.",
|
||||
str(ex))
|
||||
mock_name.assert_called_once_with(self.ctx, 'BOGUS')
|
||||
mock_shortid.assert_called_once_with(self.ctx, 'BOGUS')
|
||||
mock_name.assert_called_once_with(
|
||||
self.ctx, 'BOGUS', project_safe=False)
|
||||
mock_shortid.assert_called_once_with(
|
||||
self.ctx, 'BOGUS', project_safe=False)
|
||||
|
|
|
@ -48,12 +48,11 @@ class TestCluster(base.SenlinTestCase):
|
|||
mock_get.return_value = None
|
||||
|
||||
aid = uuidutils.generate_uuid()
|
||||
result = co.Cluster.find(self.ctx, aid, False)
|
||||
result = co.Cluster.find(self.ctx, aid)
|
||||
|
||||
self.assertEqual(x_cluster, result)
|
||||
mock_get.assert_called_once_with(self.ctx, aid, project_safe=False)
|
||||
mock_get_name.assert_called_once_with(self.ctx, aid,
|
||||
project_safe=False)
|
||||
mock_get.assert_called_once_with(self.ctx, aid, project_safe=True)
|
||||
mock_get_name.assert_called_once_with(self.ctx, aid, project_safe=True)
|
||||
|
||||
@mock.patch.object(co.Cluster, 'get_by_name')
|
||||
def test_find_by_name(self, mock_get_name):
|
||||
|
@ -74,13 +73,13 @@ class TestCluster(base.SenlinTestCase):
|
|||
mock_get_name.return_value = None
|
||||
aid = 'abcd-1234-abcd'
|
||||
|
||||
result = co.Cluster.find(self.ctx, aid, False)
|
||||
result = co.Cluster.find(self.ctx, aid)
|
||||
|
||||
self.assertEqual(x_cluster, result)
|
||||
mock_get_name.assert_called_once_with(self.ctx, aid,
|
||||
project_safe=False)
|
||||
project_safe=True)
|
||||
mock_get_shortid.assert_called_once_with(self.ctx, aid,
|
||||
project_safe=False)
|
||||
project_safe=True)
|
||||
|
||||
@mock.patch.object(co.Cluster, 'get_by_short_id')
|
||||
@mock.patch.object(co.Cluster, 'get_by_name')
|
||||
|
|
|
@ -34,7 +34,7 @@ class TestEvent(testtools.TestCase):
|
|||
result = eo.Event.find(self.ctx, aid)
|
||||
|
||||
self.assertEqual(x_event, result)
|
||||
mock_get.assert_called_once_with(self.ctx, aid)
|
||||
mock_get.assert_called_once_with(self.ctx, aid, project_safe=False)
|
||||
|
||||
@mock.patch.object(eo.Event, 'get_by_short_id')
|
||||
@mock.patch.object(eo.Event, 'get')
|
||||
|
@ -56,10 +56,10 @@ class TestEvent(testtools.TestCase):
|
|||
mock_shortid.return_value = x_event
|
||||
aid = 'abcdef'
|
||||
|
||||
result = eo.Event.find(self.ctx, aid, project_safe=True)
|
||||
result = eo.Event.find(self.ctx, aid)
|
||||
|
||||
self.assertEqual(x_event, result)
|
||||
mock_shortid.assert_called_once_with(self.ctx, aid, project_safe=True)
|
||||
mock_shortid.assert_called_once_with(self.ctx, aid, project_safe=False)
|
||||
|
||||
@mock.patch.object(eo.Event, 'get_by_short_id')
|
||||
def test_find_not_found(self, mock_shortid):
|
||||
|
@ -70,4 +70,5 @@ class TestEvent(testtools.TestCase):
|
|||
self.ctx, 'BOGUS')
|
||||
self.assertEqual("The event 'BOGUS' could not be found.",
|
||||
str(ex))
|
||||
mock_shortid.assert_called_once_with(self.ctx, 'BOGUS')
|
||||
mock_shortid.assert_called_once_with(
|
||||
self.ctx, 'BOGUS', project_safe=False)
|
||||
|
|
|
@ -47,11 +47,11 @@ class TestNode(base.SenlinTestCase):
|
|||
mock_name.return_value = x_node
|
||||
aid = uuidutils.generate_uuid()
|
||||
|
||||
result = no.Node.find(self.ctx, aid, False)
|
||||
result = no.Node.find(self.ctx, aid)
|
||||
|
||||
self.assertEqual(x_node, result)
|
||||
mock_get.assert_called_once_with(self.ctx, aid, project_safe=False)
|
||||
mock_name.assert_called_once_with(self.ctx, aid, project_safe=False)
|
||||
mock_get.assert_called_once_with(self.ctx, aid, project_safe=True)
|
||||
mock_name.assert_called_once_with(self.ctx, aid, project_safe=True)
|
||||
|
||||
@mock.patch.object(no.Node, 'get_by_name')
|
||||
def test_find_by_name(self, mock_name):
|
||||
|
@ -72,11 +72,11 @@ class TestNode(base.SenlinTestCase):
|
|||
mock_shortid.return_value = x_node
|
||||
aid = 'abcdef'
|
||||
|
||||
result = no.Node.find(self.ctx, aid, False)
|
||||
result = no.Node.find(self.ctx, aid)
|
||||
|
||||
self.assertEqual(x_node, result)
|
||||
mock_name.assert_called_once_with(self.ctx, aid, project_safe=False)
|
||||
mock_shortid.assert_called_once_with(self.ctx, aid, project_safe=False)
|
||||
mock_name.assert_called_once_with(self.ctx, aid, project_safe=True)
|
||||
mock_shortid.assert_called_once_with(self.ctx, aid, project_safe=True)
|
||||
|
||||
@mock.patch.object(no.Node, 'get_by_name')
|
||||
@mock.patch.object(no.Node, 'get_by_short_id')
|
||||
|
|
|
@ -34,7 +34,7 @@ class TestPolicy(testtools.TestCase):
|
|||
result = po.Policy.find(self.ctx, aid)
|
||||
|
||||
self.assertEqual(x_policy, result)
|
||||
mock_get.assert_called_once_with(self.ctx, aid)
|
||||
mock_get.assert_called_once_with(self.ctx, aid, project_safe=False)
|
||||
|
||||
@mock.patch.object(po.Policy, 'get_by_name')
|
||||
@mock.patch.object(po.Policy, 'get')
|
||||
|
@ -60,7 +60,8 @@ class TestPolicy(testtools.TestCase):
|
|||
result = po.Policy.find(self.ctx, aid)
|
||||
|
||||
self.assertEqual(x_policy, result)
|
||||
mock_get_name.assert_called_once_with(self.ctx, aid)
|
||||
mock_get_name.assert_called_once_with(
|
||||
self.ctx, aid, project_safe=False)
|
||||
|
||||
@mock.patch.object(po.Policy, 'get_by_short_id')
|
||||
@mock.patch.object(po.Policy, 'get_by_name')
|
||||
|
@ -90,4 +91,5 @@ class TestPolicy(testtools.TestCase):
|
|||
|
||||
self.assertEqual("The policy 'Bogus' could not be found.",
|
||||
str(ex))
|
||||
mock_get_name.assert_called_once_with(self.ctx, 'Bogus')
|
||||
mock_get_name.assert_called_once_with(
|
||||
self.ctx, 'Bogus', project_safe=False)
|
||||
|
|
|
@ -31,10 +31,10 @@ class TestProfile(testtools.TestCase):
|
|||
mock_get.return_value = x_profile
|
||||
aid = uuidutils.generate_uuid()
|
||||
|
||||
result = po.Profile.find(self.ctx, aid, project_safe=True)
|
||||
result = po.Profile.find(self.ctx, aid)
|
||||
|
||||
self.assertEqual(x_profile, result)
|
||||
mock_get.assert_called_once_with(self.ctx, aid, project_safe=True)
|
||||
mock_get.assert_called_once_with(self.ctx, aid, project_safe=False)
|
||||
|
||||
@mock.patch.object(po.Profile, 'get_by_name')
|
||||
@mock.patch.object(po.Profile, 'get')
|
||||
|
@ -57,10 +57,11 @@ class TestProfile(testtools.TestCase):
|
|||
mock_get_name.return_value = x_profile
|
||||
|
||||
aid = 'this-is-not-uuid'
|
||||
result = po.Profile.find(self.ctx, aid, project_safe=True)
|
||||
result = po.Profile.find(self.ctx, aid)
|
||||
|
||||
self.assertEqual(x_profile, result)
|
||||
mock_get_name.assert_called_once_with(self.ctx, aid, project_safe=True)
|
||||
mock_get_name.assert_called_once_with(
|
||||
self.ctx, aid, project_safe=False)
|
||||
|
||||
@mock.patch.object(po.Profile, 'get_by_short_id')
|
||||
@mock.patch.object(po.Profile, 'get_by_name')
|
||||
|
@ -90,4 +91,5 @@ class TestProfile(testtools.TestCase):
|
|||
|
||||
self.assertEqual("The profile 'Bogus' could not be found.",
|
||||
str(ex))
|
||||
mock_get_name.assert_called_once_with(self.ctx, 'Bogus')
|
||||
mock_get_name.assert_called_once_with(
|
||||
self.ctx, 'Bogus', project_safe=False)
|
||||
|
|
|
@ -34,7 +34,7 @@ class ReceiverTest(testtools.TestCase):
|
|||
res = ro.Receiver.find(self.ctx, fake_id)
|
||||
|
||||
self.assertEqual(fake_obj, res)
|
||||
mock_get.assert_called_once_with(self.ctx, fake_id)
|
||||
mock_get.assert_called_once_with(self.ctx, fake_id, project_safe=False)
|
||||
|
||||
@mock.patch.object(ro.Receiver, 'get_by_name')
|
||||
@mock.patch.object(ro.Receiver, 'get')
|
||||
|
@ -60,7 +60,8 @@ class ReceiverTest(testtools.TestCase):
|
|||
res = ro.Receiver.find(self.ctx, fake_id)
|
||||
|
||||
self.assertEqual(fake_obj, res)
|
||||
mock_get_name.assert_called_once_with(self.ctx, fake_id)
|
||||
mock_get_name.assert_called_once_with(
|
||||
self.ctx, fake_id, project_safe=False)
|
||||
|
||||
@mock.patch.object(ro.Receiver, 'get_by_short_id')
|
||||
@mock.patch.object(ro.Receiver, 'get_by_name')
|
||||
|
@ -89,4 +90,5 @@ class ReceiverTest(testtools.TestCase):
|
|||
ro.Receiver.find,
|
||||
self.ctx, fake_id)
|
||||
|
||||
mock_get_name.assert_called_once_with(self.ctx, fake_id)
|
||||
mock_get_name.assert_called_once_with(
|
||||
self.ctx, fake_id, project_safe=False)
|
||||
|
|
|
@ -201,12 +201,13 @@ class TestPolicyBase(base.SenlinTestCase):
|
|||
def test_load_diff_project(self):
|
||||
policy = utils.create_policy(self.ctx, UUID1)
|
||||
|
||||
new_ctx = utils.dummy_context(project='a-different-project')
|
||||
self.assertRaises(exception.ResourceNotFound,
|
||||
pb.Policy.load,
|
||||
new_ctx, policy.id, None)
|
||||
new_ctx = utils.dummy_context(
|
||||
project='a-different-project', is_admin=True)
|
||||
# self.assertRaises(exception.ResourceNotFound,
|
||||
# pb.Policy.load,
|
||||
# new_ctx, policy.id, None)
|
||||
|
||||
res = pb.Policy.load(new_ctx, policy.id, project_safe=False)
|
||||
res = pb.Policy.load(new_ctx, policy.id)
|
||||
self.assertIsNotNone(res)
|
||||
self.assertEqual(policy.id, res.id)
|
||||
|
||||
|
|
Loading…
Reference in New Issue