From 2ef704cba619a149336692311c2614742aa32909 Mon Sep 17 00:00:00 2001 From: Andrey Volkov Date: Wed, 12 Dec 2018 09:11:17 +0300 Subject: [PATCH] Exclude build request marker from server listing When listing "real" (already in cell) instances e.g. from nova_cell1.instances table, a marker option means "start after the instance with marker". For VMs: | uuid | name | | 1 | vm1 | | 2 | vm2 | "openstack server list --marker 1" returns vm2 only. But for VMs from nova_api.build_requests table it's different. For VMs: | uuid | name | | 1 | vm1 | | 2 | vm2 | "openstack server list --marker 1" returns both vm1 and vm2. This patch excludes instance with marker from listing for instances from build_requests table. Closes-Bug: #1808286 Change-Id: I5165b69f956fbf1904112a742698b2739f747e72 --- nova/objects/build_request.py | 5 ++++- .../tests/functional/db/test_build_request.py | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/nova/objects/build_request.py b/nova/objects/build_request.py index 38006c50f63b..32c6c99a6eab 100644 --- a/nova/objects/build_request.py +++ b/nova/objects/build_request.py @@ -445,7 +445,10 @@ class BuildRequestList(base.ObjectListBase, base.NovaObject): if marker: for i, build_req in enumerate(sorted_build_reqs): if build_req.instance.uuid == marker: - marker_index = i + # The marker is the last seen item in the last page, so + # we increment the index to the next item immediately + # after the marker so the marker is not returned. + marker_index = i + 1 break else: raise exception.MarkerNotFound(marker=marker) diff --git a/nova/tests/functional/db/test_build_request.py b/nova/tests/functional/db/test_build_request.py index e34109cd8931..71e9091fd280 100644 --- a/nova/tests/functional/db/test_build_request.py +++ b/nova/tests/functional/db/test_build_request.py @@ -520,11 +520,14 @@ class BuildRequestListTestCase(test.NoDBTestCase): sort_dirs=['asc']) self.assertIsInstance(req_list, objects.BuildRequestList) - self.assertEqual(2, len(req_list)) - for i, req in enumerate(reqs[1:]): - self.assertEqual(req.instance_uuid, req_list[i].instance_uuid) - objects.base.obj_equal_prims(req.instance, - req_list[i].instance) + self.assertEqual(1, len(req_list)) + req = req_list[0] + expected_req = reqs[2] + # The returned build request should be the last one in the reqs list + # since the marker is the 2nd item in the list (of 3). + self.assertEqual(expected_req.instance_uuid, req.instance_uuid) + objects.base.obj_equal_prims(expected_req.instance, + req.instance) def test_get_by_filters_marker_not_found(self): self._create_req() @@ -565,7 +568,7 @@ class BuildRequestListTestCase(test.NoDBTestCase): self.assertIsInstance(req_list, objects.BuildRequestList) self.assertEqual(2, len(req_list)) - for i, req in enumerate(reqs[1:3]): + for i, req in enumerate(reqs[2:]): self.assertEqual(req.instance_uuid, req_list[i].instance_uuid) objects.base.obj_equal_prims(req.instance, req_list[i].instance) @@ -585,8 +588,8 @@ class BuildRequestListTestCase(test.NoDBTestCase): sort_keys=['id'], sort_dirs=['asc']) self.assertIsInstance(req_list, objects.BuildRequestList) - self.assertEqual(3, len(req_list)) - for i, req in enumerate(reqs[1:]): + self.assertEqual(2, len(req_list)) + for i, req in enumerate(reqs[2:]): self.assertEqual(req.instance_uuid, req_list[i].instance_uuid) objects.base.obj_equal_prims(req.instance, req_list[i].instance)