summaryrefslogtreecommitdiff
path: root/nova
diff options
context:
space:
mode:
authorjichenjc <jichenjc@cn.ibm.com>2014-03-25 14:47:39 +0800
committerjichenjc <jichenjc@cn.ibm.com>2014-06-17 03:18:31 +0800
commitd62fb490b10d9372bd52189d4c688a7c1b495d8b (patch)
tree4e6d668bd378bed274ea68e3b399c5919beb6357 /nova
parentfc03bd4595ace761c0ca3244c1da5290d6ec1b7b (diff)
downloadnova-d62fb490b10d9372bd52189d4c688a7c1b495d8b.tar.gz
Make resize raise exception when no valid host found
When resize operation starts, it will ask conductor to find a valid host and try to resize to that host. When there is no valid host can be found ,current code return directly without error notification, which will make upper layer code (e.g novaclient) thinks the execution is succesfully performed and report 'Finished'. But actually it isn't due to no valid host was found. Change-Id: I3d66dbfc0a7346762b920e802aa3be92c43d93b7 Closes-Bug: #1297052
Diffstat (limited to 'nova')
-rw-r--r--nova/api/openstack/compute/contrib/admin_actions.py2
-rw-r--r--nova/api/openstack/compute/plugins/v3/migrate_server.py3
-rw-r--r--nova/api/openstack/compute/servers.py2
-rw-r--r--nova/conductor/manager.py5
-rw-r--r--nova/tests/api/openstack/compute/test_server_actions.py11
-rw-r--r--nova/tests/conductor/test_conductor.py11
-rw-r--r--nova/tests/integrated/test_api_samples.py3
-rw-r--r--nova/tests/integrated/v3/test_migrate_server.py5
8 files changed, 33 insertions, 9 deletions
diff --git a/nova/api/openstack/compute/contrib/admin_actions.py b/nova/api/openstack/compute/contrib/admin_actions.py
index 1702371581..183b5d7d83 100644
--- a/nova/api/openstack/compute/contrib/admin_actions.py
+++ b/nova/api/openstack/compute/contrib/admin_actions.py
@@ -159,6 +159,8 @@ class AdminActionsController(wsgi.Controller):
'migrate')
except exception.InstanceNotFound as e:
raise exc.HTTPNotFound(explanation=e.format_message())
+ except exception.NoValidHost as e:
+ raise exc.HTTPBadRequest(explanation=e.format_message())
except Exception as e:
LOG.exception(_("Error in migrate %s"), e)
raise exc.HTTPBadRequest()
diff --git a/nova/api/openstack/compute/plugins/v3/migrate_server.py b/nova/api/openstack/compute/plugins/v3/migrate_server.py
index e43a3c99fa..b2aa8a9dc9 100644
--- a/nova/api/openstack/compute/plugins/v3/migrate_server.py
+++ b/nova/api/openstack/compute/plugins/v3/migrate_server.py
@@ -63,6 +63,9 @@ class MigrateServerController(wsgi.Controller):
'migrate')
except exception.InstanceNotFound as e:
raise exc.HTTPNotFound(explanation=e.format_message())
+ except exception.NoValidHost as e:
+ raise exc.HTTPBadRequest(explanation=e.format_message())
+
return webob.Response(status_int=202)
@extensions.expected_errors((400, 404, 409))
diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py
index a1da4ccb25..9ede845318 100644
--- a/nova/api/openstack/compute/servers.py
+++ b/nova/api/openstack/compute/servers.py
@@ -1188,6 +1188,8 @@ class Controller(wsgi.Controller):
except exception.Invalid:
msg = _("Invalid instance image.")
raise exc.HTTPBadRequest(explanation=msg)
+ except exception.NoValidHost as e:
+ raise exc.HTTPBadRequest(explanation=e.format_message())
return webob.Response(status_int=202)
diff --git a/nova/conductor/manager.py b/nova/conductor/manager.py
index e33cced6fe..8bd1e1e01b 100644
--- a/nova/conductor/manager.py
+++ b/nova/conductor/manager.py
@@ -722,9 +722,8 @@ class ComputeTaskManager(base.Base):
updates, ex, request_spec)
quotas.rollback()
- LOG.warning(_("No valid host found for cold migrate"),
- instance=instance)
- return
+ msg = _("No valid host found for cold migrate")
+ raise exception.NoValidHost(reason=msg)
try:
scheduler_utils.populate_filter_properties(filter_properties,
diff --git a/nova/tests/api/openstack/compute/test_server_actions.py b/nova/tests/api/openstack/compute/test_server_actions.py
index 3fedb1ef72..c9d5403e19 100644
--- a/nova/tests/api/openstack/compute/test_server_actions.py
+++ b/nova/tests/api/openstack/compute/test_server_actions.py
@@ -16,6 +16,7 @@
import base64
import uuid
+import mock
import mox
from oslo.config import cfg
import webob
@@ -866,6 +867,16 @@ class ServerActionsControllerTest(test.TestCase):
self.controller._action_resize,
req, FAKE_UUID, body)
+ @mock.patch('nova.compute.api.API.resize',
+ side_effect=exception.NoValidHost(reason=''))
+ def test_resize_raises_no_valid_host(self, mock_resize):
+ body = dict(resize=dict(flavorRef="http://localhost/3"))
+
+ req = fakes.HTTPRequest.blank(self.url)
+ self.assertRaises(webob.exc.HTTPBadRequest,
+ self.controller._action_resize,
+ req, FAKE_UUID, body)
+
def test_confirm_resize_server(self):
body = dict(confirmResize=None)
diff --git a/nova/tests/conductor/test_conductor.py b/nova/tests/conductor/test_conductor.py
index fcfc406ac5..72a7530f46 100644
--- a/nova/tests/conductor/test_conductor.py
+++ b/nova/tests/conductor/test_conductor.py
@@ -1806,8 +1806,10 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
self.mox.ReplayAll()
- self.conductor._cold_migrate(self.context, inst_obj,
- 'flavor', filter_props, [resvs])
+ self.assertRaises(exc.NoValidHost,
+ self.conductor._cold_migrate,
+ self.context, inst_obj,
+ 'flavor', filter_props, [resvs])
def test_cold_migrate_no_valid_host_back_in_stopped_state(self):
inst = fake_instance.fake_db_instance(image_ref='fake-image_ref',
@@ -1858,8 +1860,9 @@ class ConductorTaskTestCase(_BaseTaskTestCase, test_compute.BaseTestCase):
self.mox.ReplayAll()
- self.conductor._cold_migrate(self.context, inst_obj,
- 'flavor', filter_props, [resvs])
+ self.assertRaises(exc.NoValidHost,
+ self.conductor._cold_migrate, self.context,
+ inst_obj, 'flavor', filter_props, [resvs])
def test_cold_migrate_exception_host_in_error_state_and_raise(self):
inst = fake_instance.fake_db_instance(image_ref='fake-image_ref',
diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py
index d4660b7a53..0c34647ab5 100644
--- a/nova/tests/integrated/test_api_samples.py
+++ b/nova/tests/integrated/test_api_samples.py
@@ -1952,7 +1952,8 @@ class AdminActionsSamplesJsonTest(ServersSampleBase):
'admin-actions-resume', {})
self.assertEqual(response.status, 202)
- def test_post_migrate(self):
+ @mock.patch('nova.conductor.manager.ComputeTaskManager._cold_migrate')
+ def test_post_migrate(self, mock_cold_migrate):
# Get api samples to migrate server request.
response = self._do_post('servers/%s/action' % self.uuid,
'admin-actions-migrate', {})
diff --git a/nova/tests/integrated/v3/test_migrate_server.py b/nova/tests/integrated/v3/test_migrate_server.py
index 5c188aec21..a75a918dbf 100644
--- a/nova/tests/integrated/v3/test_migrate_server.py
+++ b/nova/tests/integrated/v3/test_migrate_server.py
@@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
+import mock
+
from nova.conductor import manager as conductor_manager
from nova import db
from nova.tests.integrated.v3 import test_servers
@@ -30,7 +32,8 @@ class MigrateServerSamplesJsonTest(test_servers.ServersSampleBase):
super(MigrateServerSamplesJsonTest, self).setUp()
self.uuid = self._post_server()
- def test_post_migrate(self):
+ @mock.patch('nova.conductor.manager.ComputeTaskManager._cold_migrate')
+ def test_post_migrate(self, mock_cold_migrate):
# Get api samples to migrate server request.
response = self._do_post('servers/%s/action' % self.uuid,
'migrate-server', {})