Skip to content

Commit 1316c1c

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Delete unused get_all_host_states method"
2 parents e9d7b1c + d7ba0d0 commit 1316c1c

File tree

2 files changed

+83
-68
lines changed

2 files changed

+83
-68
lines changed

nova/scheduler/host_manager.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -754,15 +754,6 @@ def get_host_states_by_uuids(self, context, compute_uuids, spec_obj):
754754
context, cells, compute_uuids=compute_uuids)
755755
return self._get_host_states(context, compute_nodes, services)
756756

757-
def get_all_host_states(self, context):
758-
"""Returns a generator of HostStates that represents all the hosts
759-
the HostManager knows about. Also, each of the consumable resources
760-
in HostState are pre-populated and adjusted based on data in the db.
761-
"""
762-
compute_nodes, services = self._get_computes_for_cells(context,
763-
self.cells)
764-
return self._get_host_states(context, compute_nodes, services)
765-
766757
def _get_host_states(self, context, compute_nodes, services):
767758
"""Returns a generator over HostStates given a list of computes.
768759

nova/tests/unit/scheduler/test_host_manager.py

Lines changed: 83 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -539,16 +539,19 @@ def test_get_filtered_hosts_with_ignore_hosts_and_force_same_nodes(self):
539539
@mock.patch('nova.objects.ServiceList.get_by_binary')
540540
@mock.patch('nova.objects.ComputeNodeList.get_all')
541541
@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):
544544
mock_get_by_host.return_value = []
545545
mock_get_all.return_value = fakes.COMPUTE_NODES
546546
mock_get_by_binary.return_value = fakes.SERVICES
547547
context = 'fake_context'
548+
compute_nodes, services = self.host_manager._get_computes_for_cells(
549+
context, self.host_manager.cells)
548550

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
550552
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)}
552555
self.assertEqual(4, len(host_states_map))
553556

554557
calls = [
@@ -598,17 +601,22 @@ def test_get_all_host_states(self, mock_get_by_host, mock_get_all,
598601
@mock.patch.object(host_manager.HostState, '_update_from_compute_node')
599602
@mock.patch.object(objects.ComputeNodeList, 'get_all')
600603
@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):
604607
svc_get_by_binary.return_value = [objects.Service(host='fake')]
605608
cn_get_all.return_value = [
606609
objects.ComputeNode(host='fake', hypervisor_hostname='fake')]
607610
mock_get_by_host.return_value = []
608611
self.host_manager.host_aggregates_map = collections.defaultdict(set)
609612

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
612620
host_states_map = {(state.host, state.nodename): state for state in
613621
hosts}
614622
host_state = host_states_map[('fake', 'fake')]
@@ -618,10 +626,10 @@ def test_get_all_host_states_with_no_aggs(self, svc_get_by_binary,
618626
@mock.patch.object(host_manager.HostState, '_update_from_compute_node')
619627
@mock.patch.object(objects.ComputeNodeList, 'get_all')
620628
@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):
625633
svc_get_by_binary.return_value = [objects.Service(host='fake')]
626634
cn_get_all.return_value = [
627635
objects.ComputeNode(host='fake', hypervisor_hostname='fake')]
@@ -631,8 +639,13 @@ def test_get_all_host_states_with_matching_aggs(self, svc_get_by_binary,
631639
set, {'fake': set([1])})
632640
self.host_manager.aggs_by_id = {1: fake_agg}
633641

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
636649
host_states_map = {(state.host, state.nodename): state for state in
637650
hosts}
638651
host_state = host_states_map[('fake', 'fake')]
@@ -642,11 +655,10 @@ def test_get_all_host_states_with_matching_aggs(self, svc_get_by_binary,
642655
@mock.patch.object(host_manager.HostState, '_update_from_compute_node')
643656
@mock.patch.object(objects.ComputeNodeList, 'get_all')
644657
@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):
650662
svc_get_by_binary.return_value = [objects.Service(host='fake'),
651663
objects.Service(host='other')]
652664
cn_get_all.return_value = [
@@ -658,8 +670,13 @@ def test_get_all_host_states_with_not_matching_aggs(self,
658670
set, {'other': set([1])})
659671
self.host_manager.aggs_by_id = {1: fake_agg}
660672

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
663680
host_states_map = {(state.host, state.nodename): state for state in
664681
hosts}
665682
host_state = host_states_map[('fake', 'fake')]
@@ -670,11 +687,10 @@ def test_get_all_host_states_with_not_matching_aggs(self,
670687
@mock.patch.object(host_manager.HostState, '_update_from_compute_node')
671688
@mock.patch.object(objects.ComputeNodeList, 'get_all')
672689
@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):
678694
"""Regression test for bug 1605804
679695
680696
A host can be in multiple host-aggregates at the same time. When a
@@ -700,16 +716,14 @@ def test_get_all_host_states_corrupt_aggregates_info(self,
700716
aggregate.hosts = [host_a]
701717
self.host_manager.delete_aggregate(aggregate)
702718

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)
704724

