]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
fullstack: Skip NotFound in safe_client cleanup
authorJakub Libosvar <libosvar@redhat.com>
Tue, 18 Aug 2015 15:05:21 +0000 (15:05 +0000)
committerJakub Libosvar <libosvar@redhat.com>
Wed, 19 Aug 2015 09:18:03 +0000 (09:18 +0000)
If we explicitly remove resource in the test we don't need to fail in
safe_client during cleanup phase.

Change-Id: Ia3b0756b7aa9b159de1949889ae03ca5248bc5fa
Closes-Bug: 1486081

neutron/tests/fullstack/resources/client.py

index 42350793c5944d059df90e744be1ff0444b88131..2297b5f0cbddc3cd410eb53208aa168507031897 100644 (file)
 #    License for the specific language governing permissions and limitations
 #    under the License.
 #
+import functools
 
 import fixtures
+from neutronclient.common import exceptions
 
 from neutron.tests import base
 
 
+def _safe_method(f):
+    @functools.wraps(f)
+    def delete(*args, **kwargs):
+        try:
+            return f(*args, **kwargs)
+        except exceptions.NotFound:
+            pass
+    return delete
+
+
 class ClientFixture(fixtures.Fixture):
     """Manage and cleanup neutron resources."""
 
@@ -32,7 +44,7 @@ class ClientFixture(fixtures.Fixture):
         body = {resource_type: spec}
         resp = create(body=body)
         data = resp[resource_type]
-        self.addCleanup(delete, data['id'])
+        self.addCleanup(_safe_method(delete), data['id'])
         return data
 
     def create_router(self, tenant_id, name=None, ha=False):
@@ -68,5 +80,5 @@ class ClientFixture(fixtures.Fixture):
     def add_router_interface(self, router_id, subnet_id):
         body = {'subnet_id': subnet_id}
         self.client.add_interface_router(router=router_id, body=body)
-        self.addCleanup(self.client.remove_interface_router,
+        self.addCleanup(_safe_method(self.client.remove_interface_router),
                         router=router_id, body=body)