update README to point to rel4
[osm/devops.git] / installers / install_osm.sh
index 054b2c2..b8f0da3 100755 (executable)
@@ -39,6 +39,7 @@ function usage(){
 #    echo -e "     --update:       update to the latest stable release or to the latest commit if using a specific branch"
     echo -e "     --showopts:     print chosen options and exit (only for debugging)"
     echo -e "     -y:             do not prompt for confirmation, assumes yes"
+    echo -e "     -D <devops path> use local devops installation path"
     echo -e "     -h / --help:    print this help"
 }
 
@@ -48,11 +49,13 @@ function uninstall(){
     if [ $RC_CLONE ] || [ -n "$TEST_INSTALLER" ]; then
         $OSM_DEVOPS/jenkins/host/clean_container RO
         $OSM_DEVOPS/jenkins/host/clean_container VCA
+        $OSM_DEVOPS/jenkins/host/clean_container MON
         $OSM_DEVOPS/jenkins/host/clean_container SO
         #$OSM_DEVOPS/jenkins/host/clean_container UI
     else
         lxc stop RO && lxc delete RO
         lxc stop VCA && lxc delete VCA
+        lxc stop MON && lxc delete MON
         lxc stop SO-ub && lxc delete SO-ub
     fi
     echo -e "\nDeleting imported lxd images if they exist"
@@ -147,6 +150,34 @@ function update(){
         # lxc exec SO-ub -- ...
     fi
     echo
+    echo -e "Updating MON Container"
+    CONTAINER="MON"
+    MDG="MON"
+    INSTALL_FOLDER="/root/MON"
+    echo -e "     Fetching the repo"
+    lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all
+    BRANCH=""
+    BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'`
+    [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'"
+    CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1`
+    CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD`
+    echo "         FROM: $CURRENT ($CURRENT_COMMIT_ID)"
+    # COMMIT_ID either was  previously set with -b option, or is an empty string
+    CHECKOUT_ID=$COMMIT_ID
+    [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS"
+    [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH"
+    if [[ $CHECKOUT_ID == "tags/"* ]]; then
+        REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID`
+    else
+        REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID`
+    fi
+    echo "         TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)"
+    if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then
+        echo "         Nothing to be done."
+    else
+        echo "         Update required."
+    fi
+    echo
 }
 
 function so_is_up() {
@@ -186,6 +217,15 @@ function vca_is_up() {
     FATAL "OSM Failed to startup. VCA failed to startup"
 }
 
+function mon_is_up() {
+    if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then
+            echo "MON is up and running"
+            return 0
+    fi
+
+    FATAL "OSM Failed to startup. MON failed to startup"
+}
+
 function ro_is_up() {
     if [ -n "$1" ]; then
         RO_IP=$1
@@ -219,7 +259,7 @@ function configure_RO(){
 
     lxc exec RO -- openmano tenant-delete -f osm >/dev/null
     lxc exec RO -- openmano tenant-create osm > /dev/null
-    lxc exec RO -- sed -i '/export OPENMANO_TENANT=osm/d' .bashrc 
+    lxc exec RO -- sed -i '/export OPENMANO_TENANT=osm/d' .bashrc
     lxc exec RO -- sed -i '$ i export OPENMANO_TENANT=osm' .bashrc
     lxc exec RO -- sh -c 'echo "export OPENMANO_TENANT=osm" >> .bashrc'
 }
@@ -235,6 +275,9 @@ function configure_SOUI(){
     JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'`
     RO_TENANT_ID=`lxc exec RO -- openmano tenant-list osm |awk '{print $1}'`
 
+    echo -e " Configuring MON"
+    #Information to be added about SO socket for logging
+
     echo -e "       Configuring SO"
     sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP
     sudo sed -i "$ i route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP" /etc/rc.local
@@ -304,7 +347,7 @@ function configure_SOUI(){
 
     lxc exec SO-ub -- tee /etc/network/interfaces.d/60-rift.cfg <<EOF
 auto lo:1
-iface lo:1 inet static 
+iface lo:1 inet static
         address  $DEFAULT_IP
         netmask 255.255.255.255
 EOF
@@ -413,6 +456,8 @@ function install_from_lxdimages(){
     ro_is_up && track RO
     launch_container_from_lxd VCA osm-vca
     vca_is_up && track VCA
+    launch_container_from_lxd MON osm-mon
+    mon_is_up && track MON
     launch_container_from_lxd SO osm-soui
     #so_is_up && track SOUI
     track SOUI
@@ -515,8 +560,9 @@ LXD_REPOSITORY_PATH=""
 NOCONFIGURE=""
 RELEASE_DAILY=""
 SESSION_ID=`date +%s`
+OSM_DEVOPS=
 
-while getopts ":hy-:b:r:k:u:R:l:p:" o; do
+while getopts ":hy-:b:r:k:u:R:l:p:D:" o; do
     case "${o}" in
         h)
             usage && exit 0
@@ -542,6 +588,9 @@ while getopts ":hy-:b:r:k:u:R:l:p:" o; do
         p)
             LXD_REPOSITORY_PATH="${OPTARG}"
             ;;
+        D)
+            OSM_DEVOPS="${OPTARG}"
+            ;;
         -)
             [ "${OPTARG}" == "help" ] && usage && exit 0
             [ "${OPTARG}" == "source" ] && INSTALL_FROM_SOURCE="y" && continue
@@ -586,13 +635,15 @@ fi
 # forcing source from master removed. Now only install from source when explicit
 # [ -n "$COMMIT_ID" ] && [ "$COMMIT_ID" == "master" ] && INSTALL_FROM_SOURCE="y"
 
-if [ -n "$TEST_INSTALLER" ]; then
-    echo -e "\nUsing local devops repo for OSM installation"
-    TEMPDIR="$(dirname $(realpath $(dirname $0)))"
-else
-    echo -e "\nCreating temporary dir for OSM installation"
-    TEMPDIR="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
-    trap 'rm -rf "$TEMPDIR"' EXIT
+if [ -z "$OSM_DEVOPS" ]; then
+    if [ -n "$TEST_INSTALLER" ]; then
+        echo -e "\nUsing local devops repo for OSM installation"
+        TEMPDIR="$(dirname $(realpath $(dirname $0)))"
+    else
+        echo -e "\nCreating temporary dir for OSM installation"
+        TEMPDIR="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
+        trap 'rm -rf "$TEMPDIR"' EXIT
+    fi
 fi
 
 need_packages="git jq"
@@ -604,27 +655,29 @@ for package in $need_packages; do
         || FATAL "failed to install $package"
 done
 
-if [ -z "$TEST_INSTALLER" ]; then
-    echo -e "\nCloning devops repo temporarily"
-    git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR
-    RC_CLONE=$?
-fi
+if [ -z "$OSM_DEVOPS" ]; then
+    if [ -z "$TEST_INSTALLER" ]; then
+        echo -e "\nCloning devops repo temporarily"
+        git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR
+        RC_CLONE=$?
+    fi
 
-echo -e "\nGuessing the current stable release"
-LATEST_STABLE_DEVOPS=`git -C $TEMPDIR tag -l v[0-9].* | sort -V | tail -n1`
-[ -z "$COMMIT_ID" ] && [ -z "$LATEST_STABLE_DEVOPS" ] && echo "Could not find the current latest stable release" && exit 0
-echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS"
-[ -z "$COMMIT_ID" ] && [ -n "$LATEST_STABLE_DEVOPS" ] && COMMIT_ID="tags/$LATEST_STABLE_DEVOPS"
-
-if [ -n "$RELEASE_DAILY" ]; then
-    echo "Using master/HEAD devops"
-    git -C $TEMPDIR checkout master
-elif [ -z "$TEST_INSTALLER" ]; then
-    git -C $TEMPDIR checkout tags/$LATEST_STABLE_DEVOPS
+    echo -e "\nGuessing the current stable release"
+    LATEST_STABLE_DEVOPS=`git -C $TEMPDIR tag -l v[0-9].* | sort -V | tail -n1`
+    [ -z "$COMMIT_ID" ] && [ -z "$LATEST_STABLE_DEVOPS" ] && echo "Could not find the current latest stable release" && exit 0
+    echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS"
+    [ -z "$COMMIT_ID" ] && [ -n "$LATEST_STABLE_DEVOPS" ] && COMMIT_ID="tags/$LATEST_STABLE_DEVOPS"
+
+    if [ -n "$RELEASE_DAILY" ]; then
+        echo "Using master/HEAD devops"
+        git -C $TEMPDIR checkout master
+    elif [ -z "$TEST_INSTALLER" ]; then
+        git -C $TEMPDIR checkout tags/$LATEST_STABLE_DEVOPS
+    fi
+    OSM_DEVOPS=$TEMPDIR
 fi
 
-OSM_DEVOPS=$TEMPDIR
-OSM_JENKINS="$TEMPDIR/jenkins"
+OSM_JENKINS="$OSM_DEVOPS/jenkins"
 . $OSM_JENKINS/common/all_funcs
 
 [ -n "$UNINSTALL" ] && uninstall && echo -e "\nDONE" && exit 0
@@ -634,7 +687,7 @@ OSM_JENKINS="$TEMPDIR/jenkins"
 
 #Installation starts here
 echo -e "\nInstalling OSM from refspec: $COMMIT_ID"
-if [ -n "$INSTALL_FROM_SOURCE" ] && [ -z "$ASSUME_YES" ]; then 
+if [ -n "$INSTALL_FROM_SOURCE" ] && [ -z "$ASSUME_YES" ]; then
     ! ask_user "The installation will take about 75-90 minutes. Continue (Y/n)? " y && echo "Cancelled!" && exit 1
 fi
 
@@ -645,7 +698,7 @@ echo -e "Checking required packages: lxd"
 lxd --version &>/dev/null || FATAL "lxd not present, exiting."
 [ -n "$INSTALL_LXD" ] && echo -e "\nInstalling and configuring lxd" && install_lxd
 
-wget -q -O- https://osm-download.etsi.org/ftp/osm-3.0-three/README.txt &> /dev/null
+wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README.txt &> /dev/null
 track start
 
 # use local devops for containers
@@ -656,6 +709,8 @@ if [ -n "$INSTALL_FROM_SOURCE" ]; then #install from source
     ro_is_up && track RO
     $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA container build failed"
     vca_is_up && track VCA
+    $OSM_DEVOPS/jenkins/host/start_build MON || FATAL "MON install failed"
+    mon_is_up && track MON
     $OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID || FATAL "SO container build failed (refspec: '$COMMIT_ID')"
     $OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID || FATAL "UI container build failed (refspec: '$COMMIT_ID')"
     #so_is_up && track SOUI
@@ -669,6 +724,8 @@ else #install from binaries
     ro_is_up && track RO
     $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA install failed"
     vca_is_up && track VCA
+    $OSM_DEVOPS/jenkins/host/install MON || FATAL "MON build failed"
+    mon_is_up && track MON
     $OSM_DEVOPS/jenkins/host/install SO $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "SO install failed"
     $OSM_DEVOPS/jenkins/host/install UI $REPOSITORY $RELEASE $REPOSITORY_KEY $REPOSITORY_BASE || FATAL "UI install failed"
     #so_is_up && track SOUI
@@ -690,7 +747,7 @@ if [ -n "$INSTALL_VIMEMU" ]; then
     install_vimemu
 fi
 
-wget -q -O- https://osm-download.etsi.org/ftp/osm-3.0-three/README2.txt &> /dev/null
+wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null
 track end
 echo -e "\nDONE"