Moving API microversion fixture in resource_setup

API microversion fixture is used to set the API
microversion on service client and reset it back
after test execution. That is done in setUp()
method and due to that API microversion is not
set on service client during resource_setup()
method and any API call will be requested on base
version.

To sync the complete test execution of test class
with requested API microversion, this commit moves
the API microversion setting in resource_setup()
method.

Closes-Bug: #1881863

Change-Id: Ia4b884a79cc0e50057dd57090737332bd76da37e
changes/32/820932/7
Ghanshyam Mann 10 months ago
parent 93a902072f
commit 18b45d7285
  1. 13
      tempest/api/compute/base.py
  2. 10
      tempest/api/volume/base.py
  3. 11
      tempest/scenario/manager.py
  4. 29
      tempest/test.py
  5. 186
      tempest/tests/test_test.py

@ -21,7 +21,6 @@ from tempest.common import compute
from tempest.common import waiters
from tempest import config
from tempest import exceptions
from tempest.lib.common import api_microversion_fixture
from tempest.lib.common import api_version_request
from tempest.lib.common import api_version_utils
from tempest.lib.common.utils import data_utils
@ -164,6 +163,11 @@ class BaseV2ComputeTest(api_version_utils.BaseMicroversionTest,
api_version_utils.select_request_microversion(
cls.placement_min_microversion,
CONF.placement.min_microversion))
cls.setup_api_microversion_fixture(
compute_microversion=cls.request_microversion,
volume_microversion=cls.volume_request_microversion,
placement_microversion=cls.placement_request_microversion)
cls.build_interval = CONF.compute.build_interval
cls.build_timeout = CONF.compute.build_timeout
cls.image_ref = CONF.compute.image_ref
@ -499,13 +503,6 @@ class BaseV2ComputeTest(api_version_utils.BaseMicroversionTest,
else:
raise lib_exc.InvalidConfiguration()
def setUp(self):
super(BaseV2ComputeTest, self).setUp()
self.useFixture(api_microversion_fixture.APIMicroversionFixture(
compute_microversion=self.request_microversion,
volume_microversion=self.volume_request_microversion,
placement_microversion=self.placement_request_microversion))
@classmethod
def create_volume(cls, image_ref=None, **kwargs):
"""Create a volume and wait for it to become 'available'.

@ -16,7 +16,6 @@
from tempest.common import compute
from tempest.common import waiters
from tempest import config
from tempest.lib.common import api_microversion_fixture
from tempest.lib.common import api_version_utils
from tempest.lib.common.utils import data_utils
from tempest.lib.common.utils import test_utils
@ -75,12 +74,6 @@ class BaseVolumeTest(api_version_utils.BaseMicroversionTest,
cls.os_primary.volume_availability_zone_client_latest)
cls.volume_limits_client = cls.os_primary.volume_limits_client_latest
def setUp(self):
super(BaseVolumeTest, self).setUp()
self.useFixture(api_microversion_fixture.APIMicroversionFixture(
compute_microversion=self.compute_request_microversion,
volume_microversion=self.volume_request_microversion))
@classmethod
def resource_setup(cls):
super(BaseVolumeTest, cls).resource_setup()
@ -92,6 +85,9 @@ class BaseVolumeTest(api_version_utils.BaseMicroversionTest,
api_version_utils.select_request_microversion(
cls.min_microversion,
CONF.compute.min_microversion))
cls.setup_api_microversion_fixture(
compute_microversion=cls.compute_request_microversion,
volume_microversion=cls.volume_request_microversion)
cls.image_ref = CONF.compute.image_ref
cls.flavor_ref = CONF.compute.flavor_ref

@ -30,7 +30,6 @@ from tempest.common.utils import net_utils
from tempest.common import waiters
from tempest import config
from tempest import exceptions
from tempest.lib.common import api_microversion_fixture
from tempest.lib.common import api_version_utils
from tempest.lib.common.utils import data_utils
from tempest.lib.common.utils import test_utils
@ -85,12 +84,10 @@ class ScenarioTest(tempest.test.BaseTestCase):
cls.placement_min_microversion,
CONF.placement.min_microversion))
def setUp(self):
super(ScenarioTest, self).setUp()
self.useFixture(api_microversion_fixture.APIMicroversionFixture(
compute_microversion=self.compute_request_microversion,
volume_microversion=self.volume_request_microversion,
placement_microversion=self.placement_request_microversion))
cls.setup_api_microversion_fixture(
compute_microversion=cls.compute_request_microversion,
volume_microversion=cls.volume_request_microversion,
placement_microversion=cls.placement_request_microversion)
def setup_compute_client(cls):
"""Compute client"""

@ -27,6 +27,7 @@ from tempest.common import credentials_factory as credentials
from tempest.common import utils
from tempest import config
from tempest.lib import base as lib_base
from tempest.lib.common import api_microversion_fixture
from tempest.lib.common import fixed_network
from tempest.lib.common import profiler
from tempest.lib.common import validation_resources as vr
@ -479,6 +480,34 @@ class BaseTestCase(testtools.testcase.WithAttributes,
"""
pass
@classmethod
def setup_api_microversion_fixture(
cls, compute_microversion=None, volume_microversion=None,
placement_microversion=None):
"""Set up api microversion fixture on service clients.
`setup_api_microversion_fixture` is used to set the api microversion
on service clients. This can be invoked from resource_setup() method.
Example::
@classmethod
def resource_setup(cls):
super(MyTest, cls).resource_setup()
cls.setup_api_microversion_fixture(
compute_microversion=cls.compute_request_microversion,
volume_microversion=cls.volume_request_microversion,
placement_microversion=cls.placement_request_microversion)
"""
api_fixture = api_microversion_fixture.APIMicroversionFixture(
compute_microversion=compute_microversion,
volume_microversion=volume_microversion,
placement_microversion=placement_microversion)
api_fixture.setUp()
cls.addClassResourceCleanup(api_fixture._reset_microversion)
@classmethod
def resource_setup(cls):
"""Class level resource setup for test cases.

@ -24,6 +24,9 @@ from tempest import clients
from tempest import config
from tempest.lib.common import validation_resources as vr
from tempest.lib import exceptions as lib_exc
from tempest.lib.services.compute import base_compute_client
from tempest.lib.services.placement import base_placement_client
from tempest.lib.services.volume import base_client as base_volume_client
from tempest import test
from tempest.tests import base
from tempest.tests import fake_config
@ -749,3 +752,186 @@ class TestTempestBaseTestClassFixtures(base.TestCase):
self.test.fixtures_invoked)
found_exc = log[0][1][1]
self.assertIn(expected_exc, str(found_exc))
class TestAPIMicroversionTest1(test.BaseTestCase):
@classmethod
def resource_setup(cls):
super(TestAPIMicroversionTest1, cls).resource_setup()
# Setting microvesions and checks that every tests
# of this class will have those microversion set
# on service clients requesting service APIs.
cls.setup_api_microversion_fixture(
compute_microversion='2.30',
volume_microversion='3.10',
placement_microversion='3.1')
# Check microvesion is set during resource_setup()
if base_compute_client.COMPUTE_MICROVERSION != '2.30':
raise testtools.TestCase.failureException(
"Microversion is not set in resource_setup method")
if base_volume_client.VOLUME_MICROVERSION != '3.10':
raise testtools.TestCase.failureException(
"Microversion is not set in resource_setup method")
if base_placement_client.PLACEMENT_MICROVERSION != '3.1':
raise testtools.TestCase.failureException(
"Microversion is not set in resource_setup method")
@classmethod
def resource_cleanup(cls):
super(TestAPIMicroversionTest1, cls).resource_cleanup()
# Check microversion is reset back to None in resource_cleanup()
if base_compute_client.COMPUTE_MICROVERSION is not None:
raise testtools.TestCase.failureException(
"Microversion is not reset to None in resource_cleanup method")
if base_volume_client.VOLUME_MICROVERSION is not None:
raise testtools.TestCase.failureException(
"Microversion is not reset to None in resource_cleanup method")
if base_placement_client.PLACEMENT_MICROVERSION is not None:
raise testtools.TestCase.failureException(
"Microversion is not reset to None in resource_cleanup method")
def setUp(self):
super(TestAPIMicroversionTest1, self).setUp()
# Check microversion is set in setUp method also.
self.assertEqual('2.30', base_compute_client.COMPUTE_MICROVERSION)
self.assertEqual('3.10', base_volume_client.VOLUME_MICROVERSION)
self.assertEqual('3.1', base_placement_client.PLACEMENT_MICROVERSION)
def tearDown(self):
super(TestAPIMicroversionTest1, self).tearDown()
# Check microversion is set in tearDown method also.
self.assertEqual('2.30', base_compute_client.COMPUTE_MICROVERSION)
self.assertEqual('3.10', base_volume_client.VOLUME_MICROVERSION)
self.assertEqual('3.1', base_placement_client.PLACEMENT_MICROVERSION)
def test_1(self):
self.assertEqual('2.30', base_compute_client.COMPUTE_MICROVERSION)
self.assertEqual('3.10', base_volume_client.VOLUME_MICROVERSION)
self.assertEqual('3.1', base_placement_client.PLACEMENT_MICROVERSION)
def test_2(self):
self.assertEqual('2.30', base_compute_client.COMPUTE_MICROVERSION)
self.assertEqual('3.10', base_volume_client.VOLUME_MICROVERSION)
self.assertEqual('3.1', base_placement_client.PLACEMENT_MICROVERSION)
class TestAPIMicroversionTest2(test.BaseTestCase):
@classmethod
def resource_setup(cls):
super(TestAPIMicroversionTest2, cls).resource_setup()
# Setting microvesions different from what set in
# MicroversionTest1 and checks that every tests
# of this class will have the new microversion set
# on service clients requesting service APIs.
cls.setup_api_microversion_fixture(
compute_microversion='2.80',
volume_microversion='3.80',
placement_microversion='3.8')
# Check microvesion is set during resource_setup()
if base_compute_client.COMPUTE_MICROVERSION != '2.80':
raise testtools.TestCase.failureException(
"Microversion is not set in resource_setup method")
if base_volume_client.VOLUME_MICROVERSION != '3.80':
raise testtools.TestCase.failureException(
"Microversion is not set in resource_setup method")
if base_placement_client.PLACEMENT_MICROVERSION != '3.8':
raise testtools.TestCase.failureException(
"Microversion is not set in resource_setup method")
@classmethod
def resource_cleanup(cls):
super(TestAPIMicroversionTest2, cls).resource_cleanup()
# Check microversion is reset back to None in resource_cleanup()
if base_compute_client.COMPUTE_MICROVERSION is not None:
raise testtools.TestCase.failureException(
"Microversion is not reset to None in resource_cleanup method")
if base_volume_client.VOLUME_MICROVERSION is not None:
raise testtools.TestCase.failureException(
"Microversion is not reset to None in resource_cleanup method")
if base_placement_client.PLACEMENT_MICROVERSION is not None:
raise testtools.TestCase.failureException(
"Microversion is not reset to None in resource_cleanup method")
def setUp(self):
super(TestAPIMicroversionTest2, self).setUp()
# Check microversion is set in setUp method also.
self.assertEqual('2.80', base_compute_client.COMPUTE_MICROVERSION)
self.assertEqual('3.80', base_volume_client.VOLUME_MICROVERSION)
self.assertEqual('3.8', base_placement_client.PLACEMENT_MICROVERSION)
def tearDown(self):
super(TestAPIMicroversionTest2, self).tearDown()
# Check microversion is set in tearDown method also.
self.assertEqual('2.80', base_compute_client.COMPUTE_MICROVERSION)
self.assertEqual('3.80', base_volume_client.VOLUME_MICROVERSION)
self.assertEqual('3.8', base_placement_client.PLACEMENT_MICROVERSION)
def test_1(self):
self.assertEqual('2.80', base_compute_client.COMPUTE_MICROVERSION)
self.assertEqual('3.80', base_volume_client.VOLUME_MICROVERSION)
self.assertEqual('3.8', base_placement_client.PLACEMENT_MICROVERSION)
def test_2(self):
self.assertEqual('2.80', base_compute_client.COMPUTE_MICROVERSION)
self.assertEqual('3.80', base_volume_client.VOLUME_MICROVERSION)
self.assertEqual('3.8', base_placement_client.PLACEMENT_MICROVERSION)
class TestAPIMicroversionTest3(test.BaseTestCase):
@classmethod
def resource_setup(cls):
super(TestAPIMicroversionTest3, cls).resource_setup()
# Not setting microversion for this test class so
# there should not be any micorversion set on service
# clients requesting services APIs.
# Check microvesion is not set during resource_setup()
if base_compute_client.COMPUTE_MICROVERSION is not None:
raise testtools.TestCase.failureException(
"Microversion is not set in resource_setup method")
if base_volume_client.VOLUME_MICROVERSION is not None:
raise testtools.TestCase.failureException(
"Microversion is not set in resource_setup method")
if base_placement_client.PLACEMENT_MICROVERSION is not None:
raise testtools.TestCase.failureException(
"Microversion is not set in resource_setup method")
@classmethod
def resource_cleanup(cls):
super(TestAPIMicroversionTest3, cls).resource_cleanup()
# Check microversion is set to None in resource_cleanup()
if base_compute_client.COMPUTE_MICROVERSION is not None:
raise testtools.TestCase.failureException(
"Microversion is not reset to None in resource_cleanup method")
if base_volume_client.VOLUME_MICROVERSION is not None:
raise testtools.TestCase.failureException(
"Microversion is not reset to None in resource_cleanup method")
if base_placement_client.PLACEMENT_MICROVERSION is not None:
raise testtools.TestCase.failureException(
"Microversion is not reset to None in resource_cleanup method")
def setUp(self):
super(TestAPIMicroversionTest3, self).setUp()
# Check microversion is None in setUp method also.
self.assertIsNone(base_compute_client.COMPUTE_MICROVERSION)
self.assertIsNone(base_volume_client.VOLUME_MICROVERSION)
self.assertIsNone(base_placement_client.PLACEMENT_MICROVERSION)
def tearDown(self):
super(TestAPIMicroversionTest3, self).tearDown()
# Check microversion is None in tearDown method also.
self.assertIsNone(base_compute_client.COMPUTE_MICROVERSION)
self.assertIsNone(base_volume_client.VOLUME_MICROVERSION)
self.assertIsNone(base_placement_client.PLACEMENT_MICROVERSION)
def test_1(self):
self.assertIsNone(base_compute_client.COMPUTE_MICROVERSION)
self.assertIsNone(base_volume_client.VOLUME_MICROVERSION)
self.assertIsNone(base_placement_client.PLACEMENT_MICROVERSION)
def test_2(self):
self.assertIsNone(base_compute_client.COMPUTE_MICROVERSION)
self.assertIsNone(base_volume_client.VOLUME_MICROVERSION)
self.assertIsNone(base_placement_client.PLACEMENT_MICROVERSION)

Loading…
Cancel
Save