tripleo-ci/roles/run-test/templates/toci_quickstart.sh.j2
Sagi Shnaidman 75ff68608b Prevent second logs collection for OVB jobs
Closes-Bug: #1815048
Change-Id: I6d15291846a884e951b2535099bbfe1230d9473f
2019-02-07 14:06:59 +00:00

184 lines
6.8 KiB
Django/Jinja
Executable File

#!/usr/bin/env bash
set -eux
set -o pipefail
export ANSIBLE_NOCOLOR=1
LOCAL_WORKING_DIR="{{ workspace }}/.quickstart"
WORKING_DIR="$HOME"
LOGS_DIR={{ workspace }}/logs
source {{ tripleo_root }}/tripleo-ci/scripts/oooq_common_functions.sh
## Signal to toci_gate_test.sh we've started by
touch /tmp/toci.started
export DEFAULT_ARGS="--extra-vars local_working_dir=$LOCAL_WORKING_DIR \
--extra-vars virthost={{ undercloud }} \
--inventory $LOCAL_WORKING_DIR/hosts \
--extra-vars tripleo_root={{ tripleo_root }} \
--extra-vars working_dir=$WORKING_DIR \
--skip-tags "tripleo-validations,teardown-all" \
"
# --install-deps arguments installs deps and then quits, no other arguments are
# processed.
QUICKSTART_PREPARE_CMD="
./quickstart.sh
--install-deps
"
QUICKSTART_VENV_CMD="
./quickstart.sh
--bootstrap
--no-clone
--working-dir $LOCAL_WORKING_DIR
--playbook noop.yml
--retain-inventory
{{ undercloud }}
"
#REMOVE build from --skip-tags ASAP
QUICKSTART_INSTALL_CMD="
$LOCAL_WORKING_DIR/bin/ansible-playbook
--tags {{ ','.join(tags + (extra_tags|default([]))) }}
"
export QUICKSTART_DEFAULT_RELEASE_ARG="--extra-vars @$LOCAL_WORKING_DIR/config/release/tripleo-ci/{{ ansible_distribution }}-{{ ansible_distribution_major_version }}/$QUICKSTART_RELEASE.yml"
QUICKSTART_COLLECTLOGS_CMD="$LOCAL_WORKING_DIR/bin/ansible-playbook \
$LOCAL_WORKING_DIR/playbooks/collect-logs.yml \
-vvvv \
$QUICKSTART_DEFAULT_RELEASE_ARG \
{{ featureset_conf }} \
{{ env_vars }} \
{{ extra_vars }} \
$DEFAULT_ARGS \
--extra-vars @{{ tripleo_root }}/tripleo-ci/toci-quickstart/config/collect-logs.yml \
--extra-vars artcl_collect_dir=$LOGS_DIR \
--extra-vars @{{ workspace }}/logs/zuul-variables.yaml \
--tags all \
"
declare -A RELEASE_ARGS=()
if [[ -f "$RELEASES_FILE_OUTPUT" ]]; then
source $RELEASES_FILE_OUTPUT
declare -A RELEASE_ARGS=(
["multinode-undercloud.yml"]=$(get_extra_vars_from_release \
$UNDERCLOUD_INSTALL_RELEASE $UNDERCLOUD_INSTALL_HASH)
["multinode-undercloud-upgrade.yml"]=$(get_extra_vars_from_release \
$UNDERCLOUD_TARGET_RELEASE $UNDERCLOUD_TARGET_HASH)
["multinode-overcloud-prep.yml"]=$(get_extra_vars_from_release \
$OVERCLOUD_DEPLOY_RELEASE $OVERCLOUD_DEPLOY_HASH)
["multinode-overcloud.yml"]=$(get_extra_vars_from_release \
$OVERCLOUD_DEPLOY_RELEASE $OVERCLOUD_DEPLOY_HASH)
["multinode-overcloud-update.yml"]=$(get_extra_vars_from_release \
$OVERCLOUD_DEPLOY_RELEASE $OVERCLOUD_DEPLOY_HASH)
["multinode-overcloud-upgrade.yml"]=$(get_extra_vars_from_release \
$OVERCLOUD_TARGET_RELEASE $OVERCLOUD_TARGET_HASH)
["multinode-validate.yml"]=$(get_extra_vars_from_release \
$OVERCLOUD_TARGET_RELEASE $OVERCLOUD_TARGET_HASH)
["multinode-standalone.yml"]=$(get_extra_vars_from_release \
$STANDALONE_DEPLOY_RELEASE $STANDALONE_DEPLOY_HASH \
$STANDALONE_DEPLOY_NEWEST_HASH)
["multinode-standalone-upgrade.yml"]=$(get_extra_vars_from_release \
$STANDALONE_TARGET_RELEASE $STANDALONE_TARGET_HASH \
$STANDALONE_TARGET_NEWEST_HASH)
)
fi
declare -A PLAYBOOKS_ARGS=(
["baremetal-full-overcloud.yml"]=" --extra-vars validation_args='--validation-errors-nonfatal' "
["multinode-overcloud.yml"]=" --extra-vars validation_args='--validation-errors-nonfatal' "
["multinode.yml"]=" --extra-vars validation_args='--validation-errors-nonfatal' "
)
mkdir -p $LOCAL_WORKING_DIR
# TODO(gcerami) parametrize hosts
cp {{ tripleo_root }}/tripleo-ci/toci-quickstart/config/testenv/{{ environment_infra }}_hosts $LOCAL_WORKING_DIR/hosts
pushd {{ tripleo_root }}/tripleo-quickstart/
$QUICKSTART_PREPARE_CMD
$QUICKSTART_VENV_CMD
# Only ansible-playbook command will be used from this point forward, so we
# need some variables from quickstart.sh
OOOQ_DIR={{ tripleo_root }}/tripleo-quickstart/
export OPT_WORKDIR=$LOCAL_WORKING_DIR
export ANSIBLE_CONFIG=$OOOQ_DIR/ansible.cfg
export ARA_DATABASE="sqlite:///${LOCAL_WORKING_DIR}/ara.sqlite"
export VIRTUAL_ENV_DISABLE_PROMPT=1
# Workaround for virtualenv issue https://github.com/pypa/virtualenv/issues/1029
set +u
source $LOCAL_WORKING_DIR/bin/activate
set -u
source $OOOQ_DIR/ansible_ssh_env.sh
# Debug step capture env variables
{% if dryrun|default(false)|bool %}
echo "-- Capture Environment Variables Used ---------"
echo "$(env)" | tee -a $LOGS_DIR/toci_env_args_output.log
declare -p | tee -a $LOGS_DIR/toci_env_args_output.log
{% endif %}
echo "-- Playbooks Output --------------------------"
for playbook in {{ " ".join(playbooks) }}; do
echo "$QUICKSTART_INSTALL_CMD \
${RELEASE_ARGS[$playbook]:=$QUICKSTART_DEFAULT_RELEASE_ARG} \
{{ nodes_args }} \
{{ featureset_conf }} \
{{ env_vars }} \
{{ extra_vars }} \
{{ vxlan_vars }} \
$DEFAULT_ARGS \
$LOCAL_WORKING_DIR/playbooks/$playbook ${PLAYBOOKS_ARGS[$playbook]:-}" \
--extra-vars @{{ workspace }}/logs/zuul-variables.yaml \
| sed 's/--/\n--/g' \
| tee -a $LOGS_DIR/playbook_executions.log
echo "# --------------------------------------- " \
| tee -a $LOGS_DIR/playbook_executions.log
done
{% if dryrun|default(false)|bool %}
# Bypassing execution, dryrun was set
exit_value=0
{% else %}
## LOGS COLLECTION PREPARE
create_collect_logs_script
for playbook in {{ " ".join(playbooks) }}; do
echo ${RELEASE_ARGS[$playbook]:=$QUICKSTART_DEFAULT_RELEASE_ARG}
$QUICKSTART_INSTALL_CMD \
${RELEASE_ARGS[$playbook]:=$QUICKSTART_DEFAULT_RELEASE_ARG} \
{{ nodes_args }} \
{{ featureset_conf }} \
{{ env_vars }} \
{{ extra_vars }} \
{{ vxlan_vars }} \
$DEFAULT_ARGS \
--extra-vars @{{ workspace }}/logs/zuul-variables.yaml \
$LOCAL_WORKING_DIR/playbooks/$playbook ${PLAYBOOKS_ARGS[$playbook]:-} \
2>&1 | tee -a $LOGS_DIR/quickstart_install.log && exit_value=0 || exit_value=$?
# Print status of playbook run
[[ "$exit_value" == 0 ]] && echo "Playbook run of $playbook passed successfully"
[[ "$exit_value" != 0 ]] && echo "Playbook run of $playbook failed" && break
done
[[ "$exit_value" == 0 ]] && echo "Playbook run passed successfully" || echo "Playbook run failed"
## LOGS COLLECTION RUN (if applicable)
{% if environment_type == "ovb" -%}
echo "Running collect logs now, before the nodes are destryed by te broker"
/usr/bin/timeout --preserve-status 40m bash $LOGS_DIR/collect_logs.sh > $LOGS_DIR/quickstart_collect_logs.log
mv $LOGS_DIR/collect_logs.sh $LOGS_DIR/ovb_collect_logs.sh
{% else %}
echo "Running Collect Logs in post"
{% endif %}
{% endif %}
echo 'Quickstart completed.'
exit $exit_value