Merge "Fix cleanup of resources for object_storage tests"
diff --git a/tempest/api/object_storage/base.py b/tempest/api/object_storage/base.py
index 7107dc4..58ad9d4 100644
--- a/tempest/api/object_storage/base.py
+++ b/tempest/api/object_storage/base.py
@@ -15,6 +15,8 @@
 
 import time
 
+from oslo_log import log
+
 from tempest.common import custom_matchers
 from tempest.common import waiters
 from tempest import config
@@ -23,6 +25,7 @@
 import tempest.test
 
 CONF = config.CONF
+LOG = log.getLogger(__name__)
 
 
 def delete_containers(containers, container_client, object_client):
@@ -41,17 +44,33 @@
 
     for cont in containers:
         try:
-            params = {'limit': 9999, 'format': 'json'}
-            _, objlist = container_client.list_container_objects(cont, params)
-            # delete every object in the container
-            for obj in objlist:
-                object_client.delete_object(cont, obj['name'])
-                object_client.wait_for_resource_deletion(obj['name'], cont)
-            # Verify resource deletion
+            delete_objects(cont, container_client, object_client)
             container_client.delete_container(cont)
             container_client.wait_for_resource_deletion(cont)
         except lib_exc.NotFound:
-            pass
+            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):
diff --git a/tempest/api/object_storage/test_container_acl_negative.py b/tempest/api/object_storage/test_container_acl_negative.py
index 85e6ddb..347c79e 100644
--- a/tempest/api/object_storage/test_container_acl_negative.py
+++ b/tempest/api/object_storage/test_container_acl_negative.py
@@ -41,6 +41,7 @@
         super(ObjectACLsNegativeTest, self).setUp()
         self.container_name = data_utils.rand_name(name='TestContainer')
         self.container_client.update_container(self.container_name)
+        self.containers.append(self.container_name)
 
     @classmethod
     def resource_cleanup(cls):
diff --git a/tempest/api/object_storage/test_object_services.py b/tempest/api/object_storage/test_object_services.py
index 7d5bd26..61b9136 100644
--- a/tempest/api/object_storage/test_object_services.py
+++ b/tempest/api/object_storage/test_object_services.py
@@ -1016,9 +1016,10 @@
         super(PublicObjectTest, self).setUp()
         self.container_name = data_utils.rand_name(name='TestContainer')
         self.container_client.update_container(self.container_name)
+        self.containers.append(self.container_name)
 
     def tearDown(self):
-        self.delete_containers([self.container_name])
+        self.delete_containers()
         super(PublicObjectTest, self).tearDown()
 
     @decorators.idempotent_id('07c9cf95-c0d4-4b49-b9c8-0ef2c9b27193')