|
| 1 | +#!/bin/sh |
| 2 | +test_description='Test job frobnicator command' |
| 3 | + |
| 4 | +. $(dirname $0)/sharness.sh |
| 5 | + |
| 6 | +# Setup a config dir for this test_under_flux |
| 7 | +export FLUX_CONF_DIR=$(pwd)/conf.d |
| 8 | +mkdir -p conf.d |
| 9 | +cat <<EOF >conf.d/conf.toml |
| 10 | +[policy.jobspec.defaults.system] |
| 11 | +duration = "30m" |
| 12 | +EOF |
| 13 | +test_under_flux 1 job |
| 14 | + |
| 15 | +flux setattr log-stderr-level 1 |
| 16 | + |
| 17 | +JOBSPEC=${SHARNESS_TEST_SRCDIR}/jobspec |
| 18 | +Y2J="flux python ${JOBSPEC}/y2j.py" |
| 19 | + |
| 20 | +test_expect_success 'flux job-frobnicator works' ' |
| 21 | + flux mini run --env=-* --dry-run hostname \ |
| 22 | + | flux job-frobnicator --jobspec-only |
| 23 | +' |
| 24 | +test_expect_success 'flux job-frobnicator --list-plugins works' ' |
| 25 | + flux job-frobnicator --list-plugins >list-plugins.output 2>&1 && |
| 26 | + test_debug "cat list-plugins.output" && |
| 27 | + grep defaults list-plugins.output |
| 28 | +' |
| 29 | +test_expect_success 'flux job-frobnicator --help can show help for plugins' ' |
| 30 | + cat <<-EOF >test-plugin.py && |
| 31 | + from flux.job.frobnicator import FrobnicatorPlugin |
| 32 | + class Frobnicator(FrobnicatorPlugin): |
| 33 | + def __init__(self, parser): |
| 34 | + self.test = False |
| 35 | + parser.add_argument("--test", action="store_true") |
| 36 | +
|
| 37 | + def configure(self, args): |
| 38 | + self.test = args.test |
| 39 | +
|
| 40 | + def frob(self, jobspec, user, urgency, flags): |
| 41 | + pass |
| 42 | + EOF |
| 43 | + flux job-frobnicator --plugins=./test-plugin.py --help >help.out 2>&1 && |
| 44 | + test_debug "cat help.out" && |
| 45 | + grep "Options provided by plugins" help.out && |
| 46 | + grep "\-\-test" help.out |
| 47 | +' |
| 48 | +test_expect_success 'flux job-frobnicator errors on invalid plugin' ' |
| 49 | + test_expect_code 1 flux job-frobnicator --plugin=foo </dev/null && |
| 50 | + test_expect_code 1 flux job-frobnicator --plugin=/tmp </dev/null |
| 51 | +' |
| 52 | +test_expect_success 'flux job-frobnicator exits on eof' ' |
| 53 | + flux job-frobnicator --plugins=defaults </dev/null |
| 54 | +' |
| 55 | +test_expect_success 'flux job-frobnicator exits with error on bad input' ' |
| 56 | + echo {} | test_expect_code 1 flux job-frobnicator --plugins=defaults |
| 57 | +' |
| 58 | +test_expect_success 'job-frobnicator: all valid jobspecs accepted' ' |
| 59 | + for f in ${JOBSPEC}/valid/*; do |
| 60 | + $Y2J <$f | flux job-frobnicator --jobspec-only --plugins=defaults |
| 61 | + done |
| 62 | +' |
| 63 | +test_expect_success HAVE_JQ 'job-frobnicator: defaults plugin does things' ' |
| 64 | + flux mini run --env=-* --dry-run hostname \ |
| 65 | + | flux job-frobnicator --jobspec-only --plugins=defaults \ |
| 66 | + | jq -e ".data.attributes.system.duration == 1800" |
| 67 | +' |
| 68 | +test_expect_success HAVE_JQ 'job-frobnicator: defaults plugin does not do things' ' |
| 69 | + flux mini run --env=-* --dry-run -t 1h hostname \ |
| 70 | + | flux job-frobnicator --jobspec-only --plugins=defaults \ |
| 71 | + | jq -e ".data.attributes.system.duration == 3600" |
| 72 | +' |
| 73 | +test_expect_success 'configure queues with default durations' ' |
| 74 | + cat <<-EOF >conf.d/conf.toml && |
| 75 | + [policy.jobspec.defaults.system] |
| 76 | + queue = "debug" |
| 77 | + [queues.debug] |
| 78 | + policy.jobspec.defaults.system.duration = "1h" |
| 79 | + [queues.batch] |
| 80 | + policy.jobspec.defaults.system.duration = "8h" |
| 81 | + EOF |
| 82 | + flux config reload |
| 83 | +' |
| 84 | +test_expect_success HAVE_JQ 'job-frobnicator sets default queue duration' ' |
| 85 | + flux mini run --env=-* --dry-run hostname \ |
| 86 | + | flux job-frobnicator --jobspec-only --plugins=defaults \ |
| 87 | + > queue-debug.out && |
| 88 | + jq -e ".data.attributes.system.queue == \"debug\"" < queue-debug.out && |
| 89 | + jq -e ".data.attributes.system.duration == 3600" < queue-debug.out |
| 90 | +' |
| 91 | +test_expect_success HAVE_JQ 'job-frobnicator sets specified queue duration' ' |
| 92 | + flux mini run --env=-* --setattr queue=batch --dry-run hostname \ |
| 93 | + | flux job-frobnicator --jobspec-only --plugins=defaults \ |
| 94 | + > queue-batch.out && |
| 95 | + jq -e ".data.attributes.system.queue == \"batch\"" < queue-batch.out && |
| 96 | + jq -e ".data.attributes.system.duration == 28800" < queue-batch.out |
| 97 | +' |
| 98 | +test_expect_success 'job-frobnicator errors on a missing queue config' ' |
| 99 | + cat <<-EOF >conf.d/conf.toml && |
| 100 | + [policy.jobspec.defaults.system] |
| 101 | + queue = "debug" |
| 102 | + EOF |
| 103 | + flux jobtap remove .jobspec-default && |
| 104 | + flux config reload && |
| 105 | + flux mini run --env=-* --dry-run hostname \ |
| 106 | + | test_expect_code 1 \ |
| 107 | + flux job-frobnicator --jobspec-only --plugins=defaults \ |
| 108 | + >bad1.out 2>&1 && |
| 109 | + grep "default queue.*debug.*must be in" bad1.out |
| 110 | +' |
| 111 | +test_expect_success 'job-frobnicator errors on an invalid queue config' ' |
| 112 | + cat <<-EOF >conf.d/conf.toml && |
| 113 | + queues = 42 |
| 114 | + [policy.jobspec.defaults.system] |
| 115 | + queue = "debug" |
| 116 | + EOF |
| 117 | + flux config reload && |
| 118 | + flux mini run --env=-* --dry-run hostname \ |
| 119 | + | test_expect_code 1 \ |
| 120 | + flux job-frobnicator --jobspec-only --plugins=defaults \ |
| 121 | + >bad2.out 2>&1 && |
| 122 | + grep "queues must be a table" bad2.out |
| 123 | +' |
| 124 | + |
| 125 | +test_done |
0 commit comments