Skip to content

Commit

Permalink
EOS: Fix VLAN translation configuration
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sebageek committed Dec 1, 2023
1 parent 6b89e46 commit fa803e8
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 92 deletions.
28 changes: 17 additions & 11 deletions networking_ccloud/ml2/agent/eos/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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 = []
Expand All @@ -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,
Expand All @@ -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)
Expand Down
160 changes: 79 additions & 81 deletions networking_ccloud/tests/unit/ml2/agent/eos/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}]
}
}
}
Expand All @@ -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']}}}),
Expand Down Expand Up @@ -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"])
Expand Down

0 comments on commit fa803e8

Please sign in to comment.