]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Handle no ofport in get_vif_port_to_ofport_map
authorKevin Benton <blak111@gmail.com>
Tue, 31 Mar 2015 03:29:51 +0000 (20:29 -0700)
committerKevin Benton <kevinbenton@buttewifi.com>
Fri, 24 Apr 2015 01:46:16 +0000 (01:46 +0000)
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)

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

index d79092d2416c2226ba9687296bba3c4f927976fa..f73f73114dc6db34a56ead3bd4e7174504beb367 100644 (file)
@@ -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):
index 66d2b809fb40733854f581071a4f98abf87919ef..28633e8e47863e01b4721f60fc6492456c304144 100644 (file)
@@ -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)