Added kubernetes core bundle support.
[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|kubernates>]
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     maas_ip=`grep " ip_address" deployment.yaml | cut -d " "  -f 10`
78     apikey=`grep maas-oauth: environments.yaml | cut -d "'" -f 2`
79     maas login maas http://${maas_ip}/MAAS/api/1.0 ${apikey}
80
81     nodeexist=`maas maas nodes list hostname=node3-control`
82
83     if [ $nodeexist != *node3* ]; then
84         sudo virt-install --connect qemu:///system --name node3-control --ram 8192 --vcpus 4 --disk size=120,format=qcow2,bus=virtio,io=native,pool=default --network bridge=virbr0,model=virtio --network bridge=virbr0,model=virtio --boot network,hd,menu=off --noautoconsole --vnc --print-xml | tee node3-control
85
86         sudo virt-install --connect qemu:///system --name node4-control --ram 8192 --vcpus 4 --disk size=120,format=qcow2,bus=virtio,io=native,pool=default --network bridge=virbr0,model=virtio --network bridge=virbr0,model=virtio --boot network,hd,menu=off --noautoconsole --vnc --print-xml | tee node4-control
87
88         node3controlmac=`grep  "mac address" node3-control | head -1 | cut -d "'" -f 2`
89         node4controlmac=`grep  "mac address" node4-control | head -1 | cut -d "'" -f 2`
90
91         sudo virsh -c qemu:///system define --file node3-control
92         sudo virsh -c qemu:///system define --file node4-control
93
94         controlnodeid=`maas maas nodes new autodetect_nodegroup='yes' name='node3-control' tags='control' hostname='node3-control' power_type='virsh' mac_addresses=$node3controlmac power_parameters_power_address='qemu+ssh://'$USER'@192.168.122.1/system' architecture='amd64/generic' power_parameters_power_id='node3-control' | grep system_id | cut -d '"' -f 4 `
95
96         maas maas tag update-nodes control add=$controlnodeid
97
98         controlnodeid=`maas maas nodes new autodetect_nodegroup='yes' name='node4-control' tags='control' hostname='node4-control' power_type='virsh' mac_addresses=$node4controlmac power_parameters_power_address='qemu+ssh://'$USER'@192.168.122.1/system' architecture='amd64/generic' power_parameters_power_id='node4-control' | grep system_id | cut -d '"' -f 4 `
99
100         maas maas tag update-nodes control add=$controlnodeid
101
102     fi
103 }
104
105 #copy the files and create extra resources needed for HA deployment
106 # in case of default VM labs.
107 deploy() {
108
109     if [ ! -f ./environments.yaml ] && [ -e ~/.juju/environments.yaml ]; then
110         cp ~/.juju/environments.yaml ./environments.yaml
111     elif [ ! -f ./environments.yaml ] && [ -e ~/joid_config/environments.yaml ]; then
112         cp ~/joid_config/environments.yaml ./environments.yaml
113     fi
114     if [ ! -f ./deployment.yaml ] && [ -e ~/.juju/deployment.yaml ]; then
115         cp ~/.juju/deployment.yaml ./deployment.yaml
116     elif [ ! -f ./deployment.yaml ] && [ -e ~/joid_config/deployment.yaml ]; then
117         cp ~/joid_config/deployment.yaml ./deployment.yaml
118     fi
119     if [ ! -f ./labconfig.yaml ] && [ -e ~/.juju/labconfig.yaml ]; then
120         cp ~/.juju/labconfig.yaml ./labconfig.yaml
121     elif [ ! -f ./labconfig.yaml ] && [ -e ~/joid_config/labconfig.yaml ]; then
122         cp ~/joid_config/labconfig.yaml ./labconfig.yaml
123     fi
124     if [ ! -f ./deployconfig.yaml ] && [ -e ~/.juju/deployconfig.yaml ]; then
125         cp ~/.juju/deployconfig.yaml ./deployconfig.yaml
126     elif [ ! -f ./deployconfig.yaml ] && [ -e ~/joid_config/deployconfig.yaml ]; then
127         cp ~/joid_config/deployconfig.yaml ./deployconfig.yaml
128     fi
129
130     #copy the script which needs to get deployed as part of ofnfv release
131     echo "...... deploying now ......"
132     echo "   " >> environments.yaml
133     echo "        enable-os-refresh-update: false" >> environments.yaml
134     echo "        enable-os-upgrade: false" >> environments.yaml
135     echo "        admin-secret: admin" >> environments.yaml
136     echo "        default-series: $opnfvdistro" >> environments.yaml
137
138     cp environments.yaml ~/.juju/
139     cp environments.yaml ~/joid_config/
140
141     if [[ "$opnfvtype" = "ha" && "$opnfvlab" = "default" ]]; then
142         createresource
143     fi
144
145     #bootstrap the node
146     ./01-bootstrap.sh
147
148     if [[ "$jujuver" > "2" ]]; then
149         juju model-config default-series=$opnfvdistro enable-os-refresh-update=false enable-os-upgrade=false
150     fi
151
152     #case default deploy the opnfv platform:
153     ./02-deploybundle.sh $opnfvtype $openstack $opnfvlab $opnfvsdn $opnfvfeature $opnfvdistro $opnfvmodel
154 }
155
156 #check whether charms are still executing the code even juju-deployer says installed.
157 check_status() {
158     retval=0
159     timeoutiter=0
160     while [ $retval -eq 0 ]; do
161        sleep 30
162        juju status > status.txt
163        if [ "$(grep -c "executing" status.txt )" -ge 1 ]; then
164            echo " still executing the reltionship within charms ..."
165            if [ $timeoutiter -ge 120 ]; then
166                retval=1
167            fi
168            timeoutiter=$((timeoutiter+1))
169        else
170            retval=1
171        fi
172     done
173
174     if [[ "$opnfvmodel" = "openstack" ]]; then
175         juju expose ceph-radosgw || true
176         #juju ssh ceph/0 \ 'sudo radosgw-admin user create --uid="ubuntu" --display-name="Ubuntu Ceph"'
177     fi
178     echo "...... deployment finishing ......."
179 }
180
181 echo "...... deployment started ......"
182 deploy
183
184 check_status
185
186 echo "...... deployment finished  ......."
187
188 if [[ "$opnfvmodel" = "openstack" ]]; then
189     ./openstack.sh "$opnfvsdn" "$opnfvlab" "$opnfvdistro" "$openstack" || true
190
191     # creating heat domain after puching the public API into /etc/hosts
192
193     if [[ "$jujuver" > "2" ]]; then
194         status=`juju run-action heat/0 domain-setup`
195         echo $status
196     else
197         status=`juju action do heat/0 domain-setup`
198         echo $status
199     fi
200
201
202     sudo ../juju/get-cloud-images || true
203     ../juju/joid-configure-openstack || true
204
205 fi
206
207 echo "...... finished  ......."