Skip to content

Commit

Permalink
Ironic: Continue pagination when listing nodes
Browse files Browse the repository at this point in the history
Ironic API supports pagination and limit the number of items returned
by the API based on a config option, by default a max of 1000 items is
returned per request. The Ironic client library by default respect that
limit, so when the Nova Ironic driver list the nodes it might hit that
limit and the wrong information will be passed to nova.

This patch fix the problem by passing a "limit=0" flag to the client
library to tell it to continue pagination until there're no more nodes
ot be returned.

Change-Id: I63795e2b4de828fa41e97812e99a714f04d2f580
Closes-Bug: #1367349
  • Loading branch information
umago committed Oct 15, 2014
1 parent c3b2ee3 commit c9ac589
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 4 additions & 4 deletions nova/tests/virt/ironic/test_driver.py
Expand Up @@ -351,7 +351,7 @@ def test_list_instances(self, mock_inst_by_uuid, mock_call):
mock_call.return_value = nodes

response = self.driver.list_instances()
mock_call.assert_called_with("node.list", associated=True)
mock_call.assert_called_with("node.list", associated=True, limit=0)
expected_calls = [mock.call(mock.ANY, instances[0].uuid),
mock.call(mock.ANY, instances[1].uuid)]
mock_inst_by_uuid.assert_has_calls(expected_calls)
Expand All @@ -368,7 +368,7 @@ def test_list_instance_uuids(self, mock_call):

mock_call.return_value = nodes
uuids = self.driver.list_instance_uuids()
mock_call.assert_called_with('node.list', associated=True)
mock_call.assert_called_with('node.list', associated=True, limit=0)
expected = [n.instance_uuid for n in nodes]
self.assertEqual(sorted(expected), sorted(uuids))

Expand All @@ -381,7 +381,7 @@ def test_node_is_available_empty_cache_empty_list(self, mock_get,
mock_list.return_value = []
self.assertTrue(self.driver.node_is_available(node.uuid))
mock_get.assert_called_with(node.uuid)
mock_list.assert_called_with(detail=True)
mock_list.assert_called_with(detail=True, limit=0)

mock_get.side_effect = ironic_exception.NotFound
self.assertFalse(self.driver.node_is_available(node.uuid))
Expand All @@ -393,7 +393,7 @@ def test_node_is_available_empty_cache(self, mock_get, mock_list):
mock_get.return_value = node
mock_list.return_value = [node]
self.assertTrue(self.driver.node_is_available(node.uuid))
mock_list.assert_called_with(detail=True)
mock_list.assert_called_with(detail=True, limit=0)
self.assertEqual(0, mock_get.call_count)

@mock.patch.object(FAKE_CLIENT.node, 'list')
Expand Down
12 changes: 9 additions & 3 deletions nova/virt/ironic/driver.py
Expand Up @@ -400,7 +400,9 @@ def list_instances(self):
"""
ironicclient = client_wrapper.IronicClientWrapper()
node_list = ironicclient.call("node.list", associated=True)
# NOTE(lucasagomes): limit == 0 is an indicator to continue
# pagination until there're no more values to be returned.
node_list = ironicclient.call("node.list", associated=True, limit=0)
context = nova_context.get_admin_context()
return [objects.Instance.get_by_uuid(context,
i.instance_uuid).name
Expand All @@ -413,7 +415,9 @@ def list_instance_uuids(self):
"""
ironicclient = client_wrapper.IronicClientWrapper()
node_list = ironicclient.call("node.list", associated=True)
# NOTE(lucasagomes): limit == 0 is an indicator to continue
# pagination until there're no more values to be returned.
node_list = ironicclient.call("node.list", associated=True, limit=0)
return list(n.instance_uuid for n in node_list)

def node_is_available(self, nodename):
Expand Down Expand Up @@ -446,7 +450,9 @@ def node_is_available(self, nodename):

def _refresh_cache(self):
ironicclient = client_wrapper.IronicClientWrapper()
node_list = ironicclient.call('node.list', detail=True)
# NOTE(lucasagomes): limit == 0 is an indicator to continue
# pagination until there're no more values to be returned.
node_list = ironicclient.call('node.list', detail=True, limit=0)
node_cache = {}
for node in node_list:
node_cache[node.uuid] = node
Expand Down

0 comments on commit c9ac589

Please sign in to comment.