From f5a94c7c2cdf090659689fb3194e7e045a1ea2d4 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Fri, 11 Jan 2013 14:11:08 -0500 Subject: Handle waiting for conductor in nova.service. Previously we were waiting for conductor to respond to a ping() in the compute manager. This patch moves this down to the base Service class. A nova service binary can indicate that db access is not allowed and if so, as soon as the service gets created, it will block while waiting for conductor to respond. The compute service has been updated to use this. This should not result in any real functional difference. The reason for this is that there is some database access that needs to be avoided down at this level. This allows us to divert these actions to conductor if needed. Part of bp no-db-compute. Change-Id: Idd6387b9428e3f9f4e4dbfe51293693238b2daf0 --- bin/nova-compute | 3 ++- nova/compute/manager.py | 7 ++----- nova/service.py | 13 ++++++++++--- nova/tests/compute/test_compute.py | 8 ++++---- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/bin/nova-compute b/bin/nova-compute index d93ddb5bd..8826015d4 100755 --- a/bin/nova-compute +++ b/bin/nova-compute @@ -55,6 +55,7 @@ if __name__ == '__main__': logging.setup('nova') utils.monkey_patch() server = service.Service.create(binary='nova-compute', - topic=CONF.compute_topic) + topic=CONF.compute_topic, + db_allowed=False) service.serve(server) service.wait() diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 98ed1286e..a517f8ffb 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -478,15 +478,12 @@ class ComputeManager(manager.SchedulerDependentManager): LOG.warning(_('Hypervisor driver does not support ' 'firewall rules'), instance=instance) - def _get_instances_at_startup(self, context): - self.conductor_api.wait_until_ready(context) - return self.conductor_api.instance_get_all_by_host(context, self.host) - def init_host(self): """Initialization for a standalone compute service.""" self.driver.init_host(host=self.host) context = nova.context.get_admin_context() - instances = self._get_instances_at_startup(context) + instances = self.conductor_api.instance_get_all_by_host(context, + self.host) if CONF.defer_iptables_apply: self.driver.filter_defer_apply_on() diff --git a/nova/service.py b/nova/service.py index 86f022f61..05049d464 100644 --- a/nova/service.py +++ b/nova/service.py @@ -30,6 +30,7 @@ import time import eventlet import greenlet +from nova import conductor from nova import context from nova import db from nova import exception @@ -38,6 +39,7 @@ from nova.openstack.common import eventlet_backdoor from nova.openstack.common import importutils from nova.openstack.common import log as logging from nova.openstack.common import rpc +from nova.openstack.common.rpc import common as rpc_common from nova import servicegroup from nova import utils from nova import version @@ -392,7 +394,7 @@ class Service(object): def __init__(self, host, binary, topic, manager, report_interval=None, periodic_enable=None, periodic_fuzzy_delay=None, - periodic_interval_max=None, + periodic_interval_max=None, db_allowed=True, *args, **kwargs): self.host = host self.binary = binary @@ -407,6 +409,9 @@ class Service(object): self.saved_args, self.saved_kwargs = args, kwargs self.timers = [] self.backdoor_port = None + self.db_allowed = db_allowed + self.conductor_api = conductor.API(use_local=db_allowed) + self.conductor_api.wait_until_ready(context.get_admin_context()) self.servicegroup_api = servicegroup.API() def start(self): @@ -481,7 +486,8 @@ class Service(object): @classmethod def create(cls, host=None, binary=None, topic=None, manager=None, report_interval=None, periodic_enable=None, - periodic_fuzzy_delay=None, periodic_interval_max=None): + periodic_fuzzy_delay=None, periodic_interval_max=None, + db_allowed=True): """Instantiates class and passes back application object. :param host: defaults to CONF.host @@ -514,7 +520,8 @@ class Service(object): report_interval=report_interval, periodic_enable=periodic_enable, periodic_fuzzy_delay=periodic_fuzzy_delay, - periodic_interval_max=periodic_interval_max) + periodic_interval_max=periodic_interval_max, + db_allowed=db_allowed) return service_obj diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 23df703be..2239e243a 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -3175,8 +3175,8 @@ class ComputeTestCase(BaseTestCase): def _do_mock_calls(defer_iptables_apply): self.compute.driver.init_host(host=our_host) context.get_admin_context().AndReturn(fake_context) - self.compute._get_instances_at_startup(fake_context).AndReturn( - startup_instances) + self.compute.conductor_api.instance_get_all_by_host( + fake_context, our_host).AndReturn(startup_instances) if defer_iptables_apply: self.compute.driver.filter_defer_apply_on() self.compute._destroy_evacuated_instances(fake_context) @@ -3193,8 +3193,8 @@ class ComputeTestCase(BaseTestCase): 'filter_defer_apply_on') self.mox.StubOutWithMock(self.compute.driver, 'filter_defer_apply_off') - self.mox.StubOutWithMock(self.compute, - '_get_instances_at_startup') + self.mox.StubOutWithMock(self.compute.conductor_api, + 'instance_get_all_by_host') self.mox.StubOutWithMock(context, 'get_admin_context') self.mox.StubOutWithMock(self.compute, '_destroy_evacuated_instances') -- cgit