From 2ac740e09d44bb91d0ec4180a1b5e500bc844f7c Mon Sep 17 00:00:00 2001 From: Arne Wiebalck Date: Mon, 17 Jan 2022 14:42:39 +0100 Subject: [PATCH] Set resource_url when getting all ports or portgroups Since the default value resource_url is None, make sure the parameter is set to 'ports' when getting all ports. Change-Id: Id603ae5a4a802dfc8f866b15c8d327d95eba9310 --- ironic/api/controllers/v1/port.py | 6 ++++-- ironic/api/controllers/v1/portgroup.py | 2 ++ ironic/tests/unit/api/controllers/v1/test_node.py | 2 ++ .../fix_pagination_resource_url_ports-8d2696a6a7ab012f.yaml | 6 ++++++ 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/fix_pagination_resource_url_ports-8d2696a6a7ab012f.yaml diff --git a/ironic/api/controllers/v1/port.py b/ironic/api/controllers/v1/port.py index eacbdf5dbe..0658fbf3fa 100644 --- a/ironic/api/controllers/v1/port.py +++ b/ironic/api/controllers/v1/port.py @@ -407,10 +407,12 @@ class PortsController(rest.RestController): and not uuidutils.is_uuid_like(node)): raise exception.NotAcceptable() + resource_url = 'ports' return self._get_ports_collection(node_uuid or node, address, portgroup, marker, limit, sort_key, - sort_dir, fields=fields, - detail=detail, project=project) + sort_dir, resource_url=resource_url, + fields=fields, detail=detail, + project=project) @METRICS.timer('PortsController.detail') @method.expose() diff --git a/ironic/api/controllers/v1/portgroup.py b/ironic/api/controllers/v1/portgroup.py index 9a2c2dc053..7900c46837 100644 --- a/ironic/api/controllers/v1/portgroup.py +++ b/ironic/api/controllers/v1/portgroup.py @@ -283,10 +283,12 @@ class PortgroupsController(pecan.rest.RestController): fields = api_utils.get_request_return_fields(fields, detail, _DEFAULT_RETURN_FIELDS) + resource_url = 'portgroups' return self._get_portgroups_collection(node, address, marker, limit, sort_key, sort_dir, fields=fields, + resource_url=resource_url, detail=detail, project=project) diff --git a/ironic/tests/unit/api/controllers/v1/test_node.py b/ironic/tests/unit/api/controllers/v1/test_node.py index 61eebc6dad..0f955a4275 100644 --- a/ironic/tests/unit/api/controllers/v1/test_node.py +++ b/ironic/tests/unit/api/controllers/v1/test_node.py @@ -1495,6 +1495,7 @@ class TestListNodes(test_api_base.BaseApiTest): headers=headers) self.assertEqual(1, len(data['portgroups'])) self.assertIn('next', data) + self.assertIn('portgroups', data['next']) def test_portgroups_subresource_link(self): node = obj_utils.create_test_node(self.context) @@ -1533,6 +1534,7 @@ class TestListNodes(test_api_base.BaseApiTest): data = self.get_json('/nodes/%s/ports?limit=1' % node.uuid) self.assertEqual(1, len(data['ports'])) self.assertIn('next', data) + self.assertIn('ports', data['next']) def test_ports_subresource_noid(self): node = obj_utils.create_test_node(self.context) diff --git a/releasenotes/notes/fix_pagination_resource_url_ports-8d2696a6a7ab012f.yaml b/releasenotes/notes/fix_pagination_resource_url_ports-8d2696a6a7ab012f.yaml new file mode 100644 index 0000000000..fc70d53c8a --- /dev/null +++ b/releasenotes/notes/fix_pagination_resource_url_ports-8d2696a6a7ab012f.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fixes an issue where clients would get a 404 due to the port and + portgroups pagination breaking at max_limit due to an uninitialised + resource_url.