Merge "UT: do not hide an original error in test resource ctxtmgr"

This commit is contained in:
Jenkins 2014-03-31 06:32:15 +00:00 committed by Gerrit Code Review
commit 5a5cc61272
14 changed files with 210 additions and 256 deletions

View File

@ -303,9 +303,7 @@ class TestCiscoPortsV2(CiscoNetworkPluginV2TestCase,
res = self._create_port(self.fmt, net_id, arg_list=args,
context=ctx, **port_dict)
port = self.deserialize(self.fmt, res)
try:
yield res
finally:
if do_delete:
self._delete('ports', port['port']['id'])
@ -961,9 +959,7 @@ class TestCiscoNetworksV2(CiscoNetworkPluginV2TestCase,
res = self._create_network(self.fmt, net_name, True,
arg_list=arg_list, **provider_attrs)
network = self.deserialize(self.fmt, res)['network']
try:
yield network
finally:
req = self.new_delete_request('networks', network['id'])
req.get_response(self.api)
@ -1073,9 +1069,7 @@ class TestCiscoRouterInterfacesV2(CiscoNetworkPluginV2TestCase):
request = self.new_create_request('routers', data, self.fmt)
response = request.get_response(self.ext_api)
router = self.deserialize(self.fmt, response)
try:
yield network, subnet, router
finally:
self._delete('routers', router['router']['id'])
@contextlib.contextmanager
@ -1089,9 +1083,9 @@ class TestCiscoRouterInterfacesV2(CiscoNetworkPluginV2TestCase):
router['router']['id'],
'add_router_interface')
response = request.get_response(self.ext_api)
try:
yield response
finally:
# If router interface was created successfully, delete it now.
if response.status_int == wexc.HTTPOk.code:
request = self.new_action_request('routers', interface_data,

View File

@ -188,9 +188,7 @@ class FirewallPluginDbTestCase(test_db_plugin.NeutronDbPluginV2TestCase):
if res.status_int >= 400:
raise webob.exc.HTTPClientError(code=res.status_int)
firewall_policy = self.deserialize(fmt or self.fmt, res)
try:
yield firewall_policy
finally:
if not no_delete:
self._delete('firewall_policies',
firewall_policy['firewall_policy']['id'])
@ -240,9 +238,7 @@ class FirewallPluginDbTestCase(test_db_plugin.NeutronDbPluginV2TestCase):
if res.status_int >= 400:
raise webob.exc.HTTPClientError(code=res.status_int)
firewall_rule = self.deserialize(fmt or self.fmt, res)
try:
yield firewall_rule
finally:
if not no_delete:
self._delete('firewall_rules',
firewall_rule['firewall_rule']['id'])
@ -275,9 +271,7 @@ class FirewallPluginDbTestCase(test_db_plugin.NeutronDbPluginV2TestCase):
if res.status_int >= 400:
raise webob.exc.HTTPClientError(code=res.status_int)
firewall = self.deserialize(fmt or self.fmt, res)
try:
yield firewall
finally:
if not no_delete:
self._delete('firewalls', firewall['firewall']['id'])

View File

@ -227,10 +227,8 @@ class LoadBalancerTestMixin(object):
explanation=_("Unexpected error code: %s") %
res.status_int
)
try:
vip = self.deserialize(fmt or self.fmt, res)
yield vip
finally:
if not no_delete:
self._delete('vips', vip['vip']['id'])
@ -250,10 +248,8 @@ class LoadBalancerTestMixin(object):
raise webob.exc.HTTPClientError(
explanation=_("Unexpected error code: %s") % res.status_int
)
try:
pool = self.deserialize(fmt or self.fmt, res)
yield pool
finally:
if not no_delete:
self._delete('pools', pool['pool']['id'])
@ -271,10 +267,8 @@ class LoadBalancerTestMixin(object):
raise webob.exc.HTTPClientError(
explanation=_("Unexpected error code: %s") % res.status_int
)
try:
member = self.deserialize(fmt or self.fmt, res)
yield member
finally:
if not no_delete:
self._delete('members', member['member']['id'])
@ -310,9 +304,7 @@ class LoadBalancerTestMixin(object):
else:
for arg in http_related_attributes:
self.assertIsNone(the_health_monitor.get(arg))
try:
yield health_monitor
finally:
if not no_delete:
self._delete('health_monitors', the_health_monitor['id'])

View File

@ -96,9 +96,7 @@ class MeteringPluginDbTestCaseMixin(object):
fmt = self.fmt
metering_label = self._make_metering_label(fmt, name,
description, **kwargs)
try:
yield metering_label
finally:
if not no_delete:
self._delete('metering-labels',
metering_label['metering_label']['id'])
@ -114,9 +112,7 @@ class MeteringPluginDbTestCaseMixin(object):
direction,
remote_ip_prefix,
excluded)
try:
yield metering_label_rule
finally:
if not no_delete:
self._delete('metering-label-rules',
metering_label_rule['metering_label_rule']['id'])

