Enable multi tenant for k8s resource get_xx_by_id

1) get_pod_by_id
2) get_service_by_id
3) get_rc_by_id

Implements part of bp multi-tenant

Change-Id: I4b3bb49984b14369e7d79c7981271b17d6169646
changes/34/152834/2
Jay Lau (Guangya Liu) 8 years ago committed by Jay Lau
parent 150139321a
commit ce0ef7c421

@ -382,9 +382,10 @@ class Connection(object):
"""
@abc.abstractmethod
def get_pod_by_id(self, pod_id):
def get_pod_by_id(self, context, pod_id):
"""Return a pod.
:param context: The security context
:param pod_id: The id of a pod.
:returns: A pod.
"""
@ -472,9 +473,10 @@ class Connection(object):
"""
@abc.abstractmethod
def get_service_by_id(self, service_id):
def get_service_by_id(self, context, service_id):
"""Return a service.
:param context: The security context
:param service_id: The id of a service.
:returns: A service.
"""
@ -561,9 +563,10 @@ class Connection(object):
"""
@abc.abstractmethod
def get_rc_by_id(self, rc_id):
def get_rc_by_id(self, context, rc_id):
"""Return a ReplicationController.
:param context: The security context
:param rc_id: The id of a rc.
:returns: A ReplicationController.
"""

@ -638,8 +638,10 @@ class Connection(api.Connection):
raise exception.PodAlreadyExists(uuid=values['uuid'])
return pod
def get_pod_by_id(self, pod_id):
query = model_query(models.Pod).filter_by(id=pod_id)
def get_pod_by_id(self, context, pod_id):
query = model_query(models.Pod)
query = self._add_tenant_filters(context, query)
query = query.filter_by(id=pod_id)
try:
return query.one()
except NoResultFound:
@ -751,8 +753,10 @@ class Connection(api.Connection):
raise exception.ServiceAlreadyExists(uuid=values['uuid'])
return service
def get_service_by_id(self, service_id):
query = model_query(models.Service).filter_by(id=service_id)
def get_service_by_id(self, context, service_id):
query = model_query(models.Service)
query = self._add_tenant_filters(context, query)
query = query.filter_by(id=service_id)
try:
return query.one()
except NoResultFound:
@ -855,8 +859,10 @@ class Connection(api.Connection):
uuid=values['uuid'])
return rc
def get_rc_by_id(self, rc_id):
query = model_query(models.ReplicationController).filter_by(id=rc_id)
def get_rc_by_id(self, context, rc_id):
query = model_query(models.ReplicationController)
query = self._add_tenant_filters(context, query)
query = query.filter_by(id=rc_id)
try:
return query.one()
except NoResultFound:

@ -81,7 +81,7 @@ class Pod(base.MagnumObject):
:param pod_id: the id of a pod.
:returns: a :class:`Pod` object.
"""
db_pod = cls.dbapi.get_pod_by_id(pod_id)
db_pod = cls.dbapi.get_pod_by_id(context, pod_id)
pod = Pod._from_db_object(cls(context), db_pod)
return pod

@ -83,7 +83,7 @@ class ReplicationController(base.MagnumObject):
:param rc_id: the id of a ReplicationController.
:returns: a :class:`ReplicationController` object.
"""
db_rc = cls.dbapi.get_rc_by_id(rc_id)
db_rc = cls.dbapi.get_rc_by_id(context, rc_id)
rc = ReplicationController._from_db_object(cls(context), db_rc)
return rc

@ -82,7 +82,7 @@ class Service(base.MagnumObject):
:param service_id: the id of a service.
:returns: a :class:`Service` object.
"""
db_service = cls.dbapi.get_service_by_id(service_id)
db_service = cls.dbapi.get_service_by_id(context, service_id)
service = Service._from_db_object(cls(context), db_service)
return service

