diff --git a/nova/scheduler/host_manager.py b/nova/scheduler/host_manager.py index 009767b04993..6a8b7fc0b9fd 100644 --- a/nova/scheduler/host_manager.py +++ b/nova/scheduler/host_manager.py @@ -427,7 +427,7 @@ class HostManager(object): count = 0 if not computes_by_cell: computes_by_cell = {} - for cell in self.cells: + for cell in self.cells.values(): with context_module.target_cell(context, cell) as cctxt: cell_cns = objects.ComputeNodeList.get_all( cctxt).objects @@ -654,24 +654,26 @@ class HostManager(object): temp_cells.objects.remove(c) # once its done break for optimization break - # NOTE(danms, tssurya): global list of cells cached which - # will be refreshed every time a SIGHUP is sent to the scheduler. - self.cells = temp_cells + # NOTE(danms, tssurya): global dict, keyed by cell uuid, of cells + # cached which will be refreshed every time a SIGHUP is sent to the + # scheduler. + self.cells = {cell.uuid: cell for cell in temp_cells} LOG.debug('Found %(count)i cells: %(cells)s', {'count': len(self.cells), - 'cells': ', '.join([c.uuid for c in self.cells])}) + 'cells': ', '.join(self.cells)}) # NOTE(tssurya): Global cache of only the enabled cells. This way # scheduling is limited only to the enabled cells. However this # cache will be refreshed every time a cell is disabled or enabled # or when a new cell is created as long as a SIGHUP signal is sent # to the scheduler. - self.enabled_cells = [c for c in self.cells if not c.disabled] + self.enabled_cells = [c for c in temp_cells if not c.disabled] # Filtering the disabled cells only for logging purposes. - disabled_cells = [c for c in self.cells if c.disabled] - LOG.debug('Found %(count)i disabled cells: %(cells)s', - {'count': len(disabled_cells), - 'cells': ', '.join( - [c.identity for c in disabled_cells])}) + if LOG.isEnabledFor(logging.DEBUG): + disabled_cells = [c for c in temp_cells if c.disabled] + LOG.debug('Found %(count)i disabled cells: %(cells)s', + {'count': len(disabled_cells), + 'cells': ', '.join( + [c.identity for c in disabled_cells])}) def get_host_states_by_uuids(self, context, compute_uuids, spec_obj): diff --git a/nova/tests/unit/scheduler/test_host_manager.py b/nova/tests/unit/scheduler/test_host_manager.py index c6997ec95622..faad28d59eda 100644 --- a/nova/tests/unit/scheduler/test_host_manager.py +++ b/nova/tests/unit/scheduler/test_host_manager.py @@ -108,10 +108,12 @@ class HostManagerTestCase(test.NoDBTestCase): return_value=cells) as mock_cm: self.host_manager.refresh_cells_caches() mock_cm.assert_called_once() + # Cell2 is not in the enabled list. self.assertEqual(2, len(self.host_manager.enabled_cells)) self.assertEqual(cell_uuid3, self.host_manager.enabled_cells[1].uuid) + # But it is still in the full list. self.assertEqual(3, len(self.host_manager.cells)) - self.assertEqual(cell_uuid2, self.host_manager.cells[1].uuid) + self.assertIn(cell_uuid2, self.host_manager.cells) def test_refresh_cells_caches_except_cell0(self): ctxt = nova_context.RequestContext('fake-user', 'fake_project') @@ -546,7 +548,7 @@ class HostManagerTestCase(test.NoDBTestCase): mock_get_by_binary.return_value = fakes.SERVICES context = 'fake_context' compute_nodes, services = self.host_manager._get_computes_for_cells( - context, self.host_manager.cells) + context, self.host_manager.enabled_cells) # _get_host_states returns a generator, so make a map from it host_states_map = {(state.host, state.nodename): state for state in @@ -612,7 +614,7 @@ class HostManagerTestCase(test.NoDBTestCase): context = nova_context.get_admin_context() compute_nodes, services = self.host_manager._get_computes_for_cells( - context, self.host_manager.cells) + context, self.host_manager.enabled_cells) hosts = self.host_manager._get_host_states( context, compute_nodes, services) @@ -641,7 +643,7 @@ class HostManagerTestCase(test.NoDBTestCase): context = nova_context.get_admin_context() compute_nodes, services = self.host_manager._get_computes_for_cells( - context, self.host_manager.cells) + context, self.host_manager.enabled_cells) hosts = self.host_manager._get_host_states( context, compute_nodes, services) @@ -672,7 +674,7 @@ class HostManagerTestCase(test.NoDBTestCase): context = nova_context.get_admin_context() compute_nodes, services = self.host_manager._get_computes_for_cells( - context, self.host_manager.cells) + context, self.host_manager.enabled_cells) hosts = self.host_manager._get_host_states( context, compute_nodes, services) @@ -718,7 +720,7 @@ class HostManagerTestCase(test.NoDBTestCase): context = nova_context.get_admin_context() compute_nodes, services = self.host_manager._get_computes_for_cells( - context, self.host_manager.cells) + context, self.host_manager.enabled_cells) self.host_manager._get_host_states(context, compute_nodes, services) @@ -1077,7 +1079,7 @@ class HostManagerChangedNodesTestCase(test.NoDBTestCase): context = 'fake_context' compute_nodes, services = self.host_manager._get_computes_for_cells( - context, self.host_manager.cells) + context, self.host_manager.enabled_cells) # _get_host_states returns a generator, so make a map from it host_states_map = {(state.host, state.nodename): state for state in @@ -1103,7 +1105,7 @@ class HostManagerChangedNodesTestCase(test.NoDBTestCase): # first call: all nodes compute_nodes, services = self.host_manager._get_computes_for_cells( - context, self.host_manager.cells) + context, self.host_manager.enabled_cells) hosts = self.host_manager._get_host_states( context, compute_nodes, services) # _get_host_states returns a generator, so make a map from it @@ -1113,7 +1115,7 @@ class HostManagerChangedNodesTestCase(test.NoDBTestCase): # second call: just running nodes compute_nodes, services = self.host_manager._get_computes_for_cells( - context, self.host_manager.cells) + context, self.host_manager.enabled_cells) hosts = self.host_manager._get_host_states( context, compute_nodes, services) host_states_map = {(state.host, state.nodename): state for state in @@ -1133,7 +1135,7 @@ class HostManagerChangedNodesTestCase(test.NoDBTestCase): # first call: all nodes compute_nodes, services = self.host_manager._get_computes_for_cells( - context, self.host_manager.cells) + context, self.host_manager.enabled_cells) hosts = self.host_manager._get_host_states( context, compute_nodes, services) # _get_host_states returns a generator, so make a map from it @@ -1143,7 +1145,7 @@ class HostManagerChangedNodesTestCase(test.NoDBTestCase): # second call: no nodes compute_nodes, services = self.host_manager._get_computes_for_cells( - context, self.host_manager.cells) + context, self.host_manager.enabled_cells) hosts = self.host_manager._get_host_states( context, compute_nodes, services) host_states_map = {(state.host, state.nodename): state for state in