Correct bad var name
[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 ## Create LAB_CONFIG folder if not exists
9 ##
10 mkdir -p $LAB_CONFIG
11
12 ##
13 ## Override default passwords with local settings if needed
14 ##
15
16 if [ -e "$LAB_CONFIG/$PWD_FILENAME" ]; then
17     echo "------ Load local passwords ------"
18     source $LAB_CONFIG/$PWD_FILENAME
19 fi
20
21 ##
22 ## Set Joid pod config name
23 ##
24     # This part will be removed when pod names will be synced between jenkins and joid config
25     case $NODE_NAME in
26         orange-fr-pod2)
27             POD=orange-pod2 ;;
28         *)
29             POD=$NODE_NAME ;;
30     esac
31     export POD_NAME=${POD/-}
32
33 ##
34 ## Redeploy MAAS or recover the previous config
35 ##
36
37 cd $WORKSPACE/ci
38 if [ -e "$LAB_CONFIG/environments.yaml" ] && [ "$MAAS_REINSTALL" == "false" ]; then
39     echo "------ Recover Juju environment to use MAAS ------"
40     cp $LAB_CONFIG/environments.yaml .
41 else
42     MAASCONFIG=$WORKSPACE/ci/maas/${POD/-*}/${POD/*-}/deployment.yaml
43     echo "------ Set MAAS password ------"
44     if [ -n "$MAAS_USER" ]; then
45         sed -i -- "s/user: ubuntu/user: $MAAS_USER/" $MAASCONFIG
46     fi
47     if [ -n "$MAAS_PASSWORD" ]; then
48         sed -i -- "s/password: ubuntu/password: $MAAS_PASSWORD/" $MAASCONFIG
49     fi
50     echo "------ Redeploy MAAS ------"
51     ./02-maasdeploy.sh $POD_NAME
52     RES=$?
53     if [ $RES != 0 ]; then
54         echo "MAAS Deploy FAILED"
55         exit $RES
56     fi
57 fi
58
59 ##
60 ## Configure Joid deployment
61 ##
62
63 # Get juju deployer file
64 if [ "$HA_MODE" == 'nonha' ]; then
65     SRCBUNDLE=$WORKSPACE/ci/$SDN_CONTROLLER/juju-deployer/ovs-$SDN_CONTROLLER.yaml
66 else
67     SRCBUNDLE=$WORKSPACE/ci/$SDN_CONTROLLER/juju-deployer/ovs-$SDN_CONTROLLER-$HA_MODE.yaml
68 fi
69
70 # Modify files
71
72 echo "------ Set openstack password ------"
73 if [ -n "$OS_ADMIN_PASSWORD" ]; then
74     sed -i -- "s/\"admin-password\": openstack/\"admin-password\": $OS_ADMIN_PASSWORD/" $SRCBUNDLE
75 fi
76
77 echo "------ Set ceph disks ------"
78 if [ -z "$CEPH_DISKS_CONTROLLERS" ]; then
79     CEPH_DISKS_CONTROLLERS=$CEPH_DISKS
80 fi
81 #Find the first line of osd-devices to change the one for ceph, then the other for ceph-osd
82 CEPH_DEV_LINE=$(grep -nr osd-devices $SRCBUNDLE |head -n1|cut -d: -f1)
83 sed -i -- "${CEPH_DEV_LINE}s@osd-devices: /srv@osd-devices: $CEPH_DISKS@" $SRCBUNDLE
84 sed -i -- "s@osd-devices: /srv@osd-devices: $CEPH_DISKS_CONTROLLERS@" $SRCBUNDLE
85 sed -i -r -- "s/^(\s+osd-reformat: )'no'/\1'$CEPH_REFORMAT'/" $SRCBUNDLE
86
87 ##
88 ## Configure Joid deployment
89 ##
90
91 echo "------ Deploy with juju ------"
92 echo "Execute: ./deploy.sh -t $HA_MODE -o $OS_RELEASE -s $SDN_CONTROLLER -l $POD_NAME"
93
94 ./deploy.sh -t $HA_MODE -o $OS_RELEASE -s $SDN_CONTROLLER -l $POD_NAME
95 RES=$?
96 if [ $RES != 0 ]; then
97     echo "Deploy FAILED"
98     exit $RES
99 fi
100
101 ##
102 ## Set Admin RC
103 ##
104 JOID_ADMIN_OPENRC=$LAB_CONFIG/admin-openrc
105 echo "------ Create OpenRC file [$JOID_ADMIN_OPENRC] ------"
106 KEYSTONE=$(cat bundles.yaml |shyaml get-value openstack-phase2.services.keystone.options.vip)
107
108 # export the openrc file
109 cat << EOF > $JOID_ADMIN_OPENRC
110 export OS_USERNAME=admin
111 export OS_PASSWORD=$OS_ADMIN_PASSWORD
112 export OS_TENANT_NAME=admin
113 export OS_AUTH_URL=http://$KEYSTONE:5000/v2.0
114 export OS_REGION_NAME=Canonical
115 EOF
116
117 ##
118 ## Backup local juju env
119 ##
120
121 echo "------ Backup Juju environment ------"
122 cp environments.yaml $LAB_CONFIG/
123
124 ##
125 ## Basic test to return a realistic result to jenkins
126 ##
127
128 echo "------ Do basic test ------"
129 source $JOID_ADMIN_OPENRC
130 curl -i -sw '%{http_code}' -H "Content-Type: application/json"   -d "
131 { \"auth\": {
132     \"identity\": {
133       \"methods\": [\"password\"],
134       \"password\": {
135         \"user\": {
136           \"name\": \"admin\",
137           \"domain\": { \"id\": \"default\" },
138           \"password\": \"$OS_ADMIN_PASSWORD\"
139         }
140       }
141     }
142   }
143 }"   http://$KEYSTONE:5000/v3/auth/tokens |grep "HTTP/1.1 20" 2>&1 >/dev/null;
144 RES=$?
145 if [ $RES == 0 ]; then
146     echo "Deploy SUCCESS"
147 else
148     echo "Deploy FAILED to auth to openstack"
149 fi
150 exit $RES