From 00f5729f34b2e689a1a78cd2dc5c70accc4de5eb Mon Sep 17 00:00:00 2001 From: Praveen K Pandey Date: Wed, 8 May 2024 08:58:51 +0530 Subject: [PATCH] Added utility in disk library help to Set io scheduler to a device Added utility in disk library help to Set io scheduler to a device Signed-off-by: Praveen K Pandey --- avocado/utils/disk.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/avocado/utils/disk.py b/avocado/utils/disk.py index 1694072a61..e740701961 100644 --- a/avocado/utils/disk.py +++ b/avocado/utils/disk.py @@ -474,4 +474,17 @@ def get_io_scheduler(device_name): def __sched_path(device_name): - return "/sys/block/%s/queue/scheduler" % device_name \ No newline at end of file + return "/sys/block/%s/queue/scheduler" % device_name + + +def set_io_scheduler(device_name, name): + """ + Set io scheduler to a device + :param device_name: Device name example like sda , hda + :param name: io scheduler name + """ + if name not in get_io_scheduler_list(device_name): + raise DiskError("No such IO scheduler: %s" % name) + + with open(__sched_path(device_name), "w") as fp: + fp.write(name)