b50923f98aaf893c0cbc41ac5206245d782e17e9
[releng.git] / jjb / joid / joid-deploy.sh
1 #!/bin/bash
2 set +e
3 set -o nounset
4
5 PWD_FILENAME="passwords.sh"
6
7 ##
8 ##
9 ##
10 function exit_on_error {
11     RES=$1
12     MSG=$2
13     if [ $RES != 0 ]; then
14         echo "FAILED - $MSG"
15         exit $RES
16     fi
17 }
18
19
20 ##
21 ## Create LAB_CONFIG folder if not exists
22 ##
23 mkdir -p $LAB_CONFIG
24
25 ##
26 ## Override default passwords with local settings if needed
27 ##
28
29 if [ -e "$LAB_CONFIG/$PWD_FILENAME" ]; then
30     echo "------ Load local passwords ------"
31     source $LAB_CONFIG/$PWD_FILENAME
32 else
33     export MAAS_USER=ubuntu
34     export MAAS_PASSWORD=ubuntu
35     export OS_ADMIN_PASSWORD=openstack
36 fi
37
38 ##
39 ## Set Joid pod config name
40 ##
41     # This part will be removed when pod names will be synced between jenkins and joid config
42     case $NODE_NAME in
43         orange-fr-pod2)
44             POD=orange-pod2 ;;
45         *)
46             POD=$NODE_NAME ;;
47     esac
48     export POD_NAME=${POD/-}
49
50 ##
51 ## Redeploy MAAS or recover the previous config
52 ##
53
54 cd $WORKSPACE/ci
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 .
58 else
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"
66 fi
67
68 ##
69 ## Configure Joid deployment
70 ##
71
72 # Based on scenario naming we can get joid options
73 # naming convention:
74 #    os-<controller>-<nfvfeature>-<mode>[-<extrastuff>]
75 # With parameters:
76 #    controller=(nosdn|odl_l3|odl_l2|onos|ocl)
77 #       No odl_l3 today
78 #    nfvfeature=(kvm|ovs|dpdk|nofeature)
79 #       '_' list separated.
80 #    mode=(ha|noha)
81 #    extrastuff=(none)
82 #       Optional field - Not used today
83
84 IFS='-' read -r -a DEPLOY_OPTIONS <<< "${DEPLOY_SCENARIO}--"
85 #last -- need to avoid nounset error
86
87 SDN_CONTROLLER=${DEPLOY_OPTIONS[1]}
88 NFV_FEATURES=${DEPLOY_OPTIONS[2]}
89 HA_MODE=${DEPLOY_OPTIONS[3]}
90 EXTRA=${DEPLOY_OPTIONS[4]}
91
92 # Get the juju config path with those options, later we will directly use
93 # scenario name
94 case $SDN_CONTROLLER in
95     odl_l2)
96         SRCBUNDLE="ovs-odl"
97         ;;
98     onos)
99         SRCBUNDLE="onos"
100         ;;
101     ocl)
102         SRCBUNDLE="contrail"
103         SDN_CONTROLLER="opencontrail"
104         ;;
105     *)
106         SRCBUNDLE="ovs"
107         echo "${SDN_CONTROLLER} not in SDN controllers list, using 'nosdn' setting"
108         SDN_CONTROLLER="nosdn"
109         ;;
110     esac
111 SRCBUNDLE="${WORKSPACE}/ci/${SDN_CONTROLLER}/juju-deployer/${SRCBUNDLE}"
112 if [ "$HA_MODE" == 'noha' ]; then
113     SRCBUNDLE="${SRCBUNDLE}.yaml"
114     HA_MODE == 'nonha'
115 else
116     SRCBUNDLE="${SRCBUNDLE}-${HA_MODE}.yaml"
117 fi
118
119 # Modify files
120
121 echo "------ Set openstack password ------"
122 sed -i -- "s/\"admin-password\": openstack/\"admin-password\": $OS_ADMIN_PASSWORD/" $SRCBUNDLE
123
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
128 fi
129
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
135
136 ##
137 ## Configure Joid deployment
138 ##
139
140 echo "------ Deploy with juju ------"
141 echo "Execute: ./deploy.sh -t $HA_MODE -o $OS_RELEASE -s $SDN_CONTROLLER -l $POD_NAME"
142
143 ./deploy.sh -t $HA_MODE -o $OS_RELEASE -s $SDN_CONTROLLER -l $POD_NAME
144 exit_on_error $? "Main deploy FAILED"
145
146 ##
147 ## Set Admin RC
148 ##
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)
152
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
160 EOF
161
162 ##
163 ## Backup local juju env
164 ##
165
166 echo "------ Backup Juju environment ------"
167 cp environments.yaml $LAB_CONFIG/
168
169 ##
170 ## Basic test to return a realistic result to jenkins
171 ##
172
173 echo "------ Do basic test ------"
174 source $JOID_ADMIN_OPENRC
175 curl -i -sw '%{http_code}' -H "Content-Type: application/json"   -d "
176 { \"auth\": {
177     \"identity\": {
178       \"methods\": [\"password\"],
179       \"password\": {
180         \"user\": {
181           \"name\": \"admin\",
182           \"domain\": { \"id\": \"default\" },
183           \"password\": \"$OS_ADMIN_PASSWORD\"
184         }
185       }
186     }
187   }
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"
190
191
192 ##
193 ## Create external network if needed
194 ##
195
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 ------"
208 else
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"
217 fi
218
219 ##
220 ## Exit success
221 ##
222
223 echo "Deploy success"
224 exit 0