Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LACP: rollback vlan setting, fix perf endpoints generation #361

Merged
merged 4 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lnst/Recipes/ENRT/BaseLACPRecipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
)
from lnst.Devices import BondDevice
from lnst.Common.IpAddress import interface_addresses
from lnst.Recipes.ENRT.helpers import ip_endpoint_pairs
from lnst.Recipes.ENRT.DoubleBondRecipe import DoubleBondRecipe


Expand Down Expand Up @@ -74,3 +75,7 @@ def test_wide_deconfiguration(self, config):
self.test_wide_switch_deconfiguration()

super().test_wide_deconfiguration(config)

def generate_perf_endpoints(self, config):
return [ip_endpoint_pairs(config, (self.matched.host1.bond0, self.matched.host2.bond0), combination_func=zip)]

2 changes: 1 addition & 1 deletion lnst/Recipes/ENRT/ConfigMixins/BaseRESTConfigMixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ def api_request(self, method: str, endpoint: str, response_code: int = 200, **kw

logging.debug("API response: %s", response.content)

return response.content
return response
61 changes: 54 additions & 7 deletions lnst/Recipes/ENRT/DellLACPRecipe.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,42 @@
import logging
import requests

from lnst.Recipes.ENRT.BaseLACPRecipe import BaseLACPRecipe
from lnst.Recipes.ENRT.ConfigMixins.BaseRESTConfigMixin import BaseRESTConfigMixin


class DellLACPRecipe(BaseRESTConfigMixin, BaseLACPRecipe):
def __init__(self, *args, **kwargs):
self._vlan_connections = {} # structure: {"INTERFACE1": ["vlan10", "vlan20", ...]}

super().__init__(*args, **kwargs)

def get_interface_vlans(self, interfaces: list[str]):
vlans = {interface: [] for interface in interfaces}

infs = self.api_request(
"get", "/restconf/data/ietf-interfaces:interfaces/interface"
).json()

for sw_inf in infs["ietf-interfaces:interface"]:
if (
sw_inf["type"].lower() != "iana-if-type:l2vlan"
or sw_inf["name"].lower() == "vlan1"
):
# ^^ vlan1 is default vlan. Each inf is connected to it, this cannot be changed.
continue

for interface in interfaces:
if interface in sw_inf["dell-interface:tagged-ports"]:
vlans[interface].append(sw_inf["name"])

return vlans

def test_wide_switch_configuration(self):
self._vlan_connections = self.get_interface_vlans([interface for interfaces in self.params.topology.values() for interface in interfaces])

logging.info(f"Interface/VLAN connections: {self._vlan_connections}")

for bond, interfaces in self.params.topology.items():
interfaces = [
{"name": interface, "lacp-mode": self.params.lacp_mode}
Expand All @@ -16,10 +49,7 @@ def test_wide_switch_configuration(self):
response_code=204,
json={
"ietf-interfaces:interface": [
{
"name": bond,
"dell-interface:member-ports": interfaces
}
{"name": bond, "dell-interface:member-ports": interfaces}
]
},
)
Expand All @@ -31,7 +61,24 @@ def test_wide_switch_deconfiguration(self):
"delete",
f"/restconf/data/ietf-interfaces:interfaces/interface/{bond}",
response_code=204,
json={
"dell-interface:member-ports": [{"name": interface}]
}
json={"dell-interface:member-ports": [{"name": interface}]},
)

for interface, vlans in self._vlan_connections.items():
self.api_request(
"put",
f"/restconf/data/ietf-interfaces:interfaces/interface/{requests.utils.quote(interface, safe='')}/dell-interface{requests.utils.quote(':')}mode",
response_code=204,
json={"dell-interface:mode": "MODE_L2HYBRID"},
)
logging.info(f"Interface {interface} set to MODE_L2HYBRID")

for vlan in vlans:
self.api_request(
"put",
f"/restconf/data/ietf-interfaces:interfaces/interface/{vlan}/dell-interface{requests.utils.quote(':')}tagged-ports",
response_code=204,
json={"dell-interface:tagged-ports": [interface]},
)
logging.info(f"Vlan {vlan} added to interface {interface}")

6 changes: 4 additions & 2 deletions lnst/Recipes/ENRT/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@


def ip_endpoint_pairs(
config: EnrtConfiguration, *device_pairs: tuple[RemoteDevice, RemoteDevice]
config: EnrtConfiguration,
*device_pairs: tuple[RemoteDevice, RemoteDevice],
combination_func: callable = itertools.product
) -> Collection[EndpointPair[IPEndpoint]]:
"""Helper function for use in generate_perf_endpoints method.

Expand All @@ -20,7 +22,7 @@ def ip_endpoint_pairs(
dev1_ips = [ip for ip in config.ips_for_device(dev1) if isinstance(ip, ip_type)]
dev2_ips = [ip for ip in config.ips_for_device(dev2) if isinstance(ip, ip_type)]

for ip1, ip2 in itertools.product(dev1_ips, dev2_ips):
for ip1, ip2 in combination_func(dev1_ips, dev2_ips):
endpoint_pairs.append(
EndpointPair(
IPEndpoint(dev1, ip1),
Expand Down
Loading