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