[CONSUL-453] Docker hostname in Helper functions (#64)

pull/15235/head
Franco Bruno Lavayen 2 years ago committed by Jose Ignacio Lorenzo
parent f0e2b44d09
commit febc36244f

@ -1,5 +1,6 @@
#!/bin/bash
CONSUL_HOSTNAME=""
MOD_ARG=""
function split_hostport {
@ -11,6 +12,12 @@ function split_hostport {
fi
}
function get_consul_hostname {
local DC=${1:-primary}
[[ $XDS_TARGET = "client" ]] && CONSUL_HOSTNAME="consul-$DC-client" || CONSUL_HOSTNAME="consul-$DC"
}
# retry based on
# https://github.com/fernandoacorreia/azure-docker-registry/blob/master/tools/scripts/create-registry-server
# under MIT license.
@ -562,8 +569,9 @@ function assert_service_has_healthy_instances {
function check_intention {
local SOURCE=$1
local DESTINATION=$2
get_consul_hostname primary
curl -m 5 -s -f "consul-primary:8500/v1/connect/intentions/check?source=${SOURCE}&destination=${DESTINATION}" | jq ".Allowed"
curl -m 5 -s -f "${CONSUL_HOSTNAME}:8500/v1/connect/intentions/check?source=${SOURCE}&destination=${DESTINATION}" | jq ".Allowed"
}
function assert_intention_allowed {
@ -832,13 +840,16 @@ function read_config_entry {
local KIND=$1
local NAME=$2
local DC=${3:-primary}
docker_consul_exec "$DC" bash -c "consul config read -kind $KIND -name $NAME -http-addr="consul-$DC:8500""
get_consul_hostname $DC
docker_consul_exec "$DC" bash -c "consul config read -kind $KIND -name $NAME -http-addr="$CONSUL_HOSTNAME:8500""
}
function wait_for_namespace {
local NS="${1}"
local DC=${2:-primary}
retry_default docker_curl "$DC" -sLf "http://consul-${DC}:8500/v1/namespace/${NS}" >/dev/null
get_consul_hostname $DC
retry_default docker_curl "$DC" -sLf "http://${CONSUL_HOSTNAME}:8500/v1/namespace/${NS}" >/dev/null
}
function wait_for_config_entry {
@ -848,7 +859,9 @@ function wait_for_config_entry {
function delete_config_entry {
local KIND=$1
local NAME=$2
retry_default curl -sL -XDELETE "http://consul-primary:8500/v1/config/${KIND}/${NAME}"
get_consul_hostname primary
retry_default curl -sL -XDELETE "http://${CONSUL_HOSTNAME}:8500/v1/config/${KIND}/${NAME}"
}
function register_services {
@ -860,28 +873,32 @@ function register_services {
# wait_for_leader waits until a leader is elected.
# Its first argument must be the datacenter name.
function wait_for_leader {
retry_default docker_consul_exec "$1" sh -c '[[ $(curl --fail -sS http://consul-primary:8500/v1/status/leader) ]]'
get_consul_hostname primary
retry_default docker_consul_exec "$1" sh -c "[[ $(curl --fail -sS http://${CONSUL_HOSTNAME}:8500/v1/status/leader) ]]"
}
function setup_upsert_l4_intention {
local SOURCE=$1
local DESTINATION=$2
local ACTION=$3
get_consul_hostname primary
retry_default docker_consul_exec primary bash -c "curl -sL -X PUT -d '{\"Action\": \"${ACTION}\"}' 'http://consul-primary:8500/v1/connect/intentions/exact?source=${SOURCE}&destination=${DESTINATION}'"
retry_default docker_consul_exec primary bash -c "curl -sL -X PUT -d '{\"Action\": \"${ACTION}\"}' 'http://${CONSUL_HOSTNAME}:8500/v1/connect/intentions/exact?source=${SOURCE}&destination=${DESTINATION}'"
}
function upsert_l4_intention {
local SOURCE=$1
local DESTINATION=$2
local ACTION=$3
get_consul_hostname primary
retry_default curl -sL -XPUT "http://consul-primary:8500/v1/connect/intentions/exact?source=${SOURCE}&destination=${DESTINATION}" \
retry_default curl -sL -XPUT "http://${CONSUL_HOSTNAME}:8500/v1/connect/intentions/exact?source=${SOURCE}&destination=${DESTINATION}" \
-d"{\"Action\": \"${ACTION}\"}" >/dev/null
}
function get_ca_root {
curl -s -f "http://consul-primary:8500/v1/connect/ca/roots" | jq -r ".Roots[0].RootCert"
get_consul_hostname primary
curl -s -f "http://${CONSUL_HOSTNAME}:8500/v1/connect/ca/roots" | jq -r ".Roots[0].RootCert"
}
function cacert_curl {
@ -899,14 +916,16 @@ function cacert_curl {
function wait_for_agent_service_register {
local SERVICE_ID=$1
local DC=${2:-primary}
get_consul_hostname $DC
retry_default docker_consul_exec "$DC" bash -c "curl -sLf 'http://consul-${DC}:8500/v1/agent/service/${SERVICE_ID}' >/dev/null"
retry_default docker_consul_exec "$DC" bash -c "curl -sLf 'http://${CONSUL_HOSTNAME}:8500/v1/agent/service/${SERVICE_ID}' >/dev/null"
}
function set_ttl_check_state {
local CHECK_ID=$1
local CHECK_STATE=$2
local DC=${3:-primary}
get_consul_hostname $DC
case "$CHECK_STATE" in
pass)
@ -920,7 +939,7 @@ function set_ttl_check_state {
return 1
esac
retry_default docker_consul_exec "$DC" bash -c "curl -sL -XPUT 'http://consul-${DC}:8500/v1/agent/check/warn/${CHECK_ID}' >/dev/null"
retry_default docker_consul_exec "$DC" bash -c "curl -sL -XPUT 'http://${CONSUL_HOSTNAME}:8500/v1/agent/check/warn/${CHECK_ID}' >/dev/null"
}
function get_upstream_fortio_name {

@ -354,6 +354,7 @@ function verify {
# need to tell the PID 1 inside of the container that it won't be actual PID
# 1 because we're using --pid=host so we use TINI_SUBREAPER
if docker.exe exec -i ${SINGLE_CONTAINER_BASE_NAME}-${CLUSTER}_1 bash -c "TINI_SUBREAPER=1 \
XDS_TARGET=${XDS_TARGET} \
ENVOY_VERSION=${ENVOY_VERSION} \
/c/bats/bin/bats \
--pretty \
@ -464,6 +465,10 @@ function stop_and_copy_files {
}
function run_tests {
local CONSUL_VERSION=$(docker image inspect --format='{{(index (.ContainerConfig.Env) 0)}}' \
windows/consul:local | grep "VERSION=" | cut -c9-)
echo "Running Tests with Consul=$CONSUL_VERSION - Envoy=$ENVOY_VERSION - XDS_TARGET=$XDS_TARGET"
CASE_DIR="${CASE_DIR?CASE_DIR must be set to the path of the test case}"
CASE_NAME=$( basename $CASE_DIR | cut -c6- )
export CASE_NAME

Loading…
Cancel
Save