From f1d98a93941013e5fda5489de1629cc5e282fd07 Mon Sep 17 00:00:00 2001 From: Pierre Riteau Date: Mon, 15 Mar 2021 12:26:13 +0100 Subject: [PATCH] Support specifying a Kayobe environment to use This also includes a cherry-pick of I9a44578196086ec24de80b992fed385826778feb, Stop accessing unbound variables. The kayobe-env script would try accessing $1 which is an unbound variable if no argument is passed. This fails when `set -u` is set. Also refactor usage output into a function. As a side effect, a missing argument to --environment now causes the script to properly exit with an error. Change-Id: I604c2ae6c47ef16fdc98e0598cad820e49e2ff26 Story: 2002009 Task: 41577 (cherry picked from commit 75b6402f8b0d4e39c40a1d11091ca760d8b99dee) --- kayobe-env | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/kayobe-env b/kayobe-env index dbd5605..949e99b 100644 --- a/kayobe-env +++ b/kayobe-env @@ -35,3 +35,30 @@ export KOLLA_SOURCE_PATH=${KOLLA_SOURCE_PATH:-${base_path}/src/kolla-ansible} # NOTE: This should not be in the Vagrant shared directory, as there are # issues with symlinks on Windows hosts. export KOLLA_VENV_PATH=~/kolla-venv + +function usage { + echo "usage: ${BASH_SOURCE[0]:-${(%):-%x}} [--environment ]" + return 1 +} + +if [ "$#" -ge 1 ]; then + if [ "$1" = "--environment" -a "$#" -eq 2 ]; then + kayobe_env="$2" + # Look for existing Kayobe environments + if [ -d "${KAYOBE_CONFIG_PATH}/environments" ]; then + if [ -d "${KAYOBE_CONFIG_PATH}/environments/${kayobe_env}" ]; then + export KAYOBE_ENVIRONMENT="${kayobe_env}" + echo "Using Kayobe environment ${KAYOBE_ENVIRONMENT}" + return 0 + else + echo "Unable to find Kayobe environment ${kayobe_env} in ${KAYOBE_CONFIG_PATH}/environments" + return 1 + fi + else + echo "Cannot find environments folder in ${KAYOBE_CONFIG_PATH}" + return 1 + fi + else + usage + fi +fi