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
2 changed files with 119 additions and 25 deletions
|
|
@ -15,6 +15,11 @@ let
|
|||
# `FAKE_BAO_READ_TIMEOUT` is `timeout` ending the read: status 124, silent.
|
||||
# `FAKE_BAO_READ_5XX` is a server error on the read. A leaf nobody wrote is
|
||||
# "No value found at <path>", status 2, as `bao kv get` answers it.
|
||||
# `kv list -format=json` answers `FAKE_BAO_LIST` (a JSON array) when it is
|
||||
# set, and as bao answers a prefix that holds nothing when it is not: status
|
||||
# 2, `{}`, nothing on stderr. `FAKE_BAO_LIST_DENY` and `FAKE_BAO_LIST_SEALED`
|
||||
# are the errors, which end with status 2 as well but print on stderr, and
|
||||
# `FAKE_BAO_LIST_NOISY` is an empty answer with a line on stderr.
|
||||
# `FAKE_BAO_RACE` has another run create the leaf between this one's read and
|
||||
# its write. `FAKE_BAO_READ_DELAY` holds each read that long and records, in
|
||||
# `$FAKE_BAO_KV/.peak`, how many reads were in flight with it. Every call is
|
||||
|
|
@ -47,6 +52,19 @@ let
|
|||
[ -e "$leaf" ] || { echo "No value found at secret/data/x" >&2; exit 2; }
|
||||
cat "$leaf"
|
||||
;;
|
||||
"kv list")
|
||||
[ "''${BAO_TOKEN-}" = s.fake ] || { echo "fake bao: kv without the login's token" >&2; exit 97; }
|
||||
[ "$3" = -format=json ] || { echo "fake bao: kv list without -format=json" >&2; exit 98; }
|
||||
# As bao answers: a refusal and a sealed store end with status 2, the
|
||||
# error on stderr and nothing on stdout.
|
||||
[ -z "''${FAKE_BAO_LIST_DENY-}" ] || { printf 'Error listing %s: Code: 403. Errors:\n\n* 1 error occurred:\n\t* permission denied\n' "$4" >&2; exit 2; }
|
||||
[ -z "''${FAKE_BAO_LIST_SEALED-}" ] || { echo "Error making API request. Code: 503. Errors: * Vault is sealed" >&2; exit 2; }
|
||||
# An empty answer with something on stderr is not "nothing there".
|
||||
[ -z "''${FAKE_BAO_LIST_NOISY-}" ] || { echo "fake bao: a warning" >&2; echo '{}'; exit 2; }
|
||||
# A prefix that holds nothing: status 2, `{}`, nothing on stderr.
|
||||
[ -n "''${FAKE_BAO_LIST-}" ] || { echo '{}'; exit 2; }
|
||||
printf '%s\n' "$FAKE_BAO_LIST"
|
||||
;;
|
||||
"kv put")
|
||||
[ "''${BAO_TOKEN-}" = s.fake ] || { echo "fake bao: kv without the login's token" >&2; exit 97; }
|
||||
[ "$3" = -cas=0 ] || { echo "fake bao: put without -cas=0" >&2; exit 96; }
|
||||
|
|
|
|||
|
|
@ -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