|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +test_description='Test RFC 33 policy config verification |
| 4 | +
|
| 5 | +Ensure that the broker catches violations of the configuration |
| 6 | +specified in RFC 33 for [policy] and [queue.<name>.policy]. |
| 7 | +' |
| 8 | + |
| 9 | +. $(dirname $0)/sharness.sh |
| 10 | + |
| 11 | +mkdir -p config |
| 12 | + |
| 13 | +test_under_flux 1 minimal -o,--config-path=$(pwd)/config |
| 14 | + |
| 15 | +flux setattr log-stderr-level 1 |
| 16 | + |
| 17 | +test_expect_success 'unknown policy key fails' ' |
| 18 | + cat >config/policy.toml <<-EOT && |
| 19 | + policy.foo = 1 |
| 20 | + EOT |
| 21 | + test_must_fail flux config reload |
| 22 | +' |
| 23 | +test_expect_success 'unknown policy.jobspec key fails' ' |
| 24 | + cat >config/policy.toml <<-EOT && |
| 25 | + policy.jobspec.foo = 1 |
| 26 | + EOT |
| 27 | + test_must_fail flux config reload |
| 28 | +' |
| 29 | +test_expect_success 'unknown policy.jobspec.defaults key fails' ' |
| 30 | + cat >config/policy.toml <<-EOT && |
| 31 | + policy.jobspec.defaults.foo = 1 |
| 32 | + EOT |
| 33 | + test_must_fail flux config reload |
| 34 | +' |
| 35 | +test_expect_success 'unknown policy.jobspec.defaults.system key fails' ' |
| 36 | + cat >config/policy.toml <<-EOT && |
| 37 | + policy.jobspec.defaults.system.foo = 1 |
| 38 | + EOT |
| 39 | + test_must_fail flux config reload |
| 40 | +' |
| 41 | +test_expect_success 'malformed policy.jobspec.defaults.system.duration fails' ' |
| 42 | + cat >config/policy.toml <<-EOT && |
| 43 | + policy.jobspec.defaults.system.duration = 1 |
| 44 | + EOT |
| 45 | + test_must_fail flux config reload |
| 46 | +' |
| 47 | +test_expect_success 'wrong type policy.jobspec.defaults.system.queue fails' ' |
| 48 | + cat >config/policy.toml <<-EOT && |
| 49 | + policy.jobspec.defaults.system.queue = 1 |
| 50 | + EOT |
| 51 | + test_must_fail flux config reload |
| 52 | +' |
| 53 | +test_expect_success 'unknown policy.limits key fails' ' |
| 54 | + cat >config/policy.toml <<-EOT && |
| 55 | + policy.limits.foo = 1 |
| 56 | + EOT |
| 57 | + test_must_fail flux config reload |
| 58 | +' |
| 59 | +test_expect_success 'unknown policy.limits.job-size key fails' ' |
| 60 | + cat >config/policy.toml <<-EOT && |
| 61 | + policy.limits.job-size.foo = 1 |
| 62 | + EOT |
| 63 | + test_must_fail flux config reload |
| 64 | +' |
| 65 | +test_expect_success 'unknown policy.limits.job-size.max key fails' ' |
| 66 | + cat >config/policy.toml <<-EOT && |
| 67 | + policy.limits.job-size.max.foo = 1 |
| 68 | + EOT |
| 69 | + test_must_fail flux config reload |
| 70 | +' |
| 71 | +test_expect_success 'unknown policy.limits.job-size.min key fails' ' |
| 72 | + cat >config/policy.toml <<-EOT && |
| 73 | + policy.limits.job-size.min.foo = 1 |
| 74 | + EOT |
| 75 | + test_must_fail flux config reload |
| 76 | +' |
| 77 | +test_expect_success 'incorrect policy.limits.job-size.min.nnodes fails' ' |
| 78 | + cat >config/policy.toml <<-EOT && |
| 79 | + policy.limits.job-size.min.nnodes = -2 |
| 80 | + EOT |
| 81 | + test_must_fail flux config reload |
| 82 | +' |
| 83 | +test_expect_success 'malformed policy.limits.duration fails' ' |
| 84 | + cat >config/policy.toml <<-EOT && |
| 85 | + policy.limits.duration = 1.0 |
| 86 | + EOT |
| 87 | + test_must_fail flux config reload |
| 88 | +' |
| 89 | +test_expect_success 'unknown policy.access key fails' ' |
| 90 | + cat >config/policy.toml <<-EOT && |
| 91 | + policy.access.foo = 1.0 |
| 92 | + EOT |
| 93 | + test_must_fail flux config reload |
| 94 | +' |
| 95 | +test_expect_success 'malformed policy.access.allow-user key fails' ' |
| 96 | + cat >config/policy.toml <<-EOT && |
| 97 | + policy.access.allow-user = 1.0 |
| 98 | + EOT |
| 99 | + test_must_fail flux config reload |
| 100 | +' |
| 101 | +test_expect_success 'malformed policy.access.allow-group key fails' ' |
| 102 | + cat >config/policy.toml <<-EOT && |
| 103 | + policy.access.allow-group = 1.0 |
| 104 | + EOT |
| 105 | + test_must_fail flux config reload |
| 106 | +' |
| 107 | +test_expect_success 'malformed policy.access.allow-user entry fails' ' |
| 108 | + cat >config/policy.toml <<-EOT && |
| 109 | + policy.access.allow-user = [ 1 ] |
| 110 | + EOT |
| 111 | + test_must_fail flux config reload |
| 112 | +' |
| 113 | +test_expect_success 'malformed policy.access.allow-group entry fails' ' |
| 114 | + cat >config/policy.toml <<-EOT && |
| 115 | + policy.access.allow-group = [ 1 ] |
| 116 | + EOT |
| 117 | + test_must_fail flux config reload |
| 118 | +' |
| 119 | +test_expect_success 'well formed policy.access works' ' |
| 120 | + cat >config/policy.toml <<-EOT && |
| 121 | + [policy.access] |
| 122 | + allow-user = [ "alice", "bob" ] |
| 123 | + allow-group = [ "smurfs" ] |
| 124 | + EOT |
| 125 | + flux config reload |
| 126 | +' |
| 127 | +test_expect_success 'unknown queues.NAME.policy.foo key fails' ' |
| 128 | + cat >config/policy.toml <<-EOT && |
| 129 | + queues.x.policy.foo = 1 |
| 130 | + EOT |
| 131 | + test_must_fail flux config reload |
| 132 | +' |
| 133 | +test_expect_success 'malformed queues.NAME.policy.limits.duration key fails' ' |
| 134 | + cat >config/policy.toml <<-EOT && |
| 135 | + queues.x.policy.limits.duration = 1 |
| 136 | + EOT |
| 137 | + test_must_fail flux config reload |
| 138 | +' |
| 139 | +# Example from flux-config-policy(5) |
| 140 | +test_expect_success 'valid config passes' ' |
| 141 | + cat >config/policy.toml <<-EOT && |
| 142 | + [policy.jobspec.defaults.system] |
| 143 | + duration = "1h" |
| 144 | + queue = "batch" |
| 145 | +
|
| 146 | + [policy.limits] |
| 147 | + duration = "4h" |
| 148 | + job-size.max.nnodes = 8 |
| 149 | + job-size.max.ngpus = 4 |
| 150 | +
|
| 151 | + [queues.debug.policy.limits] |
| 152 | + duration = "30m" |
| 153 | + job-size.max.ngpus = -1 # unlimited |
| 154 | + EOT |
| 155 | + flux config reload |
| 156 | +' |
| 157 | +test_done |
0 commit comments