From: "Juraj Linkeš" <juraj.linkes@pantheon.tech>
To: thomas@monjalon.net, Honnappa.Nagarahalli@arm.com,
paul.szczepanek@arm.com, Luca.Vizzarro@arm.com,
alex.chapman@arm.com, probb@iol.unh.edu, jspewock@iol.unh.edu,
npratte@iol.unh.edu, dmarx@iol.unh.edu
Cc: dev@dpdk.org, "Tomáš Ďurovec" <tomas.durovec@pantheon.tech>
Subject: [RFC PATCH v1 06/12] dts: add ability to prevent overwriting files/dirs
Date: Fri, 6 Sep 2024 15:26:50 +0200 [thread overview]
Message-ID: <20240906132656.21729-7-juraj.linkes@pantheon.tech> (raw)
In-Reply-To: <20240906132656.21729-1-juraj.linkes@pantheon.tech>
From: Tomáš Ďurovec <tomas.durovec@pantheon.tech>
Signed-off-by: Tomáš Ďurovec <tomas.durovec@pantheon.tech>
---
dts/framework/settings.py | 17 ++++++++++
dts/framework/testbed_model/os_session.py | 31 +++++++++++++++---
dts/framework/testbed_model/posix_session.py | 33 +++++++++++++++++---
3 files changed, 71 insertions(+), 10 deletions(-)
diff --git a/dts/framework/settings.py b/dts/framework/settings.py
index 2b8c583853..2f7089a26b 100644
--- a/dts/framework/settings.py
+++ b/dts/framework/settings.py
@@ -55,6 +55,11 @@
Git revision ID to test. Could be commit, tag, tree ID etc.
To test local changes, first commit them, then use their commit ID.
+.. option:: -f, --force
+.. envvar:: DTS_FORCE
+
+ Specify to remove an already existing dpdk tarball before copying/extracting a new one.
+
.. option:: --test-suite
.. envvar:: DTS_TEST_SUITES
@@ -110,6 +115,8 @@ class Settings:
#:
dpdk_tarball_path: Path | str = ""
#:
+ force: bool = False
+ #:
compile_timeout: float = 1200
#:
test_suites: list[TestSuiteConfig] = field(default_factory=list)
@@ -337,6 +344,16 @@ def _get_parser() -> _DTSArgumentParser:
)
_add_env_var_to_action(action)
+ action = parser.add_argument(
+ "-f",
+ "--force",
+ action="store_true",
+ default=SETTINGS.force,
+ help="Specify to remove an already existing dpdk tarball before copying/extracting a "
+ "new one.",
+ )
+ _add_env_var_to_action(action)
+
action = parser.add_argument(
"--compile-timeout",
default=SETTINGS.compile_timeout,
diff --git a/dts/framework/testbed_model/os_session.py b/dts/framework/testbed_model/os_session.py
index 92b1a09d94..afc9ffb814 100644
--- a/dts/framework/testbed_model/os_session.py
+++ b/dts/framework/testbed_model/os_session.py
@@ -178,7 +178,9 @@ def join_remote_path(self, *args: str | PurePath) -> PurePath:
"""
@abstractmethod
- def copy_from(self, source_file: str | PurePath, destination_dir: str | Path) -> None:
+ def copy_from(
+ self, source_file: str | PurePath, destination_dir: str | Path, force: bool = SETTINGS.force
+ ) -> None:
"""Copy a file from the remote node to the local filesystem.
Copy `source_file` from the remote node associated with this remote
@@ -188,10 +190,14 @@ def copy_from(self, source_file: str | PurePath, destination_dir: str | Path) ->
source_file: The file on the remote node.
destination_dir: A dir path on the local filesystem, where the `source_file`
will be saved.
+ force: If :data:`True`, remove an already existing `source_file` at the
+ `destination_dir` before copying to prevent overwriting data.
"""
@abstractmethod
- def copy_to(self, source_file: str | Path, destination_dir: str | PurePath) -> None:
+ def copy_to(
+ self, source_file: str | Path, destination_dir: str | PurePath, force: bool = SETTINGS.force
+ ) -> None:
"""Copy a file from local filesystem to the remote node.
Copy `source_file` from local filesystem to `destination_dir`
@@ -201,6 +207,8 @@ def copy_to(self, source_file: str | Path, destination_dir: str | PurePath) -> N
source_file: The file on the local filesystem.
destination_dir: A dir path on the remote Node, where the `source_file`
will be saved.
+ force: If :data:`True`, remove an already existing `source_file` at the
+ `destination_dir` before copying to prevent overwriting data.
"""
@abstractmethod
@@ -210,6 +218,7 @@ def copy_dir_from(
destination_dir: str | Path,
compress_format: TarCompressionFormat = TarCompressionFormat.none,
exclude: str | list[str] | None = None,
+ force: bool = SETTINGS.force,
) -> None:
"""Copy a dir from the remote node to the local filesystem.
@@ -222,6 +231,8 @@ def copy_dir_from(
destination_dir: A dir path on the local filesystem.
compress_format: The compression format to use. Default is no compression.
exclude: Files or dirs to exclude before creating the tarball.
+ force: If :data:`True`, remove an already existing `source_dir` at the `destination_dir`
+ before copying to prevent overwriting data.
"""
@abstractmethod
@@ -231,18 +242,21 @@ def copy_dir_to(
destination_dir: str | PurePath,
compress_format: TarCompressionFormat = TarCompressionFormat.none,
exclude: str | list[str] | None = None,
+ force: bool = SETTINGS.force,
) -> None:
"""Copy a dir from the local filesystem to the remote node.
Copy `source_dir` from the local filesystem to `destination_dir` on the remote node
- associated with this remote session. The new remote dir will be created at
- `destination_dir` path.
+ associated with this remote session. The new remote dir will be created
+ at `destination_dir` path.
Args:
source_dir: The dir on the local filesystem.
destination_dir: A dir path on the remote node.
compress_format: The compression format to use. Default is no compression.
exclude: Files or dirs to exclude before creating the tarball.
+ force: If :data:`True`, remove an already existing `source_dir` at the `destination_dir`
+ before copying to prevent overwriting data.
"""
@abstractmethod
@@ -275,6 +289,7 @@ def create_remote_tarball(
remote_dir_path: str | PurePath,
compress_format: TarCompressionFormat = TarCompressionFormat.none,
exclude: str | list[str] | None = None,
+ force: bool = SETTINGS.force,
) -> None:
"""Create a tarball from dir on the remote node.
@@ -284,6 +299,8 @@ def create_remote_tarball(
remote_dir_path: The path of dir on the remote node.
compress_format: The compression format to use. Default is no compression.
exclude: Files or dirs to exclude before creating the tarball.
+ force: If :data:`True`, remove an already existing tarball at the directory of
+ `remote_dir_path` before creating a new one to prevent overwriting data.
"""
@abstractmethod
@@ -291,13 +308,17 @@ def extract_remote_tarball(
self,
remote_tarball_path: str | PurePath,
expected_dir: str | PurePath | None = None,
+ force: bool = SETTINGS.force,
) -> None:
- """Extract remote tarball in its remote directory.
+ """Extract remote tarball in its remote dir.
Args:
remote_tarball_path: The path of the tarball on the remote node.
expected_dir: If non-empty, check whether `expected_dir` exists after extracting
the archive.
+ force: If :data:`True` and `expected_dir` is defined, remove an already
+ existing `expected_dir` at the directory of `remote_dir_path` before
+ extracting to prevent overwriting data.
"""
@abstractmethod
diff --git a/dts/framework/testbed_model/posix_session.py b/dts/framework/testbed_model/posix_session.py
index 5a6d971d7d..94aac68e8d 100644
--- a/dts/framework/testbed_model/posix_session.py
+++ b/dts/framework/testbed_model/posix_session.py
@@ -91,12 +91,22 @@ def join_remote_path(self, *args: str | PurePath) -> PurePosixPath:
"""Overrides :meth:`~.os_session.OSSession.join_remote_path`."""
return PurePosixPath(*args)
- def copy_from(self, source_file: str | PurePath, destination_dir: str | Path) -> None:
+ def copy_from(
+ self, source_file: str | PurePath, destination_dir: str | Path, force: bool = SETTINGS.force
+ ) -> None:
"""Overrides :meth:`~.os_session.OSSession.copy_from`."""
+ if force:
+ Path(destination_dir, PurePath(source_file).name).unlink(missing_ok=True)
+
self.remote_session.copy_from(source_file, destination_dir)
- def copy_to(self, source_file: str | Path, destination_dir: str | PurePath) -> None:
+ def copy_to(
+ self, source_file: str | Path, destination_dir: str | PurePath, force: bool = SETTINGS.force
+ ) -> None:
"""Overrides :meth:`~.os_session.OSSession.copy_to`."""
+ if force:
+ self.remove_remote_file(PurePath(destination_dir, Path(source_file).name))
+
self.remote_session.copy_to(source_file, destination_dir)
def copy_dir_from(
@@ -105,13 +115,14 @@ def copy_dir_from(
destination_dir: str | Path,
compress_format: TarCompressionFormat = TarCompressionFormat.none,
exclude: str | list[str] | None = None,
+ force: bool = SETTINGS.force,
) -> None:
"""Overrides :meth:`~.os_session.OSSession.copy_dir_from`."""
tarball_name = f"{PurePath(source_dir).name}{compress_format.extension}"
remote_tarball_path = self.join_remote_path(PurePath(source_dir).parent, tarball_name)
self.create_remote_tarball(source_dir, compress_format, exclude)
- self.copy_from(remote_tarball_path, destination_dir)
+ self.copy_from(remote_tarball_path, destination_dir, force)
self.remove_remote_file(remote_tarball_path)
tarball_path = Path(destination_dir, tarball_name)
@@ -124,6 +135,7 @@ def copy_dir_to(
destination_dir: str | PurePath,
compress_format: TarCompressionFormat = TarCompressionFormat.none,
exclude: str | list[str] | None = None,
+ force: bool = SETTINGS.force,
) -> None:
"""Overrides :meth:`~.os_session.OSSession.copy_dir_to`."""
source_dir_name = Path(source_dir).name
@@ -131,7 +143,7 @@ def copy_dir_to(
tar_path = Path(Path(source_dir).parent, tar_name)
create_tarball(source_dir, compress_format, arcname=source_dir_name, exclude=exclude)
- self.copy_to(tar_path, destination_dir)
+ self.copy_to(tar_path, destination_dir, force)
tar_path.unlink()
remote_tar_path = self.join_remote_path(destination_dir, tar_name)
@@ -158,6 +170,7 @@ def create_remote_tarball(
remote_dir_path: str | PurePath,
compress_format: TarCompressionFormat = TarCompressionFormat.none,
exclude: str | list[str] | None = None,
+ force: bool = SETTINGS.force,
) -> None:
"""Overrides :meth:`~.os_session.OSSession.create_remote_tarball`."""
@@ -176,6 +189,9 @@ def generate_tar_exclude_args(exclude_patterns):
return ""
target_tarball_path = f"{remote_dir_path}{compress_format.extension}"
+ if force:
+ self.remove_remote_file(target_tarball_path)
+
self.send_command(
f"tar caf {target_tarball_path}{generate_tar_exclude_args(exclude)} "
f"-C {PurePath(remote_dir_path).parent} {PurePath(remote_dir_path).name}",
@@ -183,13 +199,20 @@ def generate_tar_exclude_args(exclude_patterns):
)
def extract_remote_tarball(
- self, remote_tarball_path: str | PurePath, expected_dir: str | PurePath | None = None
+ self,
+ remote_tarball_path: str | PurePath,
+ expected_dir: str | PurePath | None = None,
+ force: bool = SETTINGS.force,
) -> None:
"""Overrides :meth:`~.os_session.OSSession.extract_remote_tarball`."""
+ if force and expected_dir:
+ self.remove_remote_dir(expected_dir)
+
self.send_command(
f"tar xfm {remote_tarball_path} -C {PurePosixPath(remote_tarball_path).parent}",
60,
)
+
if expected_dir:
self.send_command(f"ls {expected_dir}", verify=True)
--
2.43.0
next prev parent reply other threads:[~2024-09-06 13:27 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-06 13:26 [RFC PATCH v1 00/12] DTS external DPDK build and stats Juraj Linkeš
2024-09-06 13:26 ` [RFC PATCH v1 01/12] dts: rename build target to DPDK build Juraj Linkeš
2024-09-06 13:26 ` [RFC PATCH v1 02/12] dts: one dpdk build per test run Juraj Linkeš
2024-09-06 13:26 ` [RFC PATCH v1 03/12] dts: fix remote session transferring files Juraj Linkeš
2024-09-06 13:26 ` [RFC PATCH v1 04/12] dts: improve path handling for local and remote paths Juraj Linkeš
2024-09-06 13:26 ` [RFC PATCH v1 05/12] dts: add the ability to copy directories via remote Juraj Linkeš
2024-09-06 13:26 ` Juraj Linkeš [this message]
2024-09-06 13:26 ` [RFC PATCH v1 07/12] dts: update argument option for prevent overwriting Juraj Linkeš
2024-09-06 13:26 ` [RFC PATCH v1 08/12] dts: add support for externally compiled DPDK Juraj Linkeš
2024-09-06 13:26 ` [RFC PATCH v1 09/12] doc: update argument options for external DPDK build Juraj Linkeš
2024-09-06 13:26 ` [RFC PATCH v1 10/12] dts: remove git ref option Juraj Linkeš
2024-09-06 13:26 ` [RFC PATCH v1 11/12] doc: remove git-ref argument Juraj Linkeš
2024-09-06 13:26 ` [RFC PATCH v1 12/12] dts: improve statistics Juraj Linkeš
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240906132656.21729-7-juraj.linkes@pantheon.tech \
--to=juraj.linkes@pantheon.tech \
--cc=Honnappa.Nagarahalli@arm.com \
--cc=Luca.Vizzarro@arm.com \
--cc=alex.chapman@arm.com \
--cc=dev@dpdk.org \
--cc=dmarx@iol.unh.edu \
--cc=jspewock@iol.unh.edu \
--cc=npratte@iol.unh.edu \
--cc=paul.szczepanek@arm.com \
--cc=probb@iol.unh.edu \
--cc=thomas@monjalon.net \
--cc=tomas.durovec@pantheon.tech \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).