Merge "enable interface and subnet as per the labconfig.yaml"
[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=newton
11 opnfvlab=default
12 opnfvrel=d
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\").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\").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             if [ -e ./labconfig.yaml ]; then
130                 if [ ! -f ./deployconfig.yaml ] && [ -e ~/joid_config/deployconfig.yaml ]; then
131                     cp ~/joid_config/deployconfig.yaml ./deployconfig.yaml
132                 else
133                     python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
134                 fi
135             else
136                 echo " MAAS not deployed please deploy MAAS first."
137             fi
138         fi
139     else
140         if [ ! -f ./environments.yaml ] && [ -e ~/.juju/environments.yaml ]; then
141             cp ~/.juju/environments.yaml ./environments.yaml
142         elif [ ! -f ./environments.yaml ] && [ -e ~/joid_config/environments.yaml ]; then
143             cp ~/joid_config/environments.yaml ./environments.yaml
144         fi
145         #copy the script which needs to get deployed as part of ofnfv release
146         echo "...... deploying now ......"
147         echo "   " >> environments.yaml
148         echo "        enable-os-refresh-update: false" >> environments.yaml
149         echo "        enable-os-upgrade: false" >> environments.yaml
150         echo "        admin-secret: admin" >> environments.yaml
151         echo "        default-series: $opnfvdistro" >> environments.yaml
152         cp environments.yaml ~/.juju/
153         cp environments.yaml ~/joid_config/
154     fi
155
156     if [[ "$opnfvtype" = "ha" && "$opnfvlab" = "default" ]]; then
157         createresource
158     fi
159
160     #bootstrap the node
161     ./01-bootstrap.sh
162
163     if [[ "$jujuver" > "2" ]]; then
164         juju model-config default-series=$opnfvdistro enable-os-refresh-update=false enable-os-upgrade=false
165     fi
166
167     #case default deploy the opnfv platform:
168     ./02-deploybundle.sh $opnfvtype $openstack $opnfvlab $opnfvsdn $opnfvfeature $opnfvdistro $opnfvmodel
169 }
170
171 #check whether charms are still executing the code even juju-deployer says installed.
172 check_status() {
173     retval=0
174     timeoutiter=0
175
176     echo -n "executing the reltionship within charms ."
177     while [ $retval -eq 0 ]; do
178        sleep 30
179        if juju status | grep -q "executing"; then
180            echo -n '.'
181            if [ $timeoutiter -ge 120 ]; then
182                echo 'timed out'
183                retval=1
184            fi
185            timeoutiter=$((timeoutiter+1))
186        else
187            echo 'done'
188            retval=1
189        fi
190     done
191
192     if [[ "$opnfvmodel" = "openstack" ]]; then
193         juju expose ceph-radosgw || true
194         #juju ssh ceph/0 \ 'sudo radosgw-admin user create --uid="ubuntu" --display-name="Ubuntu Ceph"'
195     fi
196     echo "...... deployment finishing ......."
197 }
198
199 echo "...... deployment started ......"
200 deploy
201
202 check_status
203
204 echo "...... deployment finished  ......."
205
206 if [[ "$opnfvmodel" = "openstack" ]]; then
207     ./openstack.sh "$opnfvsdn" "$opnfvlab" "$opnfvdistro" "$openstack" || true
208
209     # creating heat domain after puching the public API into /etc/hosts
210
211     if [[ "$jujuver" > "2" ]]; then
212         status=`juju run-action heat/0 domain-setup`
213         echo $status
214     else
215         status=`juju action do heat/0 domain-setup`
216         echo $status
217     fi
218
219
220     sudo ../juju/get-cloud-images || true
221     ../juju/joid-configure-openstack || true
222
223 fi
224 if [[ "$opnfvmodel" = "kubernetes" ]]; then
225     ./k8.sh
226 fi
227
228 echo "...... finished  ......."