From 900c2af4839f49f17b80c613974559f65426520b Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Wed, 4 Jan 2017 18:04:34 -0600 Subject: [PATCH] Remove unused context variable in db api Change-Id: I78d7ddccddcc3630ddaf8fc6ddfc62dcff352bcd --- magnum/db/api.py | 6 ++---- magnum/db/sqlalchemy/api.py | 4 ++-- magnum/objects/magnum_service.py | 4 ++-- magnum/tests/unit/db/test_magnum_service.py | 14 +++++++------- magnum/tests/unit/objects/test_magnum_service.py | 9 ++++----- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/magnum/db/api.py b/magnum/db/api.py index 19b70e32be..a34fad1cd2 100644 --- a/magnum/db/api.py +++ b/magnum/db/api.py @@ -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 diff --git a/magnum/db/sqlalchemy/api.py b/magnum/db/sqlalchemy/api.py index 8dcdee351e..9b333526c3 100644 --- a/magnum/db/sqlalchemy/api.py +++ b/magnum/db/sqlalchemy/api.py @@ -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) diff --git a/magnum/objects/magnum_service.py b/magnum/objects/magnum_service.py index ee0aeb8c22..bcc29eba70 100644 --- a/magnum/objects/magnum_service.py +++ b/magnum/objects/magnum_service.py @@ -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) diff --git a/magnum/tests/unit/db/test_magnum_service.py b/magnum/tests/unit/db/test_magnum_service.py index 90ee86ce4c..60c1628d0e 100644 --- a/magnum/tests/unit/db/test_magnum_service.py +++ b/magnum/tests/unit/db/test_magnum_service.py @@ -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(): diff --git a/magnum/tests/unit/objects/test_magnum_service.py b/magnum/tests/unit/objects/test_magnum_service.py index d472fe823b..2b94032e2e 100644 --- a/magnum/tests/unit/objects/test_magnum_service.py +++ b/magnum/tests/unit/objects/test_magnum_service.py @@ -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'],