Merge "Delete unused get_all_host_states method"

This commit is contained in:
Zuul
2019-06-08 11:40:21 +00:00
committed by Gerrit Code Review
2 changed files with 83 additions and 68 deletions

View File

@@ -754,15 +754,6 @@ class HostManager(object):
context, cells, compute_uuids=compute_uuids)
return self._get_host_states(context, compute_nodes, services)
def get_all_host_states(self, context):
"""Returns a generator of HostStates that represents all the hosts
the HostManager knows about. Also, each of the consumable resources
in HostState are pre-populated and adjusted based on data in the db.
"""
compute_nodes, services = self._get_computes_for_cells(context,
self.cells)
return self._get_host_states(context, compute_nodes, services)
def _get_host_states(self, context, compute_nodes, services):
"""Returns a generator over HostStates given a list of computes.

View File

@@ -539,16 +539,19 @@ class HostManagerTestCase(test.NoDBTestCase):
@mock.patch('nova.objects.ServiceList.get_by_binary')
@mock.patch('nova.objects.ComputeNodeList.get_all')
@mock.patch('nova.objects.InstanceList.get_uuids_by_host')
def test_get_all_host_states(self, mock_get_by_host, mock_get_all,
def test_get_host_states(self, mock_get_by_host, mock_get_all,
mock_get_by_binary, mock_log):
mock_get_by_host.return_value = []
mock_get_all.return_value = fakes.COMPUTE_NODES
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)
# get_all_host_states returns a generator, so make a map from it
# _get_host_states returns a generator, so make a map from it
host_states_map = {(state.host, state.nodename): state for state in
self.host_manager.get_all_host_states(context)}
self.host_manager._get_host_states(
context, compute_nodes, services)}
self.assertEqual(4, len(host_states_map))
calls = [
@@ -598,7 +601,7 @@ class HostManagerTestCase(test.NoDBTestCase):
@mock.patch.object(host_manager.HostState, '_update_from_compute_node')
@mock.patch.object(objects.ComputeNodeList, 'get_all')
@mock.patch.object(objects.ServiceList, 'get_by_binary')
def test_get_all_host_states_with_no_aggs(self, svc_get_by_binary,
def test_get_host_states_with_no_aggs(self, svc_get_by_binary,
cn_get_all, update_from_cn,
mock_get_by_host):
svc_get_by_binary.return_value = [objects.Service(host='fake')]
@@ -607,8 +610,13 @@ class HostManagerTestCase(test.NoDBTestCase):
mock_get_by_host.return_value = []
self.host_manager.host_aggregates_map = collections.defaultdict(set)
hosts = self.host_manager.get_all_host_states('fake-context')
# get_all_host_states returns a generator, so make a map from it
context = nova_context.get_admin_context()
compute_nodes, services = self.host_manager._get_computes_for_cells(
context, self.host_manager.cells)
hosts = self.host_manager._get_host_states(
context, compute_nodes, services)
# _get_host_states returns a generator, so make a map from it
host_states_map = {(state.host, state.nodename): state for state in
hosts}
host_state = host_states_map[('fake', 'fake')]
@@ -618,7 +626,7 @@ class HostManagerTestCase(test.NoDBTestCase):
@mock.patch.object(host_manager.HostState, '_update_from_compute_node')
@mock.patch.object(objects.ComputeNodeList, 'get_all')
@mock.patch.object(objects.ServiceList, 'get_by_binary')
def test_get_all_host_states_with_matching_aggs(self, svc_get_by_binary,
def test_get_host_states_with_matching_aggs(self, svc_get_by_binary,
cn_get_all,
update_from_cn,
mock_get_by_host):
@@ -631,8 +639,13 @@ class HostManagerTestCase(test.NoDBTestCase):
set, {'fake': set([1])})
self.host_manager.aggs_by_id = {1: fake_agg}
hosts = self.host_manager.get_all_host_states('fake-context')
# get_all_host_states returns a generator, so make a map from it
context = nova_context.get_admin_context()
compute_nodes, services = self.host_manager._get_computes_for_cells(
context, self.host_manager.cells)
hosts = self.host_manager._get_host_states(
context, compute_nodes, services)
# _get_host_states returns a generator, so make a map from it
host_states_map = {(state.host, state.nodename): state for state in
hosts}
host_state = host_states_map[('fake', 'fake')]
@@ -642,8 +655,7 @@ class HostManagerTestCase(test.NoDBTestCase):
@mock.patch.object(host_manager.HostState, '_update_from_compute_node')
@mock.patch.object(objects.ComputeNodeList, 'get_all')
@mock.patch.object(objects.ServiceList, 'get_by_binary')
def test_get_all_host_states_with_not_matching_aggs(self,
svc_get_by_binary,
def test_get_host_states_with_not_matching_aggs(self, svc_get_by_binary,
cn_get_all,
update_from_cn,
mock_get_by_host):
@@ -658,8 +670,13 @@ class HostManagerTestCase(test.NoDBTestCase):
set, {'other': set([1])})
self.host_manager.aggs_by_id = {1: fake_agg}
hosts = self.host_manager.get_all_host_states('fake-context')
# get_all_host_states returns a generator, so make a map from it
context = nova_context.get_admin_context()
compute_nodes, services = self.host_manager._get_computes_for_cells(
context, self.host_manager.cells)
hosts = self.host_manager._get_host_states(
context, compute_nodes, services)
# _get_host_states returns a generator, so make a map from it
host_states_map = {(state.host, state.nodename): state for state in
hosts}
host_state = host_states_map[('fake', 'fake')]
@@ -670,8 +687,7 @@ class HostManagerTestCase(test.NoDBTestCase):
@mock.patch.object(host_manager.HostState, '_update_from_compute_node')
@mock.patch.object(objects.ComputeNodeList, 'get_all')
@mock.patch.object(objects.ServiceList, 'get_by_binary')
def test_get_all_host_states_corrupt_aggregates_info(self,
svc_get_by_binary,
def test_get_host_states_corrupt_aggregates_info(self, svc_get_by_binary,
cn_get_all,
update_from_cn,
mock_get_by_host):
@@ -700,16 +716,14 @@ class HostManagerTestCase(test.NoDBTestCase):
aggregate.hosts = [host_a]
self.host_manager.delete_aggregate(aggregate)
self.host_manager.get_all_host_states('fake-context')
context = nova_context.get_admin_context()
compute_nodes, services = self.host_manager._get_computes_for_cells(
context, self.host_manager.cells)
self.host_manager._get_host_states(context, compute_nodes, services)
@mock.patch('nova.objects.ServiceList.get_by_binary')
@mock.patch('nova.objects.ComputeNodeList.get_all')
@mock.patch('nova.objects.InstanceList.get_by_host')
def test_get_all_host_states_updated(self, mock_get_by_host,
mock_get_all_comp,
mock_get_svc_by_binary):
mock_get_all_comp.return_value = fakes.COMPUTE_NODES
mock_get_svc_by_binary.return_value = fakes.SERVICES
def test_host_state_update(self, mock_get_by_host):
context = 'fake_context'
hm = self.host_manager
inst1 = objects.Instance(uuid=uuids.instance)
@@ -725,14 +739,8 @@ class HostManagerTestCase(test.NoDBTestCase):
self.assertTrue(host_state.instances)
self.assertEqual(host_state.instances[uuids.instance], inst1)
@mock.patch('nova.objects.ServiceList.get_by_binary')
@mock.patch('nova.objects.ComputeNodeList.get_all')
@mock.patch('nova.objects.InstanceList.get_uuids_by_host')
def test_get_all_host_states_not_updated(self, mock_get_by_host,
mock_get_all_comp,
mock_get_svc_by_binary):
mock_get_all_comp.return_value = fakes.COMPUTE_NODES
mock_get_svc_by_binary.return_value = fakes.SERVICES
def test_host_state_not_updated(self, mock_get_by_host):
context = 'fake_context'
hm = self.host_manager
inst1 = objects.Instance(uuid=uuids.instance)
@@ -1155,22 +1163,26 @@ class HostManagerChangedNodesTestCase(test.NoDBTestCase):
@mock.patch('nova.objects.ServiceList.get_by_binary')
@mock.patch('nova.objects.ComputeNodeList.get_all')
@mock.patch('nova.objects.InstanceList.get_uuids_by_host')
def test_get_all_host_states(self, mock_get_by_host, mock_get_all,
def test_get_host_states(self, mock_get_by_host, mock_get_all,
mock_get_by_binary):
mock_get_by_host.return_value = []
mock_get_all.return_value = fakes.COMPUTE_NODES
mock_get_by_binary.return_value = fakes.SERVICES
context = 'fake_context'
# get_all_host_states returns a generator, so make a map from it
compute_nodes, services = self.host_manager._get_computes_for_cells(
context, self.host_manager.cells)
# _get_host_states returns a generator, so make a map from it
host_states_map = {(state.host, state.nodename): state for state in
self.host_manager.get_all_host_states(context)}
self.host_manager._get_host_states(
context, compute_nodes, services)}
self.assertEqual(len(host_states_map), 4)
@mock.patch('nova.objects.ServiceList.get_by_binary')
@mock.patch('nova.objects.ComputeNodeList.get_all')
@mock.patch('nova.objects.InstanceList.get_uuids_by_host')
def test_get_all_host_states_after_delete_one(self, mock_get_by_host,
def test_get_host_states_after_delete_one(self, mock_get_by_host,
mock_get_all,
mock_get_by_binary):
getter = (lambda n: n.hypervisor_hostname
@@ -1184,14 +1196,20 @@ class HostManagerChangedNodesTestCase(test.NoDBTestCase):
context = 'fake_context'
# first call: all nodes
hosts = self.host_manager.get_all_host_states(context)
# get_all_host_states returns a generator, so make a map from it
compute_nodes, services = self.host_manager._get_computes_for_cells(
context, self.host_manager.cells)
hosts = self.host_manager._get_host_states(
context, compute_nodes, services)
# _get_host_states returns a generator, so make a map from it
host_states_map = {(state.host, state.nodename): state for state in
hosts}
self.assertEqual(len(host_states_map), 4)
# second call: just running nodes
hosts = self.host_manager.get_all_host_states(context)
compute_nodes, services = self.host_manager._get_computes_for_cells(
context, self.host_manager.cells)
hosts = self.host_manager._get_host_states(
context, compute_nodes, services)
host_states_map = {(state.host, state.nodename): state for state in
hosts}
self.assertEqual(len(host_states_map), 3)
@@ -1199,7 +1217,7 @@ class HostManagerChangedNodesTestCase(test.NoDBTestCase):
@mock.patch('nova.objects.ServiceList.get_by_binary')
@mock.patch('nova.objects.ComputeNodeList.get_all')
@mock.patch('nova.objects.InstanceList.get_uuids_by_host')
def test_get_all_host_states_after_delete_all(self, mock_get_by_host,
def test_get_host_states_after_delete_all(self, mock_get_by_host,
mock_get_all,
mock_get_by_binary):
mock_get_by_host.return_value = []
@@ -1208,14 +1226,20 @@ class HostManagerChangedNodesTestCase(test.NoDBTestCase):
context = 'fake_context'
# first call: all nodes
hosts = self.host_manager.get_all_host_states(context)
# get_all_host_states returns a generator, so make a map from it
compute_nodes, services = self.host_manager._get_computes_for_cells(
context, self.host_manager.cells)
hosts = self.host_manager._get_host_states(
context, compute_nodes, services)
# _get_host_states returns a generator, so make a map from it
host_states_map = {(state.host, state.nodename): state for state in
hosts}
self.assertEqual(len(host_states_map), 4)
# second call: no nodes
hosts = self.host_manager.get_all_host_states(context)
compute_nodes, services = self.host_manager._get_computes_for_cells(
context, self.host_manager.cells)
hosts = self.host_manager._get_host_states(
context, compute_nodes, services)
host_states_map = {(state.host, state.nodename): state for state in
hosts}
self.assertEqual(len(host_states_map), 0)
@@ -1255,7 +1279,7 @@ class HostStateTestCase(test.NoDBTestCase):
"""Test case for HostState class."""
# update_from_compute_node() and consume_from_request() are tested
# in HostManagerTestCase.test_get_all_host_states()
# in HostManagerTestCase.test_get_host_states()
@mock.patch('nova.utils.synchronized',
side_effect=lambda a: lambda f: lambda *args: f(*args))