Only auto-disable new nova-compute services

Change If1e03c9343b8cc9c34bd51c2b4d25acdb21131ff made the
os-services REST API only able to perform PUT actions on
nova-compute services, since those are the only ones with
host mappings in the API database. Attempting to enable or
disable a nova-scheduler service, for example, will fail with a
404 error now.

The enable_new_services config option is used to auto-disable
newly registered services to test them out before bringing them
into the pool of services for scheduling. This was really only
intended, and only makes sense for, nova-compute services. Disabling
scheduler, conductor, or API services does nothing functionally, and
requires the operator to later enable those services just to make
the GET /os-services output make sense.

This change makes the enable_new_services config option only have
an effect on auto-disabling new nova-compute services. All other
services are ignored and will not be auto-disabled. The config
option help text is updated to make this clear.

Change-Id: Ie9cb44d3f87ba85420e2909170f4d207ec4bf717
Closes-Bug: #1697960
This commit is contained in:
Matt Riedemann 2017-06-14 12:38:35 -04:00
parent b94b02b450
commit 38cca9d905
4 changed files with 38 additions and 13 deletions

View File

@ -1098,19 +1098,21 @@ Possible values:
cfg.BoolOpt('enable_new_services',
default=True,
help="""
Enable new services on this host automatically.
Enable new nova-compute services on this host automatically.
When a new service (for example "nova-compute") starts up, it gets
When a new nova-compute service starts up, it gets
registered in the database as an enabled service. Sometimes it can be useful
to register new services in disabled state and then enabled them at a later
point in time. This option can set this behavior for all services per host.
to register new compute services in disabled state and then enabled them at a
later point in time. This option only sets this behavior for nova-compute
services, it does not auto-disable other services like nova-conductor,
nova-scheduler, nova-consoleauth, or nova-osapi_compute.
Possible values:
* ``True``: Each new service is enabled as soon as it registers itself.
* ``False``: Services must be enabled via a REST API call or with the CLI
with ``nova service-enable <hostname> <binary>``, otherwise they are not
ready to use.
* ``True``: Each new compute service is enabled as soon as it registers itself.
* ``False``: Compute services must be enabled via an os-services REST API call
or with the CLI with ``nova service-enable <hostname> <binary>``, otherwise
they are not ready to use.
"""),
cfg.StrOpt('instance_name_template',
default='instance-%08x',

View File

@ -585,8 +585,13 @@ def service_get_by_compute_host(context, host):
def service_create(context, values):
service_ref = models.Service()
service_ref.update(values)
if not CONF.enable_new_services:
msg = _("New service disabled due to config option.")
# We only auto-disable nova-compute services since those are the only
# ones that can be enabled using the os-services REST API and they are
# the only ones where being disabled means anything. It does
# not make sense to be able to disable non-compute services like
# nova-scheduler or nova-osapi_compute since that does nothing.
if not CONF.enable_new_services and values.get('binary') == 'nova-compute':
msg = _("New compute service disabled due to config option.")
service_ref.disabled = True
service_ref.disabled_reason = msg
try:

View File

@ -3515,15 +3515,24 @@ class ServiceTestCase(test.TestCase, ModelsObjectComparatorMixin):
def test_service_create_disabled(self):
self.flags(enable_new_services=False)
service = self._create_service({})
service = self._create_service({'binary': 'nova-compute'})
self.assertTrue(service['disabled'])
def test_service_create_disabled_reason(self):
self.flags(enable_new_services=False)
service = self._create_service({})
msg = "New service disabled due to config option."
service = self._create_service({'binary': 'nova-compute'})
msg = "New compute service disabled due to config option."
self.assertEqual(msg, service['disabled_reason'])
def test_service_create_disabled_non_compute_ignored(self):
"""Tests that enable_new_services=False has no effect on
auto-disabling a new non-nova-compute service.
"""
self.flags(enable_new_services=False)
service = self._create_service({'binary': 'nova-scheduler'})
self.assertFalse(service['disabled'])
self.assertIsNone(service['disabled_reason'])
def test_service_destroy(self):
service1 = self._create_service({})
service2 = self._create_service({'host': 'fake_host2'})

View File

@ -0,0 +1,9 @@
---
other:
- |
The ``[DEFAULT]/enable_new_services`` configuration option will now only be
used to auto-disable new nova-compute services. Other services like
nova-conductor, nova-scheduler and nova-osapi_compute will not be
auto-disabled since disabling them does nothing functionally, and starting
in Pike the ``PUT /os-services/enable`` REST API will not be able to find
non-compute services to enable them.