Skip to content

Commit

Permalink
Merge pull request #5928 from PraveenPenguin/add_disk
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Richter <jarichte@redhat.com>
  • Loading branch information
richtja committed May 14, 2024
2 parents 17dd26c + d6d293b commit bf9bc74
Showing 1 changed file with 41 additions and 0 deletions.
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)

0 comments on commit bf9bc74

Please sign in to comment.