@ -39,7 +39,7 @@ class DbPodTestCase(base.DbTestCase):
bay_uuid=self.bay.uuid)
def test_get_pod_by_id(self):
res = self.dbapi.get_pod_by_id(self.pod.id)
res = self.dbapi.get_pod_by_id(self.context, self.pod.id)
self.assertEqual(self.pod.id, res.id)
self.assertEqual(self.pod.uuid, res.uuid)
@ -55,7 +55,7 @@ class DbPodTestCase(base.DbTestCase):
def test_get_pod_that_does_not_exist(self):
self.assertRaises(exception.PodNotFound,
self.dbapi.get_pod_by_id, 999)
self.dbapi.get_pod_by_id, self.context, 999)
self.assertRaises(exception.PodNotFound,
self.dbapi.get_pod_by_uuid,
self.context,
@ -189,7 +189,7 @@ class DbPodTestCase(base.DbTestCase):
def test_destroy_pod(self):
self.dbapi.destroy_pod(self.pod.id)
self.assertRaises(exception.PodNotFound,
self.dbapi.get_pod_by_id, self.pod.id)
self.dbapi.get_pod_by_id, self.context, self.pod.id)
def test_destroy_pod_by_uuid(self):
self.assertIsNotNone(self.dbapi.get_pod_by_uuid(self.context,

@ -39,7 +39,7 @@ class DbRCTestCase(base.DbTestCase):
bay_uuid=self.bay.uuid)
def test_get_rc_by_id(self):
rc = self.dbapi.get_rc_by_id(self.rc.id)
rc = self.dbapi.get_rc_by_id(self.context, self.rc.id)
self.assertEqual(self.rc.id, rc.id)
self.assertEqual(self.rc.uuid, rc.uuid)
@ -50,7 +50,7 @@ class DbRCTestCase(base.DbTestCase):
def test_get_rc_that_does_not_exist(self):
self.assertRaises(exception.ReplicationControllerNotFound,
self.dbapi.get_rc_by_id, 999)
self.dbapi.get_rc_by_id, self.context, 999)
self.assertRaises(exception.ReplicationControllerNotFound,
self.dbapi.get_rc_by_uuid,
self.context,
@ -141,7 +141,7 @@ class DbRCTestCase(base.DbTestCase):
def test_destroy_rc(self):
self.dbapi.destroy_rc(self.rc.id)
self.assertRaises(exception.ReplicationControllerNotFound,
self.dbapi.get_rc_by_id, self.rc.id)
self.dbapi.get_rc_by_id, self.context, self.rc.id)
def test_destroy_rc_by_uuid(self):
self.assertIsNotNone(self.dbapi.get_rc_by_uuid(self.context,

@ -39,7 +39,7 @@ class DbServiceTestCase(base.DbTestCase):
bay_uuid=self.bay.uuid)
def test_get_service_by_id(self):
res = self.dbapi.get_service_by_id(self.service.id)
res = self.dbapi.get_service_by_id(self.context, self.service.id)
self.assertEqual(self.service.id, res.id)
self.assertEqual(self.service.uuid, res.uuid)
@ -50,7 +50,7 @@ class DbServiceTestCase(base.DbTestCase):
def test_get_service_that_does_not_exist(self):
self.assertRaises(exception.ServiceNotFound,
self.dbapi.get_service_by_id, 999)
self.dbapi.get_service_by_id, self.context, 999)
self.assertRaises(exception.ServiceNotFound,
self.dbapi.get_service_by_uuid,
self.context,
@ -183,7 +183,8 @@ class DbServiceTestCase(base.DbTestCase):
def test_destroy_service(self):
self.dbapi.destroy_service(self.service.id)
self.assertRaises(exception.ServiceNotFound,
self.dbapi.get_service_by_id, self.service.id)
self.dbapi.get_service_by_id,
self.context, self.service.id)
def test_destroy_service_by_uuid(self):
self.assertIsNotNone(self.dbapi.get_service_by_uuid(self.context,

@ -35,7 +35,7 @@ class TestPodObject(base.DbTestCase):
autospec=True) as mock_get_pod:
mock_get_pod.return_value = self.fake_pod
pod = objects.Pod.get(self.context, pod_id)
mock_get_pod.assert_called_once_with(pod_id)
mock_get_pod.assert_called_once_with(self.context, pod_id)
self.assertEqual(self.context, pod._context)
def test_get_by_uuid(self):

@ -35,7 +35,7 @@ class TestReplicationControllerObject(base.DbTestCase):
autospec=True) as mock_get_rc:
mock_get_rc.return_value = self.fake_rc
rc = objects.ReplicationController.get(self.context, rc_id)
mock_get_rc.assert_called_once_with(rc_id)
mock_get_rc.assert_called_once_with(self.context, rc_id)
self.assertEqual(self.context, rc._context)
def test_get_by_uuid(self):

@ -35,7 +35,7 @@ class TestServiceObject(base.DbTestCase):
autospec=True) as mock_get_service:
mock_get_service.return_value = self.fake_service
service = objects.Service.get(self.context, service_id)
mock_get_service.assert_called_once_with(service_id)
mock_get_service.assert_called_once_with(self.context, service_id)
self.assertEqual(self.context, service._context)
def test_get_by_uuid(self):

Loading…
Cancel
Save