nodegroup list with --limit gives wrong next URL
This fixes the next url in the list nodegroups API response. Change-Id: Ice682bcf77c3ce1c8b1fbd12296eada63219e9e5 story: 2006851 task: 37442
This commit is contained in:
parent
9910925da9
commit
82d71cd8d0
|
@ -180,12 +180,13 @@ class NodeGroupCollection(collection.Collection):
|
||||||
self._type = 'nodegroups'
|
self._type = 'nodegroups'
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def convert(nodegroups, limit, expand=True, **kwargs):
|
def convert(nodegroups, cluster_id, limit, expand=True, **kwargs):
|
||||||
collection = NodeGroupCollection()
|
collection = NodeGroupCollection()
|
||||||
collection.nodegroups = [NodeGroup.convert(ng, expand)
|
collection.nodegroups = [NodeGroup.convert(ng, expand)
|
||||||
for ng in nodegroups]
|
for ng in nodegroups]
|
||||||
|
url = "clusters/%s/nodegroups" % cluster_id
|
||||||
collection.next = collection.get_next(limit,
|
collection.next = collection.get_next(limit,
|
||||||
marker_attribute='id',
|
url=url,
|
||||||
**kwargs)
|
**kwargs)
|
||||||
return collection
|
return collection
|
||||||
|
|
||||||
|
@ -217,13 +218,14 @@ class NodeGroupController(base.Controller):
|
||||||
filters=filters)
|
filters=filters)
|
||||||
|
|
||||||
return NodeGroupCollection.convert(nodegroups,
|
return NodeGroupCollection.convert(nodegroups,
|
||||||
|
cluster_id,
|
||||||
limit,
|
limit,
|
||||||
expand=expand,
|
expand=expand,
|
||||||
sort_key=sort_key,
|
sort_key=sort_key,
|
||||||
sort_dir=sort_dir)
|
sort_dir=sort_dir)
|
||||||
|
|
||||||
@base.Controller.api_version("1.9")
|
@base.Controller.api_version("1.9")
|
||||||
@expose.expose(NodeGroupCollection, types.uuid_or_name, int, int,
|
@expose.expose(NodeGroupCollection, types.uuid_or_name, types.uuid, int,
|
||||||
wtypes.text, wtypes.text, wtypes.text)
|
wtypes.text, wtypes.text, wtypes.text)
|
||||||
def get_all(self, cluster_id, marker=None, limit=None, sort_key='id',
|
def get_all(self, cluster_id, marker=None, limit=None, sort_key='id',
|
||||||
sort_dir='asc', role=None):
|
sort_dir='asc', role=None):
|
||||||
|
|
|
@ -114,11 +114,29 @@ class TestListNodegroups(NodeGroupControllerTest):
|
||||||
self._test_list_nodegroups(self.cluster.name, expected=expected)
|
self._test_list_nodegroups(self.cluster.name, expected=expected)
|
||||||
|
|
||||||
def test_get_all_with_pagination_marker(self):
|
def test_get_all_with_pagination_marker(self):
|
||||||
ng_uuid = self.cluster.default_ng_master.uuid
|
worker_ng_uuid = self.cluster.default_ng_worker.uuid
|
||||||
url = '/clusters/%s/nodegroups?limit=1&marker=1' % (self.cluster_uuid)
|
master_ng_uuid = self.cluster.default_ng_master.uuid
|
||||||
|
# First make sure that the api returns 1 ng and since they
|
||||||
|
# are sorted by id, the ng should be the default-worker
|
||||||
|
url = '/clusters/%s/nodegroups?limit=1' % (self.cluster_uuid)
|
||||||
response = self.get_json(url)
|
response = self.get_json(url)
|
||||||
self.assertEqual(1, len(response['nodegroups']))
|
self.assertEqual(1, len(response['nodegroups']))
|
||||||
self.assertEqual(ng_uuid, response['nodegroups'][0]['uuid'])
|
self.assertEqual(worker_ng_uuid, response['nodegroups'][0]['uuid'])
|
||||||
|
marker = "marker=%s" % worker_ng_uuid
|
||||||
|
self.assertIn(marker, response['next'])
|
||||||
|
# Now using the next url make sure that we get the default-master
|
||||||
|
next_url = response['next'].split('v1')[1]
|
||||||
|
response = self.get_json(next_url)
|
||||||
|
self.assertEqual(1, len(response['nodegroups']))
|
||||||
|
self.assertEqual(master_ng_uuid, response['nodegroups'][0]['uuid'])
|
||||||
|
marker = "marker=%s" % master_ng_uuid
|
||||||
|
self.assertIn(marker, response['next'])
|
||||||
|
# Now we should not get any other entry since the cluster only has two
|
||||||
|
# nodegroups and the marker is set at the default-master.
|
||||||
|
next_url = response['next'].split('v1')[1]
|
||||||
|
response = self.get_json(next_url)
|
||||||
|
self.assertEqual(0, len(response['nodegroups']))
|
||||||
|
self.assertNotIn('next', response)
|
||||||
|
|
||||||
def test_get_all_by_role(self):
|
def test_get_all_by_role(self):
|
||||||
filters = {'role': 'master'}
|
filters = {'role': 'master'}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- |
|
||||||
|
Fixes the next url in the list nodegroups API response.
|
Loading…
Reference in New Issue