7a7f858ae2
Instaling and using Ansible from source for bifrost has several drawbacks, mainly due to how Ansible's 'ansible/hacking/env-setup' script mangles with PATH and PYTHONPATH, which complicates running it as part of other scripts. Besides, cloning the whole repo and it's submodules is somewhat longer. The main reason why we were doing that at all was a necessity to install some additional Ansible modules from newer Ansible versions, which we dropped right into the source of Ansible code - but this does not have to be so. Luckily for us, all Ansible versions we target to support can load modules from 'library' directory next to playbooks/roles, and we already use that for 'os_ironic_facts' module. The need to install a particular module can be assessed by running ad-hoc 'ansible' command against localhost with the module in question and without any arguments ('ansible localhost -m <module>'): - if the module is available in Ansible, the stderr will contain "changed" substring (as part of the standard module output) - if the module is absent form Ansible, "changed" string will be absent from stderr too, in which case we can download the module from github directly into 'playbooks/library' directory. This patch removes possibility of installing Ansible from source, and always installs a released Ansible version via pip. If not installed into venv, Ansible will be installed in user's ~/.local directory via 'pip install --user'. The missing but needed modules are downloaded as described above. Some level of backward compatibility is provided: - when the ANSIBLE_GIT_BRANCH has form of 'stable-X.Y', the env-setup.sh script will do the next best thing and install latest available Ansible version of X.Y.w.z Also, ANSIBLE_PIP_VERSION can now accept a full pip version specifier: - if ANSIBLE_PIP_VERSION starts with a digit, this exact version will be installed (as 'ansible==X.Y.W.Z') - otherwize this whole variable is assigned as Ansible version specifier for pip, e.g env ANSIBLE_PIP_VERSION="<2.2" env-setup.sh will result in pip being called as pip install -U "ansible<2.2" Closes-Bug: #1663562 Change-Id: I2c9f47abbbb6740d03978f684ad2c876749655b7
163 lines
4.7 KiB
Bash
Executable File
163 lines
4.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
set -eux
|
|
set -o pipefail
|
|
export PYTHONUNBUFFERED=1
|
|
SCRIPT_HOME="$(cd "$(dirname "$0")" && pwd)"
|
|
BIFROST_HOME=$SCRIPT_HOME/..
|
|
ANSIBLE_INSTALL_ROOT=${ANSIBLE_INSTALL_ROOT:-/opt/stack}
|
|
ENABLE_VENV="false"
|
|
USE_DHCP="false"
|
|
USE_VENV="false"
|
|
BUILD_IMAGE="false"
|
|
|
|
# Set defaults for ansible command-line options to drive the different
|
|
# tests.
|
|
|
|
# NOTE(TheJulia/cinerama): The variables defined on the command line
|
|
# for the default and DHCP tests are to drive the use of Cirros as the
|
|
# deployed operating system, and as such sets the test user to cirros,
|
|
# and writes a debian style interfaces file out to the configuration
|
|
# drive as cirros does not support the network_info.json format file
|
|
# placed in the configuration drive. The "build image" test does not
|
|
# use cirros.
|
|
|
|
VM_MEMORY_SIZE="3072"
|
|
VM_DOMAIN_TYPE=qemu
|
|
export VM_DISK_CACHE="unsafe"
|
|
TEST_VM_NUM_NODES=1
|
|
USE_CIRROS=true
|
|
TESTING_USER=cirros
|
|
TEST_PLAYBOOK="test-bifrost.yaml"
|
|
USE_INSPECTOR=true
|
|
INSPECT_NODES=true
|
|
INVENTORY_DHCP=false
|
|
INVENTORY_DHCP_STATIC_IP=false
|
|
DOWNLOAD_IPA=true
|
|
CREATE_IPA_IMAGE=false
|
|
WRITE_INTERFACES_FILE=true
|
|
PROVISION_WAIT_TIMEOUT=${PROVISION_WAIT_TIMEOUT:-900}
|
|
NOAUTH_MODE=true
|
|
ENABLE_KEYSTONE=false
|
|
CLOUD_CONFIG=""
|
|
WAIT_FOR_DEPLOY=true
|
|
|
|
# NOTE(cinerama): We could remove this if we change the CI job to use
|
|
# USE_DHCP, BUILD_IMAGE, etc.
|
|
SOURCE=$(basename ${BASH_SOURCE[0]})
|
|
if [ $SOURCE = "test-bifrost-inventory-dhcp.sh" ]; then
|
|
USE_DHCP="true"
|
|
elif [ $SOURCE = "test-bifrost-venv.sh" ]; then
|
|
USE_VENV="true"
|
|
elif [ $SOURCE = "test-bifrost-build-images.sh" ]; then
|
|
BUILD_IMAGE="true"
|
|
elif [ $SOURCE = "test-bifrost-keystone-auth.sh" ]; then
|
|
ENABLE_KEYSTONE="true"
|
|
fi
|
|
|
|
if [ ${USE_VENV} = "true" ]; then
|
|
export VENV=/opt/stack/bifrost
|
|
export PATH=${VENV}/bin:${PATH}
|
|
$SCRIPT_HOME/env-setup.sh
|
|
# Note(cinerama): activate is not compatible with "set -u";
|
|
# disable it just for this line.
|
|
set +u
|
|
source /opt/stack/bifrost/bin/activate
|
|
set -u
|
|
ANSIBLE=${VENV}/bin/ansible-playbook
|
|
ENABLE_VENV="true"
|
|
else
|
|
$SCRIPT_HOME/env-setup.sh
|
|
ANSIBLE=${HOME}/.local/bin/ansible-playbook
|
|
fi
|
|
|
|
# Adjust options for DHCP, VM, or Keystone tests
|
|
if [ ${USE_DHCP} = "true" ]; then
|
|
VM_MEMORY_SIZE="1024"
|
|
ENABLE_INSPECTOR=false
|
|
INSPECT_NODES=false
|
|
TEST_VM_NUM_NODES=5
|
|
INVENTORY_DHCP=true
|
|
INVENTORY_DHCP_STATIC_IP=true
|
|
WRITE_INTERFACES_FILE=false
|
|
elif [ ${BUILD_IMAGE} = "true" ]; then
|
|
USE_CIRROS=false
|
|
TESTING_USER=root
|
|
VM_MEMORY_SIZE="4096"
|
|
ENABLE_INSPECTOR=false
|
|
INSPECT_NODES=false
|
|
DOWNLOAD_IPA=false
|
|
CREATE_IPA_IMAGE=true
|
|
elif [ ${ENABLE_KEYSTONE} = "true" ]; then
|
|
NOAUTH_MODE=false
|
|
CLOUD_CONFIG="-e cloud_name=bifrost"
|
|
fi
|
|
|
|
# Change working directory
|
|
cd $BIFROST_HOME/playbooks
|
|
|
|
# Syntax check of dynamic inventory test path
|
|
for task in syntax-check list-tasks; do
|
|
${ANSIBLE} -vvvv \
|
|
-i inventory/localhost \
|
|
test-bifrost-create-vm.yaml \
|
|
--${task}
|
|
${ANSIBLE} -vvvv \
|
|
-i inventory/localhost \
|
|
${TEST_PLAYBOOK} \
|
|
--${task} \
|
|
-e testing_user=${TESTING_USER}
|
|
done
|
|
|
|
# Create the test VM
|
|
${ANSIBLE} -vvvv \
|
|
-i inventory/localhost \
|
|
test-bifrost-create-vm.yaml \
|
|
-e test_vm_num_nodes=${TEST_VM_NUM_NODES} \
|
|
-e test_vm_memory_size=${VM_MEMORY_SIZE} \
|
|
-e test_vm_domain_type=${VM_DOMAIN_TYPE} \
|
|
-e enable_venv=${ENABLE_VENV}
|
|
|
|
if [ ${USE_DHCP} = "true" ]; then
|
|
# cut file to limit number of nodes to enroll for testing purposes
|
|
head -n -2 /tmp/baremetal.csv > /tmp/baremetal.csv.new && mv /tmp/baremetal.csv.new /tmp/baremetal.csv
|
|
fi
|
|
|
|
set +e
|
|
|
|
# Set BIFROST_INVENTORY_SOURCE
|
|
export BIFROST_INVENTORY_SOURCE=/tmp/baremetal.csv
|
|
|
|
# Execute the installation and VM startup test.
|
|
|
|
${ANSIBLE} -vvvv \
|
|
-i inventory/bifrost_inventory.py \
|
|
${TEST_PLAYBOOK} \
|
|
-e use_cirros=${USE_CIRROS} \
|
|
-e testing_user=${TESTING_USER} \
|
|
-e test_vm_num_nodes=${TEST_VM_NUM_NODES} \
|
|
-e inventory_dhcp=${INVENTORY_DHCP} \
|
|
-e inventory_dhcp_static_ip=${INVENTORY_DHCP_STATIC_IP} \
|
|
-e enable_venv=${ENABLE_VENV} \
|
|
-e enable_inspector=${USE_INSPECTOR} \
|
|
-e inspect_nodes=${INSPECT_NODES} \
|
|
-e download_ipa=${DOWNLOAD_IPA} \
|
|
-e create_ipa_image=${CREATE_IPA_IMAGE} \
|
|
-e write_interfaces_file=${WRITE_INTERFACES_FILE} \
|
|
-e wait_timeout=${PROVISION_WAIT_TIMEOUT} \
|
|
-e noauth_mode=${NOAUTH_MODE} \
|
|
-e enable_keystone=${ENABLE_KEYSTONE} \
|
|
-e wait_for_node_deploy=${WAIT_FOR_DEPLOY} \
|
|
${CLOUD_CONFIG}
|
|
EXITCODE=$?
|
|
|
|
if [ $EXITCODE != 0 ]; then
|
|
echo "****************************"
|
|
echo "Test failed. See logs folder"
|
|
echo "****************************"
|
|
fi
|
|
|
|
$SCRIPT_HOME/collect-test-info.sh
|
|
|
|
exit $EXITCODE
|