From a863a803abb11feaa8f61b83909a0d71dc4a0c92 Mon Sep 17 00:00:00 2001 From: Shih-Hao Li Date: Wed, 12 Oct 2016 22:35:53 -0700 Subject: [PATCH] NSXv3: Create logical router after neutron router is created This will avoid dangling backend entries when neutron DB exception occurred during creating a neutron router and retry the API request. Change-Id: I2cba90f4268b67a150d19894fb21fd20daec4c41 --- vmware_nsx/plugins/nsx_v3/plugin.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/vmware_nsx/plugins/nsx_v3/plugin.py b/vmware_nsx/plugins/nsx_v3/plugin.py index 5c3dac2900..e23885d3d9 100644 --- a/vmware_nsx/plugins/nsx_v3/plugin.py +++ b/vmware_nsx/plugins/nsx_v3/plugin.py @@ -2297,16 +2297,32 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, tags = self.nsxlib.build_v3_tags_payload( router['router'], resource_type='os-neutron-router-id', project_name=context.tenant_name) - result = self._router_client.create( - display_name=utils.get_name_and_uuid( - router['router']['name'] or 'router', router['router']['id']), - tags=tags) with context.session.begin(): router = super(NsxV3Plugin, self).create_router( context, router) + + # Create backend entries here in case neutron DB exception + # occurred during super.create_router(), which will cause + # API retry and leaves dangling backend entries. + try: + result = self._router_client.create( + display_name=utils.get_name_and_uuid( + router['name'] or 'router', router['id']), tags=tags) + except nsx_lib_exc.ManagerError: + with excutils.save_and_reraise_exception(): + LOG.error(_LE("Unable to create logical router for " + "neutron router %s"), router['id']) + self.delete_router(context, router['id']) + + try: nsx_db.add_neutron_nsx_router_mapping( context.session, router['id'], result['id']) + except db_exc.DBError: + with excutils.save_and_reraise_exception(): + LOG.error(_LE("Unable to create router mapping for " + "router %s"), router['id']) + self.delete_router(context, router['id']) if gw_info != const.ATTR_NOT_SPECIFIED: try: