]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix OVSBridge.get_port_ofport to handle empty output
authorMaru Newby <marun@redhat.com>
Tue, 1 Jul 2014 23:51:15 +0000 (23:51 +0000)
committerMaru Newby <marun@redhat.com>
Tue, 1 Jul 2014 23:57:20 +0000 (23:57 +0000)
Previously ovs_lib.OVSBridge.get_port_ofport() was not handling the
case where db_get_val() was returning None when no output was recieved
from ovs-vsctl.  This patch ensures that the TypeError that results
from this condition is appropriately handled.

Change-Id: I168eb0f2c6f0cb98a3eb3e118972bbaf0383ff89
Partial-bug: #1336172

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

index 4197b4ec811134592bdcd4c0e6cbb78f6a9b47ea..9adb2d35dd9c1f3287014ec79eedea430c73265e 100644 (file)
@@ -182,7 +182,7 @@ class OVSBridge(BaseOVS):
         try:
             int(ofport)
             return ofport
-        except ValueError:
+        except (ValueError, TypeError):
             return constants.INVALID_OFPORT
 
     def get_datapath_id(self):
index 8a19ed39a599d5e35d1da1518ba70f2f4d770e18..e60e62cbdbc0f6a1ad25f4ef8d7491cf8e13b724 100644 (file)
@@ -319,23 +319,22 @@ class OVS_Lib_Test(base.BaseTestCase):
             process_input=None,
             root_helper=self.root_helper)
 
-    def test_get_port_ofport(self):
+    def _test_get_port_ofport(self, ofport, expected_result):
         pname = "tap99"
-        ofport = "6"
         self.execute.return_value = ofport
-        self.assertEqual(self.br.get_port_ofport(pname), ofport)
+        self.assertEqual(self.br.get_port_ofport(pname), expected_result)
         self.execute.assert_called_once_with(
             ["ovs-vsctl", self.TO, "get", "Interface", pname, "ofport"],
             root_helper=self.root_helper)
 
-    def test_get_port_ofport_non_int(self):
-        pname = "tap99"
-        ofport = "[]"
-        self.execute.return_value = ofport
-        self.assertEqual(self.br.get_port_ofport(pname), const.INVALID_OFPORT)
-        self.execute.assert_called_once_with(
-            ["ovs-vsctl", self.TO, "get", "Interface", pname, "ofport"],
-            root_helper=self.root_helper)
+    def test_get_port_ofport_succeeds_for_valid_ofport(self):
+        self._test_get_port_ofport("6", "6")
+
+    def test_get_port_ofport_returns_invalid_ofport_for_non_int(self):
+        self._test_get_port_ofport("[]", const.INVALID_OFPORT)
+
+    def test_get_port_ofport_returns_invalid_ofport_for_none(self):
+        self._test_get_port_ofport(None, const.INVALID_OFPORT)
 
     def test_get_datapath_id(self):
         datapath_id = '"0000b67f4fbcc149"'