2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2016 Orange and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
13 PWD_FILENAME="passwords.sh"
18 function exit_on_error {
21 if [ $RES != 0 ]; then
29 ## Create LAB_CONFIG folder if not exists
34 ## Override default passwords with local settings if needed
37 if [ -e "$LAB_CONFIG/$PWD_FILENAME" ]; then
38 echo "------ Load local passwords ------"
39 source $LAB_CONFIG/$PWD_FILENAME
41 export MAAS_USER=ubuntu
42 export MAAS_PASSWORD=ubuntu
43 export OS_ADMIN_PASSWORD=openstack
47 ## Set Joid pod config name
49 # This part will be removed when pod names will be synced between jenkins and joid config
60 export POD_NAME=${POD/-}
63 ## Parse Network config
66 EXTERNAL_NETWORK=${EXTERNAL_NETWORK:-}
67 # split EXTERNAL_NETWORK=name;type;first ip;last ip; gateway;network
68 IFS=';' read -r -a EXTNET <<< "$EXTERNAL_NETWORK"
69 EXTNET_NAME=${EXTNET[0]}
70 EXTNET_TYPE=${EXTNET[1]}
71 EXTNET_FIP=${EXTNET[2]}
72 EXTNET_LIP=${EXTNET[3]}
73 EXTNET_GW=${EXTNET[4]}
74 EXTNET_NET=${EXTNET[5]}
77 ## Redeploy MAAS or recover the previous config
81 if [ -e "$LAB_CONFIG/environments.yaml" ] && [ "$MAAS_REINSTALL" == "false" ]; then
82 echo "------ Recover Juju environment to use MAAS ------"
83 cp $LAB_CONFIG/environments.yaml .
85 MAASCONFIG=$WORKSPACE/ci/maas/${POD/-*}/${POD/*-}/deployment.yaml
86 echo "------ Set MAAS password ------"
87 sed -i -- "s/user: ubuntu/user: $MAAS_USER/" $MAASCONFIG
88 sed -i -- "s/password: ubuntu/password: $MAAS_PASSWORD/" $MAASCONFIG
89 echo "------ Redeploy MAAS ------"
90 ./02-maasdeploy.sh $POD_NAME
91 exit_on_error $? "MAAS Deploy FAILED"
95 ## Configure Joid deployment
98 # Based on scenario naming we can get joid options
100 # os-<controller>-<nfvfeature>-<mode>[-<extrastuff>]
102 # controller=(nosdn|odl_l3|odl_l2|onos|ocl)
104 # nfvfeature=(kvm|ovs|dpdk|nofeature)
105 # '_' list separated.
108 # Optional field - Not used today
110 IFS='-' read -r -a DEPLOY_OPTIONS <<< "${DEPLOY_SCENARIO}--"
111 #last -- need to avoid nounset error
113 SDN_CONTROLLER=${DEPLOY_OPTIONS[1]}
114 NFV_FEATURES=${DEPLOY_OPTIONS[2]}
115 HA_MODE=${DEPLOY_OPTIONS[3]}
116 EXTRA=${DEPLOY_OPTIONS[4]}
118 if [ "$SDN_CONTROLLER" == 'odl_l2' ] || [ "$SDN_CONTROLLER" == 'odl_l3' ]; then
121 if [ "$HA_MODE" == 'noha' ]; then
124 SRCBUNDLE="${WORKSPACE}/ci/${SDN_CONTROLLER}/juju-deployer/"
125 SRCBUNDLE="${SRCBUNDLE}/ovs-${SDN_CONTROLLER}-${HA_MODE}.yaml"
129 echo "------ Set openstack password ------"
130 sed -i -- "s/admin-password: openstack/admin-password: $OS_ADMIN_PASSWORD/" $SRCBUNDLE
132 if [ -n "$EXTNET_NAME" ]; then
133 echo "------ Set openstack default network ------"
134 sed -i -- "s/neutron-external-network: ext_net/neutron-external-network: $EXTNET_NAME/" $SRCBUNDLE
137 echo "------ Set ceph disks ------"
138 #Find the first line of osd-devices to change the one for ceph, then the other for ceph-osd
139 sed -i -- "s@osd-devices: /srv@osd-devices: $CEPH_DISKS@" $SRCBUNDLE
140 sed -i -r -- "s/^(\s+osd-reformat: )'no'/\1'$CEPH_REFORMAT'/" $SRCBUNDLE
143 ## Configure Joid deployment
146 echo "------ Deploy with juju ------"
147 echo "Execute: ./deploy.sh -t $HA_MODE -o $OS_RELEASE -s $SDN_CONTROLLER -l $POD_NAME"
149 ./deploy.sh -t $HA_MODE -o $OS_RELEASE -s $SDN_CONTROLLER -l $POD_NAME
150 exit_on_error $? "Main deploy FAILED"
155 JOID_ADMIN_OPENRC=$LAB_CONFIG/admin-openrc
156 echo "------ Create OpenRC file [$JOID_ADMIN_OPENRC] ------"
161 KEYSTONE=$(cat bundles.yaml |shyaml get-value openstack-phase2.services.keystone.options.vip)
164 KEYSTONE=$(juju status keystone |grep public-address|sed -- 's/.*\: //')
170 case "$SDN_CONTROLLER" in
172 SDN_CONTROLLER_IP=$(juju status odl-controller/0 |grep public-address|sed -- 's/.*\: //')
175 SDN_CONTROLLER_IP=$(juju status onos-controller/0 |grep public-address|sed -- 's/.*\: //')
178 SDN_CONTROLLER_IP='none'
183 # export the openrc file
184 cat << EOF > $JOID_ADMIN_OPENRC
185 export OS_USERNAME=admin
186 export OS_PASSWORD=$OS_ADMIN_PASSWORD
187 export OS_TENANT_NAME=admin
188 export OS_AUTH_URL=http://$KEYSTONE:5000/v2.0
189 export OS_REGION_NAME=Canonical
190 export SDN_CONTROLLER=$SDN_CONTROLLER_IP
191 export SDN_PASSWORD=$SDN_PASSWORD
195 ## Backup local juju env
198 echo "------ Backup Juju environment ------"
199 cp environments.yaml $LAB_CONFIG/
202 ## Basic test to return a realistic result to jenkins
205 echo "------ Do basic test ------"
206 source $JOID_ADMIN_OPENRC
207 curl -i -sw '%{http_code}' -H "Content-Type: application/json" -d "
210 \"methods\": [\"password\"],
214 \"domain\": { \"id\": \"default\" },
215 \"password\": \"$OS_ADMIN_PASSWORD\"
220 }" http://$KEYSTONE:5000/v3/auth/tokens |grep "HTTP/1.1 20" 2>&1 >/dev/null;
221 exit_on_error $? "Deploy FAILED to auth to openstack"
225 ## Create external network if needed
228 # If we have more information than only the name, try to create it
229 if [ -z "$EXTNET_TYPE" ]; then
230 echo "------ No data for external network creation, pass ------"
231 elif [[ "$DEPLOY_SCENARIO" =~ "onos" ]]; then
232 echo "------ ONOS have created the external network, pass ------"
234 echo "------ External network creation ------"
235 neutron net-create $EXTNET_NAME --router:external True \
236 --provider:physical_network external --provider:network_type $EXTNET_TYPE
237 exit_on_error $? "External network creation failed"
238 neutron subnet-create $EXTNET_NAME --name $EXTNET_NAME \
239 --allocation-pool start=$EXTNET_FIP,end=$EXTNET_LIP \
240 --disable-dhcp --gateway $EXTNET_GW $EXTNET_NET
241 exit_on_error $? "External subnet creation failed"
242 neutron net-update $EXTNET_NAME --shared
243 exit_on_error $? "External network sharing failed"
250 echo "Deploy success"