Add functional regression test for list deleted instances on v2.16
There is a bug such that listing deleted instances with microversion 2.16 and greater is broken. It results in a 404. This adds a functional regression test to exhibit the failure. The fix will build on the test to show it's working again. Change-Id: Ifca42c23e2ead2b533776365de29f874819cb2a8 Related-Bug: #1548980
This commit is contained in:
parent
19f13c8f37
commit
d6c3347655
|
@ -0,0 +1,88 @@
|
|||
# Copyright 2016 IBM Corp.
|
||||
#
|
||||
# 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.
|
||||
|
||||
import time
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
import nova.scheduler.utils
|
||||
import nova.servicegroup
|
||||
from nova import test
|
||||
from nova.tests import fixtures as nova_fixtures
|
||||
from nova.tests.functional.api import client
|
||||
from nova.tests.unit import cast_as_call
|
||||
import nova.tests.unit.image.fake
|
||||
from nova.tests.unit import policy_fixture
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class TestServerGet(test.TestCase):
|
||||
REQUIRES_LOCKING = True
|
||||
|
||||
def setUp(self):
|
||||
super(TestServerGet, self).setUp()
|
||||
self.useFixture(policy_fixture.RealPolicyFixture())
|
||||
api_fixture = self.useFixture(nova_fixtures.OSAPIFixture(
|
||||
api_version='v2.1'))
|
||||
|
||||
# The non-admin API client is fine to stay at 2.1 since it just creates
|
||||
# and deletes the server.
|
||||
self.api = api_fixture.api
|
||||
self.admin_api = api_fixture.admin_api
|
||||
# The admin API client needs to be at microversion 2.16 to exhibit the
|
||||
# regression.
|
||||
self.admin_api.microversion = '2.16'
|
||||
|
||||
# the image fake backend needed for image discovery
|
||||
nova.tests.unit.image.fake.stub_out_image_service(self)
|
||||
|
||||
self.start_service('conductor', manager=CONF.conductor.manager)
|
||||
self.flags(scheduler_driver='chance_scheduler')
|
||||
self.start_service('scheduler')
|
||||
self.network = self.start_service('network')
|
||||
self.compute = self.start_service('compute')
|
||||
self.consoleauth = self.start_service('consoleauth')
|
||||
|
||||
self.useFixture(cast_as_call.CastAsCall(self.stubs))
|
||||
self.addCleanup(nova.tests.unit.image.fake.FakeImageService_reset)
|
||||
|
||||
self.image_id = self.api.get_images()[0]['id']
|
||||
self.flavor_id = self.api.get_flavors()[0]['id']
|
||||
|
||||
def test_list_deleted_instances(self):
|
||||
"""Regression test for bug #1548980.
|
||||
|
||||
Before fixing this bug, listing deleted instances returned a 404
|
||||
because lazy-loading services from a deleted instance failed. Now
|
||||
we should be able to list the deleted instance and the host_state
|
||||
attribute should be "".
|
||||
"""
|
||||
server = dict(name='server1',
|
||||
imageRef=self.image_id,
|
||||
flavorRef=self.flavor_id)
|
||||
server = self.api.post_server({'server': server})
|
||||
self.api.delete_server(server['id'])
|
||||
# Wait 30 seconds for it to be gone.
|
||||
for x in range(30):
|
||||
try:
|
||||
self.api.get_server(server['id'])
|
||||
time.sleep(1)
|
||||
except client.OpenStackApiNotFoundException:
|
||||
break
|
||||
else:
|
||||
self.fail('Timed out waiting to delete server: %s' % server['id'])
|
||||
self.assertRaises(client.OpenStackApiNotFoundException,
|
||||
self.admin_api.get_servers,
|
||||
search_opts={'deleted': 1})
|
Loading…
Reference in New Issue