Download OCL container packages from OPNFV artifact repo (if not present).
[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     waitstatus=$1
29     retval=0
30     timeoutiter=0
31
32     echo -n "executing the reltionship within charms ."
33     while [ $retval -eq 0 ]; do
34         if juju status | grep -q $waitstatus; then
35            echo -n '.'
36            if [ $timeoutiter -ge 240 ]; then
37                echo 'timed out'
38                retval=1
39            else
40                sleep 30
41            fi
42            timeoutiter=$((timeoutiter+1))
43        else
44            echo 'done'
45            retval=1
46        fi
47     done
48     echo "...... deployment finishing ......."
49 }
50
51 #read the value from deployconfig.yaml
52
53 PROFILE=maas
54 MAAS_IP=$(grep " ip_address" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //')
55 API_SERVERMAAS="http://$MAAS_IP/MAAS/"
56 if [[ "$maasver" > "2" ]]; then
57     API_KEY=`sudo maas-region apikey --username=ubuntu || true`
58 else
59     API_KEY=`sudo maas-region-admin apikey --username=ubuntu || true`
60 fi
61
62
63 if [[ "$API_KEY" = "" ]]; then
64     if [[ "$maasver" > "2" ]]; then
65         API_KEY=`sshpass -p ubuntu ssh ubuntu@$MAAS_IP 'sudo maas-region apikey --username=ubuntu'`
66     else
67         API_KEY=`sshpass -p ubuntu ssh ubuntu@$MAAS_IP 'sudo maas-region-admin apikey --username=ubuntu'`
68     fi
69 fi
70
71 maas login $PROFILE $API_SERVERMAAS $API_KEY
72
73 if [[ "$opnfvmodel" = "openstack" ]]; then
74     if [ -e ./deployconfig.yaml ]; then
75        extport=`grep "ext-port" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //' | tr ',' ' '`
76        datanet=`grep "dataNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
77        admnet=`grep "admNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
78        cephdisk=`grep "ceph-disk" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
79        osdomname=`grep "os-domain-name" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
80     fi
81
82     if [[ "$maasver" > "2" ]]; then
83         workmutiple=`maas maas nodes read | grep "cpu_count" | cut -d ':' -f 2 | sed -e 's/ //' | tr ',' ' '`
84     else
85         workmutiple=`maas maas nodes list | grep "cpu_count" | cut -d ':' -f 2 | sed -e 's/ //' | tr ',' ' '`
86     fi
87     max=0
88     for v in ${workmutiple[@]}; do
89         if (( $v > $max )); then max=$v; fi;
90     done
91     echo $max
92
93     if [ "$max" -lt 4 ];then
94         workmutiple=1.1
95     elif [ "$max" -lt 33 ]; then
96         workmutiple=0.25
97     elif [ "$max" -lt 73 ]; then
98         workmutiple=0.1
99     else
100         workmutiple=0.05
101     fi
102     sed -i "s/worker_multiplier: 1.0/worker_multiplier: ${workmutiple}/g" default_deployment_config.yaml
103
104     if [ "$opnfvlab" != "default" ]; then
105         sed -i "s/cpu_pin_set: all/cpu_pin_set: 2-${max},^${max}/g" default_deployment_config.yaml
106     else
107         sed -i "s/cpu_pin_set: all/cpu_pin_set: 1/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 allocating
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 if [ "$opnfvsdn" = "ocl" ]
186 then
187   ROLES="contrail-controller contrail-analytics contrail-analyticsdb"
188   TAG="ubuntu16.04-4.0.0.0-20.tar.gz"
189
190   for ROLE in $ROLES
191   do
192     FILE="${ROLE}-${TAG}"
193   if [ ! -f $FILE ]
194   then
195     curl -o $FILE http://artifacts.opnfv.org/ovno/containers/$FILE
196   fi
197   juju attach $ROLE ${ROLE}="./$FILE"
198 done
199 fi
200 #lets gather the status of deployment once juju-deployer completed.
201 juju status --format=tabular