Merge "ovs: raise RuntimeError in _get_dp if id is None"

This commit is contained in:
Zuul 2018-04-18 14:48:55 +00:00 committed by Gerrit Code Review
commit 26b744740e
2 changed files with 10 additions and 3 deletions

View File

@ -42,10 +42,12 @@ class OVSAgentBridge(ofswitch.OpenFlowSwitchMixin,
"""
while True:
if self._cached_dpid is None:
dpid_str = self.get_datapath_id()
dpid = self.get_datapath_id()
LOG.info("Bridge %(br_name)s has datapath-ID %(dpid)s",
{"br_name": self.br_name, "dpid": dpid_str})
self._cached_dpid = int(dpid_str, 16)
{"br_name": self.br_name, "dpid": dpid})
if dpid is None:
raise RuntimeError("Unknown datapath id.")
self._cached_dpid = int(dpid, 16)
try:
dp = self._get_dp_by_dpid(self._cached_dpid)
return dp, dp.ofproto, dp.ofproto_parser

View File

@ -49,3 +49,8 @@ class OVSAgentBridgeTestCase(ovs_test_base.OVSRyuTestBase):
# make sure that in case of any misconfiguration when no datapath is
# found a proper exception, not a TypeError is raised
self.assertRaises(RuntimeError, br._get_dp)
def test__get_dp_when_get_datapath_id_returns_None(self):
br = self.br_int_cls('br-int')
with mock.patch.object(br, 'get_datapath_id', return_value=None):
self.assertRaises(RuntimeError, br._get_dp)