Skip to content

Commit

Permalink
Explicit errors on confirm/revertResize failures
Browse files Browse the repository at this point in the history
Fixing bug 856527

Change-Id: Ib9be618596ade2e9a899ecdc10ec9f61bf06958a
  • Loading branch information
Brian Waldon committed Oct 10, 2011
1 parent 33e5892 commit 261b411
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions nova/api/openstack/servers.py
Expand Up @@ -664,6 +664,9 @@ def _action_change_password(self, input_dict, req, id):
def _action_confirm_resize(self, input_dict, req, id):
try:
self.compute_api.confirm_resize(req.environ['nova.context'], id)
except exception.MigrationNotFound:
msg = _("Instance has not been resized.")
raise exc.HTTPBadRequest(explanation=msg)
except Exception, e:
LOG.exception(_("Error in confirm-resize %s"), e)
raise exc.HTTPBadRequest()
Expand All @@ -672,6 +675,9 @@ def _action_confirm_resize(self, input_dict, req, id):
def _action_revert_resize(self, input_dict, req, id):
try:
self.compute_api.revert_resize(req.environ['nova.context'], id)
except exception.MigrationNotFound:
msg = _("Instance has not been resized.")
raise exc.HTTPBadRequest(explanation=msg)
except Exception, e:
LOG.exception(_("Error in revert-resize %s"), e)
raise exc.HTTPBadRequest()
Expand Down
28 changes: 28 additions & 0 deletions nova/tests/api/openstack/test_server_actions.py
Expand Up @@ -272,6 +272,20 @@ def confirm_resize_mock(*args):
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 400)

def test_confirm_resize_migration_not_found(self):
req = self.webreq('/1/action', 'POST', dict(confirmResize=None))

def confirm_resize_mock(*args):
raise exception.MigrationNotFoundByStatus(instance_id=1,
status='finished')

self.stubs.Set(nova.compute.api.API,
'confirm_resize',
confirm_resize_mock)

res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 400)

def test_revert_resize_server(self):
req = self.webreq('/1/action', 'POST', dict(revertResize=None))

Expand Down Expand Up @@ -299,6 +313,20 @@ def revert_resize_mock(*args):
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 400)

def test_revert_resize_migration_not_found(self):
req = self.webreq('/1/action', 'POST', dict(revertResize=None))

def revert_resize_mock(*args):
raise exception.MigrationNotFoundByStatus(instance_id=1,
status='finished')

self.stubs.Set(nova.compute.api.API,
'revert_resize',
revert_resize_mock)

res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 400)

def test_create_backup(self):
"""The happy path for creating backups"""
self.flags(allow_admin_api=True)
Expand Down

0 comments on commit 261b411

Please sign in to comment.