Skip to content

Commit 77032ea

Browse files
authored
Merge pull request #103 from stackhpc/upstream/master-2025-02-10
Synchronise master with upstream
2 parents 29da45c + 6711765 commit 77032ea

File tree

3 files changed

+27
-46
lines changed

3 files changed

+27
-46
lines changed

Diff for: doc/source/dev/dev-quickstart.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ verifies that ovs port has been assigned to correct VLAN::
8181
bash ~/networking-generic-switch/devstack/exercise.sh
8282

8383

84-
Test with real hardware:
85-
------------------------
84+
Test with real hardware
85+
-----------------------
8686

8787
Add information about hardware switch to Networking-generic-switch
8888
config ``/etc/neutron/plugins/ml2/ml2_conf_genericswitch.ini`` and

Diff for: networking_generic_switch/generic_switch_mech.py

+20-40
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def update_port_postcommit(self, context):
376376
{'switch_port': port_id, 'switch_info': switch_info,
377377
'segmentation_id': segmentation_id})
378378
# Move port to network
379-
if is_802_3ad and hasattr(switch, 'plug_bond_to_network'):
379+
if is_802_3ad:
380380
switch.plug_bond_to_network(port_id, segmentation_id)
381381
else:
382382
switch.plug_port_to_network(port_id, segmentation_id)
@@ -466,6 +466,10 @@ def bind_port(self, context):
466466
can use with ports.
467467
"""
468468

469+
# NOTE(vsaienko): Important that this method remains lightweight.
470+
# The actual port handling is done in update_port_postcommit.
471+
# For more info please read docstring.
472+
469473
port = context.current
470474
network = context.network.current
471475
binding_profile = port['binding:profile']
@@ -477,44 +481,7 @@ def bind_port(self, context):
477481
if not self._is_link_valid(port, network):
478482
return
479483

480-
is_802_3ad = self._is_802_3ad(port)
481-
for link in local_link_information:
482-
port_id = link.get('port_id')
483-
switch_info = link.get('switch_info')
484-
switch_id = link.get('switch_id')
485-
switch = device_utils.get_switch_device(
486-
self.switches, switch_info=switch_info,
487-
ngs_mac_address=switch_id)
488-
489-
segments = context.segments_to_bind
490-
# If segmentation ID is None, set vlan 1
491-
segmentation_id = segments[0].get('segmentation_id') or 1
492-
493-
# Fail if port or vlan not in allow list
494-
if not switch.is_allowed(port_id, segmentation_id):
495-
LOG.warn("Skipped binding port %(port_id)s, "
496-
"port %(port)s in segment "
497-
"%(segment_id)s on device %(device)s, as either "
498-
"the port or vlan is not on the allow list",
499-
{'port_id': port['id'], 'port': port_id,
500-
'device': switch_info,
501-
'segment_id': segmentation_id})
502-
return
503-
504-
LOG.debug("Putting port %(port_id)s on %(switch_info)s "
505-
"to vlan: %(segmentation_id)s",
506-
{'port_id': port_id, 'switch_info': switch_info,
507-
'segmentation_id': segmentation_id})
508-
# Move port to network
509-
if is_802_3ad and hasattr(switch, 'plug_bond_to_network'):
510-
switch.plug_bond_to_network(port_id, segmentation_id)
511-
else:
512-
switch.plug_port_to_network(port_id, segmentation_id)
513-
LOG.info("Successfully bound port %(port_id)s in segment "
514-
"%(segment_id)s on device %(device)s",
515-
{'port_id': port['id'], 'device': switch_info,
516-
'segment_id': segmentation_id})
517-
484+
segments = context.segments_to_bind
518485
context.set_binding(segments[0][api.ID],
519486
portbindings.VIF_TYPE_OTHER, {})
520487

@@ -540,6 +507,7 @@ def _is_link_valid(self, port, network):
540507
local_link_information = binding_profile.get('local_link_information')
541508

542509
for link in local_link_information:
510+
port_id = link.get('port_id')
543511
switch_info = link.get('switch_info')
544512
switch_id = link.get('switch_id')
545513
switch = device_utils.get_switch_device(
@@ -555,6 +523,7 @@ def _is_link_valid(self, port, network):
555523

556524
physnet = network['provider:physical_network']
557525
switch_physnets = switch._get_physical_networks()
526+
segmentation_id = network.get('provider:segmentation_id') or 1
558527

559528
if switch_physnets and physnet not in switch_physnets:
560529
LOG.error("Cannot bind port %(port)s as device %(device)s "
@@ -563,6 +532,17 @@ def _is_link_valid(self, port, network):
563532
{'port': port['id'], 'device': switch_info,
564533
'physnet': physnet})
565534
return False
535+
536+
# Fail if port or vlan not in allow list
537+
if not switch.is_allowed(port_id, segmentation_id):
538+
LOG.warn("Skipped binding port %(port_id)s, "
539+
"port %(port)s in segment "
540+
"%(segment_id)s on device %(device)s, as either "
541+
"the port or vlan is not on the allow list",
542+
{'port_id': port['id'], 'port': port_id,
543+
'device': switch_info,
544+
'segment_id': segmentation_id})
545+
return False
566546
return True
567547

568548
@staticmethod
@@ -639,7 +619,7 @@ def _unplug_port_from_network(self, port, network):
639619
{'port': port_id, 'switch_info': switch_info,
640620
'segmentation_id': segmentation_id})
641621
try:
642-
if is_802_3ad and hasattr(switch, 'unplug_bond_from_network'):
622+
if is_802_3ad:
643623
switch.unplug_bond_from_network(port_id, segmentation_id)
644624
else:
645625
switch.delete_port(port_id, segmentation_id)

Diff for: networking_generic_switch/tests/unit/test_generic_switch_mech.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ def test_bind_port(self, m_apc, m_list):
904904
mock_context.current['id'],
905905
resources.PORT,
906906
'GENERICSWITCH')
907-
self.switch_mock.plug_port_to_network.assert_called()
907+
self.switch_mock.plug_port_to_network.assert_not_called()
908908

909909
@mock.patch.object(provisioning_blocks, 'add_provisioning_component',
910910
autospec=True)
@@ -946,7 +946,7 @@ def test_bind_portgroup(self, m_apc, m_list):
946946
mock_context.current['id'],
947947
resources.PORT,
948948
'GENERICSWITCH')])
949-
self.switch_mock.plug_port_to_network.assert_called()
949+
self.switch_mock.plug_port_to_network.assert_not_called()
950950

951951
@mock.patch.object(provisioning_blocks, 'add_provisioning_component',
952952
autospec=True)
@@ -993,7 +993,7 @@ def test_bind_portgroup_802_3ad(self, m_apc, m_list):
993993
resources.PORT,
994994
'GENERICSWITCH')])
995995
self.switch_mock.plug_port_to_network.assert_not_called()
996-
self.switch_mock.plug_bond_to_network.assert_called()
996+
self.switch_mock.plug_bond_to_network.assert_not_called()
997997

998998
@mock.patch.object(provisioning_blocks, 'add_provisioning_component',
999999
autospec=True)
@@ -1030,7 +1030,8 @@ def test_bind_port_with_physnet(self, m_apc, m_list):
10301030
mock_context.current['id'],
10311031
resources.PORT,
10321032
'GENERICSWITCH')
1033-
self.switch_mock.plug_port_to_network.assert_called()
1033+
# NOTE(vsaienko): make sure we do not call heavy methods in bind_port
1034+
self.switch_mock.plug_port_to_network.assert_not_called()
10341035

10351036
@mock.patch.object(provisioning_blocks, 'add_provisioning_component',
10361037
autospec=True)

0 commit comments

Comments
 (0)