Skip to content
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

Limits yaml schema #39

Open
wants to merge 5 commits into
base: 4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions roles/slurm/files/test_update_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import pytest
import requests_mock
import yaml

import update_config


@pytest.mark.parametrize(
"data",
[
("""
VM.Standard2.1:
1: 1
2: 1
3: 1
VM.Standard2.2:
1: 1
2: 1
3: 1
"""),
]
)
def test_get_limits(mocker, data):
mocker.patch("update_config.load_yaml", return_value=yaml.safe_load(data))
assert isinstance(update_config.get_limits(), dict)


@pytest.mark.parametrize(
"data,error",
[
("""
VM.Standard2.1:
1: 1
2: 1
3: 1
VM.Standard2.2:
1: 1
2: 1
3: 1
""",
SyntaxError),
]
)
def test_get_limits_errors(mocker, data, error):
mocker.patch("update_config.load_yaml", return_value=yaml.safe_load(data))
with pytest.raises(error):
update_config.get_limits()
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,19 @@ def get_limits() -> Dict[str, Dict[str, str]]:
Until OCI has an API to fetch service limits, we have to hard-code
them in a file.
"""
return load_yaml("limits.yaml")
limits = load_yaml("limits.yaml")
for mappings in limits.values():
if not isinstance(mappings, dict):
raise SyntaxError
for ad, count in mappings.items():
if not isinstance(ad, int):
raise SyntaxError
if not isinstance(count, int):
raise SyntaxError
for shape in limits:
if re.match(r"\w{2}\.", shape) is None:
raise ValueError
return limits


def get_shapes() -> Dict[str, Dict[str, str]]:
Expand Down Expand Up @@ -73,18 +85,24 @@ def get_node_configs(limits, shapes, mgmt_info):
yield create_slurmconf_line(i, shape_info, shape, ad)


# TODO Make sure that any nodes which are no longer managed due to service limit reductions are terminated.
if __name__ == "__main__":
# TODO Make sure that any nodes which are no longer managed due to service limit reductions are terminated.

slurm_conf_filename = "/mnt/shared/etc/slurm/slurm.conf"
slurm_conf_filename = "/mnt/shared/etc/slurm/slurm.conf"

node_config = "\n".join(get_node_configs(get_limits(), get_shapes(), get_mgmt_info()))
try:
limits = get_limits()
except SyntaxError:
print("ERROR: Syntax error in `limits.yaml`.")
exit(1)
node_config = "\n".join(get_node_configs(limits, get_shapes(), get_mgmt_info()))

chop = re.compile('(?<=# STARTNODES\n)(.*?)(?=\n?# ENDNODES)', re.DOTALL)
chop = re.compile('(?<=# STARTNODES\n)(.*?)(?=\n?# ENDNODES)', re.DOTALL)

with open(slurm_conf_filename) as f:
all_config = f.read()
with open(slurm_conf_filename) as f:
all_config = f.read()

new_config = chop.sub('{}'.format(node_config), all_config)
new_config = chop.sub('{}'.format(node_config), all_config)

with open(slurm_conf_filename, "w") as f:
f.write(new_config)
with open(slurm_conf_filename, "w") as f:
f.write(new_config)
6 changes: 3 additions & 3 deletions roles/slurm/tasks/elastic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
dest: /usr/local/bin/stopnode
mode: 0755

- name: configure update_config script
template:
src: update_config.j2
- name: install update_config script
copy:
src: update_config.py
dest: /usr/local/bin/update_config
mode: 0755

Expand Down