Merge "Auto Generated INFO.yaml file"
[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     ./$opnfvsdn/fetch-charms.sh $opnfvdistro
18     osdomname=''
19 else
20     ./kubernetes/fetch-charms.sh $opnfvdistro
21 fi
22
23 #check whether charms are still executing the code even juju-deployer says installed.
24 check_status() {
25     waitstatus=$1
26     waittime=$2
27     retval=0
28     timeoutiter=0
29
30     echo -n "executing the reltionship within charms ."
31     while [ $retval -eq 0 ]; do
32         if juju status | grep -q $waitstatus; then
33            echo -n '.'
34            if [ $timeoutiter -ge $waittime ]; then
35                echo 'timed out'
36                retval=1
37            else
38                sleep 30
39            fi
40            timeoutiter=$((timeoutiter+1))
41        else
42            echo 'done'
43            retval=1
44        fi
45     done
46     echo "...... deployment finishing ......."
47 }
48
49 #read the value from deployconfig.yaml
50
51 PROFILE=maas
52 MAAS_IP=$(grep " ip_address" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //')
53 API_SERVERMAAS="http://$MAAS_IP:5240/MAAS/"
54 API_KEY=`sudo maas-region apikey --username=ubuntu || true`
55
56 if [[ "$API_KEY" = "" ]]; then
57     API_KEY=`sshpass -p ubuntu ssh ubuntu@$MAAS_IP 'sudo maas-region apikey --username=ubuntu'`
58 fi
59
60 maas login $PROFILE $API_SERVERMAAS $API_KEY
61
62 if [[ "$opnfvmodel" = "openstack" ]]; then
63     if [ -e ./deployconfig.yaml ]; then
64        extport=`grep "ext-port" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //' | tr ',' ' '`
65        datanet=`grep "dataNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
66        cephdisk=`grep "ceph-disk" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
67        admnet=`grep "admNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
68        osdomname=`grep "os-domain-name" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
69     fi
70
71     workmutiple=`maas maas nodes read | grep "cpu_count" | cut -d ':' -f 2 | sed -e 's/ //' | tr ',' ' '`
72     max=0
73     for v in ${workmutiple[@]}; do
74         if (( $v > $max )); then max=$v; fi;
75     done
76     echo $max
77
78     if [ "$max" -lt 4 ];then
79         workmutiple=1.1
80     elif [ "$max" -lt 33 ]; then
81         workmutiple=0.25
82     elif [ "$max" -lt 73 ]; then
83         workmutiple=0.1
84     else
85         workmutiple=0.05
86     fi
87     sed -i "s/worker_multiplier: 1.0/worker_multiplier: ${workmutiple}/g" default_deployment_config.yaml
88
89     if [ "$opnfvlab" != "default" ]; then
90         sed -i "s/cpu_pin_set: all/cpu_pin_set: 2-${max},^${max}/g" default_deployment_config.yaml
91     else
92         sed -i "s/cpu_pin_set: all/cpu_pin_set: 1/g" default_deployment_config.yaml
93     fi
94 else
95     cephdisk=`grep "ceph-disk" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
96 fi
97
98 case "$opnfvlab" in
99      'juniperpod1' )
100          sed -i -- 's/10.4.1.1/172.16.50.1/g' ./bundles.yaml
101          sed -i -- 's/#ext-port: "eth1"/ext-port: "eth1"/g' ./bundles.yaml
102          ;;
103      'ravellodemopod' )
104          sed -i -- 's/#ext-port: "eth1"/ext-port: "eth2"/g' ./bundles.yaml
105         ;;
106 esac
107
108 # lets put the if separator as "," as this will save me from world.
109 fea=""
110 IFS=","
111 for feature in $opnfvfeature; do
112     if [ "$fea" == "" ]; then
113         fea=$feature
114     else
115         fea=$fea"_"$feature
116     fi
117 done
118
119 if [[ "$opnfvmodel" = "openstack" ]]; then
120     #update source if trusty is target distribution
121     var=os-$opnfvsdn-$fea-$opnfvtype"-"$opnfvdistro"_"$openstack
122
123 else
124     var=k8-$opnfvsdn-$fea-baremetal-core
125 fi
126
127 if [[ "$opnfvmodel" = "openstack" ]]; then
128     #lets generate the bundle for all target using genBundle.py
129     python genBundle.py  -l deployconfig.yaml  -s $var > bundles.yaml
130 else
131     #lets generate the bundle for k8 target using genK8Bundle.py
132     python genK8Bundle.py  -l deployconfig.yaml  -s $var > bundles.yaml
133 fi
134
135 #keep the back in cloud for later debugging.
136 pastebinit bundles.yaml || true
137
138 # with JUJU 2.0 bundles has to be deployed only once.
139 juju deploy bundles.yaml --debug
140 sleep 720
141 check_status allocating 220
142
143 # need to revisit later if not needed we will remove the below.
144 openfile_fix() {
145     # seeing issue related to number of open files.
146     count=`juju status nodes --format=short | grep nodes | wc -l`
147     c=0
148     while [ $c -lt $count ]; do
149         juju ssh nodes/$c 'echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p' || true
150         juju ssh nodes-compute/$c 'echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p' || true
151         juju ssh nodes/$c 'echo 2048 | sudo tee /proc/sys/fs/inotify/max_user_instances' || true
152         juju ssh nodes-compute/$c 'echo 2048 | sudo tee /proc/sys/fs/inotify/max_user_instances' || true
153         let c+=1
154     done
155 }
156
157 if [ "$opnfvsdn" = "ocl" ]
158 then
159   TAG="ubuntu16.04-4.1.1.0-103.tar.gz"
160
161   for ROLE in contrail-controller contrail-analytics contrail-analyticsdb
162   do
163     FILE="${ROLE}-${TAG}"
164   if [ ! -f $FILE ]
165   then
166     curl -o $FILE http://artifacts.opnfv.org/ovno/containers/$FILE
167   fi
168   juju attach $ROLE ${ROLE}="./$FILE"
169 done
170 fi
171 #lets gather the status of deployment once juju-deployer completed.
172 juju status --format=tabular