[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
This commit is contained in:
Nguyen Thanh Cong 2020-02-25 17:25:36 +07:00
parent 6b9765c991
commit 5600163e9b
2 changed files with 31 additions and 19 deletions

View File

@ -1627,15 +1627,15 @@ class OVSNeutronAgent(l2population_rpc.L2populationRpcCallBackTunnelMixin,
updated_ports.update({p['name'] for p in events['modified']})
ports_re_added = added_ports & removed_ports
for p in ports_re_added:
if ovs_lib.BaseOVS().port_exists(p):
events['re_added'] = [e for e in events['removed']
if e['name'] == p]
events['removed'] = [e for e in events['removed']
if e['name'] != p]
else:
events['added'] = [e for e in events['added']
if e['name'] != p]
ports_re_added = [p for p in ports_re_added if
ovs_lib.BaseOVS().port_exists(p)]
events['re_added'] = [e for e in events['removed']
if e['name'] in ports_re_added]
events['removed'] = [e for e in events['removed'] if e['name']
not in ports_re_added]
ports_removed = [p['name'] for p in events['removed']]
events['added'] = [e for e in events['added'] if e['name'] not in
ports_removed]
# TODO(rossella_s): scanning the ancillary bridge won't be needed
# anymore when https://review.opendev.org/#/c/203381 since the bridge

View File

@ -463,26 +463,38 @@ class TestOvsNeutronAgent(object):
actual)
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 = {
'removed':
[{'ofport': 1,
'external_ids': {'iface-id': port_id,
'external_ids': {'iface-id': port_id_one,
'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':
[{'ofport': 2,
'external_ids': {'iface-id': port_id,
[{'ofport': 3,
'external_ids': {'iface-id': port_id_one,
'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': []
}
registered_ports = {port_id}
registered_ports = {port_id_one, port_id_two}
expected_ancillary = ovs_agent.PortInfo()
# port was removed and then added
expected_ports = ovs_agent.PortInfo(current={port_id}, added={port_id},
re_added={port_id})
expected_ports = ovs_agent.PortInfo(
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",
return_value=True):
self._test_process_ports_events(events.copy(), registered_ports,
@ -490,7 +502,7 @@ class TestOvsNeutronAgent(object):
expected_ancillary)
# 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",
return_value=False):
self._test_process_ports_events(events.copy(), registered_ports,