<commit_before>#!/bin/bash
#
# This abstracts starting up an extended server.

# If invoked with arguments, executes the test directly.
function os::test::extended::focus () {
	if [[ $# -ne 0 ]]; then
		os::log::info "Running custom: $*"
		os::test::extended::test_list "$@"
		if [[ "${TEST_COUNT}" -eq 0 ]]; then
			os::log::error "No tests would be run"
			exit 1
		fi
		extended.test "$@"
		exit $?
	fi
}

# Launches an extended server for OpenShift
# TODO: this should be doing less, because clusters should be stood up outside
#		and then tests are executed.	Tests that depend on fine grained setup should
#		be done in other contexts.
function os::test::extended::setup () {
	# build binaries
	os::util::ensure::built_binary_exists 'ginkgo' 'vendor/github.com/onsi/ginkgo/ginkgo'
	os::util::ensure::built_binary_exists 'extended.test' 'test/extended/extended.test'
	os::util::ensure::built_binary_exists 'openshift'
	os::util::ensure::built_binary_exists 'oadm'
	os::util::ensure::built_binary_exists 'oc'
	os::util::ensure::built_binary_exists 'junitmerge'

	# ensure proper relative directories are set
	export EXTENDED_TEST_PATH="${OS_ROOT}/test/extended"
	export KUBE_REPO_ROOT="${OS_ROOT}/vendor/k8s.io/kubernetes"

	# allow setup to be skipped
	if [[ -n "${TEST_ONLY+x}" ]]; then
		# be sure to set VOLUME_DIR if you are running with TEST_ONLY
		os::log::info "Not starting server, VOLUME_DIR=${VOLUME_DIR:-}"
		return 0
	fi

	os::util::environment::setup_time_vars
	os::util::environment::use_sudo
	os::util::environment::setup_all_server_vars "test-extended/core"

	os::util::ensure::iptables_privileges_exist

	function cleanup() {
		out=$?
		cleanup_openshift

		# TODO(skuznets): un-hack this nonsense once traps are in a better
		# state
		if [[ -n "${JUNIT_REPORT_OUTPUT:-}" ]]; then
			# get the jUnit output file into a workable state in case we
			# crashed in the middle of testing something
			os::test::junit::reconcile_output

			# check that we didn't mangle jUnit output
			os::test::junit::check_test_counters

			# use the junitreport tool to generate us a report
			os::util::ensure::built_binary_exists 'junitreport'

			cat "${JUNIT_REPORT_OUTPUT}" \
				| junitreport --type oscmd \
				--suites nested \
				--roots github.com/openshift/origin \
				--output "${ARTIFACT_DIR}/report.xml"
			cat "${ARTIFACT_DIR}/report.xml" | junitreport summarize
		fi

		os::log::info "Exiting"
		return $out
	}

	trap "exit" INT TERM
	trap "cleanup" EXIT
	os::log::info "Starting server"

	os::util::environment::setup_images_vars

	local sudo=${USE_SUDO:+sudo}

	# If the current system has the XFS volume dir mount point we configure
	# in the test images, assume to use it which will allow the local storage
	# quota tests to pass.
	LOCAL_STORAGE_QUOTA=""
	if [[ -d "/mnt/openshift-xfs-vol-dir" ]] && ${sudo} lvs | grep -q "xfs"; then
		LOCAL_STORAGE_QUOTA="1"
		export VOLUME_DIR="/mnt/openshift-xfs-vol-dir"
	else
		os::log::warn "/mnt/openshift-xfs-vol-dir does not exist, local storage quota tests may fail."
	fi

	# Allow setting $JUNIT_REPORT to toggle output behavior
	if [[ -n "${JUNIT_REPORT:-}" ]]; then
		export JUNIT_REPORT_OUTPUT="${LOG_DIR}/raw_test_output.log"
		# the Ginkgo tests also generate jUnit but expect different envars
		export TEST_REPORT_DIR="${ARTIFACT_DIR}"<commit_msg>Reorder extended startup to yield jUnit with TEST_ONLY<commit_after>#!/bin/bash
#
# This abstracts starting up an extended server.

# If invoked with arguments, executes the test directly.
function os::test::extended::focus () {
	if [[ $# -ne 0 ]]; then
		os::log::info "Running custom: $*"
		os::test::extended::test_list "$@"
		if [[ "${TEST_COUNT}" -eq 0 ]]; then
			os::log::error "No tests would be run"
			exit 1
		fi
		extended.test "$@"
		exit $?
	fi
}

# Launches an extended server for OpenShift
# TODO: this should be doing less, because clusters should be stood up outside
#		and then tests are executed.	Tests that depend on fine grained setup should
#		be done in other contexts.
function os::test::extended::setup () {
	# build binaries
	os::util::ensure::built_binary_exists 'ginkgo' 'vendor/github.com/onsi/ginkgo/ginkgo'
	os::util::ensure::built_binary_exists 'extended.test' 'test/extended/extended.test'
	os::util::ensure::built_binary_exists 'openshift'
	os::util::ensure::built_binary_exists 'oadm'
	os::util::ensure::built_binary_exists 'oc'
	os::util::ensure::built_binary_exists 'junitmerge'

	# ensure proper relative directories are set
	export EXTENDED_TEST_PATH="${OS_ROOT}/test/extended"
	export KUBE_REPO_ROOT="${OS_ROOT}/vendor/k8s.io/kubernetes"

	os::util::environment::setup_time_vars
	os::util::environment::use_sudo
	os::util::environment::setup_all_server_vars "test-extended/core"

	os::util::ensure::iptables_privileges_exist

	# Allow setting $JUNIT_REPORT to toggle output behavior
	if [[ -n "${JUNIT_REPORT:-}" ]]; then
		export JUNIT_REPORT_OUTPUT="${LOG_DIR}/raw_test_output.log"
		# the Ginkgo tests also generate jUnit but expect different envars
		export TEST_REPORT_DIR="${ARTIFACT_DIR}"
	fi

	function cleanup() {
		out=$?
		cleanup_openshift

		# TODO(skuznets): un-hack this nonsense once traps are in a better
		# state
		if [[ -n "${JUNIT_REPORT_OUTPUT:-}" ]]; then
			# get the jUnit output file into a workable state in case we
			# crashed in the middle of testing something
			os::test::junit::reconcile_output

			# check that we didn't mangle jUnit output
			os::test::junit::check_test_counters

			# use the junitreport tool to generate us a report
			os::util::ensure::built_binary_exists 'junitreport'

			cat "${JUNIT_REPORT_OUTPUT}" \
				| junitreport --type oscmd \
				--suites nested \
				--roots github.com/openshift/origin \
				--output "${ARTIFACT_DIR}/report.xml"
			cat "${ARTIFACT_DIR}/report.xml" | junitreport summarize
		fi

		os::log::info "Exiting"
		return $out
	}

	trap "exit" INT TERM
	trap "cleanup" EXIT

	# allow setup to be skipped
	if [[ -n "${TEST_ONLY+x}" ]]; then
		export SKIP_TEARDOWN='true'
		# be sure to set VOLUME_DIR if you are running with TEST_ONLY
		os::log::info "Not starting server, VOLUME_DIR=${VOLUME_DIR:-}"
		return 0
	fi

	os::log::info "Starting server"

	os::util::environment::setup_images_vars

	local sudo=${USE_SUDO:+sudo}

	# If the current system has the XFS volume dir mount point we configure
	# in the test images, assume to use it which will allow the local storage
	# quota tests to pass.
	LOCAL_STORAGE_QUOTA=""
	if [[ -d "/mnt/openshift-xfs-vol-dir" ]] && ${sudo} lvs | grep -q "xfs"; then
		LOCAL_STORAGE_QUOTA="1"
		export VOLUME_DIR="/mnt/openshift-xfs-vol-dir"
	else
		os::log::warn "/mnt/openshift-xfs-vol-dir does not exist, local storage quota tests may fail."
{'fraction_non_alphanumeric': 0.1275677284906222, 'fraction_numerical': 0.0017862459065197975, 'mean_word_length': 4.641477749790092, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7021644', 'n_tokens_mistral': 2482, 'n_tokens_neox': 2241, 'n_words': 636}