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

Fix RepresenterError in db slurm new assoc #37

Merged
merged 2 commits into from
Feb 26, 2025
Merged
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
2 changes: 1 addition & 1 deletion cheeto/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.3.2'
__version__ = '1.3.3'
13 changes: 12 additions & 1 deletion cheeto/cmds/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,18 @@ def cmd_slurm_new_assoc(args: Namespace):
console.print(f'[red] QOS {args.qos} does not exist.')
return ExitCode.DOES_NOT_EXIST

console.print(assoc.pretty())
output = dumps_yaml(_show_slurm_assoc(assoc))
console.print(highlight_yaml(output))


def _show_slurm_assoc(assoc: SiteSlurmAssociation) -> dict:
return assoc._pretty(
lift=['partition'],
skip=('id',),
formatters={
'group': '{data.groupname}',
}
)


#########################################
Expand Down
1 change: 1 addition & 0 deletions cheeto/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
query_user_access,
query_user_status,
query_group_exists,
query_slurm_association,
tag_comment,
add_user_comment,
set_user_shell,
Expand Down
7 changes: 7 additions & 0 deletions cheeto/database/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,13 @@ def create_slurm_association(sitename: str, partitionname: str, groupname: str,
return assoc


def query_slurm_association(sitename: str, qosname: str, partition: str, groupname: str):
qos = SiteSlurmQOS.objects.get(qosname=qosname, sitename=sitename)
group = SiteGroup.objects.get(groupname=groupname, sitename=sitename)
partition = SiteSlurmPartition.objects.get(partitionname=partition, sitename=sitename)
return SiteSlurmAssociation.objects.get(sitename=sitename, qos=qos, group=group, partition=partition)


def slurm_qos_state(sitename: str) -> dict[str, SiteSlurmQOS]:
return {s.qosname: s.to_puppet() for s in SiteSlurmQOS.objects(sitename=sitename)}

Expand Down
13 changes: 13 additions & 0 deletions cheeto/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ def run_shell_cmd(cmd, print_stderr=True, in_directory=None):
os.chdir(cwd)


@pytest.fixture
def run_cmd(config_file):
def _run_cmd(*args):
from logging import getLogger
from ..cmds.__main__ import commands
logger = getLogger(__name__)
args = [str(arg) for arg in args]
args.extend(['--config', str(config_file)])
logger.info(f'running: {" ".join(args)}')
return commands.run(args)
return _run_cmd


@pytest.fixture(scope='session', autouse=True)
def setup_logging():
_setup_logging(sys.stdout)
Expand Down
36 changes: 28 additions & 8 deletions cheeto/tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,35 @@ def test_create_qos_cleaning(self):
assert qos.user_limits.mem == '1024M'
assert qos.job_limits.mem == '1024M'

def test_create_qos_command(self, config_file):
run_shell_cmd(['cheeto', 'database', 'slurm', 'new', 'qos',
'--config', config_file,
'--qosname', 'test-qos',
'--site', 'test-site',
'--group-limits', 'cpus=16,mem=1G,gpus=0',
'--user-limits', 'cpus=16,mem=1G,gpus=0',
'--job-limits', 'cpus=16,mem=1G,gpus=0'])
def test_create_qos_command(self, run_cmd):
run_cmd('database', 'slurm', 'new', 'qos',
'--qosname', 'test-qos',
'--site', 'test-site',
'--group-limits', 'cpus=16,mem=1G,gpus=0',
'--user-limits', 'cpus=16,mem=1G,gpus=0',
'--job-limits', 'cpus=16,mem=1G,gpus=0')
assert SiteSlurmQOS.objects.count() == 1
assert SiteSlurmQOS.objects.get(qosname='test-qos').group_limits.mem == '1024M'
assert SiteSlurmQOS.objects.get(qosname='test-qos').user_limits.mem == '1024M'
assert SiteSlurmQOS.objects.get(qosname='test-qos').job_limits.mem == '1024M'

def test_create_assoc_command(self, run_cmd):
create_group('test-group', 10000, sites=['test-site'])
create_slurm_partition('test-partition', 'test-site')

run_cmd('database', 'slurm', 'new', 'qos',
'--qosname', 'test-qos',
'--site', 'test-site',
'--group-limits', 'cpus=16,mem=1G,gpus=0',
'--user-limits', 'cpus=16,mem=1G,gpus=0',
'--job-limits', 'cpus=16,mem=1G,gpus=0')
run_cmd('database', 'slurm', 'new', 'assoc',
'--site', 'test-site',
'--group', 'test-group',
'--partition', 'test-partition',
'--qos', 'test-qos')
assert SiteSlurmAssociation.objects.count() == 1
assoc = query_slurm_association('test-site', 'test-qos', 'test-partition', 'test-group')
assert assoc.group.groupname == 'test-group'
assert assoc.partition.partitionname == 'test-partition'
assert assoc.qos.qosname == 'test-qos'
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "cheeto"
version = "1.3.2"
version = "1.3.3"
description = "Utilities for the UC Davis HPC Core Facility."
license = "Proprietary"
authors = [
Expand Down