Skip to content

Commit dc9f0ff

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

File tree

6 files changed

+193
-12
lines changed

6 files changed

+193
-12
lines changed

scripts/fetch_tools.sh

Lines changed: 61 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,63 @@ 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="${GINKGO_TESTS_REPO_URL}"
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+
echo "Building openshift-tests-private binary"
260+
# Ensure binary directory exists
261+
mkdir -p "$(dirname "${binary_path}")"
262+
263+
# Use global WORK_DIR for cloning
264+
local clone_dir="${WORK_DIR}/openshift-tests-private"
265+
266+
# Clone repository with release branch preference
267+
echo "Cloning openshift-tests-private repository to temporary directory..."
268+
if ! git clone --depth 1 --branch "${release_branch}" "${repo_url}" "${clone_dir}" 2>/dev/null; then
269+
echo "Branch ${release_branch} not found, cloning default branch..."
270+
if ! git clone --depth 1 "${repo_url}" "${clone_dir}"; then
271+
echo "Error: Failed to clone repository"
272+
return 1
273+
fi
274+
else
275+
echo "Successfully cloned ${release_branch} branch"
276+
fi
277+
278+
# Build the binary
279+
pushd "${clone_dir}" &>/dev/null
280+
281+
local test_binary="./bin/extended-platform-tests"
282+
go build -o "${test_binary}" ./cmd/extended-platform-tests
283+
284+
# Copy binary to centralized location
285+
if [[ -f "${test_binary}" ]]; then
286+
cp "${test_binary}" "${binary_path}"
287+
chmod +x "${binary_path}"
288+
echo "Binary installed to ${binary_path}"
289+
popd &>/dev/null
290+
else
291+
echo "Error: Test binary not found after build"
292+
popd &>/dev/null
293+
return 1
294+
fi
295+
}
296+
236297
tool_getters=$(declare -F | awk '$3 ~ /^gettool_/ {print $3}' | sed 's/^gettool_//g')
237298

238299
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ KICKSTART_TEMPLATE_DIR="${TESTDIR}/kickstart-templates"
2525
# The location the web server should serve.
2626
export IMAGEDIR="${OUTPUTDIR}/test-images"
2727

28+
GITHUB_TOKEN="$(cat /tmp/token-git 2>/dev/null || echo '')"
29+
export GITHUB_TOKEN
30+
31+
# Ginkgo test binary and repository paths
32+
export GINKGO_TESTS_REPO_URL="https://${GITHUB_TOKEN}@github.com/openshift/openshift-tests-private.git"
33+
export GINKGO_TESTS_REPO_DIR="${OUTPUTDIR}/tools/openshift-tests-private"
34+
export GINKGO_TEST_BINARY="${OUTPUTDIR}/bin/extended-platform-tests"
35+
2836
# The storage pool base name for VMs.
2937
# The actual pool names will be '${VM_POOL_BASENAME}-${SCENARIO}'.
3038
VM_POOL_BASENAME="vm-storage"

test/bin/scenario.sh

Lines changed: 91 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,76 @@ 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 -r 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 ssh_port=$(get_vm_property "${vmname}" "ssh_port")
1115+
local -r full_vmname="$(full_vm_name "${vmname}")"
1116+
local -r vm_hostname="${full_vmname/./-}"
1117+
1118+
# Debug: Find all kubeconfig files on VM
1119+
echo "Searching for kubeconfig files on VM..."
1120+
run_command_on_vm "${vmname}" "find . -name kubeconfig"
1121+
run_command_on_vm "${vmname}" "sudo find / -name kubeconfig"
1122+
1123+
# Copy kubeconfig to accessible location and then scp it
1124+
echo "Getting kubeconfig from VM..."
1125+
run_command_on_vm "${vmname}" "sudo cp /var/lib/microshift/resources/kubeadmin/${vm_ip}/kubeconfig /tmp/kubeconfig && sudo chown redhat:redhat /tmp/kubeconfig"
1126+
scp -P "${ssh_port}" "redhat@${vm_ip}:/tmp/kubeconfig" "${KUBECONFIG}"
1127+
run_command_on_vm "${vmname}" "rm -f /tmp/kubeconfig" # cleanup
1128+
echo "Successfully got kubeconfig from VM"
1129+
export KUBECONFIG="${KUBECONFIG}"
1130+
record_junit "${vmname}" "setup_kubeconfig" "OK"
1131+
1132+
# Run the Gingko tests with MicroShift filter
1133+
echo "Running Gingko tests with MicroShift filter..."
1134+
1135+
# Run the tests and capture output
1136+
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
1137+
echo "Some Gingko tests may have failed. Check results for details."
1138+
record_junit "${vmname}" "run_gingko_tests" "FAILED"
1139+
return 1
1140+
fi
1141+
1142+
record_junit "${vmname}" "run_gingko_tests" "OK"
1143+
popd &>/dev/null
1144+
1145+
# Display results summary
1146+
echo "Gingko test execution completed"
1147+
echo "Results are available in: ${test_results_dir}"
1148+
if [[ -f "${test_results_dir}/test-output.log" ]]; then
1149+
echo "Test output log: ${test_results_dir}/test-output.log"
1150+
fi
1151+
}
1152+
10721153
load_global_settings() {
10731154
local filename="${TESTDIR}/scenario_settings.sh"
10741155
if [ ! -f "${filename}" ]; then
@@ -1224,11 +1305,10 @@ action_run() {
12241305

12251306
if [ $# -eq 0 ]; then
12261307
RUN_HOST_OVERRIDE=""
1227-
check_dependencies
1308+
check_dependencies
12281309
else
12291310
RUN_HOST_OVERRIDE="$1"
12301311
fi
1231-
12321312
scenario_run_tests
12331313
record_junit "run" "scenario_run_tests" "OK"
12341314
}
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)