UT: do not hide an original error in test resource ctxtmgr
In unit tests, resource contextmanagers such as network(), subnet() try to delete themselves after returning from yield even if an exception occurs. However when an exception occurs, there is a case where deletion fails. In this case original exception will be hidden and it makes difficult to debug test failures. Before each test starts, resources like database entries will be recreated, so there is no need to try to delete resources even when an exception occurs. This commit removes try-finally clause from resource contextmanagers to make original errors visible. Closes-Bug: #1295887 Change-Id: Ia844d2aa2c9fc036e643068c5284f64798963ee3
This commit is contained in:
parent
e6e5e0daac
commit
38eefdf1a2
@ -125,10 +125,8 @@ class VPNTestMixin(object):
|
|||||||
**kwargs)
|
**kwargs)
|
||||||
if res.status_int >= 400:
|
if res.status_int >= 400:
|
||||||
raise webob.exc.HTTPClientError(code=res.status_int)
|
raise webob.exc.HTTPClientError(code=res.status_int)
|
||||||
try:
|
|
||||||
ikepolicy = self.deserialize(fmt or self.fmt, res)
|
ikepolicy = self.deserialize(fmt or self.fmt, res)
|
||||||
yield ikepolicy
|
yield ikepolicy
|
||||||
finally:
|
|
||||||
if not no_delete:
|
if not no_delete:
|
||||||
self._delete('ikepolicies', ikepolicy['ikepolicy']['id'])
|
self._delete('ikepolicies', ikepolicy['ikepolicy']['id'])
|
||||||
|
|
||||||
@ -188,10 +186,8 @@ class VPNTestMixin(object):
|
|||||||
**kwargs)
|
**kwargs)
|
||||||
if res.status_int >= 400:
|
if res.status_int >= 400:
|
||||||
raise webob.exc.HTTPClientError(code=res.status_int)
|
raise webob.exc.HTTPClientError(code=res.status_int)
|
||||||
try:
|
|
||||||
ipsecpolicy = self.deserialize(fmt or self.fmt, res)
|
ipsecpolicy = self.deserialize(fmt or self.fmt, res)
|
||||||
yield ipsecpolicy
|
yield ipsecpolicy
|
||||||
finally:
|
|
||||||
if not no_delete:
|
if not no_delete:
|
||||||
self._delete('ipsecpolicies', ipsecpolicy['ipsecpolicy']['id'])
|
self._delete('ipsecpolicies', ipsecpolicy['ipsecpolicy']['id'])
|
||||||
|
|
||||||
@ -250,7 +246,7 @@ class VPNTestMixin(object):
|
|||||||
'add',
|
'add',
|
||||||
tmp_router['router']['id'],
|
tmp_router['router']['id'],
|
||||||
tmp_subnet['subnet']['id'], None)
|
tmp_subnet['subnet']['id'], None)
|
||||||
try:
|
|
||||||
res = self._create_vpnservice(fmt,
|
res = self._create_vpnservice(fmt,
|
||||||
name,
|
name,
|
||||||
admin_state_up,
|
admin_state_up,
|
||||||
@ -260,11 +256,9 @@ class VPNTestMixin(object):
|
|||||||
['id']),
|
['id']),
|
||||||
**kwargs)
|
**kwargs)
|
||||||
vpnservice = self.deserialize(fmt or self.fmt, res)
|
vpnservice = self.deserialize(fmt or self.fmt, res)
|
||||||
if res.status_int >= 400:
|
if res.status_int < 400:
|
||||||
raise webob.exc.HTTPClientError(
|
|
||||||
code=res.status_int, detail=vpnservice)
|
|
||||||
yield vpnservice
|
yield vpnservice
|
||||||
finally:
|
|
||||||
if not no_delete and vpnservice.get('vpnservice'):
|
if not no_delete and vpnservice.get('vpnservice'):
|
||||||
self._delete('vpnservices',
|
self._delete('vpnservices',
|
||||||
vpnservice['vpnservice']['id'])
|
vpnservice['vpnservice']['id'])
|
||||||
@ -280,6 +274,9 @@ class VPNTestMixin(object):
|
|||||||
network_id = external_gateway['network_id']
|
network_id = external_gateway['network_id']
|
||||||
self._remove_external_gateway_from_router(
|
self._remove_external_gateway_from_router(
|
||||||
tmp_router['router']['id'], network_id)
|
tmp_router['router']['id'], network_id)
|
||||||
|
if res.status_int >= 400:
|
||||||
|
raise webob.exc.HTTPClientError(
|
||||||
|
code=res.status_int, detail=vpnservice)
|
||||||
|
|
||||||
def _create_ipsec_site_connection(self, fmt, name='test',
|
def _create_ipsec_site_connection(self, fmt, name='test',
|
||||||
peer_address='192.168.1.10',
|
peer_address='192.168.1.10',
|
||||||
@ -379,12 +376,12 @@ class VPNTestMixin(object):
|
|||||||
**kwargs)
|
**kwargs)
|
||||||
if res.status_int >= 400:
|
if res.status_int >= 400:
|
||||||
raise webob.exc.HTTPClientError(code=res.status_int)
|
raise webob.exc.HTTPClientError(code=res.status_int)
|
||||||
try:
|
|
||||||
ipsec_site_connection = self.deserialize(
|
ipsec_site_connection = self.deserialize(
|
||||||
fmt or self.fmt, res
|
fmt or self.fmt, res
|
||||||
)
|
)
|
||||||
yield ipsec_site_connection
|
yield ipsec_site_connection
|
||||||
finally:
|
|
||||||
if not no_delete:
|
if not no_delete:
|
||||||
self._delete(
|
self._delete(
|
||||||
'ipsec-site-connections',
|
'ipsec-site-connections',
|
||||||
|
Loading…
Reference in New Issue
Block a user