service instance: also recognize instance name
Using the generic driver needs a service instance. The variable "service_instance_name_or_id" indicates that it's possible to use the UUID or the name of the Nova VM. Using the VM name currently only works, when the instance is in the current tenant. This fix searches the instance at first in the current tenant and if not found, it searches again over all tenants. Without this fix, you get the following error when using the name: Failed to get Nova VM. No server with a name or ID of 'myname' exists. Change-Id: I8770eff9752b76ebe490abf03a7ea6548282bf9b Closes-Bug: #1535775
This commit is contained in:
parent
f81bc489b8
commit
bca18c6f10
@ -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
|
||||
|
@ -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},
|
||||
|
Loading…
Reference in New Issue
Block a user