From 24ca7a8ae3b5f5c235a244c77163c71d1990b94f Mon Sep 17 00:00:00 2001 From: tierno Date: Mon, 8 May 2017 15:45:32 +0200 Subject: [PATCH] fix issues at installation scripts. Change at initopenvim Change-Id: I9837ada6b892fbcaa58a64bd1601593064b16b57 Signed-off-by: tierno --- database_utils/install-db-server.sh | 16 +++++----- osm_openvim/osm-openvim.service | 3 +- scripts/{initopenvim.sh => initopenvim} | 39 +++++++++++++++++-------- scripts/install-openvim-service.sh | 37 +++++++++++++---------- 4 files changed, 57 insertions(+), 38 deletions(-) rename scripts/{initopenvim.sh => initopenvim} (83%) 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.sh b/scripts/initopenvim similarity index 83% rename from scripts/initopenvim.sh rename to scripts/initopenvim index 1bd152a..b6c5de6 100755 --- a/scripts/initopenvim.sh +++ b/scripts/initopenvim @@ -78,8 +78,10 @@ done [[ -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_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 @@ -125,7 +127,8 @@ then 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)}'` + 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#*:} @@ -166,14 +169,16 @@ then 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 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 @@ -190,13 +195,14 @@ then ${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-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=`openvim tenant-create '{tenant: {name: osm, description: admin}}'` + 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 @@ -204,6 +210,15 @@ then 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` 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 -- 2.25.1