Remove unreachable code in API utils
The last line of method "get_rpc_resource" is unreachable. This patch removes it. Also, add tests to this method. Change-Id: Ib47ad473078f91b5ae238112b7acda14ea907ef2 Closes-Bug: 1470908
This commit is contained in:
parent
eb7abda967
commit
a7fd9a052b
|
@ -63,7 +63,6 @@ def get_rpc_resource(resource, resource_ident):
|
||||||
:param resource_ident: the UUID or logical name of the resource.
|
:param resource_ident: the UUID or logical name of the resource.
|
||||||
|
|
||||||
:returns: The RPC resource.
|
:returns: The RPC resource.
|
||||||
:raises: InvalidUuidOrName if the name or uuid provided is not valid.
|
|
||||||
"""
|
"""
|
||||||
resource = getattr(objects, resource)
|
resource = getattr(objects, resource)
|
||||||
|
|
||||||
|
@ -72,8 +71,6 @@ def get_rpc_resource(resource, resource_ident):
|
||||||
|
|
||||||
return resource.get_by_name(pecan.request.context, resource_ident)
|
return resource.get_by_name(pecan.request.context, resource_ident)
|
||||||
|
|
||||||
raise exception.InvalidUuidOrName(name=resource_ident)
|
|
||||||
|
|
||||||
|
|
||||||
def get_openstack_resource(manager, resource_ident, resource_type):
|
def get_openstack_resource(manager, resource_ident, resource_type):
|
||||||
"""Get the openstack resource from the uuid or logical name.
|
"""Get the openstack resource from the uuid or logical name.
|
||||||
|
|
|
@ -51,6 +51,42 @@ class TestApiUtils(base.FunctionalTest):
|
||||||
utils.validate_sort_dir,
|
utils.validate_sort_dir,
|
||||||
'fake-sort')
|
'fake-sort')
|
||||||
|
|
||||||
|
@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(
|
||||||
|
self,
|
||||||
|
mock_get_by_uuid,
|
||||||
|
mock_get_by_name,
|
||||||
|
mock_request):
|
||||||
|
mock_bay = mock.MagicMock
|
||||||
|
mock_get_by_uuid.return_value = mock_bay
|
||||||
|
uuid = common_utils.generate_uuid()
|
||||||
|
|
||||||
|
returned_bay = utils.get_rpc_resource('Bay', uuid)
|
||||||
|
|
||||||
|
mock_get_by_uuid.assert_called_once_with(mock_request.context, uuid)
|
||||||
|
self.assertFalse(mock_get_by_name.called)
|
||||||
|
self.assertEqual(returned_bay, mock_bay)
|
||||||
|
|
||||||
|
@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(
|
||||||
|
self,
|
||||||
|
mock_get_by_uuid,
|
||||||
|
mock_get_by_name,
|
||||||
|
mock_request):
|
||||||
|
mock_bay = mock.MagicMock
|
||||||
|
mock_get_by_name.return_value = mock_bay
|
||||||
|
|
||||||
|
returned_bay = utils.get_rpc_resource('Bay', 'fake-name')
|
||||||
|
|
||||||
|
self.assertFalse(mock_get_by_uuid.called)
|
||||||
|
mock_get_by_name.assert_called_once_with(mock_request.context,
|
||||||
|
'fake-name')
|
||||||
|
self.assertEqual(returned_bay, mock_bay)
|
||||||
|
|
||||||
@mock.patch.object(common_utils, 'is_uuid_like', return_value=True)
|
@mock.patch.object(common_utils, 'is_uuid_like', return_value=True)
|
||||||
def test_get_openstack_resource_by_uuid(self, fake_is_uuid_like):
|
def test_get_openstack_resource_by_uuid(self, fake_is_uuid_like):
|
||||||
fake_manager = mock.MagicMock()
|
fake_manager = mock.MagicMock()
|
||||||
|
|
Loading…
Reference in New Issue