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
58 export POD_NAME=${POD/-}
61 ## Parse Network config
64 EXTERNAL_NETWORK=${EXTERNAL_NETWORK:-}
65 # split EXTERNAL_NETWORK=name;type;first ip;last ip; gateway;network
66 IFS=';' read -r -a EXTNET <<< "$EXTERNAL_NETWORK"
67 EXTNET_NAME=${EXTNET[0]}
68 EXTNET_TYPE=${EXTNET[1]}
69 EXTNET_FIP=${EXTNET[2]}
70 EXTNET_LIP=${EXTNET[3]}
71 EXTNET_GW=${EXTNET[4]}
72 EXTNET_NET=${EXTNET[5]}
75 ## Redeploy MAAS or recover the previous config
79 if [ -e "$LAB_CONFIG/environments.yaml" ] && [ "$MAAS_REINSTALL" == "false" ]; then
80 echo "------ Recover Juju environment to use MAAS ------"
81 cp $LAB_CONFIG/environments.yaml .
83 MAASCONFIG=$WORKSPACE/ci/maas/${POD/-*}/${POD/*-}/deployment.yaml
84 echo "------ Set MAAS password ------"
85 sed -i -- "s/user: ubuntu/user: $MAAS_USER/" $MAASCONFIG
86 sed -i -- "s/password: ubuntu/password: $MAAS_PASSWORD/" $MAASCONFIG
87 echo "------ Redeploy MAAS ------"
88 ./02-maasdeploy.sh $POD_NAME
89 exit_on_error $? "MAAS Deploy FAILED"
93 ## Configure Joid deployment
96 # Based on scenario naming we can get joid options
98 # os-<controller>-<nfvfeature>-<mode>[-<extrastuff>]
100 # controller=(nosdn|odl_l3|odl_l2|onos|ocl)
102 # nfvfeature=(kvm|ovs|dpdk|nofeature)
103 # '_' list separated.
106 # Optional field - Not used today
108 IFS='-' read -r -a DEPLOY_OPTIONS <<< "${DEPLOY_SCENARIO}--"
109 #last -- need to avoid nounset error
111 SDN_CONTROLLER=${DEPLOY_OPTIONS[1]}
112 NFV_FEATURES=${DEPLOY_OPTIONS[2]}
113 HA_MODE=${DEPLOY_OPTIONS[3]}
114 EXTRA=${DEPLOY_OPTIONS[4]}
116 if [ "$SDN_CONTROLLER" == 'odl_l2' ] || [ "$SDN_CONTROLLER" == 'odl_l3' ]; then
119 if [ "$HA_MODE" == 'noha' ]; then
122 SRCBUNDLE="${WORKSPACE}/ci/${SDN_CONTROLLER}/juju-deployer/"
123 SRCBUNDLE="${SRCBUNDLE}/ovs-${SDN_CONTROLLER}-${HA_MODE}.yaml"
127 echo "------ Set openstack password ------"
128 sed -i -- "s/admin-password: openstack/admin-password: $OS_ADMIN_PASSWORD/" $SRCBUNDLE
130 if [ -n "$EXTNET_NAME" ]; then
131 echo "------ Set openstack default network ------"
132 sed -i -- "s/neutron-external-network: ext_net/neutron-external-network: $EXTNET_NAME/" $SRCBUNDLE
135 echo "------ Set ceph disks ------"
136 #Find the first line of osd-devices to change the one for ceph, then the other for ceph-osd
137 sed -i -- "s@osd-devices: /srv@osd-devices: $CEPH_DISKS@" $SRCBUNDLE
138 sed -i -r -- "s/^(\s+osd-reformat: )'no'/\1'$CEPH_REFORMAT'/" $SRCBUNDLE
141 ## Configure Joid deployment
144 echo "------ Deploy with juju ------"
145 echo "Execute: ./deploy.sh -t $HA_MODE -o $OS_RELEASE -s $SDN_CONTROLLER -l $POD_NAME -d $UBUNTU_DISTRO"
147 ./deploy.sh -t $HA_MODE -o $OS_RELEASE -s $SDN_CONTROLLER -l $POD_NAME -d $UBUNTU_DISTRO
148 exit_on_error $? "Main deploy FAILED"
153 JOID_ADMIN_OPENRC=$LAB_CONFIG/admin-openrc
154 echo "------ Create OpenRC file [$JOID_ADMIN_OPENRC] ------"
159 KEYSTONE=$(cat bundles.yaml |shyaml get-value openstack-phase2.services.keystone.options.vip)
162 KEYSTONE=$(juju status keystone |grep public-address|sed -- 's/.*\: //')
168 case "$SDN_CONTROLLER" in
170 SDN_CONTROLLER_IP=$(juju status odl-controller/0 |grep public-address|sed -- 's/.*\: //')
173 SDN_CONTROLLER_IP=$(juju status onos-controller/0 |grep public-address|sed -- 's/.*\: //')
176 SDN_CONTROLLER_IP='none'
181 # export the openrc file
182 cat << EOF > $JOID_ADMIN_OPENRC
183 export OS_USERNAME=admin
184 export OS_PASSWORD=$OS_ADMIN_PASSWORD
185 export OS_TENANT_NAME=admin
186 export OS_AUTH_URL=http://$KEYSTONE:5000/v2.0
187 export OS_REGION_NAME=Canonical
188 export SDN_CONTROLLER=$SDN_CONTROLLER_IP
189 export SDN_PASSWORD=$SDN_PASSWORD
193 ## Backup local juju env
196 echo "------ Backup Juju environment ------"
197 cp environments.yaml $LAB_CONFIG/
200 ## Basic test to return a realistic result to jenkins
203 echo "------ Do basic test ------"
204 source $JOID_ADMIN_OPENRC
205 curl -i -sw '%{http_code}' -H "Content-Type: application/json" -d "
208 \"methods\": [\"password\"],
212 \"domain\": { \"id\": \"default\" },
213 \"password\": \"$OS_ADMIN_PASSWORD\"
218 }" http://$KEYSTONE:5000/v3/auth/tokens |grep "HTTP/1.1 20" 2>&1 >/dev/null;
219 exit_on_error $? "Deploy FAILED to auth to openstack"
223 ## Create external network if needed
226 # If we have more information than only the name, try to create it
227 if [ -z "$EXTNET_TYPE" ]; then
228 echo "------ No data for external network creation, pass ------"
229 elif [[ "$DEPLOY_SCENARIO" =~ "onos" ]]; then
230 echo "------ ONOS have created the external network, pass ------"
232 echo "------ External network creation ------"
233 neutron net-create $EXTNET_NAME --router:external True \
234 --provider:physical_network external --provider:network_type $EXTNET_TYPE
235 exit_on_error $? "External network creation failed"
236 neutron subnet-create $EXTNET_NAME --name $EXTNET_NAME \
237 --allocation-pool start=$EXTNET_FIP,end=$EXTNET_LIP \
238 --disable-dhcp --gateway $EXTNET_GW $EXTNET_NET
239 exit_on_error $? "External subnet creation failed"
240 neutron net-update $EXTNET_NAME --shared
241 exit_on_error $? "External network sharing failed"
248 echo "Deploy success"