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 # Get juju deployer file
73 if [ "$HA_MODE" == 'nonha' ]; then
74 SRCBUNDLE=$WORKSPACE/ci/$SDN_CONTROLLER/juju-deployer/ovs-$SDN_CONTROLLER.yaml
76 SRCBUNDLE=$WORKSPACE/ci/$SDN_CONTROLLER/juju-deployer/ovs-$SDN_CONTROLLER-$HA_MODE.yaml
81 echo "------ Set openstack password ------"
82 sed -i -- "s/\"admin-password\": openstack/\"admin-password\": $OS_ADMIN_PASSWORD/" $SRCBUNDLE
84 echo "------ Set ceph disks ------"
85 CEPH_DISKS_CONTROLLERS=${CEPH_DISKS_CONTROLLERS:-}
86 if [ -z "$CEPH_DISKS_CONTROLLERS" ]; then
87 CEPH_DISKS_CONTROLLERS=$CEPH_DISKS
90 #Find the first line of osd-devices to change the one for ceph, then the other for ceph-osd
91 CEPH_DEV_LINE=$(grep -nr osd-devices $SRCBUNDLE |head -n1|cut -d: -f1)
92 sed -i -- "${CEPH_DEV_LINE}s@osd-devices: /srv@osd-devices: $CEPH_DISKS@" $SRCBUNDLE
93 sed -i -- "s@osd-devices: /srv@osd-devices: $CEPH_DISKS_CONTROLLERS@" $SRCBUNDLE
94 sed -i -r -- "s/^(\s+osd-reformat: )'no'/\1'$CEPH_REFORMAT'/" $SRCBUNDLE
97 ## Configure Joid deployment
100 echo "------ Deploy with juju ------"
101 echo "Execute: ./deploy.sh -t $HA_MODE -o $OS_RELEASE -s $SDN_CONTROLLER -l $POD_NAME"
103 ./deploy.sh -t $HA_MODE -o $OS_RELEASE -s $SDN_CONTROLLER -l $POD_NAME
104 exit_on_error $? "Main deploy FAILED"
109 JOID_ADMIN_OPENRC=$LAB_CONFIG/admin-openrc
110 echo "------ Create OpenRC file [$JOID_ADMIN_OPENRC] ------"
111 KEYSTONE=$(cat bundles.yaml |shyaml get-value openstack-phase2.services.keystone.options.vip)
113 # export the openrc file
114 cat << EOF > $JOID_ADMIN_OPENRC
115 export OS_USERNAME=admin
116 export OS_PASSWORD=$OS_ADMIN_PASSWORD
117 export OS_TENANT_NAME=admin
118 export OS_AUTH_URL=http://$KEYSTONE:5000/v2.0
119 export OS_REGION_NAME=Canonical
123 ## Backup local juju env
126 echo "------ Backup Juju environment ------"
127 cp environments.yaml $LAB_CONFIG/
130 ## Basic test to return a realistic result to jenkins
133 echo "------ Do basic test ------"
134 source $JOID_ADMIN_OPENRC
135 curl -i -sw '%{http_code}' -H "Content-Type: application/json" -d "
138 \"methods\": [\"password\"],
142 \"domain\": { \"id\": \"default\" },
143 \"password\": \"$OS_ADMIN_PASSWORD\"
148 }" http://$KEYSTONE:5000/v3/auth/tokens |grep "HTTP/1.1 20" 2>&1 >/dev/null;
149 exit_on_error $? "Deploy FAILED to auth to openstack"
153 ## Create external network if needed
156 EXTERNAL_NETWORK=${EXTERNAL_NETWORK:-}
157 # split EXTERNAL_NETWORK=name;type;first ip;last ip; gateway;network
158 IFS=';' read -r -a EXTNET <<< "$EXTERNAL_NETWORK"
159 EXTNET_NAME=${EXTNET[0]}
160 EXTNET_TYPE=${EXTNET[1]}
161 EXTNET_FIP=${EXTNET[2]}
162 EXTNET_LIP=${EXTNET[3]}
163 EXTNET_GW=${EXTNET[4]}
164 EXTNET_NET=${EXTNET[5]}
165 # If we have more information than only the name, try to create it
166 if [ -z "$EXTNET_TYPE" ]; then
167 echo "------ No data for external network creation, pass ------"
169 echo "------ External network creation ------"
170 neutron net-create $EXTNET_NAME --router:external True \
171 --provider:physical_network external --provider:network_type $EXTNET_TYPE
172 exit_on_error $? "External network creation failed"
173 neutron subnet-create $EXTNET_NAME --name $EXTNET_NAME \
174 --allocation-pool start=$EXTNET_FIP,end=$EXTNET_LIP \
175 --disable-dhcp --gateway $EXTNET_GW $EXTNET_NET
176 exit_on_error $? "External subnet creation failed"
183 echo "Deploy success"