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