Skip to content

Commit 29b1b03

Browse files
Fix RepresenterError in db slurm new assoc (#37)
* bugfix: the new asosc command was raising a ruamel serialization error while attempting to display the newly created qos * v1.3.3
1 parent c39a71a commit 29b1b03

File tree

7 files changed

+63
-11
lines changed

7 files changed

+63
-11
lines changed

cheeto/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.3.2'
1+
__version__ = '1.3.3'

cheeto/cmds/database.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,18 @@ def cmd_slurm_new_assoc(args: Namespace):
11901190
console.print(f'[red] QOS {args.qos} does not exist.')
11911191
return ExitCode.DOES_NOT_EXIST
11921192

1193-
console.print(assoc.pretty())
1193+
output = dumps_yaml(_show_slurm_assoc(assoc))
1194+
console.print(highlight_yaml(output))
1195+
1196+
1197+
def _show_slurm_assoc(assoc: SiteSlurmAssociation) -> dict:
1198+
return assoc._pretty(
1199+
lift=['partition'],
1200+
skip=('id',),
1201+
formatters={
1202+
'group': '{data.groupname}',
1203+
}
1204+
)
11941205

11951206

11961207
#########################################

cheeto/database/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
query_user_access,
7373
query_user_status,
7474
query_group_exists,
75+
query_slurm_association,
7576
tag_comment,
7677
add_user_comment,
7778
set_user_shell,

cheeto/database/crud.py

+7
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,13 @@ def create_slurm_association(sitename: str, partitionname: str, groupname: str,
882882
return assoc
883883

884884

885+
def query_slurm_association(sitename: str, qosname: str, partition: str, groupname: str):
886+
qos = SiteSlurmQOS.objects.get(qosname=qosname, sitename=sitename)
887+
group = SiteGroup.objects.get(groupname=groupname, sitename=sitename)
888+
partition = SiteSlurmPartition.objects.get(partitionname=partition, sitename=sitename)
889+
return SiteSlurmAssociation.objects.get(sitename=sitename, qos=qos, group=group, partition=partition)
890+
891+
885892
def slurm_qos_state(sitename: str) -> dict[str, SiteSlurmQOS]:
886893
return {s.qosname: s.to_puppet() for s in SiteSlurmQOS.objects(sitename=sitename)}
887894

cheeto/tests/conftest.py

+13
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ def run_shell_cmd(cmd, print_stderr=True, in_directory=None):
7878
os.chdir(cwd)
7979

8080

81+
@pytest.fixture
82+
def run_cmd(config_file):
83+
def _run_cmd(*args):
84+
from logging import getLogger
85+
from ..cmds.__main__ import commands
86+
logger = getLogger(__name__)
87+
args = [str(arg) for arg in args]
88+
args.extend(['--config', str(config_file)])
89+
logger.info(f'running: {" ".join(args)}')
90+
return commands.run(args)
91+
return _run_cmd
92+
93+
8194
@pytest.fixture(scope='session', autouse=True)
8295
def setup_logging():
8396
_setup_logging(sys.stdout)

cheeto/tests/test_db.py

+28-8
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,35 @@ def test_create_qos_cleaning(self):
109109
assert qos.user_limits.mem == '1024M'
110110
assert qos.job_limits.mem == '1024M'
111111

112-
def test_create_qos_command(self, config_file):
113-
run_shell_cmd(['cheeto', 'database', 'slurm', 'new', 'qos',
114-
'--config', config_file,
115-
'--qosname', 'test-qos',
116-
'--site', 'test-site',
117-
'--group-limits', 'cpus=16,mem=1G,gpus=0',
118-
'--user-limits', 'cpus=16,mem=1G,gpus=0',
119-
'--job-limits', 'cpus=16,mem=1G,gpus=0'])
112+
def test_create_qos_command(self, run_cmd):
113+
run_cmd('database', 'slurm', 'new', 'qos',
114+
'--qosname', 'test-qos',
115+
'--site', 'test-site',
116+
'--group-limits', 'cpus=16,mem=1G,gpus=0',
117+
'--user-limits', 'cpus=16,mem=1G,gpus=0',
118+
'--job-limits', 'cpus=16,mem=1G,gpus=0')
120119
assert SiteSlurmQOS.objects.count() == 1
121120
assert SiteSlurmQOS.objects.get(qosname='test-qos').group_limits.mem == '1024M'
122121
assert SiteSlurmQOS.objects.get(qosname='test-qos').user_limits.mem == '1024M'
123122
assert SiteSlurmQOS.objects.get(qosname='test-qos').job_limits.mem == '1024M'
123+
124+
def test_create_assoc_command(self, run_cmd):
125+
create_group('test-group', 10000, sites=['test-site'])
126+
create_slurm_partition('test-partition', 'test-site')
127+
128+
run_cmd('database', 'slurm', 'new', 'qos',
129+
'--qosname', 'test-qos',
130+
'--site', 'test-site',
131+
'--group-limits', 'cpus=16,mem=1G,gpus=0',
132+
'--user-limits', 'cpus=16,mem=1G,gpus=0',
133+
'--job-limits', 'cpus=16,mem=1G,gpus=0')
134+
run_cmd('database', 'slurm', 'new', 'assoc',
135+
'--site', 'test-site',
136+
'--group', 'test-group',
137+
'--partition', 'test-partition',
138+
'--qos', 'test-qos')
139+
assert SiteSlurmAssociation.objects.count() == 1
140+
assoc = query_slurm_association('test-site', 'test-qos', 'test-partition', 'test-group')
141+
assert assoc.group.groupname == 'test-group'
142+
assert assoc.partition.partitionname == 'test-partition'
143+
assert assoc.qos.qosname == 'test-qos'

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "cheeto"
3-
version = "1.3.2"
3+
version = "1.3.3"
44
description = "Utilities for the UC Davis HPC Core Facility."
55
license = "Proprietary"
66
authors = [

0 commit comments

Comments
 (0)