View File

@ -125,10 +125,8 @@ class VPNTestMixin(object):
**kwargs)
if res.status_int >= 400:
raise webob.exc.HTTPClientError(code=res.status_int)
try:
ikepolicy = self.deserialize(fmt or self.fmt, res)
yield ikepolicy
finally:
if not no_delete:
self._delete('ikepolicies', ikepolicy['ikepolicy']['id'])
@ -188,10 +186,8 @@ class VPNTestMixin(object):
**kwargs)
if res.status_int >= 400:
raise webob.exc.HTTPClientError(code=res.status_int)
try:
ipsecpolicy = self.deserialize(fmt or self.fmt, res)
yield ipsecpolicy
finally:
if not no_delete:
self._delete('ipsecpolicies', ipsecpolicy['ipsecpolicy']['id'])
@ -250,7 +246,7 @@ class VPNTestMixin(object):
'add',
tmp_router['router']['id'],
tmp_subnet['subnet']['id'], None)
try:
res = self._create_vpnservice(fmt,
name,
admin_state_up,
@ -260,11 +256,9 @@ class VPNTestMixin(object):
['id']),
**kwargs)
vpnservice = self.deserialize(fmt or self.fmt, res)
if res.status_int >= 400:
raise webob.exc.HTTPClientError(
code=res.status_int, detail=vpnservice)
if res.status_int < 400:
yield vpnservice
finally:
if not no_delete and vpnservice.get('vpnservice'):
self._delete('vpnservices',
vpnservice['vpnservice']['id'])
@ -280,6 +274,9 @@ class VPNTestMixin(object):
network_id = external_gateway['network_id']
self._remove_external_gateway_from_router(
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',
peer_address='192.168.1.10',
@ -379,12 +376,12 @@ class VPNTestMixin(object):
**kwargs)
if res.status_int >= 400:
raise webob.exc.HTTPClientError(code=res.status_int)
try:
ipsec_site_connection = self.deserialize(
fmt or self.fmt, res
)
yield ipsec_site_connection
finally:
if not no_delete:
self._delete(
'ipsec-site-connections',

View File

@ -97,9 +97,7 @@ class TestNecPluginPacketFilterBase(test_nec_plugin.NecPluginV2TestCase):
with test_plugin.optional_ctx(network, self.network) as network_to_use:
net_id = network_to_use['network']['id']
pf = self._make_packet_filter(fmt or self.fmt, net_id, **kwargs)
try:
yield pf
finally:
if do_delete:
self._delete('packet_filters', pf['packet_filter']['id'])
@ -121,9 +119,7 @@ class TestNecPluginPacketFilterBase(test_nec_plugin.NecPluginV2TestCase):
kwargs['in_port'] = port_id
pf = self._make_packet_filter(fmt or self.fmt, net_id, **kwargs)
self.assertEqual(port_id, pf['packet_filter']['in_port'])
try:
yield pf
finally:
if do_delete:
self._delete('packet_filters', pf['packet_filter']['id'])

View File

@ -63,9 +63,7 @@ class NetPartitionTestCase(test_nuage_plugin.NuagePluginV2TestCase):
**kwargs):
netpart = self._make_netpartition(fmt or self.fmt, name)
try:
yield netpart
finally:
if do_delete:
self._del_netpartition(netpart['net_partition']['id'])

View File

@ -523,9 +523,7 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase):
**kwargs):
network = self._make_network(fmt or self.fmt, name,
admin_state_up, **kwargs)
try:
yield network
finally:
if do_delete:
# The do_delete parameter allows you to control whether the
# created network is immediately deleted again. Therefore, this
@ -560,9 +558,7 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase):
shared=shared,
ipv6_ra_mode=ipv6_ra_mode,
ipv6_address_mode=ipv6_address_mode)
try:
yield subnet
finally:
if do_delete:
self._delete('subnets', subnet['subnet']['id'])
@ -572,9 +568,7 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase):
with optional_ctx(subnet, self.subnet) as subnet_to_use:
net_id = subnet_to_use['subnet']['network_id']
port = self._make_port(fmt or self.fmt, net_id, **kwargs)
try:
yield port
finally:
if not no_delete:
self._delete('ports', port['port']['id'])

