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