Skip to content
Merged
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
16 changes: 9 additions & 7 deletions virttest/utils_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import tempfile
from functools import cmp_to_key

import aexpect
from avocado.core import exceptions
from avocado.utils import process, wait
from avocado.utils.service import SpecificServiceManager
Expand Down Expand Up @@ -64,7 +65,9 @@ def copytree(src, dst, overwrite=True, ignore=""):
shutil.copy(src_file, dst_dir)


def is_mount(src, dst=None, fstype=None, options=None, verbose=False, session=None):
def is_mount(
src=None, dst=None, fstype=None, options=None, verbose=False, session=None
):
"""
Check is src or dst mounted.

Expand All @@ -77,23 +80,22 @@ def is_mount(src, dst=None, fstype=None, options=None, verbose=False, session=No
:return: True if mounted, else return False
"""
mount_options = [("-S", src), ("-M", dst), ("-t", fstype), ("-O", options)]
mount_opts = " ".join(
f"{opt} {val}" for opt, val in mount_options if val is not None
)
mount_opts = " ".join(f"{opt} {val}" for opt, val in mount_options if val)
if mount_opts == "":
raise exceptions.TestError("Mount options is empty, it is meaningless")
mount_check_cmd = f"findmnt -J {mount_opts}"

mount_result = None
try:
if session:
mount_result = session.cmd_output_safe(mount_check_cmd)
mount_result = session.cmd(mount_check_cmd)
else:
mount_result = process.run(mount_check_cmd, shell=True).stdout_text
if verbose:
LOG.info("Output of findmnt: %s", mount_result)
except process.CmdError:
pass
except (process.CmdError, aexpect.exceptions.ShellCmdError) as e:
LOG.error("Exception info: %s", e)
return False

if mount_result:
if verbose:
Expand Down