From f8c3ce569b2b7fe824a15cf4e3d6c6876d9a0a5d Mon Sep 17 00:00:00 2001 From: beierlm Date: Wed, 13 Apr 2022 08:19:40 -0400 Subject: [PATCH] Proper tracking of Charmed Install Adds installation ID to the charmed path, as well as tracking installation completion. Change-Id: Ieffce4d402d6d865a8acb8d8a0c213bee9355199 Signed-off-by: beierlm --- installers/charmed_install.sh | 150 +++++++++++++++++++++----------- installers/charmed_uninstall.sh | 2 +- installers/full_install_osm.sh | 7 +- 3 files changed, 103 insertions(+), 56 deletions(-) diff --git a/installers/charmed_install.sh b/installers/charmed_install.sh index 0c6928a9..4cc1cfb8 100755 --- a/installers/charmed_install.sh +++ b/installers/charmed_install.sh @@ -24,6 +24,17 @@ MICROK8S_VERSION=1.23 OSMCLIENT_VERSION=11.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 @@ -56,7 +67,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 @@ -68,13 +80,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(){ @@ -93,7 +108,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) @@ -104,7 +119,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 @@ -125,7 +140,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 @@ -139,11 +154,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 @@ -196,26 +212,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 diff --git a/installers/charmed_uninstall.sh b/installers/charmed_uninstall.sh index 20ca7b6e..09305d2a 100755 --- a/installers/charmed_uninstall.sh +++ b/installers/charmed_uninstall.sh @@ -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" diff --git a/installers/full_install_osm.sh b/installers/full_install_osm.sh index 3fc3a15d..80c613be 100755 --- a/installers/full_install_osm.sh +++ b/installers/full_install_osm.sh @@ -1118,7 +1118,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 @@ -1131,8 +1130,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 -- 2.25.1