Merge "functional: Make '_IntegratedTestBase' subclass 'InstanceHelperMixin'"

This commit is contained in:
Zuul 2020-01-09 14:28:59 +00:00 committed by Gerrit Code Review
commit 83622d389e
16 changed files with 19 additions and 104 deletions

View File

@ -53,7 +53,7 @@ CONF = nova.conf.CONF
class ApiSampleTestBaseV21(testscenarios.WithScenarios,
api_samples_test_base.ApiSampleTestBase):
api_samples_test_base.ApiSampleTestBase):
SUPPORTS_CELLS = False
api_major_version = 'v2'

View File

@ -15,11 +15,10 @@
from nova.tests.functional.api_sample_tests import test_servers
from nova.tests.functional import api_samples_test_base
from nova.tests.functional import integrated_helpers
class ServerActionsSampleJsonTest(test_servers.ServersSampleBase,
integrated_helpers.InstanceHelperMixin):
class ServerActionsSampleJsonTest(test_servers.ServersSampleBase):
microversion = None
ADMIN_API = True
sample_dir = 'os-instance-actions'

View File

@ -15,11 +15,9 @@
from nova.tests import fixtures
from nova.tests.functional.api_sample_tests import api_sample_base
from nova.tests.functional import integrated_helpers
class MultinicSampleJsonTest(integrated_helpers.InstanceHelperMixin,
api_sample_base.ApiSampleTestBaseV21):
class MultinicSampleJsonTest(api_sample_base.ApiSampleTestBaseV21):
ADMIN_API = True
sample_dir = "os-multinic"

View File

@ -38,8 +38,7 @@ class FakeCinderError(object):
raise exception.CinderConnectionFailed(reason='Fake Cinder error')
class LiveMigrationCinderFailure(integrated_helpers._IntegratedTestBase,
integrated_helpers.InstanceHelperMixin):
class LiveMigrationCinderFailure(integrated_helpers._IntegratedTestBase):
api_major_version = 'v2.1'
microversion = 'latest'
@ -47,7 +46,7 @@ class LiveMigrationCinderFailure(integrated_helpers._IntegratedTestBase,
super(LiveMigrationCinderFailure, self).setUp()
fake_notifier.stub_notifier(self)
self.addCleanup(fake_notifier.reset)
# Start a second compte node (the first one was started for us by
# Start a second compute node (the first one was started for us by
# _IntegratedTestBase. set_nodes() is needed to avoid duplicate
# nodenames. See comments in test_bug_1702454.py.
self.compute2 = self.start_service('compute', host='host2')

View File

@ -55,8 +55,7 @@ def _verify_list_fulfillment(context, instance_uuid):
class VirtualInterfaceListMigrationTestCase(
integrated_helpers._IntegratedTestBase,
integrated_helpers.InstanceHelperMixin):
integrated_helpers._IntegratedTestBase):
ADMIN_API = True
api_major_version = 'v2.1'

View File

@ -242,7 +242,7 @@ class InstanceHelperMixin(object):
return api.post_aggregate(body)['id']
class _IntegratedTestBase(test.TestCase):
class _IntegratedTestBase(test.TestCase, InstanceHelperMixin):
REQUIRES_LOCKING = True
ADMIN_API = False
# This indicates whether to include the project ID in the URL for API
@ -320,37 +320,6 @@ class _IntegratedTestBase(test.TestCase):
return (generate_new_element(flavor_names, 'flavor'),
int(generate_new_element(flavor_ids, '', True)))
def _build_minimal_create_server_request(self, name=None, image_uuid=None,
flavor_id=None, networks=None,
az=None, host=None):
server = {}
if not image_uuid:
# NOTE(takashin): In API version 2.36, image APIs were deprecated.
# In API version 2.36 or greater, self.api.get_images() returns
# a 404 error. In that case, 'image_uuid' should be specified.
image_uuid = self.api.get_images()[0]['id']
server['imageRef'] = image_uuid
if not name:
name = ''.join(
random.choice(string.ascii_lowercase) for i in range(10))
server['name'] = name
if not flavor_id:
# Set a valid flavorId
flavor_id = self.api.get_flavors()[0]['id']
server['flavorRef'] = 'http://fake.server/%s' % flavor_id
if networks is not None:
server['networks'] = networks
if az is not None:
server['availability_zone'] = az
# This requires at least microversion 2.74 to work
if host is not None:
server['host'] = host
return server
def _create_flavor_body(self, name, ram, vcpus, disk, ephemeral, id, swap,
rxtx_factor, is_public):
return {

View File

@ -16,8 +16,7 @@ from nova.tests import fixtures as nova_fixtures
from nova.tests.functional import integrated_helpers
class DeleteWithReservedVolumes(integrated_helpers._IntegratedTestBase,
integrated_helpers.InstanceHelperMixin):
class DeleteWithReservedVolumes(integrated_helpers._IntegratedTestBase):
"""Test deleting of an instance in error state that has a reserved volume.
This test boots a server from volume which will fail to be scheduled,

View File

@ -15,8 +15,7 @@ from nova import objects
from nova.tests.functional import integrated_helpers
class ResizeEvacuateTestCase(integrated_helpers._IntegratedTestBase,
integrated_helpers.InstanceHelperMixin):
class ResizeEvacuateTestCase(integrated_helpers._IntegratedTestBase):
"""Regression test for bug 1669054 introduced in Newton.
When resizing a server, if CONF.allow_resize_to_same_host is False,

View File

@ -19,8 +19,7 @@ from nova.tests.functional import integrated_helpers
CONF = nova.conf.CONF
class RebuildVolumeBackedSameImage(integrated_helpers._IntegratedTestBase,
integrated_helpers.InstanceHelperMixin):
class RebuildVolumeBackedSameImage(integrated_helpers._IntegratedTestBase):
"""Tests the regression in bug 1732947 where rebuilding a volume-backed
instance with the original image still results in conductor calling the
scheduler to validate the image. This is because the instance.image_ref

View File

@ -14,8 +14,7 @@ from nova.tests import fixtures as nova_fixtures
from nova.tests.functional import integrated_helpers
class MultiCellEvacuateTestCase(integrated_helpers._IntegratedTestBase,
integrated_helpers.InstanceHelperMixin):
class MultiCellEvacuateTestCase(integrated_helpers._IntegratedTestBase):
"""Recreate test for bug 1823370 which was introduced in Pike.
When evacuating a server, the request to the scheduler should be restricted

View File

@ -838,7 +838,7 @@ class TestAggregateFiltersTogether(AggregateRequestFiltersTest):
class TestAggregateMultiTenancyIsolationFilter(
test.TestCase, integrated_helpers.InstanceHelperMixin):
test.TestCase, integrated_helpers.InstanceHelperMixin):
def _start_compute(self, host):
self.start_service('compute', host=host)

