Adding checks for installation prerequisites 41/70841/4
authorGeorg Kunz <georg.kunz@est.tech>
Fri, 21 Aug 2020 14:09:59 +0000 (16:09 +0200)
committerGeorg Kunz <georg.kunz@est.tech>
Tue, 8 Sep 2020 18:48:28 +0000 (18:48 +0000)
This patch adds a few preliminary checks for installation prerequisites,
currently covering software dependencies and runtime prerequisites. More
checks need to be added over time.

Signed-off-by: Georg Kunz <georg.kunz@est.tech>
Change-Id: Ic59b99873983511b74ebdce06d3aeb2ade318a76
Reviewed-on: https://gerrit.opnfv.org/gerrit/c/kuberef/+/70841
Tested-by: jenkins-ci <jenkins-opnfv-ci@opnfv.org>
Reviewed-by: Victor Morales <chipahuac@hotmail.com>
Reviewed-by: Rihab Banday <rihab.banday@ericsson.com>
deploy.sh
functions.sh

index 34f13e4..78e2978 100755 (executable)
--- a/deploy.sh
+++ b/deploy.sh
@@ -25,6 +25,11 @@ source "$CURRENTPATH/deploy.env"
 # shellcheck source=./functions.sh
 source "$CURRENTPATH/functions.sh"
 
+# ---------------------------------------------------------------------
+# check installation and runtime prerequisites
+# ---------------------------------------------------------------------
+check_prerequisites
+
 # Clean up leftovers
 clean_up
 
index 47c8536..f991dc8 100755 (executable)
@@ -20,6 +20,58 @@ clean_up() {
     sleep 5
 }
 
+
+check_prerequisites() {
+    echo "Info  : Check prerequisites"
+
+    #-------------------------------------------------------------------------------
+    # We shouldn't be running as root
+    #-------------------------------------------------------------------------------
+    if [[ "$(whoami)" == "root" ]]; then
+        echo "ERROR : This script must not be run as root!"
+        echo "        Please switch to a regular user before running the script."
+        exit 1
+    fi
+
+    #-------------------------------------------------------------------------------
+    # Check for passwordless sudo
+    #-------------------------------------------------------------------------------
+    if ! sudo -n "true"; then
+        echo "ERROR : passwordless sudo is needed for '$(id -nu)' user."
+        exit 1
+    fi
+
+    #-------------------------------------------------------------------------------
+    # Check if SSH key exists
+    #-------------------------------------------------------------------------------
+    if [[ ! -f "$HOME/.ssh/id_rsa" ]]; then
+        echo "ERROR : You must have SSH keypair in order to run this script!"
+        exit 1
+    fi
+
+    #-------------------------------------------------------------------------------
+    # We are using sudo so we need to make sure that env_reset is not present
+    #-------------------------------------------------------------------------------
+    sudo sed -i "s/^Defaults.*env_reset/#&/" /etc/sudoers
+
+    #-------------------------------------------------------------------------------
+    # Check if Ansible is installed
+    #-------------------------------------------------------------------------------
+    if ! command -v ansible &> /dev/null; then
+        echo "ERROR : Ansible not found. Please install."
+        exit 1
+    fi
+
+    #-------------------------------------------------------------------------------
+    # Check is libvirt is installed
+    #-------------------------------------------------------------------------------
+    if ! command -v virsh &> /dev/null; then
+        echo "ERROR : Libvirt not found. Please install."
+        exit 1
+    fi
+}
+
+
 # Create jumphost VM
 create_jump() {
 # Create VM image