Skip to content

Commit 35c7bd8

Browse files
committed
libjob: duration is not optional in jobspecV1
Problem: Per RFC25, attributes.system.duration is not optional in jobspecV1. However, libjob considers it optional in its parsing. Solution: Update parsing to make attributes.system.duration a requirement. Also check for jobspec version 1 before parsing job duration. Update expected output in t/t0022-jj-reader.t and t/t2300-sched-simple.t as expected error message will now be different.
1 parent 9ce7281 commit 35c7bd8

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/common/libjob/jj.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,20 @@ int jj_get_counts_json (json_t *jobspec, struct jj_counts *jj)
124124
errno = EINVAL;
125125
return -1;
126126
}
127-
if (json_unpack_ex (jobspec, &error, 0, "{s:{s?{s?F}}}",
128-
"attributes",
129-
"system",
130-
"duration", &jj->duration) < 0) {
127+
if (version != 1) {
131128
snprintf (jj->error, sizeof (jj->error) - 1,
132-
"at top level: getting duration: %s", error.text);
129+
"Invalid version: expected 1, got %d", version);
133130
errno = EINVAL;
134131
return -1;
135132
}
136-
if (version != 1) {
133+
/* N.B. attributes.system is generally optional, but
134+
* attributes.system.duration is required in jobspec version 1 */
135+
if (json_unpack_ex (jobspec, &error, 0, "{s:{s:{s:F}}}",
136+
"attributes",
137+
"system",
138+
"duration", &jj->duration) < 0) {
137139
snprintf (jj->error, sizeof (jj->error) - 1,
138-
"Invalid version: expected 1, got %d", version);
140+
"at top level: getting duration: %s", error.text);
139141
errno = EINVAL;
140142
return -1;
141143
}

t/t0022-jj-reader.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ test_expect_success 'jj-reader: wrong count type throws error' '
6666
# jobspec.yaml ==<expected error>
6767
#
6868
cat <<EOF>invalid.txt
69-
jobspec/valid/basic.yaml ==jj-reader: Unable to determine slot size
69+
jobspec/valid/basic.yaml ==jj-reader: at top level: getting duration: Object item not found: system
7070
jobspec/valid/example2.yaml ==jj-reader: Unable to determine slot size
7171
jobspec/valid/use_case_1.2.yaml ==jj-reader: level 0: Expected integer, got object
7272
jobspec/valid/use_case_1.3.yaml ==jj-reader: level 2: Expected integer, got object

t/t2300-sched-simple.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ test_expect_success 'sched-simple: invalid minimal jobspec is canceled' '
7878
${Y2J}<${SPEC} | jq ".version = 1" | flux job submit >job00.id &&
7979
jobid=$(cat job00.id) &&
8080
flux job wait-event --timeout=5.0 $jobid exception &&
81-
flux job eventlog $jobid | grep "Unable to determine slot size"
81+
flux job eventlog $jobid | grep "getting duration: Object item not found: system"
8282
'
8383
test_expect_success 'sched-simple: submit 5 jobs' '
8484
flux job submit basic.json >job1.id &&

0 commit comments

Comments
 (0)