From 138483a0bdad1d3661a9bf6e80149d2195cc0e0f Mon Sep 17 00:00:00 2001 From: Hua Wang Date: Thu, 25 Feb 2016 15:56:38 +0800 Subject: [PATCH] Rename get_rpc_resource to get_resource Rename get_rpc_resource to get_resource. Because there is no rpc call in this method. Change-Id: I4dfba86b9932c9def08959f7fb1df98b7bc41436 Closes-Bug: #1549650 --- magnum/api/controllers/v1/bay.py | 24 +++---- magnum/api/controllers/v1/baymodel.py | 24 +++---- magnum/api/controllers/v1/certificate.py | 8 +-- magnum/api/controllers/v1/container.py | 70 +++++++++---------- magnum/api/controllers/v1/x509keypair.py | 14 ++-- magnum/api/utils.py | 6 +- magnum/api/validation.py | 4 +- .../api/controllers/v1/test_certificate.py | 6 +- .../unit/api/controllers/v1/test_utils.py | 8 +-- magnum/tests/unit/api/test_validation.py | 16 ++--- 10 files changed, 90 insertions(+), 90 deletions(-) diff --git a/magnum/api/controllers/v1/bay.py b/magnum/api/controllers/v1/bay.py index 4b983009ac..84da055c9f 100644 --- a/magnum/api/controllers/v1/bay.py +++ b/magnum/api/controllers/v1/bay.py @@ -64,7 +64,7 @@ class Bay(base.APIBase): def _set_baymodel_id(self, value): if value and self._baymodel_id != value: try: - baymodel = api_utils.get_rpc_resource('BayModel', value) + baymodel = api_utils.get_resource('BayModel', value) self._baymodel_id = baymodel.uuid except exception.BayModelNotFound as e: # Change error code because 404 (NotFound) is inappropriate @@ -267,9 +267,9 @@ class BaysController(rest.RestController): :param bay_ident: UUID of a bay or logical name of the bay. """ - rpc_bay = api_utils.get_rpc_resource('Bay', bay_ident) + bay = api_utils.get_resource('Bay', bay_ident) - return Bay.convert_with_links(rpc_bay) + return Bay.convert_with_links(bay) @expose.expose(Bay, body=Bay, status_code=201) @policy.enforce_wsgi("bay", "create") @@ -304,30 +304,30 @@ class BaysController(rest.RestController): :param bay_ident: UUID or logical name of a bay. :param patch: a json PATCH document to apply to this bay. """ - rpc_bay = api_utils.get_rpc_resource('Bay', bay_ident) + bay = api_utils.get_resource('Bay', bay_ident) try: - bay_dict = rpc_bay.as_dict() - bay = Bay(**api_utils.apply_jsonpatch(bay_dict, patch)) + bay_dict = bay.as_dict() + new_bay = Bay(**api_utils.apply_jsonpatch(bay_dict, patch)) except api_utils.JSONPATCH_EXCEPTIONS as e: raise exception.PatchError(patch=patch, reason=e) # Update only the fields that have changed for field in objects.Bay.fields: try: - patch_val = getattr(bay, field) + patch_val = getattr(new_bay, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None - if rpc_bay[field] != patch_val: - rpc_bay[field] = patch_val + if bay[field] != patch_val: + bay[field] = patch_val - delta = rpc_bay.obj_what_changed() + delta = bay.obj_what_changed() validate_bay_properties(delta) - res_bay = pecan.request.rpcapi.bay_update(rpc_bay) + res_bay = pecan.request.rpcapi.bay_update(bay) return Bay.convert_with_links(res_bay) @expose.expose(None, types.uuid_or_name, status_code=204) @@ -337,6 +337,6 @@ class BaysController(rest.RestController): :param bay_ident: UUID of a bay or logical name of the bay. """ - rpc_bay = api_utils.get_rpc_resource('Bay', bay_ident) + rpc_bay = api_utils.get_resource('Bay', bay_ident) pecan.request.rpcapi.bay_delete(rpc_bay.uuid) diff --git a/magnum/api/controllers/v1/baymodel.py b/magnum/api/controllers/v1/baymodel.py index d9b4b6e320..443d1e42ab 100644 --- a/magnum/api/controllers/v1/baymodel.py +++ b/magnum/api/controllers/v1/baymodel.py @@ -286,8 +286,8 @@ class BayModelsController(rest.RestController): :param baymodel_ident: UUID or logical name of a baymodel. """ - rpc_baymodel = api_utils.get_rpc_resource('BayModel', baymodel_ident) - return BayModel.convert_with_links(rpc_baymodel) + baymodel = api_utils.get_resource('BayModel', baymodel_ident) + return BayModel.convert_with_links(baymodel) @expose.expose(BayModel, body=BayModel, status_code=201) @policy.enforce_wsgi("baymodel", "create") @@ -332,17 +332,17 @@ class BayModelsController(rest.RestController): :param patch: a json PATCH document to apply to this baymodel. """ context = pecan.request.context - rpc_baymodel = api_utils.get_rpc_resource('BayModel', baymodel_ident) + baymodel = api_utils.get_resource('BayModel', baymodel_ident) try: - baymodel_dict = rpc_baymodel.as_dict() - baymodel = BayModel(**api_utils.apply_jsonpatch( + baymodel_dict = baymodel.as_dict() + new_baymodel = BayModel(**api_utils.apply_jsonpatch( baymodel_dict, patch)) except api_utils.JSONPATCH_EXCEPTIONS as e: raise exception.PatchError(patch=patch, reason=e) # check permissions when updating baymodel public flag - if rpc_baymodel.public != baymodel.public: + if baymodel.public != new_baymodel.public: if not policy.enforce(context, "baymodel:publish", None, do_raise=False): raise exception.BaymodelPublishDenied() @@ -350,17 +350,17 @@ class BayModelsController(rest.RestController): # Update only the fields that have changed for field in objects.BayModel.fields: try: - patch_val = getattr(baymodel, field) + patch_val = getattr(new_baymodel, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None - if rpc_baymodel[field] != patch_val: - rpc_baymodel[field] = patch_val + if baymodel[field] != patch_val: + baymodel[field] = patch_val - rpc_baymodel.save() - return BayModel.convert_with_links(rpc_baymodel) + baymodel.save() + return BayModel.convert_with_links(baymodel) @expose.expose(None, types.uuid_or_name, status_code=204) @policy.enforce_wsgi("baymodel") @@ -369,5 +369,5 @@ class BayModelsController(rest.RestController): :param baymodel_ident: UUID or logical name of a baymodel. """ - rpc_baymodel = api_utils.get_rpc_resource('BayModel', baymodel_ident) + rpc_baymodel = api_utils.get_resource('BayModel', baymodel_ident) rpc_baymodel.destroy() diff --git a/magnum/api/controllers/v1/certificate.py b/magnum/api/controllers/v1/certificate.py index 7700e3c2b3..d300176df3 100644 --- a/magnum/api/controllers/v1/certificate.py +++ b/magnum/api/controllers/v1/certificate.py @@ -47,7 +47,7 @@ class Certificate(base.APIBase): def _set_bay_uuid(self, value): if value and self._bay_uuid != value: try: - self._bay = api_utils.get_rpc_resource('Bay', value) + self._bay = api_utils.get_resource('Bay', value) self._bay_uuid = self._bay.uuid except exception.BayNotFound as e: # Change error code because 404 (NotFound) is inappropriate @@ -83,7 +83,7 @@ class Certificate(base.APIBase): def get_bay(self): if not self._bay: - self._bay = api_utils.get_rpc_resource('Bay', self.bay_uuid) + self._bay = api_utils.get_resource('Bay', self.bay_uuid) return self._bay @staticmethod @@ -132,8 +132,8 @@ class CertificateController(rest.RestController): :param bay_ident: UUID of a bay or logical name of the bay. """ - rpc_bay = api_utils.get_rpc_resource('Bay', bay_ident) - certificate = pecan.request.rpcapi.get_ca_certificate(rpc_bay) + bay = api_utils.get_resource('Bay', bay_ident) + certificate = pecan.request.rpcapi.get_ca_certificate(bay) return Certificate.convert_with_links(certificate) @wsme_pecan.wsexpose(Certificate, body=Certificate, status_code=201) diff --git a/magnum/api/controllers/v1/container.py b/magnum/api/controllers/v1/container.py index 57170cd752..54a0c6fc8d 100644 --- a/magnum/api/controllers/v1/container.py +++ b/magnum/api/controllers/v1/container.py @@ -174,8 +174,8 @@ class StartController(object): if pecan.request.method != 'PUT': pecan.abort(405, ('HTTP method %s is not allowed' % pecan.request.method)) - container_uuid = api_utils.get_rpc_resource('Container', - container_ident).uuid + container_uuid = api_utils.get_resource('Container', + container_ident).uuid LOG.debug('Calling conductor.container_start with %s', container_uuid) @@ -188,9 +188,9 @@ class StopController(object): if pecan.request.method != 'PUT': pecan.abort(405, ('HTTP method %s is not allowed' % pecan.request.method)) - container_uuid = api_utils.get_rpc_resource('Container', - container_ident).uuid - LOG.debug('Calling conductor.container_stop with %s', + container_uuid = api_utils.get_resource('Container', + container_ident).uuid + LOG.debug('Calling conductor.container_stop with %s' % container_uuid) return pecan.request.rpcapi.container_stop(container_uuid) @@ -201,9 +201,9 @@ class RebootController(object): if pecan.request.method != 'PUT': pecan.abort(405, ('HTTP method %s is not allowed' % pecan.request.method)) - container_uuid = api_utils.get_rpc_resource('Container', - container_ident).uuid - LOG.debug('Calling conductor.container_reboot with %s', + container_uuid = api_utils.get_resource('Container', + container_ident).uuid + LOG.debug('Calling conductor.container_reboot with %s' % container_uuid) return pecan.request.rpcapi.container_reboot(container_uuid) @@ -214,9 +214,9 @@ class PauseController(object): if pecan.request.method != 'PUT': pecan.abort(405, ('HTTP method %s is not allowed' % pecan.request.method)) - container_uuid = api_utils.get_rpc_resource('Container', - container_ident).uuid - LOG.debug('Calling conductor.container_pause with %s', + container_uuid = api_utils.get_resource('Container', + container_ident).uuid + LOG.debug('Calling conductor.container_pause with %s' % container_uuid) return pecan.request.rpcapi.container_pause(container_uuid) @@ -227,9 +227,9 @@ class UnpauseController(object): if pecan.request.method != 'PUT': pecan.abort(405, ('HTTP method %s is not allowed' % pecan.request.method)) - container_uuid = api_utils.get_rpc_resource('Container', - container_ident).uuid - LOG.debug('Calling conductor.container_unpause with %s', + container_uuid = api_utils.get_resource('Container', + container_ident).uuid + LOG.debug('Calling conductor.container_unpause with %s' % container_uuid) return pecan.request.rpcapi.container_unpause(container_uuid) @@ -240,9 +240,9 @@ class LogsController(object): if pecan.request.method != 'GET': pecan.abort(405, ('HTTP method %s is not allowed' % pecan.request.method)) - container_uuid = api_utils.get_rpc_resource('Container', - container_ident).uuid - LOG.debug('Calling conductor.container_logs with %s', + container_uuid = api_utils.get_resource('Container', + container_ident).uuid + LOG.debug('Calling conductor.container_logs with %s' % container_uuid) return pecan.request.rpcapi.container_logs(container_uuid) @@ -253,8 +253,8 @@ class ExecuteController(object): if pecan.request.method != 'PUT': pecan.abort(405, ('HTTP method %s is not allowed' % pecan.request.method)) - container_uuid = api_utils.get_rpc_resource('Container', - container_ident).uuid + container_uuid = api_utils.get_resource('Container', + container_ident).uuid LOG.debug('Calling conductor.container_exec with %s command %s' % (container_uuid, command)) return pecan.request.rpcapi.container_exec(container_uuid, command) @@ -357,9 +357,9 @@ class ContainersController(rest.RestController): :param container_ident: UUID or name of a container. """ - rpc_container = api_utils.get_rpc_resource('Container', - container_ident) - res_container = pecan.request.rpcapi.container_show(rpc_container.uuid) + container = api_utils.get_resource('Container', + container_ident) + res_container = pecan.request.rpcapi.container_show(container.uuid) return Container.convert_with_links(res_container) @expose.expose(Container, body=Container, status_code=201) @@ -393,11 +393,11 @@ class ContainersController(rest.RestController): :param container_ident: UUID or name of a container. :param patch: a json PATCH document to apply to this container. """ - rpc_container = api_utils.get_rpc_resource('Container', - container_ident) + container = api_utils.get_resource('Container', + container_ident) try: - container_dict = rpc_container.as_dict() - container = Container(**api_utils.apply_jsonpatch( + container_dict = container.as_dict() + new_container = Container(**api_utils.apply_jsonpatch( container_dict, patch)) except api_utils.JSONPATCH_EXCEPTIONS as e: raise exception.PatchError(patch=patch, reason=e) @@ -405,17 +405,17 @@ class ContainersController(rest.RestController): # Update only the fields that have changed for field in objects.Container.fields: try: - patch_val = getattr(container, field) + patch_val = getattr(new_container, field) except AttributeError: # Ignore fields that aren't exposed in the API continue if patch_val == wtypes.Unset: patch_val = None - if rpc_container[field] != patch_val: - rpc_container[field] = patch_val + if container[field] != patch_val: + container[field] = patch_val - rpc_container.save() - return Container.convert_with_links(rpc_container) + container.save() + return Container.convert_with_links(container) @expose.expose(None, types.uuid_or_name, status_code=204) @policy.enforce_wsgi("container") @@ -424,7 +424,7 @@ class ContainersController(rest.RestController): :param container_ident: UUID or Name of a container. """ - rpc_container = api_utils.get_rpc_resource('Container', - container_ident) - pecan.request.rpcapi.container_delete(rpc_container.uuid) - rpc_container.destroy() + container = api_utils.get_resource('Container', + container_ident) + pecan.request.rpcapi.container_delete(container.uuid) + container.destroy() diff --git a/magnum/api/controllers/v1/x509keypair.py b/magnum/api/controllers/v1/x509keypair.py index 9736f56204..f7fafb20ec 100644 --- a/magnum/api/controllers/v1/x509keypair.py +++ b/magnum/api/controllers/v1/x509keypair.py @@ -50,7 +50,7 @@ class X509KeyPair(base.APIBase): def _set_bay_uuid(self, value): if value and self._bay_uuid != value: try: - bay = api_utils.get_rpc_resource('Bay', value) + bay = api_utils.get_resource('Bay', value) self._bay_uuid = bay.uuid except exception.BayNotFound as e: # Change error code because 404 (NotFound) is inappropriate @@ -228,10 +228,10 @@ class X509KeyPairController(rest.RestController): :param x509keypair_ident: UUID of a x509keypair or logical name of the x509keypair. """ - rpc_x509keypair = api_utils.get_rpc_resource('X509KeyPair', - x509keypair_ident) + x509keypair = api_utils.get_resource('X509KeyPair', + x509keypair_ident) - return X509KeyPair.convert_with_links(rpc_x509keypair) + return X509KeyPair.convert_with_links(x509keypair) @wsme_pecan.wsexpose(X509KeyPair, body=X509KeyPair, status_code=201) def post(self, x509keypair): @@ -258,7 +258,7 @@ class X509KeyPairController(rest.RestController): :param x509keypair_ident: UUID of a x509keypair or logical name of the x509keypair. """ - rpc_x509keypair = api_utils.get_rpc_resource('X509KeyPair', - x509keypair_ident) + x509keypair = api_utils.get_resource('X509KeyPair', + x509keypair_ident) - pecan.request.rpcapi.x509keypair_delete(rpc_x509keypair.uuid) + pecan.request.rpcapi.x509keypair_delete(x509keypair.uuid) diff --git a/magnum/api/utils.py b/magnum/api/utils.py index 9916b7608e..361ed227b2 100644 --- a/magnum/api/utils.py +++ b/magnum/api/utils.py @@ -61,13 +61,13 @@ def apply_jsonpatch(doc, patch): return jsonpatch.apply_patch(doc, patch) -def get_rpc_resource(resource, resource_ident): - """Get the RPC resource from the uuid or logical name. +def get_resource(resource, resource_ident): + """Get the resource from the uuid or logical name. :param resource: the resource type. :param resource_ident: the UUID or logical name of the resource. - :returns: The RPC resource. + :returns: The resource. """ resource = getattr(objects, resource) diff --git a/magnum/api/validation.py b/magnum/api/validation.py index 24dc52e2f3..f320137ce7 100644 --- a/magnum/api/validation.py +++ b/magnum/api/validation.py @@ -103,7 +103,7 @@ def enforce_network_driver_types_update(): def wrapper(func, *args, **kwargs): baymodel_ident = args[1] patch = args[2] - baymodel = api_utils.get_rpc_resource('BayModel', baymodel_ident) + baymodel = api_utils.get_resource('BayModel', baymodel_ident) try: baymodel_dict = api_utils.apply_jsonpatch(baymodel.as_dict(), patch) @@ -138,7 +138,7 @@ def enforce_volume_driver_types_update(): def wrapper(func, *args, **kwargs): baymodel_ident = args[1] patch = args[2] - baymodel = api_utils.get_rpc_resource('BayModel', baymodel_ident) + baymodel = api_utils.get_resource('BayModel', baymodel_ident) try: baymodel_dict = api_utils.apply_jsonpatch(baymodel.as_dict(), patch) diff --git a/magnum/tests/unit/api/controllers/v1/test_certificate.py b/magnum/tests/unit/api/controllers/v1/test_certificate.py index 9cdf98b37a..fb8d18ea0a 100644 --- a/magnum/tests/unit/api/controllers/v1/test_certificate.py +++ b/magnum/tests/unit/api/controllers/v1/test_certificate.py @@ -23,12 +23,12 @@ from magnum.tests.unit.objects import utils as obj_utils class TestCertObject(base.TestCase): - @mock.patch('magnum.api.utils.get_rpc_resource') - def test_cert_init(self, mock_get_rpc_resource): + @mock.patch('magnum.api.utils.get_resource') + def test_cert_init(self, mock_get_resource): cert_dict = apiutils.cert_post_data() mock_bay = mock.MagicMock() mock_bay.uuid = cert_dict['bay_uuid'] - mock_get_rpc_resource.return_value = mock_bay + mock_get_resource.return_value = mock_bay cert = api_cert.Certificate(**cert_dict) diff --git a/magnum/tests/unit/api/controllers/v1/test_utils.py b/magnum/tests/unit/api/controllers/v1/test_utils.py index e49240a0e8..b54da6fc94 100644 --- a/magnum/tests/unit/api/controllers/v1/test_utils.py +++ b/magnum/tests/unit/api/controllers/v1/test_utils.py @@ -55,7 +55,7 @@ class TestApiUtils(base.FunctionalTest): @mock.patch('pecan.request') @mock.patch('magnum.objects.Bay.get_by_name') @mock.patch('magnum.objects.Bay.get_by_uuid') - def test_get_rpc_resource_with_uuid( + def test_get_resource_with_uuid( self, mock_get_by_uuid, mock_get_by_name, @@ -64,7 +64,7 @@ class TestApiUtils(base.FunctionalTest): mock_get_by_uuid.return_value = mock_bay uuid = common_utils.generate_uuid() - returned_bay = utils.get_rpc_resource('Bay', uuid) + returned_bay = utils.get_resource('Bay', uuid) mock_get_by_uuid.assert_called_once_with(mock_request.context, uuid) self.assertFalse(mock_get_by_name.called) @@ -73,7 +73,7 @@ class TestApiUtils(base.FunctionalTest): @mock.patch('pecan.request') @mock.patch('magnum.objects.Bay.get_by_name') @mock.patch('magnum.objects.Bay.get_by_uuid') - def test_get_rpc_resource_with_name( + def test_get_resource_with_name( self, mock_get_by_uuid, mock_get_by_name, @@ -81,7 +81,7 @@ class TestApiUtils(base.FunctionalTest): mock_bay = mock.MagicMock mock_get_by_name.return_value = mock_bay - returned_bay = utils.get_rpc_resource('Bay', 'fake-name') + returned_bay = utils.get_resource('Bay', 'fake-name') self.assertFalse(mock_get_by_uuid.called) mock_get_by_name.assert_called_once_with(mock_request.context, diff --git a/magnum/tests/unit/api/test_validation.py b/magnum/tests/unit/api/test_validation.py index 0df3aab684..db3c1063ca 100644 --- a/magnum/tests/unit/api/test_validation.py +++ b/magnum/tests/unit/api/test_validation.py @@ -254,10 +254,10 @@ class TestValidation(base.BaseTestCase): assert_raised=True) @mock.patch('pecan.request') - @mock.patch('magnum.api.utils.get_rpc_resource') + @mock.patch('magnum.api.utils.get_resource') def _test_enforce_network_driver_types_update( self, - mock_get_rpc_resource, + mock_get_resource, mock_pecan_request, network_driver_type, network_driver_config_dict, @@ -277,7 +277,7 @@ class TestValidation(base.BaseTestCase): uuid=baymodel_ident, coe='kubernetes') baymodel.network_driver = network_driver_type - mock_get_rpc_resource.return_value = baymodel + mock_get_resource.return_value = baymodel # Reload the validator module so that baymodel configs are # re-evaluated. @@ -290,7 +290,7 @@ class TestValidation(base.BaseTestCase): test, self, baymodel_ident, patch) else: test(self, baymodel_ident, patch) - mock_get_rpc_resource.assert_called_once_with( + mock_get_resource.assert_called_once_with( 'BayModel', baymodel_ident) def test_enforce_network_driver_types_one_allowed_update(self): @@ -349,10 +349,10 @@ class TestValidation(base.BaseTestCase): assert_raised=True) @mock.patch('pecan.request') - @mock.patch('magnum.api.utils.get_rpc_resource') + @mock.patch('magnum.api.utils.get_resource') def _test_enforce_volume_driver_types_update( self, - mock_get_rpc_resource, + mock_get_resource, mock_pecan_request, volume_driver_type, op, @@ -369,7 +369,7 @@ class TestValidation(base.BaseTestCase): baymodel = obj_utils.get_test_baymodel(context, uuid=baymodel_ident, coe='kubernetes') - mock_get_rpc_resource.return_value = baymodel + mock_get_resource.return_value = baymodel # Reload the validator module so that baymodel configs are # re-evaluated. @@ -382,7 +382,7 @@ class TestValidation(base.BaseTestCase): test, self, baymodel_ident, patch) else: test(self, baymodel_ident, patch) - mock_get_rpc_resource.assert_called_once_with( + mock_get_resource.assert_called_once_with( 'BayModel', baymodel_ident) def test_enforce_volume_driver_types_supported_replace_update(self):