d86d1e0ee2d59e3ed7c4717e5977df3bc0dfa852
[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        admnet=`grep "admNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
67        cephdisk=`grep "ceph-disk" deployconfig.yaml | cut -d ':' -f 2 | 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 fi
95
96 case "$opnfvlab" in
97      'juniperpod1' )
98          sed -i -- 's/10.4.1.1/172.16.50.1/g' ./bundles.yaml
99          sed -i -- 's/#ext-port: "eth1"/ext-port: "eth1"/g' ./bundles.yaml
100          ;;
101      'ravellodemopod' )
102          sed -i -- 's/#ext-port: "eth1"/ext-port: "eth2"/g' ./bundles.yaml
103         ;;
104 esac
105
106 # lets put the if separator as "," as this will save me from world.
107 fea=""
108 IFS=","
109 for feature in $opnfvfeature; do
110     if [ "$fea" == "" ]; then
111         fea=$feature
112     else
113         fea=$fea"_"$feature
114     fi
115 done
116
117 if [[ "$opnfvmodel" = "openstack" ]]; then
118     #update source if trusty is target distribution
119     var=os-$opnfvsdn-$fea-$opnfvtype"-"$opnfvdistro"_"$openstack
120
121 else
122     var=k8-$opnfvsdn-$fea-baremetal-core
123 fi
124
125 if [[ "$opnfvmodel" = "openstack" ]]; then
126     #lets generate the bundle for all target using genBundle.py
127     python genBundle.py  -l deployconfig.yaml  -s $var > bundles.yaml
128 else
129     #lets generate the bundle for k8 target using genK8Bundle.py
130     python genK8Bundle.py  -l deployconfig.yaml  -s $var > bundles.yaml
131 fi
132
133 #keep the back in cloud for later debugging.
134 pastebinit bundles.yaml || true
135
136 # with JUJU 2.0 bundles has to be deployed only once.
137 juju deploy bundles.yaml --debug
138 sleep 720
139 check_status allocating 220
140
141 # need to revisit later if not needed we will remove the below.
142 openfile_fix() {
143     # seeing issue related to number of open files.
144     count=`juju status nodes --format=short | grep nodes | wc -l`
145     c=0
146     while [ $c -lt $count ]; do
147         juju ssh nodes/$c 'echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p' || true
148         juju ssh nodes-compute/$c 'echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p' || true
149         juju ssh nodes/$c 'echo 2048 | sudo tee /proc/sys/fs/inotify/max_user_instances' || true
150         juju ssh nodes-compute/$c 'echo 2048 | sudo tee /proc/sys/fs/inotify/max_user_instances' || true
151         let c+=1
152     done
153 }
154
155 if [ "$opnfvsdn" = "ocl" ]
156 then
157   TAG="ubuntu16.04-4.0.1.0-32.tar.gz"
158
159   for ROLE in contrail-controller contrail-analytics contrail-analyticsdb
160   do
161     FILE="${ROLE}-${TAG}"
162   if [ ! -f $FILE ]
163   then
164     curl -o $FILE http://artifacts.opnfv.org/ovno/containers/$FILE
165   fi
166   juju attach $ROLE ${ROLE}="./$FILE"
167 done
168 fi
169 #lets gather the status of deployment once juju-deployer completed.
170 juju status --format=tabular