Browse Source

Merge "Delete unused get_all_host_states method" into stable/stein

changes/19/679519/1
Zuul 3 weeks ago
parent
commit
6a1927bfb1
2 changed files with 83 additions and 68 deletions
  1. 0
    9
      nova/scheduler/host_manager.py
  2. 83
    59
      nova/tests/unit/scheduler/test_host_manager.py

+ 0
- 9
nova/scheduler/host_manager.py View File

@@ -693,15 +693,6 @@ class HostManager(object):
693 693
             context, cells, compute_uuids=compute_uuids)
694 694
         return self._get_host_states(context, compute_nodes, services)
695 695
 
696
-    def get_all_host_states(self, context):
697
-        """Returns a generator of HostStates that represents all the hosts
698
-        the HostManager knows about. Also, each of the consumable resources
699
-        in HostState are pre-populated and adjusted based on data in the db.
700
-        """
701
-        compute_nodes, services = self._get_computes_for_cells(context,
702
-                                                               self.cells)
703
-        return self._get_host_states(context, compute_nodes, services)
704
-
705 696
     def _get_host_states(self, context, compute_nodes, services):
706 697
         """Returns a generator over HostStates given a list of computes.
707 698
 

+ 83
- 59
nova/tests/unit/scheduler/test_host_manager.py View File

@@ -539,16 +539,19 @@ class HostManagerTestCase(test.NoDBTestCase):
539 539
     @mock.patch('nova.objects.ServiceList.get_by_binary')
540 540
     @mock.patch('nova.objects.ComputeNodeList.get_all')
541 541
     @mock.patch('nova.objects.InstanceList.get_uuids_by_host')
542
-    def test_get_all_host_states(self, mock_get_by_host, mock_get_all,
543
-                                 mock_get_by_binary, mock_log):
542
+    def test_get_host_states(self, mock_get_by_host, mock_get_all,
543
+                             mock_get_by_binary, mock_log):
544 544
         mock_get_by_host.return_value = []
545 545
         mock_get_all.return_value = fakes.COMPUTE_NODES
546 546
         mock_get_by_binary.return_value = fakes.SERVICES
547 547
         context = 'fake_context'
548
+        compute_nodes, services = self.host_manager._get_computes_for_cells(
549
+            context, self.host_manager.cells)
548 550
 
549
-        # get_all_host_states returns a generator, so make a map from it
551
+        # _get_host_states returns a generator, so make a map from it
550 552
         host_states_map = {(state.host, state.nodename): state for state in
551
-                           self.host_manager.get_all_host_states(context)}
553
+                           self.host_manager._get_host_states(
554
+                               context, compute_nodes, services)}
552 555
         self.assertEqual(4, len(host_states_map))
553 556
 
554 557
         calls = [
@@ -598,17 +601,22 @@ class HostManagerTestCase(test.NoDBTestCase):
598 601
     @mock.patch.object(host_manager.HostState, '_update_from_compute_node')
599 602
     @mock.patch.object(objects.ComputeNodeList, 'get_all')
600 603
     @mock.patch.object(objects.ServiceList, 'get_by_binary')
601
-    def test_get_all_host_states_with_no_aggs(self, svc_get_by_binary,
602
-                                              cn_get_all, update_from_cn,
603
-                                              mock_get_by_host):
604
+    def test_get_host_states_with_no_aggs(self, svc_get_by_binary,
605
+                                          cn_get_all, update_from_cn,
606
+                                          mock_get_by_host):
604 607
         svc_get_by_binary.return_value = [objects.Service(host='fake')]
605 608
         cn_get_all.return_value = [
606 609
             objects.ComputeNode(host='fake', hypervisor_hostname='fake')]
607 610
         mock_get_by_host.return_value = []
608 611
         self.host_manager.host_aggregates_map = collections.defaultdict(set)
609 612
 
610
-        hosts = self.host_manager.get_all_host_states('fake-context')
611
-        # get_all_host_states returns a generator, so make a map from it
613
+        context = nova_context.get_admin_context()
614
+        compute_nodes, services = self.host_manager._get_computes_for_cells(
615
+            context, self.host_manager.cells)
616
+
617
+        hosts = self.host_manager._get_host_states(
618
+            context, compute_nodes, services)
619
+        # _get_host_states returns a generator, so make a map from it
612 620
         host_states_map = {(state.host, state.nodename): state for state in
613 621
                            hosts}
614 622
         host_state = host_states_map[('fake', 'fake')]
@@ -618,10 +626,10 @@ class HostManagerTestCase(test.NoDBTestCase):
618 626
     @mock.patch.object(host_manager.HostState, '_update_from_compute_node')
619 627
     @mock.patch.object(objects.ComputeNodeList, 'get_all')
620 628
     @mock.patch.object(objects.ServiceList, 'get_by_binary')
621
-    def test_get_all_host_states_with_matching_aggs(self, svc_get_by_binary,
622
-                                                    cn_get_all,
623
-                                                    update_from_cn,
624
-                                                    mock_get_by_host):
629
+    def test_get_host_states_with_matching_aggs(self, svc_get_by_binary,
630
+                                                cn_get_all,
631
+                                                update_from_cn,
632
+                                                mock_get_by_host):
625 633
         svc_get_by_binary.return_value = [objects.Service(host='fake')]
626 634
         cn_get_all.return_value = [
627 635
             objects.ComputeNode(host='fake', hypervisor_hostname='fake')]
@@ -631,8 +639,13 @@ class HostManagerTestCase(test.NoDBTestCase):
631 639
             set, {'fake': set([1])})
632 640
         self.host_manager.aggs_by_id = {1: fake_agg}
633 641
 
634
-        hosts = self.host_manager.get_all_host_states('fake-context')
635
-        # get_all_host_states returns a generator, so make a map from it
642
+        context = nova_context.get_admin_context()
643
+        compute_nodes, services = self.host_manager._get_computes_for_cells(
644
+            context, self.host_manager.cells)
645
+
646
+        hosts = self.host_manager._get_host_states(
647
+            context, compute_nodes, services)
648
+        # _get_host_states returns a generator, so make a map from it
636 649
         host_states_map = {(state.host, state.nodename): state for state in
637 650
                            hosts}
638 651
         host_state = host_states_map[('fake', 'fake')]
@@ -642,11 +655,10 @@ class HostManagerTestCase(test.NoDBTestCase):
642 655
     @mock.patch.object(host_manager.HostState, '_update_from_compute_node')
643 656
     @mock.patch.object(objects.ComputeNodeList, 'get_all')
644 657
     @mock.patch.object(objects.ServiceList, 'get_by_binary')
645
-    def test_get_all_host_states_with_not_matching_aggs(self,
646
-                                                        svc_get_by_binary,
647
-                                                        cn_get_all,
648
-                                                        update_from_cn,
649
-                                                        mock_get_by_host):
658
+    def test_get_host_states_with_not_matching_aggs(self, svc_get_by_binary,
659
+                                                    cn_get_all,
660
+                                                    update_from_cn,
661
+                                                    mock_get_by_host):
650 662
         svc_get_by_binary.return_value = [objects.Service(host='fake'),
651 663
                                           objects.Service(host='other')]
652 664
         cn_get_all.return_value = [
@@ -658,8 +670,13 @@ class HostManagerTestCase(test.NoDBTestCase):
658 670
             set, {'other': set([1])})
659 671
         self.host_manager.aggs_by_id = {1: fake_agg}
660 672
 
661
-        hosts = self.host_manager.get_all_host_states('fake-context')
662
-        # get_all_host_states returns a generator, so make a map from it
673
+        context = nova_context.get_admin_context()
674
+        compute_nodes, services = self.host_manager._get_computes_for_cells(
675
+            context, self.host_manager.cells)
676
+
677
+        hosts = self.host_manager._get_host_states(
678
+            context, compute_nodes, services)
679
+        # _get_host_states returns a generator, so make a map from it
663 680
         host_states_map = {(state.host, state.nodename): state for state in
664 681
                            hosts}
665 682
         host_state = host_states_map[('fake', 'fake')]
@@ -670,11 +687,10 @@ class HostManagerTestCase(test.NoDBTestCase):
670 687
     @mock.patch.object(host_manager.HostState, '_update_from_compute_node')
671 688
     @mock.patch.object(objects.ComputeNodeList, 'get_all')
672 689
     @mock.patch.object(objects.ServiceList, 'get_by_binary')
673
-    def test_get_all_host_states_corrupt_aggregates_info(self,
674
-                                                         svc_get_by_binary,
675
-                                                         cn_get_all,
676
-                                                         update_from_cn,
677
-                                                         mock_get_by_host):
690
+    def test_get_host_states_corrupt_aggregates_info(self, svc_get_by_binary,
691
+                                                     cn_get_all,
692
+                                                     update_from_cn,
693
+                                                     mock_get_by_host):
678 694
         """Regression test for bug 1605804
