]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Check for 'removed' in port_info before reference
authorKevin Benton <blak111@gmail.com>
Tue, 2 Jun 2015 23:52:14 +0000 (16:52 -0700)
committerKevin Benton <blak111@gmail.com>
Wed, 3 Jun 2015 00:04:49 +0000 (17:04 -0700)
scan_ports can return early on no changes, in which case
'removed' won't be present in the dict. The deleted_ports
logic wasn't setup to handle that.

This patch checks for the key before trying to reference it.

Change-Id: I0e2c6d76515ad8e2a2addc8d40451ac003a150f7
Closes-Bug: #1461325

neutron/plugins/openvswitch/agent/ovs_neutron_agent.py
neutron/tests/unit/plugins/openvswitch/agent/test_ovs_neutron_agent.py

index dfe156bfcfdcd932c908c3f613ce36e6d6f762be..40c1de3c0bf7781f19c37e7e6ee64119e50f571a 100644 (file)
@@ -371,7 +371,11 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
         self.deleted_ports.add(port_id)
         LOG.debug("port_delete message processed for port %s", port_id)
 
-    def process_deleted_ports(self):
+    def process_deleted_ports(self, port_info):
+        # don't try to process removed ports as deleted ports since
+        # they are already gone
+        if 'removed' in port_info:
+            self.deleted_ports -= port_info['removed']
         while self.deleted_ports:
             port_id = self.deleted_ports.pop()
             # Flush firewall rules and move to dead VLAN so deleted ports no
@@ -1516,10 +1520,7 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
                     self.updated_ports = set()
                     reg_ports = (set() if ovs_restarted else ports)
                     port_info = self.scan_ports(reg_ports, updated_ports_copy)
-                    # don't try to process removed ports as deleted ports since
-                    # they are already gone
-                    self.deleted_ports -= port_info['removed']
-                    self.process_deleted_ports()
+                    self.process_deleted_ports(port_info)
                     self.update_stale_ofport_rules()
                     LOG.debug("Agent rpc_loop - iteration:%(iter_num)d - "
                               "port information retrieved. "
index 8344764020bd16acf9f745f71d28613f14112cda..d8cd5a8c644151436d0a2246c20cd40d9a70526b 100644 (file)
@@ -536,7 +536,7 @@ class TestOvsNeutronAgent(object):
             int_br.get_vif_port_by_id.return_value = vif
             self.agent.port_delete("unused_context",
                                    port_id='id')
-            self.agent.process_deleted_ports()
+            self.agent.process_deleted_ports(port_info={})
             # the main things we care about are that it gets put in the
             # dead vlan and gets blocked
             int_br.set_db_attribute.assert_any_call(
@@ -544,6 +544,15 @@ class TestOvsNeutronAgent(object):
                 log_errors=False)
             int_br.drop_port.assert_called_once_with(in_port=vif.ofport)
 
+    def test_port_delete_removed_port(self):
+        with mock.patch.object(self.agent, 'int_br') as int_br:
+            self.agent.port_delete("unused_context",
+                                   port_id='id')
+            # if it was removed from the bridge, we shouldn't be processing it
+            self.agent.process_deleted_ports(port_info={'removed': {'id', }})
+            self.assertFalse(int_br.set_db_attribute.called)
+            self.assertFalse(int_br.drop_port.called)
+
     def test_setup_physical_bridges(self):
         with mock.patch.object(ip_lib, "device_exists") as devex_fn,\
                 mock.patch.object(sys, "exit"),\