Skip to content

Cleanup anr scripts #1714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 18, 2023
38 changes: 38 additions & 0 deletions scripts/install_anr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
set -e
set -o nounset
set -o pipefail

# Avalanche root directory
AVALANCHE_PATH=$(
cd "$(dirname "${BASH_SOURCE[0]}")"
cd .. && pwd
)

# Load the constants
source "$AVALANCHE_PATH"/scripts/constants.sh

#################################
# download avalanche-network-runner
# https://github.com/ava-labs/avalanche-network-runner
GOARCH=$(go env GOARCH)
GOOS=$(go env GOOS)
NETWORK_RUNNER_VERSION=1.3.9
anr_workdir=${ANR_WORKDIR:-"/tmp"}
DOWNLOAD_PATH=${anr_workdir}/avalanche-network-runner-v${NETWORK_RUNNER_VERSION}.tar.gz
DOWNLOAD_URL="https://github.com/ava-labs/avalanche-network-runner/releases/download/v${NETWORK_RUNNER_VERSION}/avalanche-network-runner_${NETWORK_RUNNER_VERSION}_${GOOS}_${GOARCH}.tar.gz"
echo "Installing avalanche-network-runner ${NETWORK_RUNNER_VERSION} to ${anr_workdir}/avalanche-network-runner"

# download only if not already downloaded
if [ ! -f "$DOWNLOAD_PATH" ]; then
echo "downloading avalanche-network-runner ${NETWORK_RUNNER_VERSION} at ${DOWNLOAD_URL} to ${DOWNLOAD_PATH}"
curl --fail -L ${DOWNLOAD_URL} -o ${DOWNLOAD_PATH}
else
echo "avalanche-network-runner ${NETWORK_RUNNER_VERSION} already downloaded at ${DOWNLOAD_PATH}"
fi

rm -f ${anr_workdir}/avalanche-network-runner

echo "extracting downloaded avalanche-network-runner"
tar xzvf ${DOWNLOAD_PATH} -C ${anr_workdir}
${anr_workdir}/avalanche-network-runner -h
59 changes: 16 additions & 43 deletions scripts/tests.e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,14 @@ fi
AVALANCHEGO_PATH="${1-}"
if [[ -z "${AVALANCHEGO_PATH}" ]]; then
echo "Missing AVALANCHEGO_PATH argument!"
echo "Usage: ${0} [AVALANCHEGO_PATH]" >> /dev/stderr
echo "Usage: ${0} [AVALANCHEGO_PATH]" >>/dev/stderr
exit 255
fi

# Set the CGO flags to use the portable version of BLST
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing this? Don't we need it to ensure this works locally on MacOS?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

install_anr.sh includes: source "$AVALANCHE_PATH"/scripts/constants.sh which already includes:

# Set the CGO flags to use the portable version of BLST
#
# We use "export" here instead of just setting a bash variable because we need
# to pass this flag to all child processes spawned by the shell.
export CGO_CFLAGS="-O -D__BLST_PORTABLE__"
# While CGO_ENABLED doesn't need to be explicitly set, it produces a much more
# clear error due to the default value change in go1.20.
export CGO_ENABLED=1

#
# We use "export" here instead of just setting a bash variable because we need
# to pass this flag to all child processes spawned by the shell.
export CGO_CFLAGS="-O -D__BLST_PORTABLE__"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

# While CGO_ENABLED doesn't need to be explicitly set, it produces a much more
# clear error due to the default value change in go1.20.
export CGO_ENABLED=1

#################################
# download avalanche-network-runner
# https://github.com/ava-labs/avalanche-network-runner
# TODO: migrate to upstream avalanche-network-runner
GOARCH=$(go env GOARCH)
GOOS=$(go env GOOS)
NETWORK_RUNNER_VERSION=1.3.5-rc.0
DOWNLOAD_PATH=/tmp/avalanche-network-runner.tar.gz
DOWNLOAD_URL="https://github.com/ava-labs/avalanche-network-runner/releases/download/v${NETWORK_RUNNER_VERSION}/avalanche-network-runner_${NETWORK_RUNNER_VERSION}_${GOOS}_${GOARCH}.tar.gz"

rm -f ${DOWNLOAD_PATH}
rm -f /tmp/avalanche-network-runner

echo "downloading avalanche-network-runner ${NETWORK_RUNNER_VERSION} at ${DOWNLOAD_URL} to ${DOWNLOAD_PATH}"
curl --fail -L ${DOWNLOAD_URL} -o ${DOWNLOAD_PATH}

echo "extracting downloaded avalanche-network-runner"
tar xzvf ${DOWNLOAD_PATH} -C /tmp
/tmp/avalanche-network-runner -h

GOPATH="$(go env GOPATH)"
PATH="${GOPATH}/bin:${PATH}"
echo "installing avalanche-network-runner"
ANR_WORKDIR="/tmp"
./scripts/install_anr.sh

