Fetch replication status in its own resource (#19132)
* Fix json decode errors for Enos replication verification module Signed-off-by: Jaymala Sinha <jaymala@hashicorp.com> * Rewrite the pr connection check script Signed-off-by: Jaymala Sinha <jaymala@hashicorp.com> * Do not fail on get replication status Signed-off-by: Jaymala Sinha <jaymala@hashicorp.com> --------- Signed-off-by: Jaymala Sinha <jaymala@hashicorp.com>
This commit is contained in:
parent
3003ff85ce
commit
99d4151a38
|
@ -44,18 +44,18 @@ variable "wrapping_token" {
|
|||
}
|
||||
|
||||
locals {
|
||||
primary_replication_status = jsondecode(enos_remote_exec.verify_replication_on_primary.stdout)
|
||||
secondary_replication_status = jsondecode(enos_remote_exec.verify_replication_on_secondary.stdout)
|
||||
primary_replication_status = jsondecode(enos_remote_exec.replication_status_on_primary.stdout)
|
||||
secondary_replication_status = jsondecode(enos_remote_exec.replication_status_on_secondary.stdout)
|
||||
}
|
||||
|
||||
resource "enos_remote_exec" "verify_replication_on_primary" {
|
||||
resource "enos_remote_exec" "replication_status_on_primary" {
|
||||
environment = {
|
||||
VAULT_ADDR = "http://127.0.0.1:8200"
|
||||
VAULT_INSTALL_DIR = var.vault_install_dir
|
||||
REPLICATION_MODE = "primary"
|
||||
}
|
||||
|
||||
scripts = ["${path.module}/scripts/verify-performance-replication.sh"]
|
||||
scripts = ["${path.module}/scripts/get-replication-status.sh"]
|
||||
|
||||
transport = {
|
||||
ssh = {
|
||||
|
@ -73,14 +73,14 @@ output "primary_replication_status" {
|
|||
}
|
||||
}
|
||||
|
||||
resource "enos_remote_exec" "verify_replication_on_secondary" {
|
||||
resource "enos_remote_exec" "replication_status_on_secondary" {
|
||||
environment = {
|
||||
VAULT_ADDR = "http://127.0.0.1:8200"
|
||||
VAULT_INSTALL_DIR = var.vault_install_dir
|
||||
REPLICATION_MODE = "secondary"
|
||||
}
|
||||
|
||||
scripts = ["${path.module}/scripts/verify-performance-replication.sh"]
|
||||
scripts = ["${path.module}/scripts/get-replication-status.sh"]
|
||||
|
||||
transport = {
|
||||
ssh = {
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# This script waits for the replication status to be established
|
||||
# But the replication validations are done by Terraform so this
|
||||
# script should always exit success
|
||||
|
||||
set -e
|
||||
|
||||
binpath=${VAULT_INSTALL_DIR}/vault
|
||||
|
||||
retry() {
|
||||
local retries=$1
|
||||
shift
|
||||
local count=0
|
||||
|
||||
until "$@"; do
|
||||
exit=$?
|
||||
wait=$((10 ** count))
|
||||
count=$((count + 1))
|
||||
if [ "$count" -lt "$retries" ]; then
|
||||
sleep "$wait"
|
||||
else
|
||||
echo $pr_status
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
|
||||
echo $pr_status
|
||||
return 0
|
||||
}
|
||||
|
||||
test -x "$binpath" || exit 1
|
||||
|
||||
check_pr_status() {
|
||||
pr_status=$($binpath read -format=json sys/replication/performance/status)
|
||||
cluster_state=$(echo $pr_status | jq -r '.data.state')
|
||||
|
||||
if [[ "${REPLICATION_MODE}" == "primary" ]]; then
|
||||
connection_status=$(echo $pr_status | jq -r '.data.secondaries[0].connection_status')
|
||||
else
|
||||
connection_status=$(echo $pr_status | jq -r '.data.primaries[0].connection_status')
|
||||
fi
|
||||
|
||||
if [[ "$connection_status" == 'disconnected' ]] || [[ "$cluster_state" == 'idle' ]]; then
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Retry a few times because it can take some time for replication to sync
|
||||
retry 5 check_pr_status
|
|
@ -1,53 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
binpath=${VAULT_INSTALL_DIR}/vault
|
||||
|
||||
fail() {
|
||||
echo "$1" 2>&1
|
||||
return 1
|
||||
}
|
||||
|
||||
retry() {
|
||||
local retries=$1
|
||||
shift
|
||||
local count=0
|
||||
|
||||
until "$@"; do
|
||||
exit=$?
|
||||
wait=$((10 ** count))
|
||||
count=$((count + 1))
|
||||
if [ "$count" -lt "$retries" ]; then
|
||||
sleep "$wait"
|
||||
else
|
||||
return "$exit"
|
||||
fi
|
||||
done
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
test -x "$binpath" || fail "unable to locate vault binary at $binpath"
|
||||
|
||||
check_pr_status() {
|
||||
cluster_state=$($binpath read -format=json sys/replication/performance/status | jq -r '.data.state')
|
||||
|
||||
if [[ "${REPLICATION_MODE}" == "primary" ]]; then
|
||||
connection_status=$($binpath read -format=json sys/replication/performance/status | jq -r '.data.secondaries[0].connection_status')
|
||||
else
|
||||
connection_status=$($binpath read -format=json sys/replication/performance/status | jq -r '.data.primaries[0].connection_status')
|
||||
fi
|
||||
|
||||
if [[ "$connection_status" == 'disconnected' ]]; then
|
||||
fail "expected connection status to be connected"
|
||||
fi
|
||||
|
||||
if [[ "$cluster_state" == 'idle' ]]; then
|
||||
fail "expected cluster state to be not idle"
|
||||
fi
|
||||
}
|
||||
|
||||
# Retry a few times because it can take some time for replication to sync
|
||||
retry 5 check_pr_status
|
||||
echo $($binpath read -format=json sys/replication/performance/status)
|
Loading…
Reference in New Issue