mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-05-08 22:34:12 +00:00
Refactored ci script with shellcheck suggestions and install collections
Change-Id: I071e50eadfaf0f17f413a0c5f86e5d6b96356b36
This commit is contained in:
5
ci/requirements.yml
Normal file
5
ci/requirements.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
collections:
|
||||||
|
- ansible.posix
|
||||||
|
- ansible.utils
|
||||||
|
- community.general
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#!/bin/bash
|
||||||
#############################################################################
|
#############################################################################
|
||||||
# run-ansible-tests.sh
|
# run-ansible-tests.sh
|
||||||
#
|
#
|
||||||
@@ -41,27 +42,39 @@ while getopts "c:de:u:" opt
|
|||||||
do
|
do
|
||||||
case $opt in
|
case $opt in
|
||||||
d) USE_DEV=1 ;;
|
d) USE_DEV=1 ;;
|
||||||
c) CLOUD=${OPTARG} ;;
|
c) CLOUD=$OPTARG ;;
|
||||||
u) CLOUD_ALT=${OPTARG} ;;
|
u) CLOUD_ALT=$OPTARG ;;
|
||||||
e) ENVDIR=${OPTARG} ;;
|
e) ENVDIR=$OPTARG ;;
|
||||||
?) echo "Invalid option: -${OPTARG}"
|
?) echo "Invalid option: -$OPTARG"
|
||||||
exit 1;;
|
exit 1;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -z ${ENVDIR} ]
|
# Shift arguments read by getopts
|
||||||
then
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
|
# Remaining arguments are Ansible tags
|
||||||
|
TAGS=$( echo "$*" | tr ' ' , )
|
||||||
|
|
||||||
|
if [ -z "$ENVDIR" ]; then
|
||||||
echo "Option -e is required"
|
echo "Option -e is required"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
shift $((OPTIND-1))
|
if [ ! -d ci ]; then
|
||||||
TAGS=$( echo "$*" | tr ' ' , )
|
echo "Script must be run from collection's root directory"
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
# Install collections before dealing with Ansible virtual environments
|
# Install Ansible collections before dealing with virtual environments for Ansible
|
||||||
if [[ -z "$PIP_INSTALL" ]]; then
|
|
||||||
|
# Install collections used in ci
|
||||||
|
ansible-galaxy collection install --requirements-file ci/requirements.yml
|
||||||
|
|
||||||
|
# Install this collection
|
||||||
|
if [ -z "$PIP_INSTALL" ]; then
|
||||||
tox -ebuild
|
tox -ebuild
|
||||||
ansible-galaxy collection install $(ls build_artifact/openstack-cloud-*) --force
|
ansible-galaxy collection install "$(find build_artifact/ -maxdepth 1 -name 'openstack-cloud-*')" --force
|
||||||
TEST_COLLECTIONS_PATHS=${HOME}/.ansible/collections:$ANSIBLE_COLLECTIONS_PATHS
|
TEST_COLLECTIONS_PATHS=${HOME}/.ansible/collections:$ANSIBLE_COLLECTIONS_PATHS
|
||||||
else
|
else
|
||||||
pip freeze | grep ansible-collections-openstack
|
pip freeze | grep ansible-collections-openstack
|
||||||
@@ -70,25 +83,22 @@ fi
|
|||||||
|
|
||||||
# We need to source the current tox environment so that Ansible will
|
# We need to source the current tox environment so that Ansible will
|
||||||
# be setup for the correct python environment.
|
# be setup for the correct python environment.
|
||||||
source $ENVDIR/bin/activate
|
source "$ENVDIR/bin/activate"
|
||||||
|
|
||||||
if [ ${USE_DEV} -eq 1 ]
|
if [ "$USE_DEV" -eq 1 ]; then
|
||||||
then
|
if [ -d "$ENVDIR/ansible" ]; then
|
||||||
if [ -d ${ENVDIR}/ansible ]
|
|
||||||
then
|
|
||||||
echo "Using existing Ansible source repo"
|
echo "Using existing Ansible source repo"
|
||||||
else
|
else
|
||||||
echo "Installing Ansible source repo at $ENVDIR"
|
echo "Installing Ansible source repo at $ENVDIR"
|
||||||
git clone --recursive https://github.com/ansible/ansible.git ${ENVDIR}/ansible
|
git clone --recursive https://github.com/ansible/ansible.git "$ENVDIR/ansible"
|
||||||
fi
|
fi
|
||||||
source $ENVDIR/ansible/hacking/env-setup
|
source "$ENVDIR/ansible/hacking/env-setup"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run the shade Ansible tests
|
# Run the shade Ansible tests
|
||||||
tag_opt=""
|
tag_opt=""
|
||||||
if [ ! -z ${TAGS} ]
|
if [ -n "$TAGS" ]; then
|
||||||
then
|
tag_opt="--tags $TAGS"
|
||||||
tag_opt="--tags ${TAGS}"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Loop through all ANSIBLE_VAR_ environment variables to allow passing the further
|
# Loop through all ANSIBLE_VAR_ environment variables to allow passing the further
|
||||||
@@ -103,41 +113,42 @@ done
|
|||||||
# Until we have a module that lets us determine the image we want from
|
# Until we have a module that lets us determine the image we want from
|
||||||
# within a playbook, we have to find the image here and pass it in.
|
# within a playbook, we have to find the image here and pass it in.
|
||||||
# We use the openstack client instead of nova client since it can use clouds.yaml.
|
# We use the openstack client instead of nova client since it can use clouds.yaml.
|
||||||
IMAGE=`openstack --os-cloud=${CLOUD} image list -f value -c Name | grep cirros | grep -v -e ramdisk -e kernel`
|
IMAGE=$(openstack "--os-cloud=$CLOUD" image list -f value -c Name | grep cirros | grep -v -e ramdisk -e kernel)
|
||||||
if [ $? -ne 0 ]
|
if [ -z "$IMAGE" ]; then
|
||||||
then
|
|
||||||
echo "Failed to find Cirros image"
|
echo "Failed to find Cirros image"
|
||||||
exit 1
|
exit 3
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# In case of Octavia enabled:
|
# In case of Octavia enabled:
|
||||||
_octavia_image_path="/tmp/test-only-amphora-x64-haproxy-ubuntu-bionic.qcow2"
|
_octavia_image_path="/tmp/test-only-amphora-x64-haproxy-ubuntu-bionic.qcow2"
|
||||||
if systemctl list-units --full -all | grep -Fq "devstack@o-api.service" && \
|
if systemctl list-units --full -all | grep -Fq "devstack@o-api.service" && \
|
||||||
test -f "$_octavia_image_path"
|
test -f "$_octavia_image_path"; then
|
||||||
then
|
|
||||||
# Upload apmhora image for Octavia to test load balancers
|
# Upload apmhora image for Octavia to test load balancers
|
||||||
OCTAVIA_AMP_IMAGE_FILE=${OCTAVIA_AMP_IMAGE_FILE:-"$_octavia_image_path"}
|
OCTAVIA_AMP_IMAGE_FILE=${OCTAVIA_AMP_IMAGE_FILE:-"$_octavia_image_path"}
|
||||||
OCTAVIA_AMP_IMAGE_NAME=${OCTAVIA_AMP_IMAGE_NAME:-"test-only-amphora-x64-haproxy-ubuntu-bionic"}
|
OCTAVIA_AMP_IMAGE_NAME=${OCTAVIA_AMP_IMAGE_NAME:-"test-only-amphora-x64-haproxy-ubuntu-bionic"}
|
||||||
OCTAVIA_AMP_IMAGE_SIZE=${OCTAVIA_AMP_IMAGE_SIZE:-3}
|
OCTAVIA_AMP_IMAGE_SIZE=${OCTAVIA_AMP_IMAGE_SIZE:-3}
|
||||||
openstack --os-cloud=${CLOUD} image create \
|
openstack "--os-cloud=$CLOUD" image create \
|
||||||
--container-format bare \
|
--container-format bare \
|
||||||
--disk-format qcow2 \
|
--disk-format qcow2 \
|
||||||
--private \
|
--private \
|
||||||
--file $OCTAVIA_AMP_IMAGE_FILE \
|
--file "$OCTAVIA_AMP_IMAGE_FILE" \
|
||||||
--project service $OCTAVIA_AMP_IMAGE_NAME
|
--project service "$OCTAVIA_AMP_IMAGE_NAME"
|
||||||
openstack --os-cloud=${CLOUD} image set --tag amphora $OCTAVIA_AMP_IMAGE_NAME
|
openstack "--os-cloud=$CLOUD" image set --tag amphora "$OCTAVIA_AMP_IMAGE_NAME"
|
||||||
# End of Octavia preparement
|
# End of Octavia preparement
|
||||||
else
|
else
|
||||||
tag_opt="$tag_opt --skip-tags loadbalancer"
|
# Run all tasks except for loadbalancer tasks
|
||||||
|
tag_opt+=" --skip-tags loadbalancer"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Discover openstackSDK version
|
# Discover openstacksdk version
|
||||||
SDK_VER=$(python -c "import openstack; print(openstack.version.__version__)")
|
SDK_VER=$(python -c "import openstack; print(openstack.version.__version__)")
|
||||||
pushd ci/
|
|
||||||
# run tests
|
cd ci/
|
||||||
|
|
||||||
|
# Run tests
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
# shellcheck disable=SC2086
|
||||||
ANSIBLE_COLLECTIONS_PATHS=$TEST_COLLECTIONS_PATHS ansible-playbook \
|
ANSIBLE_COLLECTIONS_PATHS=$TEST_COLLECTIONS_PATHS ansible-playbook \
|
||||||
-vvv ./run-collection.yml \
|
-vvv ./run-collection.yml \
|
||||||
-e "sdk_version=${SDK_VER} cloud=${CLOUD} cloud_alt=${CLOUD_ALT} image=${IMAGE} ${ANSIBLE_VARS}" \
|
-e "sdk_version=${SDK_VER} cloud=${CLOUD} cloud_alt=${CLOUD_ALT} image=${IMAGE} ${ANSIBLE_VARS}" \
|
||||||
${tag_opt} 2>&1 | sudo tee /opt/stack/logs/test_output.log
|
${tag_opt} 2>&1 | sudo tee /opt/stack/logs/test_output.log
|
||||||
popd
|
|
||||||
|
|||||||
Reference in New Issue
Block a user