diff --git a/nova/service.py b/nova/service.py index 5ce1c99cf246..e2e8acaaee72 100644 --- a/nova/service.py +++ b/nova/service.py @@ -249,14 +249,20 @@ class Service(service.Service): debugger.init() - utils.raise_if_old_compute() - service_obj = cls(host, binary, topic, manager, report_interval=report_interval, periodic_enable=periodic_enable, periodic_fuzzy_delay=periodic_fuzzy_delay, periodic_interval_max=periodic_interval_max) + # NOTE(gibi): This have to be after the service object creation as + # that is the point where we can safely use the RPC to the conductor. + # E.g. the Service.__init__ actually waits for the conductor to start + # up before it allows the service to be created. The + # raise_if_old_compute() depends on the RPC to be up and does not + # implement its own retry mechanism to connect to the conductor. + utils.raise_if_old_compute() + return service_obj def kill(self): diff --git a/nova/tests/unit/test_service.py b/nova/tests/unit/test_service.py index 7464c56d1a99..676eb0aa42fe 100644 --- a/nova/tests/unit/test_service.py +++ b/nova/tests/unit/test_service.py @@ -268,13 +268,23 @@ class ServiceTestCase(test.NoDBTestCase): serv.reset() mock_reset.assert_called_once_with() + @mock.patch('nova.conductor.api.API.wait_until_ready') @mock.patch('nova.utils.raise_if_old_compute') - def test_old_compute_version_is_checked(self, mock_check_old): + def test_old_compute_version_check_happens_after_wait_for_conductor( + self, mock_check_old, mock_wait): + obj_base.NovaObject.indirection_api = mock.MagicMock() + + def fake_wait(*args, **kwargs): + mock_check_old.assert_not_called() + + mock_wait.side_effect = fake_wait + service.Service.create( self.host, self.binary, self.topic, 'nova.tests.unit.test_service.FakeManager') mock_check_old.assert_called_once_with() + mock_wait.assert_called_once_with(mock.ANY) class TestWSGIService(test.NoDBTestCase):