Fix unit test for replication controller
Replication Controller is missing unit test for getting the replication controller object by name. This patch adds the needed test. This patch also adds the missing tenant filter that was missing initially. Change-Id: I28bb71f9fba4a335f67324d264bea06d0313d58d Closes-Bug: #1488295
This commit is contained in:
parent
fb168ffb47
commit
afa4b49993
|
@ -638,9 +638,10 @@ class Connection(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abc.abstractmethod
|
@abc.abstractmethod
|
||||||
def get_rc_by_name(self, rc_name):
|
def get_rc_by_name(self, context, rc_name):
|
||||||
"""Return a ReplicationController.
|
"""Return a ReplicationController.
|
||||||
|
|
||||||
|
:param context: The security context
|
||||||
:param rc_name: The name of a ReplicationController.
|
:param rc_name: The name of a ReplicationController.
|
||||||
:returns: A ReplicationController.
|
:returns: A ReplicationController.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -894,9 +894,10 @@ class Connection(api.Connection):
|
||||||
except NoResultFound:
|
except NoResultFound:
|
||||||
raise exception.ReplicationControllerNotFound(bay=bay_uuid)
|
raise exception.ReplicationControllerNotFound(bay=bay_uuid)
|
||||||
|
|
||||||
def get_rc_by_name(self, rc_name):
|
def get_rc_by_name(self, context, rc_name):
|
||||||
query = model_query(models.ReplicationController).filter_by(
|
query = model_query(models.ReplicationController)
|
||||||
name=rc_name)
|
query = self._add_tenant_filters(context, query)
|
||||||
|
query = query.filter_by(name=rc_name)
|
||||||
try:
|
try:
|
||||||
return query.one()
|
return query.one()
|
||||||
except MultipleResultsFound:
|
except MultipleResultsFound:
|
||||||
|
|
|
@ -95,7 +95,7 @@ class ReplicationController(base.MagnumPersistentObject, base.MagnumObject,
|
||||||
:param context: Security context
|
:param context: Security context
|
||||||
:returns: a :class:`ReplicationController` object.
|
:returns: a :class:`ReplicationController` object.
|
||||||
"""
|
"""
|
||||||
db_rc = cls.dbapi.get_rc_by_name(name)
|
db_rc = cls.dbapi.get_rc_by_name(context, name)
|
||||||
rc = ReplicationController._from_db_object(cls(context), db_rc)
|
rc = ReplicationController._from_db_object(cls(context), db_rc)
|
||||||
return rc
|
return rc
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ class DbRCTestCase(base.DbTestCase):
|
||||||
self.assertEqual(self.rc.uuid, rc.uuid)
|
self.assertEqual(self.rc.uuid, rc.uuid)
|
||||||
|
|
||||||
def test_get_rc_by_name(self):
|
def test_get_rc_by_name(self):
|
||||||
res = self.dbapi.get_rc_by_name(self.rc.name)
|
res = self.dbapi.get_rc_by_name(self.context, self.rc.name)
|
||||||
self.assertEqual(self.rc.name, res.name)
|
self.assertEqual(self.rc.name, res.name)
|
||||||
self.assertEqual(self.rc.uuid, res.uuid)
|
self.assertEqual(self.rc.uuid, res.uuid)
|
||||||
|
|
||||||
|
@ -57,11 +57,11 @@ class DbRCTestCase(base.DbTestCase):
|
||||||
utils.create_test_rc(bay_uuid=self.bay.uuid,
|
utils.create_test_rc(bay_uuid=self.bay.uuid,
|
||||||
uuid=magnum_utils.generate_uuid())
|
uuid=magnum_utils.generate_uuid())
|
||||||
self.assertRaises(exception.Conflict, self.dbapi.get_rc_by_name,
|
self.assertRaises(exception.Conflict, self.dbapi.get_rc_by_name,
|
||||||
self.rc.name)
|
self.context, self.rc.name)
|
||||||
|
|
||||||
def test_get_rc_by_name_not_found(self):
|
def test_get_rc_by_name_not_found(self):
|
||||||
self.assertRaises(exception.ReplicationControllerNotFound,
|
self.assertRaises(exception.ReplicationControllerNotFound,
|
||||||
self.dbapi.get_rc_by_name,
|
self.dbapi.get_rc_by_name, self.context,
|
||||||
'not_found')
|
'not_found')
|
||||||
|
|
||||||
def test_get_rc_that_does_not_exist(self):
|
def test_get_rc_that_does_not_exist(self):
|
||||||
|
|
|
@ -48,6 +48,16 @@ class TestReplicationControllerObject(base.DbTestCase):
|
||||||
mock_get_rc.assert_called_once_with(self.context, uuid)
|
mock_get_rc.assert_called_once_with(self.context, uuid)
|
||||||
self.assertEqual(self.context, rc._context)
|
self.assertEqual(self.context, rc._context)
|
||||||
|
|
||||||
|
def test_get_by_name(self):
|
||||||
|
name = self.fake_rc['name']
|
||||||
|
with mock.patch.object(self.dbapi, 'get_rc_by_name',
|
||||||
|
autospec=True) as mock_get_rc:
|
||||||
|
mock_get_rc.return_value = self.fake_rc
|
||||||
|
rc = objects.ReplicationController.get_by_name(self.context,
|
||||||
|
name)
|
||||||
|
mock_get_rc.assert_called_once_with(self.context, name)
|
||||||
|
self.assertEqual(self.context, rc._context)
|
||||||
|
|
||||||
def test_list(self):
|
def test_list(self):
|
||||||
with mock.patch.object(self.dbapi, 'get_rc_list',
|
with mock.patch.object(self.dbapi, 'get_rc_list',
|
||||||
autospec=True) as mock_get_list:
|
autospec=True) as mock_get_list:
|
||||||
|
|
Loading…
Reference in New Issue