Skip to content

Commit

Permalink
dws: add logic to validate rabbit config table
Browse files Browse the repository at this point in the history
Problem: there are no checks to ensure that the rabbit config table
is valid.

Add some simple validation.
  • Loading branch information
jameshcorbett committed Nov 5, 2024
1 parent 0686089 commit 459db7c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/modules/coral2_dws.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,38 @@ def kubernetes_backoff(handle, orig_retry_delay):
time.sleep(retry_delay)


def validate_config(config):
"""Validate the `rabbit` config table."""
accepted_keys = {
"save_datamovements",
"kubeconfig",
"tc_timeout",
"drain_compute_nodes",
"restrict_persistent_creation",
"policy",
}
keys = set(config.keys())
if not keys <= accepted_keys:
raise RuntimeError(
f"misconfiguration: unrecognized "
"`rabbit.{(keys - accepted_keys).pop()}` key in Flux config, accepted "
f"keys are {accepted_keys}"
)
if "policy" in config:
if len(config["policy"]) != 1 or "maximums" not in config["policy"]:
raise RuntimeError(
"`rabbit.policy` config table muxt have a `maximums` table"
)
keys = set(config["policy"]["maximums"].keys())
accepted_keys = set(directivebreakdown.ResourceLimits.TYPES)
if not keys <= accepted_keys:
raise RuntimeError(
f"misconfiguration: unrecognized "
"`rabbit.policy.maximums.{(keys - accepted_keys).pop()}` key in Flux "
f"config, accepted keys are {accepted_keys}"
)


def main():
"""Init script, begin processing of services."""
args = setup_parsing().parse_args()
Expand All @@ -953,6 +985,7 @@ def main():
if "FLUX_KVS_NAMESPACE" in os.environ:
del os.environ["FLUX_KVS_NAMESPACE"]
handle = flux.Flux()
validate_config(handle.conf_get("rabbit", {}))
WorkflowInfo.save_datamovements = handle.conf_get("rabbit.save_datamovements", 0)
# set the maximum allowable allocation sizes on the ResourceLimits class
for fs_type in directivebreakdown.ResourceLimits.TYPES:
Expand Down
13 changes: 13 additions & 0 deletions t/t1002-dws-workflow-obj.t
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ kubeconfig = \"/dev/null\"
-v --foobar
'

test_expect_success 'exec dws service-providing script with bad config' '
echo "
[rabbit]
foobar = false
" | flux config load &&
test_must_fail flux python ${DWS_MODULE_PATH} -v &&
echo "
[rabbit.policy.maximums]
fake = 1
" | flux config load &&
test_must_fail flux python ${DWS_MODULE_PATH} -v
'

test_expect_success 'exec dws service-providing script with fluxion scheduling disabled' '
flux config reload &&
R=$(flux R encode -r 0) &&
Expand Down

0 comments on commit 459db7c

Please sign in to comment.