View File

@ -126,9 +126,7 @@ class SecurityGroupsTestCase(test_db_plugin.NeutronDbPluginV2TestCase):
if not fmt:
fmt = self.fmt
security_group = self._make_security_group(fmt, name, description)
try:
yield security_group
finally:
if not no_delete:
self._delete('security-groups',
security_group['security_group']['id'])
@ -150,9 +148,7 @@ class SecurityGroupsTestCase(test_db_plugin.NeutronDbPluginV2TestCase):
remote_group_id,
ethertype=ethertype)
security_group_rule = self._make_security_group_rule(self.fmt, rule)
try:
yield security_group_rule
finally:
if not no_delete:
self._delete('security-group-rules',
security_group_rule['security_group_rule']['id'])

View File

@ -358,9 +358,7 @@ class L3NatTestCaseMixin(object):
router = self._make_router(fmt or self.fmt, tenant_id, name,
admin_state_up, external_gateway_info,
set_context, **kwargs)
try:
yield router
finally:
self._delete('routers', router['router']['id'])
def _set_net_external(self, net_id):
@ -413,7 +411,7 @@ class L3NatTestCaseMixin(object):
sid = private_port['port']['fixed_ips'][0]['subnet_id']
private_sub = {'subnet': {'id': sid}}
floatingip = None
try:
self._add_external_gateway_to_router(
r['router']['id'],
public_sub['subnet']['network_id'])
@ -428,7 +426,7 @@ class L3NatTestCaseMixin(object):
fixed_ip=fixed_ip,
set_context=False)
yield floatingip
finally:
if floatingip:
self._delete('floatingips',
floatingip['floatingip']['id'])
@ -445,7 +443,7 @@ class L3NatTestCaseMixin(object):
self._set_net_external(public_sub['subnet']['network_id'])
with self.router() as r:
floatingip = None
try:
self._add_external_gateway_to_router(
r['router']['id'],
public_sub['subnet']['network_id'])
@ -458,7 +456,7 @@ class L3NatTestCaseMixin(object):
public_sub['subnet']['network_id'],
set_context=set_context)
yield floatingip, r
finally:
if floatingip:
self._delete('floatingips',
floatingip['floatingip']['id'])

View File

@ -117,9 +117,9 @@ class L3SchedulerTestCase(l3_agentschedulers_db.L3AgentSchedulerDbMixin,
self._add_external_gateway_to_router(
router['router']['id'],
subnet['subnet']['network_id'])
try:
yield router
finally:
self._remove_external_gateway_from_router(
router['router']['id'], subnet['subnet']['network_id'])
self._delete('routers', router['router']['id'])

View File

@ -76,9 +76,9 @@ class TestQoSQueue(NsxPluginV2TestCase):
qos_queue = self.deserialize('json', res)
if res.status_int >= 400:
raise webob.exc.HTTPClientError(code=res.status_int)
try:
yield qos_queue
finally:
if not no_delete:
self._delete('qos-queues',
qos_queue['qos_queue']['id'])

View File

@ -355,9 +355,8 @@ class SyncTestCase(base.BaseTestCase):
routers.append(self._plugin.create_router(ctx, router(i)))
# Do not return anything as the user does need the actual
# data created
try:
yield
finally:
# Remove everything
for router in routers:
self._plugin.delete_router(ctx, router['id'])

View File

@ -85,7 +85,7 @@ class TestVpnPlugin(test_db_vpnaas.VPNTestMixin,
data = {'router': {'tenant_id': self._tenant_id}}
data['router']['service_router'] = True
router_req = self.new_create_request('routers', data, self.fmt)
try:
res = router_req.get_response(self.ext_api)
router = self.deserialize(self.fmt, res)
self._add_external_gateway_to_router(
@ -93,7 +93,7 @@ class TestVpnPlugin(test_db_vpnaas.VPNTestMixin,
s['subnet']['network_id'])
router = self._show('routers', router['router']['id'])
yield router
finally:
self._delete('routers', router['router']['id'])
def test_create_vpnservice(self, **extras):