From 16e4f06ae7343331304cc80aba78958123e1aafe Mon Sep 17 00:00:00 2001 From: jamesbeedy Date: Tue, 20 Aug 2024 19:30:11 +0000 Subject: [PATCH] fix(slurmctld): correctly parse nested config These changes modify the user supplied config parser so that it correctly handles nested user supplied configuration values. Accompanying test to show nested configuration is parsed correctly in test_charm.py Fixes #14 --- charms/slurmctld/src/charm.py | 2 +- charms/slurmctld/tests/unit/test_charm.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/charms/slurmctld/src/charm.py b/charms/slurmctld/src/charm.py index 8e75863..4e0aa92 100755 --- a/charms/slurmctld/src/charm.py +++ b/charms/slurmctld/src/charm.py @@ -326,7 +326,7 @@ def _get_user_supplied_parameters(self) -> Dict[Any, Any]: user_supplied_parameters = {} if custom_config := self.config.get("slurm-conf-parameters"): user_supplied_parameters = { - line.split("=")[0]: line.split("=")[1] + line.split("=")[0]: line.split("=", 1)[1] for line in str(custom_config).split("\n") if not line.startswith("#") and line.strip() != "" } diff --git a/charms/slurmctld/tests/unit/test_charm.py b/charms/slurmctld/tests/unit/test_charm.py index a8fe7e3..a76041f 100644 --- a/charms/slurmctld/tests/unit/test_charm.py +++ b/charms/slurmctld/tests/unit/test_charm.py @@ -171,3 +171,14 @@ def test_on_slurmdbd_unavailable(self) -> None: """Test that the on_slurmdbd_unavailable method works.""" self.harness.charm._slurmdbd.on.slurmdbd_unavailable.emit() self.assertEqual(self.harness.charm._stored.slurmdbd_host, "") + + def test_get_user_supplied_parameters(self) -> None: + """Test that user supplied parameters are parsed correctly.""" + self.harness.add_relation("slurmd", "slurmd") + self.harness.update_config( + {"slurm-conf-parameters": "JobAcctGatherFrequency=task=30,network=40"} + ) + self.assertEqual( + self.harness.charm._assemble_slurm_conf()["JobAcctGatherFrequency"], + "task=30,network=40", + )