Fix minor issues in the verify script 10/3010/15
authorZhe Huang <zhehuang@research.att.com>
Thu, 26 Mar 2020 21:35:19 +0000 (17:35 -0400)
committerZhe Huang <zhehuang@research.att.com>
Tue, 31 Mar 2020 14:21:58 +0000 (10:21 -0400)
Issue-ID: INT-109
Signed-off-by: Zhe Huang <zhehuang@research.att.com>
Change-Id: Icc74b875e3aa2851c21f65de6d66964a2b002431

bin/verify-ric-charts

index 4452a09..6cadf7c 100755 (executable)
 #   limitations under the License.
 #
 ##############################################################################
-
-# Installs well-known RIC charts then verifies specified helm chart
-# Requires chart tgz archives in /tmp
-HELMVER=$1
-OVERRIDEYAML=$2
+# Verifies RIC helm charts
+# Requires Linux with wget and tar.
+# This script should be executed inside the ric-plt/ric-dep bin directory only.
+set -eu
+echo "--> verify-ric-charts"
+
+
+# (Optional) provide HELMVERSION as first parameter. It selects the helm client version
+# (Optional) provide OVERRIDEYAML as the second parameter. It allows us to specify an override file to replace values used to render the helm charts
+if [[ "${1:-nope}" != "nope" ]]; then
+    HELMVERSION=$1
+else
+    HELMVERSION=2.12.3
+fi
+if [[ "${2:-nope}" != "nope" ]]; then
+    OVERRIDEYAML=$2
+fi
 
 ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
+HELM_COMMAND=helm
 
-# Set up helm
-HELMVERSION=${HELMVER:=2.12.3}
-if [ ! -e helm-v${HELMVERSION}-linux-amd64.tar.gz ]; then
-  wget https://storage.googleapis.com/kubernetes-helm/helm-v${HELMVERSION}-linux-amd64.tar.gz
+if ! $($HELM_COMMAND > /dev/null);then
+    echo "Download and install Helm"
+    if [ ! -e helm-v${HELMVERSION}-linux-amd64.tar.gz ]; then
+      wget -nv https://storage.googleapis.com/kubernetes-helm/helm-v${HELMVERSION}-linux-amd64.tar.gz
+    fi
+    tar -xvf ./helm-v${HELMVERSION}-linux-amd64.tar.gz
+    mv linux-amd64/helm ./
+    HELM_COMMAND=./helm
+    $HELM_COMMAND init -c
 fi
-
-tar -xvf ./helm-v${HELMVERSION}-linux-amd64.tar.gz
-mv linux-amd64/helm ./
-
-# set up ric common template
-./setup-ric-common-template
-
-
-
+# Set up ric common template
+# Download it/dep common template charts
+git clone --single-branch --branch master "https://gerrit.o-ran-sc.org/r/it/dep" ./dep
+
+# Start Helm local repo if there isn't one
+HELM_PID=$(pgrep  "$HELM_COMMAND")
+if [ ! -z "$HELM_PID" ]; then
+    echo "Stopping existing local Helm server."
+    kill -9 "$HELM_PID"
+fi
+if [ ! -d ./charts ]; then
+    mkdir ./charts
+fi
+echo "Starting local Helm server"
+nohup $HELM_COMMAND serve --repo-path charts >& /dev/null &
+# Package ric-common and serve it using Helm local repo
+$HELM_COMMAND package --save=false -d ./charts "$ROOT_DIR/dep/ric-common/Common-Template/helm/ric-common"
+$HELM_COMMAND package --save=false -d ./charts "$ROOT_DIR/dep/ric-common/Common-Template/helm/aux-common"
+$HELM_COMMAND repo index ./charts
+# Make sure that helm local repo is added
+$HELM_COMMAND repo remove local
+$HELM_COMMAND repo add local http://127.0.0.1:8879/charts
+# Remove it/dep charts
+rm -rf ./dep
 
 # Create array of helm charts
+echo "Finding all Helm charts"
 CHART_ARRAY=()
 while IFS= read -r -d $'\0'; do
     CHART_ARRAY+=("$REPLY")
-done < <(find $ROOT_DIR/../ -maxdepth 4 -name Chart.yaml -printf '%h\0')
+done < <(find "$ROOT_DIR/../" -maxdepth 4 -name Chart.yaml -printf '%h\0')
 
 echo "***************************************"
-
-
 for dir in "${CHART_ARRAY[@]}"
 do
-  
-    echo "Update chart depenedency"
-    ./helm dep up $dir 
+    echo "Running helm lint and verification on chart $dir"
+    echo "Update chart dependency"
+    $HELM_COMMAND dep up "$dir"
     # Lint clearly marks errors; e.g., [ERROR]
-    if [ -z $OVERRIDEYAML ]; then
-        ./helm lint $dir > /tmp/output 2>&1
+    echo "Performing Helm lint"
+    if [[ "${OVERRIDEYAML:-nope}" != "nope" ]]; then
+        $HELM_COMMAND lint -f "$OVERRIDEYAML" "$dir"> /tmp/output 2>&1
     else
-        ./helm lint -f $OVERRIDEYAML $dir> /tmp/output 2>&1
+        $HELM_COMMAND lint "$dir" > /tmp/output 2>&1
     fi
     echo "***************************************************************************************************************"
     cat /tmp/output 
-    
     egrep -q '^Error: [0-9]* chart\(s\) linted, [0-9]* chart\(s\) failed' /tmp/output && exit 1
     echo "***************************************************************************************************************"
-
-    if [ -z $OVERRIDEYAML ]; then
-        ./helm template $dir > /tmp/output 2>&1
+    echo "Rendering Helm charts locally"
+    if [[ "${OVERRIDEYAML:-nope}" != "nope" ]]; then
+       $HELM_COMMAND template -f "$OVERRIDEYAML" "$dir" > /tmp/output 2>&1
     else
-       ./helm template -f $OVERRIDEYAML $dir > /tmp/output 2>&1
+        $HELM_COMMAND template "$dir" > /tmp/output 2>&1
     fi
     echo "***************************************************************************************************************"
     cat /tmp/output 
-   sleep 1 
-    egrep -n '%!.\(.*=.*\)' /tmp/output && echo "Error: Type mismatch." && exit 1
+    grep -E -n '%!.\(.*=.*\)' /tmp/output && echo "Error: Type mismatch." && exit 1
     echo "***************************************************************************************************************"
-
 done
-#Error: 1 chart(s) linted, 1 chart(s) failed
-
-
-
+echo "--> verify-ric-charts ends"
 exit 0