2 #######################################################################################
3 # Copyright ETSI Contributors and Others.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #######################################################################################
20 DIR
="$( cd "$
( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
21 HTTPDDIR
="$( cd "${HOME}/snap
/qhttp
/common
" &> /dev/null && pwd )"
23 KUBECFG
="~/.osm/microk8s-config.yaml"
25 OPENSTACKRC
="/var/snap/microstack/common/etc/microstack.rc"
26 REGISTRY
="localhost:32000"
27 ROOTDIR
="$( cd "${DIR}/..
/..
/" &> /dev/null && pwd)"
28 OSM_TESTS_IMAGE_TAG
="devel"
30 function check_arguments
(){
31 while [ $# -gt 0 ] ; do
34 --apt-proxy) APT_PROXY
="$2" && shift ;;
35 --help |
-h) show_help
&& exit 0 ;;
36 --httpddir) HTTPDIR
="$2" && shift;;
37 --install-local-registry) 'install_local_registry' ;;
38 --install-microstack) 'install_microstack' ;;
39 --install-qhttpd) INSTALL_HTTPD
='install_qhttpd' ;;
40 --kubecfg) KUBECFG
="$2" && shift ;;
41 --module) TARGET_MODULE
="$2" && shift;;
42 --no-cache) NO_CACHE
="--no-cache" ;;
43 --openstackrc) OPENSTACKRC
="$2" && shift ;;
44 --registry) REGISTRY
="$2" && shift;;
45 --robot-local-mounts) ROBOT_LOCAL
=YES
;;
46 --run-tests) TESTS
=YES
;;
47 --vim-vca) VIM_VCA
="$2" && shift;;
48 --osm-tests-image-tag) OSM_TESTS_IMAGE_TAG
="$2" && shift;;
49 stage-2
) STAGE_2
='stage_2 ${TARGET_MODULE}' ;;
50 stage-3
) STAGE_3
='stage_3 ${TARGET_MODULE}' ;;
51 registry-push
) REGISTRY_PUSH
='local_registry_push ${TARGET_MODULE}' ;;
52 install-osm
) INSTALL_OSM
='install_osm' ;;
53 start-robot
) START_ROBOT
='start_robot' ;;
54 update-install
) UPDATE_INSTALL
='update_osm_module ${TARGET_MODULE}'
55 REGISTRY_PUSH
='local_registry_push ${TARGET_MODULE}' ;;
56 *) echo "Unknown option $1"
64 function show_help
() {
67 Perform a local build and potential installation of OSM from sources, using the
68 same process as Jenkins.
71 --help display this help message
72 --apt-proxy provide an apt proxy to docker build steps
73 --debug enable set -x for this script
74 --install-local-registry install and enable Microk8s local registry on port 32000
75 --install-microstack install Microstack and configure to run robot tests
76 --install-qhttpd install QHTTPD as an HTTP server on port ${HTTPPORT}
77 --kubecfg path to kubecfg.yaml (uses Charmed OSM by default)
78 --no-cache do not use any cache when building docker images
79 --module only build this comma delimited list of modules
80 --openstackrc path to Openstack RC file (uses Microstack by default)
81 --registry use this alternate docker registry
82 --run-tests run stage 2 tests
83 --vim-vca name of the a vca registered in OSM to use in the VIM account
84 --osm-tests-image-tag tag to be used in the osm/tests docker image
85 stage-2 run the stage 2 build
86 stage-3 run the stage 3 build
87 registry-push push to the local registry
88 install-osm perform full installation of Charmed OSM from registry
89 start-robot start the Robot test container and leave you at prompt
90 update-install update Charmed OSM with new module container
94 function print_section
() {
98 function install_local_registry
() {
99 sudo snap
install microk8s
--classic
100 microk8s status
--wait-ready
101 microk8s.
enable registry
104 function install_microstack
() {
105 sudo snap
install microstack
--devmode --edge
106 sudo snap
set microstack config.network.ports.dashboard
=8080
107 sudo microstack.init
--auto --control
109 sudo snap
alias microstack.openstack openstack
110 .
/var
/snap
/microstack
/common
/etc
/microstack.rc
112 for i
in $
(microstack.openstack security group list |
awk '/default/{ print $2 }'); do
113 microstack.openstack security group rule create
$i --protocol icmp
--remote-ip 0.0.0.0/0
114 microstack.openstack security group rule create
$i --protocol tcp
--remote-ip 0.0.0.0/0
117 microstack.openstack network create
--enable --no-share osm-ext
118 microstack.openstack subnet create osm-ext-subnet
--network osm-ext
--dns-nameserver 8.8.8.8 \
119 --subnet-range 172.30.0.0/24
120 microstack.openstack router create external-router
121 microstack.openstack router add subnet external-router osm-ext-subnet
122 microstack.openstack router
set --external-gateway external external-router
124 curl
-L https
://github.com
/cirros-dev
/cirros
/releases
/download
/0.3.5/cirros-0.3
.5-x86_64-disk.img \
125 | microstack.openstack image create
--public --container-format=bare \
126 --disk-format=qcow2 cirros-0.3
.5-x86_64-disk.img
127 curl https
://cloud-images.ubuntu.com
/xenial
/current
/xenial-server-cloudimg-amd64-disk1.img \
128 | microstack.openstack image create
--public --container-format=bare \
129 --disk-format=qcow2 ubuntu16.04
130 curl https
://cloud-images.ubuntu.com
/xenial
/current
/xenial-server-cloudimg-amd64-disk1.img \
131 | microstack.openstack image create
--public --container-format=bare \
132 --disk-format=qcow2 US1604
133 curl https
://cloud-images.ubuntu.com
/bionic
/current
/bionic-server-cloudimg-amd64.img \
134 | microstack.openstack image create
--public --container-format=bare \
135 --disk-format=qcow2 ubuntu18.04
136 curl https
://cloud-images.ubuntu.com
/focal
/current
/focal-server-cloudimg-amd64.img \
137 | microstack.openstack image create
--public --container-format=bare \
138 --disk-format=qcow2 ubuntu20.04
141 function install_qhttpd
() {
142 sudo snap
install qhttp
143 EXISTING_PID
=$
(ps auxw |
grep "http.server 11480" |
grep -v grep |
awk '{print $2}')
144 if [ ! -z $EXISTING_PID ] ; then
147 qhttp
-p ${HTTPPORT} &
151 print_section
"Performing Stage 2"
152 MODULES
="common devops IM LCM MON N2VC NBI NG-UI osmclient PLA POL RO tests"
153 if [ ! -z ${1} ] ; then
154 POSSIBLE_MODULES
=$
(echo ${1} |
sed "s/,/ /g")
155 for MODULE
in ${POSSIBLE_MODULES}; do
156 if ! echo "${MODULES}" |
grep -q "${MODULE}" ; then
157 echo "Unknown stage 2 module ${MODULE}"
158 echo "Must be one of ${MODULES}"
162 MODULES
=${POSSIBLE_MODULES}
164 print_section
"Cleaning HTTP Directory for full build"
165 rm -fv ${HTTPDDIR}/*.deb
168 for MODULE
in ${MODULES} ; do
170 if [ ! -d ${MODULE} ] ; then
171 echo "Directory ${ROOTDIR}/${MODULE} does not exist"
174 print_section
"Building ${MODULE}"
176 find .
-name '*.deb' -exec rm -v {} \
;
179 if [ ! -z $APT_PROXY ] ; then
180 BUILD_ARGS
="${BUILD_ARGS}--build-arg APT_PROXY=${APT_PROXY} "
182 docker build
${NO_CACHE} ${BUILD_ARGS} -t ${MODULE,,}-stage2 .
184 STAGES
="stage-build.sh"
185 if [ ! -z $TESTS ] ; then
186 STAGES
="stage-test.sh ${STAGES}"
188 for STAGE
in $STAGES ; do
193 bash
-c "groupadd -o -g $(id -g) -r $USER ;
194 useradd -o -u $(id -u) -d /build -r -g $USER $USER ;
195 runuser $USER -c devops-stages/${STAGE}"
196 if [ $?
-ne 0 ] ; then
197 print_section
"Failed to build ${MODULE}"
202 find .
-name '*.deb' -exec mv -v {} ${HTTPDDIR}/ \
;
206 function _find_module_dockerfile
() {
207 cd "${ROOTDIR}/devops/docker"
208 MODULES
=`find . -name Dockerfile -printf '%h\n' |sed 's|\./||' |sort |tr '\n' ' '`
209 if [ ! -z ${1} ] ; then
210 POSSIBLE_MODULES
=$
(echo ${1} |
sed "s/,/ /g")
211 for MODULE
in ${POSSIBLE_MODULES}; do
212 if ! echo "${MODULES}" |
grep -q "${MODULE}" ; then
213 echo "Unknown stage 3 module ${MODULE}"
214 echo "Must be one of ${MODULES}"
218 echo ${POSSIBLE_MODULES}
225 print_section
"Performing Stage 3"
226 MODULES
=$
(_find_module_dockerfile
$1)
228 if [ ! -z $APT_PROXY ] ; then
229 BUILD_ARGS
="${BUILD_ARGS}--build-arg APT_PROXY=${APT_PROXY} "
232 HOSTIP
=$
(ip
-4 addr show docker0 |
grep -Po 'inet \K[\d.]+')
233 for file in ~
/snap
/qhttp
/common
/*.deb
; do
234 file=`basename ${file}`
235 name
=`echo ${file} | cut -d_ -f1 | sed "s/-/_/g"`;
237 BUILD_ARGS
="${BUILD_ARGS}--build-arg ${name}=http://$HOSTIP:${HTTPPORT}/$file "
238 echo Added
${name} as http
://$HOSTIP:${HTTPPORT}/$file
241 for MODULE
in ${MODULES} ; do
242 cd "${ROOTDIR}/devops/docker"
243 if [ ! -d ${MODULE} ] ; then
244 echo "Directory ${ROOTDIR}/${MODULE} does not exist"
247 print_section
"Building ${MODULE}"
250 docker build
${NO_CACHE} -t opensourcemano/${MODULE}:devel ${BUILD_ARGS} .
251 if [ $?
-ne 0 ] ; then
252 print_section
"Failed to build ${MODULE}"
258 function local_registry_push
() {
259 print_section
"Pushing to local registry"
260 cd "${ROOTDIR}/devops/docker"
261 MODULES
=`find . -name Dockerfile -printf '%h\n' |sed 's|\./||' |sort |tr '\n' ' '`
262 if [ ! -z ${1} ] ; then
263 POSSIBLE_MODULES
=$
(echo ${1} |
sed "s/,/ /g")
264 for MODULE
in ${POSSIBLE_MODULES}; do
266 if ! echo "${MODULES}" |
grep -q "${MODULE}" ; then
267 echo "Unknown stage 3 module ${MODULE}"
268 echo "Must be one of ${MODULES}"
272 MODULES
=${POSSIBLE_MODULES}
274 for MODULE
in ${MODULES} ; do
276 docker tag opensourcemano
/${MODULE}:devel ${REGISTRY}/opensourcemano/${MODULE}:devel
277 docker push
${REGISTRY}/opensourcemano
/${MODULE}:devel
281 function install_osm
() {
282 cd "${ROOTDIR}/devops/installers"
284 if juju controllers
2>/dev
/null|
grep osm-vca
; then
287 .
/charmed_install.sh
--registry localhost
:32000 --tag devel
${VCA}
290 function start_robot
() {
291 mkdir
-p "${ROOTDIR}/tests/local"
292 cd "${ROOTDIR}/tests/local"
296 # Workaround for microstack auth URL
297 if [ ${OPENSTACKRC} == "/var/snap/microstack/common/etc/microstack.rc" ] ; then
298 export OS_AUTH_URL
=${OS_AUTH_URL}/v3
301 export OSM_HOSTNAME
=$
(juju config
-m osm nbi site_url |
sed "s/http.*\?:\/\///"):443
302 export PROMETHEUS_HOSTNAME
=$
(juju config
-m osm prometheus site_url |
sed "s/http.*\?:\/\///")
303 export PROMETHEUS_PORT
=80
304 export JUJU_PASSWORD
=`juju gui 2>&1 | grep password | awk '{print $2}'`
305 export HOSTIP
=$
(echo $PROMETHEUS_HOSTNAME |
sed "s/prometheus.//" |
sed "s/.nip.io//")
308 for line
in `env | grep "^OS_" | sort` ; do echo $line >> robot-systest.cfg
; done
309 cat << EOF >> robot-systest.cfg
312 ENVIRONMENTS_FOLDER=environments
313 PACKAGES_FOLDER=/robot-systest/osm-packages
319 cat << EOF > robot.etc.hosts
321 ${HOSTIP} prometheus.${HOSTIP}.nip.io nbi.${HOSTIP}.nip.io
323 cat << EOF > clouds.yaml
327 auth_url: $OS_AUTH_URL
328 project_name: $OS_PROJECT_NAME
329 username: $OS_USERNAME
330 password: $OS_PASSWORD
331 user_domain_name: $OS_USER_DOMAIN_NAME
332 project_domain_name: $OS_PROJECT_DOMAIN_NAME
335 VIM_AUTH_URL
=$
(osm vim-show osm |
grep vim_url |
awk '{print $4}' |
tr -d \")
336 if [[ ! -z ${VIM_AUTH_URL} && "$OS_AUTH_URL" != "${VIM_AUTH_URL}" ]] ; then
337 echo "Deleting existing VIM osm as auth URLs have changed"
341 if ! osm vim-show osm
&> /dev
/null
; then
342 echo "Creating VIM osm"
343 if [ -v VIM_VCA
]; then
344 VCA_OPT
="--vca $VIM_VCA"
346 osm vim-create
--name osm
$VCA_OPT --user "$OS_USERNAME" --password "$OS_PASSWORD" \
347 --auth_url "$OS_AUTH_URL" --tenant "$OS_USERNAME" --account_type openstack \
348 --config='{use_floating_ip: True,
349 management_network_name: osm-ext}'
352 if [ ! -z $ROBOT_LOCAL ] ; then
353 LOCAL_MOUNT_1
="/robot-systest/lib"
354 LOCAL_MOUNT_2
="/robot-systest/resources"
355 LOCAL_MOUNT_3
="/robot-systest/testsuite"
357 LOCAL_MOUNT_1
="/tmp/lib"
358 LOCAL_MOUNT_2
="/tmp/resources"
359 LOCAL_MOUNT_3
="/tmp/testsuite"
364 docker run
-ti --entrypoint /bin
/bash \
365 --env OSM_HOSTNAME
=${OSM_HOSTNAME} \
366 --env PROMETHEUS_HOSTNAME
=${PROMETHEUS_HOSTNAME} \
367 --env PROMETHEUS_PORT
=${PROMETHEUS_PORT} \
368 --env JUJU_PASSWORD
=${JUJU_PASSWORD} \
369 --env HOSTIP
=${HOSTIP} \
370 --env-file robot-systest.cfg \
371 -v "$(pwd)/robot.etc.hosts":/etc
/hosts \
372 -v ~
/.osm
/microk8s-config.yaml
:/root
/.kube
/config \
373 -v "$(pwd)/clouds.yaml":/etc
/openstack
/clouds.yaml \
374 -v "${HOME}/snap/qhttp/common"/robot-systest
/reports \
375 -v "${HOME}/snap/qhttp/common:"/robot-systest
/conformance-tests
/reports \
376 -v "${ROOTDIR}/tests/robot-systest/lib":${LOCAL_MOUNT_1} \
377 -v "${ROOTDIR}/tests/robot-systest/resources":${LOCAL_MOUNT_2} \
378 -v "${ROOTDIR}/tests/robot-systest/testsuite":${LOCAL_MOUNT_3} \
379 opensourcemano
/tests
:$OSM_TESTS_IMAGE_TAG
382 function update_osm_module
() {
383 MODULES
=$
(_find_module_dockerfile
$1)
384 for MODULE
in ${MODULES} ; do
386 echo "Updating ${MODULE}"
387 juju attach-resource
${MODULE} image
=localhost
:32000/opensourcemano
/${MODULE}:devel
391 if [ "$0" != "$BASH_SOURCE" ]; then
395 OPTIONS
=$
(show_help |
sed '0,/^OPTIONS:$/d' |
awk '{print $1}')
396 COMPREPLY
=($
(compgen
-W "${OPTIONS}" -- "${COMP_WORDS[-1]}"))
399 THIS_SCRIPT
="$(basename ${BASH_SOURCE[0]})"
400 echo "Setting up bash completion for ${THIS_SCRIPT}"
401 complete
-F _osm_local_build
"${THIS_SCRIPT}"
405 eval "${INSTALL_HTTPD}"
406 eval "${INSTALL_LOCAL_REGISTRY}"
407 eval "${INSTALL_MICROSTACK}"
410 eval "${REGISTRY_PUSH}"
411 eval "${INSTALL_OSM}"
412 eval "${UPDATE_INSTALL}"
413 eval "${START_ROBOT}"