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
This commit is contained in:
Hua Wang 2016-02-25 15:56:38 +08:00
parent b0b3a3db00
commit 138483a0bd
10 changed files with 90 additions and 90 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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)

View File

@ -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()

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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,

View File

@ -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):