Skip to content

Commit da8d6ae

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

File tree

3 files changed

+165
-14
lines changed

3 files changed

+165
-14
lines changed

scripts/fetch_tools.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,71 @@ gettool_tar-diff() {
233233
done
234234
}
235235

236+
gettool_ginkgo() {
237+
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
238+
# shellcheck source=test/bin/common.sh
239+
source "${SCRIPT_DIR}/../test/bin/common.sh"
240+
# shellcheck source=test/bin/common_versions.sh
241+
source "${SCRIPT_DIR}/../test/bin/common_versions.sh"
242+
243+
local repo_url="${GINKGO_TESTS_REPO_URL}"
244+
local binary_path="${GINKGO_TEST_BINARY}"
245+
local release_branch="release-4.${MINOR_VERSION}"
246+
247+
# Skip if binary already exists
248+
[[ -f "${binary_path}" ]] && return 0
249+
250+
echo "Building openshift-tests-private binary"
251+
# Ensure binary directory exists
252+
mkdir -p "$(dirname "${binary_path}")"
253+
254+
# Create temporary directory for cloning
255+
local temp_dir
256+
temp_dir="$(mktemp -d)"
257+
258+
# Clone repository with release branch preference
259+
echo "Cloning openshift-tests-private repository to temporary directory..."
260+
if ! git clone --depth 1 --branch "${release_branch}" "${repo_url}" "${temp_dir}" 2>/dev/null; then
261+
echo "Branch ${release_branch} not found, cloning default branch..."
262+
if ! git clone --depth 1 "${repo_url}" "${temp_dir}"; then
263+
echo "Error: Failed to clone repository"
264+
rm -rf "${temp_dir}"
265+
return 1
266+
fi
267+
else
268+
echo "Successfully cloned ${release_branch} branch"
269+
fi
270+
271+
# Build the binary
272+
pushd "${temp_dir}" &>/dev/null
273+
274+
local test_binary="./bin/extended-platform-tests"
275+
if [[ -f "Makefile" ]]; then
276+
make -j"$(nproc)" build
277+
elif [[ -f "go.mod" ]]; then
278+
go build -o "${test_binary}" ./cmd/extended-platform-tests
279+
else
280+
echo "Error: Unable to determine build method for tests repository"
281+
popd &>/dev/null
282+
rm -rf "${temp_dir}"
283+
return 1
284+
fi
285+
286+
# Copy binary to centralized location
287+
if [[ -f "${test_binary}" ]]; then
288+
cp "${test_binary}" "${binary_path}"
289+
chmod +x "${binary_path}"
290+
echo "Binary installed to ${binary_path}"
291+
popd &>/dev/null
292+
rm -rf "${temp_dir}"
293+
else
294+
echo "Error: Test binary not found after build"
295+
popd &>/dev/null
296+
rm -rf "${temp_dir}"
297+
return 1
298+
fi
299+
}
300+
236301
tool_getters=$(declare -F | awk '$3 ~ /^gettool_/ {print $3}' | sed 's/^gettool_//g')
237302

238303
usage() {

test/bin/common.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ 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 and repository paths
29+
export GINKGO_TESTS_REPO_URL="${OPENSHIFT_TESTS_PRIVATE_REPO:-https://github.com/openshift/openshift-tests-private.git}"
30+
export GINKGO_TESTS_REPO_DIR="${OUTPUTDIR}/tools/openshift-tests-private"
31+
export GINKGO_TEST_BINARY="${OUTPUTDIR}/bin/extended-platform-tests"
32+
2833
# The storage pool base name for VMs.
2934
# The actual pool names will be '${VM_POOL_BASENAME}-${SCENARIO}'.
3035
VM_POOL_BASENAME="vm-storage"

test/bin/scenario.sh

Lines changed: 95 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -939,23 +939,29 @@ 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 -n vmname_ref="$1"
947945
if [[ -n "${RUN_HOST_OVERRIDE}" ]]; then
948-
vmname="${RUN_HOST_OVERRIDE}"
949-
full_vmname="$(full_vm_name "${vmname}")"
946+
vmname_ref="${RUN_HOST_OVERRIDE}"
947+
local full_vmname
948+
local ip
949+
full_vmname="$(full_vm_name "${vmname_ref}")"
950950
ip=$(get_vm_ip "${full_vmname}")
951-
set_vm_property "${vmname}" "ip" "${ip}"
952-
set_vm_property "${vmname}" "ssh_port" "22"
953-
set_vm_property "${vmname}" "api_port" "6443"
954-
set_vm_property "${vmname}" "lb_port" "5678"
951+
set_vm_property "${vmname_ref}" "ip" "${ip}"
952+
set_vm_property "${vmname_ref}" "ssh_port" "22"
953+
set_vm_property "${vmname_ref}" "api_port" "6443"
954+
set_vm_property "${vmname_ref}" "lb_port" "5678"
955955
fi
956+
}
956957

