Fix OVSBridge.get_port_ofport to handle empty output
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
This commit is contained in:
parent
17686c1f24
commit
fc91e158f2
@ -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):
|
||||
|
@ -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"'
|
||||
|
Loading…
Reference in New Issue
Block a user