From 103db29c224909cd260f1619a0a4578e172f6649 Mon Sep 17 00:00:00 2001 From: huangtianhua Date: Sat, 12 Oct 2013 11:00:03 +0800 Subject: [PATCH] migrate server doesn't raise correct exception Currently a BadRequest is raised for the migrate and live-migrate API operations when the given instance isn't found. This patch changes the APIs to raise a InstanceNotFound instead to be consistent with the other admin action APIs which hit the same type of error. Closes-Bug: #1239038 Change-Id: I28cd367c5885481ea19ace43855b2518a2afd955 --- nova/api/openstack/compute/contrib/admin_actions.py | 4 ++++ .../api/openstack/compute/contrib/test_admin_actions.py | 8 ++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/nova/api/openstack/compute/contrib/admin_actions.py b/nova/api/openstack/compute/contrib/admin_actions.py index e6aae79e1d11..9ead1d1ef393 100644 --- a/nova/api/openstack/compute/contrib/admin_actions.py +++ b/nova/api/openstack/compute/contrib/admin_actions.py @@ -132,6 +132,8 @@ class AdminActionsController(wsgi.Controller): except exception.InstanceInvalidState as state_error: common.raise_http_conflict_for_instance_invalid_state(state_error, 'migrate') + except exception.InstanceNotFound as e: + raise exc.HTTPNotFound(explanation=e.format_message()) except Exception as e: LOG.exception(_("Error in migrate %s"), e) raise exc.HTTPBadRequest() @@ -301,6 +303,8 @@ class AdminActionsController(wsgi.Controller): exception.UnableToMigrateToSelf, exception.DestinationHypervisorTooOld) as ex: raise exc.HTTPBadRequest(explanation=ex.format_message()) + except exception.InstanceNotFound as e: + raise exc.HTTPNotFound(explanation=e.format_message()) except Exception: if host is None: msg = _("Live migration of instance %s to another host " diff --git a/nova/tests/api/openstack/compute/contrib/test_admin_actions.py b/nova/tests/api/openstack/compute/contrib/test_admin_actions.py index 8afd8644d3dc..30a0767a9b50 100644 --- a/nova/tests/api/openstack/compute/contrib/test_admin_actions.py +++ b/nova/tests/api/openstack/compute/contrib/test_admin_actions.py @@ -169,8 +169,12 @@ class AdminActionsTest(CommonMixin, test.NoDBTestCase): def test_actions_with_non_existed_instance(self): actions = ['pause', 'unpause', 'suspend', 'resume', 'resetNetwork', 'injectNetworkInfo', 'lock', - 'unlock', 'os-resetState'] - body_map = {'os-resetState': {'state': 'active'}} + 'unlock', 'os-resetState', 'migrate'] + body_map = {'os-resetState': {'state': 'active'}, + 'os-migrateLive': + {'host': 'hostname', + 'block_migration': False, + 'disk_over_commit': False}} for action in actions: self._test_non_existing_instance(action, body_map=body_map)