Revert "modfiied to adjust timings as it seems download the container image is slow...
[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 180 ]; 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:5240/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 separator 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 else
137     var=k8-$opnfvsdn-$fea-baremetal-core
138 fi
139
140 if [[ "$opnfvmodel" = "openstack" ]]; then
141     #lets generate the bundle for all target using genBundle.py
142     python genBundle.py  -l deployconfig.yaml  -s $var > bundles.yaml
143 else
144     #lets generate the bundle for k8 target using genK8Bundle.py
145     python genK8Bundle.py  -l deployconfig.yaml  -s $var > bundles.yaml
146 fi
147
148 #keep the back in cloud for later debugging.
149 pastebinit bundles.yaml || true
150
151 # with JUJU 2.0 bundles has to be deployed only once.
152 juju deploy bundles.yaml --debug
153 sleep 120
154 check_status allocating
155
156 # need to revisit later if not needed we will remove the below.
157 openfile_fix() {
158     # seeing issue related to number of open files.
159     count=`juju status nodes --format=short | grep nodes | wc -l`
160     c=0
161     while [ $c -lt $count ]; do
162         juju ssh nodes/$c 'echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p' || true
163         juju ssh nodes-compute/$c 'echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p' || true
164         juju ssh nodes/$c 'echo 2048 | sudo tee /proc/sys/fs/inotify/max_user_instances' || true
165         juju ssh nodes-compute/$c 'echo 2048 | sudo tee /proc/sys/fs/inotify/max_user_instances' || true
166         let c+=1
167     done
168 }
169
170 if [ "$opnfvsdn" = "ocl" ]
171 then
172   TAG="ubuntu16.04-4.0.0.0-20.tar.gz"
173
174   for ROLE in contrail-controller contrail-analytics contrail-analyticsdb
175   do
176     FILE="${ROLE}-${TAG}"
177   if [ ! -f $FILE ]
178   then
179     curl -o $FILE http://artifacts.opnfv.org/ovno/containers/$FILE
180   fi
181   juju attach $ROLE ${ROLE}="./$FILE"
182 done
183 fi
184 #lets gather the status of deployment once juju-deployer completed.
185 juju status --format=tabular