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: diff --git a/lnst/Devices/Device.py b/lnst/Devices/Device.py index d7608d863..76c97e661 100644 --- a/lnst/Devices/Device.py +++ b/lnst/Devices/Device.py @@ -12,13 +12,10 @@ """ import re -import ethtool -import pyroute2 import logging 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 @@ -28,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): @@ -55,6 +48,20 @@ class Device(object, metaclass=DeviceMeta): """ def __init__(self, if_manager): + import ethtool + 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 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: 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: 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 = {} 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 }