Improve stackrc file sourcing

We can deploy a TripleO environment from a different user than the
'stack' user. This patch will source the stackrc file coming from the
user home running this script or fail if it doesn't exist.

This patch also enforces the find command to get not more than one
validation found. For example, when running the neutron-sanity-check
playbook, the find command was getting two validations and this script
was running them both.

$ BASEDIR="/usr/share/openstack-tripleo-validations"
$ VALIDATION="neutron-sanity-check"

$ find $BASEDIR/playbooks -type f -regex "^.*${VALIDATION}.y[a]?ml"
/usr/share/openstack-tripleo-validations/playbooks/neutron-sanity-check.yaml
/usr/share/openstack-tripleo-validations/playbooks/undercloud-neutron-sanity-check.yaml

$ find $BASEDIR/playbooks -type f -regex ".*playbooks\/${VALIDATION}.y[a]?ml"
/usr/share/openstack-tripleo-validations/playbooks/neutron-sanity-check.yaml

Change-Id: I889d007fdd757788678fe3d10241024d417632d5
Signed-off-by: Gael Chamoulaud <gchamoul@redhat.com>
This commit is contained in:
Gael Chamoulaud 2019-06-11 14:16:04 +02:00
parent e819f040e4
commit 831b7ae9ea

View File

@ -1,7 +1,7 @@
#!/bin/bash
# IF running on Undercloud
source /home/stack/stackrc
source ${HOME}/stackrc || { echo "The stackrc file is missing or cannot be read"; exit 1; }
# IF running on standalone, replace by
# export OS_CLOUD=standalone
@ -71,7 +71,7 @@ fi
VALIDATIONS_BASEDIR="/usr/share/openstack-tripleo-validations"
VAL=$(find $VALIDATIONS_BASEDIR/playbooks -type f -regex ".*${VALIDATION}\.y[a]?ml")
VAL=$(find $VALIDATIONS_BASEDIR/playbooks -type f -regex ".*playbooks\/${VALIDATION}\.y[a]?ml")
if [[ -z ${VAL} ]]; then
echo "The ${VALIDATION} validation doesn't exist"
exit 1