Merge "Provide a useful error message when trying to update non-compute services"

This commit is contained in:
Zuul 2019-02-14 08:00:32 +00:00 committed by Gerrit Code Review
commit 9f00fd7169
2 changed files with 22 additions and 3 deletions

View File

@ -178,6 +178,15 @@ class ServiceController(wsgi.Controller):
def _update(self, context, host, binary, payload):
"""Do the actual PUT/update"""
# If the user tried to perform an action
# (disable/enable/force down) on a non-nova-compute
# service, provide a more useful error message.
if binary != 'nova-compute':
msg = (_(
'Updating a %(binary)s service is not supported. Only '
'nova-compute services can be updated.') % {'binary': binary})
raise webob.exc.HTTPBadRequest(explanation=msg)
try:
self.host_api.service_update(context, host, binary, payload)
except (exception.HostBinaryNotFound,
@ -330,7 +339,7 @@ class ServiceController(wsgi.Controller):
# technically disable a nova-scheduler service, although that doesn't
# really do anything within Nova and is just confusing. Now trying to
# do that will fail as a nova-scheduler service won't have a host
# mapping so you'll get a 404. In this new microversion, we close that
# mapping so you'll get a 400. In this new microversion, we close that
# old gap and make sure you can only enable/disable and set forced_down
# on nova-compute services since those are the only ones that make
# sense to update for those operations.

View File

@ -614,7 +614,7 @@ class ServicesTestV21(test.TestCase):
def test_services_enable_with_invalid_binary(self):
body = {'host': 'host1', 'binary': 'invalid'}
self.assertRaises(webob.exc.HTTPNotFound,
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update,
self.req,
"enable",
@ -637,7 +637,7 @@ class ServicesTestV21(test.TestCase):
def test_services_disable_with_invalid_binary(self):
body = {'host': 'host1', 'binary': 'invalid'}
self.assertRaises(webob.exc.HTTPNotFound,
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update,
self.req,
"disable",
@ -1079,6 +1079,16 @@ class ServicesTestV211(ServicesTestV21):
self.assertRaises(exception.ValidationError,
self.controller.update, req, 'force-down', body=req_body)
def test_update_forced_down_invalid_service(self):
req = fakes.HTTPRequest.blank('/fake/services',
use_admin_context=True,
version=self.wsgi_api_version)
req_body = {"forced_down": True,
"host": "host1", "binary": "nova-scheduler"}
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.update, req, 'force-down',
body=req_body)
class ServicesTestV252(ServicesTestV211):
"""This is a boundary test to ensure that 2.52 behaves the same as 2.11."""