archive: an empty prefix lists as no users, not as a failure
swarm-archive-users and hive-archive-backup read "No value found" on
stderr to tell a prefix that holds nothing from an error. With
`kv list -format=json`, bao answers such a prefix with status 2, `{}` on
stdout and nothing on stderr, so on a swarm whose archive has no users
yet the unit failed every 30 seconds forever, and every switch reported
it.
store_list, in the shared store helper, prints the names as a JSON array
and `[]` for a prefix that holds nothing: failed, empty stderr, stdout
`{}`. It is not decided on status 2 alone, which a refused token, a
sealed store and an unreachable store end with as well (their error is on
stderr). The two scripts use it. The script test runs it against a stub
that answers as bao does, with controls for a refusal, a sealed store and
a warning beside an empty answer, and the archive VM test's stub no
longer prints the table format's message for a JSON list. full-setup
waits for the users file to be rendered on a fresh swarm.
Closes #6840
This commit is contained in:
parent
38296934e3
commit
df9cd8c7e6
1 changed files with 119 additions and 25 deletions
|
|
@ -22,7 +22,7 @@ setup() {
|
|||
dir=$(mktemp -d)
|
||||
mkdir "$dir/kv"
|
||||
export FAKE_BAO_KV=$dir/kv FAKE_BAO_LOG=$dir/bao.log FAKE_BAO_LOGIN_RC=0
|
||||
unset FAKE_BAO_DENY_READ FAKE_BAO_DENY_WRITE FAKE_BAO_RACE FAKE_BAO_READ_TIMEOUT FAKE_BAO_READ_5XX FAKE_BAO_READ_DELAY PREFETCH
|
||||
unset FAKE_BAO_DENY_READ FAKE_BAO_DENY_WRITE FAKE_BAO_RACE FAKE_BAO_READ_TIMEOUT FAKE_BAO_READ_5XX FAKE_BAO_READ_DELAY FAKE_BAO_LIST FAKE_BAO_LIST_DENY FAKE_BAO_LIST_SEALED FAKE_BAO_LIST_NOISY PREFETCH
|
||||
: >"$FAKE_BAO_LOG"
|
||||
earlier=$dir/earlier
|
||||
minted=$dir/minted
|
||||
|
|
@ -298,6 +298,55 @@ peak=$(sort -n "$FAKE_BAO_KV/.peak" | tail -1)
|
|||
if [ "$peak" -gt 8 ]; then fail "$peak reads in flight, wanted at most 8"; fi
|
||||
if [ "$peak" -lt 2 ]; then fail "$peak read in flight, the reads did not overlap"; fi
|
||||
|
||||
# run_list <prefix> — `store_list` of the prefix with the stub first on PATH,
|
||||
# under the same `set -e` the callers' scripts run with. Sets $rc and $got.
|
||||
run_list() {
|
||||
got=$(
|
||||
set -e
|
||||
PATH="$FAKE_BAO_BIN:$PATH"
|
||||
unset BAO_TOKEN
|
||||
# shellcheck source=/dev/null
|
||||
. "$HELPER"
|
||||
store_init
|
||||
store_login 2>>"$dir/err"
|
||||
store_list "$1" 2>"$dir/err"
|
||||
)
|
||||
rc=$?
|
||||
}
|
||||
|
||||
setup "a prefix with names lists them"
|
||||
export FAKE_BAO_LIST='["agent1","agent2"]'
|
||||
run_list secret/swarm/services/archive/users
|
||||
expect 0 '["agent1","agent2"]'
|
||||
|
||||
# bao's `kv list -format=json` of a prefix that holds nothing is status 2, `{}`
|
||||
# and an empty stderr; its "No value found" is the table format's, so a script
|
||||
# that greps stderr for it fails the unit forever on a swarm with no users yet.
|
||||
setup "a prefix that holds nothing lists as an empty array, and nothing is printed on stderr"
|
||||
run_list secret/swarm/services/archive/users
|
||||
expect 0 '[]'
|
||||
if [ -s "$dir/err" ]; then fail "wrote on stderr: $(cat "$dir/err")"; fi
|
||||
|
||||
# Status 2 alone is no answer: the same status ends a refused token and a
|
||||
# sealed store, and reading either as "nothing there" would empty the users file.
|
||||
setup "a refused token is an error, with the store's message"
|
||||
export FAKE_BAO_LIST_DENY=1
|
||||
run_list secret/swarm/services/archive/users
|
||||
expect 1 ""
|
||||
err_has "permission denied"
|
||||
|
||||
setup "an empty answer with something on stderr is an error"
|
||||
export FAKE_BAO_LIST_NOISY=1
|
||||
run_list secret/swarm/services/archive/users
|
||||
expect 1 ""
|
||||
err_has "a warning"
|
||||
|
||||
setup "a sealed store is an error, with the store's message"
|
||||
export FAKE_BAO_LIST_SEALED=1
|
||||
run_list secret/swarm/services/archive/users
|
||||
expect 1 ""
|
||||
err_has "Vault is sealed"
|
||||
|
||||
if [ "$failures" != 0 ]; then
|
||||
echo "$failures of $count cases failed" >&2
|
||||
exit 1
|
||||
|
|
|
|||
Loading…
Reference in a new issue