diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 3c6843bea18c..d2f9934bbb90 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -1595,16 +1595,6 @@ class ComputeManager(manager.Manager): def init_host(self, service_ref): """Initialization for a standalone compute service.""" - if service_ref: - # If we are an existing service, check to see if we need - # to record a locally-persistent node identity because - # we have upgraded from a previous version. - self._ensure_existing_node_identity(service_ref) - else: - # If we are a new service (in the database), make sure we have no - # instances on our hypervisor as we would expect. - self._sanity_check_new_host() - if CONF.pci.device_spec: # Simply loading the PCI passthrough spec will do a bunch of # validation that would otherwise wait until the PciDevTracker is @@ -1635,6 +1625,16 @@ class ComputeManager(manager.Manager): self.driver.init_host(host=self.host) + if service_ref: + # If we are an existing service, check to see if we need + # to record a locally-persistent node identity because + # we have upgraded from a previous version. + self._ensure_existing_node_identity(service_ref) + else: + # If we are a new service (in the database), make sure we have no + # instances on our hypervisor as we would expect. + self._sanity_check_new_host() + # NOTE(gibi): At this point the compute_nodes of the resource tracker # has not been populated yet so we cannot rely on the resource tracker # here. diff --git a/nova/tests/unit/compute/test_compute_mgr.py b/nova/tests/unit/compute/test_compute_mgr.py index e088dc4ffacd..584007e33372 100644 --- a/nova/tests/unit/compute/test_compute_mgr.py +++ b/nova/tests/unit/compute/test_compute_mgr.py @@ -1044,21 +1044,12 @@ class ComputeManagerUnitTestCase(test.NoDBTestCase, test.MatchType(nova.context.RequestContext)) self.assertGreaterEqual(len(self.compute.driver.mock_calls), 2) - # This is bug https://bugs.launchpad.net/nova/+bug/2130881. - # The driver.init_host should have been called first - self.assertEqual( - mock.call.list_instance_uuids(), - self.compute.driver.mock_calls[0]) self.assertEqual( mock.call.init_host(host='fake-mini'), + self.compute.driver.mock_calls[0]) + self.assertEqual( + mock.call.list_instance_uuids(), self.compute.driver.mock_calls[1]) - # After the fix the following should pass - # self.assertEqual( - # mock.call.init_host(host='fake-mini'), - # self.compute.driver.mock_calls[0]) - # self.assertEqual( - # mock.call.list_instance_uuids(), - # self.compute.driver.mock_calls[1]) def test_init_host_new_with_instances(self): """Tests the case where we start up without an existing service_ref,