Skip to content

Commit a0a18c6

Browse files
author
Kasturi Narra
committed
Update scenario.sh script to run gingko tests
1 parent a0f8386 commit a0a18c6

File tree

6 files changed

+177
-12
lines changed

6 files changed

+177
-12
lines changed

scripts/fetch_tools.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ IFS=$'\n\t'
55

66
ARCH="$(uname -m)"
77

8+
# Set GitHub token for private repository access
9+
GITHUB_TOKEN="$(cat /tmp/token-git 2>/dev/null || echo '')"
10+
export GITHUB_TOKEN
11+
812
SCRIPT_DIR="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")"
913
ROOT_DIR=$(realpath "${SCRIPT_DIR}/..")
1014
DEFAULT_DEST_DIR="${ROOT_DIR}/_output/bin"
@@ -233,6 +237,59 @@ gettool_tar-diff() {
233237
done
234238
}
235239

240+
gettool_ginkgo() {
241+
# shellcheck source=test/bin/common.sh
242+
source "${SCRIPT_DIR}/../test/bin/common.sh"
243+
# shellcheck source=test/bin/common_versions.sh
244+
source "${SCRIPT_DIR}/../test/bin/common_versions.sh"
245+
246+
local -r repo_url="https://${GITHUB_TOKEN}@github.com/openshift/openshift-tests-private.git"
247+
local -r binary_path="${GINKGO_TEST_BINARY}"
248+
local -r release_branch="release-4.${MINOR_VERSION}"
249+
250+
# Skip if binary already exists
251+
[[ -f "${binary_path}" ]] && return 0
252+
253+
# Check if Go is available
254+
if ! command -v go &> /dev/null; then
255+
echo "Error: Go is required to build openshift-tests-private binary"
256+
return 1
257+
fi
258+
259+
# Ensure binary directory exists
260+
mkdir -p "$(dirname "${binary_path}")"
261+
262+
# Use global WORK_DIR for cloning
263+
local clone_dir="${WORK_DIR}/openshift-tests-private"
264+
265+
# Clone repository with release branch preference
266+
if ! git clone --depth 1 --branch "${release_branch}" "${repo_url}" "${clone_dir}" 2>/dev/null; then
267+
echo "Branch ${release_branch} not found, cloning default branch..."
268+
if ! git clone --depth 1 "${repo_url}" "${clone_dir}"; then
269+
echo "Error: Failed to clone repository"
270+
return 1
271+
fi
272+
fi
273+
274+
# Build the binary
275+
pushd "${clone_dir}" &>/dev/null
276+
277+
local test_binary="./bin/extended-platform-tests"
278+
go build -o "${test_binary}" ./cmd/extended-platform-tests
279+
280+
# Copy binary to centralized location
281+
if [[ -f "${test_binary}" ]]; then
282+
cp "${test_binary}" "${binary_path}"
283+
chmod +x "${binary_path}"
284+
echo "Binary installed to ${binary_path}"
285+
popd &>/dev/null
286+
else
287+
echo "Error: Test binary not found after build"
288+
popd &>/dev/null
289+
return 1
290+
fi
291+
}
292+
236293
tool_getters=$(declare -F | awk '$3 ~ /^gettool_/ {print $3}' | sed 's/^gettool_//g')
237294

