]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Properly synchronize status for ports deleted from backend
authorSalvatore Orlando <salv.orlando@gmail.com>
Tue, 24 Sep 2013 14:40:51 +0000 (07:40 -0700)
committerSalvatore Orlando <salv.orlando@gmail.com>
Tue, 24 Sep 2013 14:40:51 +0000 (07:40 -0700)
Ensure that the status for a port is properly synchronized even
when the port itself does not exist anymore in the backend, avoiding
raising exceptions due to missing results in the NVP query.

This patch also adjusts a comment and improves exception handling
in _nvp_get_port_id

Bug 1229331

Change-Id: Ibaa581006c994a543c1795dd3f1d50086583b953

neutron/plugins/nicira/NeutronPlugin.py
neutron/plugins/nicira/common/sync.py

index ae052a66db4bcbc0154487507675402d2d124089..3abe5d4b75b9dec7cbe0a76114527ae6e1a49d37 100644 (file)
@@ -741,16 +741,16 @@ class NvpPluginV2(addr_pair_db.AllowedAddressPairsMixin,
                 cluster,
                 neutron_port['network_id'],
                 neutron_port['id'])
-            if nvp_port:
-                nicira_db.add_neutron_nvp_port_mapping(
-                    context.session,
-                    neutron_port['id'],
-                    nvp_port['uuid'])
-                return nvp_port['uuid']
-        except Exception:
+        except NvpApiClient.NvpApiException:
             LOG.exception(_("Unable to find NVP uuid for Neutron port %s"),
                           neutron_port['id'])
 
+        if nvp_port:
+            nicira_db.add_neutron_nvp_port_mapping(
+                context.session, neutron_port['id'],
+                nvp_port['uuid'])
+            return nvp_port['uuid']
+
     def _extend_fault_map(self):
         """Extends the Neutron Fault Map.
 
index 687702e7cc018f29be68ba10a258267c5425bcdb..dfbc79afa91d3f4e0bb3ad65e6a58e452c335856 100644 (file)
@@ -381,17 +381,19 @@ class NvpSynchronizer():
                     lswitchport = nvplib.get_port(
                         self._cluster, neutron_port_data['network_id'],
                         lp_uuid, relations='LogicalPortStatus')
-            except exceptions.PortNotFoundOnNetwork:
+            except (exceptions.PortNotFoundOnNetwork):
                 # NOTE(salv-orlando): We should be catching
-                # NvpApiClient.ResourceNotFound here
-                # The logical switch port was not found
+                # NvpApiClient.ResourceNotFound here instead
+                # of PortNotFoundOnNetwork when the id exists but
+                # the logical switch port was not found
                 LOG.warning(_("Logical switch port for neutron port %s "
                               "not found on NVP."), neutron_port_data['id'])
                 lswitchport = None
             else:
-                # Update the cache
-                self._nvp_cache.update_lswitchport(lswitchport)
-
+                # If lswitchport is not None, update the cache.
+                # It could be none if the port was deleted from the backend
+                if lswitchport:
+                    self._nvp_cache.update_lswitchport(lswitchport)
         # Note(salv-orlando): It might worth adding a check to verify neutron
         # resource tag in nvp entity matches Neutron id.
         # By default assume things go wrong