Merge "Add support for an user admin can see details any cluster, profile"
This commit is contained in:
commit
94f8671627
|
@ -429,7 +429,8 @@ class EngineService(service.Service):
|
||||||
:return: A dictionary containing the profile details, or an exception
|
:return: A dictionary containing the profile details, or an exception
|
||||||
of type `ResourceNotFound` if no matching object is found.
|
of type `ResourceNotFound` if no matching object is found.
|
||||||
"""
|
"""
|
||||||
profile = profile_obj.Profile.find(ctx, req.identity)
|
kwargs = {"project_safe": not ctx.is_admin}
|
||||||
|
profile = profile_obj.Profile.find(ctx, req.identity, **kwargs)
|
||||||
return profile.to_dict()
|
return profile.to_dict()
|
||||||
|
|
||||||
@request_context
|
@request_context
|
||||||
|
@ -709,7 +710,9 @@ class EngineService(service.Service):
|
||||||
:param req: An instance of the ClusterGetRequest.
|
:param req: An instance of the ClusterGetRequest.
|
||||||
:return: A dictionary containing the details about a cluster.
|
:return: A dictionary containing the details about a cluster.
|
||||||
"""
|
"""
|
||||||
cluster = co.Cluster.find(context, req.identity)
|
kwargs = {"project_safe": not context.is_admin}
|
||||||
|
|
||||||
|
cluster = co.Cluster.find(context, req.identity, **kwargs)
|
||||||
return cluster.to_dict()
|
return cluster.to_dict()
|
||||||
|
|
||||||
def check_cluster_quota(self, context):
|
def check_cluster_quota(self, context):
|
||||||
|
|
|
@ -276,12 +276,15 @@ class ClusterTest(base.SenlinTestCase):
|
||||||
x_cluster = mock.Mock()
|
x_cluster = mock.Mock()
|
||||||
x_cluster.to_dict.return_value = {'foo': 'bar'}
|
x_cluster.to_dict.return_value = {'foo': 'bar'}
|
||||||
mock_find.return_value = x_cluster
|
mock_find.return_value = x_cluster
|
||||||
|
project_safe = not self.ctx.is_admin
|
||||||
|
|
||||||
req = orco.ClusterGetRequest(identity='C1')
|
req = orco.ClusterGetRequest(identity='C1')
|
||||||
|
|
||||||
result = self.eng.cluster_get(self.ctx, req.obj_to_primitive())
|
result = self.eng.cluster_get(self.ctx, req.obj_to_primitive())
|
||||||
|
|
||||||
self.assertEqual({'foo': 'bar'}, result)
|
self.assertEqual({'foo': 'bar'}, result)
|
||||||
mock_find.assert_called_once_with(self.ctx, 'C1')
|
mock_find.assert_called_once_with(
|
||||||
|
self.ctx, 'C1', project_safe=project_safe)
|
||||||
|
|
||||||
@mock.patch.object(co.Cluster, 'find')
|
@mock.patch.object(co.Cluster, 'find')
|
||||||
def test_cluster_get_not_found(self, mock_find):
|
def test_cluster_get_not_found(self, mock_find):
|
||||||
|
|
|
@ -213,11 +213,13 @@ class ProfileTest(base.SenlinTestCase):
|
||||||
mock_find.return_value = x_obj
|
mock_find.return_value = x_obj
|
||||||
x_obj.to_dict.return_value = {'foo': 'bar'}
|
x_obj.to_dict.return_value = {'foo': 'bar'}
|
||||||
req = vorp.ProfileGetRequest(identity='FAKE_PROFILE')
|
req = vorp.ProfileGetRequest(identity='FAKE_PROFILE')
|
||||||
|
project_safe = not self.ctx.is_admin
|
||||||
|
|
||||||
result = self.eng.profile_get(self.ctx, req.obj_to_primitive())
|
result = self.eng.profile_get(self.ctx, req.obj_to_primitive())
|
||||||
|
|
||||||
self.assertEqual({'foo': 'bar'}, result)
|
self.assertEqual({'foo': 'bar'}, result)
|
||||||
mock_find.assert_called_once_with(self.ctx, 'FAKE_PROFILE')
|
mock_find.assert_called_once_with(
|
||||||
|
self.ctx, 'FAKE_PROFILE', project_safe=project_safe)
|
||||||
|
|
||||||
@mock.patch.object(po.Profile, 'find')
|
@mock.patch.object(po.Profile, 'find')
|
||||||
def test_profile_get_not_found(self, mock_find):
|
def test_profile_get_not_found(self, mock_find):
|
||||||
|
@ -227,11 +229,13 @@ class ProfileTest(base.SenlinTestCase):
|
||||||
ex = self.assertRaises(rpc.ExpectedException,
|
ex = self.assertRaises(rpc.ExpectedException,
|
||||||
self.eng.profile_get, self.ctx,
|
self.eng.profile_get, self.ctx,
|
||||||
req.obj_to_primitive())
|
req.obj_to_primitive())
|
||||||
|
project_safe = not self.ctx.is_admin
|
||||||
|
|
||||||
self.assertEqual(exc.ResourceNotFound, ex.exc_info[0])
|
self.assertEqual(exc.ResourceNotFound, ex.exc_info[0])
|
||||||
self.assertEqual("The profile 'Bogus' could not be found.",
|
self.assertEqual("The profile 'Bogus' could not be found.",
|
||||||
six.text_type(ex.exc_info[1]))
|
six.text_type(ex.exc_info[1]))
|
||||||
mock_find.assert_called_once_with(self.ctx, 'Bogus')
|
mock_find.assert_called_once_with(
|
||||||
|
self.ctx, 'Bogus', project_safe=project_safe)
|
||||||
|
|
||||||
@mock.patch.object(pb.Profile, 'load')
|
@mock.patch.object(pb.Profile, 'load')
|
||||||
@mock.patch.object(po.Profile, 'find')
|
@mock.patch.object(po.Profile, 'find')
|
||||||
|
|
Loading…
Reference in New Issue