From 18c07ae15e03e2d0e0a17d171f3f056b7e4700a7 Mon Sep 17 00:00:00 2001 From: Rajat Dhasmana Date: Fri, 8 Sep 2023 12:38:10 +0000 Subject: [PATCH] Revert "Fix cleanup for volume backup tests" This reverts commit 2c2484ca6e1835105b4e322a65f6e7f588736e61. Reason for revert: This change causes failures in RBD backup tests where a container is not expected but being passed by this change. See failures at http://storage.gra.cloud.ovh.net/v1/AUTH_dcaab5e32b234d56b626f72581e3644c/zuul_opendev_logs_56f/889826/1/check/cinder-plugin-ceph-tempest/56f21fd/testr_results.html Change-Id: I98a75cbf119ba8126253a681c046f4cf44b1607e --- tempest/api/object_storage/base.py | 49 +++++++++++++- .../api/object_storage/test_account_bulk.py | 6 +- .../object_storage/test_account_services.py | 3 +- .../api/object_storage/test_container_sync.py | 3 +- .../api/object_storage/test_object_version.py | 5 +- tempest/api/volume/base.py | 20 +----- tempest/api/volume/test_volumes_backup.py | 6 +- tempest/common/object_storage.py | 64 ------------------- 8 files changed, 55 insertions(+), 101 deletions(-) delete mode 100644 tempest/common/object_storage.py diff --git a/tempest/api/object_storage/base.py b/tempest/api/object_storage/base.py index 8adbe7d791..58ad9d4eda 100644 --- a/tempest/api/object_storage/base.py +++ b/tempest/api/object_storage/base.py @@ -18,7 +18,6 @@ import time from oslo_log import log from tempest.common import custom_matchers -from tempest.common import object_storage from tempest.common import waiters from tempest import config from tempest.lib.common.utils import data_utils @@ -29,6 +28,51 @@ CONF = config.CONF LOG = log.getLogger(__name__) +def delete_containers(containers, container_client, object_client): + """Remove containers and all objects in them. + + The containers should be visible from the container_client given. + Will not throw any error if the containers don't exist. + + :param containers: List of containers(or string of a container) + to be deleted + :param container_client: Client to be used to delete containers + :param object_client: Client to be used to delete objects + """ + if isinstance(containers, str): + containers = [containers] + + for cont in containers: + try: + delete_objects(cont, container_client, object_client) + container_client.delete_container(cont) + container_client.wait_for_resource_deletion(cont) + except lib_exc.NotFound: + LOG.warning(f"Container {cont} wasn't deleted as it wasn't found.") + + +def delete_objects(container, container_client, object_client): + """Remove all objects from container. + + Will not throw any error if the objects do not exist + + :param container: Name of the container that contains the objects to be + deleted + :param container_client: Client to be used to list objects in + the container + :param object_client: Client to be used to delete objects + """ + params = {'limit': 9999, 'format': 'json'} + _, objlist = container_client.list_container_objects(container, params) + + for obj in objlist: + try: + object_client.delete_object(container, obj['name']) + object_client.wait_for_resource_deletion(obj['name'], container) + except lib_exc.NotFound: + LOG.warning(f"Object {obj} wasn't deleted as it wasn't found.") + + class BaseObjectTest(tempest.test.BaseTestCase): credentials = [['operator', CONF.object_storage.operator_role]] @@ -116,8 +160,7 @@ class BaseObjectTest(tempest.test.BaseTestCase): container_client = cls.container_client if object_client is None: object_client = cls.object_client - object_storage.delete_containers(cls.containers, container_client, - object_client) + delete_containers(cls.containers, container_client, object_client) def assertHeaders(self, resp, target, method): """Check the existence and the format of response headers""" diff --git a/tempest/api/object_storage/test_account_bulk.py b/tempest/api/object_storage/test_account_bulk.py index 0ecae85789..687fe5750a 100644 --- a/tempest/api/object_storage/test_account_bulk.py +++ b/tempest/api/object_storage/test_account_bulk.py @@ -16,7 +16,6 @@ import tarfile import tempfile from tempest.api.object_storage import base -from tempest.common import object_storage from tempest.common import utils from tempest.lib import decorators @@ -31,9 +30,8 @@ class BulkTest(base.BaseObjectTest): def tearDown(self): # NOTE(andreaf) BulkTests needs to cleanup containers after each # test is executed. - object_storage.delete_containers(self.containers, - self.container_client, - self.object_client) + base.delete_containers(self.containers, self.container_client, + self.object_client) super(BulkTest, self).tearDown() def _create_archive(self): diff --git a/tempest/api/object_storage/test_account_services.py b/tempest/api/object_storage/test_account_services.py index b7a413e178..4966ec4017 100644 --- a/tempest/api/object_storage/test_account_services.py +++ b/tempest/api/object_storage/test_account_services.py @@ -18,7 +18,6 @@ import testtools from tempest.api.object_storage import base from tempest.common import custom_matchers -from tempest.common import object_storage from tempest import config from tempest.lib.common.utils import data_utils from tempest.lib import decorators @@ -44,7 +43,7 @@ class AccountTest(base.BaseObjectTest): for i in range(ord('a'), ord('f') + 1): name = data_utils.rand_name(name='%s-' % bytes((i,))) cls.container_client.update_container(name) - cls.addClassResourceCleanup(object_storage.delete_containers, + cls.addClassResourceCleanup(base.delete_containers, [name], cls.container_client, cls.object_client) diff --git a/tempest/api/object_storage/test_container_sync.py b/tempest/api/object_storage/test_container_sync.py index 9b1d3c7600..b31ff7654b 100644 --- a/tempest/api/object_storage/test_container_sync.py +++ b/tempest/api/object_storage/test_container_sync.py @@ -19,7 +19,6 @@ from urllib import parse as urlparse import testtools from tempest.api.object_storage import base -from tempest.common import object_storage from tempest import config from tempest.lib.common.utils import data_utils from tempest.lib import decorators @@ -75,7 +74,7 @@ class ContainerSyncTest(base.BaseObjectTest): (cls.container_client_alt, cls.object_client_alt) for cont_name, client in cls.clients.items(): client[0].create_container(cont_name) - cls.addClassResourceCleanup(object_storage.delete_containers, + cls.addClassResourceCleanup(base.delete_containers, cont_name, client[0], client[1]) diff --git a/tempest/api/object_storage/test_object_version.py b/tempest/api/object_storage/test_object_version.py index 2a1f63e5bf..b64b1729dd 100644 --- a/tempest/api/object_storage/test_object_version.py +++ b/tempest/api/object_storage/test_object_version.py @@ -16,7 +16,6 @@ import testtools from tempest.api.object_storage import base -from tempest.common import object_storage from tempest import config from tempest.lib.common.utils import data_utils from tempest.lib import decorators @@ -54,7 +53,7 @@ class ContainerTest(base.BaseObjectTest): # create container vers_container_name = data_utils.rand_name(name='TestVersionContainer') resp, _ = self.container_client.update_container(vers_container_name) - self.addCleanup(object_storage.delete_containers, + self.addCleanup(base.delete_containers, [vers_container_name], self.container_client, self.object_client) @@ -66,7 +65,7 @@ class ContainerTest(base.BaseObjectTest): resp, _ = self.container_client.update_container( base_container_name, **headers) - self.addCleanup(object_storage.delete_containers, + self.addCleanup(base.delete_containers, [base_container_name], self.container_client, self.object_client) diff --git a/tempest/api/volume/base.py b/tempest/api/volume/base.py index df7801d75a..a31390a98d 100644 --- a/tempest/api/volume/base.py +++ b/tempest/api/volume/base.py @@ -14,7 +14,6 @@ # under the License. from tempest.common import compute -from tempest.common import object_storage from tempest.common import waiters from tempest import config from tempest.lib.common import api_version_utils @@ -65,8 +64,6 @@ class BaseVolumeTest(api_version_utils.BaseMicroversionTest, if CONF.service_available.glance: cls.images_client = cls.os_primary.image_client_v2 - cls.container_client = cls.os_primary.container_client - cls.object_client = cls.os_primary.object_client cls.backups_client = cls.os_primary.backups_client_latest cls.volumes_client = cls.os_primary.volumes_client_latest cls.messages_client = cls.os_primary.volume_messages_client_latest @@ -173,31 +170,16 @@ class BaseVolumeTest(api_version_utils.BaseMicroversionTest, snapshot['id'], 'available') return snapshot - def create_backup(self, volume_id, backup_client=None, object_client=None, - container_client=None, **kwargs): + def create_backup(self, volume_id, backup_client=None, **kwargs): """Wrapper utility that returns a test backup.""" if backup_client is None: backup_client = self.backups_client - if container_client is None: - container_client = self.container_client - if object_client is None: - object_client = self.object_client if 'name' not in kwargs: name = data_utils.rand_name(self.__class__.__name__ + '-Backup') kwargs['name'] = name - if 'container' not in kwargs: - cont_name = self.__class__.__name__ + '-backup-container' - cont = data_utils.rand_name(cont_name) - kwargs['container'] = cont backup = backup_client.create_backup( volume_id=volume_id, **kwargs)['backup'] - - if CONF.service_available.swift: - self.addCleanup(object_storage.delete_containers, - kwargs['container'], container_client, - object_client) - # addCleanup uses list pop to cleanup. Wait should be added before # the backup is deleted self.addCleanup(backup_client.wait_for_resource_deletion, diff --git a/tempest/api/volume/test_volumes_backup.py b/tempest/api/volume/test_volumes_backup.py index 8e89a0a6c6..85e4bb272e 100644 --- a/tempest/api/volume/test_volumes_backup.py +++ b/tempest/api/volume/test_volumes_backup.py @@ -77,13 +77,11 @@ class VolumesBackupsTest(base.BaseVolumeTest): # Create a backup backup_name = data_utils.rand_name( self.__class__.__name__ + '-Backup') - container_name = data_utils.rand_name( - self.__class__.__name__ + '-Backup-container') description = data_utils.rand_name("volume-backup-description") backup = self.create_backup(volume_id=volume['id'], name=backup_name, description=description, - container=container_name) + container='container') self.assertEqual(backup_name, backup['name']) waiters.wait_for_volume_resource_status(self.volumes_client, volume['id'], 'available') @@ -92,7 +90,7 @@ class VolumesBackupsTest(base.BaseVolumeTest): backup = self.backups_client.show_backup(backup['id'])['backup'] self.assertEqual(backup_name, backup['name']) self.assertEqual(description, backup['description']) - self.assertEqual(container_name, backup['container']) + self.assertEqual('container', backup['container']) # Get all backups with detail backups = self.backups_client.list_backups(detail=True)['backups'] diff --git a/tempest/common/object_storage.py b/tempest/common/object_storage.py deleted file mode 100644 index 7ffdc428bb..0000000000 --- a/tempest/common/object_storage.py +++ /dev/null @@ -1,64 +0,0 @@ -# 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 oslo_log import log - -from tempest import config -from tempest.lib import exceptions as lib_exc - -CONF = config.CONF -LOG = log.getLogger(__name__) - - -def delete_containers(containers, container_client, object_client): - """Remove containers and all objects in them. - - The containers should be visible from the container_client given. - Will not throw any error if the containers don't exist. - - :param containers: List of containers(or string of a container) - to be deleted - :param container_client: Client to be used to delete containers - :param object_client: Client to be used to delete objects - """ - if isinstance(containers, str): - containers = [containers] - - for cont in containers: - try: - delete_objects(cont, container_client, object_client) - container_client.delete_container(cont) - container_client.wait_for_resource_deletion(cont) - except lib_exc.NotFound: - LOG.warning(f"Container {cont} wasn't deleted as it wasn't found.") - - -def delete_objects(container, container_client, object_client): - """Remove all objects from container. - - Will not throw any error if the objects do not exist - - :param container: Name of the container that contains the objects to be - deleted - :param container_client: Client to be used to list objects in - the container - :param object_client: Client to be used to delete objects - """ - params = {'limit': 9999, 'format': 'json'} - _, objlist = container_client.list_container_objects(container, params) - - for obj in objlist: - try: - object_client.delete_object(container, obj['name']) - object_client.wait_for_resource_deletion(obj['name'], container) - except lib_exc.NotFound: - LOG.warning(f"Object {obj} wasn't deleted as it wasn't found.")