Remove unused context variable in db api

Change-Id: I78d7ddccddcc3630ddaf8fc6ddfc62dcff352bcd
This commit is contained in:
Hongbin Lu 2017-01-04 18:04:34 -06:00 committed by yatin
parent b8b40f5569
commit 900c2af483
5 changed files with 17 additions and 20 deletions

View File

@ -295,10 +295,9 @@ class Connection(object):
"""
@abc.abstractmethod
def get_magnum_service_by_host_and_binary(self, context, host, binary):
def get_magnum_service_by_host_and_binary(self, host, binary):
"""Return a magnum_service record.
:param context: The security context
:param host: The host where the binary is located.
:param binary: The name of the binary.
:returns: A magnum_service record.
@ -314,14 +313,13 @@ class Connection(object):
"""
@abc.abstractmethod
def get_magnum_service_list(self, context, disabled=None, limit=None,
def get_magnum_service_list(self, disabled=None, limit=None,
marker=None, sort_key=None, sort_dir=None):
"""Get matching magnum_service records.
Return a list of the specified columns for all magnum_services
those match the specified filters.
:param context: The security context
:param disabled: Filters disbaled services. Defaults to None.
:param limit: Maximum number of magnum_services to return.
:param marker: the last item of the previous page; we return the next

View File

@ -472,7 +472,7 @@ class Connection(api.Connection):
ref.update(values)
return ref
def get_magnum_service_by_host_and_binary(self, context, host, binary):
def get_magnum_service_by_host_and_binary(self, host, binary):
query = model_query(models.MagnumService)
query = query.filter_by(host=host, binary=binary)
try:
@ -489,7 +489,7 @@ class Connection(api.Connection):
raise exception.MagnumServiceAlreadyExists(id=magnum_service['id'])
return magnum_service
def get_magnum_service_list(self, context, disabled=None, limit=None,
def get_magnum_service_list(self, disabled=None, limit=None,
marker=None, sort_key=None, sort_dir=None
):
query = model_query(models.MagnumService)

View File

@ -59,7 +59,7 @@ class MagnumService(base.MagnumPersistentObject, base.MagnumObject):
:returns: a :class:`MagnumService` object.
"""
db_magnum_service = cls.dbapi.get_magnum_service_by_host_and_binary(
context, host, binary)
host, binary)
if db_magnum_service is None:
return None
magnum_service = MagnumService._from_db_object(
@ -80,7 +80,7 @@ class MagnumService(base.MagnumPersistentObject, base.MagnumObject):
"""
db_magnum_services = cls.dbapi.get_magnum_service_list(
context, limit=limit, marker=marker, sort_key=sort_key,
limit=limit, marker=marker, sort_key=sort_key,
sort_dir=sort_dir)
return MagnumService._from_db_object_list(db_magnum_services, cls,
context)

View File

@ -31,13 +31,13 @@ class DbMagnumServiceTestCase(base.DbTestCase):
def test_get_magnum_service_by_host_and_binary(self):
ms = utils.create_test_magnum_service()
res = self.dbapi.get_magnum_service_by_host_and_binary(
self.context, ms['host'], ms['binary'])
ms['host'], ms['binary'])
self.assertEqual(ms.id, res.id)
def test_get_magnum_service_by_host_and_binary_failure(self):
utils.create_test_magnum_service()
res = self.dbapi.get_magnum_service_by_host_and_binary(
self.context, 'fakehost1', 'fake-bin1')
'fakehost1', 'fake-bin1')
self.assertIsNone(res)
def test_update_magnum_service(self):
@ -48,7 +48,7 @@ class DbMagnumServiceTestCase(base.DbTestCase):
self.assertEqual(ms['id'], ms1['id'])
self.assertEqual(d2, ms1['disabled'])
res = self.dbapi.get_magnum_service_by_host_and_binary(
self.context, 'fakehost', 'fake-bin')
'fakehost', 'fake-bin')
self.assertEqual(ms1['id'], res['id'])
self.assertEqual(d2, res['disabled'])
@ -62,11 +62,11 @@ class DbMagnumServiceTestCase(base.DbTestCase):
def test_destroy_magnum_service(self):
ms = utils.create_test_magnum_service()
res = self.dbapi.get_magnum_service_by_host_and_binary(
self.context, 'fakehost', 'fake-bin')
'fakehost', 'fake-bin')
self.assertEqual(res['id'], ms['id'])
self.dbapi.destroy_magnum_service(ms['id'])
res = self.dbapi.get_magnum_service_by_host_and_binary(
self.context, 'fakehost', 'fake-bin')
'fakehost', 'fake-bin')
self.assertIsNone(res)
def test_destroy_magnum_service_failure(self):
@ -84,7 +84,7 @@ class DbMagnumServiceTestCase(base.DbTestCase):
'disabled_reason': 'FakeReason'
}
utils.create_test_magnum_service(**fake_ms_params)
res = self.dbapi.get_magnum_service_list(self.context)
res = self.dbapi.get_magnum_service_list()
self.assertEqual(1, len(res))
res = res[0]
for k, v in fake_ms_params.items():
@ -93,7 +93,7 @@ class DbMagnumServiceTestCase(base.DbTestCase):
fake_ms_params['binary'] = 'FakeBin1'
fake_ms_params['disabled'] = True
utils.create_test_magnum_service(**fake_ms_params)
res = self.dbapi.get_magnum_service_list(self.context, disabled=True)
res = self.dbapi.get_magnum_service_list(disabled=True)
self.assertEqual(1, len(res))
res = res[0]
for k, v in fake_ms_params.items():

View File

@ -31,8 +31,7 @@ class TestMagnumServiceObject(base.DbTestCase):
ms = objects.MagnumService.get_by_host_and_binary(self.context,
'fake-host',
'fake-bin')
mock_get_magnum_service.assert_called_once_with(self.context,
'fake-host',
mock_get_magnum_service.assert_called_once_with('fake-host',
'fake-bin')
self.assertEqual(self.context, ms._context)
@ -67,7 +66,7 @@ class TestMagnumServiceObject(base.DbTestCase):
self.context, 'fake-host', 'fake-bin')
ms.destroy()
mock_get_magnum_service.assert_called_once_with(
self.context, 'fake-host', 'fake-bin')
'fake-host', 'fake-bin')
mock_destroy_ms.assert_called_once_with(
self.fake_magnum_service['id'])
self.assertEqual(self.context, ms._context)
@ -85,7 +84,7 @@ class TestMagnumServiceObject(base.DbTestCase):
ms.disabled = True
ms.save()
mock_get_magnum_service.assert_called_once_with(
self.context, 'fake-host', 'fake-bin')
'fake-host', 'fake-bin')
mock_update_ms.assert_called_once_with(
self.fake_magnum_service['id'], {'disabled': True})
self.assertEqual(self.context, ms._context)
@ -103,7 +102,7 @@ class TestMagnumServiceObject(base.DbTestCase):
last_report_count = self.fake_magnum_service['report_count']
ms.report_state_up()
mock_get_magnum_service.assert_called_once_with(
self.context, 'fake-host', 'fake-bin')
'fake-host', 'fake-bin')
self.assertEqual(self.context, ms._context)
mock_update_ms.assert_called_once_with(
self.fake_magnum_service['id'],