Reduce the query time of the instances when call get_instance_list()
The problem is that watcher is passing limit=-1 to novaclient when listing servers which will always make at least two API calls to be sure it's done paging: https://github.com/openstack/python-novaclient/blob/13.0.1/novaclient/v2/servers.py#L896 If we can determine before we list servers that there are only a certain number where the number of servers is less than 1000. For example: 4, we should just pass the limit=len(servers) to novaclient and avoid the second call for paging which takes extra time and yields no results. Change-Id: I797ad934a0f8496dbcbf65798e28b0443f238137 Closes-Bug: #1834679
This commit is contained in:
@@ -114,4 +114,26 @@ class TestNovaClusterDataModelCollector(base.TestCase):
|
||||
m_nova_helper.get_compute_node_by_name.assert_called_once_with(
|
||||
minimal_node['hypervisor_hostname'], servers=True, detailed=True)
|
||||
m_nova_helper.get_instance_list.assert_called_once_with(
|
||||
{'host': fake_compute_node.service['host']})
|
||||
filters={'host': fake_compute_node.service['host']}, limit=1)
|
||||
|
||||
|
||||
class TestModelBuilder(base.TestCase):
|
||||
|
||||
@mock.patch.object(nova_helper, 'NovaHelper', mock.MagicMock())
|
||||
def test_add_instance_node(self):
|
||||
model_builder = nova.ModelBuilder(osc=mock.MagicMock())
|
||||
model_builder.model = mock.MagicMock()
|
||||
mock_node = mock.MagicMock()
|
||||
mock_host = mock_node.service["host"]
|
||||
mock_instances = [mock.MagicMock()]
|
||||
model_builder.add_instance_node(mock_node, mock_instances)
|
||||
# verify that when len(instances) <= 1000, limit == len(instance).
|
||||
model_builder.nova_helper.get_instance_list.assert_called_once_with(
|
||||
filters={'host': mock_host}, limit=1)
|
||||
|
||||
# verify that when len(instances) > 1000, limit == -1.
|
||||
mock_instance = mock.Mock()
|
||||
mock_instances = [mock_instance] * 1001
|
||||
model_builder.add_instance_node(mock_node, mock_instances)
|
||||
model_builder.nova_helper.get_instance_list.assert_called_with(
|
||||
filters={'host': mock_host}, limit=-1)
|
||||
|
||||
Reference in New Issue
Block a user