Browse Source

Add functional regression test for bug 1849409

Change I1aa3ca6cc70cef65d24dec1e7db9491c9b73f7ab in Queens,
which was backported through to Newton, introduced a regression
when listing deleted servers with a marker because it assumes
that if BuildRequestList.get_by_filters does not raise
MarkerNotFound that the marker was found among the build requests
and does not account for that get_by_filters method short-circuiting
if filtering servers with deleted/cleaned/limit=0. The API code
then nulls out the marker which means you'll continue to get the
marker instance back in the results even though you shouldn't,
and that can cause an infinite loop in some client-side tooling like
nova's CLI:

  nova list --deleted --limit -1

This adds a functional recreate test for the regression which will
be updated when the bug is fixed.

NOTE(mriedem): In this backport the test is modified to disable the
DiskFilter since we're using Placement for filtering on DISK_GB.
Also, _wait_until_deleted is moved to InstanceHelperMixin since
If7b02bcd8d77e94c7fb42b721792c1391bc0e3b7 is not in Ocata.

Change-Id: I324193129acb6ac739133c7e76920762a8987a84
Related-Bug: #1849409
(cherry picked from commit 45c2752f2c)
(cherry picked from commit 727d942b28)
(cherry picked from commit 47caaccd4a)
(cherry picked from commit 08337cccb0)
(cherry picked from commit f03f5075e3)
(cherry picked from commit e2ba87cb7b)
changes/46/690746/2
Matt Riedemann 2 years ago
parent
commit
b6c7456fac
3 changed files with 92 additions and 14 deletions
  1. +14
    -0
      nova/tests/functional/integrated_helpers.py
  2. +0
    -14
      nova/tests/functional/notification_sample_tests/notification_sample_base.py
  3. +78
    -0
      nova/tests/functional/regressions/test_bug_1849409.py

+ 14
- 0
nova/tests/functional/integrated_helpers.py View File

@ -27,6 +27,7 @@ import nova.conf
import nova.image.glance
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.unit import cast_as_call
import nova.tests.unit.image.fake
from nova.tests import uuidsentinel as uuids
@ -256,6 +257,19 @@ class InstanceHelperMixin(object):
server['networks'] = networks
return server
def _wait_until_deleted(self, server):
try:
for i in range(40):
server = self.api.get_server(server['id'])
if server['status'] == 'ERROR':
self.fail('Server went to error state instead of'
'disappearing.')
time.sleep(0.5)
self.fail('Server failed to delete.')
except api_client.OpenStackApiNotFoundException:
return
def _wait_for_action_fail_completion(
self, server, expected_action, event_name, api=None):
"""Polls instance action events for the given instance, action and


+ 0
- 14
nova/tests/functional/notification_sample_tests/notification_sample_base.py View File

@ -21,7 +21,6 @@ from oslo_utils import fixture as utils_fixture
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.api.openstack.compute import test_services
from nova.tests.unit import fake_notifier
@ -175,19 +174,6 @@ class NotificationSampleTestBase(test.TestCase,
found_server['reservation_id'] = reservation_id
return found_server
def _wait_until_deleted(self, server):
try:
for i in range(40):
server = self.api.get_server(server['id'])
if server['status'] == 'ERROR':
self.fail('Server went to error state instead of'
'disappearing.')
time.sleep(0.5)
self.fail('Server failed to delete.')
except api_client.OpenStackApiNotFoundException:
return
def _get_notifications(self, event_type):
return [notification for notification
in fake_notifier.VERSIONED_NOTIFICATIONS


+ 78
- 0
nova/tests/functional/regressions/test_bug_1849409.py View File

@ -0,0 +1,78 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from nova import config
from nova import test
from nova.tests import fixtures as nova_fixtures
from nova.tests.functional import integrated_helpers
from nova.tests.unit.image import fake as fake_image
from nova import utils
CONF = config.CONF
class ListDeletedServersWithMarker(test.TestCase,
integrated_helpers.InstanceHelperMixin):
"""Regression test for bug 1849409 introduced in Queens where listing
deleted servers with a marker returns the wrong results because the marker
is nulled out if BuildRequestList.get_by_filters does not raise
MarkerNotFound, but that does not mean the marker was found in the build
request list.
"""
def setUp(self):
super(ListDeletedServersWithMarker, self).setUp()
# Start standard fixtures.
self.useFixture(nova_fixtures.PlacementFixture())
self.useFixture(nova_fixtures.NeutronFixture(self))
fake_image.stub_out_image_service(self)
self.addCleanup(fake_image.FakeImageService_reset)
# Start nova services.
self.api = self.useFixture(nova_fixtures.OSAPIFixture(
api_version='v2.1')).admin_api
self.start_service('conductor')
enabled_filters = CONF.filter_scheduler.enabled_filters
# Remove the DiskFilter since we're using Placement for filtering on
# DISK_GB.
if 'DiskFilter' in enabled_filters:
enabled_filters.remove('DiskFilter')
self.flags(enabled_filters=enabled_filters, group='filter_scheduler')
self.start_service('scheduler')
self.start_service('compute')
def test_list_deleted_servers_with_marker(self):
# Create a server.
server = self._build_minimal_create_server_request(
self.api, 'test_list_deleted_servers_with_marker',
image_uuid=fake_image.get_valid_image_id(),
networks='none')
# networks='none' requires microversion >= 2.37
with utils.temporary_mutation(self.api, microversion='2.37'):
server = self.api.post_server({'server': server})
server = self._wait_for_state_change(self.api, server, 'ACTIVE')
# Now delete the server and wait for it to be gone.
self.api.delete_server(server['id'])
self._wait_until_deleted(server)
# List deleted servers, we should get the one back.
servers = self.api.get_servers(detail=False,
search_opts={'deleted': True,
'name': server['name']})
self.assertEqual(1, len(servers), servers)
self.assertEqual(server['id'], servers[0]['id'])
# Now list deleted servers with a marker which should not return the
# marker instance.
servers = self.api.get_servers(detail=False,
search_opts={'deleted': True,
'marker': server['id']})
# FIXME(mriedem): This is bug 1849409 where the marker param is not
# honored correctly when using deleted=True.
server_names = [serv['name'] for serv in servers]
self.assertIn(server['name'], server_names)

Loading…
Cancel
Save