NSX|V3: Remove neutron port if failed to create backend port

During create_port, a neutron port is created before creating
a NSX backend port. If the backend operation failed, we need
to delete the neutron port from DB.

Change-Id: I497fb3aa96095fd87acf84f4bc3ee1b2814f08b6
This commit is contained in:
Shih-Hao Li 2016-02-12 11:52:22 -08:00 committed by garyk
parent 7b216ebf78
commit 8d41bccb9c

View File

@ -776,9 +776,18 @@ class NsxV3Plugin(addr_pair_db.AllowedAddressPairsMixin,
# Operations to backend should be done outside of DB transaction.
if not is_external_net:
lport = self._create_port_at_the_backend(
context, neutron_db, port_data,
l2gw_port_check, is_psec_on)
try:
lport = self._create_port_at_the_backend(
context, neutron_db, port_data,
l2gw_port_check, is_psec_on)
except Exception:
with excutils.save_and_reraise_exception():
LOG.exception(
_LE('Failed to create port %s on NSX backend'),
neutron_db['id'])
with context.session.begin(subtransactions=True):
super(NsxV3Plugin, self).delete_port(context,
neutron_db['id'])
if sgids:
try: