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
48 export POD_NAME=${POD/-}
51 ## Redeploy MAAS or recover the previous config
55 if [ -e "$LAB_CONFIG/environments.yaml" ] && [ "$MAAS_REINSTALL" == "false" ]; then
56 echo "------ Recover Juju environment to use MAAS ------"
57 cp $LAB_CONFIG/environments.yaml .
59 MAASCONFIG=$WORKSPACE/ci/maas/${POD/-*}/${POD/*-}/deployment.yaml
60 echo "------ Set MAAS password ------"
61 sed -i -- "s/user: ubuntu/user: $MAAS_USER/" $MAASCONFIG
62 sed -i -- "s/password: ubuntu/password: $MAAS_PASSWORD/" $MAASCONFIG
63 echo "------ Redeploy MAAS ------"
64 ./02-maasdeploy.sh $POD_NAME
65 exit_on_error $? "MAAS Deploy FAILED"
69 ## Configure Joid deployment
72 # Based on scenario naming we can get joid options
74 # os-<controller>-<nfvfeature>-<mode>[-<extrastuff>]
76 # controller=(nosdn|odl_l3|odl_l2|onos|ocl)
78 # nfvfeature=(kvm|ovs|dpdk|nofeature)
82 # Optional field - Not used today
84 IFS='-' read -r -a DEPLOY_OPTIONS <<< "${DEPLOY_SCENARIO}--"
85 #last -- need to avoid nounset error
87 SDN_CONTROLLER=${DEPLOY_OPTIONS[1]}
88 NFV_FEATURES=${DEPLOY_OPTIONS[2]}
89 HA_MODE=${DEPLOY_OPTIONS[3]}
90 EXTRA=${DEPLOY_OPTIONS[4]}
92 # Get the juju config path with those options, later we will directly use
94 case $SDN_CONTROLLER in
103 SDN_CONTROLLER="opencontrail"
107 echo "${SDN_CONTROLLER} not in SDN controllers list, using 'nosdn' setting"
108 SDN_CONTROLLER="nosdn"
111 SRCBUNDLE="${WORKSPACE}/ci/${SDN_CONTROLLER}/juju-deployer/${SRCBUNDLE}"
112 if [ "$HA_MODE" == 'noha' ]; then
113 SRCBUNDLE="${SRCBUNDLE}.yaml"
116 SRCBUNDLE="${SRCBUNDLE}-${HA_MODE}.yaml"
121 echo "------ Set openstack password ------"
122 sed -i -- "s/\"admin-password\": openstack/\"admin-password\": $OS_ADMIN_PASSWORD/" $SRCBUNDLE
124 echo "------ Set ceph disks ------"
125 CEPH_DISKS_CONTROLLERS=${CEPH_DISKS_CONTROLLERS:-}
126 if [ -z "$CEPH_DISKS_CONTROLLERS" ]; then
127 CEPH_DISKS_CONTROLLERS=$CEPH_DISKS
130 #Find the first line of osd-devices to change the one for ceph, then the other for ceph-osd
131 CEPH_DEV_LINE=$(grep -nr osd-devices $SRCBUNDLE |head -n1|cut -d: -f1)
132 sed -i -- "${CEPH_DEV_LINE}s@osd-devices: /srv@osd-devices: $CEPH_DISKS@" $SRCBUNDLE
133 sed -i -- "s@osd-devices: /srv@osd-devices: $CEPH_DISKS_CONTROLLERS@" $SRCBUNDLE
134 sed -i -r -- "s/^(\s+osd-reformat: )'no'/\1'$CEPH_REFORMAT'/" $SRCBUNDLE
137 ## Configure Joid deployment
140 echo "------ Deploy with juju ------"
141 echo "Execute: ./deploy.sh -t $HA_MODE -o $OS_RELEASE -s $SDN_CONTROLLER -l $POD_NAME"
143 ./deploy.sh -t $HA_MODE -o $OS_RELEASE -s $SDN_CONTROLLER -l $POD_NAME
144 exit_on_error $? "Main deploy FAILED"
149 JOID_ADMIN_OPENRC=$LAB_CONFIG/admin-openrc
150 echo "------ Create OpenRC file [$JOID_ADMIN_OPENRC] ------"
151 KEYSTONE=$(cat bundles.yaml |shyaml get-value openstack-phase2.services.keystone.options.vip)
153 # export the openrc file
154 cat << EOF > $JOID_ADMIN_OPENRC
155 export OS_USERNAME=admin
156 export OS_PASSWORD=$OS_ADMIN_PASSWORD
157 export OS_TENANT_NAME=admin
158 export OS_AUTH_URL=http://$KEYSTONE:5000/v2.0
159 export OS_REGION_NAME=Canonical
163 ## Backup local juju env
166 echo "------ Backup Juju environment ------"
167 cp environments.yaml $LAB_CONFIG/
170 ## Basic test to return a realistic result to jenkins
173 echo "------ Do basic test ------"
174 source $JOID_ADMIN_OPENRC
175 curl -i -sw '%{http_code}' -H "Content-Type: application/json" -d "
178 \"methods\": [\"password\"],
182 \"domain\": { \"id\": \"default\" },
183 \"password\": \"$OS_ADMIN_PASSWORD\"
188 }" http://$KEYSTONE:5000/v3/auth/tokens |grep "HTTP/1.1 20" 2>&1 >/dev/null;
189 exit_on_error $? "Deploy FAILED to auth to openstack"
193 ## Create external network if needed
196 EXTERNAL_NETWORK=${EXTERNAL_NETWORK:-}
197 # split EXTERNAL_NETWORK=name;type;first ip;last ip; gateway;network
198 IFS=';' read -r -a EXTNET <<< "$EXTERNAL_NETWORK"
199 EXTNET_NAME=${EXTNET[0]}
200 EXTNET_TYPE=${EXTNET[1]}
201 EXTNET_FIP=${EXTNET[2]}
202 EXTNET_LIP=${EXTNET[3]}
203 EXTNET_GW=${EXTNET[4]}
204 EXTNET_NET=${EXTNET[5]}
205 # If we have more information than only the name, try to create it
206 if [ -z "$EXTNET_TYPE" ]; then
207 echo "------ No data for external network creation, pass ------"
209 echo "------ External network creation ------"
210 neutron net-create $EXTNET_NAME --router:external True \
211 --provider:physical_network external --provider:network_type $EXTNET_TYPE
212 exit_on_error $? "External network creation failed"
213 neutron subnet-create $EXTNET_NAME --name $EXTNET_NAME \
214 --allocation-pool start=$EXTNET_FIP,end=$EXTNET_LIP \
215 --disable-dhcp --gateway $EXTNET_GW $EXTNET_NET
216 exit_on_error $? "External subnet creation failed"
223 echo "Deploy success"