From 7684184c8c34ae4e42a282bc649b89dc1d7fa795 Mon Sep 17 00:00:00 2001 From: tierno Date: Tue, 27 Sep 2016 09:18:28 +0000 Subject: [PATCH] new option --screen at basictest to force launching in a screen Signed-off-by: tierno --- scripts/install-openmano.sh | 16 ++++++++-- test/basictest.sh | 58 ++++++++++++++++--------------------- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/scripts/install-openmano.sh b/scripts/install-openmano.sh index 3849bd73..9ffcdabc 100755 --- a/scripts/install-openmano.sh +++ b/scripts/install-openmano.sh @@ -21,11 +21,9 @@ # contact with: nfvlabs@tid.es ## -#ONLY TESTED in Ubuntu 16.04 +#ONLY TESTED in Ubuntu 16.04 partially tested in Ubuntu 14.10 14.04 16.04, CentOS7 and RHEL7 #Get needed packages, source code and configure to run openmano #Ask for database user and password if not provided -# $1: database user -# $2: database password function usage(){ echo -e "usage: sudo $0 [OPTIONS]" @@ -39,6 +37,7 @@ function usage(){ echo -e " --develop: install last version for developers, and do not configure as a service" echo -e " --forcedb: reinstall mano_db DB, deleting previous database and creating a new one" echo -e " --noclone: assumes that openmano was cloned previously and that this script is run from the local repo" + echo -e " --no-install-packages: use this option to skip updating and installing the requires packages. This avoid wasting time if you are sure requires packages are present e.g. because of a previous installation" } function install_packages(){ @@ -77,6 +76,7 @@ QUIET_MODE="" DEVELOP="" FORCEDB="" NOCLONE="" +NO_PACKAGES="" while getopts ":u:p:hiq-:" o; do case "${o}" in u) @@ -99,6 +99,7 @@ while getopts ":u:p:hiq-:" o; do [ "${OPTARG}" == "forcedb" ] && FORCEDB="y" && continue [ "${OPTARG}" == "noclone" ] && NOCLONE="y" && continue [ "${OPTARG}" == "quiet" ] && export QUIET_MODE=yes && export DEBIAN_FRONTEND=noninteractive && continue + [ "${OPTARG}" == "no-install-packages" ] && export NO_PACKAGES=yes && continue echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2 exit 1 ;; @@ -166,6 +167,8 @@ fi +if [[ -z "$NO_PACKAGES" ]] +then echo ' ################################################################# ##### UPDATE REPOSITORIES ##### @@ -178,7 +181,10 @@ echo ' && sudo rpm -ivh epel-release-7-5.noarch.rpm && sudo yum install -y epel-release && rm -f epel-release-7-5.noarch.rpm [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && sudo yum repolist +fi +if [[ -z "$NO_PACKAGES" ]] +then echo ' ################################################################# ##### INSTALL REQUIRED PACKAGES ##### @@ -210,6 +216,7 @@ then firewall-cmd --permanent --zone=public --add-service=https && firewall-cmd --reload fi +fi #[[ -z "$NO_PACKAGES" ]] #check and ask for database user password. Must be done after database installation if [[ -n $QUIET_MODE ]] @@ -228,6 +235,8 @@ then done fi +if [[ -z "$NO_PACKAGES" ]] +then echo ' ################################################################# ##### INSTALL PYTHON PACKAGES ##### @@ -241,6 +250,7 @@ echo ' #install openstack client needed for using openstack as a VIM [ "$_DISTRO" == "Ubuntu" ] && install_packages "python-novaclient python-keystoneclient python-glanceclient python-neutronclient" [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_packages "python-devel" && easy_install python-novaclient python-keystoneclient python-glanceclient python-neutronclient #TODO revise if gcc python-pip is needed +fi #[[ -z "$NO_PACKAGES" ]] if [[ -z $NOCLONE ]]; then echo ' diff --git a/test/basictest.sh b/test/basictest.sh index 43267c3e..0d4fcea5 100755 --- a/test/basictest.sh +++ b/test/basictest.sh @@ -36,6 +36,7 @@ function usage(){ echo -e " OPTIONS:" echo -e " -f --force does not prompt for confirmation" echo -e " -h --help shows this help" + echo -e " --screen forces to run openmano (and openvim) service in a screen" echo -e " --insert-bashrc insert the created tenant,datacenter variables at" echo -e " ~/.bashrc to be available by openmano CLI" echo -e " --init-openvim if openvim runs locally, an init is called to clean openvim" @@ -48,55 +49,46 @@ function is_valid_uuid(){ } #detect if is called with a source to use the 'exit'/'return' command for exiting +DIRNAME=$(dirname $(readlink -f ${BASH_SOURCE[0]})) +DIRmano=$(dirname $DIRNAME) +DIRscript=${DIRmano}/scripts + [[ ${BASH_SOURCE[0]} != $0 ]] && _exit="return" || _exit="exit" +#process options +source ${DIRscript}/get-options.sh "force:f help:h insert-bashrc init-openvim screen" $* || $_exit 1 + +#help +[ -n "$option_help" ] && usage && $_exit 0 + #check correct arguments -force="" +force_param="" && [[ -n "$option_force" ]] && force_param=" -f" +insert_bashrc_param="" && [[ -n "$option_insert_bashrc" ]] && insert_bashrc_param=" --insert-bashrc" +screen_mano_param="" && [[ -n "$option_screen" ]] && screen_mano_param=" --screen-name=mano" +screen_vim_param="" && [[ -n "$option_screen" ]] && screen_vim_param=" --screen-name=vim" + action_list="" -insert_bashrc="" -init_openvim="" -while [[ $# -gt 0 ]] +for argument in $params do - argument="$1" - shift if [[ $argument == reset ]] || [[ $argument == create ]] || [[ $argument == delete ]] then action_list="$action_list $argument" continue - #short options - elif [[ ${argument:0:1} == "-" ]] && [[ ${argument:1:1} != "-" ]] && [[ ${#argument} -ge 2 ]] - then - index=0 - while index=$((index+1)) && [[ $index -lt ${#argument} ]] - do - [[ ${argument:$index:1} == h ]] && usage && $_exit 0 - [[ ${argument:$index:1} == f ]] && force="-f" && continue - echo "invalid option '${argument:$index:1}'? Type -h for help" >&2 && $_exit 1 - done - continue fi - #long options - [[ $argument == --help ]] && usage && $_exit 0 - [[ $argument == --force ]] && force="-f" && continue - [[ $argument == --insert-bashrc ]] && insert_bashrc="--insert-bashrc" && continue - [[ $argument == --init-openvim ]] && init_openvim="y" && continue echo "invalid argument '$argument'? Type -h for help" >&2 && $_exit 1 done -DIRNAME=$(dirname $(readlink -f ${BASH_SOURCE[0]})) -DIRmano=$(dirname $DIRNAME) -DIRscript=${DIRmano}/scripts export OPENMANO_HOST=localhost export OPENMANO_PORT=9090 -[[ -n "$insert_bashrc" ]] && echo -e "\nexport OPENMANO_HOST=localhost" >> ~/.bashrc -[[ -n "$insert_bashrc" ]] && echo -e "\nexport OPENMANO_PORT=9090" >> ~/.bashrc +[[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_HOST=localhost" >> ~/.bashrc +[[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_PORT=9090" >> ~/.bashrc #by default action should be reset and create [[ -z $action_list ]] && action_list="reset create delete" -[[ -z $init_openvim ]] || initopenvim $force $insert_bashrc || echo "WARNING openvim cannot be initialized. The rest of test can fail!" +[[ -z "$option_init_openvim" ]] || initopenvim${force_param}${insert_bashrc_param}${screen_vim_param} || echo "WARNING openvim cannot be initialized. The rest of test can fail!" #check openvim client variables are set #fail="" @@ -120,15 +112,15 @@ then #ask for confirmation if argument is not -f --force force_=y - [[ -z $force ]] && read -e -p "WARNING: reset openmano database, content will be lost!!! Continue(y/N) " force_ + [[ -z "$option_force" ]] && read -e -p "WARNING: reset openmano database, content will be lost!!! Continue(y/N) " force_ [[ $force_ != y ]] && [[ $force_ != yes ]] && echo "aborted!" && $_exit echo "Stopping openmano" - $DIRscript/service-openmano.sh mano stop + $DIRscript/service-openmano.sh mano stop${screen_mano_param} echo "Initializing openmano database" $DIRmano/database_utils/init_mano_db.sh -u mano -p manopw --createdb echo "Starting openmano" - $DIRscript/service-openmano.sh mano start + $DIRscript/service-openmano.sh mano start${screen_mano_param} echo elif [[ $action == "delete" ]] @@ -167,7 +159,7 @@ then #check a valid uuid is obtained ! is_valid_uuid $nfvotenant && echo "FAIL" && echo " $result" && $_exit 1 export OPENMANO_TENANT=$nfvotenant - [[ -n "$insert_bashrc" ]] && echo -e "\nexport OPENMANO_TENANT=$nfvotenant" >> ~/.bashrc + [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_TENANT=$nfvotenant" >> ~/.bashrc echo $nfvotenant printf "%-50s" "Creating datacenter 'TEST-dc' in openmano:" @@ -181,7 +173,7 @@ then ! is_valid_uuid $datacenter && echo "FAIL" && echo " $result" && $_exit 1 echo $datacenter export OPENMANO_DATACENTER=$datacenter - [[ -n "$insert_bashrc" ]] && echo -e "\nexport OPENMANO_DATACENTER=$datacenter" >> ~/.bashrc + [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENMANO_DATACENTER=$datacenter" >> ~/.bashrc printf "%-50s" "Attaching openmano tenant to the datacenter:" result=`${DIRmano}/openmano datacenter-attach TEST-dc` -- 2.17.1