957-
shift
958+
# Run the tests for the current scenario
959+
run_tests() {
960+
local vmname="${1}"
961+
# Handle RUN_HOST_OVERRIDE
962+
apply_host_override vmname
958963

964+
shift
959965
echo "Running tests with $# args" "$@"
960966

961967
if [ ! -d "${RF_VENV}" ]; then
@@ -1016,6 +1022,7 @@ run_tests() {
10161022
local -r api_port=$(get_vm_property "${vmname}" "api_port")
10171023
local -r lb_port=$(get_vm_property "${vmname}" "lb_port")
10181024
local -r vm_ip=$(get_vm_property "${vmname}" "ip")
1025+
local -r full_vmname="$(full_vm_name "${vmname}")"
10191026

10201027
local variable_file="${SCENARIO_INFO_DIR}/${SCENARIO}/variables.yaml"
10211028
echo "Writing variables to ${variable_file}"
@@ -1069,6 +1076,81 @@ EOF
10691076
fi
10701077
}
10711078

1079+
# Implementation of Gingko tests
1080+
run_gingko_tests() {
1081+
local vmname="${1}"
1082+
shift
1083+
1084+
# Handle RUN_HOST_OVERRIDE
1085+
apply_host_override vmname
1086+
1087+
# Save current directory
1088+
pushd . &>/dev/null
1089+
1090+
# Check/install oc
1091+
"${ROOTDIR}/scripts/fetch_tools.sh" "oc" || {
1092+
record_junit "${vmname}" "oc_installed" "FAILED"
1093+
exit 1
1094+
}
1095+
1096+
# Check/get openshift-tests-binary
1097+
if ! "${ROOTDIR}/scripts/fetch_tools.sh" "ginkgo"; then
1098+
record_junit "${vmname}" "build_test_binary" "FAILED"
1099+
exit 1
1100+
fi
1101+
record_junit "${vmname}" "build_test_binary" "OK"
1102+
1103+
# Set up test environment variables
1104+
local -r test_results_dir="${SCENARIO_INFO_DIR}/${SCENARIO}/gingko-results"
1105+
mkdir -p "${test_results_dir}"
1106+
1107+
# Set up kubeconfig for tests
1108+
local -r kubeconfig_file="${test_results_dir}/kubeconfig"
1109+
local -r vm_ip=$(get_vm_property "${vmname}" "ip")
1110+
local -r full_vmname="$(full_vm_name "${vmname}")"
1111+
local -r vm_hostname="${full_vmname/./-}"
1112+
1113+
# Get kubeconfig
1114+
run_command_on_vm "${vmname}" "sudo cp /var/lib/microshift/resources/kubeadmin/${vm_hostname}/kubeconfig /home/redhat/kubeconfig-${vm_hostname}" || {
1115+
error "Failed to copy kubeconfig from /var/lib/microshift/resources/kubeadmin/${vm_hostname}/kubeconfig"
1116+
record_junit "${vmname}" "setup_kubeconfig" "FAILED"
1117+
popd &>/dev/null
1118+
exit 1
1119+
}
1120+
run_command_on_vm "${vmname}" "sudo chown redhat:redhat /home/redhat/kubeconfig-${vm_hostname}"
1121+
1122+
# Download kubeconfig to local file
1123+
copy_file_from_vm "${vmname}" "/home/redhat/kubeconfig-${vm_hostname}" "${kubeconfig_file}" || {
1124+
error "Failed to download kubeconfig from VM"
1125+
record_junit "${vmname}" "setup_kubeconfig" "FAILED"
1126+
popd &>/dev/null
1127+
exit 1
1128+
}
1129+
record_junit "${vmname}" "setup_kubeconfig" "OK"
1130+
1131+
export KUBECONFIG="${kubeconfig_file}"
1132+
1133+
# Run the Gingko tests with MicroShift filter
1134+
echo "Running Gingko tests with MicroShift filter..."
1135+
1136+
# Run the tests and capture output
1137+
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
1138+
echo "Some Gingko tests may have failed. Check results for details."
1139+
record_junit "${vmname}" "run_gingko_tests" "FAILED"
1140+
return 1
1141+
fi
1142+
1143+
record_junit "${vmname}" "run_gingko_tests" "OK"
1144+
popd &>/dev/null
1145+
1146+
# Display results summary
1147+
echo "Gingko test execution completed"
1148+
echo "Results are available in: ${test_results_dir}"
1149+
if [[ -f "${test_results_dir}/test-output.log" ]]; then
1150+
echo "Test output log: ${test_results_dir}/test-output.log"
1151+
fi
1152+
}
1153+
10721154
load_global_settings() {
10731155
local filename="${TESTDIR}/scenario_settings.sh"
10741156
if [ ! -f "${filename}" ]; then
@@ -1224,11 +1306,10 @@ action_run() {
12241306

12251307
if [ $# -eq 0 ]; then
12261308
RUN_HOST_OVERRIDE=""
1227-
check_dependencies
1309+
check_dependencies
12281310
else
12291311
RUN_HOST_OVERRIDE="$1"
12301312
fi
1231-
12321313
scenario_run_tests
12331314
record_junit "run" "scenario_run_tests" "OK"
12341315
}

0 commit comments

Comments
 (0)