# PTL testlib to alter a job

**URL:** <https://community.openpbs.org/t/ptl-testlib-to-alter-a-job/1237>\
**Category:** Developers\
**Created:** [October 10, 2018, 2:45pm UTC](https://community.openpbs.org/t/ptl-testlib-to-alter-a-job/1237 "2018-10-10T14:45:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![steveheistand](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@steveheistand](https://community.openpbs.org/u/steveheistand)\
**Post date:** [October 10, 2018, 2:45pm UTC](https://community.openpbs.org/t/ptl-testlib-to-alter-a-job/1237/1 "2018-10-10T14:45:58Z")

</div>

I would like to tweak some things on a job outside of a hook so I thought I would  
try using the ptl\_testlib python package. However its crashing when the underlying library is calling qalter:

ptl\_testlib.Server(pbs\_server\_name).alterjob(jobid=jid, attrib=new\_att)

gives:

PbsAlterError Traceback (most recent call last)  
\<ipython-input-61-48f975436349\> in \<module\>()  
----\> 1 ptl\_testlib.Server(pbs\_server\_name).alterjob(jobid=jid, attrib=new\_att)

/opt/pbs/python/lib/python2.7/site-packages/ptl/lib/pbs\_testlib.pyc in alterjob(self, jobid, attrib, extend, runas, logerr)  
6940 if rc != 0:  
6941 raise PbsAlterError(rc=rc, rv=False, msg=self.geterrmsg(),  
-\> 6942 post=self.\_disconnect, conn=c)  
6943  
6944 if c:

PbsAlterError: rc=2, rv=False, msg=["/opt/pbs/bin/qalter: invalid option – ‘v’", ‘usage: qalter [-a date\_time] [-A account\_string] [-c interval] [-e path]’, ‘\t[-h hold\_list] [-j y|n] [-k keep] [-J X-Y[:Z]] [-l resource\_list]’, ‘\t[-m mail\_options] [-M user\_list] [-N jobname] [-o path] [-p priority]’, ‘\t[-R o|e|oe] [-r y|n] [-S path] [-u user\_list] [-W dependency\_list]’, ‘\t[-P project\_name] job\_identifier…’, ’ qalter --version’]

This is using the binary rpms of 18.2 and the ptl tree from github installed as normal if that affects things any.  
The qstat from github doesnt have a ‘v’ option either so at least that matches.

thoughts/comments/concerns/etc

or better ways to tweaking something on a job outside of a hook.  
In this case I was just adding a variable onto the Variable\_List attribute.  
But I could create a new job resource and tweak that as well for what I need.

thanks

steve

---

<div class="post-metadata">

**Author:** ![agrawalravi90](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@agrawalravi90](https://community.openpbs.org/u/agrawalravi90)\
**Post date:** [October 11, 2018, 4:48am UTC](https://community.openpbs.org/t/ptl-testlib-to-alter-a-job/1237/2 "2018-10-11T04:48:36Z")

</div>

Hi Steve, can you please post the complete log? PTL logs the exact command that it runs, so you should have seen the qalter command as PTL ran it in the logs. That will give us a better idea about what it’s doing and where the ‘v’ is coming from.

---

<div class="post-metadata">

**Author:** ![steveheistand](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@steveheistand](https://community.openpbs.org/u/steveheistand)\
**Post date:** [October 11, 2018, 1:05pm UTC](https://community.openpbs.org/t/ptl-testlib-to-alter-a-job/1237/3 "2018-10-11T13:05:50Z")

</div>

Logged where? There isnt anything in the server\_logs files.  
thanks

steve

---

<div class="post-metadata">

**Author:** ![agrawalravi90](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@agrawalravi90](https://community.openpbs.org/u/agrawalravi90)\
**Post date:** [October 11, 2018, 2:19pm UTC](https://community.openpbs.org/t/ptl-testlib-to-alter-a-job/1237/4 "2018-10-11T14:19:02Z")

</div>

sorry, can you add the following to the setup section of your script and run your script again:

from ptl.utils.pbs\_cliutils import CliUtils  
fmt = ‘%(asctime)-15s %(levelname)-8s %(message)s’  
log\_level = “INFOCLI2”  
level\_int = CliUtils.get\_logging\_level(log\_level)  
stream\_hdlr = logging.StreamHandler()  
stream\_hdlr.setLevel(level\_int)  
stream\_hdlr.setFormatter(logging.Formatter(fmt))  
ptl\_logger = logging.getLogger(‘ptl’)  
ptl\_logger.addHandler(stream\_hdlr)  
ptl\_logger.setLevel(level\_int)

it will make PTL log more information than just the exception you saw.

---

<div class="post-metadata">

**Author:** ![steveheistand](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@steveheistand](https://community.openpbs.org/u/steveheistand)\
**Post date:** [October 11, 2018, 2:50pm UTC](https://community.openpbs.org/t/ptl-testlib-to-alter-a-job/1237/5 "2018-10-11T14:50:09Z")

</div>

output as follows:

2018-10-11 07:40:15,884 INFOCLI hostname: /opt/pbs/bin/qstat -Bf pbs\_server\_name  
2018-10-11 07:40:15,895 INFO server pbs\_server\_name: version 18.1.0  
2018-10-11 07:40:15,895 INFO alter on pbs\_server\_name: jobid {‘Variable\_List’: ‘stuff’}  
2018-10-11 07:40:15,895 INFOCLI hostname: /opt/pbs/bin/qalter -v stuff jobid  
2018-10-11 07:40:15,898 ERROR err: ["/opt/pbs/bin/qalter: invalid option – ‘v’", ‘usage: qalter [-a date\_time] [-A account\_string] [-c interval] [-e path]’, ‘\t[-h hold\_list] [-j y|n] [-k keep] [-J X-Y[:Z]] [-l resource\_list]’, ‘\t[-m mail\_options] [-M user\_list] [-N jobname] [-o path] [-p priority]’, ‘\t[-R o|e|oe] [-r y|n] [-S path] [-u user\_list] [-W dependency\_list]’, ‘\t[-P project\_name] job\_identifier…’, ’ qalter --version’]  
Traceback (most recent call last):  
File “./test4.py”, line 18, in   
ptl\_testlib.Server(pbs\_server\_name).alterjob(jobid=jid, attrib=new\_att)  
File “/opt/pbs/python/lib/python2.7/site-packages/ptl/lib/pbs\_testlib.py”, line 6942, in alterjob  
post=self.\_disconnect, conn=c)  
ptl.lib.pbs\_testlib.PbsAlterError: rc=2, rv=False, msg=["/opt/pbs/bin/qalter: invalid option – ‘v’", ‘usage: qalter [-a date\_time] [-A account\_string] [-c interval] [-e path]’, ‘\t[-h hold\_list] [-j y|n] [-k keep] [-J X-Y[:Z]] [-l resource\_list]’, ‘\t[-m mail\_options] [-M user\_list] [-N jobname] [-o path] [-p priority]’, ‘\t[-R o|e|oe] [-r y|n] [-S path] [-u user\_list] [-W dependency\_list]’, ‘\t[-P project\_name] job\_identifier…’, ’ qalter --version’]

prompt: qalter --version  
pbs\_version = 18.2.1.20180622093321

Note that the qalter version is different then the version ptl\_testlib returns in the logging output.  
not sure if this will matter but thought I would mention it.

thanks

steve

---

<div class="post-metadata">

**Author:** ![agrawalravi90](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@agrawalravi90](https://community.openpbs.org/u/agrawalravi90)\
**Post date:** [October 11, 2018, 3:21pm UTC](https://community.openpbs.org/t/ptl-testlib-to-alter-a-job/1237/6 "2018-10-11T15:21:32Z")

</div>

Thanks for providing more details. Unfortunately, it sounds like you’ve come across a bug in PTL. PTL needs to use the -W option while modifying Variable\_List, it’s trying to instead use qsub’s -v option for Variable\_List. I was able to successfully modify Resource\_List.ncpus, but Variable\_List error’d out for me in the same way.

---

<div class="post-metadata">

**Author:** ![steveheistand](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@steveheistand](https://community.openpbs.org/u/steveheistand)\
**Post date:** [October 11, 2018, 3:32pm UTC](https://community.openpbs.org/t/ptl-testlib-to-alter-a-job/1237/7 "2018-10-11T15:32:08Z")

</div>

At least Im not going crazy or writing bad testlib code…  
btw Im happy to do this the shell way with actual qalter commands, but everything Ive  
seen regarding the -W option to qalter deals with job dependencies. If there is a way to tweak  
job info with it Im all for it. How however I dont know.

thanks  
steve

---

<div class="post-metadata">

**Author:** ![agrawalravi90](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@agrawalravi90](https://community.openpbs.org/u/agrawalravi90)\
**Post date:** [October 11, 2018, 4:22pm UTC](https://community.openpbs.org/t/ptl-testlib-to-alter-a-job/1237/8 "2018-10-11T16:22:21Z")

</div>

I simply did the following to modify Variable\_List via qalter:  
qalter -W Variable\_List=blah 31.pbspro

[ravi@pbspro ~]$ qstat -f | grep Variable\_List  
Variable\_List = blah
