xci: Add ability to pass command line options to xci-deploy.sh 75/62575/2
authorMarkos Chandras <mchandras@suse.de>
Wed, 19 Sep 2018 15:28:10 +0000 (16:28 +0100)
committerMarkos Chandras <mchandras@suse.de>
Wed, 19 Sep 2018 16:40:54 +0000 (17:40 +0100)
We now support multiple PDF files so instead of introducing another
env variable, we can simply pass this information as command line
arguments to xci-deploy.sh. We can extend the script to allow more
options line verbosity, scenario name, functest details etc so we
can get rid of multiple env variables.

Change-Id: I6c4a8d6e8b70e91746a659de923fee19019ed5e0
Signed-off-by: Markos Chandras <mchandras@suse.de>
xci/files/xci-lib.sh
xci/playbooks/dynamic_inventory.py
xci/xci-deploy.sh

index 064b9f6..2f360e4 100644 (file)
 # Avoid double sourcing the file
 [[ -n ${XCI_LIB_SOURCED:-} ]] && return 0 || export XCI_LIB_SOURCED=1
 
+function usage() {
+    echo "
+Usage: $(basename ${0}) [-i <idf>] [-p <pdf>]
+
+    -h: This message
+    -i: Installer Descriptor File (IDF). (Default ${XCI_PATH}/xci/var/idf.yml)
+    -p: Pod Descriptor File (PDF). (Default ${XCI_PATH}/xci/var/pdf.yml)
+    "
+    exit 0
+}
+
+function parse_cmdline_opts() {
+    IDF=${XCI_PATH}/xci/var/idf.yml
+    PDF=${XCI_PATH}/xci/var/pdf.yml
+
+    while getopts ":hi:p:" o; do
+        case "${o}" in
+            i) IDF="${OPTARG}" ;;
+            p) PDF="${OPTARG}" ;;
+            h) usage ;;
+            *) echo "ERROR: Invalid option '-${OPTARG}'"; usage ;;
+        esac
+    done
+
+    # Do all the exports
+    export PDF=$(realpath ${PDF})
+    export IDF=$(realpath ${IDF})
+}
+
 function bootstrap_xci_env() {
     # Declare our virtualenv
     export XCI_VENV=${XCI_PATH}/venv/
index 9a1624b..f6e9339 100755 (executable)
@@ -74,8 +74,8 @@ class XCIInventory(object):
         self.args = parser.parse_args()
 
     def read_pdf_idf(self):
-        pdf_file = os.path.dirname(os.path.realpath(__file__)) + "/../var/pdf.yml"
-        idf_file = os.path.dirname(os.path.realpath(__file__)) + "/../var/idf.yml"
+        pdf_file = os.environ['PDF']
+        idf_file = os.environ['IDF']
         nodes = []
         host_networks = {}
 
index c165415..d9c4196 100755 (executable)
@@ -49,6 +49,11 @@ for local_user_var in ${user_local_dev_vars[@]}; do
 done
 unset user_local_dev_vars local_user_var
 
+#
+# Parse command line options
+#
+parse_cmdline_opts $*
+
 #
 # Bootstrap environment for XCI Deployment
 #