705-
@mock.patch('nova.objects.ServiceList.get_by_binary')
706-
@mock.patch('nova.objects.ComputeNodeList.get_all')
707725
@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):
713727
context = 'fake_context'
714728
hm = self.host_manager
715729
inst1 = objects.Instance(uuid=uuids.instance)
@@ -725,14 +739,8 @@ def test_get_all_host_states_updated(self, mock_get_by_host,
725739
self.assertTrue(host_state.instances)
726740
self.assertEqual(host_state.instances[uuids.instance], inst1)
727741

728-
@mock.patch('nova.objects.ServiceList.get_by_binary')
729-
@mock.patch('nova.objects.ComputeNodeList.get_all')
730742
@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):
736744
context = 'fake_context'
737745
hm = self.host_manager
738746
inst1 = objects.Instance(uuid=uuids.instance)
@@ -1155,24 +1163,28 @@ def setUp(self, mock_init_agg, mock_init_inst):
11551163
@mock.patch('nova.objects.ServiceList.get_by_binary')
11561164
@mock.patch('nova.objects.ComputeNodeList.get_all')
11571165
@mock.patch('nova.objects.InstanceList.get_uuids_by_host')
1158-
def test_get_all_host_states(self, mock_get_by_host, mock_get_all,
1159-
mock_get_by_binary):
1166+
def test_get_host_states(self, mock_get_by_host, mock_get_all,
1167+
mock_get_by_binary):
11601168
mock_get_by_host.return_value = []
11611169
mock_get_all.return_value = fakes.COMPUTE_NODES
11621170
mock_get_by_binary.return_value = fakes.SERVICES
11631171
context = 'fake_context'
11641172

1165-
# get_all_host_states returns a generator, so make a map from it
1173+
compute_nodes, services = self.host_manager._get_computes_for_cells(
1174+
context, self.host_manager.cells)
1175+
1176+
# _get_host_states returns a generator, so make a map from it
11661177
host_states_map = {(state.host, state.nodename): state for state in
1167-
self.host_manager.get_all_host_states(context)}
1178+
self.host_manager._get_host_states(
1179+
context, compute_nodes, services)}
11681180
self.assertEqual(len(host_states_map), 4)
11691181

