fullstack: Skip NotFound in safe_client cleanup

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
This commit is contained in:
Jakub Libosvar 2015-08-18 15:05:21 +00:00
parent e0bc5239e0
commit a84216b1e0
1 changed files with 14 additions and 2 deletions

View File

@ -12,12 +12,24 @@
# 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)