Skip to content

Commit

Permalink
DpdkTestpmd Installer: fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mcgov committed Sep 18, 2024
1 parent ff2e064 commit 88a0074
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 42 deletions.
57 changes: 19 additions & 38 deletions microsoft/testsuites/dpdk/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,16 @@
# Licensed under the MIT license.

from datetime import datetime
from enum import Enum
from pathlib import PurePath
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
from typing import Any, Callable, Dict, List, Optional, Sequence

from assertpy import assert_that
from semver import VersionInfo
from urllib3.util.url import parse_url

from lisa import Node
from lisa.executable import Tool
from lisa.operating_system import (
Debian,
Fedora,
OperatingSystem,
Oracle,
Posix,
Redhat,
Suse,
Ubuntu,
)
from lisa.operating_system import Debian, Fedora, Oracle, Posix, Redhat, Suse, Ubuntu
from lisa.tools import Git, Tar, Wget
from lisa.util import UnsupportedDistroException

Expand Down Expand Up @@ -72,51 +62,42 @@ def install_required_packages(
return
raise UnsupportedDistroException(
os,
message="DPDK Package installation is missing required packages for this os.",
message=("Installer did not define dependencies for this os."),
)


class Installer:
# Generic 'Installer' parent class for DpdkTestpmd/rdma-core
# NOTE: This should not be instantiated directly.
_err_msg = "not implemented for this installation type."

# setup the node before starting
# ex: updating the kernel, enabling features, checking drivers, etc.
def _setup_node(self):
raise NotImplementedError("Repo setup for DPDK Installation not implemented")
raise NotImplementedError(f"_setup_node {self._err_msg}")

# check if the package is already installed:
# Is the package installed from source? Or from the package manager?
# Does the version match the one we want if we need a specific one?
def _check_if_installed(self) -> bool:
raise NotImplementedError(
"Installed check for DPDK installation not implemented for this installation type."
)
raise NotImplementedError(f"_check_if_installed {self._err_msg}")

# setup the installation (install Ninja, Meson, etc)
def _setup_installation(self) -> None:
raise NotImplementedError(
"Setup for DPDK installation is not implemented for this installation type."
)
raise NotImplementedError(f"_setup_installation {self._err_msg}")

# do the build and installation
def _run_installation(self) -> None:
raise NotImplementedError(
"Setup for DPDK installation is not implemented for this installation type."
)
raise NotImplementedError(f"_run_installation {self._err_msg}")

# remove an installation
def _clean_previous_installation(self) -> None:
raise NotImplementedError(
"Cleanup for DPDK installation is not implemented for this installation type."
)
raise NotImplementedError(f"_clean_previous_installation {self._err_msg}")

# provide an opportunity to check tags, fetch a subproject,
# modify the config, etc.
def _configure_installation(self) -> None:
raise NotImplementedError(
"Child class must define setup steps for this source installation type."
)
raise NotImplementedError(f"_configure_installation {self._err_msg}")

# install the dependencies
def _install_dependencies(self) -> None:
Expand All @@ -127,9 +108,7 @@ def _install_dependencies(self) -> None:

# define how to check the installed version
def get_installed_version(self) -> VersionInfo:
raise NotImplementedError(
"Version check for DPDK installation is not implemented for this installation type."
)
raise NotImplementedError(f"get_installed_version {self._err_msg}")

# run the defined setup and installation steps.
def do_installation(self, required_version: Optional[VersionInfo] = None) -> None:
Expand Down Expand Up @@ -172,7 +151,7 @@ def _configure_installation(self) -> None:
def _clean_previous_installation(self) -> None:
if not isinstance(self._os, Posix):
return
if self._os_dependencies != None:
if self._os_dependencies is not None:
for os_package_check in self._os_dependencies.requirements:
if os_package_check.check_node_os(self._os):
self._os.uninstall_packages(os_package_check.packages)
Expand All @@ -185,7 +164,7 @@ def _check_if_installed(self) -> bool:
# WARNING: Don't use this for long lists of packages.
# For dpdk, pkg-manager install is only for 'dpdk' and 'dpdk-dev'
# This will take too long if it's more than a few packages.
if self._os_dependencies != None:
if self._os_dependencies is not None:
for os_package_check in self._os_dependencies.requirements:
if os_package_check.check_node_os(self._os):
for pkg in os_package_check.packages:
Expand Down Expand Up @@ -386,7 +365,7 @@ def check_dpdk_support(node: Node) -> None:
# ex: make a SIG image first using the kernel build transformer.
if node.os.get_kernel_information().version < "5.15.0":
raise UnsupportedDistroException(
node.os, f"MANA driver is not available for kernel < 5.15"
node.os, "MANA driver is not available for kernel < 5.15"
)
if not supported:
raise UnsupportedDistroException(
Expand All @@ -400,6 +379,8 @@ def is_url_for_tarball(url: str) -> bool:

def is_url_for_git_repo(url: str) -> bool:
parsed_url = parse_url(url)
return parsed_url.scheme in ["http", "https"] and PurePath(
parsed_url.path
).suffixes == [".git"]
scheme = parsed_url.scheme
path = parsed_url.path
if not (scheme and path):
return False
return scheme in ["http", "https"] and PurePath(path).suffixes == [".git"]
9 changes: 5 additions & 4 deletions microsoft/testsuites/dpdk/dpdktestpmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
from assertpy import assert_that, fail
from semver import VersionInfo

from lisa.base_tools import Mv
from lisa.executable import ExecutableResult, Tool
from lisa.nic import NicInfo
from lisa.node import Node
from lisa.operating_system import Debian, Fedora, OperatingSystem, Suse, Ubuntu
from lisa.operating_system import Debian, Fedora, Suse, Ubuntu
from lisa.tools import (
Cp,
Echo,
Expand Down Expand Up @@ -204,10 +203,12 @@ def _clean_previous_installation(self) -> None:
"DPDK Installer source path was empty during attempted cleanup!"
).is_not_empty()
assert_that(str(source_path)).described_as(
"DPDK Installer source path was set to root dir '/' during attempted cleanup!"
"DPDK Installer source path was set to root dir "
"'/' during attempted cleanup!"
).is_not_equal_to("/")
assert_that(str(source_path)).described_as(
f"DPDK Installer source path {source_path} was set to working path '{working_path}' during attempted cleanup!"
f"DPDK Installer source path {source_path} was set to "
f"working path '{working_path}' during attempted cleanup!"
).is_not_equal_to(working_path)
# remove source code directory
self._node.execute(f"rm -rf {str(source_path)}", shell=True)
Expand Down

0 comments on commit 88a0074

Please sign in to comment.