k8s VM tests: wait for the store's active node after the unseal
The tests waited on `bao status`, which answers once the node is unsealed and before raft has elected it, so the first policy write raced the election and failed with "local node not active but active cluster node not found". `unseal_bao` unseals and then waits for sys/leader to say the node is the leader; the four tests that bootstrap the store use it at both unseal sites. Closes #6807
This commit is contained in:
parent
31f5438d36
commit
e42cdd74f8
5 changed files with 23 additions and 15 deletions
|
|
@ -293,7 +293,7 @@ pkgs.testers.runNixOSTest {
|
|||
with subtest("the store is initialised, unsealed and bootstrapped"):
|
||||
machine.wait_until_succeeds('[ "$(bao status >/dev/null 2>&1; echo $?)" = 2 ]', timeout=900)
|
||||
machine.succeed(f"umask 077 && bao operator init -key-shares=1 -key-threshold=1 -format=json > {INIT}")
|
||||
machine.succeed(f"bao operator unseal \"$(jq -r '.unseal_keys_b64[0]' {INIT})\"")
|
||||
unseal_bao(machine, INIT)
|
||||
machine.succeed(
|
||||
"set -o pipefail; "
|
||||
f'export BAO_TOKEN="$(jq -r .root_token {INIT})"; '
|
||||
|
|
@ -317,7 +317,7 @@ pkgs.testers.runNixOSTest {
|
|||
if machine.execute("journalctl -u swarm-bao-agent-pki --no-pager | grep -F 'restart openbao.service'")[0] == 0:
|
||||
machine.succeed("systemctl --machine=swarm-bao restart openbao.service")
|
||||
machine.wait_until_succeeds('[ "$(bao status >/dev/null 2>&1; echo $?)" = 2 ]', timeout=900)
|
||||
machine.succeed(f"bao operator unseal \"$(jq -r '.unseal_keys_b64[0]' {INIT})\"")
|
||||
unseal_bao(machine, INIT)
|
||||
units = [
|
||||
"swarm-bao-controller-policy",
|
||||
"swarm-bao-ci-metrics-policy",
|
||||
|
|
|
|||
|
|
@ -458,8 +458,7 @@ pkgs.testers.runNixOSTest {
|
|||
with subtest("the store is initialised, unsealed and bootstrapped"):
|
||||
machine.wait_until_succeeds('[ "$(bao status >/dev/null 2>&1; echo $?)" = 2 ]', timeout=900)
|
||||
machine.succeed(f"umask 077 && bao operator init -key-shares=1 -key-threshold=1 -format=json > {INIT}")
|
||||
machine.succeed(f"bao operator unseal \"$(jq -r '.unseal_keys_b64[0]' {INIT})\"")
|
||||
machine.wait_until_succeeds("bao status", timeout=120)
|
||||
unseal_bao(machine, INIT)
|
||||
machine.succeed(
|
||||
"set -o pipefail; "
|
||||
f'export BAO_TOKEN="$(jq -r .root_token {INIT})"; '
|
||||
|
|
@ -481,8 +480,7 @@ pkgs.testers.runNixOSTest {
|
|||
if machine.execute("journalctl -u swarm-bao-agent-pki --no-pager | grep -F 'restart openbao.service'")[0] == 0:
|
||||
machine.succeed("systemctl --machine=swarm-bao restart openbao.service")
|
||||
machine.wait_until_succeeds('[ "$(bao status >/dev/null 2>&1; echo $?)" = 2 ]', timeout=900)
|
||||
machine.succeed(f"bao operator unseal \"$(jq -r '.unseal_keys_b64[0]' {INIT})\"")
|
||||
machine.wait_until_succeeds("bao status", timeout=120)
|
||||
unseal_bao(machine, INIT)
|
||||
for unit in ["swarm-bao-controller-policy", "swarm-bao-services-issuer-policy", "swarm-bao-k8s-jwt-policy"]:
|
||||
settle(f'[ "$(systemctl is-active {unit}.service)" = active ]', 900, [f"{unit}.service"])
|
||||
machine.wait_until_succeeds(
|
||||
|
|
|
|||
|
|
@ -510,8 +510,7 @@ pkgs.testers.runNixOSTest {
|
|||
with subtest("the store is initialised, unsealed and bootstrapped"):
|
||||
machine.wait_until_succeeds('[ "$(bao status >/dev/null 2>&1; echo $?)" = 2 ]', timeout=900)
|
||||
machine.succeed(f"umask 077 && bao operator init -key-shares=1 -key-threshold=1 -format=json > {INIT}")
|
||||
machine.succeed(f"bao operator unseal \"$(jq -r '.unseal_keys_b64[0]' {INIT})\"")
|
||||
machine.wait_until_succeeds("bao status", timeout=120)
|
||||
unseal_bao(machine, INIT)
|
||||
machine.succeed(
|
||||
"set -o pipefail; "
|
||||
f'export BAO_TOKEN="$(jq -r .root_token {INIT})"; '
|
||||
|
|
@ -533,8 +532,7 @@ pkgs.testers.runNixOSTest {
|
|||
if machine.execute("journalctl -u swarm-bao-agent-pki --no-pager | grep -F 'restart openbao.service'")[0] == 0:
|
||||
machine.succeed("systemctl --machine=swarm-bao restart openbao.service")
|
||||
machine.wait_until_succeeds('[ "$(bao status >/dev/null 2>&1; echo $?)" = 2 ]', timeout=900)
|
||||
machine.succeed(f"bao operator unseal \"$(jq -r '.unseal_keys_b64[0]' {INIT})\"")
|
||||
machine.wait_until_succeeds("bao status", timeout=120)
|
||||
unseal_bao(machine, INIT)
|
||||
for unit in [
|
||||
"swarm-bao-nats-tls-policy",
|
||||
"swarm-bao-nats-auth-policy",
|
||||
|
|
|
|||
|
|
@ -547,9 +547,7 @@ pkgs.testers.runNixOSTest {
|
|||
with subtest("the store is initialised, unsealed and bootstrapped"):
|
||||
machine.wait_until_succeeds('[ "$(bao status >/dev/null 2>&1; echo $?)" = 2 ]', timeout=900)
|
||||
machine.succeed(f"umask 077 && bao operator init -key-shares=1 -key-threshold=1 -format=json > {INIT}")
|
||||
machine.succeed(f"bao operator unseal \"$(jq -r '.unseal_keys_b64[0]' {INIT})\"")
|
||||
# Right after the unseal the store has no active node for a moment.
|
||||
machine.wait_until_succeeds("bao status", timeout=120)
|
||||
unseal_bao(machine, INIT)
|
||||
machine.succeed(
|
||||
"set -o pipefail; "
|
||||
f'export BAO_TOKEN="$(jq -r .root_token {INIT})"; '
|
||||
|
|
@ -573,8 +571,7 @@ pkgs.testers.runNixOSTest {
|
|||
if machine.execute("journalctl -u swarm-bao-agent-pki --no-pager | grep -F 'restart openbao.service'")[0] == 0:
|
||||
machine.succeed("systemctl --machine=swarm-bao restart openbao.service")
|
||||
machine.wait_until_succeeds('[ "$(bao status >/dev/null 2>&1; echo $?)" = 2 ]', timeout=900)
|
||||
machine.succeed(f"bao operator unseal \"$(jq -r '.unseal_keys_b64[0]' {INIT})\"")
|
||||
machine.wait_until_succeeds("bao status", timeout=120)
|
||||
unseal_bao(machine, INIT)
|
||||
for unit in [
|
||||
"swarm-bao-notify-router-policy",
|
||||
"swarm-bao-stt-policy",
|
||||
|
|
|
|||
|
|
@ -60,6 +60,21 @@ def wait_images(node: QemuMachine, timeout: int = 120) -> None:
|
|||
)
|
||||
|
||||
|
||||
def unseal_bao(node: QemuMachine, init_file: str, timeout: int = 120) -> None:
|
||||
"""Unseals the store with the key `bao operator init` saved in `init_file`,
|
||||
then waits until the store's node is the active one. `bao status` answers
|
||||
as soon as the node is unsealed, before raft has elected it, and a write
|
||||
in that gap fails with "local node not active but active cluster node not
|
||||
found"."""
|
||||
node.succeed(f"bao operator unseal \"$(jq -r '.unseal_keys_b64[0]' {init_file})\"")
|
||||
# `sys/leader` needs no token. The answer is the bare object, or under
|
||||
# `.data` where the client wraps it.
|
||||
node.wait_until_succeeds(
|
||||
"bao read -format=json sys/leader | jq -e '(.data // .).is_self == true'",
|
||||
timeout=timeout,
|
||||
)
|
||||
|
||||
|
||||
def pod(node: QemuMachine, name: str) -> dict:
|
||||
return json.loads(kube(node, f"get pod {name} -o json"))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue