Browse Source

Merge "Convert HostMapping.cells to a dict" into stable/stein

changes/19/679519/1
Zuul 3 weeks ago
parent
commit
64bbf64783
2 changed files with 26 additions and 22 deletions
  1. 13
    11
      nova/scheduler/host_manager.py
  2. 13
    11
      nova/tests/unit/scheduler/test_host_manager.py

+ 13
- 11
nova/scheduler/host_manager.py View File

@@ -427,7 +427,7 @@ class HostManager(object):
427 427
             count = 0
428 428
             if not computes_by_cell:
429 429
                 computes_by_cell = {}
430
-                for cell in self.cells:
430
+                for cell in self.cells.values():
431 431
                     with context_module.target_cell(context, cell) as cctxt:
432 432
                         cell_cns = objects.ComputeNodeList.get_all(
433 433
                             cctxt).objects
@@ -654,24 +654,26 @@ class HostManager(object):
654 654
                 temp_cells.objects.remove(c)
655 655
                 # once its done break for optimization
656 656
                 break
657
-        # NOTE(danms, tssurya): global list of cells cached which
658
-        # will be refreshed every time a SIGHUP is sent to the scheduler.
659
-        self.cells = temp_cells
657
+        # NOTE(danms, tssurya): global dict, keyed by cell uuid, of cells
658
+        # cached which will be refreshed every time a SIGHUP is sent to the
659
+        # scheduler.
660
+        self.cells = {cell.uuid: cell for cell in temp_cells}
660 661
         LOG.debug('Found %(count)i cells: %(cells)s',
661 662
                   {'count': len(self.cells),
662
-                   'cells': ', '.join([c.uuid for c in self.cells])})
663
+                   'cells': ', '.join(self.cells)})
663 664
         # NOTE(tssurya): Global cache of only the enabled cells. This way
664 665
         # scheduling is limited only to the enabled cells. However this
665 666
         # cache will be refreshed every time a cell is disabled or enabled
666 667
         # or when a new cell is created as long as a SIGHUP signal is sent
667 668
         # to the scheduler.
668
-        self.enabled_cells = [c for c in self.cells if not c.disabled]
669
+        self.enabled_cells = [c for c in temp_cells if not c.disabled]
669 670
         # Filtering the disabled cells only for logging purposes.
670
-        disabled_cells = [c for c in self.cells if c.disabled]
671
-        LOG.debug('Found %(count)i disabled cells: %(cells)s',
672
-                  {'count': len(disabled_cells),
673
-                   'cells': ', '.join(
674
-                   [c.identity for c in disabled_cells])})
671
+        if LOG.isEnabledFor(logging.DEBUG):
672
+            disabled_cells = [c for c in temp_cells if c.disabled]
673
+            LOG.debug('Found %(count)i disabled cells: %(cells)s',
674
+                      {'count': len(disabled_cells),
675
+                       'cells': ', '.join(
676
+                       [c.identity for c in disabled_cells])})
675 677
 
676 678
     def get_host_states_by_uuids(self, context, compute_uuids, spec_obj):
677 679
 

+ 13
- 11
nova/tests/unit/scheduler/test_host_manager.py View File

@@ -108,10 +108,12 @@ class HostManagerTestCase(test.NoDBTestCase):
108 108
                         return_value=cells) as mock_cm:
109 109
             self.host_manager.refresh_cells_caches()
110 110
             mock_cm.assert_called_once()
111
+        # Cell2 is not in the enabled list.
111 112
         self.assertEqual(2, len(self.host_manager.enabled_cells))
112 113
         self.assertEqual(cell_uuid3, self.host_manager.enabled_cells[1].uuid)
114
+        # But it is still in the full list.
113 115
         self.assertEqual(3, len(self.host_manager.cells))
114
-        self.assertEqual(cell_uuid2, self.host_manager.cells[1].uuid)
116
+        self.assertIn(cell_uuid2, self.host_manager.cells)
115 117
 
116 118
     def test_refresh_cells_caches_except_cell0(self):
117 119
         ctxt = nova_context.RequestContext('fake-user', 'fake_project')
@@ -546,7 +548,7 @@ class HostManagerTestCase(test.NoDBTestCase):
546 548
         mock_get_by_binary.return_value = fakes.SERVICES
547 549
         context = 'fake_context'
548 550
         compute_nodes, services = self.host_manager._get_computes_for_cells(
549
-            context, self.host_manager.cells)
551
+            context, self.host_manager.enabled_cells)
550 552
 
551 553
         # _get_host_states returns a generator, so make a map from it
552 554
         host_states_map = {(state.host, state.nodename): state for state in
@@ -612,7 +614,7 @@ class HostManagerTestCase(test.NoDBTestCase):
612 614
 
613 615
         context = nova_context.get_admin_context()
614 616
         compute_nodes, services = self.host_manager._get_computes_for_cells(
615
-            context, self.host_manager.cells)
617
+            context, self.host_manager.enabled_cells)
616 618
 
617 619
         hosts = self.host_manager._get_host_states(
618 620
             context, compute_nodes, services)
@@ -641,7 +643,7 @@ class HostManagerTestCase(test.NoDBTestCase):
641 643
 
642 644
         context = nova_context.get_admin_context()
643 645
         compute_nodes, services = self.host_manager._get_computes_for_cells(
644
-            context, self.host_manager.cells)
646
+            context, self.host_manager.enabled_cells)
645 647
 
646 648
         hosts = self.host_manager._get_host_states(
647 649
             context, compute_nodes, services)
@@ -672,7 +674,7 @@ class HostManagerTestCase(test.NoDBTestCase):
672 674
 
673 675
         context = nova_context.get_admin_context()
674 676
         compute_nodes, services = self.host_manager._get_computes_for_cells(
675
-            context, self.host_manager.cells)
677
+            context, self.host_manager.enabled_cells)
676 678
 
677 679
         hosts = self.host_manager._get_host_states(
678 680
             context, compute_nodes, services)
@@ -718,7 +720,7 @@ class HostManagerTestCase(test.NoDBTestCase):
718 720
 
719 721
         context = nova_context.get_admin_context()
720 722
         compute_nodes, services = self.host_manager._get_computes_for_cells(
721
-            context, self.host_manager.cells)
723
+            context, self.host_manager.enabled_cells)
722 724
 
723 725
         self.host_manager._get_host_states(context, compute_nodes, services)
724 726
 
@@ -1077,7 +1079,7 @@ class HostManagerChangedNodesTestCase(test.NoDBTestCase):
1077 1079
         context = 'fake_context'
1078 1080
 
1079 1081
         compute_nodes, services = self.host_manager._get_computes_for_cells(
1080
-            context, self.host_manager.cells)
1082
+            context, self.host_manager.enabled_cells)
1081 1083
 
1082 1084
         # _get_host_states returns a generator, so make a map from it
1083 1085
         host_states_map = {(state.host, state.nodename): state for state in
@@ -1103,7 +1105,7 @@ class HostManagerChangedNodesTestCase(test.NoDBTestCase):
1103 1105
 
1104 1106
         # first call: all nodes
1105 1107
         compute_nodes, services = self.host_manager._get_computes_for_cells(
1106
-            context, self.host_manager.cells)
1108
+            context, self.host_manager.enabled_cells)
1107 1109
         hosts = self.host_manager._get_host_states(
1108 1110
             context, compute_nodes, services)
1109 1111
         # _get_host_states returns a generator, so make a map from it
@@ -1113,7 +1115,7 @@ class HostManagerChangedNodesTestCase(test.NoDBTestCase):
1113 1115
 
1114 1116
         # second call: just running nodes
1115 1117
         compute_nodes, services = self.host_manager._get_computes_for_cells(
1116
-            context, self.host_manager.cells)
1118
+            context, self.host_manager.enabled_cells)
1117 1119
         hosts = self.host_manager._get_host_states(
1118 1120
             context, compute_nodes, services)
1119 1121
         host_states_map = {(state.host, state.nodename): state for state in
@@ -1133,7 +1135,7 @@ class HostManagerChangedNodesTestCase(test.NoDBTestCase):
1133 1135
 
1134 1136
         # first call: all nodes
1135 1137
         compute_nodes, services = self.host_manager._get_computes_for_cells(
1136
-            context, self.host_manager.cells)
1138
+            context, self.host_manager.enabled_cells)
1137 1139
         hosts = self.host_manager._get_host_states(
1138 1140
             context, compute_nodes, services)
1139 1141
         # _get_host_states returns a generator, so make a map from it
@@ -1143,7 +1145,7 @@ class HostManagerChangedNodesTestCase(test.NoDBTestCase):
1143 1145
 
1144 1146
         # second call: no nodes
1145 1147
         compute_nodes, services = self.host_manager._get_computes_for_cells(
1146
-            context, self.host_manager.cells)
1148
+            context, self.host_manager.enabled_cells)
1147 1149
         hosts = self.host_manager._get_host_states(
1148 1150
             context, compute_nodes, services)
1149 1151
         host_states_map = {(state.host, state.nodename): state for state in

Loading…
Cancel
Save