Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow test with already-mounted smbshare on local dir #32

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions testcases/mount/test_mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,40 @@
test_info_dict = testhelper.read_yaml(test_info)


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 _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_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)
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)
Expand All @@ -37,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]]:
Expand Down
9 changes: 8 additions & 1 deletion testhelper/testhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand All @@ -36,6 +41,7 @@ def gen_mount_params(
"share": share,
"username": username,
"password": password,
"test_dir": test_dir,
}
return ret

Expand Down Expand Up @@ -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", ""),
)


Expand Down