Bug 1035795

Summary: tuna throwing valueerror when not specified priority
Product: Red Hat Enterprise Linux 6 Reporter: Jiri Kastner <jkastner>
Component: tunaAssignee: John Kacur <jkacur>
Status: CLOSED ERRATA QA Contact: Jiri Kastner <jkastner>
Severity: medium Docs Contact:
Priority: medium    
Version: 6.4CC: bhu, jkastner, lgoncalv, poros, williams
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 1035793 Environment:
Last Closed: 2014-10-14 04:26:21 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1035793, 1035796    
Bug Blocks: 1023565    
Attachments:
Description Flags
Fix none

Description Jiri Kastner 2013-11-28 13:46:05 UTC
+++ This bug was initially created as a clone of Bug #1035793 +++

Description of problem:
when after scheduler is not specified priority 'tuna -t $PID -p OTHER' (it doesn't matter if RR or FIFO or OTHER), tuna ends with traceback.

Version-Release number of selected component (if applicable):
every

How reproducible:
alway

Steps to Reproduce:
1. install tuna
2. run tuna -t PID_OF_SOME_PROCESS -p OTHER
3. check output

Actual results:

[root@localhost ~]# tuna -t 3199 -p OTHER
Traceback (most recent call last):
  File "/usr/bin/tuna", line 598, in <module>
    main()
  File "/usr/bin/tuna", line 482, in main
    tuna.threads_set_priority(thread_list, a, affect_children)
  File "/usr/lib/python2.6/site-packages/tuna/tuna.py", line 479, in threads_set_priority
    rtprio = int(parms[0])
ValueError: invalid literal for int() with base 10: 'OTHER'


Expected results:
instead of traceback some warning and/or used some default value.

Additional info:

Comment 2 Petr Oros 2013-12-02 08:52:09 UTC
Created attachment 831472 [details]
Fix

Comment 3 John Kacur 2014-03-28 00:38:44 UTC
Fixed in 0.10.4-5

Comment 9 Clark Williams 2014-07-29 18:42:28 UTC
What do you guys think about this patch? Is this what we want for parameter verification?


diff --git a/tuna/tuna.py b/tuna/tuna.py
index 507269a..6fdeb9e 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -471,15 +471,18 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
 
 def threads_set_priority(tids, parm, affect_children = False):
        parms = parm.split(":")
+        rtprio = -1
        policy = None
-       if len(parms) != 1:
+        if parms[0].upper() in ["OTHER", "BATCH", "IDLE", "FIFO", "RR", "IDLE", "RESET_ON_FORK"]:
                policy = schedutils.schedfromstr("SCHED_%s" % parms[0].upper())
-               rtprio = int(parms[1])
-       elif parms[0].isdigit():
-               rtprio = int(parms[0])
-       else:
-               print "tuna: " + _("\"%s\" is unsupported priority value!") % parms[0]
-               return
+        if len(parms) > 1:
+                if parms[1].isdigit():
+                        rtprio = int(parms[1])
+                else:
+                        print "tuna: " + _("\"%s\" is unsupported priority value!") % parms[1]
+                        return
+        else:
+                rtprio = 0
 
        for tid in tids:
                try:

Comment 10 Clark Williams 2014-07-29 21:20:51 UTC
Here's an updated patch that uses a try/except (to be a bit more python-ish):

diff --git a/tuna/tuna.py b/tuna/tuna.py
index 507269a..7e71348 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -471,15 +471,16 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning = None,
 
 def threads_set_priority(tids, parm, affect_children = False):
        parms = parm.split(":")
+        rtprio = 0
        policy = None
-       if len(parms) != 1:
-               policy = schedutils.schedfromstr("SCHED_%s" % parms[0].upper())
-               rtprio = int(parms[1])
-       elif parms[0].isdigit():
-               rtprio = int(parms[0])
-       else:
-               print "tuna: " + _("\"%s\" is unsupported priority value!") % parms[0]
-               return
+        if parms[0].upper() in ["OTHER", "BATCH", "IDLE", "FIFO", "RR", "IDLE", "RESET_ON_FORK"]:
+                policy = schedutils.schedfromstr("SCHED_%s" % parms[0].upper())
+        if len(parms) > 1:
+                try:
+                        rtprio = int(parms[1])
+                except ValueError, e:
+                        print "tuna: " + _("\"%s\" is unsupported priority value!") % parms[1]
+                        raise e
 
        for tid in tids:
                try:

Comment 16 John Kacur 2014-08-25 22:56:40 UTC
In addition to the fix here which I provided in tuna-0.10.4-7
we need to upgrade procfs to python-linux-procfs-0.4.6-1

Then you get the following result which I believe is acceptable

tuna -t $$ -p FIFO
tuna: [Errno 22] Invalid argument

I created https://bugzilla.redhat.com/show_bug.cgi?id=1035795
to handle this

Comment 20 errata-xmlrpc 2014-10-14 04:26:21 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHBA-2014-1404.html