From fe92ea2e034c3a44028d8672b60bcb0ae3b39cc5 Mon Sep 17 00:00:00 2001 From: Praveen K Pandey Date: Mon, 13 May 2024 18:19:58 +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 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/avocado/utils/disk.py b/avocado/utils/disk.py index c0a11658bf..a26d915ea5 100644 --- a/avocado/utils/disk.py +++ b/avocado/utils/disk.py @@ -478,3 +478,15 @@ 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 , hda + :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)