From: Dan Prince Date: Thu, 9 Jul 2015 19:31:13 +0000 (-0400) Subject: get_vif_ports: ignore non-Interface ports X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=dfbe804994a576994768c95720b4f0ba53e313d7;p=openstack-build%2Fneutron-build.git get_vif_ports: ignore non-Interface ports 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 --- diff --git a/neutron/agent/common/ovs_lib.py b/neutron/agent/common/ovs_lib.py index 6db93474c..49c7a6e9c 100644 --- a/neutron/agent/common/ovs_lib.py +++ b/neutron/agent/common/ovs_lib.py @@ -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: diff --git a/neutron/tests/unit/agent/common/test_ovs_lib.py b/neutron/tests/unit/agent/common/test_ovs_lib.py index 3f0b12b3b..ee0c52eb4 100644 --- a/neutron/tests/unit/agent/common/test_ovs_lib.py +++ b/neutron/tests/unit/agent/common/test_ovs_lib.py @@ -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)