From 6157cf7d86bd47aac6c8102e2007ce8eba6ba4c4 Mon Sep 17 00:00:00 2001 From: Jozef Urbanovsky Date: Thu, 21 Sep 2023 12:51:52 +0200 Subject: [PATCH 1/7] pyproject.toml: install ethtool and pyroute2 on linux --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e1d3886a1..58db55a50 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,8 +19,8 @@ include = ["schema-am.rng", "install/*", "lnst-ctl.conf"] [tool.poetry.dependencies] python = "^3.9" lxml = "*" -ethtool = "*" -pyroute2 = "*" +ethtool = {version = "*", platform = 'linux'} +pyroute2 = {version = "*", platform = 'linux'} libvirt-python = {version = "*", optional = true } podman = {version = "*", optional = true } From 930e809ed48f60e2b798ba2e788a3f3bf21d8371 Mon Sep 17 00:00:00 2001 From: Jozef Urbanovsky Date: Thu, 21 Sep 2023 13:58:45 +0200 Subject: [PATCH 2/7] Devices/Device: move ethtool and pyroute2 Ethtool and pyroute2 are not required to be imported before they are actually needed and this change is required for other than linux platforms to be able to run Controller methods where these packages are not required --- lnst/Devices/Device.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lnst/Devices/Device.py b/lnst/Devices/Device.py index d7608d863..cceb6818d 100644 --- a/lnst/Devices/Device.py +++ b/lnst/Devices/Device.py @@ -12,8 +12,6 @@ """ import re -import ethtool -import pyroute2 import logging import pprint import time @@ -55,6 +53,10 @@ class Device(object, metaclass=DeviceMeta): """ def __init__(self, if_manager): + import ethtool + import pyroute2 + global ethtool + global pyroute2 self.ifindex = None self._nl_msg = None self._devlink = None From b52075868f29fd7455842b642044f08458e3ea71 Mon Sep 17 00:00:00 2001 From: Jozef Urbanovsky Date: Fri, 22 Sep 2023 15:09:54 +0200 Subject: [PATCH 3/7] Common/NetUtils: move pyroute2 import --- lnst/Common/NetUtils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lnst/Common/NetUtils.py b/lnst/Common/NetUtils.py index 5c5526321..fed63b8bc 100644 --- a/lnst/Common/NetUtils.py +++ b/lnst/Common/NetUtils.py @@ -13,7 +13,6 @@ import re import socket import subprocess -from pyroute2 import IPRoute def normalize_hwaddr(hwaddr): @@ -24,6 +23,7 @@ def normalize_hwaddr(hwaddr): def scan_netdevs(): + from pyroute2 import IPRoute scan = [] with IPRoute() as ipr: From 294d4ac5a1a54bf7821dfcbcd3b976e8e960d429 Mon Sep 17 00:00:00 2001 From: Jozef Urbanovsky Date: Fri, 22 Sep 2023 15:14:45 +0200 Subject: [PATCH 4/7] Devices/Device: move pyroute2 import --- lnst/Devices/Device.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lnst/Devices/Device.py b/lnst/Devices/Device.py index cceb6818d..76c97e661 100644 --- a/lnst/Devices/Device.py +++ b/lnst/Devices/Device.py @@ -16,7 +16,6 @@ import pprint import time from abc import ABCMeta -from pyroute2.netlink.rtnl import ifinfmsg from lnst.Common.Logs import log_exc_traceback from lnst.Common.ExecCmd import exec_cmd, ExecCmdFail from lnst.Common.DeviceError import DeviceError, DeviceDeleted, DeviceDisabled @@ -26,10 +25,6 @@ from lnst.Common.HWAddress import hwaddress from lnst.Common.Utils import wait_for_condition -from pyroute2.netlink.rtnl import RTM_NEWLINK -from pyroute2.netlink.rtnl import RTM_NEWADDR -from pyroute2.netlink.rtnl import RTM_DELADDR - TOGGLE_STATE_TIMEOUT = 15 + 3 # as a reserve class DeviceMeta(ABCMeta): @@ -57,6 +52,16 @@ def __init__(self, if_manager): import pyroute2 global ethtool global pyroute2 + + from pyroute2.netlink.rtnl import ifinfmsg + from pyroute2.netlink.rtnl import RTM_NEWLINK + from pyroute2.netlink.rtnl import RTM_NEWADDR + from pyroute2.netlink.rtnl import RTM_DELADDR + global ifinfmsg + global RTM_NEWLINK + global RTM_NEWADDR + global RTM_DELADDR + self.ifindex = None self._nl_msg = None self._devlink = None From 0731dff4dc1ef0bedcaa87784eed61f2c98ca7e6 Mon Sep 17 00:00:00 2001 From: Jozef Urbanovsky Date: Fri, 22 Sep 2023 15:16:51 +0200 Subject: [PATCH 5/7] RecipeCommon/L2TPManager: move pyroute2 import --- lnst/RecipeCommon/L2TPManager.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lnst/RecipeCommon/L2TPManager.py b/lnst/RecipeCommon/L2TPManager.py index dc5c69953..61a47dfb6 100644 --- a/lnst/RecipeCommon/L2TPManager.py +++ b/lnst/RecipeCommon/L2TPManager.py @@ -13,8 +13,6 @@ """ import logging -from pyroute2.netlink import NetlinkError -from pyroute2.netlink.generic.l2tp import L2tp from lnst.Common.LnstError import LnstError @@ -84,6 +82,8 @@ def _test(self): ) """ def __init__(self): + from pyroute2.netlink import NetlinkError + from pyroute2.netlink.generic.l2tp import L2tp self._tunnels = [] try: From e173c066e12c8ad67f3ad5bd889b8a2ae52eca14 Mon Sep 17 00:00:00 2001 From: Jozef Urbanovsky Date: Fri, 22 Sep 2023 15:19:13 +0200 Subject: [PATCH 6/7] Devices/L2TPSessionDevice: move pyroute2 import --- lnst/Devices/L2TPSessionDevice.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lnst/Devices/L2TPSessionDevice.py b/lnst/Devices/L2TPSessionDevice.py index 2cda9c96a..fe2367101 100644 --- a/lnst/Devices/L2TPSessionDevice.py +++ b/lnst/Devices/L2TPSessionDevice.py @@ -10,8 +10,6 @@ jtluka@redhat.com (Jan Tluka) """ -from pyroute2.netlink import NetlinkError -from pyroute2.netlink.generic.l2tp import L2tp from lnst.Common.DeviceError import DeviceError, DeviceConfigError from lnst.Devices.Device import Device @@ -55,6 +53,11 @@ def test(self): _mandatory_opts = ["tunnel_id", "session_id", "peer_session_id"] def __init__(self, ifmanager, *args, **kwargs): + from pyroute2.netlink import NetlinkError + from pyroute2.netlink.generic.l2tp import L2tp + global NetlinkError + global L2tp + self._name = None for i in self._mandatory_opts: if i not in kwargs: From b397982546acc971dc1576007a47006a24f0fbb3 Mon Sep 17 00:00:00 2001 From: Jozef Urbanovsky Date: Fri, 22 Sep 2023 15:20:25 +0200 Subject: [PATCH 7/7] RecipeCommon/MPTCPManager: move pyroute2 import --- lnst/RecipeCommon/MPTCPManager.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lnst/RecipeCommon/MPTCPManager.py b/lnst/RecipeCommon/MPTCPManager.py index c5037fb0d..4130eff38 100644 --- a/lnst/RecipeCommon/MPTCPManager.py +++ b/lnst/RecipeCommon/MPTCPManager.py @@ -1,7 +1,6 @@ from enum import IntFlag from typing import Dict, List -from pyroute2 import MPTCP from socket import AF_INET, AF_INET6 from lnst.Common.IpAddress import ipaddress, BaseIpAddress @@ -78,6 +77,8 @@ def is_backup(self): class MPTCPManager: def __init__(self): + from pyroute2 import MPTCP + self._mptcp = MPTCP() self._endpoints = {}