5 PWD_FILENAME="passwords.sh"
10 function exit_on_error {
13 if [ $RES != 0 ]; then
21 ## Create LAB_CONFIG folder if not exists
26 ## Override default passwords with local settings if needed
29 if [ -e "$LAB_CONFIG/$PWD_FILENAME" ]; then
30 echo "------ Load local passwords ------"
31 source $LAB_CONFIG/$PWD_FILENAME
33 export MAAS_USER=ubuntu
34 export MAAS_PASSWORD=ubuntu
35 export OS_ADMIN_PASSWORD=openstack
39 ## Set Joid pod config name
41 # This part will be removed when pod names will be synced between jenkins and joid config
52 export POD_NAME=${POD/-}
55 ## Parse Network config
58 EXTERNAL_NETWORK=${EXTERNAL_NETWORK:-}
59 # split EXTERNAL_NETWORK=name;type;first ip;last ip; gateway;network
60 IFS=';' read -r -a EXTNET <<< "$EXTERNAL_NETWORK"
61 EXTNET_NAME=${EXTNET[0]}
62 EXTNET_TYPE=${EXTNET[1]}
63 EXTNET_FIP=${EXTNET[2]}
64 EXTNET_LIP=${EXTNET[3]}
65 EXTNET_GW=${EXTNET[4]}
66 EXTNET_NET=${EXTNET[5]}
69 ## Redeploy MAAS or recover the previous config
73 if [ -e "$LAB_CONFIG/environments.yaml" ] && [ "$MAAS_REINSTALL" == "false" ]; then
74 echo "------ Recover Juju environment to use MAAS ------"
75 cp $LAB_CONFIG/environments.yaml .
77 MAASCONFIG=$WORKSPACE/ci/maas/${POD/-*}/${POD/*-}/deployment.yaml
78 echo "------ Set MAAS password ------"
79 sed -i -- "s/user: ubuntu/user: $MAAS_USER/" $MAASCONFIG
80 sed -i -- "s/password: ubuntu/password: $MAAS_PASSWORD/" $MAASCONFIG
81 echo "------ Redeploy MAAS ------"
82 ./02-maasdeploy.sh $POD_NAME
83 exit_on_error $? "MAAS Deploy FAILED"
87 ## Configure Joid deployment
90 # Based on scenario naming we can get joid options
92 # os-<controller>-<nfvfeature>-<mode>[-<extrastuff>]
94 # controller=(nosdn|odl_l3|odl_l2|onos|ocl)
96 # nfvfeature=(kvm|ovs|dpdk|nofeature)
100 # Optional field - Not used today
102 IFS='-' read -r -a DEPLOY_OPTIONS <<< "${DEPLOY_SCENARIO}--"
103 #last -- need to avoid nounset error
105 SDN_CONTROLLER=${DEPLOY_OPTIONS[1]}
106 NFV_FEATURES=${DEPLOY_OPTIONS[2]}
107 HA_MODE=${DEPLOY_OPTIONS[3]}
108 EXTRA=${DEPLOY_OPTIONS[4]}
110 if [ "$SDN_CONTROLLER" == 'odl_l2' ] || [ "$SDN_CONTROLLER" == 'odl_l3' ]; then
113 if [ "$HA_MODE" == 'noha' ]; then
116 SRCBUNDLE="${WORKSPACE}/ci/${SDN_CONTROLLER}/juju-deployer/"
117 SRCBUNDLE="${SRCBUNDLE}/ovs-${SDN_CONTROLLER}-${HA_MODE}.yaml"
121 echo "------ Set openstack password ------"
122 sed -i -- "s/\"admin-password\": openstack/\"admin-password\": $OS_ADMIN_PASSWORD/" $SRCBUNDLE
124 if [ -n "$EXTNET_NAME" ]; then
125 echo "------ Set openstack default network ------"
126 sed -i -- "s/\"neutron-external-network\": ext_net/\"neutron-external-network\": $EXTNET_NAME/" $SRCBUNDLE
129 echo "------ Set ceph disks ------"
130 CEPH_DISKS_CONTROLLERS=${CEPH_DISKS_CONTROLLERS:-}
131 if [ -z "$CEPH_DISKS_CONTROLLERS" ]; then
132 CEPH_DISKS_CONTROLLERS=$CEPH_DISKS
135 #Find the first line of osd-devices to change the one for ceph, then the other for ceph-osd
136 CEPH_DEV_LINE=$(grep -nr osd-devices $SRCBUNDLE |head -n1|cut -d: -f1)
137 sed -i -- "${CEPH_DEV_LINE}s@osd-devices: /srv@osd-devices: $CEPH_DISKS@" $SRCBUNDLE
138 sed -i -- "s@osd-devices: /srv@osd-devices: $CEPH_DISKS_CONTROLLERS@" $SRCBUNDLE
139 sed -i -r -- "s/^(\s+osd-reformat: )'no'/\1'$CEPH_REFORMAT'/" $SRCBUNDLE
142 ## Configure Joid deployment
145 echo "------ Deploy with juju ------"
146 echo "Execute: ./deploy.sh -t $HA_MODE -o $OS_RELEASE -s $SDN_CONTROLLER -l $POD_NAME"
148 ./deploy.sh -t $HA_MODE -o $OS_RELEASE -s $SDN_CONTROLLER -l $POD_NAME
149 exit_on_error $? "Main deploy FAILED"
154 JOID_ADMIN_OPENRC=$LAB_CONFIG/admin-openrc
155 echo "------ Create OpenRC file [$JOID_ADMIN_OPENRC] ------"
158 KEYSTONE=$(cat bundles.yaml |shyaml get-value openstack-phase2.services.keystone.options.vip)
161 case "$SDN_CONTROLLER" in
163 SDN_CONTROLLER_IP=$(juju status odl-controller/0 |grep public-address|sed -- 's/.*\: //')
166 SDN_CONTROLLER_IP=$(juju status onos-controller/0 |grep public-address|sed -- 's/.*\: //')
169 SDN_CONTROLLER_IP='none'
174 # export the openrc file
175 cat << EOF > $JOID_ADMIN_OPENRC
176 export OS_USERNAME=admin
177 export OS_PASSWORD=$OS_ADMIN_PASSWORD
178 export OS_TENANT_NAME=admin
179 export OS_AUTH_URL=http://$KEYSTONE:5000/v2.0
180 export OS_REGION_NAME=Canonical
181 export SDN_CONTROLLER=$SDN_CONTROLLER_IP
182 export SDN_PASSWORD=$SDN_PASSWORD
186 ## Backup local juju env
189 echo "------ Backup Juju environment ------"
190 cp environments.yaml $LAB_CONFIG/
193 ## Basic test to return a realistic result to jenkins
196 echo "------ Do basic test ------"
197 source $JOID_ADMIN_OPENRC
198 curl -i -sw '%{http_code}' -H "Content-Type: application/json" -d "
201 \"methods\": [\"password\"],
205 \"domain\": { \"id\": \"default\" },
206 \"password\": \"$OS_ADMIN_PASSWORD\"
211 }" http://$KEYSTONE:5000/v3/auth/tokens |grep "HTTP/1.1 20" 2>&1 >/dev/null;
212 exit_on_error $? "Deploy FAILED to auth to openstack"
216 ## Create external network if needed
219 # If we have more information than only the name, try to create it
220 if [ -z "$EXTNET_TYPE" ]; then
221 echo "------ No data for external network creation, pass ------"
222 elif [[ "$DEPLOY_SCENARIO" =~ "onos" ]]; then
223 echo "------ ONOS have created the external network, pass ------"
225 echo "------ External network creation ------"
226 neutron net-create $EXTNET_NAME --router:external True \
227 --provider:physical_network external --provider:network_type $EXTNET_TYPE
228 exit_on_error $? "External network creation failed"
229 neutron subnet-create $EXTNET_NAME --name $EXTNET_NAME \
230 --allocation-pool start=$EXTNET_FIP,end=$EXTNET_LIP \
231 --disable-dhcp --gateway $EXTNET_GW $EXTNET_NET
232 exit_on_error $? "External subnet creation failed"
233 neutron net-update $EXTNET_NAME --shared
234 exit_on_error $? "External network sharing failed"
241 echo "Deploy success"