Add APIMicroversionFixture to library interface

APIMicroversionFixture is used to set the microversion on
service clients which will take care of reseting the microversion.

This interface has been added to set the microversion on all supported
service clients which use microverison. User can set multiple
service microversion all together.

Using the new interface in compute tests to make sure it is all
working in serial and parallel testing.

Change-Id: I6ed41b02041d38c2c92c58b0d3dd6613d03da3f7
This commit is contained in:
Ghanshyam Mann 2019-04-13 01:12:58 +00:00
parent 69761f5a44
commit ad8737c7f2
4 changed files with 149 additions and 2 deletions

View File

@ -0,0 +1,7 @@
---
features:
- |
New library interface to set the API microversion on Service Clients.
``APIMicroversionFixture,`` can be used to set the API microversion
on multiple services. This Fixture will take care of reseting the service
microversion to None once test is finished.

View File

@ -17,11 +17,11 @@ import time
from oslo_log import log as logging
from tempest.api.compute import api_microversion_fixture
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
@ -470,7 +470,7 @@ class BaseV2ComputeTest(api_version_utils.BaseMicroversionTest,
def setUp(self):
super(BaseV2ComputeTest, self).setUp()
self.useFixture(api_microversion_fixture.APIMicroversionFixture(
self.request_microversion))
compute_microversion=self.request_microversion))
@classmethod
def create_volume(cls, image_ref=None, **kwargs):

View File

@ -0,0 +1,82 @@
# Copyright 2019 NEC Corporation. All rights reserved.
#
# 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 fixtures
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
class APIMicroversionFixture(fixtures.Fixture):
"""API Microversion Fixture to set service microversion.
This class provides the fixture to set and reset the microversion
on service client. Service client has global variable to set the
microversion for that service API request.
For example: base_compute_client.COMPUTE_MICROVERSION
Global variable is always risky to set directly which can affect the
other test's API request also. This class provides a way to reset the
service microversion once test finish the API request.
This class can be used with useFixture: Example::
def setUp(self):
super(BaseV2ComputeTest, self).setUp()
self.useFixture(api_microversion_fixture.APIMicroversionFixture(
compute_microversion=self.compute_request_microversion))
Or you can set microversion on multiple services together::
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))
Current supported services:
- Compute
- Volume
- Placement
:param str compute_microversion: microvesion to be set on compute
service clients
:param str volume_microversion: microvesion to be set on volume
service clients
:param str placement_microversion: microvesion to be set on placement
service clients
"""
def __init__(self, compute_microversion=None, volume_microversion=None,
placement_microversion=None):
self.compute_microversion = compute_microversion
self.volume_microversion = volume_microversion
self.placement_microversion = placement_microversion
def _setUp(self):
super(APIMicroversionFixture, self)._setUp()
if self.compute_microversion:
base_compute_client.COMPUTE_MICROVERSION = (
self.compute_microversion)
if self.volume_microversion:
base_volume_client.VOLUME_MICROVERSION = self.volume_microversion
if self.placement_microversion:
base_placement_client.PLACEMENT_MICROVERSION = (
self.placement_microversion)
self.addCleanup(self._reset_microversion)
def _reset_microversion(self):
base_compute_client.COMPUTE_MICROVERSION = None
base_volume_client.VOLUME_MICROVERSION = None
base_placement_client.PLACEMENT_MICROVERSION = None

View File

@ -0,0 +1,58 @@
# Copyright 2019 NEC Corporation.
#
# 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 tempest.lib.common import api_microversion_fixture
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
from tempest.tests import base
class TestAPIMicroversionFixture(base.TestCase):
def setUp(self):
super(TestAPIMicroversionFixture, self).setUp()
# Verify that all the microversion are reset back to None
# by Fixture.
self.assertIsNone(base_compute_client.COMPUTE_MICROVERSION)
self.assertIsNone(base_client.VOLUME_MICROVERSION)
self.assertIsNone(base_placement_client.PLACEMENT_MICROVERSION)
def test_compute_microversion(self):
self.useFixture(api_microversion_fixture.APIMicroversionFixture(
compute_microversion='2.10'))
self.assertEqual('2.10', base_compute_client.COMPUTE_MICROVERSION)
self.assertIsNone(base_client.VOLUME_MICROVERSION)
self.assertIsNone(base_placement_client.PLACEMENT_MICROVERSION)
def test_volume_microversion(self):
self.useFixture(api_microversion_fixture.APIMicroversionFixture(
volume_microversion='3.10'))
self.assertIsNone(base_compute_client.COMPUTE_MICROVERSION)
self.assertEqual('3.10', base_client.VOLUME_MICROVERSION)
self.assertIsNone(base_placement_client.PLACEMENT_MICROVERSION)
def test_placement_microversion(self):
self.useFixture(api_microversion_fixture.APIMicroversionFixture(
placement_microversion='1.10'))
self.assertIsNone(base_compute_client.COMPUTE_MICROVERSION)
self.assertIsNone(base_client.VOLUME_MICROVERSION)
self.assertEqual('1.10', base_placement_client.PLACEMENT_MICROVERSION)
def test_multiple_service_microversion(self):
self.useFixture(api_microversion_fixture.APIMicroversionFixture(
compute_microversion='2.10', volume_microversion='3.10',
placement_microversion='1.10'))
self.assertEqual('2.10', base_compute_client.COMPUTE_MICROVERSION)
self.assertEqual('3.10', base_client.VOLUME_MICROVERSION)
self.assertEqual('1.10', base_placement_client.PLACEMENT_MICROVERSION)