Skip to content
Snippets Groups Projects
Commit 2ecf42f1 authored by Chris Hines's avatar Chris Hines
Browse files

Merge branch 'fixProvisionSlurm' into 'master'

Fix provision slurm

See merge request !120
parents 1c47f801 03f9de20
No related branches found
No related tags found
1 merge request!120Fix provision slurm
...@@ -5,6 +5,7 @@ import os ...@@ -5,6 +5,7 @@ import os
import stat import stat
import subprocess import subprocess
class ldapSearchConfig: class ldapSearchConfig:
def __init__(self): def __init__(self):
self.ldapserver="" self.ldapserver=""
...@@ -14,12 +15,13 @@ class ldapSearchConfig: ...@@ -14,12 +15,13 @@ class ldapSearchConfig:
self.searchFilter="" self.searchFilter=""
self.cacertfile='' self.cacertfile=''
class genericUser: class genericUser:
def __init__(self): def __init__(self):
self.dn="" self.dn=""
self.cn="" self.cn=""
self.entry="" self.entry=""
self.uid="" self.uid=""
def get_users(server): def get_users(server):
...@@ -52,14 +54,24 @@ def mk_slurmaccount(acct): ...@@ -52,14 +54,24 @@ def mk_slurmaccount(acct):
else: else:
subprocess.call(["{{ slurm_dir }}/bin/sacctmgr","-i","create","account",acct]) subprocess.call(["{{ slurm_dir }}/bin/sacctmgr","-i","create","account",acct])
def mk_slurmuser(user,acct):
p=subprocess.Popen(["{{ slurm_dir }}/bin/sacctmgr","--noheader","list","Association","user=%s"%user,"format=account"],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
def mk_slurmuser_batch(userbatch,acct):
"""
Fetch a list of all accounts associated with users in userbatch, then add
those that aren't a member of acct to acct using sacctmgr.
"""
p=subprocess.Popen(["/opt/slurm-16.05.4/bin/sacctmgr","--noheader","list","Association","user=%s"%userbatch,"format=user,account"],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
(output,error)=p.communicate() (output,error)=p.communicate()
if acct in output.splitlines():
return userdict = defaultdict(list)
else: for line in output.splitlines():
subprocess.call(["{{ slurm_dir }}/bin/sacctmgr","-i","create","user",user,"account=%s"%acct,"DefaultAccount=%s"%acct]) (u,a) = line.split()
userdict[u].append(a)
newuserbatch = ",".join([ x[0] for x in userdict.items() if acct not in x[1] ])
if newuserbatch is not None:
subprocess.call(["/opt/slurm-16.05.4/bin/sacctmgr","-i","create","user",newuserbatch,"account=%s"%acct,"DefaultAccount=%s"%acct])
s=ldapSearchConfig() s=ldapSearchConfig()
...@@ -81,11 +93,11 @@ for user in users: ...@@ -81,11 +93,11 @@ for user in users:
userlist=[] userlist=[]
i=i+1 i=i+1
userlist.append(users[user].entry['uid'][0]) userlist.append(users[user].entry['uid'][0])
usergrouplist.append(",".join(userlist)) usergrouplist.append(",".join(userlist))
for usergroup in usergrouplist: for usergroup in usergrouplist:
try:
try: mk_slurmuser_batch(usergroup,"default")
mk_slurmuser(usergroup,"default") except:
except: print traceback.format_exc()
print traceback.format_exc() pass
pass
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment