summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSivasathurappan Radhakrishnan <siva.radhakrishnan@intel.com>2017-03-20 03:13:13 +0000
committerRajesh Tailor <ratailor@redhat.com>2018-08-10 05:50:18 +0000
commitf5b8a0a09baa3522f5c6f120d84db738cc236ab1 (patch)
tree53e19e9f81f35185317a5dad7e8d6f1b397766ec
parent456b3d68bc491a6965316e6a4f3fc11dd509237b (diff)
downloadnova-f5b8a0a09baa3522f5c6f120d84db738cc236ab1.tar.gz
Return 400 when compute host is not found
Previously user was getting a 500 error code for ComputeHostNotFound if they are using latest microversion that does live migration in async. This patches changes return response to 400 as 500 internal server error should not be returned to the user for failures due to user error that can be fixed by changing to request on client side. Change-Id: I7a9de211ecfaa7f2816fbf8bcd73ebbdd990643c closes-bug:1643623 (cherry picked from commit fb68fd12e2fd6e9686ad45c9875508bd9fa0df91)
-rw-r--r--nova/api/openstack/compute/migrate_server.py3
-rw-r--r--nova/tests/unit/api/openstack/compute/test_migrate_server.py21
2 files changed, 22 insertions, 2 deletions
diff --git a/nova/api/openstack/compute/migrate_server.py b/nova/api/openstack/compute/migrate_server.py
index 44bf0a57f7..cb543d7b0e 100644
--- a/nova/api/openstack/compute/migrate_server.py
+++ b/nova/api/openstack/compute/migrate_server.py
@@ -102,7 +102,6 @@ class MigrateServerController(wsgi.Controller):
raise exc.HTTPNotFound(explanation=e.format_message())
except (exception.NoValidHost,
exception.ComputeServiceUnavailable,
- exception.ComputeHostNotFound,
exception.InvalidHypervisorType,
exception.InvalidCPUInfo,
exception.UnableToMigrateToSelf,
@@ -121,6 +120,8 @@ class MigrateServerController(wsgi.Controller):
raise exc.HTTPBadRequest(explanation=ex.format_message())
except exception.InstanceIsLocked as e:
raise exc.HTTPConflict(explanation=e.format_message())
+ except exception.ComputeHostNotFound as e:
+ raise exc.HTTPBadRequest(explanation=e.format_message())
except exception.InstanceInvalidState as state_error:
common.raise_http_conflict_for_instance_invalid_state(state_error,
'os-migrateLive', id)
diff --git a/nova/tests/unit/api/openstack/compute/test_migrate_server.py b/nova/tests/unit/api/openstack/compute/test_migrate_server.py
index 387901533e..57722f170d 100644
--- a/nova/tests/unit/api/openstack/compute/test_migrate_server.py
+++ b/nova/tests/unit/api/openstack/compute/test_migrate_server.py
@@ -421,8 +421,27 @@ class MigrateServerTestsV234(MigrateServerTestsV230):
def test_migrate_live_migration_with_old_nova_not_supported(self):
pass
+ def test_migrate_live_compute_host_not_found(self):
+ exc = exception.ComputeHostNotFound(
+ reason="Compute host %(host)s could not be found.",
+ host='hostname')
+ self.mox.StubOutWithMock(self.compute_api, 'live_migrate')
+ instance = self._stub_instance_get()
+ self.compute_api.live_migrate(self.context, instance, None,
+ self.disk_over_commit, 'hostname',
+ self.force, self.async).AndRaise(exc)
+
+ self.mox.ReplayAll()
+ body = {'os-migrateLive':
+ {'host': 'hostname', 'block_migration': 'auto'}}
+
+ self.assertRaises(webob.exc.HTTPBadRequest,
+ self.controller._migrate_live,
+ self.req, instance.uuid, body=body)
+
def test_migrate_live_unexpected_error(self):
- exc = exception.NoValidHost(reason="No valid host found")
+ exc = exception.InvalidHypervisorType(
+ reason="The supplied hypervisor type of is invalid.")
self.mox.StubOutWithMock(self.compute_api, 'live_migrate')
instance = self._stub_instance_get()
self.compute_api.live_migrate(self.context, instance, None,