Skip to content

Commit e475aaa

Browse files
author
Kasturi Narra
committed
Fix USHIFT-5528
1 parent aab002f commit e475aaa

File tree

1 file changed

+93
-1
lines changed

1 file changed

+93
-1
lines changed

Diff for: test/bin/scenario.sh

+93-1
Original file line numberDiff line numberDiff line change
@@ -1192,9 +1192,89 @@ action_run() {
11921192
record_junit "run" "scenario_run_tests" "OK"
11931193
}
11941194

1195+
action_run_on_vm() {
1196+
if [ $# -lt 2 ]; then
1197+
echo "Usage: run_scenario_on_vm <vm_ip> <scenario_script> [args...]"
1198+
record_junit "scenario-on-vm" "fail" "Missing VM IP or scenario script"
1199+
return 1
1200+
fi
1201+
1202+
local vm_ip="$1"
1203+
SCENARIO_SCRIPT="$(realpath "${PWD}/../$2")"
1204+
shift 2
1205+
SCENARIO=$(basename "${SCENARIO_SCRIPT}" .sh)
1206+
1207+
# Source the scenario script to extract test suite
1208+
if [ ! -f "${SCENARIO_SCRIPT}" ]; then
1209+
echo "[ERROR] Scenario script '${SCENARIO_SCRIPT}' not found"
1210+
return 1
1211+
fi
1212+
1213+
# shellcheck source=/dev/null
1214+
SUITE=$(grep -oE 'suites/[^ ]+(\.robot)?' "${SCENARIO_SCRIPT}" | while read -r line; do
1215+
realpath "${SCRIPTDIR}/../${line}"
1216+
done | xargs)
1217+
echo "SUITE name is: ${SUITE}"
1218+
1219+
if [ -z "$SUITE" ]; then
1220+
echo "[ERROR] SUITE variable not defined in ${SCENARIO_SCRIPT}"
1221+
return 1
1222+
fi
1223+
1224+
1225+
echo "Running scenario ${SCENARIO_SCRIPT} on VM IP: ${vm_ip}"
1226+
1227+
if [ -z "${RF_VENV:-}" ]; then
1228+
echo "ERROR: RF_VENV is not set"
1229+
exit 1
1230+
fi
1231+
1232+
local rf_binary="${RF_VENV}/bin/robot"
1233+
# Set variable file path
1234+
local variable_file="${SCENARIO_INFO_DIR}/${SCENARIO}/variables.yaml"
1235+
echo "Writing variables to ${variable_file}"
1236+
mkdir -p "$(dirname "${variable_file}")"
1237+
cat - <<EOF | tee "${variable_file}"
1238+
VM_IP: ${vm_ip}
1239+
API_PORT: "6443"
1240+
LB_PORT: "5678"
1241+
USHIFT_HOST: ${vm_ip}
1242+
USHIFT_USER: redhat
1243+
SSH_PRIV_KEY: "${SSH_PRIVATE_KEY:-<ssh_key_path>}"
1244+
SSH_PORT: "22"
1245+
EOF
1246+
1247+
local var_arg=${variable_file:+-V "${variable_file}"}
1248+
local timeout_robot="timeout -v --kill-after=5m ${TEST_EXECUTION_TIMEOUT} ${rf_binary}"
1249+
if [ -t 0 ]; then
1250+
# Disable timeout for interactive mode when stdin is a terminal.# This is necessary for proper handling of test interruption by user.
1251+
timeout_robot="${rf_binary}"
1252+
fi
1253+
1254+
# Run tests directly
1255+
read -r -a suite_paths <<< "$SUITE"
1256+
echo "[INFO] Running Robot Framework test suite: ${SUITE}"
1257+
echo "[DEBUG] rf_binary: ${rf_binary}"
1258+
echo "[DEBUG] SUITE: ${SUITE_paths[@]}"
1259+
echo "[DEBUG] Extra args: $@"
1260+
if ! ${timeout_robot} \
1261+
--name "${SCENARIO}" \
1262+
--randomize "${TEST_RANDOMIZATION}" \
1263+
--loglevel TRACE \
1264+
--outputdir "${SCENARIO_INFO_DIR}/${SCENARIO}" \
1265+
--debugfile "${SCENARIO_INFO_DIR}/${SCENARIO}/rf-debug.log" \
1266+
-x junit.xml \
1267+
${var_arg} \
1268+
"$@" "${suite_paths[@]}" ; then
1269+
echo "Tests failed on VM ${vm_ip}"
1270+
return 1
1271+
fi
1272+
}
1273+
1274+
11951275
usage() {
11961276
cat - <<EOF
1197-
scenario.sh (create|boot|run|cleanup|rerun|recreate|login) scenario-script [args]
1277+
scenario.sh (create|boot|run|cleanup|rerun|recreate|login|run_on_vm) scenario-script [args]
11981278
11991279
create|boot -- Set up the infrastructure for the test, such as VMs.
12001280
@@ -1208,13 +1288,19 @@ scenario.sh (create|boot|run|cleanup|rerun|recreate|login) scenario-script [args
12081288
12091289
login -- Login to a host for a scenario.
12101290
1291+
run_on_vm -- Run on a vm ip that is passed to scenario.sh script
1292+
12111293
Settings
12121294
12131295
The script looks for ${TESTDIR}/scenario_settings.sh for some global settings.
12141296
12151297
Login
12161298
12171299
scenario.sh login <scenario-script> [<host>]
1300+
1301+
Run_on_vm
1302+
1303+
scenario.sh run_on_vm [<host>] <scenario-script>
12181304
EOF
12191305
}
12201306

@@ -1223,6 +1309,8 @@ if [ $# -lt 2 ]; then
12231309
exit 1
12241310
fi
12251311

1312+
ALL_ARGS=("$@")
1313+
12261314
action="$1"
12271315
shift
12281316
SCENARIO_SCRIPT="$(realpath "$1")"
@@ -1253,6 +1341,10 @@ case "${action}" in
12531341
action_create "$@"
12541342
action_run "$@"
12551343
;;
1344+
run-on-vm)
1345+
action_run_on_vm "${ALL_ARGS[@]:1}"
1346+
;;
1347+
12561348
*)
12571349
error "Unknown instruction ${action}"
12581350
usage

0 commit comments

Comments
 (0)