679 695
 
680 696
         A host can be in multiple host-aggregates at the same time. When a
@@ -700,16 +716,14 @@ class HostManagerTestCase(test.NoDBTestCase):
700 716
         aggregate.hosts = [host_a]
701 717
         self.host_manager.delete_aggregate(aggregate)
702 718
 
703
-        self.host_manager.get_all_host_states('fake-context')
719
+        context = nova_context.get_admin_context()
720
+        compute_nodes, services = self.host_manager._get_computes_for_cells(
721
+            context, self.host_manager.cells)
722
+
723
+        self.host_manager._get_host_states(context, compute_nodes, services)
704 724
 
705
-    @mock.patch('nova.objects.ServiceList.get_by_binary')
706
-    @mock.patch('nova.objects.ComputeNodeList.get_all')
707 725
     @mock.patch('nova.objects.InstanceList.get_by_host')
708
-    def test_get_all_host_states_updated(self, mock_get_by_host,
709
-                                         mock_get_all_comp,
710
-                                         mock_get_svc_by_binary):
711
-        mock_get_all_comp.return_value = fakes.COMPUTE_NODES
712
-        mock_get_svc_by_binary.return_value = fakes.SERVICES
726
+    def test_host_state_update(self, mock_get_by_host):
713 727
         context = 'fake_context'
