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