mirror of
https://github.com/kemko/nomad.git
synced 2026-01-08 03:15:42 +03:00
We're using `set -eo pipefail` everywhere in the Enos scripts, several of the scripts used for checking assertions didn't take advantage of pipefail in such a way that we could avoid early exits from transient errors. This meant that if a server was slightly late to come back up, we'd hit an error and exit the whole script instead of polling as expected. While fixing this, I've made a number of other improvements to the shell scripts: * I've changed the design of the polling loops so that we're calling a function that returns an exit code and sets `last_error` value, along with any global variables required by downstream functions. This makes the loops more readable by reducing the number of global variables, and helped identify some places where we're exiting instead of returning into the loop. * Using `shellcheck -s bash` I fixes some unused variables and undefined variables that we were missing because they were only used on the error paths.
53 lines
1.6 KiB
Bash
Executable File
53 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Copyright (c) HashiCorp, Inc.
|
|
# SPDX-License-Identifier: BUSL-1.1
|
|
|
|
set -euo pipefail
|
|
|
|
error_exit() {
|
|
printf 'Error: %s' "${1}"
|
|
exit 1
|
|
}
|
|
|
|
# Servers version
|
|
server_versions=$(nomad server members -json | jq -r '[.[] | select(.Status == "alive") | .Tags.build] | unique')
|
|
|
|
if [ "$(echo "$server_versions" | jq 'length')" -eq 0 ]; then
|
|
error_exit "Unable to get servers version"
|
|
fi
|
|
|
|
if [ "$(echo "$server_versions" | jq 'length')" -ne 1 ]; then
|
|
error_exit "Servers are running different versions: $(echo "$server_versions" | jq -c '.')"
|
|
fi
|
|
|
|
final_version=$(echo "$server_versions" | jq -r '.[0]'| xargs)
|
|
SERVERS_VERSION=$(echo "$SERVERS_VERSION" | xargs)
|
|
|
|
if [ "$final_version" != "$SERVERS_VERSION" ]; then
|
|
error_exit "Servers are not running the correct version. Found: $final_version, Expected: $SERVERS_VERSION"
|
|
fi
|
|
|
|
echo "All servers are running Nomad version $SERVERS_VERSION"
|
|
|
|
# Clients version
|
|
clients_versions=$(nomad node status -json | jq -r '[.[] | select(.Status == "ready") | .Version] | unique')
|
|
|
|
|
|
if [ "$(echo "$clients_versions" | jq 'length')" -eq 0 ]; then
|
|
error_exit "Unable to get clients version"
|
|
fi
|
|
|
|
|
|
if [ "$(echo "$clients_versions" | jq 'length')" -ne 1 ]; then
|
|
error_exit "Clients are running different versions: $(echo "$clients_versions" | jq -c '.')"
|
|
fi
|
|
|
|
final_version=$(echo "$clients_versions" | jq -r '.[0]'| xargs)
|
|
CLIENTS_VERSION=$(echo "$CLIENTS_VERSION" | xargs)
|
|
|
|
if [ "$final_version" != "$CLIENTS_VERSION" ]; then
|
|
error_exit "Clients are not running the correct version. Found: $final_version, Expected: $CLIENTS_VERSION"
|
|
fi
|
|
|
|
echo "All clients are running Nomad version $CLIENTS_VERSION"
|