Robust base dir support for bootstrapping
Currently the library expects the user to be running bootstrap scripts from the root of the openstack-ansible directory. If the user is not, then the bootstrap exits with failure and an error message. Directories with special characters (such as spaces) are also not supported, so running the script from outside the base dir will cause script errors. This patch implements support for bootstrapping outside the base dir, including support for directory names with special characters. This is extended to test and upgrade scripts. Change-Id: I5cfa5a0bdbd762c50fe5a41cb88b3c0677f62482
This commit is contained in:
parent
1a797e42ec
commit
2f87f8ca72
@ -29,16 +29,18 @@ export DEBIAN_FRONTEND=${DEBIAN_FRONTEND:-"noninteractive"}
|
||||
# Set the role fetch mode to any option [galaxy, git-clone]
|
||||
export ANSIBLE_ROLE_FETCH_MODE=${ANSIBLE_ROLE_FETCH_MODE:-galaxy}
|
||||
|
||||
# This script should be executed from the root directory of the cloned repo
|
||||
cd "$(dirname "${0}")/.."
|
||||
|
||||
## Functions -----------------------------------------------------------------
|
||||
info_block "Checking for required libraries." 2> /dev/null ||
|
||||
source $(dirname ${0})/scripts-library.sh ||
|
||||
source scripts/scripts-library.sh
|
||||
|
||||
## Main ----------------------------------------------------------------------
|
||||
info_block "Bootstrapping System with Ansible"
|
||||
|
||||
# Set the variable to the role file to be the absolute path
|
||||
ANSIBLE_ROLE_FILE="$(readlink -f ${ANSIBLE_ROLE_FILE})"
|
||||
ANSIBLE_ROLE_FILE="$(readlink -f "${ANSIBLE_ROLE_FILE}")"
|
||||
|
||||
# Create the ssh dir if needed
|
||||
ssh_key_create
|
||||
|
@ -31,7 +31,7 @@ export OSA_GATE_JOB=true
|
||||
export ANSIBLE_ROLE_FETCH_MODE="git-clone"
|
||||
|
||||
## Functions -----------------------------------------------------------------
|
||||
info_block "Checking for required libraries." 2> /dev/null || source $(dirname ${0})/scripts-library.sh
|
||||
info_block "Checking for required libraries." 2> /dev/null || source "$(dirname "${0}")/scripts-library.sh"
|
||||
|
||||
## Main ----------------------------------------------------------------------
|
||||
# Set gate job exit traps, this is run regardless of exit state when the job finishes.
|
||||
@ -41,7 +41,7 @@ trap gate_job_exit_tasks EXIT
|
||||
log_instance_info
|
||||
|
||||
# Get minimum disk size
|
||||
DATA_DISK_MIN_SIZE="$((1024**3 * $(awk '/bootstrap_host_data_disk_min_size/{print $2}' $(dirname ${0})/../tests/roles/bootstrap-host/defaults/main.yml) ))"
|
||||
DATA_DISK_MIN_SIZE="$((1024**3 * $(awk '/bootstrap_host_data_disk_min_size/{print $2}' "$(dirname "${0}")/../tests/roles/bootstrap-host/defaults/main.yml") ))"
|
||||
|
||||
# Determine the largest secondary disk device that meets the minimum size
|
||||
DATA_DISK_DEVICE=$(lsblk -brndo NAME,TYPE,RO,SIZE | awk '/d[b-z]+ disk 0/{ if ($4>m && $4>='$DATA_DISK_MIN_SIZE'){m=$4; d=$1}}; END{print d}')
|
||||
@ -52,7 +52,7 @@ if [ -n "${DATA_DISK_DEVICE}" ]; then
|
||||
fi
|
||||
|
||||
# Bootstrap Ansible
|
||||
source $(dirname ${0})/bootstrap-ansible.sh
|
||||
source "$(dirname "${0}")/bootstrap-ansible.sh"
|
||||
|
||||
# Log some data about the instance and the rest of the system
|
||||
log_instance_info
|
||||
@ -69,7 +69,7 @@ iptables -P FORWARD ACCEPT
|
||||
iptables -P OUTPUT ACCEPT
|
||||
|
||||
# Bootstrap an AIO
|
||||
pushd $(dirname ${0})/../tests
|
||||
pushd "$(dirname "${0}")/../tests"
|
||||
sed -i '/\[defaults\]/a nocolor = 1/' ansible.cfg
|
||||
ansible-playbook -i test-inventory.ini \
|
||||
-e "${BOOTSTRAP_OPTS}" \
|
||||
@ -81,9 +81,9 @@ popd
|
||||
mkdir -p /openstack/log
|
||||
|
||||
# Implement the log directory link for openstack-infra log publishing
|
||||
ln -sf /openstack/log $(dirname ${0})/../logs
|
||||
ln -sf /openstack/log "$(dirname "${0}")/../logs"
|
||||
|
||||
pushd $(dirname ${0})/../playbooks
|
||||
pushd "$(dirname "${0}")/../playbooks"
|
||||
# Disable Ansible color output
|
||||
sed -i 's/nocolor.*/nocolor = 1/' ansible.cfg
|
||||
|
||||
@ -100,13 +100,13 @@ log_instance_info
|
||||
|
||||
# Execute the Playbooks
|
||||
export DEPLOY_AIO=true
|
||||
bash $(dirname ${0})/run-playbooks.sh
|
||||
bash "$(dirname "${0}")/run-playbooks.sh"
|
||||
|
||||
# Log some data about the instance and the rest of the system
|
||||
log_instance_info
|
||||
|
||||
# Run the tempest tests
|
||||
source $(dirname ${0})/run-tempest.sh
|
||||
source "$(dirname "${0}")/run-tempest.sh"
|
||||
|
||||
# Log some data about the instance and the rest of the system
|
||||
log_instance_info
|
||||
|
@ -64,7 +64,7 @@ function playbook_run {
|
||||
|
||||
trap run_play_book_exit_message EXIT
|
||||
|
||||
info_block "Checking for required libraries." 2> /dev/null || source $(dirname ${0})/scripts-library.sh
|
||||
info_block "Checking for required libraries." 2> /dev/null || source "$(dirname "${0}")/scripts-library.sh"
|
||||
|
||||
# Initiate the deployment
|
||||
pushd "playbooks"
|
||||
|
@ -27,7 +27,7 @@ export RUN_TEMPEST_OPTS=${RUN_TEMPEST_OPTS:-'--serial'}
|
||||
export TESTR_OPTS=${TESTR_OPTS:-''}
|
||||
|
||||
## Library Check -------------------------------------------------------------
|
||||
info_block "Checking for required libraries." 2> /dev/null || source $(dirname ${0})/scripts-library.sh
|
||||
info_block "Checking for required libraries." 2> /dev/null || source "$(dirname "${0}")/scripts-library.sh"
|
||||
|
||||
|
||||
## Main ----------------------------------------------------------------------
|
||||
|
@ -21,8 +21,8 @@
|
||||
## Shell Opts ----------------------------------------------------------------
|
||||
set -e -u -v
|
||||
|
||||
export SCRIPTS_PATH="$(dirname $(readlink -f $0))"
|
||||
export MAIN_PATH="$(dirname ${SCRIPTS_PATH})"
|
||||
export SCRIPTS_PATH="$(dirname "$(readlink -f "${0}")")"
|
||||
export MAIN_PATH="$(dirname "${SCRIPTS_PATH}")"
|
||||
export UPGRADE_PLAYBOOKS="${SCRIPTS_PATH}/upgrade-utilities/playbooks"
|
||||
|
||||
## Functions -----------------------------------------------------------------
|
||||
@ -93,7 +93,7 @@ function check_for_current {
|
||||
|
||||
function pre_flight {
|
||||
## Library Check -------------------------------------------------------------
|
||||
echo "Checking for required libraries." 2> /dev/null || source $(dirname ${0})/scripts-library.sh
|
||||
echo "Checking for required libraries." 2> /dev/null || source "$(dirname "${0}")/scripts-library.sh"
|
||||
## Pre-flight Check ----------------------------------------------------------
|
||||
# Clear the screen and make sure the user understands whats happening.
|
||||
clear
|
||||
|
@ -232,7 +232,7 @@ if [[ "${OSA_BRANCH}" != "master" ]]; then
|
||||
fi
|
||||
|
||||
# Now use the information we have to update the ansible-role-requirements file
|
||||
$(dirname ${0})/ansible-role-requirements-editor.py -f ansible-role-requirements.yml -n "${role_name}" -v "${role_version}"
|
||||
"$(dirname "${0}")/ansible-role-requirements-editor.py" -f ansible-role-requirements.yml -n "${role_name}" -v "${role_version}"
|
||||
done
|
||||
echo "Completed updating ansible-role-requirements.yml"
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user