Skip to content

Commit fdc376e

Browse files
brianphaleyralonsoh
authored andcommitted
Fix AttributeError accessing local compute port
The items returned from the RPC call get_ports_on_host_by_subnet() are dictionaries, not objects, so referencing by *.id will throw an AttributeError. Added tests that would have caught it and fixed the mocking to return correct values. Introduced in: https://review.opendev.org/c/openstack/neutron/+/938657 Closes-bug: #2122065 Change-Id: If4ff23f6c79580918d90380eda1326f583fc937f Signed-off-by: Brian Haley <[email protected]> (cherry picked from commit e51a6bd)
1 parent 23ef72b commit fdc376e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

neutron/plugins/ml2/drivers/openvswitch/agent/ovs_dvr_neutron_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ def _unbind_port_on_dvr_subnet(self, port, lvm):
805805
self.context, self.host, sub_uuid))
806806
local_aap_macs = set()
807807
for lport in local_compute_ports:
808-
if lport.id != port.vif_id:
808+
if lport['id'] != port.vif_id:
809809
local_aap_macs.update({
810810
aap["mac_address"] for aap in lport.get(
811811
"allowed_address_pairs", [])})

neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4083,6 +4083,7 @@ def _test_treat_devices_removed_for_dvr(
40834083
self, device_owner, ip_version=n_const.IP_VERSION_4, aaps=False):
40844084
self._setup_for_dvr_test()
40854085
port_obj = {"id": "fake-port-uuid"}
4086+
local_port_obj = {"id": "fake-port-uuid"}
40864087
aap_mac = 'aa:bb:cc:dd:ee:ff'
40874088
aap_mac2 = 'aa:bb:cc:dd:ee:fe'
40884089
aap_mac3 = 'aa:bb:cc:dd:ee:fd'
@@ -4107,7 +4108,7 @@ def _test_treat_devices_removed_for_dvr(
41074108
'mac_address': aap_mac},
41084109
{'ip_address': '2001:100::11',
41094110
'mac_address': aap_mac2},
4110-
{'ip_address': '2001:100::0/0',
4111+
{'ip_address': '::/0',
41114112
'mac_address': aap_mac3}
41124113
]
41134114
self._port.dvr_mac = self.agent.dvr_agent.dvr_mac_address
@@ -4185,6 +4186,9 @@ def _test_treat_devices_removed_for_dvr(
41854186
self._compute_port.vif_id],
41864187
'failed_devices_up': [],
41874188
'failed_devices_down': []}),\
4189+
mock.patch.object(self.agent.dvr_agent.plugin_rpc,
4190+
'get_ports_on_host_by_subnet',
4191+
return_value=[local_port_obj]),\
41884192
mock.patch.object(self.agent.dvr_agent.plugin_rpc,
41894193
'get_ports',
41904194
return_value=[port_obj]),\
@@ -4223,6 +4227,11 @@ def test_treat_devices_removed_for_dvr_with_compute_ports(self):
42234227
device_owner=DEVICE_OWNER_COMPUTE)
42244228
self._test_treat_devices_removed_for_dvr(
42254229
device_owner=DEVICE_OWNER_COMPUTE, ip_version=n_const.IP_VERSION_6)
4230+
self._test_treat_devices_removed_for_dvr(
4231+
device_owner=DEVICE_OWNER_COMPUTE, aaps=True)
4232+
self._test_treat_devices_removed_for_dvr(
4233+
device_owner=DEVICE_OWNER_COMPUTE, ip_version=n_const.IP_VERSION_6,
4234+
aaps=True)
42264235

42274236
def test_treat_devices_removed_for_dvr_with_dhcp_ports(self):
42284237
self._test_treat_devices_removed_for_dvr(

0 commit comments

Comments
 (0)