Add test cases for capsule
Change-Id: Ic8aae6ad83414f73d67cd9d31f2a26e0f9ebbba0
This commit is contained in:
parent
29c3b97f42
commit
1c08d47a3d
@ -23,6 +23,7 @@ from tempest.lib.services.network import ports_client
|
||||
from tempest.lib.services.network import security_groups_client
|
||||
from tempest import manager
|
||||
|
||||
from zun_tempest_plugin.tests.tempest.api.models import capsule_model
|
||||
from zun_tempest_plugin.tests.tempest.api.models import container_model
|
||||
from zun_tempest_plugin.tests.tempest.api.models import service_model
|
||||
from zun_tempest_plugin.tests.tempest import utils
|
||||
@ -155,6 +156,22 @@ class ZunClient(rest_client.RestClient):
|
||||
url = "/services/"
|
||||
return url
|
||||
|
||||
@classmethod
|
||||
def capsules_uri(cls):
|
||||
url = "/capsules/"
|
||||
return url
|
||||
|
||||
@classmethod
|
||||
def capsule_uri(cls, capsule_id, params=None):
|
||||
"""Construct capsule uri
|
||||
|
||||
"""
|
||||
url = "{0}/{1}".format(cls.capsules_uri(), capsule_id)
|
||||
if params:
|
||||
url = cls.add_params(url, params)
|
||||
|
||||
return url
|
||||
|
||||
def post_container(self, model, **kwargs):
|
||||
"""Makes POST /container request
|
||||
|
||||
@ -296,6 +313,31 @@ class ZunClient(rest_client.RestClient):
|
||||
self.container_uri(container_id, action='get_archive',
|
||||
params=params), None, **kwargs)
|
||||
|
||||
def post_capsule(self, model, **kwargs):
|
||||
"""Makes POST /capsules request
|
||||
|
||||
"""
|
||||
resp, body = self.post(
|
||||
self.capsules_uri(),
|
||||
body=model.to_json(), **kwargs)
|
||||
return self.deserialize(resp, body, capsule_model.CapsuleEntity)
|
||||
|
||||
def ensure_capsule_in_desired_state(self, capsule_id, status):
|
||||
def is_capsule_in_desired_state():
|
||||
_, capsule = self.get_capsule(capsule_id)
|
||||
if capsule.status == status:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
utils.wait_for_condition(is_capsule_in_desired_state, timeout=120)
|
||||
|
||||
def get_capsule(self, capsule_id, params=None):
|
||||
resp, body = self.get(self.capsule_uri(capsule_id, params=params))
|
||||
return self.deserialize(resp, body, capsule_model.CapsuleEntity)
|
||||
|
||||
def delete_capsule(self, capsule_id, params=None):
|
||||
return self.delete(self.capsule_uri(capsule_id, params=params))
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def docker_client(docker_auth_url):
|
||||
|
@ -16,6 +16,7 @@ import string
|
||||
import struct
|
||||
|
||||
from tempest.lib.common.utils import data_utils
|
||||
from zun_tempest_plugin.tests.tempest.api.models import capsule_model
|
||||
from zun_tempest_plugin.tests.tempest.api.models import container_model
|
||||
|
||||
|
||||
@ -112,5 +113,23 @@ def container_remove_sg_data(**kwargs):
|
||||
|
||||
data.update(kwargs)
|
||||
model = container_model.ContainerPatchEntity.from_dict(data)
|
||||
|
||||
return model
|
||||
|
||||
|
||||
def capsule_data(default_data=None, **kwargs):
|
||||
if default_data is None:
|
||||
default_data = {
|
||||
'template': {
|
||||
'kind': 'capsule',
|
||||
'capsuleVersion': 'beta',
|
||||
'metadata': {'name': data_utils.rand_name('capsule')},
|
||||
'spec': {
|
||||
'containers': [
|
||||
{'image': 'cirros:latest'},
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
default_data.update(kwargs)
|
||||
model = capsule_model.CapsuleEntity.from_dict(default_data)
|
||||
return model
|
||||
|
24
zun_tempest_plugin/tests/tempest/api/models/capsule_model.py
Normal file
24
zun_tempest_plugin/tests/tempest/api/models/capsule_model.py
Normal file
@ -0,0 +1,24 @@
|
||||
# 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 zun_tempest_plugin.tests.tempest.api.common import base_model
|
||||
|
||||
|
||||
class CapsuleData(base_model.BaseModel):
|
||||
"""Data that encapsulates capsule attributes"""
|
||||
pass
|
||||
|
||||
|
||||
class CapsuleEntity(base_model.EntityModel):
|
||||
"""Entity Model that represents a single instance of CapsuleData"""
|
||||
ENTITY_NAME = 'capsule'
|
||||
MODEL_TYPE = CapsuleData
|
101
zun_tempest_plugin/tests/tempest/api/test_capsules.py
Normal file
101
zun_tempest_plugin/tests/tempest/api/test_capsules.py
Normal file
@ -0,0 +1,101 @@
|
||||
# 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 import decorators
|
||||
|
||||
from zun_tempest_plugin.tests.tempest.api import clients
|
||||
from zun_tempest_plugin.tests.tempest.api.common import datagen
|
||||
from zun_tempest_plugin.tests.tempest import base
|
||||
|
||||
|
||||
class TestCapsule(base.BaseZunTest):
|
||||
|
||||
credentials = ['primary', 'admin']
|
||||
min_microversion = '1.12'
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.cleanup_network()
|
||||
super(TestCapsule, cls).tearDownClass()
|
||||
|
||||
@classmethod
|
||||
def cleanup_network(cls):
|
||||
creds_provider = cls._get_credentials_provider()
|
||||
creds = creds_provider.get_primary_creds()
|
||||
network = getattr(creds, 'network', None)
|
||||
if not network:
|
||||
return
|
||||
|
||||
docker_base_url = cls._get_docker_url()
|
||||
networks = cls.docker_client.list_networks(
|
||||
network['id'], docker_auth_url=docker_base_url)
|
||||
for network in networks:
|
||||
cls.docker_client.remove_network(
|
||||
network['Id'], docker_auth_url=docker_base_url)
|
||||
|
||||
@classmethod
|
||||
def _get_docker_url(cls, host='localhost'):
|
||||
protocol = 'tcp'
|
||||
port = '2375'
|
||||
base_url = '%s://%s:%s' % (protocol, host, port)
|
||||
return base_url
|
||||
|
||||
@classmethod
|
||||
def get_client_manager(cls, credential_type=None, roles=None,
|
||||
force_new=None):
|
||||
manager = super(TestCapsule, cls).get_client_manager(
|
||||
credential_type=credential_type,
|
||||
roles=roles,
|
||||
force_new=force_new
|
||||
)
|
||||
return clients.Manager(manager.credentials)
|
||||
|
||||
@classmethod
|
||||
def setup_clients(cls):
|
||||
super(TestCapsule, cls).setup_clients()
|
||||
cls.container_client = cls.os_primary.container_client
|
||||
cls.docker_client = clients.DockerClient()
|
||||
cls.images_client = cls.os_primary.images_client
|
||||
cls.ports_client = cls.os_primary.ports_client
|
||||
cls.sgs_client = cls.os_primary.sgs_client
|
||||
|
||||
@classmethod
|
||||
def resource_setup(cls):
|
||||
super(TestCapsule, cls).resource_setup()
|
||||
|
||||
def setUp(self):
|
||||
super(TestCapsule, self).setUp()
|
||||
self.capsules = []
|
||||
|
||||
def tearDown(self):
|
||||
super(TestCapsule, self).tearDown()
|
||||
|
||||
@decorators.idempotent_id('d5c91423-0f83-44f8-8228-e6a28ef7817e')
|
||||
def test_create_capsule(self):
|
||||
self._create_capsule()
|
||||
|
||||
def _create_capsule(self, **kwargs):
|
||||
gen_model = datagen.capsule_data(**kwargs)
|
||||
resp, model = self.container_client.post_capsule(gen_model)
|
||||
self.addCleanup(self.container_client.delete_capsule, model.uuid)
|
||||
self.capsules.append(model.uuid)
|
||||
self.assertEqual(202, resp.status)
|
||||
# Wait for container to finish creation
|
||||
self.container_client.ensure_capsule_in_desired_state(
|
||||
model.uuid, 'Running')
|
||||
|
||||
# Assert the capsule is created
|
||||
resp, model = self.container_client.get_capsule(model.uuid)
|
||||
self.assertEqual(200, resp.status)
|
||||
self.assertEqual('Running', model.status)
|
||||
# TODO(hongbin): verify all containers are running
|
||||
return resp, model
|
Loading…
Reference in New Issue
Block a user