]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
update-port error if port does not exist in nvp
authorAaron Rosen <arosen@nicira.com>
Tue, 23 Apr 2013 20:23:17 +0000 (13:23 -0700)
committerAaron Rosen <arosen@nicira.com>
Mon, 6 May 2013 19:54:44 +0000 (12:54 -0700)
Previously the NVP plugin would query NVP for the quantum port id that was
stored in the port as a tag in NVP. Later, a look up table was added in order
to directly look up the ID without having to go to NVP. The problem that can
arise is that if a port was created in folsom before this lookup table was
added and then deleted from NVP directly an error will be raised when calling
update_port(). This patch fixes this potential problem.

Fixes bug 1172006

Change-Id: I08c74e305449f7fe32897abf43ceb430c959b02d

quantum/plugins/nicira/QuantumPlugin.py

index 52879c2a21069632096548d88037eb2a96939069..0b58a1f4ed7cb78837f1fca3bc90686ec2b4033a 100644 (file)
@@ -1262,28 +1262,38 @@ class NvpPluginV2(db_base_plugin_v2.QuantumDbPluginV2,
             LOG.warn(_("Update port request: %s"), port)
             nvp_port_id = self._nvp_get_port_id(
                 context, self.cluster, ret_port)
-            nvplib.update_port(self.cluster,
-                               ret_port['network_id'],
-                               nvp_port_id, id, tenant_id,
-                               ret_port['name'], ret_port['device_id'],
-                               ret_port['admin_state_up'],
-                               ret_port['mac_address'],
-                               ret_port['fixed_ips'],
-                               ret_port[psec.PORTSECURITY],
-                               ret_port[ext_sg.SECURITYGROUPS],
-                               ret_port[ext_qos.QUEUE])
+            if nvp_port_id:
+                try:
+                    nvplib.update_port(self.cluster,
+                                       ret_port['network_id'],
+                                       nvp_port_id, id, tenant_id,
+                                       ret_port['name'], ret_port['device_id'],
+                                       ret_port['admin_state_up'],
+                                       ret_port['mac_address'],
+                                       ret_port['fixed_ips'],
+                                       ret_port[psec.PORTSECURITY],
+                                       ret_port[ext_sg.SECURITYGROUPS],
+                                       ret_port[ext_qos.QUEUE])
+
+                    # Update the port status from nvp. If we fail here hide it
+                    # since the port was successfully updated but we were not
+                    # able to retrieve the status.
+                    ret_port['status'] = nvplib.get_port_status(
+                        self.cluster, ret_port['network_id'],
+                        nvp_port_id)
+                # FIXME(arosen) improve exception handling.
+                except Exception:
+                    ret_port['status'] = constants.PORT_STATUS_ERROR
+                    LOG.exception(_("Unable to update port id: %s."),
+                                  nvp_port_id)
+
+            # If nvp_port_id is not in database or in nvp put in error state.
+            else:
+                ret_port['status'] = constants.PORT_STATUS_ERROR
 
             # remove since it will be added in extend based on policy
             del ret_port[ext_qos.QUEUE]
             self._extend_port_qos_queue(context, ret_port)
-        # Update the port status from nvp. If we fail here hide it since
-        # the port was successfully updated but we were not able to retrieve
-        # the status.
-        try:
-            ret_port['status'] = nvplib.get_port_status(
-                self.cluster, ret_port['network_id'], nvp_port_id)
-        except Exception:
-            LOG.warn(_("Unable to retrieve port status for:%s."), nvp_port_id)
         return ret_port
 
     def delete_port(self, context, id, l3_port_check=True,