X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FSchedUtils.py;h=bb14c29de8116d647ddecfbefe2cde957237f1b8;hb=79f5ba9bf7656972dd988508eff9465562dde42c;hp=ec18b98dac14fba4a4e8389000c6a5b927cb858c;hpb=d7fed63ae2b5d7b3d1f67f572da2d23388f22018;p=csit.git diff --git a/resources/libraries/python/SchedUtils.py b/resources/libraries/python/SchedUtils.py index ec18b98dac..bb14c29de8 100644 --- a/resources/libraries/python/SchedUtils.py +++ b/resources/libraries/python/SchedUtils.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016 Cisco and/or its affiliates. +# Copyright (c) 2019 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -12,12 +12,13 @@ # limitations under the License. """Linux scheduler util library""" + from resources.libraries.python.ssh import SSH +__all__ = [u"SchedUtils"] -__all__ = ["SchedUtils"] -class SchedUtils(object): +class SchedUtils: """General class for any linux scheduler related methods/functions.""" @staticmethod @@ -32,24 +33,26 @@ class SchedUtils(object): ssh = SSH() ssh.connect(node) - cmd = "cat /proc/`pidof vpp`/task/*/stat | grep -i vpp_wk"\ - " | awk '{print $1}'" + cmd = u"cat /proc/`pidof vpp`/task/*/stat | grep -i vpp_wk" \ + u" | awk '{print $1}'" for _ in range(3): - (ret, out, _) = ssh.exec_command_sudo(cmd) + ret, out, _ = ssh.exec_command_sudo(cmd) if ret == 0: try: if not out: raise ValueError except ValueError: - print 'Reading VPP worker thread PID failed.' + print(u"Reading VPP worker thread PID failed.") else: - for pid in out.split("\n"): - if len(pid) > 0 and pid[0] != "#": + for pid in out.split(u"\n"): + if pid and pid[0] != u"#": SchedUtils.set_proc_scheduling_rr(node, int(pid)) break else: - raise RuntimeError('Failed to retrieve PID for VPP worker threads.') + raise RuntimeError( + u"Failed to retrieve PID for VPP worker threads." + ) @staticmethod def set_proc_scheduling_rr(node, pid, priority=1): @@ -69,16 +72,17 @@ class SchedUtils(object): ssh.connect(node) if pid < 1: - raise ValueError("SCHED_RR: PID must be higher then 1.") + raise ValueError(u"SCHED_RR: PID must be higher then 1.") if 1 <= priority <= 99: - cmd = "chrt -r -p {0} {1}".format(priority, pid) - (ret, _, _) = ssh.exec_command_sudo(cmd) + cmd = f"chrt -r -p {priority} {pid}" + ret, _, _ = ssh.exec_command_sudo(cmd) if ret != 0: - raise RuntimeError("SCHED_RR: Failed to set policy "\ - "for PID {0}.".format(pid)) + raise RuntimeError( + f"SCHED_RR: Failed to set policy for PID {pid}." + ) else: - raise ValueError("SCHED_RR: Priority must be in range 1-99.") + raise ValueError(u"SCHED_RR: Priority must be in range 1-99.") @staticmethod def set_proc_scheduling_other(node, pid): @@ -95,10 +99,11 @@ class SchedUtils(object): ssh.connect(node) if pid < 1: - raise ValueError("SCHED_OTHER: PID must be higher then 1.") + raise ValueError(u"SCHED_OTHER: PID must be higher then 1.") - cmd = "chrt -o -p 0 {1}".format(pid) - (ret, _, _) = ssh.exec_command_sudo(cmd) + cmd = f"chrt -o -p 0 {pid}" + ret, _, _ = ssh.exec_command_sudo(cmd) if ret != 0: - raise RuntimeError("SCHED_OTHER: Failed to set policy "\ - "for PID {0}.".format(pid)) + raise RuntimeError( + f"SCHED_OTHER: Failed to set policy for PID {pid}." + )