From: garciadeblas Date: Mon, 18 Nov 2019 16:24:43 +0000 (+0100) Subject: Moved common from jenkins folder to devops root folder X-Git-Tag: v7.0.0rc1~29 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=3c25fabc0802a4f2aa17c7e5b28de2376833d429;hp=d5f6aa6872dc5614c193b4a146ed4335f495e864;p=osm%2Fdevops.git Moved common from jenkins folder to devops root folder Change-Id: Ib56b840f5d91f5962daa5fd06d80eb1888617f9e Signed-off-by: garciadeblas --- diff --git a/common/all_funcs b/common/all_funcs new file mode 100644 index 00000000..d4693733 --- /dev/null +++ b/common/all_funcs @@ -0,0 +1,28 @@ +# this file is meant to be sourced +# +# Copyright 2016 RIFT.IO Inc +# +# 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. +# +# import all functions +# +# 24 June 2016 -- Jeremy Mordkoff -- Genesis + +if [ -z "$OSM_DEVOPS" ]; then + export OSM_DEVOPS=$(realpath ${BASH_SOURCE[0]} ) +fi + +for file in logging config container git_functions; do + . ${OSM_DEVOPS}/common/$file + INFO "$file sourced" +done diff --git a/common/config b/common/config new file mode 100644 index 00000000..7f49381e --- /dev/null +++ b/common/config @@ -0,0 +1,40 @@ +#!/bin/bash +# This file is meant to be SOURCED +# +# Copyright 2016 RIFT.IO Inc +# +# 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. +# +# config functions +# 24 June 2016 -- Jeremy Mordkoff -- Genesis + + +OSM_load_config() { + OSM_load_config_file ${OSM_JENKINS}/SETTINGS + if [ -z "$OSM_MDG" ]; then + WARNING "OSM_MDG not set" + else + OSM_load_config_file ${OSM_JENKINS}/${OSM_MDG}/SETTINGS + fi +} + +OSM_load_config_file() { + [ $# -eq 1 ] || FATAL "arg is filename" + if [ -f "$1" ]; then + . "$1" + INFO "config file $1 loaded" + else + WARNING "$1 not found" + fi +} + diff --git a/common/container b/common/container new file mode 100644 index 00000000..e29d5eb3 --- /dev/null +++ b/common/container @@ -0,0 +1,89 @@ +# This file is meant to be SOURCED +# +# Copyright 2016 RIFT.IO Inc +# Copyright 2016 Telefónica Investigación y Desarrollo S.A.U. +# +# 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. +# +# container_funcs +# 24 June 2016 -- Jeremy Mordkoff -- Genesis +# -- Gerardo García + +container_exists() { + if [ $# -ne 1 ]; then + FATAL "arg is container name" + fi + lxc config show $1 >/dev/null 2>&1 + if [ $? -eq 0 ]; then + DEBUG "container $1 exists" + return 0 + else + DEBUG "container $1 not found" + return 1 + fi +} + +create_container() { + if [ $# -lt 2 ]; then + FATAL "args are image container [options]" + fi + INFO "creating container $2 using image $1" + image=$1 + container=$2 + shift 2 + DEBUG "lxc launch $image $container $*" + lxc launch "$image" "$container" $* +} + +container_exec() { + container="$1" + shift + DEBUG "exec in $container \"$*\"" + lxc exec "$container" -- $* +} + +container_exec_stderr() { + container="$1" + shift + DEBUG "exec in $container \"$*\"" + lxc exec "$container" -- $* 2>&1 +} + +wait_container_up() { + [ $# -eq 1 ] || FATAL "arg is container name got $# args - $*" + RE="200" + ct=0 + while [ $ct -lt 10 ]; do + let ct=ct+1 + output=$(container_exec_stderr "$1" curl -sL -w "%{http_code}\\n" "http://www.google.com/" -o /dev/null) + if [[ $output =~ $RE ]]; then + DEBUG "$1 is up" + return + fi + INFO "waiting for container $1 to start" + DEBUG "expected '$RE' in $output" + sleep 5 + done + FATAL "container $1 did not start" +} +container_push_tree() { + # create a tarball locally, pipe it into the container and unpack it there + [ $# -eq 3 ] || FATAL "args are container dir_from dir_to (dir_to MUST exist)" + tar -C "$2" -c . -f - | container_exec $1 tar -C "$3" -x -f - +} + +container_push_devops() { + [ $# -eq 1 ] || FATAL "arg is container name got $# args - $*" + container_exec "$1" mkdir -p /root/devops + container_push_tree "$1" "$(dirname $OSM_JENKINS)" "/root/devops" +} diff --git a/common/git_functions b/common/git_functions new file mode 100644 index 00000000..7cfee883 --- /dev/null +++ b/common/git_functions @@ -0,0 +1,53 @@ +#!/bin/bash +# +# 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. +# + + +GIT() { + CMD git "$@" +} + + +OSM_git_checkout() { + + # Updates all the branches in the local repo (clones if it does not exist) + if [ -d $OSM_MDG ]; then + INFO "reusing existing workspace" + cd $OSM_MDG + GIT fetch --all --tags + #git checkout master #to make sure that we are in the right branch before pulling the code + #git pull + else + INFO "cloning MDG $OSM_MDG from $OSM_GIT_URL/$OSM_MDG" + GIT clone $OSM_GIT_URL/$OSM_MDG + cd $OSM_MDG + for remote in `git branch -r |grep -v /HEAD`; do GIT branch --track ${remote#origin/} $remote; done + fi + + if [ $# -gt 0 ]; then + if [ "$1" = "checkout" ]; then + INFO "Code to compile: '$2'" + GIT checkout $2 + else + INFO "Code to compile: gerrit refspec '$1', commit-id: '$2'" + GIT fetch origin $1 || FATAL "git fetch origin '$1' didn't work" + GIT checkout -f $2 || FATAL "git checkout -f '$2' didn't work" + fi + else + INFO "Code to compile: master" + GIT checkout master + fi + +} + diff --git a/common/install_common b/common/install_common new file mode 100755 index 00000000..901d287b --- /dev/null +++ b/common/install_common @@ -0,0 +1,52 @@ +# this file is meant to be sourced +# +# Copyright 2017 Sandvine +# +# 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. +# +# + +RELEASE="ReleaseTHREE" +REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg" +REPOSITORY="stable" +REPOSITORY_BASE="http://osm-download.etsi.org/repository/osm/debian" + +while getopts ":r:k:u:R:b:-:" o; do + case "${o}" in + r) + REPOSITORY=${OPTARG} + ;; + R) + RELEASE=${OPTARG} + ;; + k) + REPOSITORY_KEY=${OPTARG} + ;; + u) + REPOSITORY_BASE=${OPTARG} + ;; + b) + ## ignore branch option + ;; + -) + ;; + esac +done + +key_location=$REPOSITORY_BASE/$RELEASE/$REPOSITORY_KEY +echo $key_location + +curl $key_location | apt-key add - + +REPOSITORY_BASE=${REPOSITORY_BASE%/} +apt-get update && add-apt-repository -y "deb $REPOSITORY_BASE/$RELEASE $REPOSITORY SO UI RO MON IM osmclient openvim" diff --git a/common/logging b/common/logging new file mode 100644 index 00000000..a95b5633 --- /dev/null +++ b/common/logging @@ -0,0 +1,61 @@ +#!/bin/bash +# This file is meant to be SOURCED +# +# Copyright 2016 RIFT.IO Inc +# +# 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. +# +# container_funcs +# 24 June 2016 -- Jeremy Mordkoff -- Genesis + +print_stack() { + local i + local stack_size=${#FUNCNAME[1]} + echo "BACKTRACE:" >&2 + for (( i=1; i<$stack_size ; i++ )); do + local func="${FUNCNAME[$i]}" + [ x$func = x ] && func=MAIN + local linen="${BASH_LINENO[(( i - 1 ))]}" + local src="${BASH_SOURCE[$i]}" + [ x"$src" = x ] && src=non_file_source + echo "### $func $src $linen" >&2 + done + echo "-------" >&2 +} + + +FATAL() { + echo -e "\n### $(date) ${FUNCNAME[1]}: FATAL error: $*" >&2 + print_stack + exit 1 +} + +WARNING() { + echo -e "\n### $(date) ${FUNCNAME[1]}: WARNING error: $*" >&2 +} + +INFO() { + echo "## $(date) ${FUNCNAME[1]}: $*" >&2 +} + +DEBUG() { + echo "# $(date) ${FUNCNAME[1]}: $*" >&2 +} + +CMD() { + echo "# executing '$*' ..." + "$@" + rc=$? + echo "# .... '$*' done RC was $rc" + return $rc +} diff --git a/installers/full_install_osm.sh b/installers/full_install_osm.sh index 7b45761a..776ab061 100755 --- a/installers/full_install_osm.sh +++ b/installers/full_install_osm.sh @@ -1415,8 +1415,7 @@ if [ -z "$OSM_DEVOPS" ]; then fi fi -OSM_JENKINS="$OSM_DEVOPS/jenkins" -. $OSM_JENKINS/common/all_funcs +. $OSM_DEVOPS/common/all_funcs [ -n "$INSTALL_LIGHTWEIGHT" ] && [ -n "$UNINSTALL" ] && uninstall_lightweight && echo -e "\nDONE" && exit 0 [ -n "$UNINSTALL" ] && uninstall && echo -e "\nDONE" && exit 0 diff --git a/installers/nat_osm b/installers/nat_osm index b7b70970..e12a123f 100755 --- a/installers/nat_osm +++ b/installers/nat_osm @@ -36,8 +36,7 @@ usage(){ HERE=$(realpath $(dirname $0)) OSM_DEVOPS=$(dirname $HERE) -OSM_JENKINS="$OSM_DEVOPS/jenkins" -. $OSM_JENKINS/common/all_funcs +. $OSM_DEVOPS/common/all_funcs #Get default IP address . $OSM_DEVOPS/installers/export_ips diff --git a/jenkins/common/all_funcs b/jenkins/common/all_funcs deleted file mode 100644 index a8471087..00000000 --- a/jenkins/common/all_funcs +++ /dev/null @@ -1,28 +0,0 @@ -# this file is meant to be sourced -# -# Copyright 2016 RIFT.IO Inc -# -# 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. -# -# import all functions -# -# 24 June 2016 -- Jeremy Mordkoff -- Genesis - -if [ -z "$OSM_JENKINS" ]; then - export OSM_JENKINS=$(realpath $(dirname ${BASH_SOURCE[0]} )) -fi - -for file in logging config container git_functions; do - . ${OSM_JENKINS}/common/$file - INFO "$file sourced" -done diff --git a/jenkins/common/config b/jenkins/common/config deleted file mode 100644 index 7f49381e..00000000 --- a/jenkins/common/config +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash -# This file is meant to be SOURCED -# -# Copyright 2016 RIFT.IO Inc -# -# 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. -# -# config functions -# 24 June 2016 -- Jeremy Mordkoff -- Genesis - - -OSM_load_config() { - OSM_load_config_file ${OSM_JENKINS}/SETTINGS - if [ -z "$OSM_MDG" ]; then - WARNING "OSM_MDG not set" - else - OSM_load_config_file ${OSM_JENKINS}/${OSM_MDG}/SETTINGS - fi -} - -OSM_load_config_file() { - [ $# -eq 1 ] || FATAL "arg is filename" - if [ -f "$1" ]; then - . "$1" - INFO "config file $1 loaded" - else - WARNING "$1 not found" - fi -} - diff --git a/jenkins/common/container b/jenkins/common/container deleted file mode 100644 index e29d5eb3..00000000 --- a/jenkins/common/container +++ /dev/null @@ -1,89 +0,0 @@ -# This file is meant to be SOURCED -# -# Copyright 2016 RIFT.IO Inc -# Copyright 2016 Telefónica Investigación y Desarrollo S.A.U. -# -# 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. -# -# container_funcs -# 24 June 2016 -- Jeremy Mordkoff -- Genesis -# -- Gerardo García - -container_exists() { - if [ $# -ne 1 ]; then - FATAL "arg is container name" - fi - lxc config show $1 >/dev/null 2>&1 - if [ $? -eq 0 ]; then - DEBUG "container $1 exists" - return 0 - else - DEBUG "container $1 not found" - return 1 - fi -} - -create_container() { - if [ $# -lt 2 ]; then - FATAL "args are image container [options]" - fi - INFO "creating container $2 using image $1" - image=$1 - container=$2 - shift 2 - DEBUG "lxc launch $image $container $*" - lxc launch "$image" "$container" $* -} - -container_exec() { - container="$1" - shift - DEBUG "exec in $container \"$*\"" - lxc exec "$container" -- $* -} - -container_exec_stderr() { - container="$1" - shift - DEBUG "exec in $container \"$*\"" - lxc exec "$container" -- $* 2>&1 -} - -wait_container_up() { - [ $# -eq 1 ] || FATAL "arg is container name got $# args - $*" - RE="200" - ct=0 - while [ $ct -lt 10 ]; do - let ct=ct+1 - output=$(container_exec_stderr "$1" curl -sL -w "%{http_code}\\n" "http://www.google.com/" -o /dev/null) - if [[ $output =~ $RE ]]; then - DEBUG "$1 is up" - return - fi - INFO "waiting for container $1 to start" - DEBUG "expected '$RE' in $output" - sleep 5 - done - FATAL "container $1 did not start" -} -container_push_tree() { - # create a tarball locally, pipe it into the container and unpack it there - [ $# -eq 3 ] || FATAL "args are container dir_from dir_to (dir_to MUST exist)" - tar -C "$2" -c . -f - | container_exec $1 tar -C "$3" -x -f - -} - -container_push_devops() { - [ $# -eq 1 ] || FATAL "arg is container name got $# args - $*" - container_exec "$1" mkdir -p /root/devops - container_push_tree "$1" "$(dirname $OSM_JENKINS)" "/root/devops" -} diff --git a/jenkins/common/git_functions b/jenkins/common/git_functions deleted file mode 100644 index e5b79845..00000000 --- a/jenkins/common/git_functions +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/bash - - -GIT() { - CMD git "$@" -} - - -OSM_git_checkout() { - - # Updates all the branches in the local repo (clones if it does not exist) - if [ -d $OSM_MDG ]; then - INFO "reusing existing workspace" - cd $OSM_MDG - GIT fetch --all --tags - #git checkout master #to make sure that we are in the right branch before pulling the code - #git pull - else - INFO "cloning MDG $OSM_MDG from $OSM_GIT_URL/$OSM_MDG" - GIT clone $OSM_GIT_URL/$OSM_MDG - cd $OSM_MDG - for remote in `git branch -r |grep -v /HEAD`; do GIT branch --track ${remote#origin/} $remote; done - fi - - if [ $# -gt 0 ]; then - if [ "$1" = "checkout" ]; then - INFO "Code to compile: '$2'" - GIT checkout $2 - else - INFO "Code to compile: gerrit refspec '$1', commit-id: '$2'" - GIT fetch origin $1 || FATAL "git fetch origin '$1' didn't work" - GIT checkout -f $2 || FATAL "git checkout -f '$2' didn't work" - fi - else - INFO "Code to compile: master" - GIT checkout master - fi - -} - diff --git a/jenkins/common/install_common b/jenkins/common/install_common deleted file mode 100755 index 901d287b..00000000 --- a/jenkins/common/install_common +++ /dev/null @@ -1,52 +0,0 @@ -# this file is meant to be sourced -# -# Copyright 2017 Sandvine -# -# 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. -# -# - -RELEASE="ReleaseTHREE" -REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg" -REPOSITORY="stable" -REPOSITORY_BASE="http://osm-download.etsi.org/repository/osm/debian" - -while getopts ":r:k:u:R:b:-:" o; do - case "${o}" in - r) - REPOSITORY=${OPTARG} - ;; - R) - RELEASE=${OPTARG} - ;; - k) - REPOSITORY_KEY=${OPTARG} - ;; - u) - REPOSITORY_BASE=${OPTARG} - ;; - b) - ## ignore branch option - ;; - -) - ;; - esac -done - -key_location=$REPOSITORY_BASE/$RELEASE/$REPOSITORY_KEY -echo $key_location - -curl $key_location | apt-key add - - -REPOSITORY_BASE=${REPOSITORY_BASE%/} -apt-get update && add-apt-repository -y "deb $REPOSITORY_BASE/$RELEASE $REPOSITORY SO UI RO MON IM osmclient openvim" diff --git a/jenkins/common/logging b/jenkins/common/logging deleted file mode 100644 index a95b5633..00000000 --- a/jenkins/common/logging +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash -# This file is meant to be SOURCED -# -# Copyright 2016 RIFT.IO Inc -# -# 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. -# -# container_funcs -# 24 June 2016 -- Jeremy Mordkoff -- Genesis - -print_stack() { - local i - local stack_size=${#FUNCNAME[1]} - echo "BACKTRACE:" >&2 - for (( i=1; i<$stack_size ; i++ )); do - local func="${FUNCNAME[$i]}" - [ x$func = x ] && func=MAIN - local linen="${BASH_LINENO[(( i - 1 ))]}" - local src="${BASH_SOURCE[$i]}" - [ x"$src" = x ] && src=non_file_source - echo "### $func $src $linen" >&2 - done - echo "-------" >&2 -} - - -FATAL() { - echo -e "\n### $(date) ${FUNCNAME[1]}: FATAL error: $*" >&2 - print_stack - exit 1 -} - -WARNING() { - echo -e "\n### $(date) ${FUNCNAME[1]}: WARNING error: $*" >&2 -} - -INFO() { - echo "## $(date) ${FUNCNAME[1]}: $*" >&2 -} - -DEBUG() { - echo "# $(date) ${FUNCNAME[1]}: $*" >&2 -} - -CMD() { - echo "# executing '$*' ..." - "$@" - rc=$? - echo "# .... '$*' done RC was $rc" - return $rc -}