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