-
Notifications
You must be signed in to change notification settings - Fork 125
issues 153 and 150 #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issues 153 and 150 #156
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import datetime | ||
| import pwd | ||
| import subprocess | ||
|
|
||
| from nose.tools import assert_equals | ||
|
|
||
| import pyslurm | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would reorder these as Python builtin modules, 3rd party modules and custom modules, all separated by a space. |
||
|
|
||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be two spaces between methods. Same applies below... |
||
| def njobs_sacct_jobs(start, end, username=None): | ||
| """ | ||
| Count the number of jobs reported by sacct | ||
| For comparison with the reults of slurmdb_jobs.get | ||
| """ | ||
| sacctcmd = ['sacct', '-S', start, '-E', end, '-n', '-X'] | ||
| if username is not None: | ||
| sacctcmd.extend(['-u', username]) | ||
| else: | ||
| sacctcmd.append('-a') | ||
| sacct = subprocess.Popen(sacctcmd, | ||
| stdout=subprocess.PIPE, | ||
| stderr=None).communicate() | ||
| return len(sacct[0].splitlines()) | ||
|
|
||
|
|
||
| def njobs_slurmdb_jobs_get(start, end, uid=None): | ||
| """ | ||
| Count the number of jobs reported by slurmdb | ||
| """ | ||
| if uid is None: | ||
| jobs = pyslurm.slurmdb_jobs().get(starttime=start.encode('utf-8'), | ||
| endtime=end.encode('utf-8')) | ||
| else: | ||
| jobs = pyslurm.slurmdb_jobs().get(starttime=start.encode('utf-8'), | ||
| endtime=end.encode('utf-8'), | ||
| userids=[uid]) | ||
| return len(jobs) | ||
|
|
||
|
|
||
| def get_user(): | ||
| """ | ||
| Return a list of usernames and their uid numbers | ||
| """ | ||
| users = subprocess.Popen(['squeue', '-O', 'username', '-h'], | ||
| stdout=subprocess.PIPE, | ||
| stderr=None).communicate() | ||
| for username in users[0].splitlines(): | ||
| print(username.decode()) | ||
| uid = pwd.getpwnam("{}".format(username.strip().decode())) | ||
| yield username.strip().decode(), uid.pw_uid | ||
|
|
||
|
|
||
| def test_slurmdb_jobs_get(): | ||
| """ | ||
| Slurmdb: Compare sacct and slurmdb_jobs.get() for all users | ||
| """ | ||
| starttime = (datetime.datetime.now() - | ||
| datetime.timedelta(days=2)).strftime("%Y-%m-%dT00:00:00") | ||
| endtime = (datetime.datetime.now() - | ||
| datetime.timedelta(days=1)).strftime("%Y-%m-%dT00:00:00") | ||
| njobs_pyslurm = njobs_slurmdb_jobs_get(starttime, endtime) | ||
| njobs_sacct = njobs_sacct_jobs(starttime, endtime) | ||
| assert_equals(njobs_pyslurm, njobs_sacct) | ||
|
|
||
|
|
||
| def test_slurmdb_jobs_get_byuser(): | ||
| """ | ||
| Slurmdb: Compare sacct and slurmdb_jobs.get() for individual users | ||
| """ | ||
|
|
||
| userlist = list(get_user()) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here.... Could you add a doctstring here similar to the other test methods in this suite? |
||
| for user in userlist[:10]: | ||
| starttime = (datetime.datetime.now() - | ||
| datetime.timedelta(days=2)).strftime("%Y-%m-%dT00:00:00") | ||
| endtime = (datetime.datetime.now() - | ||
| datetime.timedelta(days=1)).strftime("%Y-%m-%dT00:00:00") | ||
| njobs_pyslurm = njobs_slurmdb_jobs_get(starttime, | ||
| endtime, | ||
| int(user[1])) | ||
| njobs_sacct = njobs_sacct_jobs(starttime, endtime, username=user[0]) | ||
| assert_equals(njobs_pyslurm, njobs_sacct) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