From: David Garcia Date: Wed, 16 Jun 2021 08:37:34 +0000 (+0200) Subject: Minor fixes and enhancements in local-build.sh X-Git-Tag: release-v11.0-start~19 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=f0014df1d65e8a1de6cd784f690c31ca34f63047;p=osm%2Fdevops.git Minor fixes and enhancements in local-build.sh - Typo in the --help: --install-local-regitstry --> --install-local-registry - Fix conditional. When VIM_AUTH_URL does not exist, the script was showing this error message: "bash: [: too many arguments" - Change from xip.io to nip.io - Parameterize the osm/tests image tag. This allows to use the published osm/tests image without needing to execute the stage-3 command - Add print_section function: Cleaner way of printing section information - Add --vim-vca option. Allows to attach an existing VCA (registered in OSM) to be used by the VIM account. Change-Id: I2c1375e031f042f505f126586c0e819c21e1dd4c Signed-off-by: David Garcia --- diff --git a/tools/local-build.sh b/tools/local-build.sh index 5c832fb7..f471e03c 100755 --- a/tools/local-build.sh +++ b/tools/local-build.sh @@ -24,6 +24,7 @@ NO_CACHE="" OPENSTACKRC="/var/snap/microstack/common/etc/microstack.rc" REGISTRY="localhost:32000" ROOTDIR="$( cd "${DIR}/../../" &> /dev/null && pwd)" +OSM_TESTS_IMAGE_TAG="devel" function check_arguments(){ while [ $# -gt 0 ] ; do @@ -41,6 +42,8 @@ function check_arguments(){ --registry) REGISTRY="$2" && shift;; --robot-local-mounts) ROBOT_LOCAL=YES ;; --run-tests) TESTS=YES ;; + --vim-vca) VIM_VCA="$2" && shift;; + --osm-tests-image-tag) OSM_TESTS_IMAGE_TAG="$2" && shift;; stage-2) STAGE_2='stage_2 ${TARGET_MODULE}' ;; stage-3) STAGE_3='stage_3 ${TARGET_MODULE}' ;; registry-push) REGISTRY_PUSH='local_registry_push ${TARGET_MODULE}' ;; @@ -65,7 +68,7 @@ same process as Jenkins. OPTIONS: --help display this help message --debug enable set -x for this script - --install-local-regitstry install and enable Microk8s local registry on port 32000 + --install-local-registry install and enable Microk8s local registry on port 32000 --install-microstack install Microstack and configure to run robot tests --install-qhttpd install QHTTPD as an HTTP server on port ${HTTPPORT} --kubecfg path to kubecfg.yaml (uses Charmed OSM by default) @@ -74,6 +77,8 @@ OPTIONS: --openstackrc path to Openstack RC file (uses Microstack by default) --registry use this alternate docker registry --run-tests run stage 2 tests + --vim-vca name of the a vca registered in OSM to use in the VIM account + --osm-tests-image-tag tag to be used in the osm/tests docker image stage-2 run the stage 2 build stage-3 run the stage 3 build registry-push push to the local registry @@ -83,6 +88,10 @@ OPTIONS: EOF } +function print_section() { + echo "$@" +} + function install_local_registry() { sudo snap install microk8s --classic microk8s status --wait-ready @@ -136,11 +145,7 @@ function install_qhttpd() { } function stage_2() { - cat << EOF -======================================================================================= -Performing Stage 2 -======================================================================================= -EOF + print_section "Performing Stage 2" MODULES="common devops IM LCM MON N2VC NBI NG-UI osmclient PLA POL RO tests" if [ ! -z ${1} ] ; then POSSIBLE_MODULES=$(echo ${1} | sed "s/,/ /g") @@ -153,11 +158,7 @@ EOF done MODULES=${POSSIBLE_MODULES} else - cat << EOF -======================================================================================= -Cleaning HTTP Directory for full build -======================================================================================= -EOF + print_section "Cleaning HTTP Directory for full build" rm -fv ${HTTPDDIR}/*.deb fi @@ -167,11 +168,7 @@ EOF echo "Directory ${ROOTDIR}/${MODULE} does not exist" exit 1 fi - cat << EOF -======================================================================================= -Building ${MODULE} -======================================================================================= -EOF + print_section "Building ${MODULE}" cd ${MODULE} find . -name '*.deb' -exec rm -v {} \; docker build ${NO_CACHE} -t ${MODULE,,}-stage2 . @@ -189,11 +186,7 @@ EOF useradd -o -u $(id -u) -d /build -r -g $USER $USER ; runuser $USER -c devops-stages/${STAGE}" if [ $? -ne 0 ] ; then - cat << EOF -======================================================================================= -Failed to build ${MODULE} -======================================================================================= -EOF + print_section "Failed to build ${MODULE}" exit 1 fi done @@ -221,11 +214,7 @@ function _find_module_dockerfile() { } function stage_3() { - cat << EOF -======================================================================================= -Performing Stage 3 -======================================================================================= -EOF + print_section "Performing Stage 3" MODULES=$(_find_module_dockerfile $1) BUILD_ARGS="" HOSTIP=$(ip -4 addr show docker0 | grep -Po 'inet \K[\d.]+') @@ -243,31 +232,19 @@ EOF echo "Directory ${ROOTDIR}/${MODULE} does not exist" exit 1 fi - cat << EOF -======================================================================================= -Building ${MODULE} -======================================================================================= -EOF + print_section "Building ${MODULE}" cd ${MODULE} MODULE=${MODULE,,} docker build ${NO_CACHE} -t opensourcemano/${MODULE}:devel ${BUILD_ARGS} . if [ $? -ne 0 ] ; then - cat << EOF -======================================================================================= -Failed to build ${MODULE} -======================================================================================= -EOF + print_section "Failed to build ${MODULE}" exit 1 fi done } function local_registry_push() { - cat << EOF -======================================================================================= -Pushing to local registry -======================================================================================= -EOF + print_section "Pushing to local registry" cd "${ROOTDIR}/devops/docker" MODULES=`find . -name Dockerfile -printf '%h\n' |sed 's|\./||' |sort |tr '\n' ' '` if [ ! -z ${1} ] ; then @@ -313,7 +290,7 @@ function start_robot() { export PROMETHEUS_HOSTNAME=$(juju config -m osm prometheus site_url | sed "s/http.*\?:\/\///") export PROMETHEUS_PORT=80 export JUJU_PASSWORD=`juju gui 2>&1 | grep password | awk '{print $2}'` - export HOSTIP=$(echo $PROMETHEUS_HOSTNAME | sed "s/prometheus.//" | sed "s/.xip.io//") + export HOSTIP=$(echo $PROMETHEUS_HOSTNAME | sed "s/prometheus.//" | sed "s/.nip.io//") rm robot-systest.cfg for line in `env | grep "^OS_" | sort` ; do echo $line >> robot-systest.cfg ; done @@ -329,7 +306,7 @@ EOF cat << EOF > robot.etc.hosts 127.0.0.1 localhost -${HOSTIP} prometheus.${HOSTIP}.xip.io nbi.${HOSTIP}.xip.io +${HOSTIP} prometheus.${HOSTIP}.nip.io nbi.${HOSTIP}.nip.io EOF cat << EOF > clouds.yaml clouds: @@ -344,14 +321,17 @@ clouds: EOF VIM_AUTH_URL=$(osm vim-show osm | grep vim_url | awk '{print $4}' | tr -d \") - if [ ! -z ${VIM_AUTH_URL} -a "$OS_AUTH_URL" != "${VIM_AUTH_URL}" ] ; then + if [[ ! -z ${VIM_AUTH_URL} && "$OS_AUTH_URL" != "${VIM_AUTH_URL}" ]] ; then echo "Deleting existing VIM osm as auth URLs have changed" osm vim-delete osm fi if ! osm vim-show osm &> /dev/null ; then echo "Creating VIM osm" - osm vim-create --name osm --user "$OS_USERNAME" --password "$OS_PASSWORD" \ + if [ -v VIM_VCA ]; then + VCA_OPT="--vca $VIM_VCA" + fi + osm vim-create --name osm $VCA_OPT --user "$OS_USERNAME" --password "$OS_PASSWORD" \ --auth_url "$OS_AUTH_URL" --tenant "$OS_USERNAME" --account_type openstack \ --config='{use_floating_ip: True, management_network_name: osm-ext}' @@ -383,7 +363,7 @@ EOF -v "${ROOTDIR}/tests/robot-systest/lib":${LOCAL_MOUNT_1} \ -v "${ROOTDIR}/tests/robot-systest/resources":${LOCAL_MOUNT_2} \ -v "${ROOTDIR}/tests/robot-systest/testsuite":${LOCAL_MOUNT_3} \ - opensourcemano/tests:devel + opensourcemano/tests:$OSM_TESTS_IMAGE_TAG } function update_osm_module() {