joid: add juniper pod1
[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         juniper-us-test-1)
46             POD=juniper-pod1 ;;
47         *)
48             POD=$NODE_NAME ;;
49     esac
50     export POD_NAME=${POD/-}
51
52 ##
53 ## Redeploy MAAS or recover the previous config
54 ##
55
56 cd $WORKSPACE/ci
57 if [ -e "$LAB_CONFIG/environments.yaml" ] && [ "$MAAS_REINSTALL" == "false" ]; then
58     echo "------ Recover Juju environment to use MAAS ------"
59     cp $LAB_CONFIG/environments.yaml .
60 else
61     MAASCONFIG=$WORKSPACE/ci/maas/${POD/-*}/${POD/*-}/deployment.yaml
62     echo "------ Set MAAS password ------"
63     sed -i -- "s/user: ubuntu/user: $MAAS_USER/" $MAASCONFIG
64     sed -i -- "s/password: ubuntu/password: $MAAS_PASSWORD/" $MAASCONFIG
65     echo "------ Redeploy MAAS ------"
66     ./02-maasdeploy.sh $POD_NAME
67     exit_on_error $? "MAAS Deploy FAILED"
68 fi
69
70 ##
71 ## Configure Joid deployment
72 ##
73
74 # Based on scenario naming we can get joid options
75 # naming convention:
76 #    os-<controller>-<nfvfeature>-<mode>[-<extrastuff>]
77 # With parameters:
78 #    controller=(nosdn|odl_l3|odl_l2|onos|ocl)
79 #       No odl_l3 today
80 #    nfvfeature=(kvm|ovs|dpdk|nofeature)
81 #       '_' list separated.
82 #    mode=(ha|noha)
83 #    extrastuff=(none)
84 #       Optional field - Not used today
85
86 IFS='-' read -r -a DEPLOY_OPTIONS <<< "${DEPLOY_SCENARIO}--"
87 #last -- need to avoid nounset error
88
89 SDN_CONTROLLER=${DEPLOY_OPTIONS[1]}
90 NFV_FEATURES=${DEPLOY_OPTIONS[2]}
91 HA_MODE=${DEPLOY_OPTIONS[3]}
92 EXTRA=${DEPLOY_OPTIONS[4]}
93
94 # Get the juju config path with those options, later we will directly use
95 # scenario name
96 case $SDN_CONTROLLER in
97     odl_l2)
98         SRCBUNDLE="ovs-odl"
99         SDN_CONTROLLER="odl"
100         ;;
101     onos)
102         SRCBUNDLE="onos"
103         ;;
104     ocl)
105         SRCBUNDLE="contrail"
106         SDN_CONTROLLER="opencontrail"
107         ;;
108     *)
109         SRCBUNDLE="ovs"
110         echo "${SDN_CONTROLLER} not in SDN controllers list, using 'nosdn' setting"
111         SDN_CONTROLLER="nosdn"
112         ;;
113     esac
114 SRCBUNDLE="${WORKSPACE}/ci/${SDN_CONTROLLER}/juju-deployer/${SRCBUNDLE}"
115 if [ "$HA_MODE" == 'noha' ]; then
116     SRCBUNDLE="${SRCBUNDLE}.yaml"
117     HA_MODE == 'nonha'
118 else
119     SRCBUNDLE="${SRCBUNDLE}-${HA_MODE}.yaml"
120 fi
121
122 # Modify files
123
124 echo "------ Set openstack password ------"
125 sed -i -- "s/\"admin-password\": openstack/\"admin-password\": $OS_ADMIN_PASSWORD/" $SRCBUNDLE
126
127 echo "------ Set ceph disks ------"
128 CEPH_DISKS_CONTROLLERS=${CEPH_DISKS_CONTROLLERS:-}
129 if [ -z "$CEPH_DISKS_CONTROLLERS" ]; then
130     CEPH_DISKS_CONTROLLERS=$CEPH_DISKS
131 fi
132
133 #Find the first line of osd-devices to change the one for ceph, then the other for ceph-osd
134 CEPH_DEV_LINE=$(grep -nr osd-devices $SRCBUNDLE |head -n1|cut -d: -f1)
135 sed -i -- "${CEPH_DEV_LINE}s@osd-devices: /srv@osd-devices: $CEPH_DISKS@" $SRCBUNDLE
136 sed -i -- "s@osd-devices: /srv@osd-devices: $CEPH_DISKS_CONTROLLERS@" $SRCBUNDLE
137 sed -i -r -- "s/^(\s+osd-reformat: )'no'/\1'$CEPH_REFORMAT'/" $SRCBUNDLE
138
139 ##
140 ## Configure Joid deployment
141 ##
142
143 echo "------ Deploy with juju ------"
144 echo "Execute: ./deploy.sh -t $HA_MODE -o $OS_RELEASE -s $SDN_CONTROLLER -l $POD_NAME"
145
146 ./deploy.sh -t $HA_MODE -o $OS_RELEASE -s $SDN_CONTROLLER -l $POD_NAME
147 exit_on_error $? "Main deploy FAILED"
148
149 ##
150 ## Set Admin RC
151 ##
152 JOID_ADMIN_OPENRC=$LAB_CONFIG/admin-openrc
153 echo "------ Create OpenRC file [$JOID_ADMIN_OPENRC] ------"
154 KEYSTONE=$(cat bundles.yaml |shyaml get-value openstack-phase2.services.keystone.options.vip)
155
156 # export the openrc file
157 cat << EOF > $JOID_ADMIN_OPENRC
158 export OS_USERNAME=admin
159 export OS_PASSWORD=$OS_ADMIN_PASSWORD
160 export OS_TENANT_NAME=admin
161 export OS_AUTH_URL=http://$KEYSTONE:5000/v2.0
162 export OS_REGION_NAME=Canonical
163 EOF
164
165 ##
166 ## Backup local juju env
167 ##
168
169 echo "------ Backup Juju environment ------"
170 cp environments.yaml $LAB_CONFIG/
171
172 ##
173 ## Basic test to return a realistic result to jenkins
174 ##
175
176 echo "------ Do basic test ------"
177 source $JOID_ADMIN_OPENRC
178 curl -i -sw '%{http_code}' -H "Content-Type: application/json"   -d "
179 { \"auth\": {
180     \"identity\": {
181       \"methods\": [\"password\"],
182       \"password\": {
183         \"user\": {
184           \"name\": \"admin\",
185           \"domain\": { \"id\": \"default\" },
186           \"password\": \"$OS_ADMIN_PASSWORD\"
187         }
188       }
189     }
190   }
191 }"   http://$KEYSTONE:5000/v3/auth/tokens |grep "HTTP/1.1 20" 2>&1 >/dev/null;
192 exit_on_error $? "Deploy FAILED to auth to openstack"
193
194
195 ##
196 ## Create external network if needed
197 ##
198
199 EXTERNAL_NETWORK=${EXTERNAL_NETWORK:-}
200 # split EXTERNAL_NETWORK=name;type;first ip;last ip; gateway;network
201 IFS=';' read -r -a EXTNET <<< "$EXTERNAL_NETWORK"
202 EXTNET_NAME=${EXTNET[0]}
203 EXTNET_TYPE=${EXTNET[1]}
204 EXTNET_FIP=${EXTNET[2]}
205 EXTNET_LIP=${EXTNET[3]}
206 EXTNET_GW=${EXTNET[4]}
207 EXTNET_NET=${EXTNET[5]}
208 # If we have more information than only the name, try to create it
209 if [ -z "$EXTNET_TYPE" ]; then
210     echo "------ No data for external network creation, pass ------"
211 else
212     echo "------ External network creation ------"
213     neutron net-create $EXTNET_NAME --router:external True \
214       --provider:physical_network external --provider:network_type $EXTNET_TYPE
215     exit_on_error $? "External network creation failed"
216     neutron subnet-create $EXTNET_NAME --name $EXTNET_NAME \
217       --allocation-pool start=$EXTNET_FIP,end=$EXTNET_LIP \
218       --disable-dhcp --gateway $EXTNET_GW $EXTNET_NET
219     exit_on_error $? "External subnet creation failed"
220 fi
221
222 ##
223 ## Exit success
224 ##
225
226 echo "Deploy success"
227 exit 0