Skip to content

Commit

Permalink
Fixed issue with -uf and false users. Better user checking altogether.
Browse files Browse the repository at this point in the history
Node_search now utilizes the pwd module specifically getpwnam to search /etc/passwd to see if a user exists instead of going through qconf -suserl. This way, if the user does indeed exist but hasn't submitted a job in awhile or whatever the case is, they will still be recognized as a real user instead of a nonsense of error of they may or may not exist. This also solves the issue of -uf showing that any import to it has access to the general_access and debug queues. The man page was updated to reflect this under BUGS.
  • Loading branch information
CodyKank committed Sep 15, 2017
1 parent f1aac41 commit 350ae55
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
14 changes: 7 additions & 7 deletions node_search.1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.\" Manpage for node_search.py.
.\" Contact [email protected] to correct typos or errors.
.TH man 1 "8 SEPT 2017" "1.0.4" "node_search man page"
.TH man 1 "15 SEPT 2017" "1.1.0" "node_search man page"
.SH NAME
node_search \- get node, user, or host-group information from Univa Grid Engine
.SH SYNOPSIS
Expand Down Expand Up @@ -104,10 +104,10 @@ specifed host-group, then the output will show all of the machines/nodes that be
or host-group. Each one of those nodes will also show its core usage (used vs total). This will be
the same behavior that occurs if \fB--details\fR is used to modify \fB-a \fR or\fB --all\fR. If \fB--details
\fRis modifying a user, then all of the nodes the specified user is running will be displayed along with all
of the processes that user owns and the respective memory usage, CPU%, and time. This is useful for when a job submitted
through UGE spawns or starts multiple processes which are not necessarily tracked by UGE. If the user has any
pending jobs then those will be shown as well. If \fB--details \fRis modifying the \fB-uf \fRoption, then it will
display all of the nodes which belong to the host-groups the specified user has access to.
of the processes that user owns and the respective memory usage, CPU%, and run time of each process. This is
useful for when a job submitted through UGE spawns or starts multiple processes which are not necessarily tracked
by UGE. If the user has any pending jobs then those will be shown as well. If \fB--details \fRis modifying the
\fB-uf \fRoption, then it will display all of the nodes which belong to the host-groups the specified user has access to.

." END OPTIONS !!

Expand Down Expand Up @@ -136,11 +136,11 @@ something along the lines of less/more. e.g. node_search.py -uf JohnDoe33 --deta
.TP
\fBnode_search.py -u JohnDoe
\fRDisplay the user JohnDoe and their jobs along with core usage and the nodes the jobs are running
on.
on. Will display total memory usage per node as used by user JohnDoe.


.SH BUGS
\fRnode_search.py -uf fake_user \- will act as if it is a real user.
\fRNo known bugs at the current moment in time.
Report any new findings to [email protected].
.SH AUTHOR
\fRCody Kankel ([email protected])
14 changes: 11 additions & 3 deletions node_search.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

from pwd import getpwnam
import sys, subprocess, urllib.request

"""Script to get and report information on nodes withtin the Sun Grid Engine for the CRC. It uses
Expand Down Expand Up @@ -377,6 +378,12 @@ def find_host_groups(user_name, detail_switch):
and method will send needed info to the respective printing functions depending if it is
a detailed print or not. Program exits after executing this method."""

try:
user_pwd = getpwnam(user_name)
except KeyError:
print("Error: User {0} is not recognized.".format(user_name))
sys.exit(25)

all_user_lists = subprocess.getoutput("qconf -sul").split('\n')

user_list = []
Expand Down Expand Up @@ -664,9 +671,10 @@ def process_user(user_name):
"""Function to process the username given after -u option. Will find information pertaining to the specified
user and send them to the printing function."""

user_list = subprocess.getoutput("qconf -suserl")
if str(user_name) not in user_list:
print('Error: User, ' + user_name + ' is currently not logged on or does not exist.')
try:
user_pwd = getpwnam(user_name)
except KeyError:
print('Error: User {0} is not recognized.'.format(user_name))
sys.exit(25)

qstat = subprocess.getoutput("qstat -f").split('-'.center(81, '-')) #81 -'s
Expand Down
2 changes: 2 additions & 0 deletions node_search.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# without having to 'module load python/3.x.x' Then, it is running the node_search.py script.
# Please read that script or view the man page for more information on what that script does.

#ckankel --> This is who to bug about this

# NOTE: These requirements will change when there is a new version of Python3 installed. To update
# simply look at what is loaded in your env when you have the latest python3 module loaded for the
# following variables:
Expand Down

0 comments on commit 350ae55

Please sign in to comment.