[OvS] Handle re_added multi ports
Multiple ports are located in ports_re_added. Assume we have port_one and port_two. It will loop through the ports. Port_one is iterated first, events ['re_added'] is assigned port_one, events ['removed'] is assigned port_two. In the second loop, events ['re_added'] is set to port_two instead of adding port_two to list. So after the loop, only port_two is left in events ['re_added']. Change-Id: If8edd29dd741f1688ffcac341fd58173539ba000 Closes-Bug: #1864630 (cherry picked from commit5600163e9b
) (cherry picked from commit22df469504
)
This commit is contained in:
parent
44a1a8cfef
commit
2711ad5819
|
@ -1477,15 +1477,15 @@ class OVSNeutronAgent(l2population_rpc.L2populationRpcCallBackTunnelMixin,
|
||||||
updated_ports.update({p['name'] for p in events['modified']})
|
updated_ports.update({p['name'] for p in events['modified']})
|
||||||
|
|
||||||
ports_re_added = added_ports & removed_ports
|
ports_re_added = added_ports & removed_ports
|
||||||
for p in ports_re_added:
|
ports_re_added = [p for p in ports_re_added if
|
||||||
if ovs_lib.BaseOVS().port_exists(p):
|
ovs_lib.BaseOVS().port_exists(p)]
|
||||||
events['re_added'] = [e for e in events['removed']
|
events['re_added'] = [e for e in events['removed']
|
||||||
if e['name'] == p]
|
if e['name'] in ports_re_added]
|
||||||
events['removed'] = [e for e in events['removed']
|
events['removed'] = [e for e in events['removed'] if e['name']
|
||||||
if e['name'] != p]
|
not in ports_re_added]
|
||||||
else:
|
ports_removed = [p['name'] for p in events['removed']]
|
||||||
events['added'] = [e for e in events['added']
|
events['added'] = [e for e in events['added'] if e['name'] not in
|
||||||
if e['name'] != p]
|
ports_removed]
|
||||||
|
|
||||||
# TODO(rossella_s): scanning the ancillary bridge won't be needed
|
# TODO(rossella_s): scanning the ancillary bridge won't be needed
|
||||||
# anymore when https://review.openstack.org/#/c/203381 since the bridge
|
# anymore when https://review.openstack.org/#/c/203381 since the bridge
|
||||||
|
|
|
@ -485,26 +485,38 @@ class TestOvsNeutronAgent(object):
|
||||||
actual)
|
actual)
|
||||||
|
|
||||||
def test_process_ports_events_port_removed_and_added(self):
|
def test_process_ports_events_port_removed_and_added(self):
|
||||||
port_id = 'f6f104bd-37c7-4f7b-9d70-53a6bb42728f'
|
port_id_one = 'f6f104bd-37c7-4f7b-9d70-53a6bb42728f'
|
||||||
|
port_id_two = 'fbaf42ef-ab63-4cda-81d2-37ee55daac3a'
|
||||||
events = {
|
events = {
|
||||||
'removed':
|
'removed':
|
||||||
[{'ofport': 1,
|
[{'ofport': 1,
|
||||||
'external_ids': {'iface-id': port_id,
|
'external_ids': {'iface-id': port_id_one,
|
||||||
'attached-mac': 'fa:16:3e:f6:1b:fb'},
|
'attached-mac': 'fa:16:3e:f6:1b:fb'},
|
||||||
'name': 'qvof6f104bd-37'}],
|
'name': 'qvof6f104bd-37'},
|
||||||
|
{'ofport': 2,
|
||||||
|
'external_ids': {'iface-id': port_id_two,
|
||||||
|
'attached-mac': 'fa:16:3e:a4:42:6e'},
|
||||||
|
'name': 'qvofbaf42ef-ab'}],
|
||||||
'added':
|
'added':
|
||||||
[{'ofport': 2,
|
[{'ofport': 3,
|
||||||
'external_ids': {'iface-id': port_id,
|
'external_ids': {'iface-id': port_id_one,
|
||||||
'attached-mac': 'fa:16:3e:f6:1b:fb'},
|
'attached-mac': 'fa:16:3e:f6:1b:fb'},
|
||||||
'name': 'qvof6f104bd-37'}],
|
'name': 'qvof6f104bd-37'},
|
||||||
|
{'ofport': 4,
|
||||||
|
'external_ids': {'iface-id': port_id_two,
|
||||||
|
'attached-mac': 'fa:16:3e:a4:42:6e'},
|
||||||
|
'name': 'qvofbaf42ef-ab'}],
|
||||||
'modified': []
|
'modified': []
|
||||||
}
|
}
|
||||||
registered_ports = {port_id}
|
registered_ports = {port_id_one, port_id_two}
|
||||||
expected_ancillary = ovs_agent.PortInfo()
|
expected_ancillary = ovs_agent.PortInfo()
|
||||||
|
|
||||||
# port was removed and then added
|
# port was removed and then added
|
||||||
expected_ports = ovs_agent.PortInfo(current={port_id}, added={port_id},
|
expected_ports = ovs_agent.PortInfo(
|
||||||
re_added={port_id})
|
added={port_id_one, port_id_two},
|
||||||
|
current={port_id_one, port_id_two},
|
||||||
|
re_added={port_id_one, port_id_two}
|
||||||
|
)
|
||||||
with mock.patch.object(ovs_lib.BaseOVS, "port_exists",
|
with mock.patch.object(ovs_lib.BaseOVS, "port_exists",
|
||||||
return_value=True):
|
return_value=True):
|
||||||
self._test_process_ports_events(events.copy(), registered_ports,
|
self._test_process_ports_events(events.copy(), registered_ports,
|
||||||
|
@ -512,7 +524,7 @@ class TestOvsNeutronAgent(object):
|
||||||
expected_ancillary)
|
expected_ancillary)
|
||||||
|
|
||||||
# port was added and then removed
|
# port was added and then removed
|
||||||
expected_ports = ovs_agent.PortInfo(removed={port_id})
|
expected_ports = ovs_agent.PortInfo(removed={port_id_one, port_id_two})
|
||||||
with mock.patch.object(ovs_lib.BaseOVS, "port_exists",
|
with mock.patch.object(ovs_lib.BaseOVS, "port_exists",
|
||||||
return_value=False):
|
return_value=False):
|
||||||
self._test_process_ports_events(events.copy(), registered_ports,
|
self._test_process_ports_events(events.copy(), registered_ports,
|
||||||
|
|
Loading…
Reference in New Issue