714 728
         hm = self.host_manager
715 729
         inst1 = objects.Instance(uuid=uuids.instance)
@@ -725,14 +739,8 @@ class HostManagerTestCase(test.NoDBTestCase):
725 739
         self.assertTrue(host_state.instances)
726 740
         self.assertEqual(host_state.instances[uuids.instance], inst1)
727 741
 
728
-    @mock.patch('nova.objects.ServiceList.get_by_binary')
729
-    @mock.patch('nova.objects.ComputeNodeList.get_all')
730 742
     @mock.patch('nova.objects.InstanceList.get_uuids_by_host')
731
-    def test_get_all_host_states_not_updated(self, mock_get_by_host,
732
-                                             mock_get_all_comp,
733
-                                             mock_get_svc_by_binary):
734
-        mock_get_all_comp.return_value = fakes.COMPUTE_NODES
735
-        mock_get_svc_by_binary.return_value = fakes.SERVICES
743
+    def test_host_state_not_updated(self, mock_get_by_host):
736 744
         context = 'fake_context'
737 745
         hm = self.host_manager
738 746
         inst1 = objects.Instance(uuid=uuids.instance)
@@ -1061,24 +1069,28 @@ class HostManagerChangedNodesTestCase(test.NoDBTestCase):
1061 1069
     @mock.patch('nova.objects.ServiceList.get_by_binary')
1062 1070
     @mock.patch('nova.objects.ComputeNodeList.get_all')
1063 1071
     @mock.patch('nova.objects.InstanceList.get_uuids_by_host')
1064
-    def test_get_all_host_states(self, mock_get_by_host, mock_get_all,
1065
-                                 mock_get_by_binary):
1072
+    def test_get_host_states(self, mock_get_by_host, mock_get_all,
1073
+                             mock_get_by_binary):
1066 1074
         mock_get_by_host.return_value = []
1067 1075
         mock_get_all.return_value = fakes.COMPUTE_NODES
1068 1076
         mock_get_by_binary.return_value = fakes.SERVICES
1069 1077
         context = 'fake_context'
1070 1078
 
1071
-        # get_all_host_states returns a generator, so make a map from it
1079
+        compute_nodes, services = self.host_manager._get_computes_for_cells(
1080
+            context, self.host_manager.cells)
1081
+
1082
+        # _get_host_states returns a generator, so make a map from it
1072 1083
         host_states_map = {(state.host, state.nodename): state for state in
1073
-                           self.host_manager.get_all_host_states(context)}
1084
+                           self.host_manager._get_host_states(
1085
+                               context, compute_nodes, services)}
1074 1086
         self.assertEqual(len(host_states_map), 4)
1075 1087
 
1076 1088
     @mock.patch('nova.objects.ServiceList.get_by_binary')
1077 1089
     @mock.patch('nova.objects.ComputeNodeList.get_all')
1078 1090
     @mock.patch('nova.objects.InstanceList.get_uuids_by_host')
