From 7dba9f70c4b1130e5c38446c77825f28b44bf364 Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Thu, 28 Feb 2019 03:30:38 +0000 Subject: [PATCH] Test capsule with cinder volume Depends-On: https://review.openstack.org/#/c/638999/ Change-Id: I54c7076e7b412c85a0ad377229bc726f328eaf66 --- .../tests/tempest/api/test_capsules.py | 54 ++++++++++++++++++- .../tests/tempest/api/test_containers.py | 1 - zun_tempest_plugin/tests/tempest/base.py | 1 + 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/zun_tempest_plugin/tests/tempest/api/test_capsules.py b/zun_tempest_plugin/tests/tempest/api/test_capsules.py index 7966789..ba55b40 100644 --- a/zun_tempest_plugin/tests/tempest/api/test_capsules.py +++ b/zun_tempest_plugin/tests/tempest/api/test_capsules.py @@ -12,10 +12,12 @@ from tempest.lib.common.utils import data_utils from tempest.lib import decorators +from tempest.lib import exceptions as lib_exc 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 +from zun_tempest_plugin.tests.tempest import utils class TestCapsule(base.BaseZunTest): @@ -54,8 +56,11 @@ class TestCapsule(base.BaseZunTest): return resp, model def _delete_capsule(self, uuid): - self.container_client.delete_capsule(uuid) - self.container_client.ensure_capsule_deleted(uuid) + try: + self.container_client.delete_capsule(uuid) + self.container_client.ensure_capsule_deleted(uuid) + except lib_exc.NotFound: + pass @decorators.idempotent_id('b7e79a0b-c09e-4539-886f-a9f33ae15620') def test_create_capsule_full(self): @@ -105,3 +110,48 @@ class TestCapsule(base.BaseZunTest): } self._create_capsule(data=capsule_data) + + @decorators.idempotent_id('8bb22511-b06f-4ea5-ae8d-9dd529205590') + @utils.requires_microversion('1.32') + def test_create_capsule_with_volume(self): + # create a volume in cinder + volume = self.vol_client.create_volume( + name=data_utils.rand_name(), size=1)['volume'] + volume_id = volume['id'] + self.addCleanup(self.vol_client.delete_volume, volume_id) + + capsule_data = { + 'template': { + 'kind': 'capsule', + 'capsuleVersion': 'beta', + 'metadata': {'name': data_utils.rand_name('capsule')}, + 'spec': { + 'containers': [ + { + 'image': 'cirros:latest', + 'volumeMounts': [{ + 'name': 'test-volume', + 'mountPath': '/test-volume', + }] + } + ], + 'volumes': [ + { + 'name': 'test-volume', + 'cinder': { + 'volumeID': volume_id, + } + } + ] + } + } + } + _, model = self._create_capsule(data=capsule_data) + # assert volume is attached + volume = self.vol_client.show_volume(volume_id)['volume'] + self.assertEqual('in-use', volume['status']) + + self._delete_capsule(model.uuid) + # assert volume is detached + volume = self.vol_client.show_volume(volume_id)['volume'] + self.assertEqual('available', volume['status']) diff --git a/zun_tempest_plugin/tests/tempest/api/test_containers.py b/zun_tempest_plugin/tests/tempest/api/test_containers.py index 5b1f134..99a7d9f 100644 --- a/zun_tempest_plugin/tests/tempest/api/test_containers.py +++ b/zun_tempest_plugin/tests/tempest/api/test_containers.py @@ -48,7 +48,6 @@ class TestContainer(base.BaseZunTest): super(TestContainer, cls).setup_clients() cls.images_client = cls.os_primary.images_client cls.sgs_client = cls.os_primary.sgs_client - cls.vol_client = cls.os_primary.vol_client @classmethod def resource_setup(cls): diff --git a/zun_tempest_plugin/tests/tempest/base.py b/zun_tempest_plugin/tests/tempest/base.py index fae70e6..886b65e 100644 --- a/zun_tempest_plugin/tests/tempest/base.py +++ b/zun_tempest_plugin/tests/tempest/base.py @@ -55,6 +55,7 @@ class BaseZunTest(api_version_utils.BaseMicroversionTest, cls.container_client = cls.os_primary.container_client cls.ports_client = cls.os_primary.ports_client cls.subnetpools_client = cls.os_primary.subnetpools_client + cls.vol_client = cls.os_primary.vol_client @classmethod def setup_credentials(cls):