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

Make blockdev calls lazy #223

Merged
merged 2 commits into from
Oct 10, 2023
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
27 changes: 21 additions & 6 deletions test_harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@
_SIZE_OF_DEVICE = 1024**4 # 1 TiB


class _LogBlockdev: # pylint: disable=too-few-public-methods
"""
Allows only running blockdev commands if the result will be logged.
"""

def __init__(self, option, device):
self.cmd = ["blockdev", option, device]

def __str__(self):
try:
with subprocess.Popen(self.cmd, stdout=subprocess.PIPE) as proc:
output = proc.stdout.readline().strip().decode("utf-8")
except: # pylint: disable=bare-except
return f"could not gather output of {self.cmd}"

return f"output of {self.cmd}: {output}"


def _make_loopbacked_devices(num):
"""
Make the requisite number of loopbacked devices.
Expand All @@ -52,6 +70,9 @@ def _make_loopbacked_devices(num):

devices.append(device)

for option in ["--getss", "--getpbsz", "--getiomin", "--getioopt"]:
logging.debug("%s", _LogBlockdev(option, device))

return devices


Expand All @@ -63,12 +84,6 @@ def _run_command(num_devices, command):
:param list command: the command to be run
"""
devices = _make_loopbacked_devices(num_devices)
for device in devices:
for option in ["--getss", "--getpbsz", "--getiomin", "--getioopt"]:
diagcmd = ["blockdev", option, device]
with subprocess.Popen(diagcmd, stdout=subprocess.PIPE) as proc:
blockdevoutput = proc.stdout.readline().strip().decode("utf-8")
logging.debug("output of %s: %s", diagcmd, blockdevoutput)

command = command + list(itertools.chain(*[["--disk", dev] for dev in devices]))
subprocess.run(command, check=True)
Expand Down