1079
-    def test_get_all_host_states_after_delete_one(self, mock_get_by_host,
1080
-                                                  mock_get_all,
1081
-                                                  mock_get_by_binary):
1091
+    def test_get_host_states_after_delete_one(self, mock_get_by_host,
1092
+                                              mock_get_all,
1093
+                                              mock_get_by_binary):
1082 1094
         getter = (lambda n: n.hypervisor_hostname
1083 1095
                   if 'hypervisor_hostname' in n else None)
1084 1096
         running_nodes = [n for n in fakes.COMPUTE_NODES
@@ -1090,14 +1102,20 @@ class HostManagerChangedNodesTestCase(test.NoDBTestCase):
1090 1102
         context = 'fake_context'
1091 1103
 
1092 1104
         # first call: all nodes
1093
-        hosts = self.host_manager.get_all_host_states(context)
1094
-        # get_all_host_states returns a generator, so make a map from it
1105
+        compute_nodes, services = self.host_manager._get_computes_for_cells(
1106
+            context, self.host_manager.cells)
1107
+        hosts = self.host_manager._get_host_states(
1108
+            context, compute_nodes, services)
1109
+        # _get_host_states returns a generator, so make a map from it
1095 1110
         host_states_map = {(state.host, state.nodename): state for state in
1096 1111
                            hosts}
1097 1112
         self.assertEqual(len(host_states_map), 4)
1098 1113
 
1099 1114
         # second call: just running nodes
1100
-        hosts = self.host_manager.get_all_host_states(context)
1115
+        compute_nodes, services = self.host_manager._get_computes_for_cells(
1116
+            context, self.host_manager.cells)
1117
+        hosts = self.host_manager._get_host_states(
1118
+            context, compute_nodes, services)
1101 1119
         host_states_map = {(state.host, state.nodename): state for state in
1102 1120
                            hosts}
1103 1121
         self.assertEqual(len(host_states_map), 3)
@@ -1105,23 +1123,29 @@ class HostManagerChangedNodesTestCase(test.NoDBTestCase):
1105 1123
     @mock.patch('nova.objects.ServiceList.get_by_binary')
1106 1124
     @mock.patch('nova.objects.ComputeNodeList.get_all')
1107 1125
     @mock.patch('nova.objects.InstanceList.get_uuids_by_host')
1108
-    def test_get_all_host_states_after_delete_all(self, mock_get_by_host,
1109
-                                                  mock_get_all,
1110
-                                                  mock_get_by_binary):
1126
+    def test_get_host_states_after_delete_all(self, mock_get_by_host,
1127
+                                              mock_get_all,
1128
+                                              mock_get_by_binary):
1111 1129
         mock_get_by_host.return_value = []
1112 1130
         mock_get_all.side_effect = [fakes.COMPUTE_NODES, []]
1113 1131
         mock_get_by_binary.side_effect = [fakes.SERVICES, fakes.SERVICES]
1114 1132
         context = 'fake_context'
1115 1133
 
1116 1134
         # first call: all nodes
1117
-        hosts = self.host_manager.get_all_host_states(context)
1118
-        # get_all_host_states returns a generator, so make a map from it
1135
+        compute_nodes, services = self.host_manager._get_computes_for_cells(
1136
+            context, self.host_manager.cells)
1137
+        hosts = self.host_manager._get_host_states(
1138
+            context, compute_nodes, services)
1139
+        # _get_host_states returns a generator, so make a map from it
1119 1140
         host_states_map = {(state.host, state.nodename): state for state in
1120 1141
                            hosts}
1121 1142
         self.assertEqual(len(host_states_map), 4)
1122 1143
 
1123 1144
         # second call: no nodes
1124
-        hosts = self.host_manager.get_all_host_states(context)
1145
+        compute_nodes, services = self.host_manager._get_computes_for_cells(
1146
+            context, self.host_manager.cells)
1147
+        hosts = self.host_manager._get_host_states(
1148
+            context, compute_nodes, services)
1125 1149
         host_states_map = {(state.host, state.nodename): state for state in
1126 1150
                            hosts}
1127 1151
         self.assertEqual(len(host_states_map), 0)
@@ -1161,7 +1185,7 @@ class HostStateTestCase(test.NoDBTestCase):
1161 1185
     """Test case for HostState class."""
1162 1186
 
1163 1187
     # update_from_compute_node() and consume_from_request() are tested
1164
-    # in HostManagerTestCase.test_get_all_host_states()
1188
+    # in HostManagerTestCase.test_get_host_states()
1165 1189
 
1166 1190
     @mock.patch('nova.utils.synchronized',
1167 1191
                 side_effect=lambda a: lambda f: lambda *args: f(*args))

Loading…
Cancel
Save