From 91b3d2985197e4979456199dfa40dcad6a049049 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Sat, 22 Jul 2023 02:19:26 -0400 Subject: [PATCH 01/22] Added support for starting baas proxy --- evergreen/install_baas.sh | 100 +++++++----- evergreen/setup_baas_host.sh | 177 +++++++++++++++++--- evergreen/setup_baas_host_local.sh | 138 ++++++++++++---- evergreen/setup_baas_proxy.sh | 252 +++++++++++++++++++++++++++++ evergreen/wait_for_baas.sh | 30 ++-- 5 files changed, 586 insertions(+), 111 deletions(-) create mode 100755 evergreen/setup_baas_proxy.sh diff --git a/evergreen/install_baas.sh b/evergreen/install_baas.sh index 59310cbed26..85a30d6244f 100755 --- a/evergreen/install_baas.sh +++ b/evergreen/install_baas.sh @@ -3,7 +3,7 @@ # and will import a given app into it. # # Usage: -# ./evergreen/install_baas.sh -w {path to working directory} [-b git revision of baas] [-v] [-h] +# ./evergreen/install_baas.sh -w PATH [-b BRANCH] [-v] [-h] # # shellcheck disable=SC1091 @@ -13,6 +13,16 @@ set -o errexit set -o pipefail set -o functrace +# Set up catch function that runs when an error occurs +trap 'catch $? ${LINENO}' ERR +trap "exit" INT TERM + +function catch() +{ + # Usage: catch EXIT_CODE LINE_NUM + echo "${BASH_SOURCE[0]}: $2: Error $1 occurred while starting baas" +} + case $(uname -s) in Darwin) if [[ "$(uname -m)" == "arm64" ]]; then @@ -123,7 +133,7 @@ REALPATH="${BASE_PATH}/abspath.sh" function usage() { echo "Usage: install_baas.sh -w PATH [-b BRANCH] [-v] [-h]" - echo -e "\t-w PATH\t\tPath to working dir" + echo -e "\t-w PATH\t\tPath to working directory" echo -e "\t-b BRANCH\tOptional branch or git spec of baas to checkout/build" echo -e "\t-v\t\tEnable verbose script debugging" echo -e "\t-h\t\tShow this usage summary and exit" @@ -139,33 +149,44 @@ while getopts "w:b:vh" opt; do case "${opt}" in w) WORK_PATH="$($REALPATH "${OPTARG}")";; b) BAAS_VERSION="${OPTARG}";; - v) VERBOSE="yes"; set -o verbose; set -o xtrace;; + v) VERBOSE="yes";; h) usage 0;; *) usage 1;; esac done if [[ -z "${WORK_PATH}" ]]; then - echo "Must specify working directory" + echo "Error: Baas working directory was empty or not provided" usage 1 fi +if [[ -z "${AWS_ACCESS_KEY_ID}" || -z "${AWS_SECRET_ACCESS_KEY}" ]]; then + echo "Error: AWS_ACCESS_KEY_ID and/or AWS_SECRET_ACCESS_KEY are not set" + exit 1 +fi + +function check_port() +{ + # Usage: check_port PORT PORT_NAME + port_check=$(lsof -P "-i:${1}" | grep "LISTEN" || true) + if [[ -n "${port_check}" ]]; then + echo "Error: ${2} port (${1}) is already in use" + echo -e "${port_check}" + exit 1 + fi +} + # Check the mongodb and baas_server port availability first MONGODB_PORT=26000 -BAAS_PORT=9090 +check_port "${MONGODB_PORT}" "mongodb" -MONGODB_PORT_CHECK=$(lsof -P -i:${MONGODB_PORT} | grep "LISTEN" || true) -if [[ -n "${MONGODB_PORT_CHECK}" ]]; then - echo "Error: mongodb port (${MONGODB_PORT}) is already in use" - echo -e "${MONGODB_PORT_CHECK}" - exit 1 -fi +BAAS_PORT=9090 +check_port "${BAAS_PORT}" "baas server" -BAAS_PORT_CHECK=$(lsof -P -i:${BAAS_PORT} | grep "LISTEN" || true) -if [[ -n "${BAAS_PORT_CHECK}" ]]; then - echo "Error: baas server port (${BAAS_PORT}) is already in use" - echo -e "${BAAS_PORT_CHECK}" - exit 1 +# Wait to enable verbosity logging, if enabled +if [[ -n "${VERBOSE}" ]]; then + set -o verbose + set -o xtrace fi # Create and cd into the working directory @@ -216,13 +237,16 @@ if [[ -f "${MONGOD_PID_FILE}" ]]; then fi # Set up the cleanup function that runs at exit and stops mongod and the baas server -function cleanup() +trap 'on_exit' EXIT + +function on_exit() { + # Usage: on_exit # The baas server is being stopped (or never started), create a 'baas_stopped' file touch "${BAAS_STOPPED_FILE}" - baas_pid="" - mongod_pid="" + baas_pid= + mongod_pid= if [[ -f "${BAAS_PID_FILE}" ]]; then baas_pid="$(< "${BAAS_PID_FILE}")" fi @@ -239,16 +263,13 @@ function cleanup() fi if [[ -n "${mongod_pid}" ]]; then - echo "Killing mongod ${mongod_pid}" + echo "Stopping mongod ${mongod_pid}" kill "${mongod_pid}" echo "Waiting for processes to exit" wait fi } -trap "exit" INT TERM ERR -trap 'cleanup $?' EXIT - echo "Installing node and go to build baas and its dependencies" # Create the /node_binaries/ directory @@ -256,16 +277,16 @@ echo "Installing node and go to build baas and its dependencies" # Download node if it's not found if [[ ! -x "${NODE_BINARIES_DIR}/bin/node" ]]; then pushd "${NODE_BINARIES_DIR}" > /dev/null - ${CURL} -LsS "${NODE_URL}" | tar -xz --strip-components=1 + "${CURL}" -LsS "${NODE_URL}" | tar -xz --strip-components=1 popd > /dev/null # node_binaries fi export PATH="${NODE_BINARIES_DIR}/bin":${PATH} echo "Node version: $(node --version)" # Download go if it's not found and set up the GOROOT for building/running baas -[[ -x ${WORK_PATH}/go/bin/go ]] || (${CURL} -sL $GO_URL | tar -xz) +[[ -x ${WORK_PATH}/go/bin/go ]] || ("${CURL}" -sL $GO_URL | tar -xz) export GOROOT="${WORK_PATH}/go" -export PATH="${WORK_PATH}/go/bin":${PATH} +export PATH="${GOROOT}/bin":${PATH} echo "Go version: $(go version)" # Create the /baas_dep_binaries/ directory @@ -275,7 +296,7 @@ export PATH="${BAAS_DEPS_DIR}":${PATH} # Download jq (used for parsing json files) if it's not found if [[ ! -x "${BAAS_DEPS_DIR}/jq" ]]; then pushd "${BAAS_DEPS_DIR}" > /dev/null - which jq || (${CURL} -LsS "${JQ_DOWNLOAD_URL}" > jq && chmod +x jq) + which jq || ("${CURL}" -LsS "${JQ_DOWNLOAD_URL}" > jq && chmod +x jq) popd > /dev/null # baas_dep_binaries fi @@ -284,7 +305,7 @@ git config --global url."git@github.com:".insteadOf "https://github.com/" # If a baas branch or commit version was not provided, retrieve the latest release version if [[ -z "${BAAS_VERSION}" ]]; then - BAAS_VERSION=$(${CURL} -LsS "https://realm.mongodb.com/api/private/v1.0/version" | jq -r '.backend.git_hash') + BAAS_VERSION=$("${CURL}" -LsS "https://realm.mongodb.com/api/private/v1.0/version" | jq -r '.backend.git_hash') fi # Clone the baas repo and check out the specified version @@ -311,7 +332,7 @@ if [[ ! -d "${DYLIB_DIR}" ]]; then echo "Downloading baas support library" mkdir -p "${DYLIB_DIR}" pushd "${DYLIB_DIR}" > /dev/null - ${CURL} -LsS "${STITCH_SUPPORT_LIB_URL}" | tar -xz --strip-components=1 + "${CURL}" -LsS "${STITCH_SUPPORT_LIB_URL}" | tar -xz --strip-components=1 popd > /dev/null # baas/etc/dylib fi fi @@ -328,7 +349,7 @@ if [[ ! -x "${LIBMONGO_LIB}" ]]; then elif [[ -n "${STITCH_ASSISTED_AGG_LIB_URL}" ]]; then echo "Downloading assisted agg library (libmongo.so)" pushd "${BAAS_DEPS_DIR}" > /dev/null - ${CURL} -LsS "${STITCH_ASSISTED_AGG_LIB_URL}" > libmongo.so + "${CURL}" -LsS "${STITCH_ASSISTED_AGG_LIB_URL}" > libmongo.so chmod 755 libmongo.so popd > /dev/null # baas_dep_binaries fi @@ -338,7 +359,7 @@ fi if [[ ! -x "${BAAS_DEPS_DIR}/assisted_agg" && -n "${STITCH_ASSISTED_AGG_URL}" ]]; then echo "Downloading assisted agg binary (assisted_agg)" pushd "${BAAS_DEPS_DIR}" > /dev/null - ${CURL} -LsS "${STITCH_ASSISTED_AGG_URL}" > assisted_agg + "${CURL}" -LsS "${STITCH_ASSISTED_AGG_URL}" > assisted_agg chmod 755 assisted_agg popd > /dev/null # baas_dep_binaries fi @@ -348,7 +369,7 @@ YARN="${WORK_PATH}/yarn/bin/yarn" if [[ ! -x "${YARN}" ]]; then echo "Getting yarn" mkdir -p yarn && pushd yarn > /dev/null - ${CURL} -LsS https://yarnpkg.com/latest.tar.gz | tar -xz --strip-components=1 + "${CURL}" -LsS https://yarnpkg.com/latest.tar.gz | tar -xz --strip-components=1 popd > /dev/null # yarn mkdir "${WORK_PATH}/yarn_cache" fi @@ -367,7 +388,7 @@ fi # Download mongod (daemon) and mongosh (shell) binaries if [ ! -x "${MONGO_BINARIES_DIR}/bin/mongod" ]; then echo "Downloading mongodb" - ${CURL} -sLS "${MONGODB_DOWNLOAD_URL}" --output mongodb-binaries.tgz + "${CURL}" -sLS "${MONGODB_DOWNLOAD_URL}" --output mongodb-binaries.tgz tar -xzf mongodb-binaries.tgz rm mongodb-binaries.tgz @@ -377,7 +398,7 @@ fi if [[ -n "${MONGOSH_DOWNLOAD_URL}" ]] && [[ ! -x "${MONGO_BINARIES_DIR}/bin/mongosh" ]]; then echo "Downloading mongosh" - ${CURL} -sLS "${MONGOSH_DOWNLOAD_URL}" --output mongosh-binaries.zip + "${CURL}" -sLS "${MONGOSH_DOWNLOAD_URL}" --output mongosh-binaries.zip unzip -jnqq mongosh-binaries.zip '*/bin/*' -d "${MONGO_BINARIES_DIR}/bin/" rm mongosh-binaries.zip fi @@ -451,16 +472,15 @@ echo "Starting baas app server" --configFile=etc/configs/test_config.json --configFile="${BASE_PATH}/config_overrides.json" > "${BAAS_SERVER_LOG}" 2>&1 & echo $! > "${BAAS_PID_FILE}" -WAIT_BAAS_OPTS=() +OPT_WAIT_BAAS=("-w" "{$WORK_PATH}") if [[ -n "${VERBOSE}" ]]; then - WAIT_BAAS_OPTS=("-v") + OPT_WAIT_BAAS+=("-v") fi - -"${BASE_PATH}/wait_for_baas.sh" "${WAIT_BAAS_OPTS[@]}" -w "${WORK_PATH}" +"${BASE_PATH}/wait_for_baas.sh" "${OPT_WAIT_BAAS[@]}" # Create the admin user and set up the allowed roles -echo "Adding roles to admin user" -${CURL} 'http://localhost:9090/api/admin/v3.0/auth/providers/local-userpass/login' \ +echo "Adding roles to admi n user" +"${CURL}" 'http://localhost:9090/api/admin/v3.0/auth/providers/local-userpass/login' \ -H 'Accept: application/json' \ -H 'Content-Type: application/json' \ --silent \ diff --git a/evergreen/setup_baas_host.sh b/evergreen/setup_baas_host.sh index 2faff3e5009..82907b493e8 100755 --- a/evergreen/setup_baas_host.sh +++ b/evergreen/setup_baas_host.sh @@ -2,38 +2,58 @@ # The script to be run on the ubuntu host that will run baas for the evergreen windows tests # # Usage: -# ./evergreen/setup_baas_host.sh [-f FILE] [-b BRANCH] [-v] [-h] +# ./evergreen/setup_baas_host.sh [-b BRANCH] [-d PATH] [-t PORT] [-v] [-h] HOST_VARS # set -o errexit +set -o errtrace set -o pipefail -trap 'catch $? ${LINENO}' EXIT +trap 'catch $? ${LINENO}' ERR +trap "exit" INT TERM + +# Set up catch function that runs when an error occurs function catch() { - if [ "$1" != "0" ]; then - echo "Error $1 occurred while starting remote baas at line $2" - fi + # Usage: catch EXIT_CODE LINE_NUM + echo "${BASH_SOURCE[0]}: $2: Error $1 occurred while starting remote baas" } function usage() { - echo "Usage: setup_baas_host.sh [-b BRANCH] [-v] [-h] HOST_VARS" + # Usage: usage [EXIT_CODE] + echo "Usage: setup_baas_host.sh [-b BRANCH] [-d PATH] [-t PORT] [-v] [-h] HOST_VARS" echo -e "\tHOST_VARS\t\tPath to baas host vars script file" echo "Options:" echo -e "\t-b BRANCH\tOptional branch or git spec of baas to checkout/build" + echo -e "\t-d PATH\t\tSkip setting up the data device and use alternate data path" echo -e "\t-v\t\tEnable verbose script debugging" echo -e "\t-h\t\tShow this usage summary and exit" + echo "ToxiProxy Options:" + echo -e "\t-t PORT\t\tEnable Toxiproxy support (proxy between baas on :9090 and PORT)" # Default to 0 if exit code not provided exit "${1:0}" } BAAS_BRANCH= +OPT_DATA_DIR= +PROXY_PORT= VERBOSE= -while getopts "b:vh" opt; do +while getopts "b:d:t:vh" opt; do case "${opt}" in b) BAAS_BRANCH="${OPTARG}";; +<<<<<<< HEAD +======= + d) if [[ -z "${OPTARG}" ]]; then + echo "Error: Alternate data directory was empty" + usage 1 + fi; OPT_DATA_DIR="${OPTARG}";; + t) if [[ -z "${OPTARG}" ]]; then + echo "Error: Baas proxy port was empty"; + usage 1 + fi; PROXY_PORT="${OPTARG}";; +>>>>>>> 261ea6389 (Added support for starting baas proxy) v) VERBOSE="yes";; h) usage 0;; *) usage 1;; @@ -41,36 +61,58 @@ while getopts "b:vh" opt; do done shift $((OPTIND - 1)) + +if [[ $# -lt 1 ]]; then + echo "Error: Baas host vars script not provided" + usage 1 +fi + BAAS_HOST_VARS="${1}"; shift; if [[ -z "${BAAS_HOST_VARS}" ]]; then - echo "Baas host vars script not provided" + echo "Error: Baas host vars script value was empty" usage 1 elif [[ ! -f "${BAAS_HOST_VARS}" ]]; then - echo "Baas host vars script not found: ${BAAS_HOST_VARS}" + echo "Error: Baas host vars script not found: ${BAAS_HOST_VARS}" usage 1 fi # shellcheck disable=SC1090 source "${BAAS_HOST_VARS}" +if [[ -z "${AWS_ACCESS_KEY_ID}" ]]; then + echo "Error: AWS_ACCESS_KEY_ID was not provided by baas host vars script" + exit 1 +fi + +if [[ -z "${AWS_SECRET_ACCESS_KEY}" ]]; then + echo "Error: AWS_SECRET_ACCESS_KEY was not provided by baas host vars script" + exit 1 +fi + +if [[ -z "${REALM_CORE_REVISION}" ]]; then + echo "REALM_CORE_REVISION was not provided by baas host vars script, using 'master'" + REALM_CORE_REVISION='master' +fi + if [[ -n "${GITHUB_KNOWN_HOSTS}" ]]; then - echo "${GITHUB_KNOWN_HOSTS}" | tee -a "${HOME}/.ssh/known_hosts" + KNOWN_HOSTS_FILE="${HOME}/.ssh/known_hosts" + if [[ -f "${KNOWN_HOSTS_FILE}" ]] && ! grep -q "${GITHUB_KNOWN_HOSTS}" "${KNOWN_HOSTS_FILE}"; then + echo "${GITHUB_KNOWN_HOSTS}" | tee -a "${KNOWN_HOSTS_FILE}" + else + echo "Github known hosts entry found - skipping known_hosts update" + fi else - echo "Warning: GITHUB_KNOWN_HOSTS not defined in baas host vars script - github clone may hang or fail during setup" + echo "Warning: GITHUB_KNOWN_HOSTS not defined in baas host vars script - 'github clone' may hang or fail during setup" fi -DATA_DIR=/data -DATA_TEMP_DIR="${DATA_DIR}/tmp" -BAAS_REMOTE_DIR="${DATA_DIR}/baas-remote" -BAAS_WORK_DIR="${BAAS_REMOTE_DIR}/baas-work-dir" - -function setup_data_dir() +function init_data_device() { + #Usage: init_data_device data_device= # Find /data ebs device to be mounted - devices=$(sudo lsblk | grep disk| awk '{print $1}') + devices=$(sudo lsblk | grep disk | awk '{print $1}') for device in ${devices}; do is_data=$(sudo file -s "/dev/${device}" | awk '{print $2}') if [ "${is_data}" == "data" ]; then @@ -96,7 +138,12 @@ function setup_data_dir() fi sudo chmod 777 "${DATA_DIR}" +} +function setup_data_dir() +{ + # Usage: setup_data_dir + # Data directory is expected to be set in DATA_DIR variable # Delete /data/baas-remote/ dir if is already exists [[ -d "${BAAS_REMOTE_DIR}" ]] && sudo rm -rf "${BAAS_REMOTE_DIR}" @@ -112,10 +159,59 @@ function setup_data_dir() # Set up the temp directory mkdir -p "${DATA_TEMP_DIR}" chmod 1777 "${DATA_TEMP_DIR}" - echo "original TMP=${TMPDIR}" export TMPDIR="${DATA_TEMP_DIR}" } +function on_exit() +{ + # Usage: on_exit + baas_pid= + proxy_pid= + if [[ -f "${PROXY_PID_FILE}" ]]; then + proxy_pid="$(< "${PROXY_PID_FILE}")" + fi + + if [[ -f "${SERVER_PID_FILE}" ]]; then + baas_pid="$(< "${SERVER_PID_FILE}")" + fi + + if [[ -n "${proxy_pid}" ]]; then + echo "Stopping baas proxy ${proxy_pid}" + kill "${proxy_pid}" + fi + + if [[ -n "${baas_pid}" ]]; then + echo "Stopping baas server ${baas_pid}" + kill "${baas_pid}" + fi + + echo "Waiting for processes to exit" + wait +} + +function start_baas_proxy() +{ + # Usage: start_baas_proxy PORT + # Delete the toxiproxy working directory if it currently exists + if [[ -n "${BAAS_PROXY_DIR}" && -d "${BAAS_PROXY_DIR}" ]]; then + rm -rf "${BAAS_PROXY_DIR}" + fi + + if [[ -f "${HOME}/setup_baas_proxy.sh" ]]; then + cp "${HOME}/setup_baas_proxy.sh" evergreen/ + fi + + proxy_options= + if [[ -n "${VERBOSE}" ]]; then + proxy_options=("-v") + fi + + # Pass the baas work directory to the toxiproxy script for the go executable + ./evergreen/setup_baas_proxy.sh "${proxy_options[@]}" -b "${BAAS_WORK_DIR}" -w "${BAAS_PROXY_DIR}" -p "${1}" 2>&1 & + echo $! > "${PROXY_PID_FILE}" +} + + # Wait until after the BAAS_HOST_VARS file is loaded to enable verbose tracing if [[ -n "${VERBOSE}" ]]; then set -o verbose @@ -124,27 +220,58 @@ fi sudo chmod 600 "${HOME}/.ssh"/* +# Should an alternate data directory location be used? If so, dont init the data device +if [[ -z "${OPT_DATA_DIR}" ]]; then + DATA_DIR=/data + init_data_device +else + DATA_DIR="${OPT_DATA_DIR}" +fi + +DATA_TEMP_DIR="${DATA_DIR}/tmp" +BAAS_REMOTE_DIR="${DATA_DIR}/baas-remote" +BAAS_WORK_DIR="${BAAS_REMOTE_DIR}/baas-work-dir" +SERVER_PID_FILE="${BAAS_REMOTE_DIR}/baas-server.pid" +BAAS_PROXY_DIR="${BAAS_REMOTE_DIR}/baas-proxy-dir" +PROXY_PID_FILE="${BAAS_REMOTE_DIR}/baas-proxy.pid" + setup_data_dir pushd "${BAAS_REMOTE_DIR}" > /dev/null -git clone git@github.com:realm/realm-core.git realm-core -pushd realm-core > /dev/null + +# Clone the realm core repo and check out the specified version +if [[ ! -d "realm-core/.git" ]]; then + git clone git@github.com:realm/realm-core.git realm-core + pushd realm-core > /dev/null +else + pushd realm-core > /dev/null + git fetch +fi git checkout "${REALM_CORE_REVISION}" git submodule update --init --recursive + if [[ -f "${HOME}/install_baas.sh" ]]; then cp "${HOME}/install_baas.sh" evergreen/ fi -INSTALL_BAAS_OPTS=() +# Set up the cleanup function that runs at exit and stops baas server and proxy (if run) +trap 'on_exit' EXIT + +BAAS_OPTIONS= if [[ -n "${BAAS_BRANCH}" ]]; then - INSTALL_BAAS_OPTS=("-b" "${BAAS_BRANCH}") + BAAS_OPTIONS=("-b" "${BAAS_BRANCH}") fi if [[ -n "${VERBOSE}" ]]; then - INSTALL_BAAS_OPTS+=("-v") + BAAS_OPTIONS+=("-v") fi -./evergreen/install_baas.sh -w "${BAAS_WORK_DIR}" "${INSTALL_BAAS_OPTS[@]}" 2>&1 +./evergreen/install_baas.sh "${BAAS_OPTIONS[@]}" -w "${BAAS_WORK_DIR}" 2>&1 & +echo $! > "${SERVER_PID_FILE}" + +if [[ -n "${PROXY_PORT}" ]]; then + start_baas_proxy "${PROXY_PORT}" +fi popd > /dev/null # realm-core popd > /dev/null # /data/baas-remote diff --git a/evergreen/setup_baas_host_local.sh b/evergreen/setup_baas_host_local.sh index ad41a414288..472e4743d4c 100755 --- a/evergreen/setup_baas_host_local.sh +++ b/evergreen/setup_baas_host_local.sh @@ -2,10 +2,11 @@ # The script to be run on the ubuntu host that will run baas for the evergreen windows tests # # Usage: -# ./evergreen/setup_baas_host_local.sh -f FILE [-i FILE] [-w PATH] [-u USER] [-d PATH] [-b BRANCH] [-v] [-h] +# ./evergreen/setup_baas_host_local.sh -f FILE [-i FILE] [-w PATH] [-u USER] [-d PATH] [-b BRANCH] [-t] [-p PORT] [-c PORT] [-v] [-h] # set -o errexit +set -o errtrace set -o pipefail function usage() @@ -20,6 +21,10 @@ function usage() echo -e "\t-b BRANCH\tOptional branch or git spec of baas to checkout/build" echo -e "\t-v\t\tEnable verbose script debugging" echo -e "\t-h\t\tShow this usage summary and exit" + echo "Baas Proxy Options:" + echo -e "\t-t\t\tEnable baas proxy support (proxy between baas on :9090 and remote port)" + echo -e "\t-p PORT\t\Baas proxy listen port on remote host (default 9092)" + echo -e "\t-c PORT\t\tLocal configuration port for proxy HTTP API (default 8474)" # Default to 0 if exit code not provided exit "${1:0}" } @@ -31,51 +36,97 @@ BAAS_USER=ubuntu BAAS_BRANCH= FILE_DEST_DIR= VERBOSE= +BAAS_PROXY= +REMOTE_PORT=9092 +CONFIG_PORT=8474 -while getopts "w:u:d:b:vh" opt; do +while getopts "w:u:d:b:tp:c:vh" opt; do case "${opt}" in w) BAAS_WORK_PATH="${OPTARG}";; u) BAAS_USER="${OPTARG}";; d) FILE_DEST_DIR="${OPTARG}";; b) BAAS_BRANCH="${OPTARG}";; +<<<<<<< HEAD v) VERBOSE="yes";; +======= + t) BAAS_PROXY="yes";; + p) REMOTE_PORT="${OPTARG}";; + c) CONFIG_PORT="${OPTARG}";; + v) VERBOSE="-v";; +>>>>>>> 261ea6389 (Added support for starting baas proxy) h) usage 0;; *) usage 1;; esac done shift $((OPTIND - 1)) + +if [[ $# -lt 1 ]]; then + echo "Error: Baas host vars script not provided" + usage 1 +fi BAAS_HOST_VARS="${1}"; shift; -BAAS_HOST_KEY="${1}"; shift; if [[ -z "${BAAS_HOST_VARS}" ]]; then - echo "Baas host vars script not provided" + echo "Error: Baas host vars script value was empty" usage 1 elif [[ ! -f "${BAAS_HOST_VARS}" ]]; then - echo "Baas host vars script not found: ${BAAS_HOST_VARS}" + echo "Error: Baas host vars script not found: ${BAAS_HOST_VARS}" usage 1 fi +if [[ $# -lt 1 ]]; then + echo "Error: Baas host private key not provided" + usage 1 +fi +BAAS_HOST_KEY="${1}"; shift; + if [[ -z "${BAAS_HOST_KEY}" ]]; then - echo "Baas host private key not provided" + echo "Error: Baas host private key value was empty" usage 1 elif [[ ! -f "${BAAS_HOST_KEY}" ]]; then - echo "Baas host private key not found: ${BAAS_HOST_KEY}" + echo "Error: Baas host private key not found: ${BAAS_HOST_KEY}" usage 1 fi -trap 'catch $? ${LINENO}' EXIT +function check_port() +{ + # Usage check_port PORT + port=${1} + if [[ -n "${port}" && ${port} -gt 0 && ${port} -lt 65536 ]]; then + return 0 + fi + return 1 +} + +if [[ -n "${BAAS_PROXY}" ]]; then + if ! check_port "${CONFIG_PORT}"; then + echo "Error: Baas proxy local HTTP API config port was invalid: '${CONFIG_PORT}'" + usage 1 + elif ! check_port "${REMOTE_PORT}"; then + echo "Error: Baas proxy listen port was invalid: '${REMOTE_PORT}'" + usage 1 + fi +fi + +trap 'catch $? ${LINENO}' ERR +trap 'on_exit' INT TERM EXIT + +# Set up catch function that runs when an error occurs function catch() { - if [ "$1" != "0" ]; then - echo "Error $1 occurred while starting baas (local) at line $2" - fi - - if [[ -n "${BAAS_WORK_PATH}" ]]; then - # Create the baas_stopped file so wait_for_baas can exit early - [[ -d "${BAAS_WORK_PATH}" ]] || mkdir -p "${BAAS_WORK_PATH}" - touch "${BAAS_WORK_PATH}/baas_stopped" - fi + # Usage: catch EXIT_CODE LINE_NUM + echo "${BASH_SOURCE[0]}: $2: Error $1 occurred while starting baas (local)" +} + +function on_exit() +{ + # Usage: on_exit + if [[ -n "${BAAS_WORK_PATH}" ]]; then + # Create the baas_stopped file so wait_for_baas can exit early + [[ -d "${BAAS_WORK_PATH}" ]] || mkdir -p "${BAAS_WORK_PATH}" + touch "${BAAS_WORK_PATH}/baas_stopped" + fi } # shellcheck disable=SC1090 @@ -88,19 +139,12 @@ if [[ -n "${VERBOSE}" ]]; then fi if [[ -z "${BAAS_HOST_NAME}" ]]; then - echo "Baas hostname not found in baas host vars script: ${BAAS_HOST_VARS}" + echo "Error: BAAS_HOST_NAME was not exported by baas host vars script" usage 1 fi -if [[ -z "${BAAS_HOST_KEY}" ]]; then - echo "Baas host private key not provided" - usage 1 -elif [[ ! -f "${BAAS_HOST_KEY}" ]]; then - echo "Baas host private key not found: ${BAAS_HOST_KEY}" - usage 1 -fi if [[ -z "${BAAS_USER}" ]]; then - echo "Baas host username not provided" + echo "Error: Baas host username was empty" usage 1 fi @@ -154,16 +198,40 @@ scp "${SSH_OPTIONS[@]}" "${BAAS_HOST_VARS}" "${SSH_USER}:${FILE_DEST_DIR}/" scp "${SSH_OPTIONS[@]}" "${EVERGREEN_PATH}/setup_baas_host.sh" "${SSH_USER}:${FILE_DEST_DIR}/" scp "${SSH_OPTIONS[@]}" "${EVERGREEN_PATH}/install_baas.sh" "${SSH_USER}:${FILE_DEST_DIR}/" -echo "Starting remote baas with branch/commit: '${BAAS_BRANCH}'" -SETUP_BAAS_OPTS=() -if [[ -n "${BAAS_BRANCH}" ]]; then - SETUP_BAAS_OPTS=("-b" "${BAAS_BRANCH}") -fi +BAAS_TUNNELS=() +EXTRA_OPTIONS=() + if [[ -n "${VERBOSE}" ]]; then - SETUP_BAAS_OPTS+=("-v") + EXTRA_OPTIONS+=("-v") +fi + +if [[ -n "${BAAS_PROXY}" ]]; then + echo "Transferring baas proxy setup script to ${SSH_USER}:${FILE_DEST_DIR}" + scp "${SSH_OPTIONS[@]}" "${EVERGREEN_PATH}/setup_baas_proxy.sh" "${SSH_USER}:${FILE_DEST_DIR}/" + + # Add extra tunnel for baas proxy HTTP API config interface + BAAS_TUNNELS=("-L" "${CONFIG_PORT}:127.0.0.1:8474") + # Enable baas proxy and use ${REMOTE_PORT} as the proxy listen port + EXTRA_OPTIONS+=("-t" "${REMOTE_PORT}") +else + # Force remote port to 9090 if baas proxy is not used - connect directly to baas + REMOTE_PORT=9090 fi +BAAS_TUNNELS+=("-L" "9090:127.0.0.1:${REMOTE_PORT}") + # Run the setup baas host script and provide the location of the baas host vars script -# Also sets up a forward tunnel for port 9090 through the ssh connection to the baas remote host -echo "Running setup script (with forward tunnel to 127.0.0.1:9090)" -ssh "${SSH_OPTIONS[@]}" -L 9090:127.0.0.1:9090 "${SSH_USER}" "${FILE_DEST_DIR}/setup_baas_host.sh" "${SETUP_BAAS_OPTS[@]}" "${FILE_DEST_DIR}/baas_host_vars.sh" +# Also sets up a forward tunnel for local port 9090 through the ssh connection to the baas remote host +# If baas proxy is enabled, a second forward tunnel is added for the HTTP API config interface +echo "Running setup script (with forward tunnel on :9090 to 127.0.0.1:${REMOTE_PORT})" +if [[ -n "${BAAS_BRANCH}" ]]; then + echo "- Starting remote baas with branch/commit: '${BAAS_BRANCH}'" + EXTRA_OPTIONS+=("-b" "${BAAS_BRANCH}") +fi +if [[ -n "${BAAS_PROXY}" ]]; then + echo "- Baas proxy enabled - local HTTP API config port 127.0.0.1:${CONFIG_PORT}" +fi + +# shellcheck disable=SC2029 +ssh "${SSH_OPTIONS[@]}" "${BAAS_TUNNELS[@]}" "${SSH_USER}" \ + "${FILE_DEST_DIR}/setup_baas_host.sh" "${EXTRA_OPTIONS[@]}" "${FILE_DEST_DIR}/baas_host_vars.sh" diff --git a/evergreen/setup_baas_proxy.sh b/evergreen/setup_baas_proxy.sh new file mode 100755 index 00000000000..7accbd119c3 --- /dev/null +++ b/evergreen/setup_baas_proxy.sh @@ -0,0 +1,252 @@ +#!/usr/bin/env bash +# The script to download, build and run toxiproxy as a proxy to the baas server +# for simulating network error conditions for testing. +# +# Usage: +# ./evergreen/setup_baas_proxy.sh -w PATH [-p PORT] [-b PATH] [-c BRANCH] [-v] [-h] +# + +set -o errexit +set -o errtrace +set -o pipefail + +trap 'catch $? ${LINENO}' ERR +trap "exit" INT TERM + +function catch() +{ + echo "Error $1 occurred while starting baas proxy at line $2" +} + +WORK_PATH= +BAAS_PATH= +TOXIPROXY_VERSION="v2.5.0" +REMOTE_PORT=9092 +BAAS_PORT=9090 +VERBOSE= + +function usage() +{ + echo "Usage: setup_baas_proxy.sh -w PATH [-p PORT] [-b PATH] [-c BRANCH] [-v] [-h]" + echo "Options:" + echo -e "\t-w PATH\t\tPath to baas proxy working directory" + echo -e "\t-p PORT\t\tRemote port for proxy connected to baas (default: ${REMOTE_PORT})" + echo -e "\t-b PATH\t\tOptional path to baas working directory (for go binary)" + echo -e "\t-c BRANCH\tOptional branch or git spec to checkout/build (default: ${TOXIPROXY_VERSION})" + echo -e "\t-v\t\tEnable verbose script debugging" + echo -e "\t-h\t\tShow this usage summary and exit" + # Default to 0 if exit code not provided + exit "${1:0}" +} + +BASE_PATH="$(cd "$(dirname "$0")"; pwd)" + +# Allow path to CURL to be overloaded by an environment variable +CURL="${CURL:=$LAUNCHER curl}" + +while getopts "w:p:b:c:vh" opt; do + case "${opt}" in + w) WORK_PATH="${OPTARG}";; + p) REMOTE_PORT="${OPTARG}";; + b) BAAS_PATH="${OPTARG}";; + c) TOXIPROXY_VERSION="${OPTARG}";; + v) VERBOSE="-v"; set -o verbose; set -o xtrace;; + h) usage 0;; + *) usage 1;; + esac +done + +if [[ -z "${WORK_PATH}" ]]; then + echo "Baas proxy work path was not provided" + usage 1 +fi +if [[ -z "${REMOTE_PORT}" ]]; then + echo "Baas proxy remote port was empty" + usage 1 +fi + +function check_port() +{ + # Usage: check_port PORT PORT_NAME + port_check=$(lsof -P "-i:${1}" | grep "LISTEN" || true) + if [[ -n "${port_check}" ]]; then + echo "Error: ${2} port (${1}) is already in use" + echo -e "${port_check}" + exit 1 + fi +} + +# Check the mongodb and baas_server port availability first +check_port "${REMOTE_PORT}" "baas proxy" + + +[[ -d "${WORK_PATH}" ]] || mkdir -p "${WORK_PATH}" +pushd "${WORK_PATH}" > /dev/null + +PROXY_CFG_FILE="${WORK_PATH}/baas_proxy.json" +PROXY_LOG="${WORK_PATH}/baas_proxy.log" +PROXY_PID_FILE="${WORK_PATH}/baas_proxy.pid" +PROXY_STOPPED_FILE="${WORK_PATH}/baas_proxy_stopped" + +# Remove some files from a previous run if they exist +if [[ -f "${CONFIG_FILE}" ]]; then + rm "${CONFIG_FILE}" +fi +if [[ -f "${PROXY_LOG}" ]]; then + rm "${PROXY_LOG}" +fi +if [[ -f "${PROXY_PID_FILE}" ]]; then + rm "${PROXY_PID_FILE}" +fi + +if [[ -f "${PROXY_STOPPED}" ]]; then + rm "${PROXY_STOPPED}" +fi + +# Set up the cleanup function that runs at exit and stops the toxiproxy server +trap 'on_exit' EXIT + +function on_exit() +{ + # Usage: on_exit + # Toxiproxy is being stopped (or never started), create a 'baas-proxy-stopped' file + touch "${PROXY_STOPPED_FILE}" + + proxy_pid= + if [[ -f "${PROXY_PID_FILE}" ]]; then + proxy_pid="$(< "${PROXY_PID_FILE}")" + fi + + if [[ -n "${proxy_pid}" ]]; then + echo "Stopping toxiproxy server ${proxy_pid}" + kill "${proxy_pid}" + echo "Waiting for toxiproxy to stop" + wait + fi +} + +case $(uname -s) in + Darwin) + if [[ "$(uname -m)" == "arm64" ]]; then + export GOARCH=arm64 + GO_URL="https://s3.amazonaws.com/static.realm.io/evergreen-assets/go1.19.3.darwin-arm64.tar.gz" + # Go's scheduler is not BIG.little aware, and by default will spawn + # threads until they end up getting scheduled on efficiency cores, + # which is slower than just not using them. Limiting the threads to + # the number of performance cores results in them usually not + # running on efficiency cores. Checking the performance core count + # wasn't implemented until the first CPU with a performance core + # count other than 4 was released, so if it's unavailable it's 4. + GOMAXPROCS="$(sysctl -n hw.perflevel0.logicalcpu || echo 4)" + export GOMAXPROCS + else + export GOARCH=amd64 + GO_URL="https://s3.amazonaws.com/static.realm.io/evergreen-assets/go1.19.1.darwin-amd64.tar.gz" + fi + ;; + Linux) + GO_URL="https://s3.amazonaws.com/static.realm.io/evergreen-assets/go1.19.1.linux-amd64.tar.gz" + ;; +esac + +# If a baas path was provided look for go (or wait up to 10 seconds for it +# to become available) +GOROOT= +if [[ -n "${BAAS_PATH}" ]]; then + WAIT_COUNTER=0 + RETRY_COUNT=10 + WAIT_START=$(date -u +'%s') + FOUND_GO="yes" + BAAS_GO_DIR="${BAAS_PATH}/go" + BAAS_STOPPED_FILE="${BAAS_PATH}/baas_stopped" + until [[ -x "${BAAS_GO_DIR}/bin/go" ]]; do + if [[ -n "${BAAS_STOPPED_FILE}" && -f "${BAAS_STOPPED_FILE}" ]]; then + echo "Error: Baas server failed to start (found baas_stopped file)" + exit 1 + fi + ((++WAIT_COUNTER)) + if [[ ${WAIT_COUNTER} -ge ${RETRY_COUNT} ]]; then + FOUND_GO= + secs_spent_waiting=$(($(date -u +'%s') - WAIT_START)) + echo "Error: Stopped after waiting ${secs_spent_waiting} seconds for baas go to become available" + break + fi + sleep 2 + done + if [[ -n "${FOUND_GO}" ]]; then + echo "Found go in baas working directory" + GOROOT="${BAAS_GO_DIR}" + fi +fi + +# If GOROOT is not set, then baas path was nor provided or go was not found +if [[ -z "${GOROOT}" ]]; then + # Download go if it's not found in the working directory + if [[ ! -x ${WORK_PATH}/go/bin/go ]]; then + if [[ -z "${GO_URL}" ]]; then + echo "Error: go url not defined for current OS architecture" + uname -a + exit 1 + fi + echo "Downloading go to build Toxiproxy" + "${CURL}" -sL "${GO_URL}" | tar -xz + else + echo "Found go in baas proxy working directory" + fi + # Set up the GOROOT for building/running baas + export GOROOT="${WORK_PATH}/go" +fi +export PATH="${GOROOT}/bin":${PATH} +echo "Go version: $(go version)" + +if [[ ! -d "toxiproxy" ]]; then + git clone git@github.com:Shopify/toxiproxy.git toxiproxy +fi + +# Clone the baas repo and check out the specified version +if [[ ! -d "toxiproxy/.git" ]]; then + git clone git@github.com:Shopify/toxiproxy.git toxiproxy + pushd toxiproxy > /dev/null +else + pushd toxiproxy > /dev/null + git fetch +fi + +pushd toxiproxy > /dev/null + +echo "Checking out Toxiproxy version '${TOXIPROXY_VERSION}'" +git checkout "${TOXIPROXY_VERSION}" +echo "Using Toxiproxy commit: $(git rev-parse HEAD)" + +# Build toxiproxy +make build + +# Wait for baas to start before starting Toxiproxy +OPT_WAIT_BAAS=() +if [[ -n "${BAAS_PATH}" ]]; then + OPT_WAIT_BAAS=("-w" "{$BAAS_PATH}") +fi +if [[ -n "${VERBOSE}" ]]; then + OPT_WAIT_BAAS+=("-v") +fi +"${BASE_PATH}/wait_for_baas.sh" "${OPT_WAIT_BAAS[@]}" + +cat >"${PROXY_CFG_FILE}" < "${PROXY_LOG}" 2>&1 & +echo $! > "${PROXY_PID_FILE}" + +echo "---------------------------------------------" +echo "Baas proxy ready" +echo "---------------------------------------------" +wait + +popd > /dev/null # toxiproxy +popd > /dev/null # / diff --git a/evergreen/wait_for_baas.sh b/evergreen/wait_for_baas.sh index f7f5605e1f1..ffc61db6e0b 100755 --- a/evergreen/wait_for_baas.sh +++ b/evergreen/wait_for_baas.sh @@ -20,15 +20,14 @@ BAAS_STOPPED_FILE= RETRY_COUNT=120 BAAS_SERVER_LOG= STATUS_OUT= -VERBOSE= function usage() { echo "Usage: wait_for_baas.sh [-w PATH] [-p FILE] [-r COUNT] [-l FILE] [-s] [-v] [-h]" echo -e "\t-w PATH\t\tPath to baas server working directory" - echo -e "\t-p FILE\t\tPath to baas server pid file" + echo -e "\t-p FILE\t\tPath to baas server pid file (also set by -w option)" echo -e "\t-r COUNT\tNumber of attempts to check for baas server (default 120)" - echo -e "\t-l FILE\t\tPath to baas server log file" + echo -e "\t-l FILE\t\tPath to baas server log file (also set by -w option)" echo -e "\t-s\t\tDisplay a status for each attempt" echo -e "\t-v\t\tEnable verbose script debugging" echo -e "\t-h\t\tShow this usage summary and exit" @@ -52,7 +51,7 @@ while getopts "w:p:r:l:svh" opt; do r) RETRY_COUNT="${OPTARG}";; l) BAAS_SERVER_LOG="${OPTARG}";; s) STATUS_OUT="yes";; - v) VERBOSE="yes"; set -o verbose; set -o xtrace;; + v) set -o verbose; set -o xtrace;; h) usage 0;; *) usage 1;; esac @@ -61,30 +60,39 @@ done WAIT_COUNTER=0 WAIT_START=$(date -u +'%s') +function output_log_tail() +{ + if [[ -n "${BAAS_SERVER_LOG}" && -f "${BAAS_SERVER_LOG}" ]]; then + tail -n 10 "${BAAS_SERVER_LOG}" + fi +} + until $CURL --output /dev/null --head --fail http://localhost:9090 --silent ; do if [[ -n "${BAAS_STOPPED_FILE}" && -f "${BAAS_STOPPED_FILE}" ]]; then echo "Baas server failed to start (found baas_stopped file)" + output_log_tail exit 1 fi if [[ -n "${BAAS_PID_FILE}" && -f "${BAAS_PID_FILE}" ]]; then - pgrep -F "${BAAS_PID_FILE}" > /dev/null || (echo "Baas server $(< "${BAAS_PID_FILE}") is not running"; exit 1) + if ! pgrep -F "${BAAS_PID_FILE}" > /dev/null; then + echo "Baas server $(< "${BAAS_PID_FILE}") is no longer running" + output_log_tail + exit 1 + fi fi ((++WAIT_COUNTER)) + secs_spent_waiting=$(($(date -u +'%s') - WAIT_START)) if [[ ${WAIT_COUNTER} -ge ${RETRY_COUNT} ]]; then - echo "Timed out waiting for baas server to start" + echo "Timed out after ${secs_spent_waiting} secs waiting for baas server to start" + output_log_tail exit 1 fi if [[ -n "${STATUS_OUT}" ]]; then - secs_spent_waiting=$(($(date -u +'%s') - WAIT_START)) echo "Waiting for baas server to start... ${secs_spent_waiting} secs so far" fi - if [[ -n "${VERBOSE}" && -n "${BAAS_SERVER_LOG}" && -f "${BAAS_SERVER_LOG}" ]]; then - tail -n 5 "${BAAS_SERVER_LOG}" - fi - sleep 5 done From fed0eccd21dd0ef2a48f36ed99990a4693752d3b Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Sat, 22 Jul 2023 18:38:14 -0400 Subject: [PATCH 02/22] Fixed some issues when running the scripts --- evergreen/install_baas.sh | 25 ++++++------ evergreen/setup_baas_host.sh | 7 ++-- evergreen/setup_baas_proxy.sh | 72 ++++++++++++++++++----------------- evergreen/wait_for_baas.sh | 1 + 4 files changed, 56 insertions(+), 49 deletions(-) diff --git a/evergreen/install_baas.sh b/evergreen/install_baas.sh index 85a30d6244f..a095177d104 100755 --- a/evergreen/install_baas.sh +++ b/evergreen/install_baas.sh @@ -277,14 +277,14 @@ echo "Installing node and go to build baas and its dependencies" # Download node if it's not found if [[ ! -x "${NODE_BINARIES_DIR}/bin/node" ]]; then pushd "${NODE_BINARIES_DIR}" > /dev/null - "${CURL}" -LsS "${NODE_URL}" | tar -xz --strip-components=1 + ${CURL} -LsS "${NODE_URL}" | tar -xz --strip-components=1 popd > /dev/null # node_binaries fi export PATH="${NODE_BINARIES_DIR}/bin":${PATH} echo "Node version: $(node --version)" # Download go if it's not found and set up the GOROOT for building/running baas -[[ -x ${WORK_PATH}/go/bin/go ]] || ("${CURL}" -sL $GO_URL | tar -xz) +[[ -x ${WORK_PATH}/go/bin/go ]] || (${CURL} -sL $GO_URL | tar -xz) export GOROOT="${WORK_PATH}/go" export PATH="${GOROOT}/bin":${PATH} echo "Go version: $(go version)" @@ -296,7 +296,7 @@ export PATH="${BAAS_DEPS_DIR}":${PATH} # Download jq (used for parsing json files) if it's not found if [[ ! -x "${BAAS_DEPS_DIR}/jq" ]]; then pushd "${BAAS_DEPS_DIR}" > /dev/null - which jq || ("${CURL}" -LsS "${JQ_DOWNLOAD_URL}" > jq && chmod +x jq) + which jq || (${CURL} -LsS "${JQ_DOWNLOAD_URL}" > jq && chmod +x jq) popd > /dev/null # baas_dep_binaries fi @@ -305,7 +305,7 @@ git config --global url."git@github.com:".insteadOf "https://github.com/" # If a baas branch or commit version was not provided, retrieve the latest release version if [[ -z "${BAAS_VERSION}" ]]; then - BAAS_VERSION=$("${CURL}" -LsS "https://realm.mongodb.com/api/private/v1.0/version" | jq -r '.backend.git_hash') + BAAS_VERSION=$(${CURL} -LsS "https://realm.mongodb.com/api/private/v1.0/version" | jq -r '.backend.git_hash') fi # Clone the baas repo and check out the specified version @@ -332,7 +332,7 @@ if [[ ! -d "${DYLIB_DIR}" ]]; then echo "Downloading baas support library" mkdir -p "${DYLIB_DIR}" pushd "${DYLIB_DIR}" > /dev/null - "${CURL}" -LsS "${STITCH_SUPPORT_LIB_URL}" | tar -xz --strip-components=1 + ${CURL} -LsS "${STITCH_SUPPORT_LIB_URL}" | tar -xz --strip-components=1 popd > /dev/null # baas/etc/dylib fi fi @@ -349,7 +349,7 @@ if [[ ! -x "${LIBMONGO_LIB}" ]]; then elif [[ -n "${STITCH_ASSISTED_AGG_LIB_URL}" ]]; then echo "Downloading assisted agg library (libmongo.so)" pushd "${BAAS_DEPS_DIR}" > /dev/null - "${CURL}" -LsS "${STITCH_ASSISTED_AGG_LIB_URL}" > libmongo.so + ${CURL} -LsS "${STITCH_ASSISTED_AGG_LIB_URL}" > libmongo.so chmod 755 libmongo.so popd > /dev/null # baas_dep_binaries fi @@ -359,7 +359,7 @@ fi if [[ ! -x "${BAAS_DEPS_DIR}/assisted_agg" && -n "${STITCH_ASSISTED_AGG_URL}" ]]; then echo "Downloading assisted agg binary (assisted_agg)" pushd "${BAAS_DEPS_DIR}" > /dev/null - "${CURL}" -LsS "${STITCH_ASSISTED_AGG_URL}" > assisted_agg + ${CURL} -LsS "${STITCH_ASSISTED_AGG_URL}" > assisted_agg chmod 755 assisted_agg popd > /dev/null # baas_dep_binaries fi @@ -369,7 +369,7 @@ YARN="${WORK_PATH}/yarn/bin/yarn" if [[ ! -x "${YARN}" ]]; then echo "Getting yarn" mkdir -p yarn && pushd yarn > /dev/null - "${CURL}" -LsS https://yarnpkg.com/latest.tar.gz | tar -xz --strip-components=1 + ${CURL} -LsS https://yarnpkg.com/latest.tar.gz | tar -xz --strip-components=1 popd > /dev/null # yarn mkdir "${WORK_PATH}/yarn_cache" fi @@ -388,7 +388,7 @@ fi # Download mongod (daemon) and mongosh (shell) binaries if [ ! -x "${MONGO_BINARIES_DIR}/bin/mongod" ]; then echo "Downloading mongodb" - "${CURL}" -sLS "${MONGODB_DOWNLOAD_URL}" --output mongodb-binaries.tgz + ${CURL} -sLS "${MONGODB_DOWNLOAD_URL}" --output mongodb-binaries.tgz tar -xzf mongodb-binaries.tgz rm mongodb-binaries.tgz @@ -398,7 +398,7 @@ fi if [[ -n "${MONGOSH_DOWNLOAD_URL}" ]] && [[ ! -x "${MONGO_BINARIES_DIR}/bin/mongosh" ]]; then echo "Downloading mongosh" - "${CURL}" -sLS "${MONGOSH_DOWNLOAD_URL}" --output mongosh-binaries.zip + ${CURL} -sLS "${MONGOSH_DOWNLOAD_URL}" --output mongosh-binaries.zip unzip -jnqq mongosh-binaries.zip '*/bin/*' -d "${MONGO_BINARIES_DIR}/bin/" rm mongosh-binaries.zip fi @@ -476,11 +476,12 @@ OPT_WAIT_BAAS=("-w" "{$WORK_PATH}") if [[ -n "${VERBOSE}" ]]; then OPT_WAIT_BAAS+=("-v") fi + "${BASE_PATH}/wait_for_baas.sh" "${OPT_WAIT_BAAS[@]}" # Create the admin user and set up the allowed roles -echo "Adding roles to admi n user" -"${CURL}" 'http://localhost:9090/api/admin/v3.0/auth/providers/local-userpass/login' \ +echo "Adding roles to admin user" +${CURL} 'http://localhost:9090/api/admin/v3.0/auth/providers/local-userpass/login' \ -H 'Accept: application/json' \ -H 'Content-Type: application/json' \ --silent \ diff --git a/evergreen/setup_baas_host.sh b/evergreen/setup_baas_host.sh index 82907b493e8..1b405a92ac5 100755 --- a/evergreen/setup_baas_host.sh +++ b/evergreen/setup_baas_host.sh @@ -97,10 +97,10 @@ fi if [[ -n "${GITHUB_KNOWN_HOSTS}" ]]; then KNOWN_HOSTS_FILE="${HOME}/.ssh/known_hosts" - if [[ -f "${KNOWN_HOSTS_FILE}" ]] && ! grep -q "${GITHUB_KNOWN_HOSTS}" "${KNOWN_HOSTS_FILE}"; then - echo "${GITHUB_KNOWN_HOSTS}" | tee -a "${KNOWN_HOSTS_FILE}" - else + if [[ -f "${KNOWN_HOSTS_FILE}" ]] && grep "${GITHUB_KNOWN_HOSTS}" < "${KNOWN_HOSTS_FILE}"; then echo "Github known hosts entry found - skipping known_hosts update" + else + echo "${GITHUB_KNOWN_HOSTS}" | tee -a "${KNOWN_HOSTS_FILE}" fi else echo "Warning: GITHUB_KNOWN_HOSTS not defined in baas host vars script - 'github clone' may hang or fail during setup" @@ -272,6 +272,7 @@ echo $! > "${SERVER_PID_FILE}" if [[ -n "${PROXY_PORT}" ]]; then start_baas_proxy "${PROXY_PORT}" fi +wait # Wait for scripts to be exited... popd > /dev/null # realm-core popd > /dev/null # /data/baas-remote diff --git a/evergreen/setup_baas_proxy.sh b/evergreen/setup_baas_proxy.sh index 7accbd119c3..59500866cb1 100755 --- a/evergreen/setup_baas_proxy.sh +++ b/evergreen/setup_baas_proxy.sh @@ -152,47 +152,51 @@ esac # If a baas path was provided look for go (or wait up to 10 seconds for it # to become available) GOROOT= -if [[ -n "${BAAS_PATH}" ]]; then - WAIT_COUNTER=0 - RETRY_COUNT=10 - WAIT_START=$(date -u +'%s') - FOUND_GO="yes" - BAAS_GO_DIR="${BAAS_PATH}/go" - BAAS_STOPPED_FILE="${BAAS_PATH}/baas_stopped" - until [[ -x "${BAAS_GO_DIR}/bin/go" ]]; do - if [[ -n "${BAAS_STOPPED_FILE}" && -f "${BAAS_STOPPED_FILE}" ]]; then - echo "Error: Baas server failed to start (found baas_stopped file)" - exit 1 +if [[ ! -x ${WORK_PATH}/go/bin/go ]]; then + # If the baas work path is set, check there first and wait + if [[ -n "${BAAS_PATH}" && -d "${BAAS_PATH}" ]]; then + WAIT_COUNTER=0 + RETRY_COUNT=10 + WAIT_START=$(date -u +'%s') + FOUND_GO="yes" + BAAS_GO_DIR="${BAAS_PATH}/go" + BAAS_STOPPED_FILE="${BAAS_PATH}/baas_stopped" + echo "Looking for go in baas work path for 20 secs in case both are starting concurrently" + until [[ -x "${BAAS_GO_DIR}/bin/go" ]]; do + if [[ -n "${BAAS_STOPPED_FILE}" && -f "${BAAS_STOPPED_FILE}" ]]; then + echo "Error: Baas server failed to start (found baas_stopped file)" + exit 1 + fi + if [[ ${WAIT_COUNTER} -ge ${RETRY_COUNT} ]]; then + FOUND_GO= + secs_spent_waiting=$(($(date -u +'%s') - WAIT_START)) + echo "Error: Stopped after waiting ${secs_spent_waiting} seconds for baas go to become available" + break + fi + ((++WAIT_COUNTER)) + sleep 2 + done + if [[ -n "${FOUND_GO}" ]]; then + echo "Found go in baas working directory" + GOROOT="${BAAS_GO_DIR}" fi - ((++WAIT_COUNTER)) - if [[ ${WAIT_COUNTER} -ge ${RETRY_COUNT} ]]; then - FOUND_GO= - secs_spent_waiting=$(($(date -u +'%s') - WAIT_START)) - echo "Error: Stopped after waiting ${secs_spent_waiting} seconds for baas go to become available" - break - fi - sleep 2 - done - if [[ -n "${FOUND_GO}" ]]; then - echo "Found go in baas working directory" - GOROOT="${BAAS_GO_DIR}" fi -fi -# If GOROOT is not set, then baas path was nor provided or go was not found -if [[ -z "${GOROOT}" ]]; then - # Download go if it's not found in the working directory - if [[ ! -x ${WORK_PATH}/go/bin/go ]]; then + # If GOROOT is not set, then baas path was nor provided or go was not found + if [[ -z "${GOROOT}" ]]; then + # Download go since it wasn't found in the working directory if [[ -z "${GO_URL}" ]]; then echo "Error: go url not defined for current OS architecture" uname -a exit 1 fi - echo "Downloading go to build Toxiproxy" - "${CURL}" -sL "${GO_URL}" | tar -xz - else - echo "Found go in baas proxy working directory" + echo "Downloading go to baas proxy working directory" + ${CURL} -sL "${GO_URL}" | tar -xz + # Set up the GOROOT for building/running baas + export GOROOT="${WORK_PATH}/go" fi +else + echo "Found go in baas proxy working directory" # Set up the GOROOT for building/running baas export GOROOT="${WORK_PATH}/go" fi @@ -212,8 +216,6 @@ else git fetch fi -pushd toxiproxy > /dev/null - echo "Checking out Toxiproxy version '${TOXIPROXY_VERSION}'" git checkout "${TOXIPROXY_VERSION}" echo "Using Toxiproxy commit: $(git rev-parse HEAD)" @@ -229,6 +231,7 @@ fi if [[ -n "${VERBOSE}" ]]; then OPT_WAIT_BAAS+=("-v") fi + "${BASE_PATH}/wait_for_baas.sh" "${OPT_WAIT_BAAS[@]}" cat >"${PROXY_CFG_FILE}" <"${PROXY_CFG_FILE}" < 127.0.0.1:${BAAS_PORT}" ./dist/toxiproxy-server -config "${PROXY_CFG_FILE}" > "${PROXY_LOG}" 2>&1 & echo $! > "${PROXY_PID_FILE}" diff --git a/evergreen/wait_for_baas.sh b/evergreen/wait_for_baas.sh index ffc61db6e0b..46adf45a93a 100755 --- a/evergreen/wait_for_baas.sh +++ b/evergreen/wait_for_baas.sh @@ -67,6 +67,7 @@ function output_log_tail() fi } +echo "Waiting for baas server to start..." until $CURL --output /dev/null --head --fail http://localhost:9090 --silent ; do if [[ -n "${BAAS_STOPPED_FILE}" && -f "${BAAS_STOPPED_FILE}" ]]; then echo "Baas server failed to start (found baas_stopped file)" From ee384d9a8e074582ed87db16eefe4eec6b656043 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Tue, 25 Jul 2023 20:47:28 -0400 Subject: [PATCH 03/22] Fixed issue with merge --- evergreen/setup_baas_host.sh | 3 --- evergreen/setup_baas_host_local.sh | 6 +----- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/evergreen/setup_baas_host.sh b/evergreen/setup_baas_host.sh index 1b405a92ac5..b7f8562b3db 100755 --- a/evergreen/setup_baas_host.sh +++ b/evergreen/setup_baas_host.sh @@ -43,8 +43,6 @@ VERBOSE= while getopts "b:d:t:vh" opt; do case "${opt}" in b) BAAS_BRANCH="${OPTARG}";; -<<<<<<< HEAD -======= d) if [[ -z "${OPTARG}" ]]; then echo "Error: Alternate data directory was empty" usage 1 @@ -53,7 +51,6 @@ while getopts "b:d:t:vh" opt; do echo "Error: Baas proxy port was empty"; usage 1 fi; PROXY_PORT="${OPTARG}";; ->>>>>>> 261ea6389 (Added support for starting baas proxy) v) VERBOSE="yes";; h) usage 0;; *) usage 1;; diff --git a/evergreen/setup_baas_host_local.sh b/evergreen/setup_baas_host_local.sh index 472e4743d4c..9aa31a97be0 100755 --- a/evergreen/setup_baas_host_local.sh +++ b/evergreen/setup_baas_host_local.sh @@ -46,14 +46,10 @@ while getopts "w:u:d:b:tp:c:vh" opt; do u) BAAS_USER="${OPTARG}";; d) FILE_DEST_DIR="${OPTARG}";; b) BAAS_BRANCH="${OPTARG}";; -<<<<<<< HEAD - v) VERBOSE="yes";; -======= t) BAAS_PROXY="yes";; p) REMOTE_PORT="${OPTARG}";; c) CONFIG_PORT="${OPTARG}";; - v) VERBOSE="-v";; ->>>>>>> 261ea6389 (Added support for starting baas proxy) + v) VERBOSE="yes";; h) usage 0;; *) usage 1;; esac From d2abe66cd052d5690c94246855f7e63d7a45f00f Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Thu, 27 Jul 2023 17:33:46 -0400 Subject: [PATCH 04/22] minor updates to install_baas.sh --- evergreen/install_baas.sh | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/evergreen/install_baas.sh b/evergreen/install_baas.sh index a095177d104..97df751b5f7 100755 --- a/evergreen/install_baas.sh +++ b/evergreen/install_baas.sh @@ -395,16 +395,21 @@ if [ ! -x "${MONGO_BINARIES_DIR}/bin/mongod" ]; then mv mongodb* mongodb-binaries chmod +x "${MONGO_BINARIES_DIR}/bin"/* fi - -if [[ -n "${MONGOSH_DOWNLOAD_URL}" ]] && [[ ! -x "${MONGO_BINARIES_DIR}/bin/mongosh" ]]; then - echo "Downloading mongosh" - ${CURL} -sLS "${MONGOSH_DOWNLOAD_URL}" --output mongosh-binaries.zip - unzip -jnqq mongosh-binaries.zip '*/bin/*' -d "${MONGO_BINARIES_DIR}/bin/" - rm mongosh-binaries.zip +echo "mongod version: $("${MONGO_BINARIES_DIR}/bin/mongod" --version --quiet | sed 1q)" + +if [[ -n "${MONGOSH_DOWNLOAD_URL}" ]]; then + if [[ ! -x "${MONGO_BINARIES_DIR}/bin/mongosh" ]]; then + echo "Downloading mongosh" + ${CURL} -sLS "${MONGOSH_DOWNLOAD_URL}" --output mongosh-binaries.zip + unzip -jnqq mongosh-binaries.zip '*/bin/*' -d "${MONGO_BINARIES_DIR}/bin/" + rm mongosh-binaries.zip + MONGOSH="mongosh" + fi +else + # Use the mongo shell provided with mongod + MONGOSH="mongo" fi - -[[ -n "${MONGOSH_DOWNLOAD_URL}" ]] && MONGOSH="mongosh" || MONGOSH="mongo" - +echo "${MONGOSH} version: $("${MONGO_BINARIES_DIR}/bin/${MONGOSH}" --version)" # Start mongod on port 26000 and listening on all network interfaces echo "Starting mongodb" From 40994d3f79b2a64ee855a7a507d62a1307d806ca Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Fri, 28 Jul 2023 17:31:41 -0400 Subject: [PATCH 05/22] Updates to scripts to run on evergreen spawn host --- evergreen/install_baas.sh | 35 ++++++------ evergreen/setup_baas_host.sh | 36 +++++++++--- evergreen/setup_baas_host_local.sh | 42 ++++++-------- evergreen/setup_baas_proxy.sh | 91 ++++++++++++++++-------------- 4 files changed, 112 insertions(+), 92 deletions(-) diff --git a/evergreen/install_baas.sh b/evergreen/install_baas.sh index 97df751b5f7..769c2950511 100755 --- a/evergreen/install_baas.sh +++ b/evergreen/install_baas.sh @@ -168,9 +168,10 @@ fi function check_port() { # Usage: check_port PORT PORT_NAME - port_check=$(lsof -P "-i:${1}" | grep "LISTEN" || true) + port_num="${1}" + port_check=$(lsof -P "-i:${port_num}" | grep "LISTEN" || true) if [[ -n "${port_check}" ]]; then - echo "Error: ${2} port (${1}) is already in use" + echo "Error: ${2} port (${port_num}) is already in use" echo -e "${port_check}" exit 1 fi @@ -212,6 +213,7 @@ BAAS_STOPPED_FILE="${WORK_PATH}/baas_stopped" BAAS_PID_FILE="${WORK_PATH}/baas_server.pid" MONGOD_PID_FILE="${WORK_PATH}/mongod.pid" MONGOD_LOG="${MONGODB_PATH}/mongod.log" +GO_ROOT_FILE="${WORK_PATH}/go_root" # Delete the mongod working directory if it exists from a previous run # Wait to create this directory until just before mongod is started @@ -221,19 +223,19 @@ fi # Remove some files from a previous run if they exist if [[ -f "${BAAS_SERVER_LOG}" ]]; then - rm "${BAAS_SERVER_LOG}" + rm -f "${BAAS_SERVER_LOG}" fi if [[ -f "${BAAS_READY_FILE}" ]]; then - rm "${BAAS_READY_FILE}" + rm -f "${BAAS_READY_FILE}" fi if [[ -f "${BAAS_STOPPED_FILE}" ]]; then - rm "${BAAS_STOPPED_FILE}" + rm -f "${BAAS_STOPPED_FILE}" fi if [[ -f "${BAAS_PID_FILE}" ]]; then - rm "${BAAS_PID_FILE}" + rm -f "${BAAS_PID_FILE}" fi if [[ -f "${MONGOD_PID_FILE}" ]]; then - rm "${MONGOD_PID_FILE}" + rm -f "${MONGOD_PID_FILE}" fi # Set up the cleanup function that runs at exit and stops mongod and the baas server @@ -243,7 +245,7 @@ function on_exit() { # Usage: on_exit # The baas server is being stopped (or never started), create a 'baas_stopped' file - touch "${BAAS_STOPPED_FILE}" + touch "${BAAS_STOPPED_FILE}" || true baas_pid= mongod_pid= @@ -257,16 +259,18 @@ function on_exit() if [[ -n "${baas_pid}" ]]; then echo "Stopping baas ${baas_pid}" - kill "${baas_pid}" + kill "${baas_pid}" || true echo "Waiting for baas to stop" wait "${baas_pid}" + rm -f "${BAAS_PID_FILE}" || true fi if [[ -n "${mongod_pid}" ]]; then echo "Stopping mongod ${mongod_pid}" - kill "${mongod_pid}" + kill "${mongod_pid}" || true echo "Waiting for processes to exit" wait + rm -f "${MONGOD_PID_FILE}" || true fi } @@ -287,6 +291,9 @@ echo "Node version: $(node --version)" [[ -x ${WORK_PATH}/go/bin/go ]] || (${CURL} -sL $GO_URL | tar -xz) export GOROOT="${WORK_PATH}/go" export PATH="${GOROOT}/bin":${PATH} +# Write the GOROOT to a file after the download completes so the baas proxy +# can use the same path. +echo "${GOROOT}" > "${GO_ROOT_FILE}" echo "Go version: $(go version)" # Create the /baas_dep_binaries/ directory @@ -477,12 +484,7 @@ echo "Starting baas app server" --configFile=etc/configs/test_config.json --configFile="${BASE_PATH}/config_overrides.json" > "${BAAS_SERVER_LOG}" 2>&1 & echo $! > "${BAAS_PID_FILE}" -OPT_WAIT_BAAS=("-w" "{$WORK_PATH}") -if [[ -n "${VERBOSE}" ]]; then - OPT_WAIT_BAAS+=("-v") -fi - -"${BASE_PATH}/wait_for_baas.sh" "${OPT_WAIT_BAAS[@]}" +"${BASE_PATH}/wait_for_baas.sh" -w "${WORK_PATH}" # Create the admin user and set up the allowed roles echo "Adding roles to admin user" @@ -503,4 +505,5 @@ echo "---------------------------------------------" echo "Baas server ready" echo "---------------------------------------------" wait + popd > /dev/null # baas \ No newline at end of file diff --git a/evergreen/setup_baas_host.sh b/evergreen/setup_baas_host.sh index b7f8562b3db..a15a0191389 100755 --- a/evergreen/setup_baas_host.sh +++ b/evergreen/setup_baas_host.sh @@ -112,7 +112,7 @@ function init_data_device() devices=$(sudo lsblk | grep disk | awk '{print $1}') for device in ${devices}; do is_data=$(sudo file -s "/dev/${device}" | awk '{print $2}') - if [ "${is_data}" == "data" ]; then + if [[ "${is_data}" == "data" ]]; then data_device="/dev/${device}" fi done @@ -153,9 +153,13 @@ function setup_data_dir() mkdir -p "${BAAS_WORK_DIR}" chmod -R 755 "${BAAS_WORK_DIR}" - # Set up the temp directory - mkdir -p "${DATA_TEMP_DIR}" - chmod 1777 "${DATA_TEMP_DIR}" + # Set up the temp directory - it may already exist on evergreen spawn hosts + if [[ -d "${DATA_TEMP_DIR}" ]]; then + sudo chmod 1777 "${DATA_TEMP_DIR}" + else + mkdir -p "${DATA_TEMP_DIR}" + chmod 1777 "${DATA_TEMP_DIR}" + fi export TMPDIR="${DATA_TEMP_DIR}" } @@ -174,12 +178,14 @@ function on_exit() if [[ -n "${proxy_pid}" ]]; then echo "Stopping baas proxy ${proxy_pid}" - kill "${proxy_pid}" + kill "${proxy_pid}" || true + rm -f "${PROXY_PID_FILE}" || true fi if [[ -n "${baas_pid}" ]]; then echo "Stopping baas server ${baas_pid}" - kill "${baas_pid}" + kill "${baas_pid}" || true + rm -f "${SERVER_PID_FILE}" || true fi echo "Waiting for processes to exit" @@ -189,6 +195,7 @@ function on_exit() function start_baas_proxy() { # Usage: start_baas_proxy PORT + listen_port="${1}" # Delete the toxiproxy working directory if it currently exists if [[ -n "${BAAS_PROXY_DIR}" && -d "${BAAS_PROXY_DIR}" ]]; then rm -rf "${BAAS_PROXY_DIR}" @@ -198,13 +205,14 @@ function start_baas_proxy() cp "${HOME}/setup_baas_proxy.sh" evergreen/ fi - proxy_options= + proxy_options=("-w" "${BAAS_PROXY_DIR}" "-s" "${BAAS_WORK_DIR}" "-p" "${listen_port}") if [[ -n "${VERBOSE}" ]]; then proxy_options=("-v") fi # Pass the baas work directory to the toxiproxy script for the go executable - ./evergreen/setup_baas_proxy.sh "${proxy_options[@]}" -b "${BAAS_WORK_DIR}" -w "${BAAS_PROXY_DIR}" -p "${1}" 2>&1 & + echo "Staring baas proxy with listen port :${listen_port}" + ./evergreen/setup_baas_proxy.sh "${proxy_options[@]}" 2>&1 & echo $! > "${PROXY_PID_FILE}" } @@ -229,8 +237,11 @@ DATA_TEMP_DIR="${DATA_DIR}/tmp" BAAS_REMOTE_DIR="${DATA_DIR}/baas-remote" BAAS_WORK_DIR="${BAAS_REMOTE_DIR}/baas-work-dir" SERVER_PID_FILE="${BAAS_REMOTE_DIR}/baas-server.pid" +BAAS_STOPPED_FILE="${BAAS_WORK_DIR}/baas_stopped" + BAAS_PROXY_DIR="${BAAS_REMOTE_DIR}/baas-proxy-dir" PROXY_PID_FILE="${BAAS_REMOTE_DIR}/baas-proxy.pid" +PROXY_STOPPED_FILE="${BAAS_PROXY_DIR}/baas_proxy_stopped" setup_data_dir @@ -263,13 +274,20 @@ if [[ -n "${VERBOSE}" ]]; then BAAS_OPTIONS+=("-v") fi +echo "Staring baas server..." ./evergreen/install_baas.sh "${BAAS_OPTIONS[@]}" -w "${BAAS_WORK_DIR}" 2>&1 & echo $! > "${SERVER_PID_FILE}" if [[ -n "${PROXY_PORT}" ]]; then start_baas_proxy "${PROXY_PORT}" fi -wait # Wait for scripts to be exited... + +# Turn off verbose logging since it's so noisy +set +o verbose +set +o xtrace +until [[ -f "${BAAS_STOPPED_FILE}" || -f "${PROXY_STOPPED_FILE}" ]]; do + sleep 1 +done popd > /dev/null # realm-core popd > /dev/null # /data/baas-remote diff --git a/evergreen/setup_baas_host_local.sh b/evergreen/setup_baas_host_local.sh index 9aa31a97be0..838aa86dac0 100755 --- a/evergreen/setup_baas_host_local.sh +++ b/evergreen/setup_baas_host_local.sh @@ -2,7 +2,7 @@ # The script to be run on the ubuntu host that will run baas for the evergreen windows tests # # Usage: -# ./evergreen/setup_baas_host_local.sh -f FILE [-i FILE] [-w PATH] [-u USER] [-d PATH] [-b BRANCH] [-t] [-p PORT] [-c PORT] [-v] [-h] +# ./evergreen/setup_baas_host_local.sh [-w PATH] [-u USER] [-b BRANCH] [-v] [-h] [-t] [-l PORT] [-c PORT] HOST_VARS SSH_KEY # set -o errexit @@ -11,19 +11,18 @@ set -o pipefail function usage() { - echo "Usage: setup_baas_host_local.sh [-w PATH] [-u USER] [-d PATH] [-b BRANCH] [-v] [-h] HOST_VARS SSH_KEY" + echo "Usage: setup_baas_host_local.sh [-w PATH] [-u USER] [-b BRANCH] [-v] [-h] [-t] [-l PORT] [-c PORT] HOST_VARS SSH_KEY" echo -e "\tHOST_VARS\t\tPath to baas host vars script file" echo -e "\tSSH_KEY\t\tPath to baas host private key file" echo "Options:" echo -e "\t-w PATH\t\tPath to local baas server working directory (default ./baas-work-dir)" echo -e "\t-u USER\t\tUsername to connect to baas host (default ubuntu)" - echo -e "\t-d PATH\t\tPath on baas host to transfer files (default /home/)" echo -e "\t-b BRANCH\tOptional branch or git spec of baas to checkout/build" echo -e "\t-v\t\tEnable verbose script debugging" echo -e "\t-h\t\tShow this usage summary and exit" echo "Baas Proxy Options:" echo -e "\t-t\t\tEnable baas proxy support (proxy between baas on :9090 and remote port)" - echo -e "\t-p PORT\t\Baas proxy listen port on remote host (default 9092)" + echo -e "\t-l PORT\t\Baas proxy listen port on remote host (default 9092)" echo -e "\t-c PORT\t\tLocal configuration port for proxy HTTP API (default 8474)" # Default to 0 if exit code not provided exit "${1:0}" @@ -34,20 +33,18 @@ BAAS_WORK_PATH=./baas-work-dir BAAS_HOST_NAME= BAAS_USER=ubuntu BAAS_BRANCH= -FILE_DEST_DIR= VERBOSE= BAAS_PROXY= -REMOTE_PORT=9092 +LISTEN_PORT=9092 CONFIG_PORT=8474 -while getopts "w:u:d:b:tp:c:vh" opt; do +while getopts "w:u:b:tl:c:vh" opt; do case "${opt}" in w) BAAS_WORK_PATH="${OPTARG}";; u) BAAS_USER="${OPTARG}";; - d) FILE_DEST_DIR="${OPTARG}";; b) BAAS_BRANCH="${OPTARG}";; t) BAAS_PROXY="yes";; - p) REMOTE_PORT="${OPTARG}";; + l) LISTEN_PORT="${OPTARG}";; c) CONFIG_PORT="${OPTARG}";; v) VERBOSE="yes";; h) usage 0;; @@ -84,12 +81,13 @@ elif [[ ! -f "${BAAS_HOST_KEY}" ]]; then echo "Error: Baas host private key not found: ${BAAS_HOST_KEY}" usage 1 fi +FILE_DEST_DIR="/home/${BAAS_USER}" function check_port() { # Usage check_port PORT - port=${1} - if [[ -n "${port}" && ${port} -gt 0 && ${port} -lt 65536 ]]; then + port_num="${1}" + if [[ -n "${port_num}" && ${port_num} -gt 0 && ${port_num} -lt 65536 ]]; then return 0 fi return 1 @@ -99,8 +97,8 @@ if [[ -n "${BAAS_PROXY}" ]]; then if ! check_port "${CONFIG_PORT}"; then echo "Error: Baas proxy local HTTP API config port was invalid: '${CONFIG_PORT}'" usage 1 - elif ! check_port "${REMOTE_PORT}"; then - echo "Error: Baas proxy listen port was invalid: '${REMOTE_PORT}'" + elif ! check_port "${LISTEN_PORT}"; then + echo "Error: Baas proxy listen port was invalid: '${LISTEN_PORT}'" usage 1 fi fi @@ -144,10 +142,6 @@ if [[ -z "${BAAS_USER}" ]]; then usage 1 fi -if [[ -z "${FILE_DEST_DIR}" ]]; then - FILE_DEST_DIR="/home/${BAAS_USER}" -fi - SSH_USER="$(printf "%s@%s" "${BAAS_USER}" "${BAAS_HOST_NAME}")" ssh-agent > ssh_agent_commands.sh @@ -207,27 +201,27 @@ if [[ -n "${BAAS_PROXY}" ]]; then # Add extra tunnel for baas proxy HTTP API config interface BAAS_TUNNELS=("-L" "${CONFIG_PORT}:127.0.0.1:8474") - # Enable baas proxy and use ${REMOTE_PORT} as the proxy listen port - EXTRA_OPTIONS+=("-t" "${REMOTE_PORT}") + # Enable baas proxy and use LISTEN_PORT as the proxy listen port + EXTRA_OPTIONS+=("-t" "${LISTEN_PORT}") else # Force remote port to 9090 if baas proxy is not used - connect directly to baas - REMOTE_PORT=9090 + LISTEN_PORT=9090 fi -BAAS_TUNNELS+=("-L" "9090:127.0.0.1:${REMOTE_PORT}") +BAAS_TUNNELS+=("-L" "9090:127.0.0.1:${LISTEN_PORT}") # Run the setup baas host script and provide the location of the baas host vars script # Also sets up a forward tunnel for local port 9090 through the ssh connection to the baas remote host # If baas proxy is enabled, a second forward tunnel is added for the HTTP API config interface -echo "Running setup script (with forward tunnel on :9090 to 127.0.0.1:${REMOTE_PORT})" +echo "Running setup script (with forward tunnel on :9090 to 127.0.0.1:${LISTEN_PORT})" if [[ -n "${BAAS_BRANCH}" ]]; then echo "- Starting remote baas with branch/commit: '${BAAS_BRANCH}'" EXTRA_OPTIONS+=("-b" "${BAAS_BRANCH}") fi if [[ -n "${BAAS_PROXY}" ]]; then - echo "- Baas proxy enabled - local HTTP API config port 127.0.0.1:${CONFIG_PORT}" + echo "- Baas proxy enabled - local HTTP API config port on :${CONFIG_PORT}" fi # shellcheck disable=SC2029 -ssh "${SSH_OPTIONS[@]}" "${BAAS_TUNNELS[@]}" "${SSH_USER}" \ +ssh -t "${SSH_OPTIONS[@]}" "${BAAS_TUNNELS[@]}" "${SSH_USER}" \ "${FILE_DEST_DIR}/setup_baas_host.sh" "${EXTRA_OPTIONS[@]}" "${FILE_DEST_DIR}/baas_host_vars.sh" diff --git a/evergreen/setup_baas_proxy.sh b/evergreen/setup_baas_proxy.sh index 59500866cb1..a3159671ceb 100755 --- a/evergreen/setup_baas_proxy.sh +++ b/evergreen/setup_baas_proxy.sh @@ -3,7 +3,7 @@ # for simulating network error conditions for testing. # # Usage: -# ./evergreen/setup_baas_proxy.sh -w PATH [-p PORT] [-b PATH] [-c BRANCH] [-v] [-h] +# ./evergreen/setup_baas_proxy.sh -w PATH [-p PORT] [-s PATH] [-b BRANCH] [-d] [-v] [-h] # set -o errexit @@ -21,18 +21,19 @@ function catch() WORK_PATH= BAAS_PATH= TOXIPROXY_VERSION="v2.5.0" -REMOTE_PORT=9092 +LISTEN_PORT=9092 BAAS_PORT=9090 -VERBOSE= +SKIP_BAAS_WAIT= function usage() { - echo "Usage: setup_baas_proxy.sh -w PATH [-p PORT] [-b PATH] [-c BRANCH] [-v] [-h]" + echo "Usage: setup_baas_proxy.sh -w PATH [-p PORT] [-s PATH] [-b BRANCH] [-d] [-v] [-h]" echo "Options:" echo -e "\t-w PATH\t\tPath to baas proxy working directory" - echo -e "\t-p PORT\t\tRemote port for proxy connected to baas (default: ${REMOTE_PORT})" - echo -e "\t-b PATH\t\tOptional path to baas working directory (for go binary)" - echo -e "\t-c BRANCH\tOptional branch or git spec to checkout/build (default: ${TOXIPROXY_VERSION})" + echo -e "\t-p PORT\t\tListen port for proxy connected to baas (default: ${LISTEN_PORT})" + echo -e "\t-s PATH\t\tOptional path to baas server working directory (for go binary)" + echo -e "\t-b BRANCH\tOptional branch or git spec to checkout/build (default: ${TOXIPROXY_VERSION})" + echo -e "\t-d\t\tDon't wait for baas to start before starting proxy" echo -e "\t-v\t\tEnable verbose script debugging" echo -e "\t-h\t\tShow this usage summary and exit" # Default to 0 if exit code not provided @@ -44,13 +45,14 @@ BASE_PATH="$(cd "$(dirname "$0")"; pwd)" # Allow path to CURL to be overloaded by an environment variable CURL="${CURL:=$LAUNCHER curl}" -while getopts "w:p:b:c:vh" opt; do +while getopts "w:p:s:b:dvh" opt; do case "${opt}" in w) WORK_PATH="${OPTARG}";; - p) REMOTE_PORT="${OPTARG}";; - b) BAAS_PATH="${OPTARG}";; - c) TOXIPROXY_VERSION="${OPTARG}";; - v) VERBOSE="-v"; set -o verbose; set -o xtrace;; + p) LISTEN_PORT="${OPTARG}";; + s) BAAS_PATH="${OPTARG}";; + b) TOXIPROXY_VERSION="${OPTARG}";; + d) SKIP_BAAS_WAIT="yes";; + v) set -o verbose; set -o xtrace;; h) usage 0;; *) usage 1;; esac @@ -60,7 +62,7 @@ if [[ -z "${WORK_PATH}" ]]; then echo "Baas proxy work path was not provided" usage 1 fi -if [[ -z "${REMOTE_PORT}" ]]; then +if [[ -z "${LISTEN_PORT}" ]]; then echo "Baas proxy remote port was empty" usage 1 fi @@ -68,17 +70,17 @@ fi function check_port() { # Usage: check_port PORT PORT_NAME - port_check=$(lsof -P "-i:${1}" | grep "LISTEN" || true) + port_num="${1}" + port_check=$(lsof -P "-i:${port_num}" | grep "LISTEN" || true) if [[ -n "${port_check}" ]]; then - echo "Error: ${2} port (${1}) is already in use" + echo "Error: ${2} port (${port_num}) is already in use" echo -e "${port_check}" exit 1 fi } # Check the mongodb and baas_server port availability first -check_port "${REMOTE_PORT}" "baas proxy" - +check_port "${LISTEN_PORT}" "baas proxy" [[ -d "${WORK_PATH}" ]] || mkdir -p "${WORK_PATH}" pushd "${WORK_PATH}" > /dev/null @@ -87,20 +89,21 @@ PROXY_CFG_FILE="${WORK_PATH}/baas_proxy.json" PROXY_LOG="${WORK_PATH}/baas_proxy.log" PROXY_PID_FILE="${WORK_PATH}/baas_proxy.pid" PROXY_STOPPED_FILE="${WORK_PATH}/baas_proxy_stopped" +BAAS_STOPPED_FILE="${BAAS_PATH}/baas_stopped" # Remove some files from a previous run if they exist if [[ -f "${CONFIG_FILE}" ]]; then - rm "${CONFIG_FILE}" + rm -f "${CONFIG_FILE}" fi if [[ -f "${PROXY_LOG}" ]]; then - rm "${PROXY_LOG}" + rm -f "${PROXY_LOG}" fi if [[ -f "${PROXY_PID_FILE}" ]]; then - rm "${PROXY_PID_FILE}" + rm -f "${PROXY_PID_FILE}" fi if [[ -f "${PROXY_STOPPED}" ]]; then - rm "${PROXY_STOPPED}" + rm -f "${PROXY_STOPPED}" fi # Set up the cleanup function that runs at exit and stops the toxiproxy server @@ -110,7 +113,7 @@ function on_exit() { # Usage: on_exit # Toxiproxy is being stopped (or never started), create a 'baas-proxy-stopped' file - touch "${PROXY_STOPPED_FILE}" + touch "${PROXY_STOPPED_FILE}" || true proxy_pid= if [[ -f "${PROXY_PID_FILE}" ]]; then @@ -118,10 +121,11 @@ function on_exit() fi if [[ -n "${proxy_pid}" ]]; then - echo "Stopping toxiproxy server ${proxy_pid}" - kill "${proxy_pid}" - echo "Waiting for toxiproxy to stop" + echo "Stopping baas proxy ${proxy_pid}" + kill "${proxy_pid}" || true + echo "Waiting for baas proxy to stop" wait + rm -f "${PROXY_PID_FILE}" || true fi } @@ -149,9 +153,10 @@ case $(uname -s) in ;; esac -# If a baas path was provided look for go (or wait up to 10 seconds for it -# to become available) +# Looking for go - first in the work path, then in the baas path (if provided), or +# download go into the work path GOROOT= +# Was it found in the work path? if [[ ! -x ${WORK_PATH}/go/bin/go ]]; then # If the baas work path is set, check there first and wait if [[ -n "${BAAS_PATH}" && -d "${BAAS_PATH}" ]]; then @@ -159,10 +164,10 @@ if [[ ! -x ${WORK_PATH}/go/bin/go ]]; then RETRY_COUNT=10 WAIT_START=$(date -u +'%s') FOUND_GO="yes" - BAAS_GO_DIR="${BAAS_PATH}/go" - BAAS_STOPPED_FILE="${BAAS_PATH}/baas_stopped" + GO_ROOT_FILE="${BAAS_PATH}/go_root" + # Bass may be initializing at the same time, allow a bit of time for the two to sync echo "Looking for go in baas work path for 20 secs in case both are starting concurrently" - until [[ -x "${BAAS_GO_DIR}/bin/go" ]]; do + until [[ -f "${GO_ROOT_FILE}" ]]; do if [[ -n "${BAAS_STOPPED_FILE}" && -f "${BAAS_STOPPED_FILE}" ]]; then echo "Error: Baas server failed to start (found baas_stopped file)" exit 1 @@ -177,8 +182,9 @@ if [[ ! -x ${WORK_PATH}/go/bin/go ]]; then sleep 2 done if [[ -n "${FOUND_GO}" ]]; then - echo "Found go in baas working directory" - GOROOT="${BAAS_GO_DIR}" + GOROOT="$(cat "${GO_ROOT_FILE}")" + echo "Found go in baas working directory: ${GOROOT}" + export GOROOT fi fi @@ -223,27 +229,26 @@ echo "Using Toxiproxy commit: $(git rev-parse HEAD)" # Build toxiproxy make build -# Wait for baas to start before starting Toxiproxy -OPT_WAIT_BAAS=() -if [[ -n "${BAAS_PATH}" ]]; then - OPT_WAIT_BAAS=("-w" "{$BAAS_PATH}") -fi -if [[ -n "${VERBOSE}" ]]; then - OPT_WAIT_BAAS+=("-v") -fi +if [[ -z "${SKIP_BAAS_WAIT}" ]]; then + # Wait for baas to start before starting Toxiproxy + OPT_WAIT_BAAS=() + if [[ -n "${BAAS_PATH}" ]]; then + OPT_WAIT_BAAS=("-w" "{$BAAS_PATH}") + fi -"${BASE_PATH}/wait_for_baas.sh" "${OPT_WAIT_BAAS[@]}" + "${BASE_PATH}/wait_for_baas.sh" "${OPT_WAIT_BAAS[@]}" +fi cat >"${PROXY_CFG_FILE}" < 127.0.0.1:${BAAS_PORT}" +echo "Starting baas proxy: 127.0.0.1:${LISTEN_PORT} => 127.0.0.1:${BAAS_PORT}" ./dist/toxiproxy-server -config "${PROXY_CFG_FILE}" > "${PROXY_LOG}" 2>&1 & echo $! > "${PROXY_PID_FILE}" From ab683b81869caf3ab6277b507110127b3cbb7f6b Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Fri, 28 Jul 2023 17:39:09 -0400 Subject: [PATCH 06/22] Added total time output to object store tests --- test/object-store/main.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/object-store/main.cpp b/test/object-store/main.cpp index 872a9582bb1..bb039f6b3ed 100644 --- a/test/object-store/main.cpp +++ b/test/object-store/main.cpp @@ -28,14 +28,18 @@ #include #include +#include #include #include #include #include +using namespace std::chrono; int main(int argc, const char** argv) { + auto t1 = steady_clock::now(); + realm::test_util::initialize_test_path(1, argv); Catch::ConfigData config; @@ -75,6 +79,10 @@ int main(int argc, const char** argv) Catch::Session session; session.useConfigData(config); int result = session.run(argc, argv); + + auto t2 = steady_clock::now(); + auto ms_int = duration_cast(t2 - t1); + std::cout << "Test time: " << (ms_int.count() / 1000.0) << "s" << std::endl << std::endl; return result < 0xff ? result : 0xff; } From c4d2b61ed05b39404efa4ab34153cf97e772d44d Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Mon, 31 Jul 2023 16:54:34 -0400 Subject: [PATCH 07/22] Increased initial ssh connect attempts; renamed proxy to 'baas_proxy' --- evergreen/setup_baas_host_local.sh | 2 +- evergreen/setup_baas_proxy.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/evergreen/setup_baas_host_local.sh b/evergreen/setup_baas_host_local.sh index 838aa86dac0..6bd48a6e25b 100755 --- a/evergreen/setup_baas_host_local.sh +++ b/evergreen/setup_baas_host_local.sh @@ -160,7 +160,7 @@ echo "running ssh with ${SSH_OPTIONS[*]}" RETRY_COUNT=25 WAIT_COUNTER=0 WAIT_START=$(date -u +'%s') -CONNECT_COUNT=2 +CONNECT_COUNT=4 # Check for remote connectivity - try to connect twice to verify server is "really" ready # The tests failed one time due to this ssh command passing, but the next scp command failed diff --git a/evergreen/setup_baas_proxy.sh b/evergreen/setup_baas_proxy.sh index a3159671ceb..8080f0e86cd 100755 --- a/evergreen/setup_baas_proxy.sh +++ b/evergreen/setup_baas_proxy.sh @@ -241,7 +241,7 @@ fi cat >"${PROXY_CFG_FILE}" < Date: Mon, 31 Jul 2023 17:35:16 -0400 Subject: [PATCH 08/22] Minor updates to help output --- evergreen/install_baas.sh | 1 + evergreen/setup_baas_host.sh | 2 +- evergreen/setup_baas_host_local.sh | 4 ++-- evergreen/setup_baas_proxy.sh | 2 +- evergreen/wait_for_baas.sh | 1 + 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/evergreen/install_baas.sh b/evergreen/install_baas.sh index 769c2950511..82bebc3b734 100755 --- a/evergreen/install_baas.sh +++ b/evergreen/install_baas.sh @@ -134,6 +134,7 @@ function usage() { echo "Usage: install_baas.sh -w PATH [-b BRANCH] [-v] [-h]" echo -e "\t-w PATH\t\tPath to working directory" + echo "Options:" echo -e "\t-b BRANCH\tOptional branch or git spec of baas to checkout/build" echo -e "\t-v\t\tEnable verbose script debugging" echo -e "\t-h\t\tShow this usage summary and exit" diff --git a/evergreen/setup_baas_host.sh b/evergreen/setup_baas_host.sh index a15a0191389..213390716f7 100755 --- a/evergreen/setup_baas_host.sh +++ b/evergreen/setup_baas_host.sh @@ -23,7 +23,7 @@ function usage() { # Usage: usage [EXIT_CODE] echo "Usage: setup_baas_host.sh [-b BRANCH] [-d PATH] [-t PORT] [-v] [-h] HOST_VARS" - echo -e "\tHOST_VARS\t\tPath to baas host vars script file" + echo -e "\tHOST_VARS\tPath to baas host vars script file" echo "Options:" echo -e "\t-b BRANCH\tOptional branch or git spec of baas to checkout/build" echo -e "\t-d PATH\t\tSkip setting up the data device and use alternate data path" diff --git a/evergreen/setup_baas_host_local.sh b/evergreen/setup_baas_host_local.sh index 6bd48a6e25b..77745e0efe3 100755 --- a/evergreen/setup_baas_host_local.sh +++ b/evergreen/setup_baas_host_local.sh @@ -12,7 +12,7 @@ set -o pipefail function usage() { echo "Usage: setup_baas_host_local.sh [-w PATH] [-u USER] [-b BRANCH] [-v] [-h] [-t] [-l PORT] [-c PORT] HOST_VARS SSH_KEY" - echo -e "\tHOST_VARS\t\tPath to baas host vars script file" + echo -e "\tHOST_VARS\tPath to baas host vars script file" echo -e "\tSSH_KEY\t\tPath to baas host private key file" echo "Options:" echo -e "\t-w PATH\t\tPath to local baas server working directory (default ./baas-work-dir)" @@ -22,7 +22,7 @@ function usage() echo -e "\t-h\t\tShow this usage summary and exit" echo "Baas Proxy Options:" echo -e "\t-t\t\tEnable baas proxy support (proxy between baas on :9090 and remote port)" - echo -e "\t-l PORT\t\Baas proxy listen port on remote host (default 9092)" + echo -e "\t-l PORT\t\tBaas proxy listen port on remote host (default 9092)" echo -e "\t-c PORT\t\tLocal configuration port for proxy HTTP API (default 8474)" # Default to 0 if exit code not provided exit "${1:0}" diff --git a/evergreen/setup_baas_proxy.sh b/evergreen/setup_baas_proxy.sh index 8080f0e86cd..a11db1c360a 100755 --- a/evergreen/setup_baas_proxy.sh +++ b/evergreen/setup_baas_proxy.sh @@ -28,8 +28,8 @@ SKIP_BAAS_WAIT= function usage() { echo "Usage: setup_baas_proxy.sh -w PATH [-p PORT] [-s PATH] [-b BRANCH] [-d] [-v] [-h]" - echo "Options:" echo -e "\t-w PATH\t\tPath to baas proxy working directory" + echo "Options:" echo -e "\t-p PORT\t\tListen port for proxy connected to baas (default: ${LISTEN_PORT})" echo -e "\t-s PATH\t\tOptional path to baas server working directory (for go binary)" echo -e "\t-b BRANCH\tOptional branch or git spec to checkout/build (default: ${TOXIPROXY_VERSION})" diff --git a/evergreen/wait_for_baas.sh b/evergreen/wait_for_baas.sh index 46adf45a93a..508ec310eca 100755 --- a/evergreen/wait_for_baas.sh +++ b/evergreen/wait_for_baas.sh @@ -24,6 +24,7 @@ STATUS_OUT= function usage() { echo "Usage: wait_for_baas.sh [-w PATH] [-p FILE] [-r COUNT] [-l FILE] [-s] [-v] [-h]" + echo "Options:" echo -e "\t-w PATH\t\tPath to baas server working directory" echo -e "\t-p FILE\t\tPath to baas server pid file (also set by -w option)" echo -e "\t-r COUNT\tNumber of attempts to check for baas server (default 120)" From c232f4f8eb6c9e6d842c3b295cc952d1faa907b3 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Tue, 1 Aug 2023 13:47:56 -0400 Subject: [PATCH 09/22] Added baas network test to run bass with the proxy --- evergreen/config.yml | 65 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/evergreen/config.yml b/evergreen/config.yml index f64433fd005..908ce1fb2e2 100644 --- a/evergreen/config.yml +++ b/evergreen/config.yml @@ -537,10 +537,14 @@ functions: if [ -n "${baas_branch}" ]; then OPT_BAAS_BRANCH="-b ${baas_branch}" fi + if [ -n "${baas_proxy}" ]; then + OPT_BAAS_PROXY="-t" + fi # Run the setup_baas_host_local.sh script to configure and run baas on the remote host # Add -v to this command for verbose script logging - ./evergreen/setup_baas_host_local.sh -w ./baas-work-dir -u $BAAS_USER $OPT_BAAS_BRANCH ./baas_host_vars.sh ./.baas_ssh_key 2>&1 | tee install_baas_output.log + ./evergreen/setup_baas_host_local.sh -w ./baas-work-dir -u $BAAS_USER $OPT_BAAS_BRANCH $OPT_BAAS_PROXY \ + ./baas_host_vars.sh ./.baas_ssh_key 2>&1 | tee install_baas_output.log "wait for baas to start": - command: shell.exec @@ -844,7 +848,7 @@ tasks: # These are local object store tests; baas is not started, however some use the sync server - name: object-store-tests - tags: [ "test_suite_remote_baas", "for_pull_requests" ] + tags: [ "object_store_test_suite", "for_pull_requests" ] exec_timeout_secs: 3600 commands: - func: "compile" @@ -859,7 +863,7 @@ tasks: # These are baas object store tests that run against baas running on a remote host - name: baas-integration-tests - tags: [ "test_suite_remote_baas", "for_pull_requests" ] + tags: [ "object_store_test_suite", "for_pull_requests" ] exec_timeout_secs: 3600 commands: - func: "launch remote baas" @@ -876,6 +880,25 @@ tasks: verbose_test_output: true - func: "check branch state" +- name: baas-network-tests + tags: [ "for_nightly_tests" ] + exec_timeout_secs: 14400 + commands: + - func: "launch remote baas" + vars: + baas_branch: 1a0d1c021460d2215b21bc4f7c7f668714ce81c7 + baas_proxy: On + - func: "compile" + vars: + target_to_build: ObjectStoreTests + - func: "wait for baas to start" + - func: "run tests" + vars: + test_label: objstore-baas + test_executable_name: "realm-object-store-tests" + verbose_test_output: true + - func: "check branch state" + - name: process_coverage_data tags: [ "for_pull_requests" ] exec_timeout_secs: 1800 @@ -1050,7 +1073,7 @@ task_groups: tasks: - compile - .test_suite - - .test_suite_remote_baas + - .object_store_test_suite - package # Runs object-store-tests against baas running on remote host @@ -1067,7 +1090,25 @@ task_groups: tasks: - compile - .test_suite - - .test_suite_remote_baas + - .object_store_test_suite + +# Runs object-store-tests against baas running on remote host and runs +# the network simulation tests as a separate task for nightly builds +- name: compile_test_network + max_hosts: 1 + setup_group_can_fail_task: true + setup_group: + - func: "fetch source" + - func: "fetch binaries" + teardown_task: + - func: "upload test results" + timeout: + - func: "run hang analyzer" + tasks: + - compile + - .test_suite + - .object_store_test_suite + - baas-network-tests # Runs object-store-tests against baas running on remote host - name: compile_test_coverage @@ -1083,7 +1124,7 @@ task_groups: tasks: - compile - .test_suite - - .test_suite_remote_baas + - .object_store_test_suite - process_coverage_data - name: benchmarks @@ -1141,7 +1182,7 @@ buildvariants: cxx_compiler: "./clang_binaries/bin/clang++" extra_flags: -DREALM_ENABLE_GEOSPATIAL=OFF # can be removed once SDKs pick this feature up tasks: - - name: compile_test + - name: compile_test_network - name: ubuntu2204 @@ -1172,7 +1213,7 @@ buildvariants: cxx_compiler: "./clang_binaries/bin/clang++" disable_sync_multiplexing: On tasks: - - name: compile_test + - name: compile_test_network - name: ubuntu2004-encryption-tsan display_name: "Ubuntu 20.04 x86_64 (Clang 11 Encryption Enabled w/TSAN)" @@ -1401,7 +1442,7 @@ buildvariants: xcode_developer_dir: /Applications/Xcode13.1.app/Contents/Developer extra_flags: -DCMAKE_SYSTEM_NAME=Darwin -DCMAKE_OSX_ARCHITECTURES=arm64 -DREALM_ENABLE_GEOSPATIAL=OFF tasks: - - name: compile_test + - name: compile_test_network - name: swift-build-and-test - name: macos-1100-arm64-release @@ -1469,8 +1510,7 @@ buildvariants: curl_base: "/cygdrive/c/curl" python3: "/cygdrive/c/python/python37/python.exe" tasks: - - name: compile_test_and_package - - name: long-running-tests + - name: compile_test_network - name: windows-64-encryption display_name: "Windows x86_64 (Encryption enabled)" @@ -1502,4 +1542,5 @@ buildvariants: curl_base: "/cygdrive/c/curl" python3: "/cygdrive/c/python/python37/python.exe" tasks: - - name: compile_test + - name: compile_test_and_package + - name: long-running-tests From 181132dcead63ba47fbfc6431028a9eb95a23222 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Tue, 1 Aug 2023 13:56:08 -0400 Subject: [PATCH 10/22] Updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8511aa725aa..38a27ac729b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ ### Internals * Timestamp objects can now only be created from a system clock timepoint. ([#6112](https://github.com/realm/realm-core/issues/6112)) +* Add baas-network-tests nightly task for testing sync client operation with non-ideal network conditions. ([PR #6852](https://github.com/realm/realm-core/pull/6852)) ---------------------------------------------- From 7fac09877884a4fdfe07b46726358f51f6b0ee6d Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Thu, 10 Aug 2023 17:36:23 -0400 Subject: [PATCH 11/22] Added support for separate baas admin api url value --- evergreen/config.yml | 87 +++++++--- evergreen/setup_baas_host_local.sh | 45 +++--- test/object-store/CMakeLists.txt | 8 + test/object-store/audit.cpp | 2 +- test/object-store/c_api/c_api.cpp | 6 +- test/object-store/sync/app.cpp | 41 ++--- test/object-store/sync/client_reset.cpp | 16 +- test/object-store/sync/flx_migration.cpp | 21 +-- test/object-store/sync/flx_sync.cpp | 9 +- .../object-store/util/sync/baas_admin_api.cpp | 150 ++++++++++-------- .../object-store/util/sync/baas_admin_api.hpp | 33 ++-- .../util/sync/flx_sync_harness.hpp | 2 +- .../util/sync/sync_test_utils.cpp | 36 ++++- .../util/sync/sync_test_utils.hpp | 2 + test/object-store/util/test_file.cpp | 2 +- 15 files changed, 275 insertions(+), 185 deletions(-) diff --git a/evergreen/config.yml b/evergreen/config.yml index 908ce1fb2e2..1f86697aec0 100644 --- a/evergreen/config.yml +++ b/evergreen/config.yml @@ -75,8 +75,12 @@ functions: fi if [ -z "${disable_tests_against_baas|}" ]; then + scheme="http" set_cmake_var baas_vars REALM_ENABLE_AUTH_TESTS BOOL On - set_cmake_var baas_vars REALM_MONGODB_ENDPOINT STRING "http://localhost:9090" + set_cmake_var baas_vars REALM_MONGODB_ENDPOINT STRING "$scheme://localhost:9090" + if [ -n "${baas_admin_port|}" ]; then + set_cmake_var baas_vars REALM_ADMIN_ENDPOINT STRING "$scheme://localhost:${baas_admin_port}" + fi fi if [ -n "${enable_asan|}" ]; then @@ -132,7 +136,7 @@ functions: fi set_cmake_var realm_vars REALM_TEST_LOGGING BOOL On - set_cmake_var realm_vars REALM_TEST_LOGGING_LEVEL STRING "debug" + set_cmake_var realm_vars REALM_TEST_LOGGING_LEVEL STRING "${test_logging_level|debug}" GENERATOR="${cmake_generator}" if [ -z "${cmake_generator|}" ]; then @@ -274,6 +278,8 @@ functions: - command: attach.results params: file_location: realm-core/${task_name}_results.json + + "upload baas artifacts": - command: shell.exec params: working_dir: realm-core @@ -289,7 +295,7 @@ functions: # Copy the baas_server log from the remote baas host if it exists if [[ ! -f baas_host.yml || ! -f .baas_ssh_key ]]; then - echo "No remote baas host or remote baas host definitions not found" + echo "Skipping - no remote baas host or remote baas host definitions not found" exit fi @@ -299,14 +305,22 @@ functions: ssh_user="$(printf "ubuntu@%s" "$BAAS_HOST_NAME")" ssh_options="-o ForwardAgent=yes -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o ConnectTimeout=10 -i .baas_ssh_key" - # Copy the baas_server.log and mongod.log files from the remote baas host - REMOTE_PATH=/data/baas-remote/baas-work-dir - LOCAL_PATH=./baas-work-dir + # Copy the baas_server.log, mongod.log and (optionally) baas_proxy.log files from the remote baas host + REMOTE_PATH=/data/baas-remote + REMOTE_BAAS_PATH="$REMOTE_PATH/baas-work-dir" + REMOTE_BAAS_DB_PATH="$REMOTE_BAAS_PATH/mongodb-dbpath" + REMOTE_PROXY_PATH="$REMOTE_PATH/baas-proxy-dir" + + LOCAL_BAAS_PATH=./baas-work-dir + LOCAL_BAAS_DB_PATH="$LOCAL_BAAS_PATH/mongodb-dbpath" + LOCAL_PROXY_PATH=./baas-proxy-dir - mkdir -p "$LOCAL_PATH/" - mkdir -p "$LOCAL_PATH/mongodb-dbpath/" - scp $ssh_options $ssh_user:"$REMOTE_PATH/baas_server.log" "$LOCAL_PATH/baas_server.log" || true - scp $ssh_options $ssh_user:"$REMOTE_PATH/mongodb-dbpath/mongod.log" "$LOCAL_PATH/mongodb-dbpath/mongod.log" || true + mkdir -p "$LOCAL_BAAS_PATH/" + mkdir -p "$LOCAL_BAAS_DB_PATH/" + mkdir -p "$LOCAL_PROXY_PATH/" + scp $ssh_options $ssh_user:"$REMOTE_BAAS_PATH/baas_server.log" "$LOCAL_BAAS_PATH/baas_server.log" || true + scp $ssh_options $ssh_user:"$REMOTE_BAAS_DB_PATH/mongod.log" "$LOCAL_BAAS_DB_PATH/mongod.log" || true + scp $ssh_options $ssh_user:"$REMOTE_PROXY_PATH/baas_proxy.log" "$LOCAL_PROXY_PATH/baas_proxy.log" || true - command: s3.put params: @@ -341,6 +355,17 @@ functions: content_type: text/text display_name: mongod logs optional: true + - command: s3.put + params: + aws_key: '${artifacts_aws_access_key}' + aws_secret: '${artifacts_aws_secret_key}' + local_file: 'realm-core/baas-proxy-dir/baas_proxy.log' + remote_file: 'realm-core-stable/${branch_name}/${task_id}/${execution}/baas_proxy.log' + bucket: mciuploads + permissions: public-read + content_type: text/text + display_name: baas proxy logs + optional: true "upload fuzzer results": - command: shell.exec @@ -534,17 +559,23 @@ functions: BAAS_USER=ubuntu OPT_BAAS_BRANCH= + OPT_BAAS_PROXY= + OPT_BAAS_DIRECT= + if [ -n "${baas_branch}" ]; then OPT_BAAS_BRANCH="-b ${baas_branch}" fi if [ -n "${baas_proxy}" ]; then OPT_BAAS_PROXY="-t" + if [ -n "${baas_admin_port}" ]; then + OPT_BAAS_DIRECT="-d ${baas_admin_port}" + fi fi # Run the setup_baas_host_local.sh script to configure and run baas on the remote host # Add -v to this command for verbose script logging ./evergreen/setup_baas_host_local.sh -w ./baas-work-dir -u $BAAS_USER $OPT_BAAS_BRANCH $OPT_BAAS_PROXY \ - ./baas_host_vars.sh ./.baas_ssh_key 2>&1 | tee install_baas_output.log + $OPT_BAAS_DIRECT ./baas_host_vars.sh ./.baas_ssh_key 2>&1 | tee install_baas_output.log "wait for baas to start": - command: shell.exec @@ -1068,6 +1099,7 @@ task_groups: - func: "fetch binaries" teardown_task: - func: "upload test results" + - func: "upload baas artifacts" timeout: - func: "run hang analyzer" tasks: @@ -1085,6 +1117,7 @@ task_groups: - func: "fetch binaries" teardown_task: - func: "upload test results" + - func: "upload baas artifacts" timeout: - func: "run hang analyzer" tasks: @@ -1094,7 +1127,7 @@ task_groups: # Runs object-store-tests against baas running on remote host and runs # the network simulation tests as a separate task for nightly builds -- name: compile_test_network +- name: network_tests max_hosts: 1 setup_group_can_fail_task: true setup_group: @@ -1102,12 +1135,11 @@ task_groups: - func: "fetch binaries" teardown_task: - func: "upload test results" + - func: "upload baas artifacts" timeout: - func: "run hang analyzer" tasks: - compile - - .test_suite - - .object_store_test_suite - baas-network-tests # Runs object-store-tests against baas running on remote host @@ -1119,6 +1151,7 @@ task_groups: - func: "fetch binaries" teardown_task: - func: "upload test results" + - func: "upload baas artifacts" timeout: - func: "run hang analyzer" tasks: @@ -1182,7 +1215,7 @@ buildvariants: cxx_compiler: "./clang_binaries/bin/clang++" extra_flags: -DREALM_ENABLE_GEOSPATIAL=OFF # can be removed once SDKs pick this feature up tasks: - - name: compile_test_network + - name: compile_test - name: ubuntu2204 @@ -1213,7 +1246,7 @@ buildvariants: cxx_compiler: "./clang_binaries/bin/clang++" disable_sync_multiplexing: On tasks: - - name: compile_test_network + - name: compile_test - name: ubuntu2004-encryption-tsan display_name: "Ubuntu 20.04 x86_64 (Clang 11 Encryption Enabled w/TSAN)" @@ -1340,6 +1373,24 @@ buildvariants: - name: fuzzer-tests activate: false +- name: ubuntu2004-network + display_name: "Ubuntu 20.04 x86_64 (Clang 11 Baas network tests)" + run_on: ubuntu2004-large + expansions: + clang_url: "https://s3.amazonaws.com/static.realm.io/evergreen-assets/clang%2Bllvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04.tar.xz" + cmake_url: "https://s3.amazonaws.com/static.realm.io/evergreen-assets/cmake-3.20.3-linux-x86_64.tar.gz" + cmake_bindir: "./cmake_binaries/bin" + fetch_missing_dependencies: On + c_compiler: "./clang_binaries/bin/clang" + cxx_compiler: "./clang_binaries/bin/clang++" + cmake_build_type: RelWithDebInfo + run_with_encryption: On + baas_admin_port: 9098 + test_logging_level: trace + tasks: + - name: network_tests + patchable: true + - name: rhel70 display_name: "RHEL 7 x86_64" run_on: rhel70-large @@ -1442,7 +1493,7 @@ buildvariants: xcode_developer_dir: /Applications/Xcode13.1.app/Contents/Developer extra_flags: -DCMAKE_SYSTEM_NAME=Darwin -DCMAKE_OSX_ARCHITECTURES=arm64 -DREALM_ENABLE_GEOSPATIAL=OFF tasks: - - name: compile_test_network + - name: compile_test - name: swift-build-and-test - name: macos-1100-arm64-release @@ -1510,7 +1561,7 @@ buildvariants: curl_base: "/cygdrive/c/curl" python3: "/cygdrive/c/python/python37/python.exe" tasks: - - name: compile_test_network + - name: compile_test - name: windows-64-encryption display_name: "Windows x86_64 (Encryption enabled)" diff --git a/evergreen/setup_baas_host_local.sh b/evergreen/setup_baas_host_local.sh index 77745e0efe3..a7d30ae4b5b 100755 --- a/evergreen/setup_baas_host_local.sh +++ b/evergreen/setup_baas_host_local.sh @@ -2,48 +2,51 @@ # The script to be run on the ubuntu host that will run baas for the evergreen windows tests # # Usage: -# ./evergreen/setup_baas_host_local.sh [-w PATH] [-u USER] [-b BRANCH] [-v] [-h] [-t] [-l PORT] [-c PORT] HOST_VARS SSH_KEY +# ./evergreen/setup_baas_host_local.sh [-w PATH] [-u USER] [-b BRANCH] [-v] [-h] [-t] [-d PORT] [-l PORT] [-c PORT] HOST_VARS SSH_KEY # set -o errexit set -o errtrace set -o pipefail +EVERGREEN_PATH=./evergreen +BAAS_WORK_PATH=./baas-work-dir +BAAS_HOST_NAME= +BAAS_USER=ubuntu +BAAS_BRANCH= +VERBOSE= +BAAS_PROXY= +DIRECT_PORT=9098 +LISTEN_PORT=9092 +CONFIG_PORT=8474 + function usage() { - echo "Usage: setup_baas_host_local.sh [-w PATH] [-u USER] [-b BRANCH] [-v] [-h] [-t] [-l PORT] [-c PORT] HOST_VARS SSH_KEY" + echo "Usage: setup_baas_host_local.sh [-w PATH] [-u USER] [-b BRANCH] [-v] [-h] [-t] [-d PORT] [-l PORT] [-c PORT] HOST_VARS SSH_KEY" echo -e "\tHOST_VARS\tPath to baas host vars script file" echo -e "\tSSH_KEY\t\tPath to baas host private key file" echo "Options:" - echo -e "\t-w PATH\t\tPath to local baas server working directory (default ./baas-work-dir)" - echo -e "\t-u USER\t\tUsername to connect to baas host (default ubuntu)" + echo -e "\t-w PATH\t\tPath to local baas server working directory (default ${BAAS_WORK_PATH})" + echo -e "\t-u USER\t\tUsername to connect to baas host (default ${BAAS_USER})" echo -e "\t-b BRANCH\tOptional branch or git spec of baas to checkout/build" echo -e "\t-v\t\tEnable verbose script debugging" echo -e "\t-h\t\tShow this usage summary and exit" echo "Baas Proxy Options:" echo -e "\t-t\t\tEnable baas proxy support (proxy between baas on :9090 and remote port)" - echo -e "\t-l PORT\t\tBaas proxy listen port on remote host (default 9092)" - echo -e "\t-c PORT\t\tLocal configuration port for proxy HTTP API (default 8474)" + echo -e "\t-d PORT\t\tPort for direct connection to baas - skips proxy (default ${DIRECT_PORT})" + echo -e "\t-l PORT\t\tBaas proxy listen port on remote host (default ${LISTEN_PORT})" + echo -e "\t-c PORT\t\tLocal configuration port for proxy HTTP API (default ${CONFIG_PORT})" # Default to 0 if exit code not provided exit "${1:0}" } -EVERGREEN_PATH=./evergreen -BAAS_WORK_PATH=./baas-work-dir -BAAS_HOST_NAME= -BAAS_USER=ubuntu -BAAS_BRANCH= -VERBOSE= -BAAS_PROXY= -LISTEN_PORT=9092 -CONFIG_PORT=8474 - -while getopts "w:u:b:tl:c:vh" opt; do +while getopts "w:u:b:ta:d:l:c:vh" opt; do case "${opt}" in w) BAAS_WORK_PATH="${OPTARG}";; u) BAAS_USER="${OPTARG}";; b) BAAS_BRANCH="${OPTARG}";; t) BAAS_PROXY="yes";; + d) DIRECT_PORT="${OPTARG}";; l) LISTEN_PORT="${OPTARG}";; c) CONFIG_PORT="${OPTARG}";; v) VERBOSE="yes";; @@ -199,8 +202,11 @@ if [[ -n "${BAAS_PROXY}" ]]; then echo "Transferring baas proxy setup script to ${SSH_USER}:${FILE_DEST_DIR}" scp "${SSH_OPTIONS[@]}" "${EVERGREEN_PATH}/setup_baas_proxy.sh" "${SSH_USER}:${FILE_DEST_DIR}/" - # Add extra tunnel for baas proxy HTTP API config interface + # Add extra tunnel for baas proxy HTTP API config interface and direct connection to baas BAAS_TUNNELS=("-L" "${CONFIG_PORT}:127.0.0.1:8474") + if [[ -n "${DIRECT_PORT}" ]]; then + BAAS_TUNNELS+=("-L" "${DIRECT_PORT}:127.0.0.1:9090") + fi # Enable baas proxy and use LISTEN_PORT as the proxy listen port EXTRA_OPTIONS+=("-t" "${LISTEN_PORT}") else @@ -220,6 +226,9 @@ if [[ -n "${BAAS_BRANCH}" ]]; then fi if [[ -n "${BAAS_PROXY}" ]]; then echo "- Baas proxy enabled - local HTTP API config port on :${CONFIG_PORT}" + if [[ -n "${DIRECT_PORT}" ]]; then + echo "- Baas direct connection on port :${DIRECT_PORT}" + fi fi # shellcheck disable=SC2029 diff --git a/test/object-store/CMakeLists.txt b/test/object-store/CMakeLists.txt index 5391e54bb81..e9deeaac218 100644 --- a/test/object-store/CMakeLists.txt +++ b/test/object-store/CMakeLists.txt @@ -130,11 +130,19 @@ if(REALM_ENABLE_SYNC) message(FATAL_ERROR "REALM_MONGODB_ENDPOINT must be set when specifying REALM_ENABLE_AUTH_TESTS.") endif() + message(STATUS "Auth tests enabled: ${REALM_MONGODB_ENDPOINT}") target_compile_definitions(ObjectStoreTests PRIVATE REALM_ENABLE_AUTH_TESTS=1 REALM_MONGODB_ENDPOINT="${REALM_MONGODB_ENDPOINT}" ) + if(REALM_ADMIN_ENDPOINT) + message(STATUS "BAAS admin endpoint: ${REALM_ADMIN_ENDPOINT}") + target_compile_definitions(ObjectStoreTests PRIVATE + REALM_ADMIN_ENDPOINT="${REALM_ADMIN_ENDPOINT}" + ) + endif() + find_package(CURL REQUIRED) target_link_libraries(ObjectStoreTests CURL::libcurl) endif() diff --git a/test/object-store/audit.cpp b/test/object-store/audit.cpp index 04a9cb5742b..b5aa55dbc68 100644 --- a/test/object-store/audit.cpp +++ b/test/object-store/audit.cpp @@ -1687,7 +1687,7 @@ TEST_CASE("audit integration tests", "[sync][pbs][audit][baas]") { const Schema no_audit_event_schema{ {"object", {{"_id", PropertyType::Int, Property::IsPrimary{true}}, {"value", PropertyType::Int}}}}; - auto app_create_config = default_app_config(get_base_url()); + auto app_create_config = default_app_config(); app_create_config.schema = schema; app_create_config.dev_mode_enabled = false; TestAppSession session = create_app(app_create_config); diff --git a/test/object-store/c_api/c_api.cpp b/test/object-store/c_api/c_api.cpp index af570b19e42..a1cd9d1f465 100644 --- a/test/object-store/c_api/c_api.cpp +++ b/test/object-store/c_api/c_api.cpp @@ -5330,9 +5330,7 @@ TEST_CASE("C API - client reset", "[sync][pbs][c_api][client reset][baas]") { }}, }; - std::string base_url = get_base_url(); - REQUIRE(!base_url.empty()); - auto server_app_config = minimal_app_config(base_url, "c_api_client_reset_tests", schema); + auto server_app_config = minimal_app_config("c_api_client_reset_tests", schema); server_app_config.partition_key = partition_prop; TestAppSession test_app_session(create_app(server_app_config)); @@ -5570,7 +5568,7 @@ TEST_CASE("C API app: link_user integration w/c_api transport", "[sync][app][c_a // user_data will be deleted when user_data_free() is called auto user_data = new TestTransportUserData(); auto http_transport = realm_http_transport_new(send_request_to_server, user_data, user_data_free); - auto app_session = get_runtime_app_session(get_base_url()); + auto app_session = get_runtime_app_session(); TestAppSession session(app_session, *http_transport, DeleteApp{false}); realm_app app(session.app()); diff --git a/test/object-store/sync/app.cpp b/test/object-store/sync/app.cpp index 8182d777d5f..4faafedac0b 100644 --- a/test/object-store/sync/app.cpp +++ b/test/object-store/sync/app.cpp @@ -970,7 +970,8 @@ TEST_CASE("app: remote mongo client", "[sync][app][mongo][baas]") { auto app = session.app(); auto remote_client = app->current_user()->mongo_client("BackingDB"); - auto db = remote_client.db(get_runtime_app_session("").config.mongo_dbname); + auto app_session = get_runtime_app_session(); + auto db = remote_client.db(app_session.config.mongo_dbname); auto dog_collection = db["Dog"]; auto cat_collection = db["Cat"]; auto person_collection = db["Person"]; @@ -1722,7 +1723,8 @@ TEST_CASE("app: token refresh", "[sync][app][token][baas]") { sync_user->update_access_token(ENCODE_FAKE_JWT("fake_access_token")); auto remote_client = app->current_user()->mongo_client("BackingDB"); - auto db = remote_client.db(get_runtime_app_session("").config.mongo_dbname); + auto app_session = get_runtime_app_session(); + auto db = remote_client.db(app_session.config.mongo_dbname); auto dog_collection = db["Dog"]; bson::BsonDocument dog_document{{"name", "fido"}, {"breed", "king charles"}}; @@ -1748,9 +1750,7 @@ TEST_CASE("app: token refresh", "[sync][app][token][baas]") { // MARK: - Sync Tests TEST_CASE("app: mixed lists with object links", "[sync][pbs][app][links][baas]") { - std::string base_url = get_base_url(); const std::string valid_pk_name = "_id"; - REQUIRE(!base_url.empty()); Schema schema{ {"TopLevel", @@ -1765,7 +1765,7 @@ TEST_CASE("app: mixed lists with object links", "[sync][pbs][app][links][baas]") }}, }; - auto server_app_config = minimal_app_config(base_url, "set_new_embedded_object", schema); + auto server_app_config = minimal_app_config("set_new_embedded_object", schema); auto app_session = create_app(server_app_config); auto partition = random_string(100); @@ -1824,9 +1824,7 @@ TEST_CASE("app: mixed lists with object links", "[sync][pbs][app][links][baas]") } TEST_CASE("app: roundtrip values", "[sync][pbs][app][baas]") { - std::string base_url = get_base_url(); const std::string valid_pk_name = "_id"; - REQUIRE(!base_url.empty()); Schema schema{ {"TopLevel", @@ -1836,7 +1834,7 @@ TEST_CASE("app: roundtrip values", "[sync][pbs][app][baas]") { }}, }; - auto server_app_config = minimal_app_config(base_url, "roundtrip_values", schema); + auto server_app_config = minimal_app_config("roundtrip_values", schema); auto app_session = create_app(server_app_config); auto partition = random_string(100); @@ -1873,9 +1871,7 @@ TEST_CASE("app: roundtrip values", "[sync][pbs][app][baas]") { } TEST_CASE("app: upgrade from local to synced realm", "[sync][pbs][app][upgrade][baas]") { - std::string base_url = get_base_url(); const std::string valid_pk_name = "_id"; - REQUIRE(!base_url.empty()); Schema schema{ {"origin", @@ -1918,7 +1914,7 @@ TEST_CASE("app: upgrade from local to synced realm", "[sync][pbs][app][upgrade][ } /* Create a synced realm and upload some data */ - auto server_app_config = minimal_app_config(base_url, "upgrade_from_local", schema); + auto server_app_config = minimal_app_config("upgrade_from_local", schema); TestAppSession test_session(create_app(server_app_config)); auto partition = random_string(100); auto user1 = test_session.app()->current_user(); @@ -1975,9 +1971,7 @@ TEST_CASE("app: upgrade from local to synced realm", "[sync][pbs][app][upgrade][ } TEST_CASE("app: set new embedded object", "[sync][pbs][app][baas]") { - std::string base_url = get_base_url(); const std::string valid_pk_name = "_id"; - REQUIRE(!base_url.empty()); Schema schema{ {"TopLevel", @@ -2005,7 +1999,7 @@ TEST_CASE("app: set new embedded object", "[sync][pbs][app][baas]") { }}, }; - auto server_app_config = minimal_app_config(base_url, "set_new_embedded_object", schema); + auto server_app_config = minimal_app_config("set_new_embedded_object", schema); TestAppSession test_session(create_app(server_app_config)); auto partition = random_string(100); @@ -2116,7 +2110,7 @@ TEST_CASE("app: make distributable client file", "[sync][pbs][app][baas]") { TestAppSession session; auto app = session.app(); - auto schema = default_app_config("").schema; + auto schema = get_default_schema(); SyncTestFile original_config(app, bson::Bson("foo"), schema); create_user_and_log_in(app); SyncTestFile target_config(app, bson::Bson("foo"), schema); @@ -2189,7 +2183,7 @@ TEST_CASE("app: make distributable client file", "[sync][pbs][app][baas]") { TEST_CASE("app: sync integration", "[sync][pbs][app][baas]") { auto logger = std::make_shared(realm::util::Logger::Level::TEST_LOGGING_LEVEL); - const auto schema = default_app_config("").schema; + const auto schema = get_default_schema(); auto get_dogs = [](SharedRealm r) -> Results { wait_for_upload(*r, std::chrono::seconds(10)); @@ -2652,8 +2646,7 @@ TEST_CASE("app: sync integration", "[sync][pbs][app][baas]") { logger->trace("redirect_url: %1", redirect_url); }; - auto base_url = get_base_url(); - auto server_app_config = minimal_app_config(base_url, "websocket_redirect", schema); + auto server_app_config = minimal_app_config("websocket_redirect", schema); TestAppSession test_session(create_app(server_app_config), redir_transport, DeleteApp{true}, realm::ReconnectMode::normal, redir_provider); auto partition = random_string(100); @@ -3470,9 +3463,7 @@ TEMPLATE_TEST_CASE("app: collections of links integration", "[sync][pbs][app][co cf::ListOfMixedLinks, cf::SetOfObjects, cf::SetOfMixedLinks, cf::DictionaryOfObjects, cf::DictionaryOfMixedLinks) { - std::string base_url = get_base_url(); const std::string valid_pk_name = "_id"; - REQUIRE(!base_url.empty()); const auto partition = random_string(100); TestType test_type("collection", "dest"); Schema schema = {{"source", @@ -3484,7 +3475,7 @@ TEMPLATE_TEST_CASE("app: collections of links integration", "[sync][pbs][app][co {valid_pk_name, PropertyType::Int | PropertyType::Nullable, true}, {"realm_id", PropertyType::String | PropertyType::Nullable}, }}}; - auto server_app_config = minimal_app_config(base_url, "collections_of_links", schema); + auto server_app_config = minimal_app_config("collections_of_links", schema); TestAppSession test_session(create_app(server_app_config)); auto wait_for_num_objects_to_equal = [](realm::SharedRealm r, const std::string& table_name, size_t count) { @@ -3623,18 +3614,16 @@ TEMPLATE_TEST_CASE("app: partition types", "[sync][pbs][app][partition][baas]", cf::UUID, cf::BoxedOptional, cf::UnboxedOptional, cf::BoxedOptional, cf::BoxedOptional) { - std::string base_url = get_base_url(); const std::string valid_pk_name = "_id"; const std::string partition_key_col_name = "partition_key_prop"; const std::string table_name = "class_partition_test_type"; - REQUIRE(!base_url.empty()); auto partition_property = Property(partition_key_col_name, TestType::property_type); Schema schema = {{Group::table_name_to_class_name(table_name), { {valid_pk_name, PropertyType::Int, true}, partition_property, }}}; - auto server_app_config = minimal_app_config(base_url, "partition_types_app_name", schema); + auto server_app_config = minimal_app_config("partition_types_app_name", schema); server_app_config.partition_key = partition_property; TestAppSession test_session(create_app(server_app_config)); auto app = test_session.app(); @@ -3707,9 +3696,7 @@ TEMPLATE_TEST_CASE("app: partition types", "[sync][pbs][app][partition][baas]", } TEST_CASE("app: full-text compatible with sync", "[sync][app][baas]") { - std::string base_url = get_base_url(); const std::string valid_pk_name = "_id"; - REQUIRE(!base_url.empty()); Schema schema{ {"TopLevel", @@ -3719,7 +3706,7 @@ TEST_CASE("app: full-text compatible with sync", "[sync][app][baas]") { }}, }; - auto server_app_config = minimal_app_config(base_url, "full_text", schema); + auto server_app_config = minimal_app_config("full_text", schema); auto app_session = create_app(server_app_config); const auto partition = random_string(100); TestAppSession test_session(app_session, nullptr); diff --git a/test/object-store/sync/client_reset.cpp b/test/object-store/sync/client_reset.cpp index 9069cde683a..4b104a2758d 100644 --- a/test/object-store/sync/client_reset.cpp +++ b/test/object-store/sync/client_reset.cpp @@ -122,9 +122,7 @@ TEST_CASE("sync: large reset with recovery is restartable", "[sync][pbs][client }}, }; - std::string base_url = get_base_url(); - REQUIRE(!base_url.empty()); - auto server_app_config = minimal_app_config(base_url, "client_reset_tests", schema); + auto server_app_config = minimal_app_config("client_reset_tests", schema); server_app_config.partition_key = partition_prop; TestAppSession test_app_session(create_app(server_app_config)); auto app = test_app_session.app(); @@ -217,9 +215,7 @@ TEST_CASE("sync: pending client resets are cleared when downloads are complete", }}, }; - std::string base_url = get_base_url(); - REQUIRE(!base_url.empty()); - auto server_app_config = minimal_app_config(base_url, "client_reset_tests", schema); + auto server_app_config = minimal_app_config("client_reset_tests", schema); server_app_config.partition_key = partition_prop; TestAppSession test_app_session(create_app(server_app_config)); auto app = test_app_session.app(); @@ -297,9 +293,7 @@ TEST_CASE("sync: client reset", "[sync][pbs][client reset][baas]") { partition_prop, }}, }; - std::string base_url = get_base_url(); - REQUIRE(!base_url.empty()); - auto server_app_config = minimal_app_config(base_url, "client_reset_tests", schema); + auto server_app_config = minimal_app_config("client_reset_tests", schema); server_app_config.partition_key = partition_prop; TestAppSession test_app_session(create_app(server_app_config)); auto app = test_app_session.app(); @@ -1798,9 +1792,7 @@ TEST_CASE("sync: Client reset during async open", "[sync][pbs][client reset][baa }}, }; - std::string base_url = get_base_url(); - REQUIRE(!base_url.empty()); - auto server_app_config = minimal_app_config(base_url, "client_reset_tests", schema); + auto server_app_config = minimal_app_config("client_reset_tests", schema); server_app_config.partition_key = partition_prop; TestAppSession test_app_session(create_app(server_app_config)); auto app = test_app_session.app(); diff --git a/test/object-store/sync/flx_migration.cpp b/test/object-store/sync/flx_migration.cpp index ddea200e28b..d07fd323205 100644 --- a/test/object-store/sync/flx_migration.cpp +++ b/test/object-store/sync/flx_migration.cpp @@ -117,7 +117,6 @@ TEST_CASE("Test server migration and rollback", "[sync][flx][flx migration][baas std::shared_ptr logger_ptr = std::make_shared(realm::util::Logger::Level::TEST_LOGGING_LEVEL); - const std::string base_url = get_base_url(); const std::string partition1 = "migration-test"; const std::string partition2 = "another-value"; const Schema mig_schema{ @@ -125,7 +124,7 @@ TEST_CASE("Test server migration and rollback", "[sync][flx][flx migration][baas {"string_field", PropertyType::String | PropertyType::Nullable}, {"realm_id", PropertyType::String | PropertyType::Nullable}}), }; - auto server_app_config = minimal_app_config(base_url, "server_migrate_rollback", mig_schema); + auto server_app_config = minimal_app_config("server_migrate_rollback", mig_schema); TestAppSession session(create_app(server_app_config)); SyncTestFile config1(session.app(), partition1, server_app_config.schema); SyncTestFile config2(session.app(), partition2, server_app_config.schema); @@ -267,14 +266,13 @@ TEST_CASE("Test client migration and rollback", "[sync][flx][flx migration][baas std::shared_ptr logger_ptr = std::make_shared(realm::util::Logger::Level::TEST_LOGGING_LEVEL); - const std::string base_url = get_base_url(); const std::string partition = "migration-test"; const Schema mig_schema{ ObjectSchema("Object", {{"_id", PropertyType::ObjectId, Property::IsPrimary{true}}, {"string_field", PropertyType::String | PropertyType::Nullable}, {"realm_id", PropertyType::String | PropertyType::Nullable}}), }; - auto server_app_config = minimal_app_config(base_url, "server_migrate_rollback", mig_schema); + auto server_app_config = minimal_app_config("server_migrate_rollback", mig_schema); TestAppSession session(create_app(server_app_config)); SyncTestFile config(session.app(), partition, server_app_config.schema); config.sync_config->client_resync_mode = ClientResyncMode::DiscardLocal; @@ -324,13 +322,12 @@ TEST_CASE("Test client migration and rollback with recovery", "[sync][flx][flx m std::shared_ptr logger_ptr = std::make_shared(realm::util::Logger::Level::TEST_LOGGING_LEVEL); - const std::string base_url = get_base_url(); const std::string partition = "migration-test"; const Schema mig_schema{ ObjectSchema("Object", {{"_id", PropertyType::ObjectId, Property::IsPrimary{true}}, {"string_field", PropertyType::String | PropertyType::Nullable}}), }; - auto server_app_config = minimal_app_config(base_url, "server_migrate_rollback", mig_schema); + auto server_app_config = minimal_app_config("server_migrate_rollback", mig_schema); TestAppSession session(create_app(server_app_config)); SyncTestFile config(session.app(), partition, server_app_config.schema); config.sync_config->client_resync_mode = ClientResyncMode::Recover; @@ -476,14 +473,13 @@ TEST_CASE("An interrupted migration or rollback can recover on the next session" std::shared_ptr logger_ptr = std::make_shared(realm::util::Logger::Level::TEST_LOGGING_LEVEL); - const std::string base_url = get_base_url(); const std::string partition = "migration-test"; const Schema mig_schema{ ObjectSchema("Object", {{"_id", PropertyType::ObjectId, Property::IsPrimary{true}}, {"string_field", PropertyType::String | PropertyType::Nullable}, {"realm_id", PropertyType::String | PropertyType::Nullable}}), }; - auto server_app_config = minimal_app_config(base_url, "server_migrate_rollback", mig_schema); + auto server_app_config = minimal_app_config("server_migrate_rollback", mig_schema); TestAppSession session(create_app(server_app_config)); SyncTestFile config(session.app(), partition, server_app_config.schema); config.sync_config->client_resync_mode = ClientResyncMode::DiscardLocal; @@ -588,14 +584,13 @@ TEST_CASE("Update to native FLX after migration", "[sync][flx][flx migration][ba std::shared_ptr logger_ptr = std::make_shared(realm::util::Logger::Level::TEST_LOGGING_LEVEL); - const std::string base_url = get_base_url(); const std::string partition = "migration-test"; const Schema mig_schema{ ObjectSchema("Object", {{"_id", PropertyType::ObjectId, Property::IsPrimary{true}}, {"string_field", PropertyType::String | PropertyType::Nullable}, {"realm_id", PropertyType::String | PropertyType::Nullable}}), }; - auto server_app_config = minimal_app_config(base_url, "server_migrate_rollback", mig_schema); + auto server_app_config = minimal_app_config("server_migrate_rollback", mig_schema); TestAppSession session(create_app(server_app_config)); SyncTestFile config(session.app(), partition, server_app_config.schema); config.sync_config->client_resync_mode = ClientResyncMode::DiscardLocal; @@ -708,14 +703,13 @@ TEST_CASE("New table is synced after migration", "[sync][flx][flx migration][baa std::shared_ptr logger_ptr = std::make_shared(realm::util::Logger::Level::TEST_LOGGING_LEVEL); - const std::string base_url = get_base_url(); const std::string partition = "migration-test"; const Schema mig_schema{ ObjectSchema("Object", {{"_id", PropertyType::ObjectId, Property::IsPrimary{true}}, {"string_field", PropertyType::String | PropertyType::Nullable}, {"realm_id", PropertyType::String | PropertyType::Nullable}}), }; - auto server_app_config = minimal_app_config(base_url, "server_migrate_rollback", mig_schema); + auto server_app_config = minimal_app_config("server_migrate_rollback", mig_schema); TestAppSession session(create_app(server_app_config)); SyncTestFile config(session.app(), partition, server_app_config.schema); config.sync_config->client_resync_mode = ClientResyncMode::DiscardLocal; @@ -817,7 +811,6 @@ TEST_CASE("Async open + client reset", "[sync][flx][flx migration][baas]") { std::shared_ptr logger_ptr = std::make_shared(realm::util::Logger::Level::TEST_LOGGING_LEVEL); - const std::string base_url = get_base_url(); const std::string partition = "async-open-migration-test"; ObjectSchema shared_object("Object", {{"_id", PropertyType::ObjectId, Property::IsPrimary{true}}, {"string_field", PropertyType::String | PropertyType::Nullable}, @@ -825,7 +818,7 @@ TEST_CASE("Async open + client reset", "[sync][flx][flx migration][baas]") { const Schema mig_schema{shared_object}; size_t num_before_reset_notifications = 0; size_t num_after_reset_notifications = 0; - auto server_app_config = minimal_app_config(base_url, "async_open_during_migration", mig_schema); + auto server_app_config = minimal_app_config("async_open_during_migration", mig_schema); std::optional config; // destruct this after the sessions are torn down TestAppSession session(create_app(server_app_config)); config.emplace(session.app(), partition, server_app_config.schema); diff --git a/test/object-store/sync/flx_sync.cpp b/test/object-store/sync/flx_sync.cpp index b2bd8852993..0eb7459a68d 100644 --- a/test/object-store/sync/flx_sync.cpp +++ b/test/object-store/sync/flx_sync.cpp @@ -2274,8 +2274,7 @@ TEST_CASE("flx: subscriptions persist after closing/reopening", "[sync][flx][baa #endif TEST_CASE("flx: no subscription store created for PBS app", "[sync][flx][baas]") { - const std::string base_url = get_base_url(); - auto server_app_config = minimal_app_config(base_url, "flx_connect_as_pbs", g_minimal_schema); + auto server_app_config = minimal_app_config("flx_connect_as_pbs", g_minimal_schema); TestAppSession session(create_app(server_app_config)); SyncTestFile config(session.app(), bson::Bson{}, g_minimal_schema); @@ -2318,9 +2317,7 @@ TEST_CASE("flx: connect to FLX with partition value returns an error", "[sync][f } TEST_CASE("flx: connect to PBS as FLX returns an error", "[sync][flx][protocol][baas]") { - const std::string base_url = get_base_url(); - - auto server_app_config = minimal_app_config(base_url, "flx_connect_as_pbs", g_minimal_schema); + auto server_app_config = minimal_app_config("flx_connect_as_pbs", g_minimal_schema); TestAppSession session(create_app(server_app_config)); auto app = session.app(); auto user = app->current_user(); @@ -3323,7 +3320,7 @@ TEST_CASE("flx: convert flx sync realm to bundled realm", "[app][flx][baas]") { create_user_and_log_in(harness->app()); SyncTestFile target_config(harness->app()->current_user(), harness->schema(), SyncConfig::FLXSyncEnabled{}); - auto pbs_app_config = minimal_app_config(harness->app()->base_url(), "pbs_to_flx_convert", harness->schema()); + auto pbs_app_config = minimal_app_config("pbs_to_flx_convert", harness->schema()); TestAppSession pbs_app_session(create_app(pbs_app_config)); SyncTestFile source_config(pbs_app_session.app()->current_user(), "54321"s, pbs_app_config.schema); diff --git a/test/object-store/util/sync/baas_admin_api.cpp b/test/object-store/util/sync/baas_admin_api.cpp index a856376dcd9..b006ad5b7ae 100644 --- a/test/object-store/util/sync/baas_admin_api.cpp +++ b/test/object-store/util/sync/baas_admin_api.cpp @@ -445,17 +445,20 @@ nlohmann::json AdminAPIEndpoint::patch_json(nlohmann::json body) const return nlohmann::json::parse(resp.body.empty() ? "{}" : resp.body); } -AdminAPISession AdminAPISession::login(const std::string& base_url, const std::string& username, - const std::string& password) +AdminAPISession AdminAPISession::login(const AppCreateConfig& config) { + std::string admin_url = config.admin_url; nlohmann::json login_req_body{ {"provider", "userpass"}, - {"username", username}, - {"password", password}, + {"username", config.admin_username}, + {"password", config.admin_password}, }; + if (config.logger) { + config.logger->trace("Logging into baas admin api: %1", admin_url); + } app::Request auth_req{ app::HttpMethod::post, - util::format("%1/api/admin/v3.0/auth/providers/local-userpass/login", base_url), + util::format("%1/api/admin/v3.0/auth/providers/local-userpass/login", admin_url), 60000, // 1 minute timeout { {"Content-Type", "application/json;charset=utf-8"}, @@ -469,12 +472,12 @@ AdminAPISession AdminAPISession::login(const std::string& base_url, const std::s std::string access_token = login_resp_body["access_token"]; - AdminAPIEndpoint user_profile(util::format("%1/api/admin/v3.0/auth/profile", base_url), access_token); + AdminAPIEndpoint user_profile(util::format("%1/api/admin/v3.0/auth/profile", admin_url), access_token); auto profile_resp = user_profile.get_json(); std::string group_id = profile_resp["roles"][0]["group_id"]; - return AdminAPISession(std::move(base_url), std::move(access_token), std::move(group_id)); + return AdminAPISession(std::move(admin_url), std::move(access_token), std::move(group_id)); } void AdminAPISession::revoke_user_sessions(const std::string& user_id, const std::string& app_id) const @@ -754,10 +757,36 @@ AdminAPIEndpoint AdminAPISession::apps(APIFamily family) const REALM_UNREACHABLE(); } -AppCreateConfig default_app_config(const std::string& base_url) +realm::Schema get_default_schema() +{ + const auto dog_schema = + ObjectSchema("Dog", {realm::Property("_id", PropertyType::ObjectId | PropertyType::Nullable, true), + realm::Property("breed", PropertyType::String | PropertyType::Nullable), + realm::Property("name", PropertyType::String), + realm::Property("realm_id", PropertyType::String | PropertyType::Nullable)}); + const auto cat_schema = + ObjectSchema("Cat", {realm::Property("_id", PropertyType::String | PropertyType::Nullable, true), + realm::Property("breed", PropertyType::String | PropertyType::Nullable), + realm::Property("name", PropertyType::String), + realm::Property("realm_id", PropertyType::String | PropertyType::Nullable)}); + const auto person_schema = + ObjectSchema("Person", {realm::Property("_id", PropertyType::ObjectId | PropertyType::Nullable, true), + realm::Property("age", PropertyType::Int), + realm::Property("dogs", PropertyType::Object | PropertyType::Array, "Dog"), + realm::Property("firstName", PropertyType::String), + realm::Property("lastName", PropertyType::String), + realm::Property("realm_id", PropertyType::String | PropertyType::Nullable)}); + return realm::Schema({dog_schema, cat_schema, person_schema}); +} + +AppCreateConfig default_app_config() { ObjectId id = ObjectId::gen(); std::string db_name = util::format("test_data_%1", id.to_string()); + std::string app_url = get_base_url(); + std::string admin_url = get_admin_url(); + REALM_ASSERT(!app_url.empty()); + REALM_ASSERT(!admin_url.empty()); std::string update_user_data_func = util::format(R"( exports = async function(data) { @@ -816,25 +845,6 @@ AppCreateConfig default_app_config(const std::string& base_url) {"resetFunc", reset_func, false}, }; - const auto dog_schema = - ObjectSchema("Dog", {realm::Property("_id", PropertyType::ObjectId | PropertyType::Nullable, true), - realm::Property("breed", PropertyType::String | PropertyType::Nullable), - realm::Property("name", PropertyType::String), - realm::Property("realm_id", PropertyType::String | PropertyType::Nullable)}); - const auto cat_schema = - ObjectSchema("Cat", {realm::Property("_id", PropertyType::String | PropertyType::Nullable, true), - realm::Property("breed", PropertyType::String | PropertyType::Nullable), - realm::Property("name", PropertyType::String), - realm::Property("realm_id", PropertyType::String | PropertyType::Nullable)}); - const auto person_schema = - ObjectSchema("Person", {realm::Property("_id", PropertyType::ObjectId | PropertyType::Nullable, true), - realm::Property("age", PropertyType::Int), - realm::Property("dogs", PropertyType::Object | PropertyType::Array, "Dog"), - realm::Property("firstName", PropertyType::String), - realm::Property("lastName", PropertyType::String), - realm::Property("realm_id", PropertyType::String | PropertyType::Nullable)}); - realm::Schema default_schema({dog_schema, cat_schema, person_schema}); - Property partition_key("realm_id", PropertyType::String | PropertyType::Nullable); AppCreateConfig::UserPassAuthConfig user_pass_config{ @@ -849,27 +859,36 @@ AppCreateConfig default_app_config(const std::string& base_url) true, }; - return AppCreateConfig{"test", - base_url, - "unique_user@domain.com", - "password", - "mongodb://localhost:26000", - db_name, - std::move(default_schema), - std::move(partition_key), - true, // dev_mode_enabled - util::none, // Default to no FLX sync config - std::move(funcs), - std::move(user_pass_config), - std::string{"authFunc"}, - true, // enable_api_key_auth - true, // enable_anonymous_auth - true}; // enable_custom_token_auth + return AppCreateConfig{ + "test", + std::move(app_url), + std::move(admin_url), // BAAS Admin API URL may be different + "unique_user@domain.com", + "password", + get_mongodb_server(), + db_name, + get_default_schema(), + std::move(partition_key), + true, // dev_mode_enabled + util::none, // Default to no FLX sync config + std::move(funcs), // Add default functions + std::move(user_pass_config), // enable basic user/pass auth + std::string{"authFunc"}, // custom auth function + true, // enable_api_key_auth + true, // enable_anonymous_auth + true, // enable_custom_token_auth + {}, // no service roles on the default rule + util::Logger::get_default_logger(), // provide the logger to the admin api + }; } -AppCreateConfig minimal_app_config(const std::string& base_url, const std::string& name, const Schema& schema) +AppCreateConfig minimal_app_config(const std::string& name, const Schema& schema) { Property partition_key("realm_id", PropertyType::String | PropertyType::Nullable); + std::string app_url = get_base_url(); + std::string admin_url = get_admin_url(); + REALM_ASSERT(!app_url.empty()); + REALM_ASSERT(!admin_url.empty()); AppCreateConfig::UserPassAuthConfig user_pass_config{ true, "Confirm", "", "http://example.com/confirmEmail", "", "Reset", "http://exmaple.com/resetPassword", @@ -879,27 +898,30 @@ AppCreateConfig minimal_app_config(const std::string& base_url, const std::strin ObjectId id = ObjectId::gen(); return AppCreateConfig{ name, - base_url, + std::move(app_url), + std::move(admin_url), // BAAS Admin API URL may be different "unique_user@domain.com", "password", - "mongodb://localhost:26000", + get_mongodb_server(), util::format("test_data_%1_%2", name, id.to_string()), schema, std::move(partition_key), - true, // dev_mode_enabled - util::none, // no FLX sync config - {}, // no functions - std::move(user_pass_config), // enable basic user/pass auth - util::none, // disable custom auth - true, // enable api key auth - true, // enable anonymous auth - {}, // no service roles on the default rule + true, // dev_mode_enabled + util::none, // no FLX sync config + {}, // no functions + std::move(user_pass_config), // enable basic user/pass auth + util::none, // disable custom auth + true, // enable api key auth + true, // enable anonymous auth + false, // enable_custom_token_auth + {}, // no service roles on the default rule + util::Logger::get_default_logger(), // provide the logger to the admin api }; } AppSession create_app(const AppCreateConfig& config) { - auto session = AdminAPISession::login(config.base_url, config.admin_username, config.admin_password); + auto session = AdminAPISession::login(config); auto create_app_resp = session.apps().post_json(nlohmann::json{{"name", config.app_name}}); std::string app_id = create_app_resp["_id"]; std::string client_app_id = create_app_resp["client_app_id"]; @@ -1153,20 +1175,22 @@ AppSession create_app(const AppCreateConfig& config) return {client_app_id, app_id, session, config}; } -AppSession get_runtime_app_session(std::string base_url) +AppSession get_runtime_app_session() { static const AppSession cached_app_session = [&] { - auto cached_app_session = create_app(default_app_config(base_url)); + auto cached_app_session = create_app(default_app_config()); return cached_app_session; }(); return cached_app_session; } +std::string get_mongodb_server() +{ + return "mongodb://localhost:26000"; +} #ifdef REALM_MONGODB_ENDPOINT TEST_CASE("app: baas admin api", "[sync][app][admin api][baas]") { - std::string base_url = REALM_QUOTE(REALM_MONGODB_ENDPOINT); - base_url.erase(std::remove(base_url.begin(), base_url.end(), '"'), base_url.end()); SECTION("embedded objects") { Schema schema{{"top", {{"_id", PropertyType::String, true}, @@ -1175,7 +1199,7 @@ TEST_CASE("app: baas admin api", "[sync][app][admin api][baas]") { ObjectSchema::ObjectType::Embedded, {{"coordinates", PropertyType::Double | PropertyType::Array}}}}; - auto test_app_config = minimal_app_config(base_url, "test", schema); + auto test_app_config = minimal_app_config("test", schema); create_app(test_app_config); } @@ -1189,7 +1213,7 @@ TEST_CASE("app: baas admin api", "[sync][app][admin api][baas]") { {{"c_link", PropertyType::Object | PropertyType::Nullable, "c"}}}, {"c", {{"_id", PropertyType::String, true}, {"d_str", PropertyType::String}}}, }; - auto test_app_config = minimal_app_config(base_url, "test", schema); + auto test_app_config = minimal_app_config("test", schema); create_app(test_app_config); } @@ -1198,7 +1222,7 @@ TEST_CASE("app: baas admin api", "[sync][app][admin api][baas]") { {"a", {{"_id", PropertyType::String, true}, {"b_dict", PropertyType::Dictionary | PropertyType::String}}}, }; - auto test_app_config = minimal_app_config(base_url, "test", schema); + auto test_app_config = minimal_app_config("test", schema); create_app(test_app_config); } @@ -1207,7 +1231,7 @@ TEST_CASE("app: baas admin api", "[sync][app][admin api][baas]") { {"a", {{"_id", PropertyType::String, true}, {"b_dict", PropertyType::Set | PropertyType::String}}}, }; - auto test_app_config = minimal_app_config(base_url, "test", schema); + auto test_app_config = minimal_app_config("test", schema); create_app(test_app_config); } } diff --git a/test/object-store/util/sync/baas_admin_api.hpp b/test/object-store/util/sync/baas_admin_api.hpp index 4756f53a2a1..c150555dc0f 100644 --- a/test/object-store/util/sync/baas_admin_api.hpp +++ b/test/object-store/util/sync/baas_admin_api.hpp @@ -30,6 +30,8 @@ #include #include +#include + #include #include @@ -65,10 +67,11 @@ class AdminAPIEndpoint { std::string m_access_token; }; +struct AppCreateConfig; + class AdminAPISession { public: - static AdminAPISession login(const std::string& base_url, const std::string& username, - const std::string& password); + static AdminAPISession login(const AppCreateConfig& config); enum class APIFamily { Admin, Private }; AdminAPIEndpoint apps(APIFamily family = APIFamily::Admin) const; @@ -133,14 +136,14 @@ class AdminAPISession { MigrationStatus get_migration_status(const std::string& app_id) const; - const std::string& base_url() const noexcept + const std::string& admin_url() const noexcept { return m_base_url; } private: - AdminAPISession(std::string base_url, std::string access_token, std::string group_id) - : m_base_url(std::move(base_url)) + AdminAPISession(std::string admin_url, std::string access_token, std::string group_id) + : m_base_url(std::move(admin_url)) , m_access_token(std::move(access_token)) , m_group_id(std::move(group_id)) { @@ -213,7 +216,8 @@ struct AppCreateConfig { }; std::string app_name; - std::string base_url; + std::string app_url; + std::string admin_url; std::string admin_username; std::string admin_password; @@ -234,10 +238,13 @@ struct AppCreateConfig { bool enable_custom_token_auth = false; std::vector service_roles; + + std::shared_ptr logger; }; -AppCreateConfig default_app_config(const std::string& base_url); -AppCreateConfig minimal_app_config(const std::string& base_url, const std::string& name, const Schema& schema); +realm::Schema get_default_schema(); +AppCreateConfig default_app_config(); +AppCreateConfig minimal_app_config(const std::string& name, const Schema& schema); struct AppSession { std::string client_app_id; @@ -271,16 +278,18 @@ class SynchronousTestTransport : public app::GenericNetworkTransport { std::mutex m_mutex; }; -// This will create a new test app in the baas server at base_url -// to be used in tests. -AppSession get_runtime_app_session(std::string base_url); +// This will create a new test app in the baas server - base_url and admin_url +// are automatically set +AppSession get_runtime_app_session(); + +std::string get_mongodb_server(); template inline app::App::Config get_config(Factory factory, const AppSession& app_session) { return {app_session.client_app_id, factory, - app_session.admin_api.base_url(), + app_session.config.app_url, util::none, util::Optional("A Local App Version"), util::none, diff --git a/test/object-store/util/sync/flx_sync_harness.hpp b/test/object-store/util/sync/flx_sync_harness.hpp index ff409e26f55..2a886d11c1f 100644 --- a/test/object-store/util/sync/flx_sync_harness.hpp +++ b/test/object-store/util/sync/flx_sync_harness.hpp @@ -52,7 +52,7 @@ class FLXSyncTestHarness { static AppSession make_app_from_server_schema(const std::string& test_name, const FLXSyncTestHarness::ServerSchema& server_schema) { - auto server_app_config = minimal_app_config(get_base_url(), test_name, server_schema.schema); + auto server_app_config = minimal_app_config(test_name, server_schema.schema); server_app_config.dev_mode_enabled = server_schema.dev_mode_enabled; AppCreateConfig::FLXSyncConfig flx_config; flx_config.queryable_fields = server_schema.queryable_fields; diff --git a/test/object-store/util/sync/sync_test_utils.cpp b/test/object-store/util/sync/sync_test_utils.cpp index 416c09d9dc1..7fc814de2bd 100644 --- a/test/object-store/util/sync/sync_test_utils.cpp +++ b/test/object-store/util/sync/sync_test_utils.cpp @@ -172,18 +172,38 @@ ExpectedRealmPaths::ExpectedRealmPaths(const std::string& base_path, const std:: #if REALM_ENABLE_AUTH_TESTS +static std::string unquote_string(std::string_view possibly_quoted_string) +{ + if (possibly_quoted_string.size() > 0) { + auto check_char = possibly_quoted_string.front(); + if (check_char == '"' || check_char == '\'') { + possibly_quoted_string.remove_prefix(1); + } + } + if (possibly_quoted_string.size() > 0) { + auto check_char = possibly_quoted_string.back(); + if (check_char == '"' || check_char == '\'') { + possibly_quoted_string.remove_suffix(1); + } + } + return std::string{possibly_quoted_string}; +} + #ifdef REALM_MONGODB_ENDPOINT std::string get_base_url() { // allows configuration with or without quotes - std::string base_url = REALM_QUOTE(REALM_MONGODB_ENDPOINT); - if (base_url.size() > 0 && base_url[0] == '"') { - base_url.erase(0, 1); - } - if (base_url.size() > 0 && base_url[base_url.size() - 1] == '"') { - base_url.erase(base_url.size() - 1); - } - return base_url; + return unquote_string(REALM_QUOTE(REALM_MONGODB_ENDPOINT)); +} + +std::string get_admin_url() +{ +#ifdef REALM_ADMIN_ENDPOINT + // allows configuration with or without quotes + return unquote_string(REALM_QUOTE(REALM_ADMIN_ENDPOINT)); +#else + return get_base_url(); +#endif } #endif // REALM_MONGODB_ENDPOINT diff --git a/test/object-store/util/sync/sync_test_utils.hpp b/test/object-store/util/sync/sync_test_utils.hpp index f1a60f5ab1f..865c9094951 100644 --- a/test/object-store/util/sync/sync_test_utils.hpp +++ b/test/object-store/util/sync/sync_test_utils.hpp @@ -146,6 +146,8 @@ TestSyncManager::Config get_config(Transport&& transport) #ifdef REALM_MONGODB_ENDPOINT std::string get_base_url(); +std::string get_admin_url(); + #endif struct AutoVerifiedEmailCredentials : app::AppCredentials { diff --git a/test/object-store/util/test_file.cpp b/test/object-store/util/test_file.cpp index f789079b1c5..2bcf460666c 100644 --- a/test/object-store/util/test_file.cpp +++ b/test/object-store/util/test_file.cpp @@ -317,7 +317,7 @@ void set_app_config_defaults(app::App::Config& app_config, #if REALM_ENABLE_AUTH_TESTS TestAppSession::TestAppSession() - : TestAppSession(get_runtime_app_session(get_base_url()), nullptr, DeleteApp{false}) + : TestAppSession(get_runtime_app_session(), nullptr, DeleteApp{false}) { } From 4627f9cd2f19d7194aa089839c3f829ffe6bdeea Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Thu, 10 Aug 2023 23:45:27 -0400 Subject: [PATCH 12/22] empty commit From a26a87aeaf6e1bf17861cf5fed571943b7a0168d Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Fri, 11 Aug 2023 00:24:56 -0400 Subject: [PATCH 13/22] Minor port check adjustments --- evergreen/install_baas.sh | 11 +++++------ evergreen/setup_baas_host.sh | 2 +- evergreen/setup_baas_host_local.sh | 27 ++++++++++++++++++++++++++- evergreen/setup_baas_proxy.sh | 10 ++++++---- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/evergreen/install_baas.sh b/evergreen/install_baas.sh index 82bebc3b734..046ba88c5f2 100755 --- a/evergreen/install_baas.sh +++ b/evergreen/install_baas.sh @@ -166,9 +166,9 @@ if [[ -z "${AWS_ACCESS_KEY_ID}" || -z "${AWS_SECRET_ACCESS_KEY}" ]]; then exit 1 fi -function check_port() +function check_port_in_use() { - # Usage: check_port PORT PORT_NAME + # Usage: check_port_in_use PORT PORT_NAME port_num="${1}" port_check=$(lsof -P "-i:${port_num}" | grep "LISTEN" || true) if [[ -n "${port_check}" ]]; then @@ -180,10 +180,10 @@ function check_port() # Check the mongodb and baas_server port availability first MONGODB_PORT=26000 -check_port "${MONGODB_PORT}" "mongodb" +check_port_in_use "${MONGODB_PORT}" "mongodb" BAAS_PORT=9090 -check_port "${BAAS_PORT}" "baas server" +check_port_in_use "${BAAS_PORT}" "baas server" # Wait to enable verbosity logging, if enabled if [[ -n "${VERBOSE}" ]]; then @@ -437,7 +437,6 @@ mkdir -p "${MONGODB_PATH}" --dbpath "${MONGODB_PATH}/" \ --pidfilepath "${MONGOD_PID_FILE}" & - # Wait for mongod to start (up to 40 secs) while attempting to initialize the replica set echo "Initializing replica set" @@ -507,4 +506,4 @@ echo "Baas server ready" echo "---------------------------------------------" wait -popd > /dev/null # baas \ No newline at end of file +popd > /dev/null # baas diff --git a/evergreen/setup_baas_host.sh b/evergreen/setup_baas_host.sh index 213390716f7..62c67d52af3 100755 --- a/evergreen/setup_baas_host.sh +++ b/evergreen/setup_baas_host.sh @@ -225,7 +225,7 @@ fi sudo chmod 600 "${HOME}/.ssh"/* -# Should an alternate data directory location be used? If so, dont init the data device +# Should an alternate data directory location be used? If so, don't init the data device if [[ -z "${OPT_DATA_DIR}" ]]; then DATA_DIR=/data init_data_device diff --git a/evergreen/setup_baas_host_local.sh b/evergreen/setup_baas_host_local.sh index a7d30ae4b5b..388137fe6cc 100755 --- a/evergreen/setup_baas_host_local.sh +++ b/evergreen/setup_baas_host_local.sh @@ -32,7 +32,7 @@ function usage() echo -e "\t-v\t\tEnable verbose script debugging" echo -e "\t-h\t\tShow this usage summary and exit" echo "Baas Proxy Options:" - echo -e "\t-t\t\tEnable baas proxy support (proxy between baas on :9090 and remote port)" + echo -e "\t-t\t\tEnable baas proxy support (proxy between baas on :9090 and listen port)" echo -e "\t-d PORT\t\tPort for direct connection to baas - skips proxy (default ${DIRECT_PORT})" echo -e "\t-l PORT\t\tBaas proxy listen port on remote host (default ${LISTEN_PORT})" echo -e "\t-c PORT\t\tLocal configuration port for proxy HTTP API (default ${CONFIG_PORT})" @@ -96,6 +96,22 @@ function check_port() return 1 } +function check_port_in_use() +{ + # Usage: check_port_in_use PORT PORT_NAME + port_num="${1}" + port_check=$(lsof -P "-i:${port_num}" | grep "LISTEN" || true) + if [[ -n "${port_check}" ]]; then + echo "Error: ${2} port (${port_num}) is already in use" + echo -e "${port_check}" + exit 1 + fi +} + +# Check the local baas port availability +check_port_in_use "${CONFIG_PORT}" "Baas proxy config" + +# Check the port values and local ports in use for baas proxy if [[ -n "${BAAS_PROXY}" ]]; then if ! check_port "${CONFIG_PORT}"; then echo "Error: Baas proxy local HTTP API config port was invalid: '${CONFIG_PORT}'" @@ -104,6 +120,15 @@ if [[ -n "${BAAS_PROXY}" ]]; then echo "Error: Baas proxy listen port was invalid: '${LISTEN_PORT}'" usage 1 fi + check_port_in_use "${CONFIG_PORT}" "Baas proxy config" + + if [[ -n "${DIRECT_PORT}" ]]; then + if ! check_port "${DIRECT_PORT}"; then + echo "Error: Baas direct connect port was invalid: '${DIRECT_PORT}'" + usage 1 + fi + check_port_in_use "${DIRECT_PORT}" "Baas direct connect" + fi fi trap 'catch $? ${LINENO}' ERR diff --git a/evergreen/setup_baas_proxy.sh b/evergreen/setup_baas_proxy.sh index a11db1c360a..3255d142a2f 100755 --- a/evergreen/setup_baas_proxy.sh +++ b/evergreen/setup_baas_proxy.sh @@ -24,6 +24,7 @@ TOXIPROXY_VERSION="v2.5.0" LISTEN_PORT=9092 BAAS_PORT=9090 SKIP_BAAS_WAIT= +CONFIG_PORT=8474 function usage() { @@ -67,9 +68,9 @@ if [[ -z "${LISTEN_PORT}" ]]; then usage 1 fi -function check_port() +function check_port_in_use() { - # Usage: check_port PORT PORT_NAME + # Usage: check_port_in_use PORT PORT_NAME port_num="${1}" port_check=$(lsof -P "-i:${port_num}" | grep "LISTEN" || true) if [[ -n "${port_check}" ]]; then @@ -79,8 +80,9 @@ function check_port() fi } -# Check the mongodb and baas_server port availability first -check_port "${LISTEN_PORT}" "baas proxy" +# Check the baas proxy listen and Toxiproxy config port availability first +check_port_in_use "${LISTEN_PORT}" "baas proxy" +checK_port_in_use "${CONFIG_PORT}" "Toxiproxy config" [[ -d "${WORK_PATH}" ]] || mkdir -p "${WORK_PATH}" pushd "${WORK_PATH}" > /dev/null From cb61a46a823b851e3e8410bbe8de3e2dfd4c4aeb Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Fri, 11 Aug 2023 00:53:17 -0400 Subject: [PATCH 14/22] Removed 'compile' task from network_tests --- evergreen/config.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/evergreen/config.yml b/evergreen/config.yml index 1f86697aec0..526ce5ff772 100644 --- a/evergreen/config.yml +++ b/evergreen/config.yml @@ -1139,7 +1139,6 @@ task_groups: timeout: - func: "run hang analyzer" tasks: - - compile - baas-network-tests # Runs object-store-tests against baas running on remote host @@ -1389,7 +1388,7 @@ buildvariants: test_logging_level: trace tasks: - name: network_tests - patchable: true + activate: true - name: rhel70 display_name: "RHEL 7 x86_64" From 2b134b6d15dba5143cc747dbac39bb5f683cefcd Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Fri, 11 Aug 2023 08:55:15 -0400 Subject: [PATCH 15/22] Misspelled function name --- evergreen/setup_baas_proxy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/evergreen/setup_baas_proxy.sh b/evergreen/setup_baas_proxy.sh index 3255d142a2f..8a5d1ba4443 100755 --- a/evergreen/setup_baas_proxy.sh +++ b/evergreen/setup_baas_proxy.sh @@ -82,7 +82,7 @@ function check_port_in_use() # Check the baas proxy listen and Toxiproxy config port availability first check_port_in_use "${LISTEN_PORT}" "baas proxy" -checK_port_in_use "${CONFIG_PORT}" "Toxiproxy config" +check_port_in_use "${CONFIG_PORT}" "Toxiproxy config" [[ -d "${WORK_PATH}" ]] || mkdir -p "${WORK_PATH}" pushd "${WORK_PATH}" > /dev/null From f6c2d5856479defb8b5a9c6ef70f46db7da3ec09 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Fri, 11 Aug 2023 14:20:52 -0400 Subject: [PATCH 16/22] Updated changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0487b25f782..5b8f95bfac0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ ### Internals * Removed some unused files/directories and dogless dependency. ([PR #6884](https://github.com/realm/realm-core/pull/6884)) +* Add baas-network-tests nightly task for (future) testing sync client operation with non-ideal network conditions. ([PR #6852](https://github.com/realm/realm-core/pull/6852)) ---------------------------------------------- @@ -48,7 +49,6 @@ ### Internals * Timestamp objects can now only be created from a system clock timepoint. ([#6112](https://github.com/realm/realm-core/issues/6112)) -* Add baas-network-tests nightly task for testing sync client operation with non-ideal network conditions. ([PR #6852](https://github.com/realm/realm-core/pull/6852)) ---------------------------------------------- From 3080c0c520bc63116f6ace37c0157762450450fe Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Mon, 14 Aug 2023 19:04:53 -0400 Subject: [PATCH 17/22] Disable development mode by default --- test/object-store/sync/client_reset.cpp | 8 ++++++- test/object-store/sync/flx_migration.cpp | 23 ++++++++----------- .../object-store/util/sync/baas_admin_api.cpp | 4 ++-- .../util/sync/sync_test_utils.cpp | 18 +++++++++++++++ .../util/sync/sync_test_utils.hpp | 1 + 5 files changed, 37 insertions(+), 17 deletions(-) diff --git a/test/object-store/sync/client_reset.cpp b/test/object-store/sync/client_reset.cpp index 175c47c2c6c..3ca652e4004 100644 --- a/test/object-store/sync/client_reset.cpp +++ b/test/object-store/sync/client_reset.cpp @@ -598,6 +598,7 @@ TEST_CASE("sync: client reset", "[sync][pbs][client reset][baas]") { } }; make_reset(local_config, remote_config) + ->set_development_mode(true) ->setup([&](SharedRealm before) { before->update_schema( { @@ -697,6 +698,7 @@ TEST_CASE("sync: client reset", "[sync][pbs][client reset][baas]") { err = error; }; make_reset(local_config, remote_config) + ->set_development_mode(true) ->make_local_changes([&](SharedRealm local) { local->update_schema( { @@ -1174,6 +1176,7 @@ TEST_CASE("sync: client reset", "[sync][pbs][client reset][baas]") { err = error; }; make_reset(local_config, remote_config) + ->set_development_mode(true) ->make_local_changes([&](SharedRealm local) { local->update_schema( { @@ -1206,6 +1209,7 @@ TEST_CASE("sync: client reset", "[sync][pbs][client reset][baas]") { err = error; }; make_reset(local_config, remote_config) + ->set_development_mode(true) ->make_local_changes([](SharedRealm local) { local->update_schema( { @@ -1237,7 +1241,7 @@ TEST_CASE("sync: client reset", "[sync][pbs][client reset][baas]") { } SECTION("compatible schema changes in both remote and local transactions") { - test_reset + test_reset->set_development_mode(true) ->make_local_changes([](SharedRealm local) { local->update_schema( { @@ -1289,6 +1293,7 @@ TEST_CASE("sync: client reset", "[sync][pbs][client reset][baas]") { err = error; }; make_reset(local_config, remote_config) + ->set_development_mode(true) ->make_local_changes([](SharedRealm local) { local->update_schema( { @@ -1331,6 +1336,7 @@ TEST_CASE("sync: client reset", "[sync][pbs][client reset][baas]") { }; make_reset(local_config, remote_config) + ->set_development_mode(true) ->make_local_changes([](SharedRealm local) { local->update_schema( { diff --git a/test/object-store/sync/flx_migration.cpp b/test/object-store/sync/flx_migration.cpp index 7b47fccf7bb..5f0aa3c9e45 100644 --- a/test/object-store/sync/flx_migration.cpp +++ b/test/object-store/sync/flx_migration.cpp @@ -704,12 +704,14 @@ TEST_CASE("New table is synced after migration", "[sync][flx][flx migration][baa std::make_shared(realm::util::Logger::Level::TEST_LOGGING_LEVEL); const std::string partition = "migration-test"; - const Schema mig_schema{ - ObjectSchema("Object", {{"_id", PropertyType::ObjectId, Property::IsPrimary{true}}, - {"string_field", PropertyType::String | PropertyType::Nullable}, - {"realm_id", PropertyType::String | PropertyType::Nullable}}), - }; - auto server_app_config = minimal_app_config("server_migrate_rollback", mig_schema); + const auto obj1_schema = ObjectSchema("Object", {{"_id", PropertyType::ObjectId, Property::IsPrimary{true}}, + {"string_field", PropertyType::String | PropertyType::Nullable}, + {"realm_id", PropertyType::String | PropertyType::Nullable}}); + const auto obj2_schema = ObjectSchema("Object2", {{"_id", PropertyType::ObjectId, Property::IsPrimary{true}}, + {"realm_id", PropertyType::String | PropertyType::Nullable}}); + const Schema mig_schema{obj1_schema}; + const Schema two_obj_schema{obj1_schema, obj2_schema}; + auto server_app_config = minimal_app_config("server_migrate_rollback", two_obj_schema); TestAppSession session(create_app(server_app_config)); SyncTestFile config(session.app(), partition, server_app_config.schema); config.sync_config->client_resync_mode = ClientResyncMode::DiscardLocal; @@ -743,14 +745,7 @@ TEST_CASE("New table is synced after migration", "[sync][flx][flx migration][baa // Open a new realm with an additional table. { - const Schema schema{ - ObjectSchema("Object", {{"_id", PropertyType::ObjectId, Property::IsPrimary{true}}, - {"string_field", PropertyType::String | PropertyType::Nullable}, - {"realm_id", PropertyType::String | PropertyType::Nullable}}), - ObjectSchema("Object2", {{"_id", PropertyType::ObjectId, Property::IsPrimary{true}}, - {"realm_id", PropertyType::String | PropertyType::Nullable}}), - }; - SyncTestFile flx_config(session.app()->current_user(), schema, SyncConfig::FLXSyncEnabled{}); + SyncTestFile flx_config(session.app()->current_user(), two_obj_schema, SyncConfig::FLXSyncEnabled{}); auto flx_realm = Realm::get_shared_realm(flx_config); diff --git a/test/object-store/util/sync/baas_admin_api.cpp b/test/object-store/util/sync/baas_admin_api.cpp index b006ad5b7ae..d2623b75938 100644 --- a/test/object-store/util/sync/baas_admin_api.cpp +++ b/test/object-store/util/sync/baas_admin_api.cpp @@ -869,7 +869,7 @@ AppCreateConfig default_app_config() db_name, get_default_schema(), std::move(partition_key), - true, // dev_mode_enabled + false, // Dev mode disabled util::none, // Default to no FLX sync config std::move(funcs), // Add default functions std::move(user_pass_config), // enable basic user/pass auth @@ -906,7 +906,7 @@ AppCreateConfig minimal_app_config(const std::string& name, const Schema& schema util::format("test_data_%1_%2", name, id.to_string()), schema, std::move(partition_key), - true, // dev_mode_enabled + false, // Dev mode disabled util::none, // no FLX sync config {}, // no functions std::move(user_pass_config), // enable basic user/pass auth diff --git a/test/object-store/util/sync/sync_test_utils.cpp b/test/object-store/util/sync/sync_test_utils.cpp index 7fc814de2bd..a94696626f0 100644 --- a/test/object-store/util/sync/sync_test_utils.cpp +++ b/test/object-store/util/sync/sync_test_utils.cpp @@ -521,6 +521,13 @@ struct BaasClientReset : public TestClientReset { { } + TestClientReset* set_development_mode(bool enable) override + { + const AppSession& app_session = m_test_app_session.app_session(); + app_session.admin_api.set_development_mode_to(app_session.server_app_id, enable); + return this; + } + void run() override { m_did_run = true; @@ -646,6 +653,13 @@ struct BaasFLXClientReset : public TestClientReset { REALM_ASSERT(m_local_config.schema->find(c_object_schema_name) != m_local_config.schema->end()); } + TestClientReset* set_development_mode(bool enable) override + { + const AppSession& app_session = m_test_app_session.app_session(); + app_session.admin_api.set_development_mode_to(app_session.server_app_id, enable); + return this; + } + void run() override { m_did_run = true; @@ -821,6 +835,10 @@ TestClientReset* TestClientReset::on_post_reset(Callback&& post_reset) m_on_post_reset = std::move(post_reset); return this; } +TestClientReset* TestClientReset::set_development_mode(bool) +{ + return this; +} void TestClientReset::set_pk_of_object_driving_reset(const ObjectId& pk) { diff --git a/test/object-store/util/sync/sync_test_utils.hpp b/test/object-store/util/sync/sync_test_utils.hpp index 865c9094951..06f9efaf7d9 100644 --- a/test/object-store/util/sync/sync_test_utils.hpp +++ b/test/object-store/util/sync/sync_test_utils.hpp @@ -194,6 +194,7 @@ struct TestClientReset { ObjectId get_pk_of_object_driving_reset() const; void disable_wait_for_reset_completion(); + virtual TestClientReset* set_development_mode(bool enable = true); virtual void run() = 0; protected: From a62b4b24e4a5e1494df1a18a287a3883dca0b596 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Wed, 16 Aug 2023 13:53:04 -0400 Subject: [PATCH 18/22] Updated baas branch to 'master' --- evergreen/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/evergreen/config.yml b/evergreen/config.yml index 63dc303d0b2..8b65c7e0f5e 100644 --- a/evergreen/config.yml +++ b/evergreen/config.yml @@ -899,7 +899,7 @@ tasks: commands: - func: "launch remote baas" vars: - baas_branch: 3f31617aacfe5d31b9057fc298b735b60acd6424 + baas_branch: master - func: "compile" vars: target_to_build: ObjectStoreTests @@ -917,7 +917,7 @@ tasks: commands: - func: "launch remote baas" vars: - baas_branch: 1a0d1c021460d2215b21bc4f7c7f668714ce81c7 + baas_branch: master baas_proxy: On - func: "compile" vars: From 5475eaae0dc8fb1a5bbdad8d8292fa6dd99d01f4 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Fri, 18 Aug 2023 16:38:55 -0400 Subject: [PATCH 19/22] Updated changelog after release --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8993be0f883..624ca9c749b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ ----------- ### Internals -* None. +* Add baas-network-tests nightly task for (future) testing sync client operation with non-ideal network conditions. ([PR #6852](https://github.com/realm/realm-core/pull/6852)) ---------------------------------------------- @@ -49,7 +49,6 @@ ### Internals * Removed some unused files/directories and dogless dependency. ([PR #6884](https://github.com/realm/realm-core/pull/6884)) -* Add baas-network-tests nightly task for (future) testing sync client operation with non-ideal network conditions. ([PR #6852](https://github.com/realm/realm-core/pull/6852)) ---------------------------------------------- From 7e9f5c1959cd9fc20541f0beae79564a827afa27 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Tue, 22 Aug 2023 00:43:14 -0400 Subject: [PATCH 20/22] Added baas remote host and network tests instructions doc --- doc/development/how-to-use-baas-proxy.md | 261 +++++++++++++++++++++++ evergreen/setup_baas_host.sh | 2 +- evergreen/setup_baas_host_local.sh | 7 +- 3 files changed, 266 insertions(+), 4 deletions(-) create mode 100644 doc/development/how-to-use-baas-proxy.md diff --git a/doc/development/how-to-use-baas-proxy.md b/doc/development/how-to-use-baas-proxy.md new file mode 100644 index 00000000000..d6a326bc4b8 --- /dev/null +++ b/doc/development/how-to-use-baas-proxy.md @@ -0,0 +1,261 @@ +# How to Run remote-baas, the baas-proxy and Network Tests Locally + +The following instructions demonstrate how to set up and run the remote baas and remote proxy + +## Running remote baas on an Evergreen Spawn Host + +1. Spawn and/or start an `ubuntu2004-medium` host in Evergreen and select an SSH key to use + for the connection. Make sure you have a local copy of the private and public key selected. +2. Create a `baas_host_vars.sh` file with the following contents: + +```bash +export AWS_ACCESS_KEY_ID='' +export AWS_SECRET_ACCESS_KEY='' +export BAAS_HOST_NAME="" +export REALM_CORE_REVISION="" +export GITHUB_KNOWN_HOSTS="github.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphnt+VTTvDP6mHBL9j1aNUkY4Ue1gvwnGLVlOhGeYrnZaMgRK6+PKCUXaDbC7qtbW8gIkhL7aGCsOr/C56SJMy/BCZfxd1nWzAOxSDPgVsmerOBYfNqltV9/hWCqBywINIR+5dIg6JTJ72pcEpEjcYgXkE2YEFXV1JHnsKgbLWNlhScqb2UmyRkQyytRLtL+38TGxkxCflmO+5Z8CSSNY7GidjMIZ7Q4zMjA2n1nGrlTDkzwDCsw+wqFPGQA179cnfGWOWRVruj16z6XyvxvjJwbz0wQZ75XK5tKSb7FNyeIEs4TT4jk+S4dhPeAUC5y+bDYirYgM4GC7uEnztnZyaVWQ7B381AK4Qdrwt51ZqExKbQpTUNn+EjqoTwvqNj4kqx5QUCI0ThS/YkOxJCXmPUWZbhjpCg56i+2aB6CmK2JGhn57K5mj0MNdBXA4/WnwH6XoPWJzK5Nyu2zB3nAZp+S5hpQs+p1vN1/wsjk=" +``` + +**NOTE**: The `install_baas.sh` and `setup_baas_host.sh` files from the +local _evergreen/_ directory will be transferred to the remote host. The `REALM_CORE_REVISION` +specifies which Realm Core branch/commit to use for other auxillary files used during baas_server +and baas_proxy setup. + +3. CD into the _realm-core/_ directory. +4. Run the _evergreen/setup_baas_host_local.sh_ script with the following arguments: + +```bash +$ evergreen/setup_baas_host_local.sh +. . . +Running setup script (with forward tunnel on :9090 to 127.0.0.1:9090) +. . . +Starting baas app server +Adding roles to admin user +--------------------------------------------- +Baas server ready +--------------------------------------------- + +# To enable verbose logging, add the -v argument before the baas_host_vars.sh file argurment +# Use the '-b ' to specify a specific version of the baas server to download/use +``` + +**NOTES:** + +* You must be connected to the MongoDB network either directly or via VPN in order to communicate +with the spawn host. If you get this error, check your network connection. It could also be due to +an incorrect host name for the `BAAS_HOST_NAME` setting in `baas_host_vars.sh`. + +```bash +SSH connection attempt 1/25 failed. Retrying... +ssh: connect to host port 22: Operation timed out +``` + +* If any of the local ports are in use, an error message will be displayed when the + script is run. Close any programs that are using these ports. + +```bash +Error: Local baas server port (9090) is already in use +baas_serv 66287 ... 12u IPv6 0x20837f52a108aa91 0t0 TCP *:9090 (LISTEN) +``` + +5. The required script files will be uploaded to the spawn host and the baas server will be + downloaded and started. The following local tunnels will be created over the SSH + connection to forward traffic to the remote host: + * **localhost:9090 -> baas server** - any traffic to local port 9090 will be forwarded to + the baas server running on the remote host. +6. Use CTRL-C to cancel the baas remote host script and stop the baas server running on the + spawn host. + +## Running remote baas and proxy on an Evergreen Spawn Host + +1. Spawn and/or start an `ubuntu2004-medium` host in Evergreen and select an SSH key to use + for the connection. Make sure you have a local copy of the private and public key selected. +2. Create a `baas_host_vars.sh` file with the following contents: + +```bash +export AWS_ACCESS_KEY_ID='' +export AWS_SECRET_ACCESS_KEY='' +export BAAS_HOST_NAME="" +export REALM_CORE_REVISION="" +export GITHUB_KNOWN_HOSTS="github.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphnt+VTTvDP6mHBL9j1aNUkY4Ue1gvwnGLVlOhGeYrnZaMgRK6+PKCUXaDbC7qtbW8gIkhL7aGCsOr/C56SJMy/BCZfxd1nWzAOxSDPgVsmerOBYfNqltV9/hWCqBywINIR+5dIg6JTJ72pcEpEjcYgXkE2YEFXV1JHnsKgbLWNlhScqb2UmyRkQyytRLtL+38TGxkxCflmO+5Z8CSSNY7GidjMIZ7Q4zMjA2n1nGrlTDkzwDCsw+wqFPGQA179cnfGWOWRVruj16z6XyvxvjJwbz0wQZ75XK5tKSb7FNyeIEs4TT4jk+S4dhPeAUC5y+bDYirYgM4GC7uEnztnZyaVWQ7B381AK4Qdrwt51ZqExKbQpTUNn+EjqoTwvqNj4kqx5QUCI0ThS/YkOxJCXmPUWZbhjpCg56i+2aB6CmK2JGhn57K5mj0MNdBXA4/WnwH6XoPWJzK5Nyu2zB3nAZp+S5hpQs+p1vN1/wsjk=" +``` + +**NOTE**: The `install_baas.sh` and `setup_baas_host.sh` files from the +local _evergreen/_ directory will be transferred to the remote host. The `REALM_CORE_REVISION` +specifies which Realm Core branch/commit to use for other auxillary files used during baas_server +and baas_proxy setup. + +3. CD into the _realm-core/_ directory. +4. Run the _evergreen/setup_baas_host_local.sh_ script with the following arguments: + +```bash +$ evergreen/setup_baas_host_local.sh -t +. . . +Running setup script (with forward tunnel on :9090 to 127.0.0.1:9092) +- Baas proxy enabled - local HTTP API config port on :8474 +- Baas direct connection on port :9098 +. . . +Starting baas app server +Adding roles to admin user +Starting baas proxy: 127.0.0.1:9092 => 127.0.0.1:9090 +--------------------------------------------- +Baas proxy ready +--------------------------------------------- +--------------------------------------------- +Baas server ready +--------------------------------------------- + +# To enable verbose logging, add the -v argument before the baas_host_vars.sh file argurment +# Use the '-b ' to specify a specific version of the baas server to download/use +# Use the '-d ' to change the local port number for the baas server direct connection +# Use the '-c ' to change the local port number for the baas proxy configuration connection +# Use the '-l ' to change the port number for the baas proxy server listen port for new +# connections if there is a conflict with the default port (9092) on the remote host. The local +# baas server port 9090 forwards traffic to this port. +``` + +**NOTES:** + +* You must be connected to the MongoDB network either directly or via VPN in order to communicate +with the spawn host. If you get this error, check your network connection. It could also be due to +an incorrect host name for the `BAAS_HOST_NAME` setting in `baas_host_vars.sh`. + +```bash +SSH connection attempt 1/25 failed. Retrying... +ssh: connect to host port 22: Operation timed out +``` + +* If any of the local ports are in use, an error message will be displayed when the script is + run. Close any programs that are using these ports. + +```bash +Error: Local baas server port (9090) is already in use +baas_serv 66287 ... 12u IPv6 0x20837f52a108aa91 0t0 TCP *:9090 (LISTEN) +``` + +5. The required script files will be uploaded to the spawn host and the baas server will be + downloaded and started. The following local tunnels will be created over the SSH + connection to forward traffic to the remote host: + * **localhost:9090 -> baas proxy** - any traffic intended for the baas server will first go + through the baas proxy so network "faults" can be applied to the connection or packet. + * **localhost:9098 -> baas server** - any baas Admin API configuration or test setup should + be sent directly to the baas server via this port, since this traffic is not part of + the test. The local port value can be changed using the `-d ` command line option. + * **localhost:8474 -> baas proxy configuration** - the Toxiproxy server providing the baas + proxy operation can be configured through this port. The `baas_proxy` proxy for routing + traffic to the baas server is automatically configured when the baas proxy is started. The + local port value can be changed using the `-c ` command line option. +6. Use CTRL-C to cancel the baas remote host script and stop the baas server running on the + spawn host. + +## Running network fault tests + +### Building Realm Core for testing + +The Realm Core object store test executable needs to be built with the following options +provided to `cmake` when configuring the build: + +* REALM_ENABLE_SYNC: `On` +* REALM_ENABLE_AUTH_TESTS: `On` +* REALM_MONGODB_ENDPOINT: `"https://localhost1:9090"` +* REALM_ADMIN_ENDPOINT: `"https://localhost:9098"` + +When the object store tests executable it compiled, the baas Admin API commands will be +sent directly to the baas server via local port 9098 and all other baas server network +traffic will be sent to the baas server via the baas proxy using local port 9090. + +### Starting the baas proxy and server + +Refer to the +**[Running remote baas and proxy on an Evergreen Spawn Host](#running-remote-baas-and-proxy-on-an-evergreen-spawn-host)** +section for instructions on starting the baas proxy and server on the remote host. + +### Configuring network "faults" in baas proxy + +The complete list of network faults/conditions suppported by Toxiproxy can be found in the +_README.md_ file in the [Shopify/toxiproxy](https://github.com/Shopify/toxiproxy) github repo. +Any fault or condition added to a proxy is called a "toxic" and multiple toxics can be applied +to a proxy with a toxicity value that specifies the probability of applying that toxic to the +connection when it is opened. + +#### View current toxics applied to the proxy + +Query the `baas_proxy` proxy on the /proxies endpoint to view the current list of toxics +configured for the baas proxy. + +```bash +$ curl localhost:8474/proxies/baas_proxy/toxics +[]% + +$ curl localhost:8474/proxies/baas_proxy/toxics +[{"attributes":{"rate":20},"name":"bandwidth_limit","type":"bandwidth","stream":"downstream","toxicity":1}]% +``` + +#### Add a new toxic parameter to a proxy + +To create a new toxic send a message via the POST HTTP method with a JSON payload containing +details about the toxic and the attributes for the toxic type. A toxicity value is supported +to specify the probability that the toxic will be applied to a connection when it is opened. + +**NOTE:** A name is recommended when adding a toxic to make referencing it easier. Otherwise, +the name defaults to `_` (e.g. `bandwidth_downstream`). Using a unique name for +each toxic entry allows multiple toxics of the same type and stream to be configured for the +proxy. + +The following parameters can be provided or are required when adding a toxic: + +* `name`: toxic name (string, defaults to `_`) +* `type`: toxic type (string). See **[Available Toxics](#available-toxics)**. +* `stream`: link direction to affect (defaults to `downstream`) +* `toxicity`: probability of the toxic being applied to a link (defaults to 1.0, 100%) +* `attributes`: a map of toxic-specific attributes + +```bash +curl --data "{\"name\":\"bandwidth_limit\", \"type\":\"bandwidth\", \"stream\": \"downstream\", \"toxicity\": 1.0, \"attributes\": {\"rate\": 20}}" localhost:8474/proxies/baas_proxy/toxics +{"attributes":{"rate":20},"name":"bandwidth_limit","type":"bandwidth","stream":"downstream","toxicity":1}% + +$ curl localhost:8474/proxies/baas_proxy/toxics +[{"attributes":{"rate":20},"name":"bandwidth_limit","type":"bandwidth","stream":"downstream","toxicity":1}]% +``` + +#### Available toxics + +The following list of toxics can be configured for the proxy: + +* `bandwidth` - Limit a connection to a maximum number of kilobytes per second. + * `rate` - rate in KB/s +* `down` - The proxy can be taken down, which will close all existing connections and not + allow new connections, by setting the `enabled` field for the proxy to `false`. +* `latency` - Add a delay to all data going through proxy. The delay is equal to latency + +/- jitter. + * `latency` - time in milliseconds + * `jitter` - time in milliseconds +* `limit_data` - Close the connection after a certain number of bytes has been transmited. + * `bytes` - number of bytes to be transmitted before the connection is closed +* `reset_peer` - Simulate a TCP RESET (connection closed by peer) on the connections + immediately or after a timeout. + * `timeout` - time in milliseconds +* `slicer` - Slice (split) data up into smaller bits, optionally adding a delay between each + slice packet. + * `average_size` - size in bytes of an average packet + * `size_variation` - variation of bytes of an average packet (should be smaller than `average_size`) + * `delay` - time in microseconds to delay each packet +* `slow_close` - Delay the TCP socket from closing until delay has elapsed. + * `delay` - time in milliseconds +* `timeout` - Stops all data from getting through and closes the connection after a timeout. If + timeout is 0, the connection won't close, but the data will be delayed until the toxic is removed. + * `timeout` - time in milliseconds + +#### Delete a current toxic from the proxy + +Use the DELETE HTTP method with the toxic name to delete an existing toxic applied to the proxy. + +```bash +$ curl localhost:8474/proxies/baas_proxy/toxics +[{"attributes":{"rate":20},"name":"bandwidth_limit","type":"bandwidth","stream":"downstream","toxicity":1}]% + +$ curl -X DELETE localhost:8474/proxies/baas_proxy/toxics/bandwidth_limit + +$ curl localhost:8474/proxies/baas_proxy/toxics +[]% +``` diff --git a/evergreen/setup_baas_host.sh b/evergreen/setup_baas_host.sh index 62c67d52af3..9f0d2418cf5 100755 --- a/evergreen/setup_baas_host.sh +++ b/evergreen/setup_baas_host.sh @@ -266,7 +266,7 @@ fi # Set up the cleanup function that runs at exit and stops baas server and proxy (if run) trap 'on_exit' EXIT -BAAS_OPTIONS= +BAAS_OPTIONS=() if [[ -n "${BAAS_BRANCH}" ]]; then BAAS_OPTIONS=("-b" "${BAAS_BRANCH}") fi diff --git a/evergreen/setup_baas_host_local.sh b/evergreen/setup_baas_host_local.sh index 388137fe6cc..cc8d2db999f 100755 --- a/evergreen/setup_baas_host_local.sh +++ b/evergreen/setup_baas_host_local.sh @@ -19,6 +19,7 @@ BAAS_PROXY= DIRECT_PORT=9098 LISTEN_PORT=9092 CONFIG_PORT=8474 +BAAS_PORT=9090 function usage() { @@ -109,7 +110,7 @@ function check_port_in_use() } # Check the local baas port availability -check_port_in_use "${CONFIG_PORT}" "Baas proxy config" +check_port_in_use "${BAAS_PORT}" "Local baas server" # Check the port values and local ports in use for baas proxy if [[ -n "${BAAS_PROXY}" ]]; then @@ -120,14 +121,14 @@ if [[ -n "${BAAS_PROXY}" ]]; then echo "Error: Baas proxy listen port was invalid: '${LISTEN_PORT}'" usage 1 fi - check_port_in_use "${CONFIG_PORT}" "Baas proxy config" + check_port_in_use "${CONFIG_PORT}" "Local baas proxy config" if [[ -n "${DIRECT_PORT}" ]]; then if ! check_port "${DIRECT_PORT}"; then echo "Error: Baas direct connect port was invalid: '${DIRECT_PORT}'" usage 1 fi - check_port_in_use "${DIRECT_PORT}" "Baas direct connect" + check_port_in_use "${DIRECT_PORT}" "Local baas server direct connect" fi fi From 1dba0c173b0d1c77a16fc8bc647ca7b6bb6b8431 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Tue, 22 Aug 2023 10:13:05 -0400 Subject: [PATCH 21/22] Minor updates to the instructions --- doc/development/how-to-use-baas-proxy.md | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/doc/development/how-to-use-baas-proxy.md b/doc/development/how-to-use-baas-proxy.md index d6a326bc4b8..accc8b313f8 100644 --- a/doc/development/how-to-use-baas-proxy.md +++ b/doc/development/how-to-use-baas-proxy.md @@ -205,10 +205,10 @@ proxy. The following parameters can be provided or are required when adding a toxic: * `name`: toxic name (string, defaults to `_`) -* `type`: toxic type (string). See **[Available Toxics](#available-toxics)**. -* `stream`: link direction to affect (defaults to `downstream`) -* `toxicity`: probability of the toxic being applied to a link (defaults to 1.0, 100%) -* `attributes`: a map of toxic-specific attributes +* `type`: toxic type (string). See **[Available Toxics](#available-toxics)** +* `stream`: link direction to affect (string, defaults to `downstream`) +* `toxicity`: probability of the toxic being applied to a link (numeric, defaults to 1.0, 100%) +* `attributes`: a map (JSON object) of toxic-specific attributes ```bash curl --data "{\"name\":\"bandwidth_limit\", \"type\":\"bandwidth\", \"stream\": \"downstream\", \"toxicity\": 1.0, \"attributes\": {\"rate\": 20}}" localhost:8474/proxies/baas_proxy/toxics @@ -259,3 +259,17 @@ $ curl -X DELETE localhost:8474/proxies/baas_proxy/toxics/bandwidth_limit $ curl localhost:8474/proxies/baas_proxy/toxics []% ``` + +### Running the tests + +Only the object store tests that are performed against the baas server are needed to be run. +These can be run by running the following command. Depending on the toxics specified for the +baas proxy, these tests may take a long time. + +```bash +$ cd /test/object-store/realm-object-store-tests.app/Contents/MacOS +$ ./realm-object-store-tests "[baas]" +Filters: [baas] +Randomness seeded to: 1962875058 +. . . +``` From 179f4f0e8d11fa88de503c5d2f400acbf4372a20 Mon Sep 17 00:00:00 2001 From: Michael Wilkerson-Barker Date: Wed, 23 Aug 2023 13:38:11 -0400 Subject: [PATCH 22/22] Minor updates to documentation --- .gitignore | 4 ++ ...roxy.md => how-to-use-remote-baas-host.md} | 38 ++++++++++++++----- 2 files changed, 33 insertions(+), 9 deletions(-) rename doc/development/{how-to-use-baas-proxy.md => how-to-use-remote-baas-host.md} (87%) diff --git a/.gitignore b/.gitignore index 82281a577dd..d12d9ff9ee9 100644 --- a/.gitignore +++ b/.gitignore @@ -97,3 +97,7 @@ compile_commands.json # Swift package manager /.swiftpm /.build + +# Ignore artifacts from setup_baas_host_local.sh +/baas-work-dir +ssh_agent_commands.sh diff --git a/doc/development/how-to-use-baas-proxy.md b/doc/development/how-to-use-remote-baas-host.md similarity index 87% rename from doc/development/how-to-use-baas-proxy.md rename to doc/development/how-to-use-remote-baas-host.md index accc8b313f8..59327b78310 100644 --- a/doc/development/how-to-use-baas-proxy.md +++ b/doc/development/how-to-use-remote-baas-host.md @@ -16,10 +16,20 @@ export REALM_CORE_REVISION="" export GITHUB_KNOWN_HOSTS="github.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphnt+VTTvDP6mHBL9j1aNUkY4Ue1gvwnGLVlOhGeYrnZaMgRK6+PKCUXaDbC7qtbW8gIkhL7aGCsOr/C56SJMy/BCZfxd1nWzAOxSDPgVsmerOBYfNqltV9/hWCqBywINIR+5dIg6JTJ72pcEpEjcYgXkE2YEFXV1JHnsKgbLWNlhScqb2UmyRkQyytRLtL+38TGxkxCflmO+5Z8CSSNY7GidjMIZ7Q4zMjA2n1nGrlTDkzwDCsw+wqFPGQA179cnfGWOWRVruj16z6XyvxvjJwbz0wQZ75XK5tKSb7FNyeIEs4TT4jk+S4dhPeAUC5y+bDYirYgM4GC7uEnztnZyaVWQ7B381AK4Qdrwt51ZqExKbQpTUNn+EjqoTwvqNj4kqx5QUCI0ThS/YkOxJCXmPUWZbhjpCg56i+2aB6CmK2JGhn57K5mj0MNdBXA4/WnwH6XoPWJzK5Nyu2zB3nAZp+S5hpQs+p1vN1/wsjk=" ``` -**NOTE**: The `install_baas.sh` and `setup_baas_host.sh` files from the -local _evergreen/_ directory will be transferred to the remote host. The `REALM_CORE_REVISION` -specifies which Realm Core branch/commit to use for other auxillary files used during baas_server -and baas_proxy setup. +Here are descriptions of the different parameters in the `baas_host_vars.sh` file: + +* `AWS_ACCESS_KEY_ID` - The AWS Access Key ID used to run the baas server. +* `AWS_SECRET_ACCESS_KEY` - The AWS Secret Key used to run the baas server. +* `BAAS_HOST_NAME` - The hostname of the Linux host to download and run the baas server. +* `REALM_CORE_REVISION` - The commit/branch of Realm Core to use for other files from the + _evergreen/_ directory when running the baas server. +* `GITHUB_KNOWN_HOSTS` - The public server key to authenticate ssh with Github for downloading + files from Github. This is a fixed value that is provided by Github. + +**NOTE**: The `baas_host_vars.sh` and the `install_baas.sh` and `setup_baas_host.sh` files from the +local _evergreen/_ directory will be transferred to the remote host. The `setup_baas_host.sh` script +will check out Realm Core using the branch/commit provided to use for other auxillary files needed +when starting the baas_server. 3. CD into the _realm-core/_ directory. 4. Run the _evergreen/setup_baas_host_local.sh_ script with the following arguments: @@ -80,10 +90,20 @@ export REALM_CORE_REVISION="" export GITHUB_KNOWN_HOSTS="github.com ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQCj7ndNxQowgcQnjshcLrqPEiiphnt+VTTvDP6mHBL9j1aNUkY4Ue1gvwnGLVlOhGeYrnZaMgRK6+PKCUXaDbC7qtbW8gIkhL7aGCsOr/C56SJMy/BCZfxd1nWzAOxSDPgVsmerOBYfNqltV9/hWCqBywINIR+5dIg6JTJ72pcEpEjcYgXkE2YEFXV1JHnsKgbLWNlhScqb2UmyRkQyytRLtL+38TGxkxCflmO+5Z8CSSNY7GidjMIZ7Q4zMjA2n1nGrlTDkzwDCsw+wqFPGQA179cnfGWOWRVruj16z6XyvxvjJwbz0wQZ75XK5tKSb7FNyeIEs4TT4jk+S4dhPeAUC5y+bDYirYgM4GC7uEnztnZyaVWQ7B381AK4Qdrwt51ZqExKbQpTUNn+EjqoTwvqNj4kqx5QUCI0ThS/YkOxJCXmPUWZbhjpCg56i+2aB6CmK2JGhn57K5mj0MNdBXA4/WnwH6XoPWJzK5Nyu2zB3nAZp+S5hpQs+p1vN1/wsjk=" ``` -**NOTE**: The `install_baas.sh` and `setup_baas_host.sh` files from the -local _evergreen/_ directory will be transferred to the remote host. The `REALM_CORE_REVISION` -specifies which Realm Core branch/commit to use for other auxillary files used during baas_server -and baas_proxy setup. +Here are descriptions of the different parameters in the `baas_host_vars.sh` file: + +* `AWS_ACCESS_KEY_ID` - The AWS Access Key ID used to run the baas server. +* `AWS_SECRET_ACCESS_KEY` - The AWS Secret Key used to run the baas server. +* `BAAS_HOST_NAME` - The hostname of the Linux host to download and run the baas server and proxy. +* `REALM_CORE_REVISION` - The commit/branch of Realm Core to use for other files from the + _evergreen/_ directory when running the baas server. +* `GITHUB_KNOWN_HOSTS` - The public server key to authenticate ssh with Github for downloading + files from Github. This is a fixed value that is provided by Github. + +**NOTE**: The `baas_host_vars.sh` and the `install_baas.sh`, `setup_baas_host.sh` and +`setup_baas_proxy.sh` files from the local _evergreen/_ directory will be transferred to the +remote host. The `setup_baas_host.sh` script will check out Realm Core using the branch/commit +provided to use for other auxillary files needed when starting the baas_server. 3. CD into the _realm-core/_ directory. 4. Run the _evergreen/setup_baas_host_local.sh_ script with the following arguments: @@ -96,11 +116,11 @@ Running setup script (with forward tunnel on :9090 to 127.0.0.1:9092) - Baas direct connection on port :9098 . . . Starting baas app server -Adding roles to admin user Starting baas proxy: 127.0.0.1:9092 => 127.0.0.1:9090 --------------------------------------------- Baas proxy ready --------------------------------------------- +Adding roles to admin user --------------------------------------------- Baas server ready ---------------------------------------------