Block starting compute unless placement conf is provided

We need to signal that the compute is Ocata and since the placement is now
mandatory for Ocata, we want to hard-fail if the conf is not correct.

Depends-On: I573149b9415da2a8bb3951a4c4ce71c4c3e48c6f
Change-Id: I3919f652040f2be2641420dd469af01b268e65c9
This commit is contained in:
Sylvain Bauza 2017-01-26 17:49:55 +01:00 committed by Dan Smith
parent e57714f9f1
commit d486315e0c
6 changed files with 37 additions and 2 deletions

View File

@ -13,7 +13,7 @@
"disabled_reason": null,
"report_count": 1,
"forced_down": false,
"version": 15
"version": 16
}
},
"event_type": "service.update",

View File

@ -1129,6 +1129,12 @@ class ComputeManager(manager.Manager):
# if the configuration is wrong.
whitelist.Whitelist(CONF.pci.passthrough_whitelist)
# NOTE(sbauza): We want the compute node to hard fail if it can't be
# able to provide its resources to the placement API, or it would not
# be able to be eligible as a destination.
if CONF.placement.os_region_name is None:
raise exception.PlacementNotConfigured()
self.driver.init_host(host=self.host)
context = nova.context.get_admin_context()
instances = objects.InstanceList.get_by_host(

View File

@ -2181,3 +2181,9 @@ class Unauthorized(NovaException):
class NeutronAdminCredentialConfigurationInvalid(Invalid):
msg_fmt = _("Networking client is experiencing an unauthorized exception.")
class PlacementNotConfigured(NovaException):
msg_fmt = _("This compute is not configured to talk to the placement "
"service. Configure the [placement] section of nova.conf "
"and restart the service.")

View File

@ -30,7 +30,7 @@ LOG = logging.getLogger(__name__)
# NOTE(danms): This is the global service version counter
SERVICE_VERSION = 15
SERVICE_VERSION = 16
# NOTE(danms): This is our SERVICE_VERSION history. The idea is that any
@ -92,6 +92,9 @@ SERVICE_VERSION_HISTORY = (
# Version 15: Indicate that nova-conductor will stop a boot if BuildRequest
# is deleted before RPC to nova-compute.
{'compute_rpc': '4.13'},
# Version 16: Indicate that nova-compute will refuse to start if it doesn't
# have a placement section configured.
{'compute_rpc': '4.13'},
)

View File

@ -12,6 +12,7 @@
"""Unit tests for ComputeManager()."""
import copy
import datetime
import time
@ -2791,6 +2792,21 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase):
self.assertRaises(exception.PciDeviceInvalidDeviceName,
self.compute.init_host)
def test_init_host_placement_ensures_default_config_is_unset(self):
# Tests that by default the placement config option is unset
# NOTE(sbauza): Just resets the conf opt to the real value and not
# the faked one.
fake_conf = copy.copy(CONF)
fake_conf.clear_default('os_region_name', group='placement')
self.assertIsNone(CONF.placement.os_region_name)
def test_init_host_placement_config_failure(self):
# Tests that we fail init_host if the placement section is
# configured incorrectly.
self.flags(os_region_name=None, group='placement')
self.assertRaises(exception.PlacementNotConfigured,
self.compute.init_host)
@mock.patch('nova.compute.manager.ComputeManager._instance_update')
def test_error_out_instance_on_exception_not_implemented_err(self,
inst_update_mock):

View File

@ -75,6 +75,10 @@ class ConfFixture(config_fixture.Config):
paths.state_path_def('etc/nova/api-paste.ini'),
group='wsgi')
# placement group
self.conf.set_default('os_region_name', 'RegionOne',
group='placement')
config.parse_args([], default_config_files=[], configure_db=False,
init_rpc=False)
policy_opts.set_defaults(self.conf)