#################################
echo "building e2e.test"
Expand All @@ -60,23 +33,23 @@ ACK_GINKGO_RC=true ginkgo build ./tests/e2e
#################################
# run "avalanche-network-runner" server
echo "launch avalanche-network-runner in the background"
/tmp/avalanche-network-runner \
server \
--log-level debug \
--port=":12342" \
--disable-grpc-gateway &
$ANR_WORKDIR/avalanche-network-runner \
server \
--log-level debug \
--port=":12342" \
--disable-grpc-gateway &
PID=${!}

#################################
echo "running e2e tests against the local cluster with ${AVALANCHEGO_PATH}"
./tests/e2e/e2e.test \
--ginkgo.v \
--log-level debug \
--network-runner-grpc-endpoint="0.0.0.0:12342" \
--network-runner-avalanchego-path=${AVALANCHEGO_PATH} \
--network-runner-avalanchego-log-level="WARN" \
--test-keys-file=tests/test.insecure.secp256k1.keys \
&& EXIT_CODE=$? || EXIT_CODE=$?
--ginkgo.v \
--log-level debug \
--network-runner-grpc-endpoint="0.0.0.0:12342" \
--network-runner-avalanchego-path=${AVALANCHEGO_PATH} \
--network-runner-avalanchego-log-level="WARN" \
--test-keys-file=tests/test.insecure.secp256k1.keys &&
EXIT_CODE=$? || EXIT_CODE=$?

kill ${PID}

Expand Down
47 changes: 16 additions & 31 deletions scripts/tests.upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ fi
VERSION=$1
if [[ -z "${VERSION}" ]]; then
echo "Missing version argument!"
echo "Usage: ${0} [VERSION] [NEW-BINARY]" >> /dev/stderr
echo "Usage: ${0} [VERSION] [NEW-BINARY]" >>/dev/stderr
exit 255
fi

NEW_BINARY=$2
if [[ -z "${NEW_BINARY}" ]]; then
echo "Missing new binary path argument!"
echo "Usage: ${0} [VERSION] [NEW-BINARY]" >> /dev/stderr
echo "Usage: ${0} [VERSION] [NEW-BINARY]" >>/dev/stderr
exit 255
fi

Expand Down Expand Up @@ -52,24 +52,9 @@ fi
find /tmp/avalanchego-v${VERSION}

#################################
# download avalanche-network-runner
# https://github.com/ava-labs/avalanche-network-runner
NETWORK_RUNNER_VERSION=1.3.5-rc.0
DOWNLOAD_PATH=/tmp/avalanche-network-runner.tar.gz
DOWNLOAD_URL="https://github.com/ava-labs/avalanche-network-runner/releases/download/v${NETWORK_RUNNER_VERSION}/avalanche-network-runner_${NETWORK_RUNNER_VERSION}_${GOOS}_${GOARCH}.tar.gz"
if [[ ${GOOS} == "darwin" ]]; then
DOWNLOAD_URL="https://github.com/ava-labs/avalanche-network-runner/releases/download/v${NETWORK_RUNNER_VERSION}/avalanche-network-runner_${NETWORK_RUNNER_VERSION}_darwin_amd64.tar.gz"
fi

rm -f ${DOWNLOAD_PATH}
rm -f /tmp/avalanche-network-runner

echo "downloading avalanche-network-runner ${NETWORK_RUNNER_VERSION} at ${DOWNLOAD_URL}"
curl -L ${DOWNLOAD_URL} -o ${DOWNLOAD_PATH}

echo "extracting downloaded avalanche-network-runner"
tar xzvf ${DOWNLOAD_PATH} -C /tmp
/tmp/avalanche-network-runner -h
echo "installing avalanche-network-runner"
ANR_WORKDIR="/tmp"
./scripts/install_anr.sh

#################################
echo "building upgrade.test"
Expand All @@ -81,23 +66,23 @@ ACK_GINKGO_RC=true ginkgo build ./tests/upgrade
#################################
# run "avalanche-network-runner" server
echo "launch avalanche-network-runner in the background"
/tmp/avalanche-network-runner \
server \
--log-level debug \
--port=":12340" \
--disable-grpc-gateway &
$ANR_WORKDIR/avalanche-network-runner \
server \
--log-level debug \
--port=":12340" \
--disable-grpc-gateway &
PID=${!}

#################################
# By default, it runs all upgrade test cases!
echo "running upgrade tests against the local cluster with ${NEW_BINARY}"
./tests/upgrade/upgrade.test \
--ginkgo.v \
--log-level debug \
--network-runner-grpc-endpoint="0.0.0.0:12340" \
--network-runner-avalanchego-path=/tmp/avalanchego-v${VERSION}/avalanchego \
--network-runner-avalanchego-path-to-upgrade=${NEW_BINARY} \
--network-runner-avalanchego-log-level="WARN" || EXIT_CODE=$?
--ginkgo.v \
--log-level debug \
--network-runner-grpc-endpoint="0.0.0.0:12340" \
--network-runner-avalanchego-path=/tmp/avalanchego-v${VERSION}/avalanchego \
--network-runner-avalanchego-path-to-upgrade=${NEW_BINARY} \
--network-runner-avalanchego-log-level="WARN" || EXIT_CODE=$?

# "e2e.test" already terminates the cluster
# just in case tests are aborted, manually terminate them again
Expand Down