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

Add couple utility in disk utility #5928

Merged
merged 2 commits into from
May 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions avocado/utils/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,44 @@ def get_disk_partitions(disk):
for line in partitions_op.split("\n")
if line.startswith(disk) and "Extended" not in line
]


def get_io_scheduler_list(device_name):
"""
Returns io scheduler available for the IO Device
:param device_name: Device name example like sda
:return: list of IO scheduler
"""
names = open(__sched_path(device_name), "r", encoding="utf-8").read()
return names.translate(str.maketrans("[]", " ")).split()


def get_io_scheduler(device_name):
"""
Return io scheduler name which is set currently for device
:param device_name: Device name example like sda
:return: IO scheduler
:rtype : str
"""
return re.split(
r"[\[\]]", open(__sched_path(device_name), "r", encoding="utf-8").read()
)[1]


def __sched_path(device_name):

file_path = f"/sys/block/{device_name}/queue/scheduler"
return file_path


def set_io_scheduler(device_name, name):
"""
Set io scheduler to a device
:param device_name: Device name example like sda
:param name: io scheduler name
"""
if name not in get_io_scheduler_list(device_name):
raise DiskError(f"No such IO scheduler: {name}")

with open(__sched_path(device_name), "w", encoding="utf-8") as fp:
fp.write(name)