Skip to content

Commit c7e408a

Browse files
committed
first commit
0 parents  commit c7e408a

File tree

15 files changed

+1334
-0
lines changed

15 files changed

+1334
-0
lines changed

.github/workflows/test.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: integration-test
2+
3+
on:
4+
push:
5+
branches: [ main, dev ]
6+
pull_request:
7+
branches: [ main ]
8+
jobs:
9+
integration-test:
10+
runs-on: ubuntu-latest
11+
services:
12+
docker:
13+
image: docker:24.0.5
14+
options: --privileged
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Set up Docker Compose
20+
run: |
21+
sudo apt-get update
22+
sudo apt-get install -y docker-compose
23+
24+
- name: Build and start containers
25+
run: docker-compose up -d --build
26+
27+
- name: Wait for slurmctl to be ready
28+
run: |
29+
for i in {1..30}; do
30+
if docker-compose exec slurmctl curl -sf http://localhost:6820/slurm/v0.0.36/clusters; then
31+
break
32+
fi
33+
sleep 5
34+
done
35+
- name: Install package
36+
run: pip install
37+
38+
- name: Run integration tests
39+
run: docker-compose run --rm app pytest tests/integration

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Slurm integration for ColdFront
2+
3+
ColdFront django plugin providing Slurm REST API integration for ColdFront.
4+
5+
A command line tool is also provided with this app that allows an administrator
6+
to check the consistency between ColdFront and Slurm and optionally remove any
7+
associations that should not be in Slurm according to ColdFront.
8+
9+
## Design
10+
11+
Resources in ColdFront map to Clusters (or partitions within a cluster) in
12+
Slurm. The name of the Slurm cluster is taken from a resource attribute in
13+
ColdFront named "slurm\_cluster". You can optionally provide Slurm
14+
specifications for a cluster using a resource attribute named "slurm\_specs".
15+
The value of this attribute must conform to the Slurm specification format and
16+
are colon separated.
17+
18+
Allocations in ColdFront map to Accounts in Slurm. The name of the Slurm
19+
account is taken from a allocation attribute in ColdFront named
20+
"slurm\_account\_name" . You can optionally provide Slurm specifications for
21+
the account using a allocation attribute named "slurm\_specs". The value of
22+
this attribute must conform to the Slurm specification format and are colon
23+
separated.
24+
25+
Allocation users in ColdFront map to Users in Slurm. You can optionally
26+
provide Slurm specifications for each user in a allocation using a
27+
allocation attribute named "slurm\_user\_specs". The value of this attribute
28+
must conform to the Slurm specification format and are colon separated. Setting
29+
specifications on an individual user basis is not currently supported.
30+
31+
## Usage
32+
33+
To enable this plugin set the following environment variables:
34+
35+
```
36+
PLUGIN_SLURMREST=True
37+
SLURMREST_CLUSTERS=production # add the names of the resources that correspond to the Slurm Clusters to use, separated by commas
38+
# For each cluster listed in slurm_clusters:
39+
# Set SLURM_{clustername}_ENDPOINT to the IP or URL, e.g.:
40+
SLURM_PRODUCTION_ENDPOINT=http://production_cluster_url.com
41+
# Set SLURM_{clustername}_TOKEN to the JWT token used for authentication
42+
SLURM_PRODUCTION_TOKEN=$SLURMTEST_TOKEN
43+
```
44+
45+
46+
## Special cases
47+
48+
Resources in ColdFront can optionally be organized into parent/child
49+
relationships. This is useful in the context of Slurm for example if you have a
50+
single Slurm controller with multiple partitions. Each partition represents a
51+
separate resource in ColdFront that users can subscribe to. In this case you
52+
would create a parent resource that represents your Slurm cluster (or
53+
controller) with a resource type of "Cluster". Each Slurm partition would be a
54+
separate resource in ColdFront with a resource type of "Partition" and have
55+
their parent resource set to the Slurm cluster. Users wouldn't subscribe to the
56+
parent Slurm cluster resource but only subscribe to the partition resources. Here
57+
you would only set the "slurm\_cluster" resource attribute on the Slurm cluster
58+
resource and not on the partitions. Also, "slurm\_specs" resource attribute on
59+
partitions are merged with the allocation "slurm\_specs" and set on the Slurm
60+
account association instead of the cluster.
61+
62+
## CLI Usage
63+
64+
To check the consistency between ColdFront and Slurm run the following command:
65+
66+
```
67+
$ sacctmgr dump file=/output_dir/tux.cfg
68+
$ coldfront slurm_check -i /output_dir/tux.cfg
69+
```
70+
71+
This will compare active allocations in ColdFront to Slurm accounts and
72+
associations. Any differences in the Slurm association and ColdFront user lists
73+
will be reported. You can optionally provide the '--slurm-sync' flag to
74+
automatically add and remove Slurm associations to match the allocationuser lists
75+
in ColdFront, or the '--coldfront-sync' flag to automatically match the
76+
allocationuser lists to Slurm's associations.

