diff --git a/neutron/agent/linux/ovs_lib.py b/neutron/agent/linux/ovs_lib.py index 5f4675906da..c040d6ecc30 100644 --- a/neutron/agent/linux/ovs_lib.py +++ b/neutron/agent/linux/ovs_lib.py @@ -391,6 +391,13 @@ class OVSBridge(BaseOVS): # rows since the interface identifier is unique data = json_result['data'][0] port_name = data[name_idx] + switch = get_bridge_for_iface(self.root_helper, port_name) + if switch != self.br_name: + LOG.info(_("Port: %(port_name)s is on %(switch)s," + " not on %(br_name)s"), {'port_name': port_name, + 'switch': switch, + 'br_name': self.br_name}) + return ofport = data[ofport_idx] # ofport must be integer otherwise return None if not isinstance(ofport, int) or ofport == -1: diff --git a/neutron/tests/unit/openvswitch/test_ovs_lib.py b/neutron/tests/unit/openvswitch/test_ovs_lib.py index ff2768b9b11..a556cf74f6b 100644 --- a/neutron/tests/unit/openvswitch/test_ovs_lib.py +++ b/neutron/tests/unit/openvswitch/test_ovs_lib.py @@ -602,7 +602,7 @@ class OVS_Lib_Test(base.BaseTestCase): with testtools.ExpectedException(Exception): self.br.get_local_port_mac() - def _test_get_vif_port_by_id(self, iface_id, data): + def _test_get_vif_port_by_id(self, iface_id, data, br_name=None): headings = ['external_ids', 'name', 'ofport'] # Each element is a tuple of (expected mock call, return_value) expected_calls_and_values = [ @@ -612,7 +612,15 @@ class OVS_Lib_Test(base.BaseTestCase): 'external_ids:iface-id="%s"' % iface_id], root_helper=self.root_helper), self._encode_ovs_json(headings, data))] + if data: + if not br_name: + br_name = self.BR_NAME + expected_calls_and_values.append( + (mock.call(["ovs-vsctl", self.TO, + "iface-to-br", data[0][headings.index('name')]], + root_helper=self.root_helper), + br_name)) tools.setup_mock_calls(self.execute, expected_calls_and_values) vif_port = self.br.get_vif_port_by_id(iface_id) @@ -651,3 +659,10 @@ class OVS_Lib_Test(base.BaseTestCase): def test_get_vif_by_port_id_with_no_data(self): self.assertIsNone(self._test_get_vif_port_by_id('whatever', [])) + + def test_get_vif_by_port_id_different_bridge(self): + external_ids = [["iface-id", "tap99id"], + ["iface-status", "active"]] + data = [[["map", external_ids], "tap99", 1]] + self.assertIsNone(self._test_get_vif_port_by_id('tap99id', data, + "br-ext"))