]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
get_vif_ports: ignore non-Interface ports
authorDan Prince <dprince@redhat.com>
Thu, 9 Jul 2015 19:31:13 +0000 (15:31 -0400)
committerDan Prince <dprince@redhat.com>
Fri, 10 Jul 2015 14:47:50 +0000 (10:47 -0400)
This patch updates get_vif_ports so that it skips
ports which aren't in the 'Interfaces' table.

This fixes an issue where neutron-ovs-cleanup would
fail if any sort of OVS bond was on the bridge getting
cleaned up.  This is because bonds don't have the same
attributes as ports, and thus fail subsequent ovs-vsctl
queries.

Change-Id: Ic9d30e5916122ce23c5dc8631fbb71115ae8a960
Closes-bug: #1473179

neutron/agent/common/ovs_lib.py
neutron/tests/unit/agent/common/test_ovs_lib.py

index 6db93474cec7ce8765eefaab20f6a1312a5d9193..49c7a6e9c19d0c8efb688dd954d0c895f2fa2ea4 100644 (file)
@@ -329,6 +329,10 @@ class OVSBridge(BaseOVS):
             'Interface', columns=['name', 'external_ids', 'ofport'])
         by_name = {x['name']: x for x in port_info}
         for name in port_names:
+            if not by_name.get(name):
+                #NOTE(dprince): some ports (like bonds) won't have all
+                # these attributes so we skip them entirely
+                continue
             external_ids = by_name[name]['external_ids']
             ofport = by_name[name]['ofport']
             if "iface-id" in external_ids and "attached-mac" in external_ids:
index 3f0b12b3b850c51733c911bc56d83234e19e5cf1..ee0c52eb4b965e1558e2997456e46196e3ed78fe 100644 (file)
@@ -577,6 +577,23 @@ class OVS_Lib_Test(base.BaseTestCase):
     def test_get_vif_ports_xen(self):
         self._test_get_vif_ports(is_xen=True)
 
+    def test_get_vif_ports_with_bond(self):
+        pname = "bond0"
+        #NOTE(dprince): bond ports don't have records in the Interface table
+        external_ids = ('{"data":[], "headings":[]}')
+
+        # Each element is a tuple of (expected mock call, return_value)
+        expected_calls_and_values = [
+            (self._vsctl_mock("list-ports", self.BR_NAME), "%s\n" % pname),
+            (self._vsctl_mock("--columns=name,external_ids,ofport", "list",
+                              "Interface"), external_ids),
+        ]
+        tools.setup_mock_calls(self.execute, expected_calls_and_values)
+
+        ports = self.br.get_vif_ports()
+        self.assertEqual(0, len(ports))
+        tools.verify_mock_calls(self.execute, expected_calls_and_values)
+
     def test_get_vif_port_set_nonxen(self):
         self._test_get_vif_port_set(False)