From: Kevin Benton Date: Tue, 31 Mar 2015 03:29:51 +0000 (-0700) Subject: Handle no ofport in get_vif_port_to_ofport_map X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=1c1981e3ce16e73499bf3f9064e7f366c057ab74;p=openstack-build%2Fneutron-build.git Handle no ofport in get_vif_port_to_ofport_map Newly added ports to OVSDB might not yet have an ofport number assigned to them. This causes the return from the DB query to return a list instead of a port number. This patch handles that by attempting to convert each result into an integer and then catching the exception and continuing through the iteration to ignore uninitialized ports like these. It also adds a unit test based on data from a failure observed in the gate. Change-Id: I5c1bc8363cc7b07a03df12e3ccd49a09b1907ad2 Closes-Bug: #1444269 (cherry picked from commit e7e2609fae70dbffa0ddbf37c7804587e216648c) --- diff --git a/neutron/agent/common/ovs_lib.py b/neutron/agent/common/ovs_lib.py index d79092d24..f73f73114 100644 --- a/neutron/agent/common/ovs_lib.py +++ b/neutron/agent/common/ovs_lib.py @@ -341,7 +341,11 @@ class OVSBridge(BaseOVS): for r in results: # fall back to basic interface name key = self.portid_from_external_ids(r['external_ids']) or r['name'] - port_map[key] = r['ofport'] + try: + port_map[key] = int(r['ofport']) + except TypeError: + # port doesn't yet have an ofport entry so we ignore it + pass return port_map def get_vif_port_set(self): diff --git a/neutron/tests/unit/agent/common/test_ovs_lib.py b/neutron/tests/unit/agent/common/test_ovs_lib.py index 66d2b809f..28633e8e4 100644 --- a/neutron/tests/unit/agent/common/test_ovs_lib.py +++ b/neutron/tests/unit/agent/common/test_ovs_lib.py @@ -28,6 +28,15 @@ from neutron.tests import tools OVS_LINUX_KERN_VERS_WITHOUT_VXLAN = "3.12.0" +# some test data for get_vif_port_to_ofport_map that exhibited bug 1444269 +OVSLIST_WITH_UNSET_PORT = ( + '{"data":[["patch-tun",["map",[]],1],["tap2ab72a72-44",["map",[["attached-' + 'mac","fa:16:3e:b0:f8:38"],["iface-id","2ab72a72-4407-4ef3-806a-b2172f3e4d' + 'c7"],["iface-status","active"]]],2],["tap6b108774-15",["map",[["attached-' + 'mac","fa:16:3e:02:f5:91"],["iface-id","6b108774-1559-45e9-a7c3-b714f11722' + 'cf"],["iface-status","active"]]],["set",[]]]],"headings":["name","externa' + 'l_ids","ofport"]}') + class OFCTLParamListMatcher(object): @@ -553,6 +562,12 @@ class OVS_Lib_Test(base.BaseTestCase): if is_xen: get_xapi_iface_id.assert_called_once_with('tap99id') + def test_get_vif_port_to_ofport_map(self): + self.execute.return_value = OVSLIST_WITH_UNSET_PORT + results = self.br.get_vif_port_to_ofport_map() + expected = {'2ab72a72-4407-4ef3-806a-b2172f3e4dc7': 2, 'patch-tun': 1} + self.assertEqual(expected, results) + def test_get_vif_ports_nonxen(self): self._test_get_vif_ports(is_xen=False)