docker-compose.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
services:
2+
slurmctl:
3+
image: ghcr.io/fasrc/slurmrest-container
4+
hostname: slurmctl
5+
container_name: slurmctl
6+
volumes:
7+
- share:/share
8+
cap_add:
9+
- sys_admin
10+
tty: true # -t keep bash interactive
11+
stdin_open: true # -i keep STDIN open
12+
networks:
13+
- compute
14+
coldfront:
15+
image: ghcr.io/fasrc/coldfront-builder
16+
command: ["serve"]
17+
hostname: coldfront
18+
container_name: coldfront-test
19+
volumes:
20+
- ./coldfront/slurm_rest_coldfront:/opt/slurmrest
21+
- share:/share
22+
expose:
23+
- "22"
24+
networks:
25+
- compute
26+
mysql:
27+
image: mariadb:10.4
28+
hostname: mysql
29+
container_name: mysql
30+
environment:
31+
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
32+
volumes:
33+
- ./database:/docker-entrypoint-initdb.d
34+
- ./database:/etc/mysql/conf.d
35+
- var_lib_mysql:/var/lib/mysql
36+
expose:
37+
- "3306"
38+
networks:
39+
- compute
40+
41+
networks:
42+
compute:
43+
44+
volumes:
45+
var_lib_mysql:
46+
share:

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[build-system]
2+
requires = [
3+
"setuptools>=42",
4+
"git+https://github.com/fasrc/slurmrest_python_sdk.git",
5+
"wheel"
6+
]
7+
build-backend = "setuptools.build_meta"

setup.cfg

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[metadata]
2+
name = coldfront_plugin_slurmrest
3+
version = 0.0.1
4+
author = Claire Peters
5+
author_email = [email protected]
6+
description = Slurm REST API plugin for ColdFront
7+
long_description = file: README.md
8+
long_description_content_type = text/markdown
9+
url = https://github.com/coldfront/coldfront-slurm-plugin
10+
project_urls =
11+
Bug Tracker = https://github.com/coldfront/coldfront-slurm-plugin/issues
12+
classifiers =
13+
Programming Language :: Python :: 3
14+
License :: OSI Approved :: MIT License
15+
Operating System :: OS Independent
16+
17+
[options]
18+
package_dir =
19+
= src
20+
packages = find:
21+
python_requires = >=3.9
22+
install_requires =
23+
coldfront >= 1.1.0
24+
25+
[options.packages.find]
26+
where = src

setup.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env python
2+
3+
import setuptools
4+
5+
if __name__ == "__main__":
6+
setuptools.setup()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-FileCopyrightText: (C) ColdFront Authors
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
default_app_config = "coldfront.plugins.slurm.apps.SlurmConfig"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-FileCopyrightText: (C) ColdFront Authors
2+
#
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
from django.apps import AppConfig
6+
7+
8+
class SlurmRestConfig(AppConfig):
9+
name = "coldfront.plugins.slurmrest"
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from coldfront.config.base import INSTALLED_APPS
2+
from coldfront.config.env import ENV # noqa: F401
3+
from coldfront.config.logging import LOGGING
4+
5+
6+
if "coldfront_plugin_slurmrest" not in INSTALLED_APPS:
7+
INSTALLED_APPS += [
8+
"coldfront_plugin_slurmrest",
9+
]
10+
11+
SLURMREST_CLUSTER_ATTRIBUTE_NAME = ENV.str("SLURM_CLUSTER_ATTRIBUTE_NAME", default="slurm_cluster")
12+
SLURMREST_ACCOUNT_ATTRIBUTE_NAME = ENV.str(
13+
"SLURM_ACCOUNT_ATTRIBUTE_NAME", default="slurm_account_name")
14+
SLURMREST_SPECS_ATTRIBUTE_NAME = ENV.str(
15+
"SLURM_SPECS_ATTRIBUTE_NAME", default="slurm_specs")
16+
SLURMREST_USER_SPECS_ATTRIBUTE_NAME = ENV.str(
17+
"SLURM_USER_SPECS_ATTRIBUTE_NAME", default="slurm_user_specs")
18+
19+
SLURMREST_NOOP = ENV.bool('SLURM_NOOP', default=False)
20+
SLURMREST_IGNORE_USERS = ENV.list('SLURM_IGNORE_USERS', default=['root'])
21+
SLURMREST_IGNORE_ACCOUNTS = ENV.list('SLURM_IGNORE_ACCOUNTS', default=[])
22+
23+
SLURMREST_CLUSTERS = {}
24+
for cluster in ENV.str('SLURMREST_CLUSTERS', '').split(','):
25+
cluster_name = f"SLURM_{cluster.upper()}"
26+
cluster_type = ENV.str(f"{cluster_name}_TYPE")
27+
SLURMREST_CLUSTERS[cluster] = {
28+
'name': cluster,
29+
'base_url': ENV.str(f"{cluster_name}_ENDPOINT"),
30+
'token': ENV.str(f"{cluster_name}_TOKEN"),
31+
}
32+
33+
34+
LOGGING['handlers']['slurmrest'] = {
35+
'class': 'logging.handlers.TimedRotatingFileHandler',
36+
'filename': 'logs/slurmrest.log',
37+
'when': 'D',
38+
'backupCount': 10, # how many backup files to keep
39+
'formatter': 'default',
40+
'level': 'DEBUG',
41+
}
42+
43+
LOGGING['loggers']['coldfront.plugins.slurmrest'] = {
44+
'handlers': ['slurmrest'],
45+
}

0 commit comments

Comments
 (0)