Improve cleanup after Swift testing

Use common method to delete objects and containers after Swift
testing. The used method ensures proper deletion before continuing;
simply listing and deleting sometimes raises exeptions due to delayed
executions.

Also fixes a docstring to reflect current behaviour.

Change-Id: Ieaaba496028de741f3e506dac800b151aa833333
This commit is contained in:
Christian Schwede 2021-10-05 09:53:22 +02:00
parent a7bcabc897
commit 663f4a1f26
4 changed files with 11 additions and 15 deletions

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Improve cleanup after Swift testing. Ensures containers are empty before
deleting to prevent errors due to delayed execution.

View File

@ -29,11 +29,6 @@ def delete_containers(containers, container_client, object_client):
The containers should be visible from the container_client given.
Will not throw any error if the containers don't exist.
Will not check that object and container deletions succeed.
After delete all the objects from a container, it will wait 2
seconds before delete the container itself, in order to deployments
using HA proxy sync the deletion properly, otherwise, the container
might fail to be deleted because it's not empty.
:param containers: List of containers(or string of a container)
to be deleted

View File

@ -36,6 +36,11 @@ class ContainerNegativeTest(base.BaseObjectTest):
body = cls.capabilities_client.list_capabilities()
cls.constraints = body['swift']
@classmethod
def resource_cleanup(cls):
cls.delete_containers()
super(ContainerNegativeTest, cls).resource_cleanup()
@decorators.attr(type=["negative"])
@decorators.idempotent_id('30686921-4bed-4764-a038-40d741ed4e78')
@testtools.skipUnless(
@ -167,11 +172,7 @@ class ContainerNegativeTest(base.BaseObjectTest):
# create a container and an object within it
# attempt to delete a container that isn't empty.
container_name = self.create_container()
self.addCleanup(self.container_client.delete_container,
container_name)
object_name, _ = self.create_object(container_name)
self.addCleanup(self.object_client.delete_object,
container_name, object_name)
ex = self.assertRaises(exceptions.Conflict,
self.container_client.delete_container,

View File

@ -18,7 +18,6 @@ from oslo_utils.secretutils import md5
from tempest.api.object_storage import base
from tempest.common import utils
from tempest.lib.common.utils import data_utils
from tempest.lib.common.utils import test_utils
from tempest.lib import decorators
# Each segment, except for the final one, must be at least 1 megabyte
@ -34,11 +33,7 @@ class ObjectSloTest(base.BaseObjectTest):
self.objects = []
def tearDown(self):
for obj in self.objects:
test_utils.call_and_ignore_notfound_exc(
self.object_client.delete_object,
self.container_name, obj)
self.container_client.delete_container(self.container_name)
self.delete_containers()
super(ObjectSloTest, self).tearDown()
def _create_object(self, container_name, object_name, data, params=None):