Skip to content

Fix USHIFT-5528 #4813

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 92 additions & 1 deletion test/bin/scenario.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1192,9 +1192,88 @@ action_run() {
record_junit "run" "scenario_run_tests" "OK"
}

action_run_on_vm() {
if [ $# -lt 2 ]; then
echo "Usage: run_scenario_on_vm <vm_ip> <scenario_script> [args...]"
record_junit "scenario-on-vm" "fail" "Missing VM IP or scenario script"
return 1
fi

local vm_ip="$1"
SCENARIO_SCRIPT="$(realpath "${PWD}/../$2")"
shift 2
SCENARIO=$(basename "${SCENARIO_SCRIPT}" .sh)

# Source the scenario script to extract test suite
if [ ! -f "${SCENARIO_SCRIPT}" ]; then
echo "[ERROR] Scenario script '${SCENARIO_SCRIPT}' not found"
return 1
fi

# shellcheck source=/dev/null
SUITE=$(grep -oE 'suites/[^ ]+(\.robot)?' "${SCENARIO_SCRIPT}" | while read -r line; do
realpath "${SCRIPTDIR}/../${line}"
done | xargs)
echo "SUITE name is: ${SUITE}"

if [ -z "${SUITE}" ]; then
echo "[ERROR] SUITE variable not defined in ${SCENARIO_SCRIPT}"
return 1
fi


echo "Running scenario ${SCENARIO_SCRIPT} on VM IP: ${vm_ip}"

if [ -z "${RF_VENV:-}" ]; then
echo "ERROR: RF_VENV is not set"
exit 1
fi

local rf_binary="${RF_VENV}/bin/robot"
# Set variable file path
local variable_file="${SCENARIO_INFO_DIR}/${SCENARIO}/variables.yaml"
echo "Writing variables to ${variable_file}"
mkdir -p "$(dirname "${variable_file}")"
cat - <<EOF | tee "${variable_file}"
VM_IP: ${vm_ip}
API_PORT: "6443"
LB_PORT: "5678"
USHIFT_HOST: ${vm_ip}
USHIFT_USER: redhat
SSH_PRIV_KEY: "${SSH_PRIVATE_KEY:-<ssh_key_path>}"
SSH_PORT: "22"
EOF

local var_arg=${variable_file:+-V "${variable_file}"}
local timeout_robot="timeout -v --kill-after=5m ${TEST_EXECUTION_TIMEOUT} ${rf_binary}"
if [ -t 0 ]; then
# Disable timeout for interactive mode when stdin is a terminal.# This is necessary for proper handling of test interruption by user.
timeout_robot="${rf_binary}"
fi

# Run tests directly
read -r -a suite_paths <<< "${SUITE}"
echo "[INFO] Running Robot Framework test suite: ${SUITE}"
echo "[DEBUG] rf_binary: ${rf_binary}"
echo "[DEBUG] Extra args: $@"
if ! ${timeout_robot} \
--name "${SCENARIO}" \
--randomize "${TEST_RANDOMIZATION}" \
--loglevel TRACE \
--outputdir "${SCENARIO_INFO_DIR}/${SCENARIO}" \
--debugfile "${SCENARIO_INFO_DIR}/${SCENARIO}/rf-debug.log" \
-x junit.xml \
${var_arg} \
"$@" "${suite_paths[*]}" ; then
echo "Tests failed on VM ${vm_ip}"
return 1
fi
}


usage() {
cat - <<EOF
scenario.sh (create|boot|run|cleanup|rerun|recreate|login) scenario-script [args]
scenario.sh (create|boot|run|cleanup|rerun|recreate|login|run_on_vm) scenario-script [args]

create|boot -- Set up the infrastructure for the test, such as VMs.

Expand All @@ -1208,13 +1287,19 @@ scenario.sh (create|boot|run|cleanup|rerun|recreate|login) scenario-script [args

login -- Login to a host for a scenario.

run_on_vm -- Run on a vm ip that is passed to scenario.sh script

Settings

The script looks for ${TESTDIR}/scenario_settings.sh for some global settings.

Login

scenario.sh login <scenario-script> [<host>]

Run_on_vm

scenario.sh run_on_vm [<host>] <scenario-script>
EOF
}

Expand All @@ -1223,6 +1308,8 @@ if [ $# -lt 2 ]; then
exit 1
fi

ALL_ARGS=("$@")

action="$1"
shift
SCENARIO_SCRIPT="$(realpath "$1")"
Expand Down Expand Up @@ -1253,6 +1340,10 @@ case "${action}" in
action_create "$@"
action_run "$@"
;;
run-on-vm)
action_run_on_vm "${ALL_ARGS[@]:1}"
;;

*)
error "Unknown instruction ${action}"
usage
Expand Down