Skip to content

Commit 9aa14ab

Browse files
committed
job-manager: require duration limit to be FSD
Problem: RFC 33 states that policy durations are FSD strings, but the duration-limit jobtap plugin permits them to be numerical also. Change the duration-limit plugin to require FSD strings. This affects: policy.jobspec.defaults.system.duration policy.limits.duration as well as the per-queue policy tables. Update the flux-config-policy(5) man page. Update the t2221-job-manager-limit-duration.t sharness test.
1 parent a7760fc commit 9aa14ab

File tree

3 files changed

+21
-42
lines changed

3 files changed

+21
-42
lines changed

doc/man5/flux-config-policy.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ DEFAULTS
2020
Default values for job requests may be configured in the
2121
``policy.jobspec.defaults.system`` table. If a job request does not specify
2222
a value for a system attribute that is configured in the table, the configured
23-
value is substituted. Some common examples are:
23+
value is substituted. Currently the following values are allowed:
2424

25-
policy.jobspec.defaults.system.duration (float seconds or FSD string)
25+
policy.jobspec.defaults.system.duration (FSD string)
2626
(optional) If a job is submitted without specifying a job duration,
2727
this value is substituted.
2828

@@ -42,8 +42,8 @@ rejected at submission time if they violate configured limits.
4242
queue. The actual value used to indicate `unlimited` varies by limit
4343
type and is noted below.
4444

45-
policy.limits.duration (float seconds or FSD string)
46-
(optional) Maximum duration that a job may request (0 = unlimited).
45+
policy.limits.duration (FSD string)
46+
(optional) Maximum duration that a job may request ("0" = unlimited).
4747

4848
.. note::
4949
Limit checks take place before the scheduler sees the request, so it is
@@ -81,7 +81,7 @@ EXAMPLE
8181

8282
[policy.defaults]
8383
duration = "1h"
84-
queue = "pbatch"
84+
queue = "batch"
8585

8686
[policy.limits]
8787
duration = "4h"

src/modules/job-manager/plugins/limit-duration.c

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
*
1313
* This plugin uses the job.validate callback to accept or reject job
1414
* requests. Any default jobspec values would have been applied earlier
15-
* (where applicable) in the job.create callback.
15+
* (where applicable) at ingest.
1616
*
1717
* General limit:
1818
* policy.limits.duration
1919
* Queue-specific limit:
2020
* queues.<name>.policy.limits.duration
2121
*
2222
* N.B. a queue limit may override the general limit with a higher or lower
23-
* limit, even "unlimited" (0).
23+
* limit, or "0" for unlimited.
2424
*
2525
* See also:
2626
* RFC 33/Flux Job Queues
@@ -131,36 +131,24 @@ static int duration_parse (double *duration,
131131
flux_error_t *error)
132132
{
133133
double d = DURATION_INVALID;
134-
json_t *o = NULL;
134+
const char *ds = NULL;
135135
json_error_t jerror;
136136
const char *name = "policy.limits.duration";
137137

138138
if (json_unpack_ex (conf,
139139
&jerror,
140140
0,
141-
"{s?{s?{s?o}}}",
141+
"{s?{s?{s?s}}}",
142142
"policy",
143143
"limits",
144-
"duration", &o) < 0) {
144+
"duration", &ds) < 0) {
145145
errprintf (error, "%s: %s", name, jerror.text);
146-
return -1;
146+
goto inval;
147147
}
148-
if (o) {
149-
if (json_is_string (o)) {
150-
if (fsd_parse_duration (json_string_value (o), &d) < 0) {
151-
errprintf (error, "%s: FSD value is malformed", name);
152-
return -1;
153-
}
154-
}
155-
else if (json_is_number (o)) {
156-
if ((d = json_number_value (o)) < 0) {
157-
errprintf (error, "%s: must be >= 0", name);
158-
goto inval;
159-
}
160-
}
161-
else {
162-
errprintf (error, "%s: must be FSD (string) or seconds", name);
163-
goto inval;
148+
if (ds) {
149+
if (fsd_parse_duration (ds, &d) < 0) {
150+
errprintf (error, "%s: FSD value is malformed", name);
151+
return -1;
164152
}
165153
}
166154
*duration = d;

t/t2221-job-manager-limit-duration.t

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,20 @@ test_under_flux 2 full -o,--config-path=$(pwd)/config
1010

1111
flux setattr log-stderr-level 1
1212

13-
test_expect_success 'unload all built-in plugins' '
14-
flux jobtap remove ".*"
15-
'
16-
test_expect_success 'configure an invalid numerical duration limit' '
13+
test_expect_success 'configuring an invalid duration limit fails' '
1714
cat >config/policy.toml <<-EOT &&
1815
[policy.limits]
19-
duration = -1.0
16+
duration = 1.0
2017
EOT
21-
flux config reload
22-
'
23-
test_expect_success 'cannot load the limit-duration plugin' '
24-
test_must_fail flux jobtap load .limit-duration
18+
test_must_fail flux config reload
2519
'
26-
test_expect_success 'configure a valid duration limit (FSD)' '
20+
test_expect_success 'configure a valid duration limit' '
2721
cat >config/policy.toml <<-EOT &&
2822
[policy.limits]
2923
duration = "1m"
3024
EOT
3125
flux config reload
3226
'
33-
test_expect_success 'the limit-duration plugin can now be laoded' '
34-
flux jobtap load .limit-duration
35-
'
3627
test_expect_success 'a job that exceeds policy.limits.duration is rejected' '
3728
test_must_fail flux mini submit -t 1h /bin/true 2>duration.err &&
3829
grep "exceeds policy limit of 1m" duration.err
@@ -83,7 +74,7 @@ test_expect_success 'configure policy.limits.duration and an unlimited queue' '
8374
[policy.limits]
8475
duration = "1h"
8576
[queues.pdebug.policy.limits]
86-
duration = 0
77+
duration = "0"
8778
EOT
8879
flux config reload
8980
'
@@ -100,7 +91,7 @@ test_expect_success 'a job that sets no explicit duration is accepted by the unl
10091
--setattr=system.queue=pdebug \
10192
/bin/true
10293
'
103-
test_expect_success 'configure an invalid string duration limit' '
94+
test_expect_success 'configure an invalid duration limit' '
10495
cat >config/policy.toml <<-EOT &&
10596
[policy.limits]
10697
duration = "xyz123"

0 commit comments

Comments
 (0)