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 #######################################################################################
19 DIR
="$( cd "$
( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
20 HTTPDDIR
="$( cd "${HOME}/snap
/qhttp
/common
" &> /dev/null && pwd )"
22 KUBECFG
="~/.osm/microk8s-config.yaml"
24 OPENSTACKRC
="/var/snap/microstack/common/etc/microstack.rc"
25 REGISTRY
="localhost:32000"
26 ROOTDIR
="$( cd "${DIR}/..
/..
/" &> /dev/null && pwd)"
28 function check_arguments
(){
29 while [ $# -gt 0 ] ; do
32 --help |
-h) show_help
&& exit 0 ;;
33 --httpddir) HTTPDIR
="$2" && shift;;
34 --install-local-registry) 'install_local_registry' ;;
35 --install-microstack) 'install_microstack' ;;
36 --install-qhttpd) INSTALL_HTTPD
='install_qhttpd' ;;
37 --kubecfg) KUBECFG
="$2" && shift ;;
38 --module) TARGET_MODULE
="$2" && shift;;
39 --no-cache) NO_CACHE
="--no-cache" ;;
40 --openstackrc) OPENSTACKRC
="$2" && shift ;;
41 --registry) REGISTRY
="$2" && shift;;
42 --robot-local-mounts) ROBOT_LOCAL
=YES
;;
43 --run-tests) TESTS
=YES
;;
44 stage-2
) STAGE_2
='stage_2 ${TARGET_MODULE}' ;;
45 stage-3
) STAGE_3
='stage_3 ${TARGET_MODULE}' ;;
46 registry-push
) REGISTRY_PUSH
='local_registry_push ${TARGET_MODULE}' ;;
47 install-osm
) INSTALL_OSM
='install_osm' ;;
48 start-robot
) START_ROBOT
='start_robot' ;;
49 update-install
) UPDATE_INSTALL
='update_osm_module ${TARGET_MODULE}'
50 REGISTRY_PUSH
='local_registry_push ${TARGET_MODULE}' ;;
51 *) echo "Unknown option $1"
59 function show_help
() {
62 Perform a local build and potential installation of OSM from sources, using the
63 same process as Jenkins.
66 --help display this help message
67 --debug enable set -x for this script
68 --install-local-regitstry install and enable Microk8s local registry on port 32000
69 --install-microstack install Microstack and configure to run robot tests
70 --install-qhttpd install QHTTPD as an HTTP server on port ${HTTPPORT}
71 --kubecfg path to kubecfg.yaml (uses Charmed OSM by default)
72 --no-cache do not use any cache when building docker images
73 --module only build this comma delimited list of modules
74 --openstackrc path to Openstack RC file (uses Microstack by default)
75 --registry use this alternate docker registry
76 --run-tests run stage 2 tests
77 stage-2 run the stage 2 build
78 stage-3 run the stage 3 build
79 registry-push push to the local registry
80 install-osm perform full installation of Charmed OSM from registry
81 start-robot start the Robot test container and leave you at prompt
82 update-install update Charmed OSM with new module container
86 function install_local_registry
() {
87 sudo snap
install microk8s
--classic
88 microk8s status
--wait-ready
89 microk8s.
enable registry
92 function install_microstack
() {
93 sudo snap
install microstack
--devmode --edge
94 sudo snap
set microstack config.network.ports.dashboard
=10080
95 sudo microstack.init
--auto --control
97 sudo snap
alias microstack.openstack openstack
98 .
/var
/snap
/microstack
/common
/etc
/microstack.rc
100 for i
in $
(openstack security group list |
awk '/default/{ print $2 }'); do
101 openstack security group rule create
$i --protocol icmp
--remote-ip 0.0.0.0/0
102 openstack security group rule create
$i --protocol tcp
--remote-ip 0.0.0.0/0
105 openstack network create
--enable --no-share osm-ext
106 openstack subnet create osm-ext-subnet
--network osm-ext
--dns-nameserver 8.8.8.8 \
107 --subnet-range 172.30.0.0/24
108 openstack router create external-router
109 openstack router add subnet external-router osm-ext-subnet
110 openstack router
set --external-gateway external external-router
112 curl
-L https
://github.com
/cirros-dev
/cirros
/releases
/download
/0.3.5/cirros-0.3
.5-x86_64-disk.img \
113 | openstack image create
--public --container-format=bare \
114 --disk-format=qcow2 cirros-0.3
.5-x86_64-disk.img
115 curl https
://cloud-images.ubuntu.com
/xenial
/current
/xenial-server-cloudimg-amd64-disk1.img \
116 | openstack image create
--public --container-format=bare \
117 --disk-format=qcow2 ubuntu16.04
118 curl https
://cloud-images.ubuntu.com
/xenial
/current
/xenial-server-cloudimg-amd64-disk1.img \
119 | openstack image create
--public --container-format=bare \
120 --disk-format=qcow2 US1604
121 curl https
://cloud-images.ubuntu.com
/bionic
/current
/bionic-server-cloudimg-amd64.img \
122 | openstack image create
--public --container-format=bare \
123 --disk-format=qcow2 ubuntu18.04
124 curl https
://cloud-images.ubuntu.com
/focal
/current
/focal-server-cloudimg-amd64.img \
125 | openstack image create
--public --container-format=bare \
126 --disk-format=qcow2 ubuntu20.04
129 function install_qhttpd
() {
130 sudo snap
install qhttp
131 EXISTING_PID
=$
(ps auxw |
grep "http.server 11480" |
grep -v grep |
awk '{print $2}')
132 if [ ! -z $EXISTING_PID ] ; then
135 qhttp
-p ${HTTPPORT} &
140 =======================================================================================
142 =======================================================================================
144 MODULES
="common devops IM LCM MON N2VC NBI NG-UI osmclient PLA POL RO tests"
145 if [ ! -z ${1} ] ; then
146 POSSIBLE_MODULES
=$
(echo ${1} |
sed "s/,/ /g")
147 for MODULE
in ${POSSIBLE_MODULES}; do
148 if ! echo "${MODULES}" |
grep -q "${MODULE}" ; then
149 echo "Unknown stage 2 module ${MODULE}"
150 echo "Must be one of ${MODULES}"
154 MODULES
=${POSSIBLE_MODULES}
157 =======================================================================================
158 Cleaning HTTP Directory for full build
159 =======================================================================================
161 rm -fv ${HTTPDDIR}/*.deb
164 for MODULE
in ${MODULES} ; do
166 if [ ! -d ${MODULE} ] ; then
167 echo "Directory ${ROOTDIR}/${MODULE} does not exist"
171 =======================================================================================
173 =======================================================================================
176 find .
-name '*.deb' -exec rm -v {} \
;
177 docker build
${NO_CACHE} -t ${MODULE,,}-stage2 .
179 STAGES
="stage-build.sh"
180 if [ ! -z $TESTS ] ; then
181 STAGES
="stage-test.sh ${STAGES}"
183 for STAGE
in $STAGES ; do
188 bash
-c "groupadd -o -g $(id -g) -r $USER ;
189 useradd -o -u $(id -u) -d /build -r -g $USER $USER ;
190 runuser $USER -c devops-stages/${STAGE}"
191 if [ $?
-ne 0 ] ; then
193 =======================================================================================
194 Failed to build ${MODULE}
195 =======================================================================================
201 find .
-name '*.deb' -exec mv -v {} ${HTTPDDIR}/ \
;
205 function _find_module_dockerfile
() {
206 cd "${ROOTDIR}/devops/docker"
207 MODULES
=`find . -name Dockerfile -printf '%h\n' |sed 's|\./||' |sort |tr '\n' ' '`
208 if [ ! -z ${1} ] ; then
209 POSSIBLE_MODULES
=$
(echo ${1} |
sed "s/,/ /g")
210 for MODULE
in ${POSSIBLE_MODULES}; do
211 if ! echo "${MODULES}" |
grep -q "${MODULE}" ; then
212 echo "Unknown stage 3 module ${MODULE}"
213 echo "Must be one of ${MODULES}"
217 echo ${POSSIBLE_MODULES}
225 =======================================================================================
227 =======================================================================================
229 MODULES
=$
(_find_module_dockerfile
$1)
231 HOSTIP
=$
(ip
-4 addr show docker0 |
grep -Po 'inet \K[\d.]+')
232 for file in ~
/snap
/qhttp
/common
/*.deb
; do
233 file=`basename ${file}`
234 name
=`echo ${file} | cut -d_ -f1 | sed "s/-/_/g"`;
236 BUILD_ARGS
="${BUILD_ARGS}--build-arg ${name}=http://$HOSTIP:${HTTPPORT}/$file "
237 echo Added
${name} as http
://$HOSTIP:${HTTPPORT}/$file
240 for MODULE
in ${MODULES} ; do
241 cd "${ROOTDIR}/devops/docker"
242 if [ ! -d ${MODULE} ] ; then
243 echo "Directory ${ROOTDIR}/${MODULE} does not exist"
247 =======================================================================================
249 =======================================================================================
253 docker build
${NO_CACHE} -t opensourcemano/${MODULE}:devel ${BUILD_ARGS} .
254 if [ $?
-ne 0 ] ; then
256 =======================================================================================
257 Failed to build ${MODULE}
258 =======================================================================================
265 function local_registry_push
() {
267 =======================================================================================
268 Pushing to local registry
269 =======================================================================================
271 cd "${ROOTDIR}/devops/docker"
272 MODULES
=`find . -name Dockerfile -printf '%h\n' |sed 's|\./||' |sort |tr '\n' ' '`
273 if [ ! -z ${1} ] ; then
274 POSSIBLE_MODULES
=$
(echo ${1} |
sed "s/,/ /g")
275 for MODULE
in ${POSSIBLE_MODULES}; do
277 if ! echo "${MODULES}" |
grep -q "${MODULE}" ; then
278 echo "Unknown stage 3 module ${MODULE}"
279 echo "Must be one of ${MODULES}"
283 MODULES
=${POSSIBLE_MODULES}
285 for MODULE
in ${MODULES} ; do
287 docker tag opensourcemano
/${MODULE}:devel ${REGISTRY}/opensourcemano/${MODULE}:devel
288 docker push
${REGISTRY}/opensourcemano
/${MODULE}:devel
292 function install_osm
() {
293 cd "${ROOTDIR}/devops/installers"
295 if juju controllers
2>/dev
/null|
grep osm-vca
; then
298 .
/charmed_install.sh
--registry localhost
:32000 --tag devel
${VCA}
301 function start_robot
() {
302 mkdir
-p "${ROOTDIR}/tests/local"
303 cd "${ROOTDIR}/tests/local"
307 # Workaround for microstack auth URL
308 if [ ${OPENSTACKRC} == "/var/snap/microstack/common/etc/microstack.rc" ] ; then
309 export OS_AUTH_URL
=${OS_AUTH_URL}/v3
312 export OSM_HOSTNAME
=$
(juju config
-m osm nbi site_url |
sed "s/http.*\?:\/\///"):443
313 export PROMETHEUS_HOSTNAME
=$
(juju config
-m osm prometheus site_url |
sed "s/http.*\?:\/\///")
314 export PROMETHEUS_PORT
=80
315 export JUJU_PASSWORD
=`juju gui 2>&1 | grep password | awk '{print $2}'`
316 export HOSTIP
=$
(echo $PROMETHEUS_HOSTNAME |
sed "s/prometheus.//" |
sed "s/.xip.io//")
319 for line
in `env | grep "^OS_" | sort` ; do echo $line >> robot-systest.cfg
; done
320 cat << EOF >> robot-systest.cfg
323 ENVIRONMENTS_FOLDER=environments
324 PACKAGES_FOLDER=/robot-systest/osm-packages
330 cat << EOF > robot.etc.hosts
332 ${HOSTIP} prometheus.${HOSTIP}.xip.io nbi.${HOSTIP}.xip.io
334 cat << EOF > clouds.yaml
338 auth_url: $OS_AUTH_URL
339 project_name: $OS_PROJECT_NAME
340 username: $OS_USERNAME
341 password: $OS_PASSWORD
342 user_domain_name: $OS_USER_DOMAIN_NAME
343 project_domain_name: $OS_PROJECT_DOMAIN_NAME
346 VIM_AUTH_URL
=$
(osm vim-show osm |
grep vim_url |
awk '{print $4}' |
tr -d \")
347 if [ ! -z ${VIM_AUTH_URL} -a "$OS_AUTH_URL" != "${VIM_AUTH_URL}" ] ; then
348 echo "Deleting existing VIM osm as auth URLs have changed"
352 if ! osm vim-show osm
&> /dev
/null
; then
353 echo "Creating VIM osm"
354 osm vim-create
--name osm
--user "$OS_USERNAME" --password "$OS_PASSWORD" \
355 --auth_url "$OS_AUTH_URL" --tenant "$OS_USERNAME" --account_type openstack \
356 --config='{use_floating_ip: True,
357 management_network_name: osm-ext}'
360 if [ ! -z $ROBOT_LOCAL ] ; then
361 LOCAL_MOUNT_1
="/robot-systest/lib"
362 LOCAL_MOUNT_2
="/robot-systest/resources"
363 LOCAL_MOUNT_3
="/robot-systest/testsuite"
365 LOCAL_MOUNT_1
="/tmp/lib"
366 LOCAL_MOUNT_2
="/tmp/resources"
367 LOCAL_MOUNT_3
="/tmp/testsuite"
372 docker run
-ti --entrypoint /bin
/bash \
373 --env OSM_HOSTNAME
=${OSM_HOSTNAME} \
374 --env PROMETHEUS_HOSTNAME
=${PROMETHEUS_HOSTNAME} \
375 --env PROMETHEUS_PORT
=${PROMETHEUS_PORT} \
376 --env JUJU_PASSWORD
=${JUJU_PASSWORD} \
377 --env HOSTIP
=${HOSTIP} \
378 --env-file robot-systest.cfg \
379 -v "$(pwd)/robot.etc.hosts":/etc
/hosts \
380 -v ~
/.osm
/microk8s-config.yaml
:/root
/.kube
/config \
381 -v "$(pwd)/clouds.yaml":/etc
/openstack
/clouds.yaml \
382 -v "$(pwd)/reports:"/robot-systest
/reports \
383 -v "${ROOTDIR}/tests/robot-systest/lib":${LOCAL_MOUNT_1} \
384 -v "${ROOTDIR}/tests/robot-systest/resources":${LOCAL_MOUNT_2} \
385 -v "${ROOTDIR}/tests/robot-systest/testsuite":${LOCAL_MOUNT_3} \
386 opensourcemano
/tests
:devel
389 function update_osm_module
() {
390 MODULES
=$
(_find_module_dockerfile
$1)
391 for MODULE
in ${MODULES} ; do
393 echo "Updating ${MODULE}"
394 juju attach-resource
${MODULE} image
=localhost
:32000/opensourcemano
/${MODULE}:devel
398 if [ "$0" != "$BASH_SOURCE" ]; then
402 OPTIONS
=$
(show_help |
sed '0,/^OPTIONS:$/d' |
awk '{print $1}')
403 COMPREPLY
=($
(compgen
-W "${OPTIONS}" -- "${COMP_WORDS[-1]}"))
406 THIS_SCRIPT
="$(basename ${BASH_SOURCE[0]})"
407 echo "Setting up bash completion for ${THIS_SCRIPT}"
408 complete
-F _osm_local_build
"${THIS_SCRIPT}"
412 eval "${INSTALL_HTTPD}"
413 eval "${INSTALL_LOCAL_REGISTRY}"
414 eval "${INSTALL_MICROSTACK}"
417 eval "${REGISTRY_PUSH}"
418 eval "${INSTALL_OSM}"
419 eval "${UPDATE_INSTALL}"
420 eval "${START_ROBOT}"