Add: Prerequisites checker 77/20977/3
authorPeter Mikus <pmikus@cisco.com>
Wed, 31 Jul 2019 13:42:54 +0000 (13:42 +0000)
committerVratko Polak <vrpolak@cisco.com>
Wed, 31 Jul 2019 14:48:15 +0000 (14:48 +0000)
Change-Id: Ida54722ee5c73a0b3e0a8e22692795daf5bb09f3
Signed-off-by: Peter Mikus <pmikus@cisco.com>
resources/libraries/bash/entry/bootstrap_verify_perf.sh
resources/libraries/bash/entry/bootstrap_vpp_device.sh
resources/libraries/bash/entry/per_patch_device.sh
resources/libraries/bash/entry/per_patch_perf.sh
resources/libraries/bash/function/common.sh

index bf7fa35..2329beb 100644 (file)
@@ -33,6 +33,7 @@ source "${BASH_FUNCTION_DIR}/common.sh" || {
 source "${BASH_FUNCTION_DIR}/gather.sh" || die "Source failed."
 source "${BASH_FUNCTION_DIR}/ansible.sh" || die "Source failed."
 common_dirs || die
+check_prerequisites || die
 get_test_code "${1-}" || die
 get_test_tag_string || die
 select_topology || die
index 4ac73e7..ce887f4 100755 (executable)
@@ -32,6 +32,7 @@ source "${BASH_FUNCTION_DIR}/common.sh" || {
 }
 source "${BASH_FUNCTION_DIR}/gather.sh" || die "Source failed."
 common_dirs || die
+check_prerequisites || die
 get_test_code "${1-}" || die
 get_test_tag_string || die
 select_topology || die
index 6624047..65577c2 100644 (file)
@@ -37,6 +37,7 @@ source "${BASH_FUNCTION_DIR}/common.sh" || {
 }
 source "${BASH_FUNCTION_DIR}/per_patch.sh" || die "Source failed."
 common_dirs || die
+check_prerequisites || die
 set_perpatch_vpp_dir || die
 build_vpp_ubuntu_amd64 "CURRENT" || die
 set_aside_commit_build_artifacts || die
index ef75ea9..afe5f97 100644 (file)
@@ -40,6 +40,7 @@ source "${BASH_FUNCTION_DIR}/common.sh" || {
 }
 source "${BASH_FUNCTION_DIR}/per_patch.sh" || die "Source failed."
 common_dirs || die
+check_prerequisites || die
 set_perpatch_vpp_dir || die
 build_vpp_ubuntu_amd64 "CURRENT" || die
 set_aside_commit_build_artifacts || die
index f7a7a00..751d994 100644 (file)
@@ -167,6 +167,21 @@ function check_download_dir () {
 }
 
 
+function check_prerequisites () {
+
+    # Fail if prerequisites are not met.
+    #
+    # Functions called:
+    # - installed - Check if application is installed/present in system.
+    # - die - Print to stderr and exit.
+
+    set -exuo pipefail
+
+    if ! installed sshpass; then
+        die "Please install sshpass before continue!"
+    fi
+}
+
 function cleanup_topo () {
 
     # Variables read:
@@ -520,6 +535,24 @@ function get_test_tag_string () {
 }
 
 
+function installed () {
+
+    # Check if the given utility is installed. Fail if not installed.
+    #
+    # Duplicate of common.sh function, as this file is also used standalone.
+    #
+    # Arguments:
+    # - ${1} - Utility to check.
+    # Returns:
+    # - 0 - If command is installed.
+    # - 1 - If command is not installed.
+
+    set -exuo pipefail
+
+    command -v "${1}"
+}
+
+
 function reserve_and_cleanup_testbed () {
 
     # Reserve physical testbed, perform cleanup, register trap to unreserve.