Merge "fullstack: Skip NotFound in safe_client cleanup"

This commit is contained in:
Jenkins 2015-08-21 01:39:21 +00:00 committed by Gerrit Code Review
commit bbf213a87d

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):
@ -75,5 +87,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)