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