From dbaf80d2c94db074a6651c890d532a11baec8da0 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Fri, 26 May 2017 17:48:10 -0400 Subject: [PATCH] Fix MarkerNotFound when paging and marker was found in cell0 If we're paging over cells and the marker was found in cell0, we need to null it out so we don't attempt to lookup by marker from any other cells if there is more room in the limit. Change-Id: I8a957bebfcecd6ac712103c346e028d80f1ecd7c Closes-Bug: #1689692 --- nova/compute/api.py | 3 +++ .../functional/regressions/test_bug_1689692.py | 17 +++++------------ nova/tests/unit/compute/test_compute_api.py | 4 ++-- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/nova/compute/api.py b/nova/compute/api.py index 7a27ae352d8e..0468afd46607 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -2555,6 +2555,9 @@ class API(base.Base): cctxt, filters, limit=limit, marker=marker, expected_attrs=expected_attrs, sort_keys=sort_keys, sort_dirs=sort_dirs) + # If we found the marker in cell0 we need to set it to None + # so we don't expect to find it in the cells below. + marker = None except exception.MarkerNotFound: # We can ignore this since we need to look in the cell DB cell0_instances = objects.InstanceList(objects=[]) diff --git a/nova/tests/functional/regressions/test_bug_1689692.py b/nova/tests/functional/regressions/test_bug_1689692.py index b349ddb75937..f70bcec89189 100644 --- a/nova/tests/functional/regressions/test_bug_1689692.py +++ b/nova/tests/functional/regressions/test_bug_1689692.py @@ -14,7 +14,6 @@ from nova import test from nova.tests import fixtures as nova_fixtures -from nova.tests.functional.api import client as api_client from nova.tests.functional import integrated_helpers from nova.tests.unit import cast_as_call from nova.tests.unit.image import fake as image_fake @@ -62,8 +61,7 @@ class ServerListLimitMarkerCell0Test(test.TestCase, def test_list_servers_marker_in_cell0_more_limit(self): """Creates three servers, then lists them with a marker on the first and a limit of 3 which is more than what's left to page on (2) but - it shouldn't fail, it should just give the other two back. But due - to the bug we'll get a 400 since the marker isn't in cell1. + it shouldn't fail, it should just give the other two back. """ # create three test servers for x in range(3): @@ -80,12 +78,7 @@ class ServerListLimitMarkerCell0Test(test.TestCase, # Take the first server and user that as our marker. marker = servers[0]['id'] # Since we're paging after the first server as our marker, there are - # only two left so specifying three should just return two. However, - # due to the bug, we're going to get a MarkerNotFound error when trying - # to page to the cell1 database and the marker isn't there. Assert - # we get two servers back once the bug is fixed. - ex = self.assertRaises(api_client.OpenStackApiException, - self.api.get_servers, - search_opts=dict(marker=marker, limit=3)) - self.assertEqual(400, ex.response.status_code) - self.assertIn('marker [%s] not found' % marker, ex.message) + # only two left so specifying three should just return two. + servers = self.api.get_servers(search_opts=dict(marker=marker, + limit=3)) + self.assertEqual(2, len(servers)) diff --git a/nova/tests/unit/compute/test_compute_api.py b/nova/tests/unit/compute/test_compute_api.py index d7fab7136ca0..75513bba8aaa 100644 --- a/nova/tests/unit/compute/test_compute_api.py +++ b/nova/tests/unit/compute/test_compute_api.py @@ -4696,7 +4696,7 @@ class _ComputeAPIUnitTestMixIn(object): expected_attrs=None, sort_keys=['baz'], sort_dirs=['desc']), mock.call(mock.ANY, {'foo': 'bar'}, - limit=8, marker='fake-marker', + limit=8, marker=None, expected_attrs=None, sort_keys=['baz'], sort_dirs=['desc']) ] @@ -4753,7 +4753,7 @@ class _ComputeAPIUnitTestMixIn(object): expected_attrs=None, sort_keys=['baz'], sort_dirs=['desc']), mock.call(mock.ANY, {'foo': 'bar'}, - limit=6, marker='fake-marker', + limit=6, marker=None, expected_attrs=None, sort_keys=['baz'], sort_dirs=['desc']) ]