Merge "service instance: also recognize instance name"

This commit is contained in:
Jenkins 2016-03-16 13:49:16 +00:00 committed by Gerrit Code Review
commit 301584f3ab
2 changed files with 24 additions and 3 deletions

View File

@ -201,9 +201,16 @@ class API(base.Base):
try:
server = utils.find_resource(
novaclient(context).servers, instance_name_or_id)
except nova_exception.CommandError as e:
msg = _("Failed to get Nova VM. %s") % e
raise exception.ManilaException(msg)
except nova_exception.CommandError:
# we did not find the server in the current tenant,
# and proceed searching in all tenants
try:
server = utils.find_resource(
novaclient(context).servers, instance_name_or_id,
all_tenants=True)
except nova_exception.CommandError as e:
msg = _("Failed to get Nova VM. %s") % e
raise exception.ManilaException(msg)
return _untranslate_server_summary_view(server)
@translate_server_exception

View File

@ -170,6 +170,20 @@ class NovaApiTestCase(test.TestCase):
self.assertEqual(instance_id, result['id'])
utils.find_resource.assert_called_once_with(mock.ANY, instance_id)
def test_server_get_by_name_or_id_failed(self):
instance_id = 'instance_id1'
server = {'id': instance_id, 'fake_key': 'fake_value'}
self.mock_object(utils, 'find_resource',
mock.Mock(return_value=server,
side_effect=nova_exception.CommandError))
self.assertRaises(exception.ManilaException,
self.api.server_get_by_name_or_id,
self.ctx, instance_id)
utils.find_resource.assert_any_call(mock.ANY, instance_id)
utils.find_resource.assert_called_with(mock.ANY, instance_id,
all_tenants=True)
@ddt.data(
{'nova_e': nova_exception.NotFound(404),
'manila_e': exception.InstanceNotFound},