From fa803e84a56a0d356c6680bf688086f4a09d7194 Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Mon, 20 Nov 2023 15:30:20 +0100 Subject: [PATCH] EOS: Fix VLAN translation configuration Our code configured VLANs inside the interface's switched-vlan config, but it needs to be on the same level as the config, so we now move it to the proper location. The code for getting the config from the device looks fine though. --- networking_ccloud/ml2/agent/eos/switch.py | 28 +-- .../tests/unit/ml2/agent/eos/test_switch.py | 160 +++++++++--------- 2 files changed, 96 insertions(+), 92 deletions(-) diff --git a/networking_ccloud/ml2/agent/eos/switch.py b/networking_ccloud/ml2/agent/eos/switch.py index fb3b2d5b..6b574787 100644 --- a/networking_ccloud/ml2/agent/eos/switch.py +++ b/networking_ccloud/ml2/agent/eos/switch.py @@ -743,16 +743,17 @@ def _make_ifaces_config(self, config_req: EOSSetConfig, ifaces: Optional[List[ag existing_vtrans = None # only needed in add case and when vlan translations exist in config_req for iface in ifaces or []: # vlan stuff (native vlan, trunk vlans, translations) - data_vlan = {} + switched_vlan_config = {} + vlan_config = {} # native vlan if iface.native_vlan: - data_vlan['native-vlan'] = iface.native_vlan + vlan_config['native-vlan'] = iface.native_vlan # trunk vlans if iface.trunk_vlans: - data_vlan['interface-mode'] = 'TRUNK' - data_vlan['trunk-vlans'] = self._compress_vlan_list(iface.trunk_vlans) + vlan_config['interface-mode'] = 'TRUNK' + vlan_config['trunk-vlans'] = self._compress_vlan_list(iface.trunk_vlans) # vlan translations def remove_stale_vlan_translations(ifname, iface_cfg, is_pc): @@ -777,14 +778,19 @@ def remove_stale_vlan_translations(ifname, iface_cfg, is_pc): if operation == Op.add and existing_vtrans is None: existing_vtrans = self.get_vlan_translations() - data_vlan['vlan-translation'] = {"ingress": [], "egress": []} + vtrans_config = {} + vtrans_config['vlan-translation'] = {"ingress": [], "egress": []} for vtrans in iface.vlan_translations: - data_vlan['vlan-translation']['ingress'].append( + vtrans_config['vlan-translation']['ingress'].append( {"translation-key": vtrans.outside, "config": {"translation-key": vtrans.outside, "bridging-vlan": vtrans.inside}}) - data_vlan['vlan-translation']['egress'].append( + vtrans_config['vlan-translation']['egress'].append( {"translation-key": vtrans.inside, "config": {"translation-key": vtrans.inside, "bridging-vlan": vtrans.outside}}) + switched_vlan_config.update(vtrans_config) + + if vlan_config: + switched_vlan_config['config'] = vlan_config # port-channel configuration normal_ifaces = [] @@ -797,8 +803,8 @@ def remove_stale_vlan_translations(ifname, iface_cfg, is_pc): 'fallback-timeout': 50, }, } - if data_vlan: - agg_data['switched-vlan'] = {'config': data_vlan} + if switched_vlan_config: + agg_data['switched-vlan'] = switched_vlan_config data = { 'name': iface.name, @@ -822,8 +828,8 @@ def remove_stale_vlan_translations(ifname, iface_cfg, is_pc): data = {} if iface.portchannel_id: data['config'] = {'aggregate-id': f'Port-Channel{iface.portchannel_id}'} - if data_vlan: - data['switched-vlan'] = {'config': data_vlan} + if switched_vlan_config: + data['switched-vlan'] = switched_vlan_config if iface.vlan_translations: remove_stale_vlan_translations(iface_name, iface, is_pc=False) iface_cfg = (EOSGNMIPaths.IFACE_ETH.format(iface=iface_name), data) diff --git a/networking_ccloud/tests/unit/ml2/agent/eos/test_switch.py b/networking_ccloud/tests/unit/ml2/agent/eos/test_switch.py index 6cbb4f6c..3a47c99c 100644 --- a/networking_ccloud/tests/unit/ml2/agent/eos/test_switch.py +++ b/networking_ccloud/tests/unit/ml2/agent/eos/test_switch.py @@ -130,34 +130,34 @@ def _get(prefix, unpack=True): 'interface-mode': 'TRUNK', 'native-vlan': 1000, 'trunk-vlans': ['1000..1001'], - 'vlan-translation': { - 'egress': [{ - 'config': { - 'bridging-vlan': 2323, - 'translation-key': 1000 - }, + }, + 'vlan-translation': { + 'egress': [{ + 'config': { + 'bridging-vlan': 2323, 'translation-key': 1000 - }, { - 'config': { - 'bridging-vlan': 1337, - 'translation-key': 1001 - }, + }, + 'translation-key': 1000 + }, { + 'config': { + 'bridging-vlan': 1337, 'translation-key': 1001 - }], - 'ingress': [{ - 'config': { - 'bridging-vlan': 1000, - 'translation-key': 2323 - }, + }, + 'translation-key': 1001 + }], + 'ingress': [{ + 'config': { + 'bridging-vlan': 1000, 'translation-key': 2323 - }, { - 'config': { - 'bridging-vlan': 1001, - 'translation-key': 1337 - }, + }, + 'translation-key': 2323 + }, { + 'config': { + 'bridging-vlan': 1001, 'translation-key': 1337 - }] - } + }, + 'translation-key': 1337 + }] } } } @@ -166,36 +166,36 @@ def _get(prefix, unpack=True): {'config': {'aggregate-id': 'Port-Channel23'}, 'switched-vlan': {'config': {'interface-mode': 'TRUNK', 'native-vlan': 1000, - 'trunk-vlans': ['1000..1001'], - 'vlan-translation': {'egress': [{'config': {'bridging-vlan': 2323, - 'translation-key': 1000}, + 'trunk-vlans': ['1000..1001']}, + 'vlan-translation': {'egress': [{'config': {'bridging-vlan': 2323, 'translation-key': 1000}, - {'config': {'bridging-vlan': 1337, - 'translation-key': 1001}, - 'translation-key': 1001}], - 'ingress': [{'config': {'bridging-vlan': 1000, - 'translation-key': 2323}, + 'translation-key': 1000}, + {'config': {'bridging-vlan': 1337, + 'translation-key': 1001}, + 'translation-key': 1001}], + 'ingress': [{'config': {'bridging-vlan': 1000, 'translation-key': 2323}, - {'config': {'bridging-vlan': 1001, - 'translation-key': 1337}, - 'translation-key': 1337}]}}}}), + 'translation-key': 2323}, + {'config': {'bridging-vlan': 1001, + 'translation-key': 1337}, + 'translation-key': 1337}]}}}), ('interfaces/interface[name=Ethernet4/2]/ethernet', {'config': {'aggregate-id': 'Port-Channel23'}, 'switched-vlan': {'config': {'interface-mode': 'TRUNK', 'native-vlan': 1000, - 'trunk-vlans': ['1000..1001'], - 'vlan-translation': {'egress': [{'config': {'bridging-vlan': 2323, - 'translation-key': 1000}, + 'trunk-vlans': ['1000..1001']}, + 'vlan-translation': {'egress': [{'config': {'bridging-vlan': 2323, 'translation-key': 1000}, - {'config': {'bridging-vlan': 1337, - 'translation-key': 1001}, - 'translation-key': 1001}], - 'ingress': [{'config': {'bridging-vlan': 1000, - 'translation-key': 2323}, + 'translation-key': 1000}, + {'config': {'bridging-vlan': 1337, + 'translation-key': 1001}, + 'translation-key': 1001}], + 'ingress': [{'config': {'bridging-vlan': 1000, 'translation-key': 2323}, - {'config': {'bridging-vlan': 1001, - 'translation-key': 1337}, - 'translation-key': 1337}]}}}}), + 'translation-key': 2323}, + {'config': {'bridging-vlan': 1001, + 'translation-key': 1337}, + 'translation-key': 1337}]}}}), ('interfaces/interface[name=Ethernet23/1]/ethernet', {'switched-vlan': {'config': {'interface-mode': 'TRUNK', 'trunk-vlans': ['1001']}}}), @@ -689,53 +689,51 @@ def _get(prefix): 'lag-type': 'LACP' }, 'switched-vlan': { - 'config': { - 'vlan-translation': { - 'egress': [{ - 'config': { - 'bridging-vlan': 42, - 'translation-key': 23 - }, + 'vlan-translation': { + 'egress': [{ + 'config': { + 'bridging-vlan': 42, 'translation-key': 23 - }, { - 'config': { - 'bridging-vlan': 2000, - 'translation-key': 1000 - }, + }, + 'translation-key': 23 + }, { + 'config': { + 'bridging-vlan': 2000, 'translation-key': 1000 - }], - 'ingress': [{ - 'config': { - 'bridging-vlan': 23, - 'translation-key': 42 - }, + }, + 'translation-key': 1000 + }], + 'ingress': [{ + 'config': { + 'bridging-vlan': 23, 'translation-key': 42 - }, { - 'config': { - 'bridging-vlan': 1000, - 'translation-key': 2000 - }, + }, + 'translation-key': 42 + }, { + 'config': { + 'bridging-vlan': 1000, 'translation-key': 2000 - }] - } + }, + 'translation-key': 2000 + }] } } } }), ('interfaces/interface[name=Ethernet23/1]/ethernet', {'config': {'aggregate-id': 'Port-Channel23'}, - 'switched-vlan': {'config': {'vlan-translation': {'egress': [{'config': {'bridging-vlan': 42, - 'translation-key': 23}, + 'switched-vlan': {'vlan-translation': {'egress': [{'config': {'bridging-vlan': 42, 'translation-key': 23}, - {'config': {'bridging-vlan': 2000, - 'translation-key': 1000}, - 'translation-key': 1000}], - 'ingress': [{'config': {'bridging-vlan': 23, - 'translation-key': 42}, + 'translation-key': 23}, + {'config': {'bridging-vlan': 2000, + 'translation-key': 1000}, + 'translation-key': 1000}], + 'ingress': [{'config': {'bridging-vlan': 23, 'translation-key': 42}, - {'config': {'bridging-vlan': 1000, - 'translation-key': 2000}, - 'translation-key': 2000}]}}}})]} + 'translation-key': 42}, + {'config': {'bridging-vlan': 1000, + 'translation-key': 2000}, + 'translation-key': 2000}]}}})]} cu = messages.SwitchConfigUpdate(switch_name="seagull-sw1", operation=messages.OperationEnum.add) iface = messages.IfaceConfig(name="Port-Channel23", portchannel_id=23, members=["Ethernet23/1"])