X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=installers%2Finstall_from_source.sh;h=02d9e05a5d0fb4038fa1c96857abb29fb892da87;hb=c0a6596e29baceb1717a94d9f66f602ac8f355e9;hp=19ba1e6c24de8cecd9d4e7816be5e453c4823fda;hpb=55490d4d8625560a021a4f8e11a56c2127549a69;p=osm%2Fdevops.git diff --git a/installers/install_from_source.sh b/installers/install_from_source.sh index 19ba1e6c..02d9e05a 100755 --- a/installers/install_from_source.sh +++ b/installers/install_from_source.sh @@ -18,8 +18,15 @@ function usage(){ echo -e "Install OSM from source code" echo -e " OPTIONS" echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules" - echo -e " --develop: install OSM from source code using the master branch" + echo -e " -b : install OSM from source code using a specific branch (master, v1.0, ...)" + echo -e " -b master" + echo -e " -b v1.0" + echo -e " ..." + echo -e " --develop: (deprecated, use '-b master') install OSM from source code using the master branch" echo -e " --nat: install only NAT rules" +# 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 " -h / --help: print this help" } @@ -47,6 +54,78 @@ function nat(){ sudo $OSM_DEVOPS/installers/nat_osm } +#Update RO, SO and UI: +function update(){ + echo -e "\nUpdating components" + + echo -e " Updating RO" + CONTAINER="RO" + MDG="RO" + INSTALL_FOLDER="/opt/openmano" + 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." + lxc exec $CONTAINER -- service openmano stop + lxc exec $CONTAINER -- git -C /opt/openmano stash + lxc exec $CONTAINER -- git -C /opt/openmano pull --rebase + lxc exec $CONTAINER -- git -C /opt/openmano checkout $CHECKOUT_ID + lxc exec $CONTAINER -- git -C /opt/openmano stash pop + lxc exec $CONTAINER -- /opt/openmano/database_utils/migrate_mano_db.sh + lxc exec $CONTAINER -- service openmano start + fi + echo + + echo -e " Updating SO and UI" + CONTAINER="SO-ub" + MDG="SO" + INSTALL_FOLDER="" # To be filled in + 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." + # Instructions to be added + # lxc exec SO-ub -- ... + fi + echo +} + #Configure VCA, SO and RO with the initial configuration: # RO -> tenant:osm, logs to be sent to SO # VCA -> juju-password @@ -59,7 +138,8 @@ function configure(){ echo -e " Configuring RO" lxc exec RO -- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /opt/openmano/openmanod.cfg lxc exec RO -- service openmano restart - time=0; step=1; timelength=10; while [ $time -le $timelength ]; do sleep $step; echo -n "."; time=$((time+step)); done; echo + time=0; step=2; timelength=20; while [ $time -le $timelength ]; do sleep $step; echo -n "."; time=$((time+step)); done; echo + lxc exec RO -- openmano tenant-delete -f osm >/dev/null RO_TENANT_ID=`lxc exec RO -- openmano tenant-create osm |awk '{print $1}'` echo -e " Configuring VCA" @@ -69,8 +149,8 @@ function configure(){ echo -e " Configuring SO" sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP - lxc exec SO-ub -- nohup sudo -b -H /usr/rift/rift-shell -r -i /usr/rift -a /usr/rift/.artifacts -- ./demos/launchpad.py --use-xml-mode - time=0; step=20; timelength=200; while [ $time -le $timelength ]; do sleep $step; echo -n "."; time=$((time+step)); done; echo + lxc exec SO-ub -- nohup sudo -b -H /usr/rift/rift-shell -r -i /usr/rift -a /usr/rift/.artifacts -- ./demos/launchpad.py --use-xml-mode & + time=0; step=30; timelength=300; while [ $time -le $timelength ]; do sleep $step; echo -n "."; time=$((time+step)); done; echo curl -k --request POST \ --url https://$SO_CONTAINER_IP:8008/api/config/config-agent \ @@ -90,23 +170,45 @@ function configure(){ } +function install_lxd() { + lxd init --auto + lxd waitready + systemctl stop lxd-bridge + systemctl --system daemon-reload + systemctl enable lxd-bridge + systemctl start lxd-bridge +} + + UNINSTALL="" DEVELOP="" NAT="" +UPDATE="" RECONFIGURE="" TEST_INSTALLER="" -while getopts ":h-:" o; do +LXD="" +SHOWOPTS="" +COMMIT_ID="" +ASSUME_YES="" + +while getopts ":hy-:b:" o; do case "${o}" in h) usage && exit 0 ;; + b) + COMMIT_ID=${OPTARG} + ;; -) [ "${OPTARG}" == "help" ] && usage && exit 0 [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue [ "${OPTARG}" == "nat" ] && NAT="y" && continue + [ "${OPTARG}" == "update" ] && UPDATE="y" && continue [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE="y" && continue [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue + [ "${OPTARG}" == "lxd" ] && LXD="y" && continue + [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue echo -e "Invalid option: '--$OPTARG'\n" >&2 usage && exit 1 ;; @@ -114,12 +216,18 @@ while getopts ":h-:" o; do echo -e "Invalid option: '-$OPTARG'\n" >&2 usage && exit 1 ;; + y) + ASSUME_YES="y" + ;; *) usage && exit 1 ;; esac done +[ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID="master" +[ -n "$TEST_INSTALLER" ] && [ -z "$COMMIT_ID" ] && echo "Use -b option to specify the branch to use for the test (e.g.: v1.0)" && exit 0 + if [ -n "$TEST_INSTALLER" ]; then echo -e "\nUsing local devops repo for OSM installation" TEMPDIR="$(dirname $(realpath $(dirname $0)))" @@ -135,30 +243,60 @@ if [ -z "$TEST_INSTALLER" ]; then echo -e "\nCloning devops repo temporarily" git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR RC_CLONE=$? - DEVOPS_COMMITID="tags/v1.0.1" - git -C $TEMPDIR checkout $DEVOPS_COMMITID fi + +echo -e "\nGuessing the current stable release" +LATEST_STABLE_DEVOPS=`git -C $TEMPDIR tag -l v[0-9].* | tail -n1` +[ -z "$COMMIT_ID" ] && [ -z "$LATEST_STABLE_DEVOPS" ] && echo "Could not find the current latest stable release" && exit 0 + +if [ -n "$SHOWOPTS" ]; then + echo "DEVELOP=$DEVELOP" + echo "UNINSTALL=$UNINSTALL" + echo "NAT=$NAT" + echo "UPDATE=$UPDATE" + echo "RECONFIGURE=$RECONFIGURE" + echo "TEST_INSTALLER=$TEST_INSTALLER" + echo "LXD=$LXD" + echo "SHOWOPTS=$SHOWOPTS" + echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS" + echo "Commit to be installed (-b): $COMMIT_ID" + exit 0 +fi + OSM_DEVOPS=$TEMPDIR OSM_JENKINS="$TEMPDIR/jenkins" . $OSM_JENKINS/common/all_funcs -[ -n "$UNINSTALL" ] && uninstall && exit 0 -[ -n "$NAT" ] && nat && exit 0 -[ -n "$RECONFIGURE" ] && configure && exit 0 +[ -n "$UNINSTALL" ] && uninstall && echo -e "\nDONE" && exit 0 +[ -n "$NAT" ] && nat && echo -e "\nDONE" && exit 0 +[ -n "$UPDATE" ] && update && echo -e "\nDONE" && exit 0 +[ -n "$RECONFIGURE" ] && configure && echo -e "\nDONE" && exit 0 #Installation starts here +if [ -z "$ASSUME_YES" ]; then + read -e -p "The installation will take about 75-90 minutes. Continue (Y/n)?" USER_CONFIRMATION + [ -n "$USER_CONFIRMATION" ] && [ "$USER_CONFIRMATION" != "yes" ] && \ + [ "$USER_CONFIRMATION" != "y" ] && echo "Cancelled!" && exit 0 +fi + +echo -e "Checking required packages: lxd" +lxd --version &>/dev/null || echo -e "lxd not present, exiting " >&2 && exit 1 + +[ -z "$COMMIT_ID" ] && [ -n "$LATEST_STABLE_DEVOPS" ] && COMMIT_ID="tags/$LATEST_STABLE_DEVOPS" +echo -e "\n Installing OSM from refspec: $COMMIT_ID" + wget -q -O- https://osm-download.etsi.org/ftp/osm-1.0-one/README.txt &> /dev/null +[ -n "$LXD" ] && echo -e "\nConfiguring lxd" && install_lxd + echo -e "\nChecking required packages: wget, curl, tar" dpkg -l wget curl tar &>/dev/null || ! echo -e " One or several packages are not installed.\nInstalling required packages\n Root privileges are required" || sudo apt install -y wget curl tar echo -e "\nCreating the containers and building ..." -COMMIT_ID="tags/v1.0.1" -[ -n "$DEVELOP" ] && COMMIT_ID="master" -$OSM_DEVOPS/jenkins/host/start_build RO checkout $COMMIT_ID -$OSM_DEVOPS/jenkins/host/start_build VCA -$OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID -$OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID +$OSM_DEVOPS/jenkins/host/start_build RO --notest checkout $COMMIT_ID || FATAL "RO container build failed (refspec: '$COMMIT_ID')" +$OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA container build failed" +$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')" #Install iptables-persistent and configure NAT rules nat @@ -166,6 +304,5 @@ nat #Configure components configure +wget -q -O- https://osm-download.etsi.org/ftp/osm-1.0-one/README2.txt &> /dev/null echo -e "\nDONE" - -