Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for // runs of scenarios to molecule #133

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from
12 changes: 8 additions & 4 deletions ansible/janus.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ checkWorkdirExistsAndSetAsDefault

ansible-galaxy collection install community.fqcn_migration

pwd
ls .
if [ "${PLAYBOOK}" == 'playbooks/janus.yml' ]; then
echo "${PLAYS_DIR}/${PLAYBOOK}"
ansible-playbook "${PLAYS_DIR}/${PLAYBOOK}"
else
echo "${PLAYS_DIR}/${PROJECT_NAME}.yml"
ansible-playbook "${PLAYS_DIR}/${PROJECT_NAME}.yml"
if [ -e "${PLAYBOOK}" ]; then
echo "Using provided playbook: ${PLAYBOOK}."
ansible-playbook "${WORKDIR}/${PLAYBOOK}"
else
echo "Provided ${PLAYBOOK} is not a path, computing default playbook name instead"
echo "${PLAYS_DIR}/${PROJECT_NAME}.yml"
ansible-playbook "${PLAYS_DIR}/${PROJECT_NAME}.yml"
fi
fi
74 changes: 69 additions & 5 deletions ansible/molecule/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export ERIS_HOME

MOLECULE_DEBUG=${MOLECULE_DEBUG:-'--no-debug'}
MOLECULE_KEEP_CACHE=${MOLECULE_KEEP_CACHE:-''}
MOLECULE_CONFIG_FILE_HOME=${MOLECULE_CONFIG_FILE_HOME:-'.config/molecule/'}
MOLECULE_CONFIG_FILE=${MOLECULE_CONFIG_FILE:-"${MOLECULE_CONFIG_FILE_HOME}/config.yml"}
MOLECULE_RUN_SCENARIOS_IN_PARRALEL=${MOLECULE_RUN_SCENARIOS_IN_PARRALEL:-''}

