modified to get the juju 2.1.0 as release juju version.
[joid.git] / ci / 02-deploybundle.sh
1 #!/bin/bash
2 #placeholder for deployment script.
3 set -ex
4
5 #    ./02-deploybundle.sh $opnfvtype $openstack $opnfvlab $opnfvsdn $opnfvfeature $opnfvdistro
6
7 opnfvtype=$1
8 openstack=$2
9 opnfvlab=$3
10 opnfvsdn=$4
11 opnfvfeature=$5
12 opnfvdistro=$6
13 opnfvmodel=$7
14
15 jujuver=`juju --version`
16 maasver=`apt-cache policy maas | grep Installed | cut -d ':' -f 2 | sed -e 's/ //'`
17
18 if [[ "$opnfvmodel" = "openstack" ]]; then
19     #copy and download charms
20     ./$opnfvsdn/fetch-charms.sh $opnfvdistro
21     osdomname=''
22 else
23     ./kubernetes/fetch-charms.sh $opnfvdistro
24 fi
25
26 #check whether charms are still executing the code even juju-deployer says installed.
27 check_status() {
28     retval=0
29     timeoutiter=0
30     while [ $retval -eq 0 ]; do
31        sleep 30
32        juju status > status.txt
33        if [ "$(grep -c "waiting" status.txt )" -ge 2 ]; then
34            echo " still waiting for machines ..."
35            if [ $timeoutiter -ge 240 ]; then
36                retval=1
37            fi
38            timeoutiter=$((timeoutiter+1))
39        else
40            retval=1
41        fi
42     done
43     echo "...... deployment finishing ......."
44 }
45
46 #read the value from deployconfig.yaml
47
48 PROFILE=maas
49 MAAS_IP=$(grep " ip_address" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //')
50 API_SERVERMAAS="http://$MAAS_IP/MAAS/"
51 if [[ "$maasver" > "2" ]]; then
52     API_KEY=`sudo maas-region apikey --username=ubuntu || true`
53 else
54     API_KEY=`sudo maas-region-admin apikey --username=ubuntu || true`
55 fi
56
57
58 if [[ "$API_KEY" = "" ]]; then
59     if [[ "$maasver" > "2" ]]; then
60         API_KEY=`sshpass -p ubuntu ssh ubuntu@$MAAS_IP 'sudo maas-region apikey --username=ubuntu'`
61     else
62         API_KEY=`sshpass -p ubuntu ssh ubuntu@$MAAS_IP 'sudo maas-region-admin apikey --username=ubuntu'`
63     fi
64 fi
65
66 maas login $PROFILE $API_SERVERMAAS $API_KEY
67
68 if [[ "$opnfvmodel" = "openstack" ]]; then
69     if [ -e ./deployconfig.yaml ]; then
70        extport=`grep "ext-port" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //' | tr ',' ' '`
71        datanet=`grep "dataNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
72        admnet=`grep "admNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
73        cephdisk=`grep "ceph-disk" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
74        osdomname=`grep "os-domain-name" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
75     fi
76
77     if [[ "$maasver" > "2" ]]; then
78         workmutiple=`maas maas nodes read | grep "cpu_count" | cut -d ':' -f 2 | sed -e 's/ //' | tr ',' ' '`
79     else
80         workmutiple=`maas maas nodes list | grep "cpu_count" | cut -d ':' -f 2 | sed -e 's/ //' | tr ',' ' '`
81     fi
82     max=0
83     for v in ${workmutiple[@]}; do
84         if (( $v > $max )); then max=$v; fi;
85     done
86     echo $max
87
88     if [ "$max" -lt 4 ];then
89         workmutiple=1.1
90     elif [ "$max" -lt 33 ]; then
91         workmutiple=0.25
92     elif [ "$max" -lt 73 ]; then
93         workmutiple=0.1
94     else
95         workmutiple=0.05
96     fi
97     sed -i "s/worker_multiplier: 1.0/worker_multiplier: ${workmutiple}/g" default_deployment_config.yaml
98
99     if [ "$opnfvlab" != "default" ]; then
100         sed -i "s/cpu_pin_set: all/cpu_pin_set: 2-${max},^${max}/g" default_deployment_config.yaml
101     else
102         sed -i "s/cpu_pin_set: all/cpu_pin_set: 1/g" default_deployment_config.yaml
103     fi
104 fi
105
106 case "$opnfvlab" in
107      'juniperpod1' )
108          sed -i -- 's/10.4.1.1/172.16.50.1/g' ./bundles.yaml
109          sed -i -- 's/#ext-port: "eth1"/ext-port: "eth1"/g' ./bundles.yaml
110          ;;
111      'ravellodemopod' )
112          sed -i -- 's/#ext-port: "eth1"/ext-port: "eth2"/g' ./bundles.yaml
113         ;;
114 esac
115
116 # lets put the if seperateor as "," as this will save me from world.
117 fea=""
118 IFS=","
119 for feature in $opnfvfeature; do
120     if [ "$fea" == "" ]; then
121         fea=$feature
122     else
123         fea=$fea"_"$feature
124     fi
125 done
126
127 if [[ "$opnfvmodel" = "openstack" ]]; then
128     #update source if trusty is target distribution
129     var=os-$opnfvsdn-$fea-$opnfvtype"-"$opnfvdistro"_"$openstack
130
131     if [ "$osdomname" != "None" ]; then
132         var=$var"_"publicapi
133     fi
134 else
135     var=k8-$opnfvsdn-$fea-baremetal-core
136 fi
137
138 if [[ "$opnfvmodel" = "openstack" ]]; then
139     #lets generate the bundle for all target using genBundle.py
140     python genBundle.py  -l deployconfig.yaml  -s $var > bundles.yaml
141 else
142     #lets generate the bundle for k8 target using genK8Bundle.py
143     python genK8Bundle.py  -l deployconfig.yaml  -s $var > bundles.yaml
144 fi
145
146 #keep the back in cloud for later debugging.
147 pastebinit bundles.yaml || true
148
149 if [[ "$jujuver" < "2" ]]; then
150     echo "... Deployment Started ...."
151     juju-deployer -vW -d -t 7200 -r 5 -c bundles.yaml $opnfvdistro-"$openstack"-nodes
152     count=`juju status nodes --format=short | grep nodes | wc -l`
153     c=0
154     while [ $c -lt $count ]; do
155         juju ssh nodes/$c 'echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p' || true
156         juju ssh nodes-compute/$c 'echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p' || true
157         juju ssh nodes/$c 'echo 2048 | sudo tee /proc/sys/fs/inotify/max_user_instances' || true
158         juju ssh nodes-compute/$c 'echo 2048 | sudo tee /proc/sys/fs/inotify/max_user_instances' || true
159         let c+=1
160     done
161
162     juju-deployer -vW -d -t 7200 -r 5 -c bundles.yaml $opnfvdistro-"$openstack" || true
163 else
164     # with JUJU 2.0 bundles has to be deployed only once.
165     juju deploy bundles.yaml --debug
166     sleep 120
167     check_status
168     # seeing issue related to number of open files.
169     count=`juju status nodes --format=short | grep nodes | wc -l`
170     c=0
171     while [ $c -lt $count ]; do
172         juju ssh nodes/$c 'echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p' || true
173         juju ssh nodes-compute/$c 'echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p' || true
174         juju ssh nodes/$c 'echo 2048 | sudo tee /proc/sys/fs/inotify/max_user_instances' || true
175         juju ssh nodes-compute/$c 'echo 2048 | sudo tee /proc/sys/fs/inotify/max_user_instances' || true
176         let c+=1
177     done
178 fi
179
180 #lets gather the status of deployment once juju-deployer completed.
181 juju status --format=tabular