View File

@ -25,8 +25,7 @@ from nova.tests.unit.image import fake as fake_image
from nova.tests.unit import policy_fixture
class BootFromVolumeTest(integrated_helpers.InstanceHelperMixin,
test_servers.ServersTestBase):
class BootFromVolumeTest(test_servers.ServersTestBase):
def _get_hypervisor_stats(self):
response = self.admin_api.api_get('/os-hypervisors/statistics')
@ -118,8 +117,7 @@ class BootFromVolumeTest(integrated_helpers.InstanceHelperMixin,
# Shelve
post_data = {'shelve': None}
self.api.post_server_action(server_id, post_data)
self._wait_for_state_change(created_server,
'SHELVED_OFFLOADED')
self._wait_for_state_change(created_server, 'SHELVED_OFFLOADED')
# Check that hypervisor local disk reporting is still 0
self._verify_zero_local_gb_used()

View File

@ -16,12 +16,10 @@ import six
from nova.tests import fixtures as nova_fixtures
from nova.tests.functional.api import client
from nova.tests.functional import integrated_helpers
from nova.tests.functional import test_servers
class ConfigurableMaxDiskDevicesTest(integrated_helpers.InstanceHelperMixin,
test_servers.ServersTestBase):
class ConfigurableMaxDiskDevicesTest(test_servers.ServersTestBase):
def setUp(self):
super(ConfigurableMaxDiskDevicesTest, self).setUp()
self.cinder = self.useFixture(

View File

@ -15,8 +15,7 @@ from nova.tests import fixtures as nova_fixtures
from nova.tests.functional import integrated_helpers
class TestMultiattachVolumes(integrated_helpers._IntegratedTestBase,
integrated_helpers.InstanceHelperMixin):
class TestMultiattachVolumes(integrated_helpers._IntegratedTestBase):
"""Functional tests for creating a server from a multiattach volume
and attaching a multiattach volume to a server.

View File

@ -1430,9 +1430,7 @@ class TestDBArchiveDeletedRows(integrated_helpers._IntegratedTestBase):
# Now delete one server and then we can archive.
server = self.api.get_server(server['id'])
self.api.delete_server(server['id'])
helper = integrated_helpers.InstanceHelperMixin()
helper.api = self.api
helper._wait_until_deleted(server)
self._wait_until_deleted(server)
# Now archive.
self.cli.archive_deleted_rows(verbose=True)
# Assert only one instance_group_member record was deleted.

View File

@ -75,43 +75,6 @@ class ServersTestBase(integrated_helpers._IntegratedTestBase):
self.computes = {}
super(ServersTestBase, self).setUp()
def _wait_for_server_parameter(self, server, expected_params,
max_retries=10):
api = getattr(self, 'admin_api', self.api)
retry_count = 0
while True:
server = api.get_server(server['id'])
if all([server[attr] == expected_params[attr]
for attr in expected_params]):
break
retry_count += 1
if retry_count == max_retries:
self.fail('Wait for state change failed, '
'expected_params=%s, server=%s' % (
expected_params, server))
time.sleep(0.5)
return server
def _wait_for_state_change(self, server, expected_status, max_retries=10):
return self._wait_for_server_parameter(
server, {'status': expected_status}, max_retries)
# TODO(stephenfin): Remove this once we subclass 'InstanceHelperMixin'
def _wait_until_deleted(self, server):
initially_in_error = server.get('status') == 'ERROR'
try:
for i in range(40):
server = self.api.get_server(server['id'])
if not initially_in_error and server['status'] == 'ERROR':
self.fail('Server went to error state instead of'
'disappearing.')
time.sleep(0.5)
self.fail('Server failed to delete.')
except client.OpenStackApiNotFoundException:
return
def _delete_server(self, server):
# Delete the server
self.api.delete_server(server['id'])
@ -1366,8 +1329,7 @@ class ServerTestV269(ServersTestBase):
self.assertIn('image', server)
class ServerRebuildTestCase(integrated_helpers._IntegratedTestBase,
integrated_helpers.InstanceHelperMixin):
class ServerRebuildTestCase(integrated_helpers._IntegratedTestBase):
api_major_version = 'v2.1'
# We have to cap the microversion at 2.38 because that's the max we
# can use to update image metadata via our compute images proxy API.