11701182
@mock.patch('nova.objects.ServiceList.get_by_binary')
11711183
@mock.patch('nova.objects.ComputeNodeList.get_all')
11721184
@mock.patch('nova.objects.InstanceList.get_uuids_by_host')
1173-
def test_get_all_host_states_after_delete_one(self, mock_get_by_host,
1174-
mock_get_all,
1175-
mock_get_by_binary):
1185+
def test_get_host_states_after_delete_one(self, mock_get_by_host,
1186+
mock_get_all,
1187+
mock_get_by_binary):
11761188
getter = (lambda n: n.hypervisor_hostname
11771189
if 'hypervisor_hostname' in n else None)
11781190
running_nodes = [n for n in fakes.COMPUTE_NODES
@@ -1184,38 +1196,50 @@ def test_get_all_host_states_after_delete_one(self, mock_get_by_host,
11841196
context = 'fake_context'
11851197

11861198
# first call: all nodes
1187-
hosts = self.host_manager.get_all_host_states(context)
1188-
# get_all_host_states returns a generator, so make a map from it
1199+
compute_nodes, services = self.host_manager._get_computes_for_cells(
1200+
context, self.host_manager.cells)
1201+
hosts = self.host_manager._get_host_states(
1202+
context, compute_nodes, services)
1203+
# _get_host_states returns a generator, so make a map from it
11891204
host_states_map = {(state.host, state.nodename): state for state in
11901205
hosts}
11911206
self.assertEqual(len(host_states_map), 4)
11921207

11931208
# second call: just running nodes
1194-
hosts = self.host_manager.get_all_host_states(context)
1209+
compute_nodes, services = self.host_manager._get_computes_for_cells(
1210+
context, self.host_manager.cells)
1211+
hosts = self.host_manager._get_host_states(
1212+
context, compute_nodes, services)
11951213
host_states_map = {(state.host, state.nodename): state for state in
11961214
hosts}
11971215
self.assertEqual(len(host_states_map), 3)
11981216

11991217
@mock.patch('nova.objects.ServiceList.get_by_binary')
12001218
@mock.patch('nova.objects.ComputeNodeList.get_all')
12011219
@mock.patch('nova.objects.InstanceList.get_uuids_by_host')
1202-
def test_get_all_host_states_after_delete_all(self, mock_get_by_host,
1203-
mock_get_all,
1204-
mock_get_by_binary):
1220+
def test_get_host_states_after_delete_all(self, mock_get_by_host,
1221+
mock_get_all,
1222+
mock_get_by_binary):
12051223
mock_get_by_host.return_value = []
12061224
mock_get_all.side_effect = [fakes.COMPUTE_NODES, []]
12071225
mock_get_by_binary.side_effect = [fakes.SERVICES, fakes.SERVICES]
12081226
context = 'fake_context'
12091227

12101228
# first call: all nodes
1211-
hosts = self.host_manager.get_all_host_states(context)
1212-
# get_all_host_states returns a generator, so make a map from it
1229+
compute_nodes, services = self.host_manager._get_computes_for_cells(
1230+
context, self.host_manager.cells)
1231+
hosts = self.host_manager._get_host_states(
1232+
context, compute_nodes, services)
1233+
# _get_host_states returns a generator, so make a map from it
12131234
host_states_map = {(state.host, state.nodename): state for state in
12141235
hosts}
12151236
self.assertEqual(len(host_states_map), 4)
12161237

12171238
# second call: no nodes
1218-
hosts = self.host_manager.get_all_host_states(context)
1239+
compute_nodes, services = self.host_manager._get_computes_for_cells(
1240+
context, self.host_manager.cells)
1241+
hosts = self.host_manager._get_host_states(
1242+
context, compute_nodes, services)
12191243
host_states_map = {(state.host, state.nodename): state for state in
12201244
hosts}
12211245
self.assertEqual(len(host_states_map), 0)
@@ -1255,7 +1279,7 @@ class HostStateTestCase(test.NoDBTestCase):
12551279
"""Test case for HostState class."""
12561280

12571281
# update_from_compute_node() and consume_from_request() are tested
1258-
# in HostManagerTestCase.test_get_all_host_states()
1282+
# in HostManagerTestCase.test_get_host_states()
12591283

12601284
@mock.patch('nova.utils.synchronized',
12611285
side_effect=lambda a: lambda f: lambda *args: f(*args))

0 commit comments

Comments
 (0)