[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'].

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

Change-Id: If8edd29dd741f1688ffcac341fd58173539ba000
Closes-Bug: #1864630
(cherry picked from commit 5600163e9b)
(cherry picked from commit 22df469504)
This commit is contained in:
Nguyen Thanh Cong 2020-02-25 17:25:36 +07:00 committed by Slawek Kaplonski
parent 2bcbd947b3
commit 489ec55094
2 changed files with 31 additions and 19 deletions

View File

@ -1433,15 +1433,15 @@ class OVSNeutronAgent(l2population_rpc.L2populationRpcCallBackTunnelMixin,
removed_ports = {p['name'] for p in events['removed']}
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.openstack.org/#/c/203381 since the bridge

View File

@ -478,25 +478,37 @@ 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'}],
}
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,
@ -504,7 +516,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,