From f96d86f0776321a0554a5d27d6e70643f3924b27 Mon Sep 17 00:00:00 2001 From: Brad Davidson Date: Wed, 26 Oct 2022 17:10:42 +0000 Subject: [PATCH] Bump test framework versions and add hooks to helpers Signed-off-by: Brad Davidson --- Dockerfile.test | 4 +- conformance/Dockerfile | 2 +- scripts/test-helpers | 87 +++++----------------------- scripts/test-setup-sonobuoy-mysql | 18 +----- scripts/test-setup-sonobuoy-postgres | 18 +----- 5 files changed, 23 insertions(+), 106 deletions(-) diff --git a/Dockerfile.test b/Dockerfile.test index c89a7d8ed2..333ab79c47 100644 --- a/Dockerfile.test +++ b/Dockerfile.test @@ -15,9 +15,9 @@ ENTRYPOINT ["/bin/test-mods"] From test-base as test-k3s -RUN apk -U --no-cache add git gcc musl-dev docker curl coreutils python3 openssl py3-pip procps +RUN apk -U --no-cache add git gcc musl-dev docker curl coreutils python3 openssl py3-pip procps findutils -ENV SONOBUOY_VERSION 0.56.5 +ENV SONOBUOY_VERSION 0.56.10 RUN OS=linux; \ ARCH=$(go env GOARCH); \ diff --git a/conformance/Dockerfile b/conformance/Dockerfile index 2e8c0f0db5..f87e1452d3 100644 --- a/conformance/Dockerfile +++ b/conformance/Dockerfile @@ -1,5 +1,5 @@ FROM alpine:3.16 -ENV SONOBUOY_VERSION 0.56.5 +ENV SONOBUOY_VERSION 0.56.10 RUN apk add curl tar gzip RUN curl -sfL https://github.com/vmware-tanzu/sonobuoy/releases/download/v${SONOBUOY_VERSION}/sonobuoy_${SONOBUOY_VERSION}_linux_amd64.tar.gz | tar xvzf - -C /usr/bin COPY run-test.sh /usr/bin diff --git a/scripts/test-helpers b/scripts/test-helpers index 8bb52496b1..8d27cb727a 100755 --- a/scripts/test-helpers +++ b/scripts/test-helpers @@ -263,7 +263,6 @@ test-cleanup() { echo 'Cleaning up...' trap - EXIT INT TERM if has-function test-post-hook; then - echo 'Running post-hook' test-post-hook $code code=$? fi @@ -276,6 +275,9 @@ test-cleanup() { echo "Removing container $container" docker rm -f -v $container done + if has-function test-cleanup-hook; then + test-cleanup-hook + fi echo if [ "$TEST_CLEANUP" = true ]; then echo "Removing test directory $TEST_DIR" @@ -336,68 +338,6 @@ export -f test-setup # --- -gen-certs() {( - set -e -x - #umask 077 - - local opensslConfig=$(pwd)/scripts/test-certs-openssl.cnf - local subject="/C=US/ST=AZ/L=Tempe/O=Rancher/OU=DevOps/DC=com/DC=rancher" - local caDir=$TEST_DIR/db-ca - [ -d $caDir ] && rm -rf $caDir - mkdir -p $caDir - - cd $caDir - mkdir -p private certs newcerts crl - touch index.txt - echo '01' > serial - - openssl req \ - -config $opensslConfig \ - -new -x509 \ - -nodes \ - -subj $subject \ - -extensions v3_ca \ - -keyout private/ca.key \ - -out certs/ca.crt - - openssl req \ - -config $opensslConfig \ - -new \ - -nodes \ - -subj $subject"/CN=server" \ - -keyout private/db.key \ - -out db.csr - - openssl ca \ - -config $opensslConfig \ - -batch \ - -extensions db_server \ - -keyfile private/ca.key \ - -cert certs/ca.crt \ - -out certs/db.crt \ - -infiles db.csr - - openssl req \ - -config $opensslConfig \ - -new \ - -nodes \ - -subj $subject"/CN=client" \ - -keyout private/client.key \ - -out client.csr - - openssl ca \ - -config $opensslConfig \ - -batch \ - -extensions db_client \ - -keyfile private/ca.key \ - -cert certs/ca.crt \ - -out certs/client.crt \ - -infiles client.csr -)} -export -f gen-certs - -# --- - inc-count() {( shopt -s extglob local count=$(exec 2>/dev/null; ls -1d $TEST_DIR/$1/+([0-9]) | xargs -n1 basename | sort -n -r | head -1) @@ -427,7 +367,7 @@ export -f run-function provision-server() { local count=$(inc-count servers) local testID=$(basename $TEST_DIR) - local name=$(echo "k3s-server-$count-$testID" | tee $TEST_DIR/servers/$count/metadata/name) + local name=$(echo "k3s-server-${count}-${testID,,}" | tee $TEST_DIR/servers/$count/metadata/name) local port=$(timeout --foreground 5s bash -c get-port | tee $TEST_DIR/servers/$count/metadata/port) local SERVER_INSTANCE_ARGS="SERVER_${count}_ARGS" @@ -435,14 +375,15 @@ provision-server() { docker run \ -d --name $name \ + --hostname $name \ --privileged \ - -v $TEST_DIR/db-ca/:/db-ca \ -p 127.0.0.1:$port:6443 \ -p 6443 \ -e K3S_TOKEN=$(cat $TEST_DIR/metadata/secret) \ -e K3S_DEBUG=true \ + ${SERVER_DOCKER_ARGS:-} \ ${REGISTRY_CLUSTER_ARGS:-} \ - ${K3S_IMAGE_SERVER:-$K3S_IMAGE} server $ARGS $SERVER_ARGS ${!SERVER_INSTANCE_ARGS} + ${K3S_IMAGE_SERVER:-$K3S_IMAGE} server ${ARGS} ${SERVER_ARGS} ${!SERVER_INSTANCE_ARGS} local ip=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $name | tee $TEST_DIR/servers/$count/metadata/ip) local url=$(echo "https://$ip:6443" | tee $TEST_DIR/servers/$count/metadata/url) @@ -458,17 +399,21 @@ provision-agent() { local K3S_URL=${K3S_URL:-"$(cat $TEST_DIR/servers/1/metadata/url)"} local count=$(inc-count agents) local testID=$(basename $TEST_DIR) - local name=$(echo "k3s-agent-$count-$testID" | tee $TEST_DIR/agents/$count/metadata/name) + local name=$(echo "k3s-agent-${count}-${testID,,}" | tee $TEST_DIR/agents/$count/metadata/name) local AGENT_INSTANCE_ARGS="AGENT_${count}_ARGS" run-function agent-pre-hook $count docker run \ -d --name $name \ + --hostname $name \ --privileged \ -e K3S_TOKEN=$(cat $TEST_DIR/metadata/secret) \ -e K3S_URL=$K3S_URL \ + ${AGENT_DOCKER_ARGS:-} \ ${REGISTRY_CLUSTER_ARGS:-} \ - ${K3S_IMAGE_AGENT:-$K3S_IMAGE} agent $ARGS $AGENT_ARGS ${!AGENT_INSTANCE_ARGS} + ${K3S_IMAGE_AGENT:-$K3S_IMAGE} agent ${ARGS} ${AGENT_ARGS} ${!AGENT_INSTANCE_ARGS} + + local ip=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $name | tee $TEST_DIR/agents/$count/metadata/ip) echo "Started $name" run-function agent-post-hook $count @@ -592,10 +537,10 @@ cleanup-test-env(){ export SERVER_ARGS='' export WAIT_SERVICES="${all_services[@]}" - unset AGENT_1_ARGS AGENT_2_ARGS AGENT_3_ARGS - unset SERVER_1_ARGS SERVER_2_ARGS SERVER_3_ARGS + unset AGENT_1_ARGS AGENT_2_ARGS AGENT_3_ARGS AGENT_DOCKER_ARGS + unset SERVER_1_ARGS SERVER_2_ARGS SERVER_3_ARGS SERVER_DOCKER_ARGS - unset -f server-pre-hook server-post-hook agent-pre-hook agent-post-hook cluster-pre-hook cluster-post-hook test-post-hook + unset -f server-pre-hook server-post-hook agent-pre-hook agent-post-hook cluster-pre-hook cluster-post-hook test-post-hook test-cleanup-hook } # --- diff --git a/scripts/test-setup-sonobuoy-mysql b/scripts/test-setup-sonobuoy-mysql index 8862af5c5d..438241e8c7 100644 --- a/scripts/test-setup-sonobuoy-mysql +++ b/scripts/test-setup-sonobuoy-mysql @@ -5,26 +5,19 @@ # --- cluster-pre-hook() { - # gen-certs - mkdir -p $TEST_DIR/db/$LABEL_SUFFIX/metadata local testID=$(basename $TEST_DIR) - local name=$(echo $LABEL_SUFFIX-$testID | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/name) + local name=$(echo ${LABEL_SUFFIX}-${testID,,} | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/name) local port=$(timeout --foreground 5s bash -c get-port | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/port) local secret=$(echo "${RANDOM}${RANDOM}${RANDOM}" | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/secret) docker run --name $name \ --privileged \ -p 0.0.0.0:$port:3306 \ - -v $TEST_DIR/db-ca/:/db-ca \ -e MYSQL_ROOT_PASSWORD=$secret \ -e MYSQL_ROOT_HOST=% \ -d mysql:latest \ >/dev/null - # --require-secure-transport=ON \ - # --ssl-ca /db-ca/certs/ca.crt \ - # --ssl-cert /db-ca/certs/db.crt \ - # --ssl-key /db-ca/private/db.key \ local ip=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $name | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/ip) # local host=host.docker.internal @@ -32,7 +25,6 @@ cluster-pre-hook() { DB_CONNECTION_TEST=" docker run - -v $TEST_DIR/db-ca/:/db-ca --rm mysql mysql -h$host @@ -41,17 +33,11 @@ cluster-pre-hook() { -p$secret -e status" \ timeout --foreground 1m bash -c "wait-for-db-connection" - # --ssl-ca /db-ca/certs/ca.crt - # --ssl-cert /db-ca/certs/client.crt - # --ssl-key /db-ca/private/client.key echo "Started $LABEL_SUFFIX db @ $host" export SERVER_ARGS="${SERVER_ARGS} --datastore-endpoint=mysql://root:$secret@tcp($host:$port)/testdb " - # --datastore-cafile /db-ca/certs/ca.crt - # --datastore-certfile /db-ca/certs/client.crt - # --datastore-keyfile /db-ca/private/client.key } export -f cluster-pre-hook @@ -65,4 +51,4 @@ test-post-hook() { totalFails=$( grep -scF -e "[Fail]" <<< "$failures" ) [ "$totalFails" -le "$flakyFails" ] } -export -f test-post-hook \ No newline at end of file +export -f test-post-hook diff --git a/scripts/test-setup-sonobuoy-postgres b/scripts/test-setup-sonobuoy-postgres index 062459f717..01ad61cb1c 100644 --- a/scripts/test-setup-sonobuoy-postgres +++ b/scripts/test-setup-sonobuoy-postgres @@ -5,26 +5,19 @@ # --- cluster-pre-hook() { - # gen-certs - mkdir -p $TEST_DIR/db/$LABEL_SUFFIX/metadata local testID=$(basename $TEST_DIR) - local name=$(echo $LABEL_SUFFIX-$testID | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/name) + local name=$(echo ${LABEL_SUFFIX}-${testID,,} | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/name) local port=$(timeout --foreground 5s bash -c get-port | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/port) local secret=$(echo "${RANDOM}${RANDOM}${RANDOM}" | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/secret) docker run --name $name \ --privileged \ -p 0.0.0.0:$port:5432 \ - -v $TEST_DIR/db-ca/:/db-ca \ -e POSTGRES_USER=root \ -e POSTGRES_PASSWORD=$secret \ -d postgres:latest \ >/dev/null - # -c ssl=on \ - # -c ssl_ca_file=/db-ca/certs/ca.crt \ - # -c ssl_cert_file=/db-ca/certs/db.crt \ - # -c ssl_key_file=/db-ca/private/db.key \ local ip=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $name | tee $TEST_DIR/db/$LABEL_SUFFIX/metadata/ip) # local host=host.docker.internal @@ -32,7 +25,6 @@ cluster-pre-hook() { DB_CONNECTION_TEST=" docker run - -v $TEST_DIR/db-ca/:/db-ca -e PGPASSWORD=$secret --rm postgres psql @@ -41,17 +33,11 @@ cluster-pre-hook() { -U root -c \conninfo" \ timeout --foreground 1m bash -c "wait-for-db-connection" - # --set sslrootcert=/db-ca/certs/ca.crt - # --set sslcert=/db-ca/certs/client.crt - # --set sslkey=/db-ca/private/client.key echo "Started $LABEL_SUFFIX db @ $host" export SERVER_ARGS="${SERVER_ARGS} --datastore-endpoint=postgres://root:$secret@$host:$port/testdb?sslmode=disable " - # --datastore-cafile /db-ca/certs/ca.crt - # --datastore-certfile /db-ca/certs/client.crt - # --datastore-keyfile /db-ca/private/client.key } export -f cluster-pre-hook @@ -65,4 +51,4 @@ test-post-hook() { totalFails=$( grep -scF -e "[Fail]" <<< "$failures" ) [ "$totalFails" -le "$flakyFails" ] } -export -f test-post-hook \ No newline at end of file +export -f test-post-hook