Skip to content

Commit

Permalink
Added some utility in disk library
Browse files Browse the repository at this point in the history
added a utility that performs the operation on io scheduler

Signed-off-by: Praveen K Pandey <[email protected]>
  • Loading branch information
PraveenPenguin committed Mar 9, 2020
1 parent e2d8351 commit e02b7c8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions avocado/utils/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,17 @@
import os
import json
import re
import string

from . import process


class DiskUtilsError(Exception):
"""
Base Exception Class for all DiskUtils Error
"""


def freespace(path):
fs_stats = os.statvfs(path)
return fs_stats.f_bsize * fs_stats.f_bavail
Expand Down Expand Up @@ -87,3 +94,41 @@ def get_filesystem_type(mount_point='/'):
_, fs_file, fs_vfstype, _, _, _ = mount_line.split()
if fs_file == mount_point:
return fs_vfstype


def get_io_scheduler_list(device_name):
"""
Returns io scheduler available for the IO Device
:param device_name: Device name example like sda , hda
:return: list of IO scheduler
"""
names = open(__sched_path(device_name)).read()
return names.translate(string.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 , hda
:return: IO scheduler
:rtype : str
"""
return re.split(r'[\[\]]',
open(__sched_path(device_name)).read())[1]


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 DiskUtilsError('No such IO scheduler: %s' % name)

with open(__sched_path(device_name), 'w') as fp:
fp.write(name)


def __sched_path(device_name):
return '/sys/block/%s/queue/scheduler' % device_name
Empty file added avocado/utils/system_log.py
Empty file.

0 comments on commit e02b7c8

Please sign in to comment.