Add tempest test for legacy API version

Currently, the container test cases requires API version 1.20
or higher. This commit adds legacy test class to cover
API version 1.19 or lower.

Change-Id: I5e5f23ceab5438f6025beb9dc6ac1ffebd33f9a9
This commit is contained in:
Hongbin Lu 2018-10-13 18:50:54 +00:00
parent b38210e6a4
commit 9988487a20
3 changed files with 80 additions and 8 deletions

View File

@ -72,6 +72,30 @@ def container_data(default_data=None, **kwargs):
return model
def container_data_legacy(default_data=None, **kwargs):
if default_data is None:
default_data = {
'name': data_utils.rand_name('container'),
'image': 'cirros:latest',
'command': 'sleep 10000',
'cpu': 0.1,
'memory': '100',
'environment': {},
'labels': {},
'image_driver': 'docker',
'image_pull_policy': 'always',
'restart_policy': {'Name': 'no'},
'workdir': '/',
'interactive': False,
'security_groups': ['default'],
}
default_data.update(kwargs)
model = container_model.ContainerEntity.from_dict(default_data)
return model
def container_patch_data(**kwargs):
data = {
'cpu': 0.2,

View File

@ -223,6 +223,7 @@ class TestContainer(base.BaseZunTest):
self.assertIs(True, stdin_open)
@decorators.idempotent_id('f181eeda-a9d1-4b2e-9746-d6634ca81e2f')
@utils.requires_microversion('1.20')
def test_run_container_without_security_groups(self):
gen_model = datagen.container_data()
delattr(gen_model, 'security_groups')
@ -347,6 +348,7 @@ class TestContainer(base.BaseZunTest):
self.assertTrue('hello' in encodeutils.safe_decode(body))
@decorators.idempotent_id('e49231b2-b095-40d3-9b54-33bb1b371cbe')
@utils.requires_microversion('1.20')
def test_run_container_with_cinder_volume_dynamic_created(self):
"""Tests the following:
@ -396,7 +398,7 @@ class TestContainer(base.BaseZunTest):
volume_id)
@decorators.idempotent_id('8a4395ff-3a91-4a35-bd71-5248afc6c465')
@utils.requires_microversion(min_microversion, '1.25')
@utils.requires_microversion('1.25')
def test_run_container_with_injected_file(self):
# create a container with the volume
file_content = 'Random text'
@ -545,6 +547,7 @@ class TestContainer(base.BaseZunTest):
self.assertTrue('hello' in encodeutils.safe_decode(body))
@decorators.idempotent_id('d383f359-3ebd-40ef-9dc5-d36922790230')
@utils.requires_microversion('1.14')
def test_update_container(self):
_, model = self._run_container(cpu=0.1, memory=100)
self.assertEqual('100', model.memory)
@ -565,6 +568,7 @@ class TestContainer(base.BaseZunTest):
self._assert_resource_constraints(container, cpu=0.2, memory=200)
@decorators.idempotent_id('b218bea7-f19b-499f-9819-c7021ffc59f4')
@utils.requires_microversion('1.14')
def test_rename_container(self):
container1_name = data_utils.rand_name('container1')
_, model = self._run_container(name=container1_name)
@ -706,7 +710,7 @@ class TestContainer(base.BaseZunTest):
self._ensure_network_attached(model, network)
@decorators.idempotent_id('037d800c-2262-4e15-90cd-95292b5ef958')
@utils.requires_microversion(min_microversion, '1.1', '1.24')
@utils.requires_microversion('1.1', '1.24')
def test_put_and_get_archive_from_container(self):
_, model = self._run_container()
self.assertEqual(1, len(model.addresses))
@ -744,7 +748,7 @@ class TestContainer(base.BaseZunTest):
self.assertEqual(body['stat']['size'], tarinfo.size)
@decorators.idempotent_id('4ea3a2a5-cf89-48e7-bdd2-0bafc70ca7cb')
@utils.requires_microversion(min_microversion, '1.25')
@utils.requires_microversion('1.25')
def test_put_and_get_archive_from_container_encoded(self):
_, model = self._run_container()
self.assertEqual(1, len(model.addresses))
@ -801,3 +805,48 @@ class TestContainer(base.BaseZunTest):
return False
utils.wait_for_condition(is_network_attached)
class TestContainerLegacy(TestContainer):
credentials = ['primary', 'admin']
min_microversion = '1.1'
max_microversion = '1.19'
def _run_container(self, gen_model=None, **kwargs):
if 'command' in kwargs and isinstance(kwargs['command'], list):
command = ' '.join(["'%s'" % c for c in kwargs['command']])
kwargs['command'] = command
if gen_model is None:
gen_model = datagen.container_data_legacy(**kwargs)
resp, model = self.container_client.run_container(gen_model)
self.containers.append(model.uuid)
self.assertEqual(202, resp.status)
# Wait for container to started
self.container_client.ensure_container_in_desired_state(
model.uuid, 'Running')
# Assert the container is started
resp, model = self.container_client.get_container(model.uuid)
self.assertEqual('Running', model.status)
self.assertEqual('Running', self._get_container_state(model))
return resp, model
def _create_container(self, **kwargs):
if 'command' in kwargs and isinstance(kwargs['command'], list):
command = ' '.join(["'%s'" % c for c in kwargs['command']])
kwargs['command'] = command
gen_model = datagen.container_data_legacy(**kwargs)
resp, model = self.container_client.post_container(gen_model)
self.containers.append(model.uuid)
self.assertEqual(202, resp.status)
# Wait for container to finish creation
self.container_client.ensure_container_in_desired_state(
model.uuid, 'Created')
# Assert the container is created
resp, model = self.container_client.get_container(model.uuid)
self.assertEqual(200, resp.status)
self.assertEqual('Created', model.status)
self.assertEqual('Created', self._get_container_state(model))
return resp, model

View File

@ -34,8 +34,7 @@ def wait_for_condition(condition, interval=2, timeout=60):
"on %s") % (timeout, start_time, end_time))
def requires_microversion(cls_min_version, min_version, max_version='latest',
**kwargs):
def requires_microversion(min_version, max_version='latest', **kwargs):
"""A decorator to skip tests if a microversion is not matched
@param extension
@ -43,16 +42,16 @@ def requires_microversion(cls_min_version, min_version, max_version='latest',
"""
def decorator(func):
@functools.wraps(func)
def wrapper(*func_args, **func_kwargs):
def wrapper(self, *func_args, **func_kwargs):
selected_version = api_version_utils.select_request_microversion(
cls_min_version,
self.request_microversion,
CONF.container_service.min_microversion)
api_version_utils.check_skip_with_microversion(
min_version,
max_version,
selected_version,
selected_version)
return func(*func_args, **func_kwargs)
return func(self, *func_args, **func_kwargs)
return wrapper
return decorator