Optimize NovaClusterDataModelCollector.add_instance_node
This does two things: 1. Rather than make an API call per server on the host, get all of the servers in a single API call by filtering on the host. The os-hypervisors API results to use make this require a bit of refactoring since get_compute_node_by_name does not have the service entry in it and get_compute_node_by_id does not have the servers entry in it. A TODO is added to clean that up with a single call to os-hypervisors once we have the support in python-novaclient. 2. Pulls get_node_by_uuid() out of the loop. A test is added for the nova_helper get_instance_list method since one did not exist before. The fake compute node mocks in test_nova_cdmc_execute are also cleaned up since, as noted above, get_compute_node_by_name and get_compute_node_by_id don't both return all the details. Change-Id: Ifd9f83c2f399d4c1765b0c520f4d5a62ad0f5fbd
This commit is contained in:
committed by
Sergey Slabnov
parent
3b9364d4c7
commit
fdea38fb06
@@ -146,6 +146,22 @@ class TestNovaHelper(base.TestCase):
|
||||
nova_util.get_compute_node_by_hostname,
|
||||
hypervisor_name)
|
||||
|
||||
def test_get_instance_list(self, *args):
|
||||
nova_util = nova_helper.NovaHelper()
|
||||
# Call it once with no filters.
|
||||
with mock.patch.object(nova_util, 'nova') as nova_mock:
|
||||
result = nova_util.get_instance_list()
|
||||
nova_mock.servers.list.assert_called_once_with(
|
||||
search_opts={'all_tenants': True}, limit=-1)
|
||||
self.assertIs(result, nova_mock.servers.list.return_value)
|
||||
# Call it again with filters.
|
||||
with mock.patch.object(nova_util, 'nova') as nova_mock:
|
||||
result = nova_util.get_instance_list(filters={'host': 'fake-host'})
|
||||
nova_mock.servers.list.assert_called_once_with(
|
||||
search_opts={'all_tenants': True, 'host': 'fake-host'},
|
||||
limit=-1)
|
||||
self.assertIs(result, nova_mock.servers.list.return_value)
|
||||
|
||||
@mock.patch.object(time, 'sleep', mock.Mock())
|
||||
def test_stop_instance(self, mock_glance, mock_cinder, mock_neutron,
|
||||
mock_nova):
|
||||
|
||||
Reference in New Issue
Block a user