bug fixes
[joid.git] / ci / deploy.sh
1 #!/bin/bash
2
3 set -ex
4
5 #need to put mutiple cases here where decide this bundle to deploy by default use the odl bundle.
6 # Below parameters are the default and we can according the release
7
8 opnfvsdn=nosdn
9 opnfvtype=nonha
10 openstack=mitaka
11 opnfvlab=default
12 opnfvrel=c
13 opnfvfeature=none
14 opnfvdistro=xenial
15 opnfvarch=amd64
16 opnfvmodel=openstack
17
18 jujuver=`juju --version`
19
20 read_config() {
21     opnfvrel=`grep release: deploy.yaml | cut -d ":" -f2`
22     openstack=`grep openstack: deploy.yaml | cut -d ":" -f2`
23     opnfvtype=`grep type: deploy.yaml | cut -d ":" -f2`
24     opnfvlab=`grep lab: deploy.yaml | cut -d ":" -f2`
25     opnfvsdn=`grep sdn: deploy.yaml | cut -d ":" -f2`
26 }
27
28 usage() { echo "Usage: $0 [-s <nosdn|odl|opencontrail>]
29                          [-t <nonha|ha|tip>]
30                          [-o <juno|liberty>]
31                          [-l <default|intelpod5>]
32                          [-f <ipv6,dpdk,lxd,dvr>]
33                          [-d <trusty|xenial>]
34                          [-a <amd64>]
35                          [-m <openstack|kubernetes>]
36                          [-r <a|b>]" 1>&2 exit 1; }
37
38 while getopts ":s:t:o:l:h:r:f:d:a:m:" opt; do
39     case "${opt}" in
40         s)
41             opnfvsdn=${OPTARG}
42             ;;
43         t)
44             opnfvtype=${OPTARG}
45             ;;
46         o)
47             openstack=${OPTARG}
48             ;;
49         l)
50             opnfvlab=${OPTARG}
51             ;;
52         r)
53             opnfvrel=${OPTARG}
54             ;;
55         f)
56             opnfvfeature=${OPTARG}
57             ;;
58         d)
59             opnfvdistro=${OPTARG}
60             ;;
61         a)
62             opnfvarch=${OPTARG}
63             ;;
64         m)
65             opnfvmodel=${OPTARG}
66             ;;
67         h)
68             usage
69             ;;
70         *)
71             ;;
72     esac
73 done
74
75 #by default maas creates two VMs in case of three more VM needed.
76 createresource() {
77     # TODO: make sure this function run with the same parameters used in 03-maasdeploy.sh
78     PROFILE=${PROFILE:-ubuntu}
79     MAAS_IP=$(grep " ip_address" deployconfig.yaml | cut -d ':' -f 2 | sed -e 's/ //')
80     API_SERVER="http://$MAAS_IP/MAAS/api/2.0"
81     API_KEY=`sudo maas-region apikey --username=ubuntu`
82     maas login $PROFILE $API_SERVER $API_KEY
83
84     for node in node3-control node4-control
85     do
86         node_id=$(maas $PROFILE machines read | \
87                   jq -r "select(.[].hostname == \"$node\")[0].system_id")
88         if [[ -z "$node_id" ]]; then
89             sudo virt-install --connect qemu:///system --name $node \
90                 --ram 8192 --cpu host --vcpus 4 \
91                 --disk size=120,format=qcow2,bus=virtio,io=native,pool=default \
92                 --network bridge=virbr0,model=virtio \
93                 --network bridge=virbr0,model=virtio \
94                 --boot network,hd,menu=off \
95                 --noautoconsole --vnc --print-xml | tee _node.xml
96             node_mac=$(grep "mac address" _node.xml | head -1 | cut -d "'" -f 2)
97             sudo virsh -c qemu:///system define --file _node.xml
98             rm -f _node.xml
99
100             maas $PROFILE nodes new autodetect_nodegroup='yes' name=$node \
101                 tags='control' hostname=$name power_type='virsh' \
102                 mac_addresses=$node3controlmac \
103                 power_parameters_power_address="qemu+ssh://$USER@192.168.122.1/system" \
104                 architecture='amd64/generic' power_parameters_power_id='node3-control'
105             node_id=$(maas $PROFILE machines read | \
106                   jq -r "select(.[].hostname == \"$node\")[0].system_id")
107         fi
108         if [[ -z "$node_id" ]]; then
109             echo "Error: failed to create node $node ."
110             exit 1
111         fi
112         maas $PROFILE tag update-nodes control add=$node_id || true
113     done
114 }
115
116 #copy the files and create extra resources needed for HA deployment
117 # in case of default VM labs.
118 deploy() {
119     if [[ "$jujuver" > "2" ]]; then
120         if [ ! -f ./labconfig.yaml ] && [ -e ~/joid_config/labconfig.yaml ]; then
121             cp ~/joid_config/labconfig.yaml ./labconfig.yaml
122
123             if [ ! -f ./deployconfig.yaml ] && [ -e ~/joid_config/deployconfig.yaml ]; then
124                 cp ~/joid_config/deployconfig.yaml ./deployconfig.yaml
125             else
126                 python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
127             fi
128         else
129             echo " MAAS not deployed please deploy MAAS first."
130         fi
131     else
132         if [ ! -f ./environments.yaml ] && [ -e ~/.juju/environments.yaml ]; then
133             cp ~/.juju/environments.yaml ./environments.yaml
134         elif [ ! -f ./environments.yaml ] && [ -e ~/joid_config/environments.yaml ]; then
135             cp ~/joid_config/environments.yaml ./environments.yaml
136         fi
137         #copy the script which needs to get deployed as part of ofnfv release
138         echo "...... deploying now ......"
139         echo "   " >> environments.yaml
140         echo "        enable-os-refresh-update: false" >> environments.yaml
141         echo "        enable-os-upgrade: false" >> environments.yaml
142         echo "        admin-secret: admin" >> environments.yaml
143         echo "        default-series: $opnfvdistro" >> environments.yaml
144         cp environments.yaml ~/.juju/
145         cp environments.yaml ~/joid_config/
146     fi
147
148     if [[ "$opnfvtype" = "ha" && "$opnfvlab" = "default" ]]; then
149         createresource
150     fi
151
152     #bootstrap the node
153     ./01-bootstrap.sh
154
155     if [[ "$jujuver" > "2" ]]; then
156         juju model-config default-series=$opnfvdistro enable-os-refresh-update=false enable-os-upgrade=false
157     fi
158
159     #case default deploy the opnfv platform:
160     ./02-deploybundle.sh $opnfvtype $openstack $opnfvlab $opnfvsdn $opnfvfeature $opnfvdistro $opnfvmodel
161 }
162
163 #check whether charms are still executing the code even juju-deployer says installed.
164 check_status() {
165     retval=0
166     timeoutiter=0
167
168     echo -n "executing the reltionship within charms ."
169     while [ $retval -eq 0 ]; do
170        sleep 30
171        if juju status | grep -q "executing"; then
172            echo -n '.'
173            if [ $timeoutiter -ge 120 ]; then
174                echo 'timed out'
175                retval=1
176            fi
177            timeoutiter=$((timeoutiter+1))
178        else
179            echo 'done'
180            retval=1
181        fi
182     done
183
184     if [[ "$opnfvmodel" = "openstack" ]]; then
185         juju expose ceph-radosgw || true
186         #juju ssh ceph/0 \ 'sudo radosgw-admin user create --uid="ubuntu" --display-name="Ubuntu Ceph"'
187     fi
188     echo "...... deployment finishing ......."
189 }
190
191 echo "...... deployment started ......"
192 deploy
193
194 check_status
195
196 echo "...... deployment finished  ......."
197
198 if [[ "$opnfvmodel" = "openstack" ]]; then
199     ./openstack.sh "$opnfvsdn" "$opnfvlab" "$opnfvdistro" "$openstack" || true
200
201     # creating heat domain after puching the public API into /etc/hosts
202
203     if [[ "$jujuver" > "2" ]]; then
204         status=`juju run-action heat/0 domain-setup`
205         echo $status
206     else
207         status=`juju action do heat/0 domain-setup`
208         echo $status
209     fi
210
211
212     sudo ../juju/get-cloud-images || true
213     ../juju/joid-configure-openstack || true
214
215 fi
216 if [[ "$opnfvmodel" = "kubernetes" ]]; then
217     ./k8.sh
218 fi
219
220 echo "...... finished  ......."