зеркало из https://github.com/microsoft/lisa.git
Use Aria tool for downloading image files
This commit is contained in:
Родитель
c8b496212b
Коммит
cdbcb796fc
|
@ -14,7 +14,9 @@ from lisa.base_tools import (
|
|||
YumConfigManager,
|
||||
)
|
||||
|
||||
from .aria import Aria
|
||||
from .blkid import Blkid
|
||||
from .bzip2 import Bzip2
|
||||
from .chmod import Chmod
|
||||
from .chown import Chown
|
||||
from .chrony import Chrony
|
||||
|
@ -106,7 +108,9 @@ from .who import Who
|
|||
from .whoami import Whoami
|
||||
|
||||
__all__ = [
|
||||
"Aria",
|
||||
"Blkid",
|
||||
"Bzip2",
|
||||
"Cat",
|
||||
"Chmod",
|
||||
"Chown",
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
from typing import Optional
|
||||
|
||||
from lisa.base_tools import Wget
|
||||
from lisa.executable import Tool
|
||||
from lisa.operating_system import Posix
|
||||
from lisa.tools.lscpu import Lscpu
|
||||
from lisa.tools.make import Make
|
||||
from lisa.tools.mkdir import Mkdir
|
||||
from lisa.tools.tar import Tar
|
||||
|
||||
|
||||
class Aria(Tool):
|
||||
_DOWNLOAD_LOCATION = "https://github.com/q3aql/aria2-static-builds/releases/download/v1.35.0/aria2-1.35.0-linux-gnu-64bit-build1.tar.bz2" # noqa: E501
|
||||
_DOWNLOAD_TAR_NAME = "aria2-1.35.0-linux-gnu-64bit-build1.tar.bz2"
|
||||
_DOWNLOAD_NAME = "aria2-1.35.0-linux-gnu-64bit-build1"
|
||||
|
||||
@property
|
||||
def command(self) -> str:
|
||||
return "aria2c"
|
||||
|
||||
@property
|
||||
def can_install(self) -> bool:
|
||||
return True
|
||||
|
||||
def install(self) -> bool:
|
||||
posix_os: Posix = self.node.os # type: ignore
|
||||
try:
|
||||
posix_os.install_packages(["aria2"])
|
||||
except Exception as identifier:
|
||||
self._log.debug(f"Failed to install aria2: {identifier}")
|
||||
|
||||
if not self._check_exists():
|
||||
self._log.debug("Installing aria2 from source")
|
||||
downloaded_file_path = self.node.tools[Wget].get(
|
||||
self._DOWNLOAD_LOCATION,
|
||||
file_path=str(self.node.working_path),
|
||||
filename=self._DOWNLOAD_TAR_NAME,
|
||||
force_run=True,
|
||||
)
|
||||
self.node.tools[Tar].extract(
|
||||
file=downloaded_file_path, dest_dir=str(self.node.working_path)
|
||||
)
|
||||
|
||||
# make and install aria2
|
||||
self.node.tools[Make].make_install(
|
||||
cwd=self.node.working_path / self._DOWNLOAD_NAME
|
||||
)
|
||||
|
||||
return self._check_exists()
|
||||
|
||||
def get(
|
||||
self,
|
||||
url: str,
|
||||
file_path: str = "",
|
||||
filename: str = "",
|
||||
overwrite: bool = True,
|
||||
sudo: bool = False,
|
||||
force_run: bool = False,
|
||||
num_connections: Optional[int] = None,
|
||||
timeout: int = 600,
|
||||
) -> str:
|
||||
|
||||
if file_path:
|
||||
# create folder when it doesn't exist
|
||||
self.node.tools[Mkdir].create_directory(file_path, sudo=sudo)
|
||||
else:
|
||||
file_path = str(self.node.working_path)
|
||||
|
||||
# set download path
|
||||
download_path = f"{file_path}/{filename}"
|
||||
|
||||
# if num_connections is not specified, set to minimum of number of cores
|
||||
# on the node, or 16 which is the max number of connections aria2 can
|
||||
# handle
|
||||
if not num_connections:
|
||||
num_connections = min(self.node.tools[Lscpu].get_core_count(), 16)
|
||||
|
||||
# setup aria2c command and run
|
||||
command = f"-x {num_connections} --dir={file_path} --out={filename} "
|
||||
if overwrite:
|
||||
command += "--allow-overwrite=true "
|
||||
force_run = True
|
||||
command += f"'{url}'"
|
||||
self.run(
|
||||
command,
|
||||
sudo=sudo,
|
||||
force_run=force_run,
|
||||
timeout=timeout,
|
||||
)
|
||||
|
||||
return download_path
|
|
@ -0,0 +1,18 @@
|
|||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT license.
|
||||
from lisa.executable import Tool
|
||||
from lisa.operating_system import Posix
|
||||
|
||||
|
||||
class Bzip2(Tool):
|
||||
@property
|
||||
def command(self) -> str:
|
||||
return "bzip2"
|
||||
|
||||
def can_install(self) -> bool:
|
||||
return True
|
||||
|
||||
def _install(self) -> bool:
|
||||
posix_os: Posix = self.node.os # type: ignore
|
||||
posix_os.install_packages([self])
|
||||
return self._check_exists()
|
|
@ -6,7 +6,7 @@ from typing import TYPE_CHECKING, Dict, Optional, cast
|
|||
|
||||
from lisa.executable import Tool
|
||||
from lisa.operating_system import Posix
|
||||
from lisa.tools import Gcc
|
||||
from lisa.tools.gcc import Gcc
|
||||
from lisa.tools.lscpu import Lscpu
|
||||
|
||||
if TYPE_CHECKING:
|
||||
|
|
|
@ -6,6 +6,8 @@ from typing import Callable, List
|
|||
from assertpy import assert_that
|
||||
|
||||
from lisa.executable import Tool
|
||||
from lisa.operating_system import Suse
|
||||
from lisa.tools.bzip2 import Bzip2
|
||||
|
||||
|
||||
class Tar(Tool):
|
||||
|
@ -13,6 +15,13 @@ class Tar(Tool):
|
|||
def command(self) -> str:
|
||||
return "tar"
|
||||
|
||||
def _check_exists(self) -> bool:
|
||||
if isinstance(self.node.os, Suse):
|
||||
# ensure that bzip2 is installed on Suse
|
||||
_ = self.node.tools[Bzip2]
|
||||
|
||||
return True
|
||||
|
||||
def extract(
|
||||
self,
|
||||
file: str,
|
||||
|
|
|
@ -7,7 +7,7 @@ from lisa import RemoteNode, schema
|
|||
from lisa.features.network_interface import Synthetic
|
||||
from lisa.operating_system import Debian, Fedora, Suse
|
||||
from lisa.schema import Node
|
||||
from lisa.tools import HyperV, Lscpu, Qemu, Wget
|
||||
from lisa.tools import Aria, HyperV, Lscpu, Qemu, Wget
|
||||
from lisa.tools.rm import Rm
|
||||
from lisa.util import SkippedException, fields_to_dict
|
||||
from lisa.util.logger import Logger
|
||||
|
@ -60,7 +60,7 @@ def qemu_connect_nested_vm(
|
|||
|
||||
image_folder_path = host.find_partition_with_freespace(image_size)
|
||||
|
||||
host.tools[Wget].get(
|
||||
host.tools[Aria].get(
|
||||
url=guest_image_url,
|
||||
file_path=image_folder_path,
|
||||
filename=image_name,
|
||||
|
|
Загрузка…
Ссылка в новой задаче