determineMoleculeVersion() {
echo "$(molecule --version | head -1 | sed -e 's/using python .*$//' -e 's/^molecule *//' -e 's/ //g' | grep -e '4' | wc -l )"
Expand All @@ -20,7 +23,6 @@ determineMoleculeSlaveImage() {
else
echo "localhost/molecule-slave-9"
fi

}

determineMoleculeDriverName() {
Expand Down Expand Up @@ -90,6 +92,67 @@ printScenariosThatFailed() {
done
}

configMolForParralelRuns() {
if [ -n "${MOLECULE_RUN_SCENARIOS_IN_PARRALEL}" ]; then
if [ -e "${MOLECULE_CONFIG_FILE}" ] ; then
echo "Molecule configuration file already exists: ${MOLECULE_CONFIG_FILE}."
echo "Skipping creation and configuration for parallel runs, it is assumed that configuration allow parralel execution of the projet scenarios."
else
# see https://www.die-welt.net/2024/04/running-ansible-molecule-tests-in-parallel/
mkdir -p "${MOLECULE_CONFIG_FILE_HOME}"
echo 'prerun: false' >> "${MOLECULE_CONFIG_FILE}"
fi
fi
}

runAllMoleculeScenarios() {
local scenario_name=${1:-"${SCENARIO_NAME}"}
local scenario_driver_name=${2:-"${HARMONIA_MOLECULE_DEFAULT_DRIVER_NAME}"}
local extra_args=${3:-"${EXTRA_ARGS}"}

echo "DEBUG> molecule ${MOLECULE_DEBUG} test "${scenario_name}" -d "${scenario_driver_name}" -- ${extra_args}"
# shellcheck disable=SC2086
molecule ${MOLECULE_DEBUG} test "${scenario_name}" -d "${scenario_driver_name}" -- ${extra_args}
echo "${?}"
}

listAllScenarios() {
for molecule_xml in $(find molecule/*/molecule.yml -maxdepth 1 -print)
do
echo $(basename $(dirname "${molecule_xml}"))
done
}

runAllMoleculeScenariosInParralel() {
declare -A pids
local scenario_driver_name=${1:-"${HARMONIA_MOLECULE_DEFAULT_DRIVER_NAME}"}
local extra_args=${2:-"${EXTRA_ARGS}"}

configMolForParralelRuns
for scenario_name in $(listAllScenarios)
do
echo "DEBUG> molecule ${MOLECULE_DEBUG} test --parallel -s "${scenario_name}" -d "${scenario_driver_name}" -- ${extra_args}" -e wildfly_node_id=${scenario_name} ${extra_args} "${@}" '&>' "${scenario_name}.log '&'"
# shellcheck disable=SC2086
molecule ${MOLECULE_DEBUG} test --parallel -s "${scenario_name}" -d "${scenario_driver_name}" -- -e wildfly_node_id=${scenario_name} ${extra_args} "${@}" &> "${scenario_name}.log" &
pids["${scenario_name}"]="${!}"
echo PID:${pids[${scenario_name}]} for scenario ${scenario_name}
done

sleep 300

MOLECULE_RUN_STATUS=0
for pid in ${pids[@]}
do
wait "${pid}"
scenario_exit_status=${?}
echo "PID ${pid} returned: ${scenario_exit_status}"
if [ "${scenario_exit_status}" -ne 0 ]; then
MOLECULE_RUN_STATUS="${scenario_exit_status}"
fi
done
export MOLECULE_RUN_STATUS
}

runMoleculeScenario() {
local scenario_name=${1:-"${SCENARIO_NAME}"}
local scenario_driver_name=${2:-"${HARMONIA_MOLECULE_DEFAULT_DRIVER_NAME}"}
Expand All @@ -100,10 +163,11 @@ runMoleculeScenario() {
if [ "${scenario_name}" != '--all' ]; then
executeRequestedScenarios "${scenario_name}" "${scenario_driver_name}" "${extra_args}"
else
echo "DEBUG> molecule ${MOLECULE_DEBUG} test "${scenario_name}" -d "${scenario_driver_name}" -- ${extra_args}"
# shellcheck disable=SC2086
molecule ${MOLECULE_DEBUG} test "${scenario_name}" -d "${scenario_driver_name}" -- ${extra_args}
MOLECULE_RUN_STATUS="${?}"
if [ -z "${MOLECULE_RUN_SCENARIOS_IN_PARRALEL}" ]; then
MOLECULE_RUN_STATUS="$(runAllMoleculeScenarios '--all' "${scenario_driver_name}" ${extra_args})"
else
runAllMoleculeScenariosInParralel "${scenario_driver_name}" ${extra_args}
fi
fi
readonly MOLECULE_RUN_STATUS

Expand Down
2 changes: 1 addition & 1 deletion ansible/molecule/molecule-downstream.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ else
fi

# shellcheck disable=SC2155
readonly EXTRA_ARGS="$(loadJBossNetworkAPISecrets)"
readonly EXTRA_ARGS="${EXTRA_ARGS} $(loadJBossNetworkAPISecrets)"
export EXTRA_ARGS
"${HARMONIA_HOME}/ansible/molecule/molecule.sh"
56 changes: 33 additions & 23 deletions eap-job-64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ usage() {
echo
echo "ex: ${script_name} 'testsuite' -Dcustom.args"
echo
echo Note that if no arguments is provided, it default to 'build'. To run the testsuite, you need to provide 'testsuite' as a first argument. All arguments beyond this first will be appended to the mvn command line.
echo "Note that if no arguments are provided, it defaults to 'build'. To run the testsuite, you need to provide 'testsuite' as the first argument. All arguments beyond this first will be appended to the mvn command line."
echo
echo 'Warning: This script also set several mvn args. Please refer to its content before adding some extra maven arguments.'
echo 'Warning: This script also sets several mvn args. Please refer to its content before adding some extra maven arguments.'
}

is_dirpath_defined_and_exists() {
Expand Down Expand Up @@ -55,9 +55,12 @@ function get_eap_version() {
echo $eap_version;
}

function get_dist_folder() {
dist_folder="build/target"
echo "${dist_folder}"
function debug_script() {
if [ -z "${DEBUG}" ] ; then
echo ""
else
echo '-x'
fi
}

BUILD_COMMAND=${1}
Expand All @@ -81,9 +84,13 @@ if [ -n "${JAVA_HOME}" ]; then
export PATH=${JAVA_HOME}/bin:${PATH}
fi

if [ -n "${IS_CCI}" ]; then
readonly EAP_SOURCES_FOLDER=${EAP_SOURCES_FOLDER:-"eap-sources"}
readonly EAP_SOURCES_DIR=${EAP_SOURCES_DIR:-"${WORKSPACE}/${EAP_SOURCES_FOLDER}"}
else
readonly EAP_SOURCES_DIR=${EAP_SOURCES_DIR:-"${WORKSPACE}"}
fi
readonly GIT_SKIP_BISECT_ERROR_CODE=${GIT_SKIP_BISECT_ERROR_CODE:-'125'}
readonly EAP_SOURCES_DIR=${EAP_SOURCES_DIR:-"${WORKSPACE}"}
readonly MAVEN_SETTINGS_XML=${MAVEN_SETTINGS_XML-'/home/master/settings.xml'}
readonly MEMORY_SETTINGS=${MEMORY_SETTINGS:-''}
readonly LOCAL_REPO_DIR=${LOCAL_REPO_DIR:-${WORKSPACE}/maven-local-repository}
export BUILD_OPTS=${BUILD_OPTS:-'-Drelease'}
Expand All @@ -92,6 +99,7 @@ readonly MAVEN_WAGON_HTTP_MAX_PER_ROUTE=${MAVEN_WAGON_HTTP_MAX_PER_ROUTE:-'3'}
readonly SUREFIRE_FORKED_PROCESS_TIMEOUT=${SUREFIRE_FORKED_PROCESS_TIMEOUT:-'90000'}
readonly FAIL_AT_THE_END=${FAIL_AT_THE_END:-'-fae'}
readonly RERUN_FAILING_TESTS=${RERUN_FAILING_TESTS:-'0'}
readonly DIST_FOLDER=${DIST_FOLDER:-'dist/target'}

readonly OLD_RELEASES_FOLDER=${OLD_RELEASES_FOLDER:-/opt/old-as-releases}

Expand Down Expand Up @@ -129,6 +137,16 @@ readonly MAVEN_BIN_DIR=${MAVEN_HOME}/bin
echo "Adding ${MAVEN_BIN_DIR} to PATH:${PATH}."
export PATH=${MAVEN_BIN_DIR}:${PATH}

# Check Maven version and perform the maven setup accordingly.
readonly MAVEN_VERSION=$(mvn -v | awk '/Apache Maven/ {print $3}')
function maven_setup() {
if [ "${MAVEN_VERSION}" != "3.2.5" ]; then
# with EAP 6.4, let maven 3.2 be downloaded to the tools/maven/ directory, which is a hardcoded path in the integration-tests.sh script
cd "${EAP_SOURCES_DIR}"
bash $(debug_script) ./tools/download-maven.sh
fi
}

command -v java
java -version
# shellcheck disable=SC2181
Expand Down Expand Up @@ -162,11 +180,9 @@ if [ "${BUILD_COMMAND}" = 'build' ]; then

# configure product repository URL used by tests
export BUILD_OPTS="${BUILD_OPTS} -Dorg.jboss.model.test.maven.repository.urls=http://download.lab.bos.redhat.com/brewroot/repos/jb-eap-6.4-rhel-6-build/latest/maven/,https://repository.jboss.org/nexus/content/repositories/releases/"

# shellcheck disable=SC2086,SC2068
echo mvn clean install -Dts.skipTests=true ${MAVEN_VERBOSE} "${FAIL_AT_THE_END}" ${MAVEN_SETTINGS_XML_OPTION} -B ${BUILD_OPTS} ${@}
maven_setup
# shellcheck disable=SC2086,SC2068
mvn clean install -Dts.skipTests=true ${MAVEN_VERBOSE} "${FAIL_AT_THE_END}" ${MAVEN_SETTINGS_XML_OPTION} -B ${BUILD_OPTS} ${@}
bash $(debug_script) ./build.sh ${MAVEN_VERBOSE} "${FAIL_AT_THE_END}" ${MAVEN_SETTINGS_XML_OPTION} -B ${BUILD_OPTS} ${@}
status=${?}
if [ "${status}" -ne 0 ]; then
echo "Compilation failed"
Expand All @@ -178,15 +194,14 @@ if [ "${BUILD_COMMAND}" = 'build' ]; then
fi

if [ -n "${IS_CCI}" ]; then
readonly EAP_DIST_DIR=$(get_dist_folder)
readonly EAP_DIST_DIR="${DIST_FOLDER}"
echo "Using ${EAP_DIST_DIR}"

cd "${EAP_DIST_DIR}" || exit "${FOLDER_DOES_NOT_EXIST_ERROR_CODE}"
zip -qr "${WORKSPACE}/jboss-eap-dist-${GIT_COMMIT:0:7}.zip" jboss-eap-*/
zip -qr "${WORKSPACE}/jboss-eap-dist-${GIT_COMMIT:0:7}.zip" jboss-eap-*
cd "${LOCAL_REPO_DIR}/.." || exit "${FOLDER_DOES_NOT_EXIST_ERROR_CODE}"
zip -qr "${WORKSPACE}/jboss-eap-maven-artifacts-${GIT_COMMIT:0:7}.zip" "maven-local-repository"


cd "${WORKSPACE}"

record_build_properties
Expand All @@ -200,8 +215,9 @@ else
if [ -n "${IS_CCI}" ]; then
# unzip artifacts from build job
find . -maxdepth 1 -name '*.zip' -exec unzip -q {} \;
for file in jboss-eap-6.[0-9]*.zip; do unzip "$file"; done

TEST_JBOSS_DIST=$(find . -regextype posix-extended -regex '.*jboss-eap-7\.[0-9]+')
TEST_JBOSS_DIST=$(find . -regextype posix-extended -regex '.*jboss-eap-6\.[0-9]+')
if [ -z "$TEST_JBOSS_DIST" ]; then
echo "No EAP distribution to be tested"
exit 2
Expand All @@ -226,20 +242,14 @@ else
export TESTSUITE_OPTS="${TESTSUITE_OPTS} ${MAVEN_SETTINGS_XML_OPTION}"

export TEST_TO_RUN=${TEST_TO_RUN:-'-DallTests'}
cd "${EAP_SOURCES_DIR}/testsuite" || exit "${FOLDER_DOES_NOT_EXIST_ERROR_CODE}"
mvn clean
cd ..

# with EAP 6.4, let maven 3.2 be downloaded to the tools/maven/ directory, which is a hardcoded path in the integration-tests.sh script
bash -x ./tools/download-maven.sh

maven_setup
# define this var so that integration-tests.sh doesn't use its hardcoded default value
export MVN_ARGS="-DsomeNoneEmptyValue"

# configure product repository URL used by integration tests
export TESTSUITE_OPTS="${TESTSUITE_OPTS} -Dorg.jboss.model.test.eap.repourl=http://download.lab.bos.redhat.com/brewroot/repos/jb-eap-6.4-rhel-6-build/latest/maven/"

# shellcheck disable=SC2086,SC2068
bash -x ./integration-tests.sh "${TEST_TO_RUN}" ${MAVEN_VERBOSE} "${FAIL_AT_THE_END}" ${TESTSUITE_OPTS} ${@}
bash $(debug_script) ./integration-tests.sh "${TEST_TO_RUN}" ${MAVEN_VERBOSE} "${FAIL_AT_THE_END}" ${TESTSUITE_OPTS} ${@}
exit "${?}"
fi
10 changes: 9 additions & 1 deletion eap-job/base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ is_dirpath_defined_and_exists() {
check_java() {
# ensure provided JAVA_HOME, if any, is first in PATH
if [ -n "${JAVA_HOME}" ]; then
export PATH=${JAVA_HOME}/bin:${PATH}
export PATH="${JAVA_HOME}/bin:${PATH}"
if [ ! -x "${JAVA_HOME}/bin/java" ]; then
echo "JAVA_HOME is defined but the file is not executable."
exit 5
fi
fi

command -v java
Expand Down Expand Up @@ -69,6 +73,10 @@ configure_mvn_home() {
export MAVEN_BIN_DIR
echo "Adding ${MAVEN_BIN_DIR} to PATH:${PATH}."
export PATH="${MAVEN_BIN_DIR}":"${PATH}"
if [ ! -x "${MAVEN_HOME}/bin/mvn" ]; then
echo "MAVEN_HOME is defined but the file is not executable."
exit 5
fi

command -v mvn
mvn -version
Expand Down
Loading