Skip to content
Snippets Groups Projects
Commit 89125730 authored by Andreas Hamacher's avatar Andreas Hamacher
Browse files

avoid errors with sacctmgr

parent 3946e66a
No related branches found
No related tags found
1 merge request!297Cicd merge back
#!/bin/bash
REBOOT_TIME=90
NODETYPES=${@}
# make sure you define variable STACKNAME in current environment
if [[ -z $STACKNAME ]]; then
echo "please define STACKNAME variable"
exit 1
fi
# prepend CICD to stack name
if [[ "$STACKNAME" == "CICD"* ]]; then
echo "CICD found in stackname. doing nothing"
else
STACKNAME="CICD"$STACKNAME
fi
function check_stack_exists {
if openstack stack list | grep -w $STACKNAME;
then
echo "stack found";
else
echo "stack not found";
return 1
fi
}
if ! check_stack_exists
then
exit 0
fi
# return and dictionary in json format, which map server name to ansible_host_groups. There will be IndexError if the servers, which names are prefixed by STACKNAME, don't have ansible_host_groups property
host_group_mapping=$(openstack server list --long -f json | python3 -c "import json,sys,re;ivt=json.load(sys.stdin);json.dump({i['Name']: re.search('ansible_host_groups\=\'\[(.+)\]\'', i['Properties']).groups()[0].replace('\"', '').split() for i in ivt if re.match('$STACKNAME',i['Name'])}, fp=sys.stdout)")
# all available ansible_host_groups
available_groups=$(echo $host_group_mapping | python3 -c "import json,sys;mapping=json.load(sys.stdin);output=[];[output.extend(v) for v in mapping.values()];print(output)" | tr -d "[',]")
# if the first input parameter is all then rebuild all groups
if [[ "$1" == "all" ]]; then
NODETYPES=$available_groups
fi
echo "going to update group $NODETYPES"
server_list=$(echo $host_group_mapping | python3 -c "import json,sys;mapping=json.load(sys.stdin);avail_groups='$available_groups'.split();print([k for k in mapping.keys() if len(set(mapping[k]).intersection(set(avail_groups))) > 0])" | tr -d "[,]'" | xargs -n1 | sort -u)
rebuild_func(){
echo "rebuilding server $1"
openstack server rebuild --wait $1
}
# for eaech line in data
for server in $server_list
do
rebuild_func $server & # run parallel in background
done
wait # wait for all servers to be rebuild
# add an extra time for reboot
echo "waiting for reboot"
sleep $REBOOT_TIME
echo "All done"
......@@ -64,9 +64,8 @@
- name: "create cluster in slurm db"
shell: "{{slurm_dir}}/bin/sacctmgr -i create cluster {{ clustername }}"
shell: sacctmgr show assoc format=Cluster -Pn | grep -q {{ clustername }} && {{ slurm_dir }}/bin/sacctmgr -i create cluster {{ clustername }}
become: true
ignore_errors: true
- name: start slurmctl
service: name=slurmctld state=restarted enabled=no
......
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