I have a Python Hook to change the assigned/default que for a user testuser1 to another Que testq if the user is found in a text file. But it is not working for me. the hook is not called at all as per the server logs. Can anyone help me to identify the problem?
$cat set_queue_based_on_user.PY
#!/usr/bin/env python3
import sys
import os
sys.path.append(f’/opt/pbs/lib/python/‘)
sys.path.append(f’/opt/pbs/lib/python/altair’)
import pbs
EVENT = pbs.event()
def set_queue_based_on_user():
try:
# Get the job object
job = EVENT.job
# Read the reference file
queue_map = {}
ref_file = "/myhpc/pbs/server_priv/users/testq_user_list.txt"
with open(ref_file, "r") as f:
for line in f:
if line.strip() and not line.startswith("#"):
user, queue = line.split()
queue_map[user.strip()] = queue.strip()
# Get the user submitting the job
job_user = job.euser # Effective user submitting the job
# Assign the queue based on the user
if job_user in queue_map:
job.queue = queue_map[job_user]
elif "default" in queue_map:
job.queue = queue_map["default"]
else:
e.reject("User not found in the queue reference file.")
except Exception as ex:
pbs.logmsg(pbs.LOG_DEBUG, f"Hook error: {str(ex)}")
e.reject(f"Hook error: {str(ex)}")
if EVENT.type == ‘queuejob’:
set_queue_based_on_user()
EVENT.accept()
#cat /etc/pbs/server_priv/users/testq_user_list.txt
testuser1 testq
default workq
#qmgr -c “list hook set_queue_based_on_user”
Hook set_queue_based_on_user
type = site
enabled = true
event = queuejob
user = pbsadmin
alarm = 30
order = 1
debug = false
fail_action = none