From b5a6cfbb9368185f4235758b8c59ffb50b9d46fb Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Thu, 3 Oct 2024 08:31:28 +0200 Subject: [PATCH 1/2] Introduce crc32 Signed-off-by: Michal Mielewczyk --- test_tools/fs_utils.py | 7 +++++++ test_utils/filesystem/file.py | 3 +++ 2 files changed, 10 insertions(+) diff --git a/test_tools/fs_utils.py b/test_tools/fs_utils.py index 40b1b7d..497fb07 100644 --- a/test_tools/fs_utils.py +++ b/test_tools/fs_utils.py @@ -191,6 +191,13 @@ def md5sum(file, binary=True, timeout: timedelta = timedelta(minutes=30)): return output.stdout.split()[0] +def crc32sum(file, timeout: timedelta = timedelta(minutes=30)): + output = TestRun.executor.run(f"crc32 {file}", timeout) + if output.exit_code != 0: + raise Exception(f"crc32 command execution failed! {output.stdout}\n{output.stderr}") + return output.stdout + + # For some reason separators other than '/' don't work when using sed on system paths # This requires escaping '/' in pattern and target string def escape_sed_string(string: str, sed_replace: bool = False): diff --git a/test_utils/filesystem/file.py b/test_utils/filesystem/file.py index 9554222..369b510 100644 --- a/test_utils/filesystem/file.py +++ b/test_utils/filesystem/file.py @@ -23,6 +23,9 @@ class File(FsItem): def md5sum(self, binary=True, timeout: timedelta = timedelta(minutes=30)): return fs_utils.md5sum(str(self), binary, timeout) + def crc32sum(self, timeout: timedelta = timedelta(minutes=30)): + return fs_utils.crc32sum(str(self), timeout) + def read(self): return fs_utils.read_file(str(self)) From cb0ac3ba3ad539698c4f30f41308f200140d1728 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Thu, 3 Oct 2024 09:06:06 +0200 Subject: [PATCH 2/2] User-defined timeout for `copy` and `move` Signed-off-by: Michal Mielewczyk --- test_tools/fs_utils.py | 9 +++++---- test_utils/filesystem/file.py | 5 +++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/test_tools/fs_utils.py b/test_tools/fs_utils.py index 497fb07..648f1b3 100644 --- a/test_tools/fs_utils.py +++ b/test_tools/fs_utils.py @@ -108,17 +108,18 @@ def copy(source: str, destination: str, force: bool = False, recursive: bool = False, - dereference: bool = False): + dereference: bool = False, + timeout: timedelta = timedelta(minutes=30)): cmd = f"cp{' --force' if force else ''}" \ f"{' --recursive' if recursive else ''}" \ f"{' --dereference' if dereference else ''} " \ f"{source} {destination}" - return TestRun.executor.run_expect_success(cmd) + return TestRun.executor.run_expect_success(cmd, timeout) -def move(source, destination, force: bool = False): +def move(source, destination, force: bool = False, timeout: timedelta = timedelta(minutes=30)): cmd = f"mv{' --force' if force else ''} \"{source}\" \"{destination}\"" - return TestRun.executor.run_expect_success(cmd) + return TestRun.executor.run_expect_success(cmd, timeout) def remove(path: str, force: bool = False, recursive: bool = False, ignore_errors: bool = False): diff --git a/test_utils/filesystem/file.py b/test_utils/filesystem/file.py index 369b510..6848598 100644 --- a/test_utils/filesystem/file.py +++ b/test_utils/filesystem/file.py @@ -54,8 +54,9 @@ class File(FsItem): destination, force: bool = False, recursive: bool = False, - dereference: bool = False): - fs_utils.copy(str(self), destination, force, recursive, dereference) + dereference: bool = False, + timeout: timedelta = timedelta(minutes=30)): + fs_utils.copy(str(self), destination, force, recursive, dereference, timeout) if fs_utils.check_if_directory_exists(destination): path = f"{destination}{'/' if destination[-1] != '/' else ''}{self.name}" else: