From e243393b908175f10818d14d417a1b3dbc55f850 Mon Sep 17 00:00:00 2001 From: Shachar Sharon Date: Wed, 27 Sep 2023 17:24:39 +0300 Subject: [PATCH 1/3] testhelper: allow optional 'test_dir' in 'test-info.yml' In cases where user may want to run (some) tests over existing smbshare, allow passing explicit 'test_dir' via 'test-info.yml' configuration file. It is up to the user to ensure that this value hold reference to valid (and mounted) samba share. May be used in Windows/PowerShell case where adding network device is done from outside of sit-test-cases. Signed-off-by: Shachar Sharon --- testhelper/testhelper.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/testhelper/testhelper.py b/testhelper/testhelper.py index 681ca0f..e2ca2c7 100644 --- a/testhelper/testhelper.py +++ b/testhelper/testhelper.py @@ -18,7 +18,11 @@ def read_yaml(test_info): def gen_mount_params( - host: str, share: str, username: str, password: str + host: str, + share: str, + username: str, + password: str, + test_dir: str = "", ) -> typing.Dict[str, str]: """Generate a dict of parameters required to mount a SMB share. @@ -27,6 +31,7 @@ def gen_mount_params( share: exported share name username: username password: password for the user + test_dir: (optional) local-host test-dir over a mounted share Returns: dict: mount parameters in a dict @@ -36,6 +41,7 @@ def gen_mount_params( "share": share, "username": username, "password": password, + "test_dir": test_dir, } return ret @@ -90,6 +96,7 @@ def get_mount_parameters( share, test_info["test_users"][num_users]["username"], test_info["test_users"][num_users]["password"], + test_info.get("test_dir", ""), ) From 6bc1cca19f802dca4dc6324ec4aed83b63b53704 Mon Sep 17 00:00:00 2001 From: Shachar Sharon Date: Mon, 16 Oct 2023 17:20:06 +0300 Subject: [PATCH 2/3] mount: call all sub-tests from single func Code cleanup: have single function for all sub-tests where already having a test-directory over SMB share. Signed-off-by: Shachar Sharon --- testcases/mount/test_mount.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/testcases/mount/test_mount.py b/testcases/mount/test_mount.py index 75f0e11..a12093e 100755 --- a/testcases/mount/test_mount.py +++ b/testcases/mount/test_mount.py @@ -16,6 +16,11 @@ test_info_dict = testhelper.read_yaml(test_info) +def _check_mounted_smbshare(test_dir: str) -> None: + check_io_consistency(test_dir) + check_dbm_consistency(test_dir) + + def mount_check(ipaddr: str, share_name: str) -> None: mount_params = testhelper.get_mount_parameters(test_info_dict, share_name) mount_params["host"] = ipaddr @@ -27,8 +32,7 @@ def mount_check(ipaddr: str, share_name: str) -> None: flag_mounted = True test_dir = os.path.join(mount_point, "mount_test") os.mkdir(test_dir) - check_io_consistency(test_dir) - check_dbm_consistency(test_dir) + _check_mounted_smbshare(test_dir) finally: if flag_mounted: shutil.rmtree(test_dir, ignore_errors=True) From 1b7ec40f56ebf061707b03c53c08f0d1d1d5c748 Mon Sep 17 00:00:00 2001 From: Shachar Sharon Date: Mon, 16 Oct 2023 17:31:22 +0300 Subject: [PATCH 3/3] mount: allow test over already-mounted test-dir Allow two modes of operation: if user provided explicit 'test_dir', use it for I/O consistency tests (assuming it is a valid smb share); otherwise, do the normal flow using cifs_mount/cifs_umount helper functions. Signed-off-by: Shachar Sharon --- testcases/mount/test_mount.py | 37 ++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/testcases/mount/test_mount.py b/testcases/mount/test_mount.py index a12093e..b83b26e 100755 --- a/testcases/mount/test_mount.py +++ b/testcases/mount/test_mount.py @@ -16,16 +16,33 @@ test_info_dict = testhelper.read_yaml(test_info) +def _get_test_dirs( + mount_params: typing.Dict[str, str] +) -> typing.Tuple[str, str, str, bool]: + test_dir = mount_params.get("test_dir", "") + if not test_dir: + tmp_root = testhelper.get_tmp_root() + mount_point = testhelper.get_tmp_mount_point(tmp_root) + test_dir = os.path.join(mount_point, "mount_test") + do_mnt = True + else: + tmp_root = "" + mount_point = "" + do_mnt = False + return (tmp_root, mount_point, test_dir, do_mnt) + + def _check_mounted_smbshare(test_dir: str) -> None: check_io_consistency(test_dir) check_dbm_consistency(test_dir) -def mount_check(ipaddr: str, share_name: str) -> None: - mount_params = testhelper.get_mount_parameters(test_info_dict, share_name) - mount_params["host"] = ipaddr - tmp_root = testhelper.get_tmp_root() - mount_point = testhelper.get_tmp_mount_point(tmp_root) +def _mount_and_check( + mount_params: typing.Dict[str, str], + tmp_root: str, + mount_point: str, + test_dir: str, +) -> None: flag_mounted = False try: testhelper.cifs_mount(mount_params, mount_point) @@ -41,6 +58,16 @@ def mount_check(ipaddr: str, share_name: str) -> None: os.rmdir(tmp_root) +def mount_check(ipaddr: str, share_name: str) -> None: + mount_params = testhelper.get_mount_parameters(test_info_dict, share_name) + mount_params["host"] = ipaddr + (tmp_root, mount_point, test_dir, do_mnt) = _get_test_dirs(mount_params) + if do_mnt: + _mount_and_check(mount_params, tmp_root, mount_point, test_dir) + else: + _check_mounted_smbshare(test_dir) + + def generate_mount_check( test_info_file: dict, ) -> typing.List[typing.Tuple[str, str]]: