Proper tracking of Charmed Install 30/12030/1
authorbeierlm <mark.beierl@canonical.com>
Wed, 13 Apr 2022 12:19:40 +0000 (08:19 -0400)
committerbeierlm <mark.beierl@canonical.com>
Tue, 10 May 2022 18:59:41 +0000 (14:59 -0400)
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 e61bbdd..4d84de4 100755 (executable)
@@ -24,6 +24,17 @@ MICROK8S_VERSION=1.23
 OSMCLIENT_VERSION=10.0
 IMAGES_OVERLAY_FILE=~/.osm/images-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
 
@@ -57,7 +68,8 @@ function check_arguments(){
 function install_snaps(){
     if [ ! -v KUBECFG ]; then
         KUBEGRP="microk8s"
-        sudo snap install microk8s --classic --channel=${MICROK8S_VERSION}/stable
+        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
@@ -69,13 +81,16 @@ function install_snaps(){
         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(){
@@ -307,7 +304,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
@@ -434,32 +431,73 @@ function add_local_k8scluster() {
 }
 
 function install_microstack() {
-    sudo snap install microstack --classic --beta
-    sudo microstack.init --auto
-    wget https://cloud-images.ubuntu.com/releases/16.04/release/ubuntu-16.04-server-cloudimg-amd64-disk1.img -P ~/.osm/
-    microstack.openstack image create \
-    --public \
-    --disk-format qcow2 \
-    --container-format bare \
-    --file ~/.osm/ubuntu-16.04-server-cloudimg-amd64-disk1.img \
-    ubuntu1604
-    ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
-    microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
-    export OSM_HOSTNAME=`juju status -m $MODEL_NAME --format json | jq -rc '.applications."nbi".address'`
-    osm vim-create --name microstack-site \
-    --user admin \
-    --password keystone \
-    --auth_url http://10.20.20.1:5000/v3 \
-    --tenant admin \
-    --account_type openstack \
-    --config='{security_groups: default,
-        keypair: microstack,
-        project_name: admin,
-        user_domain_name: default,
-        region_name: microstack,
-        insecure: True,
-        availability_zone: nova,
-    version: 3}'
+    sudo snap install microstack --beta --devmode
+
+    CHECK=$(microstack.openstack server list)
+    if [ $? -ne 0 ] ; then
+        if [[ $CHECK == *"not initialized"* ]]; then
+            echo "Setting MicroStack dashboard to listen to port 8080"
+            sudo snap set microstack config.network.ports.dashboard=8080
+            echo "Initializing MicroStack.  This can take several minutes"
+            sudo microstack.init --auto --control
+        fi
+    fi
+
+    sudo snap alias microstack.openstack openstack
+
+    echo "Updating default security group in MicroStack to allow all access"
+
+    for i in $(microstack.openstack security group list | awk '/default/{ print $2 }'); do
+        for PROTO in icmp tcp udp ; do
+            echo "  $PROTO ingress"
+            CHECK=$(microstack.openstack security group rule create $i --protocol $PROTO --remote-ip 0.0.0.0/0 2>&1)
+            if [ $? -ne 0 ] ; then
+                if [[ $CHECK != *"409"* ]]; then
+                    echo "Error creating ingress rule for $PROTO"
+                    echo $CHECK
+                fi
+            fi
+        done
+    done
+
+    microstack.openstack network show osm-ext &>/dev/null
+    if [ $? -ne 0 ]; then
+       echo "Creating osm-ext network with router to bridge to MicroStack external network"
+        microstack.openstack network create --enable --no-share osm-ext
+        microstack.openstack subnet create osm-ext-subnet --network osm-ext --dns-nameserver 8.8.8.8 \
+              --subnet-range 172.30.0.0/24
+        microstack.openstack router create external-router
+        microstack.openstack router add subnet external-router osm-ext-subnet
+        microstack.openstack router set --external-gateway external external-router
+    fi
+
+    microstack.openstack image list | grep ubuntu20.04 &> /dev/null
+    if [ $? -ne 0 ] ; then
+        echo "Fetching Ubuntu 20.04 image and upLoading to MicroStack"
+        wget -q -O- https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img \
+            | microstack.openstack image create --public --container-format=bare \
+             --disk-format=qcow2 ubuntu20.04 | grep status
+    fi
+
+    if [ ! -f ~/.ssh/microstack ]; then
+        ssh-keygen -t rsa -N "" -f ~/.ssh/microstack
+        microstack.openstack keypair create --public-key ~/.ssh/microstack.pub microstack
+    fi
+
+    echo "Creating VIM microstack-site in OSM"
+    . /var/snap/microstack/common/etc/microstack.rc
+
+    osm vim-create \
+        --name microstack-site \
+        --user "$OS_USERNAME" \
+        --password "$OS_PASSWORD" \
+        --auth_url "$OS_AUTH_URL" \
+        --tenant "$OS_USERNAME" \
+        --account_type openstack \
+        --config='{use_floating_ip: True,
+                   insecure: True,
+                   keypair: microstack,
+                   management_network_name: osm-ext}'
 }
 
 DEFAULT_IF=`ip route list match 0.0.0.0 | awk '{print $5}'`
@@ -483,14 +521,19 @@ 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
     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:"
@@ -504,5 +547,6 @@ else
     echo "echo \"export OSM_HOSTNAME=$OSM_HOSTNAME\" >> ~/.bashrc"
     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 3b0465f..d9f0995 100755 (executable)
@@ -1889,17 +1889,29 @@ done
 [ -n "$TO_REBUILD" ] && [ "$TO_REBUILD" != " NONE" ] && echo $TO_REBUILD | grep -q NONE && FATAL "Incompatible option: -m NONE cannot be used with other -m options"
 [ -n "$TO_REBUILD" ] && [ "$TO_REBUILD" == " PLA" ] && [ -z "$INSTALL_PLA" ] && FATAL "Incompatible option: -m PLA cannot be used without --pla option"
 
-if [ -n "$SHOWOPTS" ]; then
-    dump_vars
+# Uninstall if "--uninstall"
+if [ -n "$UNINSTALL" ]; then
+    if [ -n "$CHARMED" ]; then
+        ${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
+        ${OSM_DEVOPS}/installers/uninstall_osm.sh "$@" || \
+        FATAL_TRACK community_uninstall "uninstall_osm.sh failed"
+    fi
+    echo -e "\nDONE"
     exit 0
 fi
 
 if [ -n "$CHARMED" ]; then
-     if [ -n "$UNINSTALL" ]; then
-        ${OSM_DEVOPS}/installers/charmed_uninstall.sh -R $RELEASE -r $REPOSITORY -u $REPOSITORY_BASE -D /usr/share/osm-devops -t $DOCKER_TAG "$@"
-     else
-        ${OSM_DEVOPS}/installers/charmed_install.sh -R $RELEASE -r $REPOSITORY -u $REPOSITORY_BASE -D /usr/share/osm-devops -t $DOCKER_TAG "$@"
-     fi
+    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
 
      exit 0
 fi