r = router['router']
gw_info = r.pop(EXTERNAL_GW_INFO, None)
tenant_id = self._get_tenant_id_for_create(context, r)
- with context.session.begin(subtransactions=True):
- router_db = self._create_router_db(context, r, tenant_id)
+ router_db = self._create_router_db(context, r, tenant_id)
+ try:
if gw_info:
self._update_router_gw_info(context, router_db['id'],
gw_info, router=router_db)
+ except Exception:
+ with excutils.save_and_reraise_exception():
+ LOG.exception(_LE("An exception occurred while creating "
+ "the router: %s"), router)
+ self.delete_router(context, router_db.id)
+
return self._make_router_dict(router_db)
def _update_router_db(self, context, router_id, data, gw_info):
fip['floatingip']['floating_ip_address'])
self.assertEqual(floating_ip.version, 4)
+ def test_create_router_gateway_fails(self):
+ # Force _update_router_gw_info failure
+ plugin = manager.NeutronManager.get_service_plugins()[
+ service_constants.L3_ROUTER_NAT]
+ ctx = context.Context('', 'foo')
+ plugin._update_router_gw_info = mock.Mock(
+ side_effect=n_exc.NeutronException)
+ data = {'router': {
+ 'name': 'router1', 'admin_state_up': True,
+ 'external_gateway_info': {'network_id': 'some_uuid'}}}
+
+ # Verify router doesn't persist on failure
+ self.assertRaises(n_exc.NeutronException,
+ plugin.create_router, ctx, data)
+ routers = plugin.get_routers(ctx)
+ self.assertEqual(0, len(routers))
+
class L3AgentDbTestCaseBase(L3NatTestCaseMixin):