From: tierno Date: Mon, 8 May 2017 13:45:32 +0000 (+0200) Subject: fix issues at installation scripts. Change at initopenvim X-Git-Tag: v2.0.1~12 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=24ca7a8ae3b5f5c235a244c77163c71d1990b94f;p=osm%2Fopenvim.git fix issues at installation scripts. Change at initopenvim Change-Id: I9837ada6b892fbcaa58a64bd1601593064b16b57 Signed-off-by: tierno --- diff --git a/database_utils/install-db-server.sh b/database_utils/install-db-server.sh index 7f5c9eb..c3a0248 100755 --- a/database_utils/install-db-server.sh +++ b/database_utils/install-db-server.sh @@ -156,8 +156,8 @@ echo ' function db_exists(){ # (db_name, credential_file) # check credentials mysqlshow --defaults-extra-file="$2" >/dev/null || exit 1 - RESULT=`mysqlshow --defaults-extra-file="$2" | grep -v Wildcard | grep -w $1` - if [ "$RESULT" == "$1" ]; then + if mysqlshow --defaults-extra-file="$2" | grep -v Wildcard | grep -w -q $1 + then # echo " DB $1 exists" return 0 fi @@ -231,6 +231,12 @@ fi # if not assuming ubuntu type [ -f /etc/redhat-release ] || _DISTRO=$(lsb_release -is 2>/dev/null) +if [[ -z "$NO_PACKAGES" ]] +then + [ "$USER" != "root" ] && echo "Needed root privileges" >&2 && exit 1 + _install_mysql_package || exit 1 +fi + # Creating temporary file for MYSQL installation and initialization" TEMPFILE="$(mktemp -q --tmpdir "installdb.XXXXXX")" trap 'rm -f "$TEMPFILE"' EXIT @@ -262,12 +268,6 @@ then exit fi -if [[ -z "$NO_PACKAGES" ]] -then - [ "$USER" != "root" ] && echo "Needed root privileges" >&2 && exit 1 - _install_mysql_package || exit 1 -fi - # Create or update database if db_exists $DB_NAME $TEMPFILE ; then if [[ -n $FORCEDB ]] ; then diff --git a/osm_openvim/osm-openvim.service b/osm_openvim/osm-openvim.service index 4431c6b..b6e08d5 100644 --- a/osm_openvim/osm-openvim.service +++ b/osm_openvim/osm-openvim.service @@ -2,8 +2,7 @@ Description=openvim server [Service] -User=${USER_OWNER} -ExecStart=openvimd -c /etc/osm/openvimd.cfg --log-file=/var/log/osm/openvim.log +ExecStart=/usr/bin/openvimd -c /etc/osm/openvimd.cfg --log-file=/var/log/osm/openvim.log Restart=always [Install] diff --git a/scripts/initopenvim b/scripts/initopenvim new file mode 100755 index 0000000..b6c5de6 --- /dev/null +++ b/scripts/initopenvim @@ -0,0 +1,240 @@ +#!/bin/bash + +## +# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U. +# This file is part of openvim +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# For those usages not covered by the Apache License, Version 2.0 please +# contact with: nfvlabs@tid.es +## + +#This script can be used as a basic test of openvim +#stopping on an error +#WARNING: It destroy the database content + +DIRNAME=$(readlink -f ${BASH_SOURCE[0]}) +DIRNAME=$(dirname $DIRNAME ) + +function usage(){ + echo -e "usage: ${BASH_SOURCE[0]} [OPTIONS] \n Deletes openvim content and add fake hosts, networks" + echo -e " is a list of the following items (by default 'reset create')" + echo -e " reset reset the openvim database content" + echo -e " create creates fake hosts and networks" + echo -e " delete delete created items" + echo -e " delete-all delete vms. flavors, images, ..." + echo -e " OPTIONS:" + echo -e " -f --force : does not prompt for confirmation" + echo -e " -d --delete : same to action delete-all" + echo -e " -p --port PORT : port to start openvim service" + echo -e " -P --admin-port PORT : administrator port to start openvim service" + echo -e " --screen-name NAME : screen name to launch openvim (default vim)" + echo -e " --dbname NAME : database name to use (default vim_db)" + echo -e " --insert-bashrc insert the created tenant variables at" + echo -e " ~/.bashrc to be available by openvim CLI" + echo -e " -h --help : shows this help" +} + +function is_valid_uuid(){ + echo "$1" | grep -q -E '^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$' && return 0 + return 1 +} + + +#detect if is called with a source to use the 'exit'/'return' command for exiting +[[ ${BASH_SOURCE[0]} != $0 ]] && _exit="return" || _exit="exit" + + +#process options +source ${DIRNAME}/get-options.sh \ + "force:f delete:d delete-all port:p= admin-port:P= screen-name= help:h dbname= insert-bashrc" $* || $_exit 1 + +#check correct arguments +action_list="" +for param in $params +do + if [[ "$param" == reset ]] || [[ "$param" == create ]] || [[ "$param" == delete ]] || [[ "$param" == delete-all ]] + then + action_list="$action_list $param" + continue + else + echo "invalid argument '$param'? Type -h for help" >&2 && $_exit 1 + fi +done + +#help +[[ -n "$option_help" ]] && usage && $_exit 0 + +#check numeric values for port +[[ -n "$option_port" ]] && ( [[ "$option_port" -lt 1 ]] || [[ "$option_port" -gt 65535 ]] ) && + echo "Option '-p' or '--port' requires a valid numeric argument" >&2 && $_exit 1 +[[ -n "$option_admin_port" ]] && ( [[ "$option_admin_port" -lt 1 ]] || [[ "$option_admin_port" -gt 65535 ]] ) && + echo "Option '-P' or '--admin-port' requieres a valid numeric argument" >&2 && $_exit 1 + +[[ -n "$option_screen_name" ]] && screen_name="$option_screen_name" && screen_name_param=" --screen-name $screen_name" +[[ -z "$option_screen_name" ]] && screen_name=vim && screen_name_param="" #default value + +[[ -n "$option_delete" ]] && action_list="delete-all $action_list" + +openvim_param=" --" +[[ -n "$option_port" ]] && openvim_param="$openvim_param -p $option_port" +[[ -n "$option_admin_port" ]] && openvim_param="$openvim_param -P $option_admin_port" +[[ -n "$option_dbname" ]] && openvim_param="$openvim_param --dbname $option_dbname" +[[ $openvim_param = " --" ]] && openvim_param="" +db_name=vim_db #default value +[[ -n "$option_dbname" ]] && db_name="$option_dbname" + +DIRNAME=$(dirname $(readlink -f ${BASH_SOURCE[0]})) +DIRvim=$(dirname $DIRNAME) +export OPENVIM_HOST=localhost +[[ -n "$option_port" ]] && export OPENVIM_PORT=$option_port +[[ -n "$option_admin_port" ]] && export OPENVIM_ADMIN_PORT=$option_admin_port + +[[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENVIM_HOST=localhost" >> ~/.bashrc +[[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENVIM_PORT=9080" >> ~/.bashrc +#by default action should be reset and create +[[ -z "$action_list" ]] && action_list="reset create" + + +for action in $action_list +do +if [[ $action == "reset" ]] +then + #ask for confirmation if argument is not -f --force + force_="y" + [[ -z "$option_force" ]] && read -e -p "WARNING: openvim database content will be lost!!! Continue(y/N)" force_ + [[ $force_ != y ]] && [[ $force_ != yes ]] && echo "aborted!" && $_exit + echo "deleting deployed vm" + ${DIRvim}/openvim vm-delete -f | grep -q deleted && sleep 10 #give some time to get virtual machines deleted + echo "Stopping openvim${screen_name_param}${openvim_param}" + $DIRNAME/service-openvim stop${screen_name_param}${openvim_param} + echo "Initializing databases $db_name" + $DIRvim/database_utils/init_vim_db.sh -u vim -p vimpw -d $db_name + echo "Starting openvim${screen_name_param}${openvim_param}" + $DIRNAME/service-openvim start${screen_name_param}${openvim_param} + +elif [[ $action == delete-all ]] +then + for t in `${DIRvim}/openvim tenant-list | + awk '/^ *[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12} +/{printf("%s:%s",$1,$2)}'` + do + t_id=${t%%:*} + t_name=${t#*:} + [[ -z $t_id ]] && continue + export OPENVIM_TENANT=${t_id} + for what in vm image flavor port net + do + items=`${DIRvim}/openvim $what-list | awk '/^ *[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12} +/{print $1}'` + if [[ -n $items ]] + then + [[ $option_force == "-" ]] && echo deleting openvim ${what}s from tenant ${t_name} + [[ $option_force != "-" ]] && read -e -p "Delete openvim ${what}s from tenant ${t_name}?(y/N) " force_ + [[ $force_ != y ]] && [[ $force_ != yes ]] && echo "aborted!" && $_exit + for item in $items + do + echo -n "$item " + ${DIRvim}/openvim $what-delete -f $item || ! echo "fail" >&2 || $_exit 1 + done + fi + done + ${DIRvim}/openvim tenant-delete -f $t_id || ! echo "fail" >&2 || $_exit 1 + for what in host + do + items=`${DIRvim}/openvim $what-list | awk '/^ *[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12} +/{print $1}'` + if [[ -n $items ]] + then + [[ $option_force == "-" ]] && echo deleting openvim ${what}s + [[ $option_force != "-" ]] && read -e -p "Delete openvim ${what}s?(y/N) " force_ + [[ $force_ != y ]] && [[ $force_ != yes ]] && echo "aborted!" && $_exit + for item in $items + do + echo -n "$item " + ${DIRvim}/openvim $what-delete -f $item || ! echo "fail" >&2 || $_exit 1 + done + fi + done + + done +elif [[ $action == "delete" ]] +then + ${DIRvim}/openvim net-delete -f mgmt || echo "fail" + # ${DIRvim}/openvim net-delete -f default || echo "fail" + # ${DIRvim}/openvim net-delete -f macvtap:em1 || echo "fail" + # ${DIRvim}/openvim net-delete -f shared_bridge_net || echo "fail" + # ${DIRvim}/openvim net-delete -f data_net || echo "fail" + ${DIRvim}/openvim host-remove -f fake-host-0 || echo "fail" + ${DIRvim}/openvim host-remove -f fake-host-1 || echo "fail" + ${DIRvim}/openvim host-remove -f fake-host-2 || echo "fail" + ${DIRvim}/openvim host-remove -f fake-host-3 || echo "fail" + ${DIRvim}/openvim image-delete -f cirros034 || echo "fail" + result=`openvim tenant-list osm` + vimtenant=`echo $result |gawk '{print $1}'` + #check a valid uuid is obtained + is_valid_uuid $vimtenant || ! echo "Tenant 'osm' not found. Already delete?" >&2 || $_exit 1 + export OPENVIM_TENANT=$vimtenant + ${DIRvim}/openvim tenant-delete -f osm || echo "fail" + echo + +elif [[ $action == "create" ]] +then + echo "Adding example hosts" + ${DIRvim}/openvim host-add $DIRvim/test/hosts/host-example0.yaml || ! echo "fail" >&2 || $_exit 1 + ${DIRvim}/openvim host-add $DIRvim/test/hosts/host-example1.yaml || ! echo "fail" >&2 || $_exit 1 + ${DIRvim}/openvim host-add $DIRvim/test/hosts/host-example2.yaml || ! echo "fail" >&2 || $_exit 1 + ${DIRvim}/openvim host-add $DIRvim/test/hosts/host-example3.yaml || ! echo "fail" >&2 || $_exit 1 + echo "Adding example nets" + # ${DIRvim}/openvim net-create $DIRvim/test/networks/net-example0.yaml || ! echo "fail" >&2 || $_exit 1 + # ${DIRvim}/openvim net-create $DIRvim/test/networks/net-example1.yaml || ! echo "fail" >&2 || $_exit 1 + # ${DIRvim}/openvim net-create $DIRvim/test/networks/net-example2.yaml || ! echo "fail" >&2 || $_exit 1 + # ${DIRvim}/openvim net-create $DIRvim/test/networks/net-example3.yaml || ! echo "fail" >&2 || $_exit 1 + ${DIRvim}/openvim net-create $DIRvim/test/networks/net-example4.yaml || ! echo "fail" >&2 || $_exit 1 + + printf "%-50s" "Creating openvim tenant 'osm': " + result=`${DIRvim}/openvim tenant-create '{tenant: {name: osm, description: admin}}'` + vimtenant=`echo $result |gawk '{print $1}'` + #check a valid uuid is obtained + ! is_valid_uuid $vimtenant && echo "FAIL" && echo " $result" && $_exit 1 + echo " $vimtenant" + export OPENVIM_TENANT=$vimtenant + [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENVIM_TENANT=$vimtenant" >> ~/.bashrc + + printf "%-50s" "Adding example image 'cirros034': " + result=`${DIRvim}/openvim image-create --name cirros034 \ + --path http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img \ + --description "cirros from web"` + image=`echo $result |gawk '{print $1}'` + ! is_valid_uuid $image && echo "FAIL" && echo " $result" && $_exit 1 + echo " $image" + + + echo + #echo "Check virtual machines are deployed" + #vms_error=`openvim vm-list | grep ERROR | wc -l` + #vms=`openvim vm-list | wc -l` + #[[ $vms -ne 8 ]] && echo "WARNING: $vms VMs created, must be 8 VMs" >&2 && $_exit 1 + #[[ $vms_error -gt 0 ]] && echo "WARNING: $vms_error VMs with ERROR" >&2 && $_exit 1 +fi +done + +echo +echo DONE +#echo "Listing VNFs" +#openvim vnf-list +#echo "Listing scenarios" +#openvim scenario-list +#echo "Listing scenario instances" +#openvim instance-scenario-list + + diff --git a/scripts/initopenvim.sh b/scripts/initopenvim.sh deleted file mode 100755 index 1bd152a..0000000 --- a/scripts/initopenvim.sh +++ /dev/null @@ -1,225 +0,0 @@ -#!/bin/bash - -## -# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U. -# This file is part of openvim -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. -# -# For those usages not covered by the Apache License, Version 2.0 please -# contact with: nfvlabs@tid.es -## - -#This script can be used as a basic test of openvim -#stopping on an error -#WARNING: It destroy the database content - -DIRNAME=$(readlink -f ${BASH_SOURCE[0]}) -DIRNAME=$(dirname $DIRNAME ) - -function usage(){ - echo -e "usage: ${BASH_SOURCE[0]} [OPTIONS] \n Deletes openvim content and add fake hosts, networks" - echo -e " is a list of the following items (by default 'reset create')" - echo -e " reset reset the openvim database content" - echo -e " create creates fake hosts and networks" - echo -e " delete delete created items" - echo -e " delete-all delete vms. flavors, images, ..." - echo -e " OPTIONS:" - echo -e " -f --force : does not prompt for confirmation" - echo -e " -d --delete : same to action delete-all" - echo -e " -p --port PORT : port to start openvim service" - echo -e " -P --admin-port PORT : administrator port to start openvim service" - echo -e " --screen-name NAME : screen name to launch openvim (default vim)" - echo -e " --dbname NAME : database name to use (default vim_db)" - echo -e " --insert-bashrc insert the created tenant variables at" - echo -e " ~/.bashrc to be available by openvim CLI" - echo -e " -h --help : shows this help" -} - -function is_valid_uuid(){ - echo "$1" | grep -q -E '^[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$' && return 0 - return 1 -} - - -#detect if is called with a source to use the 'exit'/'return' command for exiting -[[ ${BASH_SOURCE[0]} != $0 ]] && _exit="return" || _exit="exit" - - -#process options -source ${DIRNAME}/get-options.sh \ - "force:f delete:d delete-all port:p= admin-port:P= screen-name= help:h dbname= insert-bashrc" $* || $_exit 1 - -#check correct arguments -action_list="" -for param in $params -do - if [[ "$param" == reset ]] || [[ "$param" == create ]] || [[ "$param" == delete ]] || [[ "$param" == delete-all ]] - then - action_list="$action_list $param" - continue - else - echo "invalid argument '$param'? Type -h for help" >&2 && $_exit 1 - fi -done - -#help -[[ -n "$option_help" ]] && usage && $_exit 0 - -#check numeric values for port -[[ -n "$option_port" ]] && ( [[ "$option_port" -lt 1 ]] || [[ "$option_port" -gt 65535 ]] ) && echo "Option '-p' or '--port' requires a valid numeric argument" >&2 && $_exit 1 -[[ -n "$option_admin_port" ]] && ( [[ "$option_admin_port" -lt 1 ]] || [[ "$option_admin_port" -gt 65535 ]] ) && echo "Option '-P' or '--admin-port' requieres a valid numeric argument" >&2 && $_exit 1 - -[[ -n "$option_screen_name" ]] && screen_name="$option_screen_name" && screen_name_param=" --screen-name $screen_name" -[[ -z "$option_screen_name" ]] && screen_name=vim && screen_name_param="" #default value - -[[ -n "$option_delete" ]] && action_list="delete-all $action_list" - -openvim_param=" --" -[[ -n "$option_port" ]] && openvim_param="$openvim_param -p $option_port" -[[ -n "$option_admin_port" ]] && openvim_param="$openvim_param -P $option_admin_port" -[[ -n "$option_dbname" ]] && openvim_param="$openvim_param --dbname $option_dbname" -[[ $openvim_param = " --" ]] && openvim_param="" -db_name=vim_db #default value -[[ -n "$option_dbname" ]] && db_name="$option_dbname" - -DIRNAME=$(dirname $(readlink -f ${BASH_SOURCE[0]})) -DIRvim=$(dirname $DIRNAME) -export OPENVIM_HOST=localhost -[[ -n "$option_port" ]] && export OPENVIM_PORT=$option_port -[[ -n "$option_admin_port" ]] && export OPENVIM_ADMIN_PORT=$option_admin_port - -[[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENVIM_HOST=localhost" >> ~/.bashrc -[[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENVIM_PORT=9080" >> ~/.bashrc -#by default action should be reset and create -[[ -z "$action_list" ]] && action_list="reset create" - - -for action in $action_list -do -if [[ $action == "reset" ]] -then - #ask for confirmation if argument is not -f --force - force_="y" - [[ -z "$option_force" ]] && read -e -p "WARNING: openvim database content will be lost!!! Continue(y/N)" force_ - [[ $force_ != y ]] && [[ $force_ != yes ]] && echo "aborted!" && $_exit - echo "deleting deployed vm" - ${DIRvim}/openvim vm-delete -f | grep -q deleted && sleep 10 #give some time to get virtual machines deleted - echo "Stopping openvim${screen_name_param}${openvim_param}" - $DIRNAME/service-openvim stop${screen_name_param}${openvim_param} - echo "Initializing databases $db_name" - $DIRvim/database_utils/init_vim_db.sh -u vim -p vimpw -d $db_name - echo "Starting openvim${screen_name_param}${openvim_param}" - $DIRNAME/service-openvim start${screen_name_param}${openvim_param} - -elif [[ $action == delete-all ]] -then - for t in `${DIRvim}/openvim tenant-list | awk '/^ *[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12} +/{printf("%s:%s",$1,$2)}'` - do - t_id=${t%%:*} - t_name=${t#*:} - [[ -z $t_id ]] && continue - export OPENVIM_TENANT=${t_id} - for what in vm image flavor port net - do - items=`${DIRvim}/openvim $what-list | awk '/^ *[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12} +/{print $1}'` - if [[ -n $items ]] - then - [[ $option_force == "-" ]] && echo deleting openvim ${what}s from tenant ${t_name} - [[ $option_force != "-" ]] && read -e -p "Delete openvim ${what}s from tenant ${t_name}?(y/N) " force_ - [[ $force_ != y ]] && [[ $force_ != yes ]] && echo "aborted!" && $_exit - for item in $items - do - echo -n "$item " - ${DIRvim}/openvim $what-delete -f $item || ! echo "fail" >&2 || $_exit 1 - done - fi - done - ${DIRvim}/openvim tenant-delete -f $t_id || ! echo "fail" >&2 || $_exit 1 - for what in host - do - items=`${DIRvim}/openvim $what-list | awk '/^ *[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12} +/{print $1}'` - if [[ -n $items ]] - then - [[ $option_force == "-" ]] && echo deleting openvim ${what}s - [[ $option_force != "-" ]] && read -e -p "Delete openvim ${what}s?(y/N) " force_ - [[ $force_ != y ]] && [[ $force_ != yes ]] && echo "aborted!" && $_exit - for item in $items - do - echo -n "$item " - ${DIRvim}/openvim $what-delete -f $item || ! echo "fail" >&2 || $_exit 1 - done - fi - done - - done -elif [[ $action == "delete" ]] -then - ${DIRvim}/openvim net-delete -f default || echo "fail" - ${DIRvim}/openvim net-delete -f macvtap:em1 || echo "fail" - ${DIRvim}/openvim net-delete -f shared_bridge_net || echo "fail" - ${DIRvim}/openvim net-delete -f data_net || echo "fail" - ${DIRvim}/openvim host-remove -f fake-host-0 || echo "fail" - ${DIRvim}/openvim host-remove -f fake-host-1 || echo "fail" - ${DIRvim}/openvim host-remove -f fake-host-2 || echo "fail" - ${DIRvim}/openvim host-remove -f fake-host-3 || echo "fail" - result=`openvim tenant-list osm` - vimtenant=`echo $result |gawk '{print $1}'` - #check a valid uuid is obtained - is_valid_uuid $vimtenant || ! echo "Tenant 'osm' not found. Already delete?" >&2 || $_exit 1 - export OPENVIM_TENANT=$vimtenant - ${DIRvim}/openvim tenant-delete -f osm || echo "fail" - echo - -elif [[ $action == "create" ]] -then - echo "Adding example hosts" - ${DIRvim}/openvim host-add $DIRvim/test/hosts/host-example0.yaml || ! echo "fail" >&2 || $_exit 1 - ${DIRvim}/openvim host-add $DIRvim/test/hosts/host-example1.yaml || ! echo "fail" >&2 || $_exit 1 - ${DIRvim}/openvim host-add $DIRvim/test/hosts/host-example2.yaml || ! echo "fail" >&2 || $_exit 1 - ${DIRvim}/openvim host-add $DIRvim/test/hosts/host-example3.yaml || ! echo "fail" >&2 || $_exit 1 - echo "Adding example nets" - ${DIRvim}/openvim net-create $DIRvim/test/networks/net-example0.yaml || ! echo "fail" >&2 || $_exit 1 - ${DIRvim}/openvim net-create $DIRvim/test/networks/net-example1.yaml || ! echo "fail" >&2 || $_exit 1 - ${DIRvim}/openvim net-create $DIRvim/test/networks/net-example2.yaml || ! echo "fail" >&2 || $_exit 1 - ${DIRvim}/openvim net-create $DIRvim/test/networks/net-example3.yaml || ! echo "fail" >&2 || $_exit 1 - - printf "%-50s" "Creating openvim tenant 'osm': " - result=`openvim tenant-create '{tenant: {name: osm, description: admin}}'` - vimtenant=`echo $result |gawk '{print $1}'` - #check a valid uuid is obtained - ! is_valid_uuid $vimtenant && echo "FAIL" && echo " $result" && $_exit 1 - echo " $vimtenant" - export OPENVIM_TENANT=$vimtenant - [[ -n "$option_insert_bashrc" ]] && echo -e "\nexport OPENVIM_TENANT=$vimtenant" >> ~/.bashrc - - echo - #echo "Check virtual machines are deployed" - #vms_error=`openvim vm-list | grep ERROR | wc -l` - #vms=`openvim vm-list | wc -l` - #[[ $vms -ne 8 ]] && echo "WARNING: $vms VMs created, must be 8 VMs" >&2 && $_exit 1 - #[[ $vms_error -gt 0 ]] && echo "WARNING: $vms_error VMs with ERROR" >&2 && $_exit 1 -fi -done - -echo -echo DONE -#echo "Listing VNFs" -#openvim vnf-list -#echo "Listing scenarios" -#openvim scenario-list -#echo "Listing scenario instances" -#openvim instance-scenario-list - - diff --git a/scripts/install-openvim-service.sh b/scripts/install-openvim-service.sh index b862cc1..f9270f2 100755 --- a/scripts/install-openvim-service.sh +++ b/scripts/install-openvim-service.sh @@ -36,16 +36,21 @@ function usage(){ } function uninstall(){ - echo "systemctl disable openvim.service " && systemctl disable openvim.service 2>/dev/null || echo " Already done" - echo "service openvim stop " && service openvim stop 2>/dev/null || echo " Already done" - for file in /opt/openvim /etc/default/openvimd.cfg /var/log/openvim /etc/systemd/system/openvim.service /usr/bin/openvim /usr/bin/initopenvim /usr/sbin/service-openvim /usr/bin/openvim-report /usr/bin/openflow + echo "systemctl disable openvim.service " && systemctl disable openvim.service 2>/dev/null || + echo " Already done" + echo "systemctl disable osm-openvim.service " && systemctl disable osm-openvim.service 2>/dev/null || + echo " Already done" + echo "service osm-openvim stop " && service osm-openvim stop 2>/dev/null || echo " Already done" + for file in /opt/openvim /etc/default/openvimd.cfg /etc/osm/openvimd.cfg /var/log/openvim /var/log/osm/openvim* \ + /etc/systemd/system/openvim.service /etc/systemd/system/osm-openvim.service /usr/bin/openvim /usr/sbin/service-openvim \ + /usr/bin/openvim-report /usr/bin/initopenvim /usr/bin/openflow do + echo rm $file rm -rf $file || ! echo "Can not delete '$file'. Needed root privileges?" >&2 || exit 1 done echo "Done" } -BAD_PATH_ERROR="Path '$FILE' does not contain a valid openvim distribution" GIT_URL=https://osm.etsi.org/gerrit/osm/openvim.git USER_OWNER="root" QUIET_MODE="" @@ -115,50 +120,50 @@ else fi -if [[ -z $FILE ]] +if [[ -z "$FILE" ]] then FILE=__temp__${RANDOM} git clone $GIT_URL $FILE || ! echo "Cannot get openvim source code from $GIT_URL" >&2 || exit 1 DELETE=y - #git checkout else [[ -d "$FILE" ]] || ! echo $BAD_PATH_ERROR >&2 || exit 1 fi -#make idenpotent +#make idempotent uninstall #copy files cp -r "$FILE" /opt/openvim || ! echo $BAD_PATH_ERROR >&2 || exit 1 -mkdir -p /opt/openvim/logs +mkdir -p /etc/osm || echo "warning cannot create config folder '/etc/osm'" +cp /opt/openvim/osm_openvim/openvimd.cfg /etc/osm/openvimd.cfg || + echo "warning cannot create file '/etc/osm/openvimd.cfg'" +mkdir -p /var/log/osm || echo "warning cannot create log folder '/var/log/osm'" #makes links -ln -s -v /opt/openvim/openvimd.cfg /etc/default/openvimd.cfg || echo "warning cannot create link '/etc/default/openvimd.cfg'" -ln -s -v /opt/openvim/logs /var/log/openvim || echo "warning cannot create link '/var/log/openvim'" ln -s -v /opt/openvim/openvim /usr/bin/openvim ln -s -v /opt/openvim/scripts/service-openvim /usr/sbin/service-openvim ln -s -v /opt/openvim/scripts/openvim-report /usr/bin/openvim-report -ln -s -v /opt/openvim/scripts/initopenvim.sh /usr/bin/initopenvim +ln -s -v /opt/openvim/scripts/initopenvim /usr/bin/initopenvim ln -s -v /opt/openvim/openflow /usr/bin/openflow chown -R $SUDO_USER /opt/openvim mkdir -p /etc/systemd/system/ -cat > /etc/systemd/system/openvim.service << EOF +cat > /etc/systemd/system/osm-openvim.service << EOF [Unit] Description=openvim server [Service] User=${USER_OWNER} -ExecStart=/opt/openvim/openvimd -c /opt/openvim/osm_openvim/openvimd.cfg --log-file=/opt/openvim/logs/openvim.log +ExecStart=/opt/openvim/openvimd -c /etc/osm/openvimd.cfg --log-file=/var/log/osm/openvim.log Restart=always [Install] WantedBy=multi-user.target EOF -[[ -n $DELETE ]] && rm -rf $FILE +[[ -n $DELETE ]] && rm -rf "${FILE}" -service openvim start -systemctl enable openvim.service +service osm-openvim start +systemctl enable osm-openvim.service echo Done exit