Skip to content

Commit 4b45244

Browse files
committed
Support hosts in multiple partitions when templating gres.conf
1 parent 65957bb commit 4b45244

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ openhpc_retry_delay: 10
1313
openhpc_job_maxtime: '60-0' # quote this to avoid ansible converting some formats to seconds, which is interpreted as minutes by Slurm
1414
openhpc_config: "{{ openhpc_extra_config | default({}) }}"
1515
openhpc_gres_template: gres.conf.j2
16+
openhpc_gres_autodetect: 'disabled'
1617
openhpc_slurm_configless: "{{ 'enable_configless' in openhpc_config.get('SlurmctldParameters', []) }}"
1718

1819
openhpc_state_save_location: /var/spool/slurm

filter_plugins/slurm_conf.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# NB: To test this from the repo root run:
1616
# ansible-playbook -i tests/inventory -i tests/inventory-mock-groups tests/filter.yml
1717

18+
from collections import defaultdict
1819
from ansible import errors
1920
import jinja2
2021
import re
@@ -65,6 +66,16 @@ def hostlist_expression(hosts):
6566
unmatchable.append(v)
6667
return ['{}[{}]'.format(k, _group_numbers(v)) for k, v in results.items()] + unmatchable
6768

69+
@jinja2.pass_context
70+
def group_by_gres_autodetect(context, hosts):
71+
""" Groups a list of hosts by the gres_autodetect variable
72+
"""
73+
result = defaultdict(list)
74+
for host in hosts:
75+
gres_autodetect = _get_hostvar(context, 'gres_autodetect', inventory_hostname=host)
76+
result[gres_autodetect].append(host)
77+
return result
78+
6879
def _group_numbers(numbers):
6980
units = []
7081
ints = [int(n) for n in numbers]
@@ -133,4 +144,5 @@ def filters(self):
133144
'error': error,
134145
'dict2parameters': dict2parameters,
135146
'config2dict': config2dict,
147+
'group_by_gres_autodetect': group_by_gres_autodetect,
136148
}

templates/gres.conf.j2

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
AutoDetect=off
22
{% for part in openhpc_slurm_partitions %}
33
{% set nodelist = [] %}
4+
{% set donehosts = set() %}
45
{% for group in part.get('groups', [part]) %}
5-
{% set group_name = group.cluster_name|default(openhpc_cluster_name) ~ '_' ~ group.name %}
6-
{% set inventory_group_hosts = groups.get(group_name, []) %}
7-
{% if 'gres_autodetect' in group %}
8-
{% for hostlist in (inventory_group_hosts | hostlist_expression) %}
9-
NodeName={{ hostlist }} AutoDetect={{ group.gres_autodetect }}
10-
{% endfor %}
11-
{% elif 'gres' in group %}
12-
{% for gres in group.gres %}
13-
{% set gres_name, gres_type, _ = gres.conf.split(':') %}
14-
{% for hostlist in (inventory_group_hosts | hostlist_expression) %}
6+
{% if 'gres' in group %}
7+
{% set group_name = group.cluster_name|default(openhpc_cluster_name) ~ '_' ~ group.name %}
8+
{% set inventory_group_hosts = groups.get(group_name, []) %}
9+
{% set autodetect_mechanisms = inventory_group_hosts | group_by_gres_autodetect %}
10+
{% for mechanism, _mechanism_hosts in autodetect_mechanisms.items() %}
11+
{% set mechanism_hosts = _mechanism_hosts - donehosts %}
12+
{% if mechanism != 'disabled' %}
13+
{% for hostlist in (mechanism_hosts | hostlist_expression) %}
14+
NodeName={{ hostlist }} AutoDetect={{ mechanism }}
15+
16+
{% endfor %}
17+
{% else %}
18+
{% for gres in group.gres %}
19+
{% set gres_name, gres_type, _ = gres.conf.split(':') %}
20+
{% for hostlist in (mechanism_hosts | hostlist_expression) %}
1521
NodeName={{ hostlist }} Name={{ gres_name }} Type={{ gres_type }} File={{ gres.file }}
1622

17-
{% endfor %}
23+
{% endfor %}
24+
{% endfor %}
25+
{% endif %}
26+
{% set _ = donehosts.update(mechanism_hosts) %}
1827
{% endfor %}
1928
{% endif %}
2029
{% endfor %}

0 commit comments

Comments
 (0)