V3 Pause: treat case when driver does not implement the operation
Some virt drivers may not support this operation. Change-Id: I21a3fbb6e41e4a32810fd8c76f0fabb7aeff9244
This commit is contained in:
parent
4d7a65d9f1
commit
1196abe0ea
@ -21,6 +21,7 @@ from nova.api.openstack import extensions
|
||||
from nova.api.openstack import wsgi
|
||||
from nova import compute
|
||||
from nova import exception
|
||||
from nova.openstack.common.gettextutils import _
|
||||
from nova.openstack.common import log as logging
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@ -37,7 +38,7 @@ class PauseServerController(wsgi.Controller):
|
||||
super(PauseServerController, self).__init__(*args, **kwargs)
|
||||
self.compute_api = compute.API()
|
||||
|
||||
@extensions.expected_errors((404, 409))
|
||||
@extensions.expected_errors((404, 409, 501))
|
||||
@wsgi.action('pause')
|
||||
def _pause(self, req, id, body):
|
||||
"""Permit Admins to pause the server."""
|
||||
@ -54,9 +55,12 @@ class PauseServerController(wsgi.Controller):
|
||||
'pause')
|
||||
except exception.InstanceNotFound as e:
|
||||
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||
except NotImplementedError:
|
||||
msg = _("Virt driver does not implement pause function.")
|
||||
raise exc.HTTPNotImplemented(explanation=msg)
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
@extensions.expected_errors((404, 409))
|
||||
@extensions.expected_errors((404, 409, 501))
|
||||
@wsgi.action('unpause')
|
||||
def _unpause(self, req, id, body):
|
||||
"""Permit Admins to unpause the server."""
|
||||
@ -73,6 +77,9 @@ class PauseServerController(wsgi.Controller):
|
||||
'unpause')
|
||||
except exception.InstanceNotFound as e:
|
||||
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||
except NotImplementedError:
|
||||
msg = _("Virt driver does not implement pause function.")
|
||||
raise exc.HTTPNotImplemented(explanation=msg)
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
|
||||
|
@ -90,6 +90,28 @@ class CommonMixin(object):
|
||||
self.mox.VerifyAll()
|
||||
self.mox.UnsetStubs()
|
||||
|
||||
def _test_not_implemented_state(self, action, method=None):
|
||||
if method is None:
|
||||
method = action
|
||||
|
||||
instance = self._stub_instance_get()
|
||||
body = {}
|
||||
compute_api_args_map = {}
|
||||
args, kwargs = compute_api_args_map.get(action, ((), {}))
|
||||
getattr(self.compute_api, method)(self.context, instance,
|
||||
*args, **kwargs).AndRaise(
|
||||
NotImplementedError())
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
res = self._make_request('/servers/%s/action' % instance.uuid,
|
||||
{action: body})
|
||||
self.assertEqual(501, res.status_int)
|
||||
# Do these here instead of tearDown because this method is called
|
||||
# more than once for the same test case
|
||||
self.mox.VerifyAll()
|
||||
self.mox.UnsetStubs()
|
||||
|
||||
def _test_invalid_state(self, action, method=None, body_map=None,
|
||||
compute_api_args_map=None):
|
||||
if method is None:
|
||||
|
@ -38,6 +38,13 @@ class PauseServerTests(admin_only_action_common.CommonTests):
|
||||
def test_pause_unpause(self):
|
||||
self._test_actions(['pause', 'unpause'])
|
||||
|
||||
def test_actions_raise_on_not_implemented(self):
|
||||
for action in ['pause', 'unpause']:
|
||||
self.mox.StubOutWithMock(self.compute_api, action)
|
||||
self._test_not_implemented_state(action)
|
||||
# Re-mock this.
|
||||
self.mox.StubOutWithMock(self.compute_api, 'get')
|
||||
|
||||
def test_pause_unpause_with_non_existed_instance(self):
|
||||
self._test_actions_with_non_existed_instance(['pause', 'unpause'])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user