238295
usage() {

test/bin/ci_phase_boot_and_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ BOOT_TEST_JOB_LOG="${IMAGEDIR}/boot_test_jobs.txt"
6363
cd "${TESTDIR}"
6464

6565
if [ ! -d "${RF_VENV}" ]; then
66-
"${ROOTDIR}/scripts/fetch_tools.sh" robotframework
66+
"${ROOTDIR}/scripts/fetch_tools.sh" robotframework ginkgo
6767
fi
6868

6969
# Tell scenario.sh to merge stderr into stdout

test/bin/common.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ KICKSTART_TEMPLATE_DIR="${TESTDIR}/kickstart-templates"
2525
# The location the web server should serve.
2626
export IMAGEDIR="${OUTPUTDIR}/test-images"
2727

28+
# Ginkgo test binary path
29+
export GINKGO_TEST_BINARY="${OUTPUTDIR}/bin/extended-platform-tests"
30+
2831
# The storage pool base name for VMs.
2932
# The actual pool names will be '${VM_POOL_BASENAME}-${SCENARIO}'.
3033
VM_POOL_BASENAME="vm-storage"

test/bin/scenario.sh

Lines changed: 84 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -939,23 +939,33 @@ stress_testing() {
939939
fi
940940
}
941941

942-
# Run the tests for the current scenario
943-
run_tests() {
944-
local vmname="${1}"
945-
local full_vmname
946-
full_vmname="$(full_vm_name "${vmname}")"
942+
# Apply RUN_HOST_OVERRIDE logic if needed
943+
apply_host_override() {
944+
local -r original_vmname="$1"
945+
local vmname="${original_vmname}"
946+
947947
if [[ -n "${RUN_HOST_OVERRIDE}" ]]; then
948-
vmname="${RUN_HOST_OVERRIDE}"
949-
full_vmname="$(full_vm_name "${vmname}")"
948+
vmname="${RUN_HOST_OVERRIDE}"
949+
local full_vmname
950+
local ip
951+
full_vmname="$(full_vm_name "${vmname}")"
950952
ip=$(get_vm_ip "${full_vmname}")
951-
set_vm_property "${vmname}" "ip" "${ip}"
953+
set_vm_property "${vmname}" "ip" "${ip}"
952954
set_vm_property "${vmname}" "ssh_port" "22"
953955
set_vm_property "${vmname}" "api_port" "6443"
954956
set_vm_property "${vmname}" "lb_port" "5678"
955957
fi
956958

957-
shift
959+
echo "${vmname}"
960+
}
961+
962+
# Run the tests for the current scenario
963+
run_tests() {
964+
local vmname="${1}"
965+
# Handle RUN_HOST_OVERRIDE
966+
vmname=$(apply_host_override "${vmname}")
958967

968+
shift
959969
echo "Running tests with $# args" "$@"
960970

961971
if [ ! -d "${RF_VENV}" ]; then
@@ -1016,6 +1026,7 @@ run_tests() {
10161026
local -r api_port=$(get_vm_property "${vmname}" "api_port")
10171027
local -r lb_port=$(get_vm_property "${vmname}" "lb_port")
10181028
local -r vm_ip=$(get_vm_property "${vmname}" "ip")
1029+
local -r full_vmname="$(full_vm_name "${vmname}")"
10191030

10201031
local variable_file="${SCENARIO_INFO_DIR}/${SCENARIO}/variables.yaml"
10211032
echo "Writing variables to ${variable_file}"
@@ -1069,6 +1080,69 @@ EOF
10691080
fi
10701081
}
10711082

1083+
# Implementation of Gingko tests
1084+
run_gingko_tests() {
1085+
local vmname="${1}"
1086+
shift
1087+
1088+
# Handle RUN_HOST_OVERRIDE
1089+
vmname=$(apply_host_override "${vmname}")
1090+
1091+
# Save current directory
1092+
pushd . &>/dev/null
1093+
1094+
# Check/install oc
1095+
"${ROOTDIR}/scripts/fetch_tools.sh" "oc" || {
1096+
record_junit "${vmname}" "oc_installed" "FAILED"
1097+
exit 1
1098+
}
1099+
1100+
# Check/get openshift-tests-binary
1101+
if ! "${ROOTDIR}/scripts/fetch_tools.sh" "ginkgo"; then
1102+
record_junit "${vmname}" "build_test_binary" "FAILED"
1103+
exit 1
1104+
fi
1105+
record_junit "${vmname}" "build_test_binary" "OK"
1106+
1107+
# Set up test environment variables
1108+
local kubeconfig="${SCENARIO_INFO_DIR}/${SCENARIO}/kubeconfig"
1109+
local -r test_results_dir="${SCENARIO_INFO_DIR}/${SCENARIO}/gingko-results"
1110+
mkdir -p "${test_results_dir}"
1111+
1112+
# Set up kubeconfig for tests
1113+
local -r vm_ip=$(get_vm_property "${vmname}" "ip")
1114+
local -r full_vmname="$(full_vm_name "${vmname}")"
1115+
1116+
# Wait for MicroShift to be ready
1117+
if ! wait_for_greenboot "${full_vmname}" "${vm_ip}"; then
1118+
record_junit "${vmname}" "pre_test_greenboot_check" "FAILED"
1119+
popd &>/dev/null
1120+
exit 1
1121+
fi
1122+
record_junit "${vmname}" "pre_test_greenboot_check" "OK"
1123+
1124+
# Get kubeconfig from VM
1125+
run_command_on_vm "${vmname}" "sudo cat /var/lib/microshift/resources/kubeadmin/${vm_ip}/kubeconfig" > "${kubeconfig}"
1126+
export KUBECONFIG="${kubeconfig}"
1127+
record_junit "${vmname}" "setup_kubeconfig" "OK"
1128+
1129+
# Run the tests and capture output
1130+
if ! "${GINKGO_TEST_BINARY}" run all --dry-run | grep "MicroShift" | "${GINKGO_TEST_BINARY}" run -f - --timeout 60m 2>&1 | tee "${test_results_dir}/test-output.log"; then
1131+
record_junit "${vmname}" "run_gingko_tests" "FAILED"
1132+
return 1
1133+
fi
1134+
1135+
record_junit "${vmname}" "run_gingko_tests" "OK"
1136+
popd &>/dev/null
1137+
1138+
# Display results summary
1139+
echo "Gingko test execution completed"
1140+
echo "Results are available in: ${test_results_dir}"
1141+
if [[ -f "${test_results_dir}/test-output.log" ]]; then
1142+
echo "Test output log: ${test_results_dir}/test-output.log"
1143+
fi
1144+
}
1145+
10721146
load_global_settings() {
10731147
local filename="${TESTDIR}/scenario_settings.sh"
10741148
if [ ! -f "${filename}" ]; then
@@ -1224,11 +1298,10 @@ action_run() {
12241298

12251299
if [ $# -eq 0 ]; then
12261300
RUN_HOST_OVERRIDE=""
1227-
check_dependencies
1301+
check_dependencies
12281302
else
12291303
RUN_HOST_OVERRIDE="$1"
12301304
fi
1231-
12321305
scenario_run_tests
12331306
record_junit "run" "scenario_run_tests" "OK"
12341307
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
# Sourced from scenario.sh and uses functions defined there.
4+
5+
scenario_create_vms() {
6+
prepare_kickstart host1 kickstart-bootc.ks.template "rhel96-bootc-brew-${LATEST_RELEASE_TYPE}-with-optional"
7+
launch_vm --boot_blueprint rhel96-bootc
8+
}
9+
10+
scenario_remove_vms() {
11+
remove_vm host1
12+
}
13+
14+
scenario_run_tests() {
15+
run_gingko_tests host1
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
# Sourced from scenario.sh and uses functions defined there.
4+
5+
scenario_create_vms() {
6+
prepare_kickstart host1 kickstart.ks.template "rhel-9.6-microshift-brew-optionals-4.${MINOR_VERSION}-${LATEST_RELEASE_TYPE}"
7+
launch_vm
8+
}
9+
10+
scenario_remove_vms() {
11+
remove_vm host1
12+
}
13+
14+
scenario_run_tests() {
15+
run_gingko_tests host1
16+
}

0 commit comments

Comments
 (0)