Enable multi tenant for get_pod_by_uuid
Implements part of bp multi-tenant Change-Id: Ief0c3f93880f62a3bc50132927338c83447b7739
This commit is contained in:
parent
df3960eb38
commit
1e98de6973
|
@ -231,8 +231,12 @@ class PodsController(rest.RestController):
|
||||||
raise exception.OperationNotPermitted
|
raise exception.OperationNotPermitted
|
||||||
|
|
||||||
pod.parse_manifest()
|
pod.parse_manifest()
|
||||||
pod_obj = objects.Pod(pecan.request.context,
|
pod_dict = pod.as_dict()
|
||||||
**pod.as_dict())
|
ctxt = pecan.request.context
|
||||||
|
auth_token = ctxt.auth_token_info['token']
|
||||||
|
pod_dict['project_id'] = auth_token['project']['id']
|
||||||
|
pod_dict['user_id'] = auth_token['user']['id']
|
||||||
|
pod_obj = objects.Pod(ctxt, **pod_dict)
|
||||||
new_pod = pecan.request.rpcapi.pod_create(pod_obj)
|
new_pod = pecan.request.rpcapi.pod_create(pod_obj)
|
||||||
# Set the HTTP Location Header
|
# Set the HTTP Location Header
|
||||||
pecan.response.location = link.build_url('pods', new_pod.uuid)
|
pecan.response.location = link.build_url('pods', new_pod.uuid)
|
||||||
|
|
|
@ -389,9 +389,10 @@ class Connection(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_pod_by_uuid(self, pod_uuid):
|
def get_pod_by_uuid(self, context, pod_uuid):
|
||||||
"""Return a pod.
|
"""Return a pod.
|
||||||
|
|
||||||
|
:param context: The security context
|
||||||
:param pod_uuid: The uuid of a pod.
|
:param pod_uuid: The uuid of a pod.
|
||||||
:returns: A pod.
|
:returns: A pod.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -644,8 +644,10 @@ class Connection(api.Connection):
|
||||||
except NoResultFound:
|
except NoResultFound:
|
||||||
raise exception.PodNotFound(pod=pod_id)
|
raise exception.PodNotFound(pod=pod_id)
|
||||||
|
|
||||||
def get_pod_by_uuid(self, pod_uuid):
|
def get_pod_by_uuid(self, context, pod_uuid):
|
||||||
query = model_query(models.Pod).filter_by(uuid=pod_uuid)
|
query = model_query(models.Pod)
|
||||||
|
query = self._add_tenant_filters(context, query)
|
||||||
|
query = query.filter_by(uuid=pod_uuid)
|
||||||
try:
|
try:
|
||||||
return query.one()
|
return query.one()
|
||||||
except NoResultFound:
|
except NoResultFound:
|
||||||
|
|
|
@ -93,7 +93,7 @@ class Pod(base.MagnumObject):
|
||||||
:param context: Security context
|
:param context: Security context
|
||||||
:returns: a :class:`Pod` object.
|
:returns: a :class:`Pod` object.
|
||||||
"""
|
"""
|
||||||
db_pod = cls.dbapi.get_pod_by_uuid(uuid)
|
db_pod = cls.dbapi.get_pod_by_uuid(context, uuid)
|
||||||
pod = Pod._from_db_object(cls(context), db_pod)
|
pod = Pod._from_db_object(cls(context), db_pod)
|
||||||
return pod
|
return pod
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ class DbPodTestCase(base.DbTestCase):
|
||||||
self.assertEqual(self.pod.uuid, res.uuid)
|
self.assertEqual(self.pod.uuid, res.uuid)
|
||||||
|
|
||||||
def test_get_pod_by_uuid(self):
|
def test_get_pod_by_uuid(self):
|
||||||
res = self.dbapi.get_pod_by_uuid(self.pod.uuid)
|
res = self.dbapi.get_pod_by_uuid(self.context, self.pod.uuid)
|
||||||
self.assertEqual(self.pod.id, res.id)
|
self.assertEqual(self.pod.id, res.id)
|
||||||
self.assertEqual(self.pod.uuid, res.uuid)
|
self.assertEqual(self.pod.uuid, res.uuid)
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ class DbPodTestCase(base.DbTestCase):
|
||||||
self.dbapi.get_pod_by_id, 999)
|
self.dbapi.get_pod_by_id, 999)
|
||||||
self.assertRaises(exception.PodNotFound,
|
self.assertRaises(exception.PodNotFound,
|
||||||
self.dbapi.get_pod_by_uuid,
|
self.dbapi.get_pod_by_uuid,
|
||||||
|
self.context,
|
||||||
magnum_utils.generate_uuid())
|
magnum_utils.generate_uuid())
|
||||||
self.assertRaises(exception.PodNotFound,
|
self.assertRaises(exception.PodNotFound,
|
||||||
self.dbapi.get_pod_by_name,
|
self.dbapi.get_pod_by_name,
|
||||||
|
@ -184,10 +185,12 @@ class DbPodTestCase(base.DbTestCase):
|
||||||
self.dbapi.get_pod_by_id, self.pod.id)
|
self.dbapi.get_pod_by_id, self.pod.id)
|
||||||
|
|
||||||
def test_destroy_pod_by_uuid(self):
|
def test_destroy_pod_by_uuid(self):
|
||||||
self.assertIsNotNone(self.dbapi.get_pod_by_uuid(self.pod.uuid))
|
self.assertIsNotNone(self.dbapi.get_pod_by_uuid(self.context,
|
||||||
|
self.pod.uuid))
|
||||||
self.dbapi.destroy_pod(self.pod.uuid)
|
self.dbapi.destroy_pod(self.pod.uuid)
|
||||||
self.assertRaises(exception.PodNotFound,
|
self.assertRaises(exception.PodNotFound,
|
||||||
self.dbapi.get_pod_by_uuid, self.pod.uuid)
|
self.dbapi.get_pod_by_uuid,
|
||||||
|
self.context, self.pod.uuid)
|
||||||
|
|
||||||
def test_destroy_pod_that_does_not_exist(self):
|
def test_destroy_pod_that_does_not_exist(self):
|
||||||
self.assertRaises(exception.PodNotFound,
|
self.assertRaises(exception.PodNotFound,
|
||||||
|
|
|
@ -44,7 +44,7 @@ class TestPodObject(base.DbTestCase):
|
||||||
autospec=True) as mock_get_pod:
|
autospec=True) as mock_get_pod:
|
||||||
mock_get_pod.return_value = self.fake_pod
|
mock_get_pod.return_value = self.fake_pod
|
||||||
pod = objects.Pod.get(self.context, uuid)
|
pod = objects.Pod.get(self.context, uuid)
|
||||||
mock_get_pod.assert_called_once_with(uuid)
|
mock_get_pod.assert_called_once_with(self.context, uuid)
|
||||||
self.assertEqual(self.context, pod._context)
|
self.assertEqual(self.context, pod._context)
|
||||||
|
|
||||||
def test_get_bad_id_and_uuid(self):
|
def test_get_bad_id_and_uuid(self):
|
||||||
|
@ -79,7 +79,7 @@ class TestPodObject(base.DbTestCase):
|
||||||
autospec=True) as mock_destroy_pod:
|
autospec=True) as mock_destroy_pod:
|
||||||
pod = objects.Pod.get_by_uuid(self.context, uuid)
|
pod = objects.Pod.get_by_uuid(self.context, uuid)
|
||||||
pod.destroy()
|
pod.destroy()
|
||||||
mock_get_pod.assert_called_once_with(uuid)
|
mock_get_pod.assert_called_once_with(self.context, uuid)
|
||||||
mock_destroy_pod.assert_called_once_with(uuid)
|
mock_destroy_pod.assert_called_once_with(uuid)
|
||||||
self.assertEqual(self.context, pod._context)
|
self.assertEqual(self.context, pod._context)
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ class TestPodObject(base.DbTestCase):
|
||||||
pod.desc = 'test-pod'
|
pod.desc = 'test-pod'
|
||||||
pod.save()
|
pod.save()
|
||||||
|
|
||||||
mock_get_pod.assert_called_once_with(uuid)
|
mock_get_pod.assert_called_once_with(self.context, uuid)
|
||||||
mock_update_pod.assert_called_once_with(
|
mock_update_pod.assert_called_once_with(
|
||||||
uuid, {'desc': 'test-pod'})
|
uuid, {'desc': 'test-pod'})
|
||||||
self.assertEqual(self.context, pod._context)
|
self.assertEqual(self.context, pod._context)
|
||||||
|
@ -104,7 +104,8 @@ class TestPodObject(base.DbTestCase):
|
||||||
new_uuid = magnum_utils.generate_uuid()
|
new_uuid = magnum_utils.generate_uuid()
|
||||||
returns = [dict(self.fake_pod, uuid=uuid),
|
returns = [dict(self.fake_pod, uuid=uuid),
|
||||||
dict(self.fake_pod, uuid=new_uuid)]
|
dict(self.fake_pod, uuid=new_uuid)]
|
||||||
expected = [mock.call(uuid), mock.call(uuid)]
|
expected = [mock.call(self.context, uuid),
|
||||||
|
mock.call(self.context, uuid)]
|
||||||
with mock.patch.object(self.dbapi, 'get_pod_by_uuid',
|
with mock.patch.object(self.dbapi, 'get_pod_by_uuid',
|
||||||
side_effect=returns,
|
side_effect=returns,
|
||||||
autospec=True) as mock_get_pod:
|
autospec=True) as mock_get_pod:
|
||||||
|
|
Loading…
Reference in New Issue