Proper tracking of Charmed Install 81/11881/7
authorbeierlm <mark.beierl@canonical.com>
Wed, 13 Apr 2022 12:19:40 +0000 (08:19 -0400)
committerbeierlm <mark.beierl@canonical.com>
Thu, 5 May 2022 17:46:33 +0000 (19:46 +0200)
Adds installation ID to the charmed path, as well as tracking installation
completion.

Change-Id: Ieffce4d402d6d865a8acb8d8a0c213bee9355199
Signed-off-by: beierlm <mark.beierl@canonical.com>
installers/charmed_install.sh
installers/charmed_uninstall.sh
installers/full_install_osm.sh

index bdf043e..a1e5001 100755 (executable)
@@ -25,6 +25,17 @@ OSMCLIENT_VERSION=latest
 IMAGES_OVERLAY_FILE=~/.osm/images-overlay.yaml
 PASSWORD_OVERLAY_FILE=~/.osm/password-overlay.yaml
 PATH=/snap/bin:${PATH}
+OSM_DEVOPS="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. &> /dev/null && pwd )"
+if [ -f ${OSM_DEVOPS}/common/all_funcs ] ; then
+    source ${OSM_DEVOPS}/common/all_funcs
+else
+    function track(){
+        true
+    }
+    function FATAL_TRACK(){
+        exit 1
+    }
+fi
 
 MODEL_NAME=osm
 
@@ -56,26 +67,30 @@ function check_arguments(){
 
 function install_snaps(){
     if [ ! -v KUBECFG ]; then
-        sudo snap install microk8s --classic --channel=${MICROK8S_VERSION}/stable
+        KUBEGRP="microk8s"
+        sudo snap install microk8s --classic --channel=${MICROK8S_VERSION}/stable ||
+          FATAL_TRACK k8scluster "snap install microk8s ${MICROK8S_VERSION}/stable failed"
+        sudo usermod -a -G microk8s `whoami`
         sudo cat /var/snap/microk8s/current/args/kube-apiserver | grep advertise-address || (
                 echo "--advertise-address $DEFAULT_IP" | sudo tee -a /var/snap/microk8s/current/args/kube-apiserver
-                microk8s.stop
-                microk8s.start
+                sg ${KUBEGRP} -c microk8s.stop
+                sg ${KUBEGRP} -c microk8s.start
             )
-        sudo usermod -a -G microk8s `whoami`
         mkdir -p ~/.kube
         sudo chown -f -R `whoami` ~/.kube
-        KUBEGRP="microk8s"
         sg ${KUBEGRP} -c "microk8s status --wait-ready"
         KUBECONFIG=~/.osm/microk8s-config.yaml
         sg ${KUBEGRP} -c "microk8s config" | tee ${KUBECONFIG}
+        track k8scluster k8scluster_ok
     else
         KUBECTL="kubectl"
         sudo snap install kubectl --classic
         export KUBECONFIG=${KUBECFG}
         KUBEGRP=$(id -g -n)
     fi
-    sudo snap install juju --classic --channel=$JUJU_VERSION/stable
+    sudo snap install juju --classic --channel=$JUJU_VERSION/stable ||
+    FATAL_TRACK juju "snap install juju ${JUJU_VERSION}/stable failed"
+    track juju juju_ok
 }
 
 function bootstrap_k8s_lxd(){
@@ -94,7 +109,7 @@ using this command:
 
 Please retry the installation once this conflict has been resolved.
 EOF
-            exit 1
+            FATAL_TRACK bootstrap_k8s "VCA already present"
         fi
     else
         CONTROLLER_PRESENT=$(juju controllers 2>/dev/null| grep ${CONTROLLER_NAME} | wc -l)
@@ -105,7 +120,7 @@ that exists, or remove the --vca ${CONTROLLER_NAME} option.
 
 Please retry the installation with one of the solutions applied.
 EOF
-            exit 1
+            FATAL_TRACK bootstrap_k8s "Requested VCA not present"
         fi
     fi
 
@@ -126,7 +141,7 @@ EOF
             if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
                 echo "Microk8s storage failed to enable"
                 sg ${KUBEGRP} -c "microk8s.status"
-                exit 1
+                FATAL_TRACK bootstrap_k8s "Microk8s storage failed to enable"
             fi
             storage_status=`sg ${KUBEGRP} -c "microk8s.status -a storage"`
             if [[ $storage_status == "enabled" ]]; then
@@ -140,11 +155,12 @@ EOF
             "juju bootstrap microk8s $CONTROLLER_NAME --config controller-service-type=loadbalancer --agent-version=$JUJU_AGENT_VERSION" \
             && K8S_CLOUD_NAME=microk8s
     fi
+    track bootstrap_k8s bootstrap_k8s_ok
 
     if [ -v LXD_CLOUD ]; then
         if [ ! -v LXD_CREDENTIALS ]; then
             echo "The installer needs the LXD server certificate if the LXD is external"
-            exit 1
+            FATAL_TRACK bootstrap_lxd "No LXD certificate supplied"
         fi
     else
         LXDENDPOINT=$DEFAULT_IP
@@ -197,26 +213,7 @@ EOF
     juju add-credential -c $CONTROLLER_NAME lxd-cloud -f $LXD_CREDENTIALS
     sg lxd -c "lxd waitready"
     juju controller-config features=[k8s-operators]
-}
-
-function wait_for_port(){
-    SERVICE=$1
-    INDEX=$2
-    TIME_TO_WAIT=30
-    start_time="$(date -u +%s)"
-    while true
-    do
-        now="$(date -u +%s)"
-        if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
-            echo "Failed to expose external ${SERVICE} interface port"
-            exit 1
-        fi
-
-        if [ $(sg ${KUBEGRP} -c "${KUBECTL} get ingresses.networking -n osm -o json | jq -r '.items[$INDEX].metadata.name'") == ${SERVICE} ] ; then
-            break
-        fi
-        sleep 1
-    done
+    track bootstrap_lxd bootstrap_lxd_ok
 }
 
 function deploy_charmed_osm(){
@@ -311,7 +308,7 @@ function check_osm_deployed() {
         now="$(date -u +%s)"
         if [[ $(( now - start_time )) -gt $TIME_TO_WAIT ]];then
             echo "Timed out waiting for OSM services to become ready"
-            exit 1
+            FATAL_TRACK deploy_osm "Timed out waiting for services to become ready"
         fi
         sleep 10
     done
@@ -466,7 +463,6 @@ function add_local_k8scluster() {
 }
 
 function install_microstack() {
-
     sudo snap install microstack --beta --devmode
 
     CHECK=$(microstack.openstack server list)
@@ -557,15 +553,20 @@ if [ -v ONLY_VCA ]; then
 
     echo "Use the following command to register the installed VCA to your OSM:"
     echo -e "  osm vca-add --endpoints $vca_host:$vca_port \\\n         --user $vca_user \\\n         --secret $vca_secret \\\n         --cacert $vca_cacert \\\n         --lxd-cloud lxd-cloud \\\n         --lxd-credentials lxd-cloud \\\n         --k8s-cloud microk8s \\\n         --k8s-credentials microk8s\\\n         $hostname-vca"
+    track deploy_osm deploy_vca_only_ok
 else
     deploy_charmed_osm
+    track deploy_osm deploy_osm_services_k8s_ok
     install_osmclient
+    track osmclient osmclient_ok
     export OSM_HOSTNAME=$(juju config -m $MODEL_NAME nbi site_url | sed "s/http.*\?:\/\///"):443
     export OSM_PASSWORD=$keystone_admin_password
     sleep 10
     add_local_k8scluster
+    track final_ops add_local_k8scluster_ok
     if [ -v MICROSTACK ]; then
         install_microstack
+        track final_ops install_microstack_ok
     fi
 
     echo "Your installation is now complete, follow these steps for configuring the osmclient:"
@@ -583,5 +584,6 @@ else
     echo "3. Login OSM GUI by using admin password: $OSM_PASSWORD"
     echo
     echo "DONE"
+    track end
 fi
 
index 20ca7b6..09305d2 100755 (executable)
@@ -14,7 +14,7 @@
 #
 
 
-juju destroy-model osm --destroy-storage -y --force
+juju destroy-model osm --destroy-storage -y --force --no-wait
 sudo snap unalias osm
 sudo snap remove osmclient
 CONTROLLER_NAME="osm-vca"
index 3084207..b7864d1 100755 (executable)
@@ -1120,7 +1120,6 @@ source $OSM_DEVOPS/common/all_funcs
 # Uninstall if "--uninstall"
 if [ -n "$UNINSTALL" ]; then
     if [ -n "$CHARMED" ]; then
-        track start release $RELEASE none none docker_tag $OSM_DOCKER_TAG none none installation_type $OSM_INSTALLATION_TYPE none none
         ${OSM_DEVOPS}/installers/charmed_uninstall.sh -R $RELEASE -r $REPOSITORY -u $REPOSITORY_BASE -D $OSM_DEVOPS -t $DOCKER_TAG "$@" || \
         FATAL_TRACK charmed_uninstall "charmed_uninstall.sh failed"
     else
@@ -1133,8 +1132,12 @@ fi
 
 # Charmed installation
 if [ -n "$CHARMED" ]; then
-    ${OSM_DEVOPS}/installers/charmed_install.sh -R $RELEASE -r $REPOSITORY -u $REPOSITORY_BASE -D $OSM_DEVOPS -t $DOCKER_TAG "$@" || \
+    export OSM_TRACK_INSTALLATION_ID="$(date +%s)-$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16)"
+    track start release $RELEASE none none docker_tag $OSM_DOCKER_TAG none none installation_type $OSM_INSTALLATION_TYPE none none
+    ${OSM_DEVOPS}/installers/charmed_install.sh --tag $OSM_DOCKER_TAG "$@" || \
     FATAL_TRACK charmed_install "charmed_install.sh failed"
+    wget -q -O- https://osm-download.etsi.org/ftp/osm-11.0-eleven/README2.txt &> /dev/null
+    track end installation_type $OSM_INSTALLATION_TYPE
     echo -e "\nDONE"
     exit 0
 fi