Set api_version on tempest tests
* Follow the guide [1] * Add admin credentials to test_containers. We need this to force delete containers. [1] https://docs.openstack.org/tempest/latest/microversion_testing.html#how-to-implement-microversion-tests Change-Id: I7b1a79cfb171b76f49d48bf86d233d8e544e3afc Closes-Bug: #1732014
This commit is contained in:
parent
df0b2c4fbb
commit
e502cad7dd
@ -0,0 +1,28 @@
|
||||
# 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 zun_tempest_plugin.tests.tempest.api import clients
|
||||
|
||||
|
||||
class APIMicroversionFixture(fixtures.Fixture):
|
||||
|
||||
def __init__(self, container_management_microversion):
|
||||
self.container_management_microversion = \
|
||||
container_management_microversion
|
||||
|
||||
def _setUp(self):
|
||||
super(APIMicroversionFixture, self)._setUp()
|
||||
clients.set_container_management_api_microversion(
|
||||
self.container_management_microversion)
|
||||
self.addCleanup(clients.reset_container_management_api_microversion)
|
@ -13,7 +13,9 @@ import contextlib
|
||||
|
||||
import docker
|
||||
from six.moves.urllib import parse
|
||||
from tempest.common import credentials_factory as common_creds
|
||||
from tempest import config
|
||||
from tempest.lib.common import api_version_utils
|
||||
from tempest.lib.common import rest_client
|
||||
from tempest.lib.services.image.v2 import images_client
|
||||
from tempest.lib.services.network import ports_client
|
||||
@ -27,10 +29,40 @@ from zun_tempest_plugin.tests.tempest import utils
|
||||
|
||||
CONF = config.CONF
|
||||
|
||||
ADMIN_CREDS = None
|
||||
|
||||
CONTAINER_MANAGEMENT_MICROVERSION = None
|
||||
|
||||
|
||||
def get_container_management_api_version():
|
||||
"""Get zun-api-version with format: 'container X.Y'"""
|
||||
return 'container ' + CONTAINER_MANAGEMENT_MICROVERSION
|
||||
|
||||
|
||||
def set_container_management_api_microversion(
|
||||
container_management_microversion):
|
||||
global CONTAINER_MANAGEMENT_MICROVERSION
|
||||
CONTAINER_MANAGEMENT_MICROVERSION = container_management_microversion
|
||||
|
||||
|
||||
def reset_container_management_api_microversion():
|
||||
global CONTAINER_MANAGEMENT_MICROVERSION
|
||||
CONTAINER_MANAGEMENT_MICROVERSION = None
|
||||
|
||||
|
||||
class Manager(manager.Manager):
|
||||
|
||||
def __init__(self, credentials=None, service=None):
|
||||
def __init__(self, credentials=None):
|
||||
"""Initialization of Manager class.
|
||||
|
||||
Setup service client and make it available for test cases.
|
||||
:param credentials: type Credentials or TestResources
|
||||
"""
|
||||
if credentials is None:
|
||||
global ADMIN_CREDS
|
||||
if ADMIN_CREDS is None:
|
||||
ADMIN_CREDS = common_creds.get_configured_admin_credentials()
|
||||
credentials = ADMIN_CREDS
|
||||
super(Manager, self).__init__(credentials=credentials)
|
||||
|
||||
self.images_client = images_client.ImagesClient(
|
||||
@ -43,6 +75,9 @@ class Manager(manager.Manager):
|
||||
|
||||
|
||||
class ZunClient(rest_client.RestClient):
|
||||
""""Base Tempest REST client for Zun API."""
|
||||
|
||||
api_microversion_header_name = 'OpenStack-API-Version'
|
||||
|
||||
def __init__(self, auth_provider):
|
||||
super(ZunClient, self).__init__(
|
||||
@ -52,6 +87,24 @@ class ZunClient(rest_client.RestClient):
|
||||
disable_ssl_certificate_validation=True
|
||||
)
|
||||
|
||||
def get_headers(self):
|
||||
headers = super(ZunClient, self).get_headers()
|
||||
if CONTAINER_MANAGEMENT_MICROVERSION:
|
||||
headers[self.api_microversion_header_name] = \
|
||||
get_container_management_api_version()
|
||||
return headers
|
||||
|
||||
def request(self, *args, **kwargs):
|
||||
resp, resp_body = super(ZunClient, self).request(*args, **kwargs)
|
||||
if (CONTAINER_MANAGEMENT_MICROVERSION and
|
||||
CONTAINER_MANAGEMENT_MICROVERSION
|
||||
!= api_version_utils.LATEST_MICROVERSION):
|
||||
api_version_utils.assert_version_header_matches_request(
|
||||
self.api_microversion_header_name,
|
||||
get_container_management_api_version(),
|
||||
resp)
|
||||
return resp, resp_body
|
||||
|
||||
@classmethod
|
||||
def deserialize(cls, resp, body, model_type):
|
||||
return resp, model_type.from_json(body)
|
||||
|
@ -21,6 +21,9 @@ from zun_tempest_plugin.tests.tempest import utils
|
||||
|
||||
class TestContainer(base.BaseZunTest):
|
||||
|
||||
credentials = ['primary', 'admin']
|
||||
min_microversion = '1.7'
|
||||
|
||||
@classmethod
|
||||
def get_client_manager(cls, credential_type=None, roles=None,
|
||||
force_new=None):
|
||||
@ -55,8 +58,12 @@ class TestContainer(base.BaseZunTest):
|
||||
if c['uuid'] in self.containers:
|
||||
if c['host'] and c['host'] not in hosts:
|
||||
hosts.append(c['host'])
|
||||
self.container_client.delete_container(c['uuid'],
|
||||
params={'force': True})
|
||||
# NOTE(kiennt): From version 1.7, Zun disallowed non-admin
|
||||
# users to force delete containers. Therefore,
|
||||
# we have to be admin to do this action.
|
||||
self.os_admin.container_client.delete_container(
|
||||
c['uuid'],
|
||||
params={'force': True, 'all_tenants': True})
|
||||
self.container_client.ensure_container_deleted(c['uuid'])
|
||||
|
||||
# cleanup the network resources
|
||||
@ -453,8 +460,12 @@ class TestContainer(base.BaseZunTest):
|
||||
return resp, model
|
||||
|
||||
def _delete_container(self, container_id, container_host, force=False):
|
||||
resp, _ = self.container_client.delete_container(
|
||||
container_id, params={'force': force})
|
||||
# NOTE(kiennt): From version 1.7, Zun disallowed non-admin users
|
||||
# to force delete containers. Therefore, we
|
||||
# have to be admin to do this action.
|
||||
resp, _ = self.os_admin.container_client.delete_container(
|
||||
container_id,
|
||||
params={'force': force, 'all_tenants': True})
|
||||
self.assertEqual(204, resp.status)
|
||||
self.container_client.ensure_container_deleted(container_id)
|
||||
container = self.docker_client.get_container(
|
||||
|
@ -19,6 +19,8 @@ from zun_tempest_plugin.tests.tempest import base
|
||||
|
||||
class TestService(base.BaseZunTest):
|
||||
|
||||
min_microversion = '1.7'
|
||||
|
||||
@classmethod
|
||||
def get_client_manager(cls, credential_type=None, roles=None,
|
||||
force_new=None):
|
||||
|
@ -13,12 +13,16 @@
|
||||
# limitations under the License.
|
||||
|
||||
from tempest import config
|
||||
from tempest.lib.common import api_version_utils
|
||||
from tempest import test
|
||||
|
||||
from zun_tempest_plugin.tests.tempest.api import api_microversion_fixture
|
||||
|
||||
CONF = config.CONF
|
||||
|
||||
|
||||
class BaseZunTest(test.BaseTestCase):
|
||||
class BaseZunTest(api_version_utils.BaseMicroversionTest,
|
||||
test.BaseTestCase):
|
||||
|
||||
credentials = ['primary']
|
||||
|
||||
@ -28,8 +32,40 @@ class BaseZunTest(test.BaseTestCase):
|
||||
if not CONF.service_available.zun:
|
||||
skip_msg = 'Zun is disabled'
|
||||
raise cls.skipException(skip_msg)
|
||||
cfg_min_version = CONF.container_management.min_microversion
|
||||
cfg_max_version = CONF.container_management.max_microversion
|
||||
api_version_utils.check_skip_with_microversion(cls.min_microversion,
|
||||
cls.max_microversion,
|
||||
cfg_min_version,
|
||||
cfg_max_version)
|
||||
|
||||
@classmethod
|
||||
def setup_clients(cls):
|
||||
super(BaseZunTest, cls).setup_clients()
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def setup_credentials(cls):
|
||||
cls.request_microversion = (
|
||||
api_version_utils.select_request_microversion(
|
||||
cls.min_microversion,
|
||||
CONF.container_management.min_microversion
|
||||
))
|
||||
cls.services_microversion = {
|
||||
CONF.container_management.catalog_type: cls.request_microversion}
|
||||
super(BaseZunTest, cls).setup_credentials()
|
||||
|
||||
@classmethod
|
||||
def resource_setup(cls):
|
||||
super(BaseZunTest, cls).resource_setup()
|
||||
cls.request_microversion = (
|
||||
api_version_utils.select_request_microversion(
|
||||
cls.min_microversion,
|
||||
CONF.container_management.min_microversion))
|
||||
cls.wait_timeout = CONF.container_management.wait_timeout
|
||||
|
||||
def setUp(self):
|
||||
super(BaseZunTest, self).setUp()
|
||||
self.useFixture(api_microversion_fixture.APIMicroversionFixture(
|
||||
self.request_microversion
|
||||
))
|
||||
|
@ -29,7 +29,23 @@ ContainerManagementGroup = [
|
||||
help="Catalog type of the container management service."),
|
||||
cfg.IntOpt("wait_timeout",
|
||||
default=60,
|
||||
help="Waiting time for a specific status, in seconds.")
|
||||
help="Waiting time for a specific status, in seconds."),
|
||||
cfg.StrOpt('min_microversion',
|
||||
default=None,
|
||||
help="Lower version of the test target microversion range. "
|
||||
"The format is 'X.Y', where 'X' and 'Y' are int values. "
|
||||
"Tempest selects tests based on the range between "
|
||||
"min_microversion and max_microversion. If both values "
|
||||
"are None, Tempest avoids tests which require a "
|
||||
"microversion."),
|
||||
cfg.StrOpt('max_microversion',
|
||||
default='latest',
|
||||
help="Upper version of the test target microversion range. "
|
||||
"The format is 'X.Y'. where 'X' and 'Y' are int values. "
|
||||
"Tempest selects tests based on the range between "
|
||||
"microversion and max_microversion. If both values "
|
||||
"are None, Tempest avoids tests which require a "
|
||||
"microversion.")
|
||||
]
|
||||
|
||||
docker_group = cfg.OptGroup(name='docker',
|
||||
|
Loading…
x
Reference in New Issue
Block a user