Add section on release notes for all HA scenarios
[joid.git] / ci / 00-maasdeploy.sh
1 #!/bin/bash
2 #placeholder for deployment script.
3 set -ex
4
5 virtinstall=0
6 labname=$1
7
8 #install the packages needed
9 sudo apt-add-repository ppa:maas-deployers/stable -y
10 sudo apt-add-repository ppa:juju/stable -y
11 sudo apt-add-repository ppa:maas/stable -y
12 sudo apt-add-repository cloud-archive:mitaka -y
13 sudo apt-get update -y
14 sudo apt-get dist-upgrade -y
15 sudo apt-get install openssh-server bzr git maas-deployer juju juju-deployer \
16              maas-cli python-pip python-psutil python-openstackclient \
17              python-congressclient gsutil charm-tools -y
18
19 #first parameter should be custom and second should be either
20 # absolute location of file (including file name) or url of the
21 # file to download.
22
23 labname=$1
24 labfile=$2
25
26 #
27 # Config preparation
28 #
29
30 # Get labconfig and generate deployment.yaml for MAAS and deployconfig.yaml
31 case "$labname" in
32     intelpod[569]|orangepod[12]|cengnpod[12] )
33         array=(${labname//pod/ })
34         cp ../labconfig/${array[0]}/pod${array[1]}/labconfig.yaml .
35         python genMAASConfig.py -l labconfig.yaml > deployment.yaml
36         python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
37         ;;
38     'attvirpod1' )
39         cp ../labconfig/att/virpod1/labconfig.yaml .
40         python genMAASConfig.py -l labconfig.yaml > deployment.yaml
41         python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
42         ;;
43     'juniperpod1' )
44         cp maas/juniper/pod1/deployment.yaml ./deployment.yaml
45         ;;
46     'custom')
47         if [ -e $labfile ]; then
48             cp $labfile ./labconfig.yaml || true
49         else
50             wget $labconfigfile -t 3 -T 10 -O ./labconfig.yaml || true
51             count=`wc -l labconfig.yaml  | cut -d " " -f 1`
52             if [ $count -lt 10 ]; then
53                 rm -rf labconfig.yaml
54             fi
55         fi
56         if [ ! -e ./labconfig.yaml ]; then
57             virtinstall=1
58         else
59             python genMAASConfig.py -l labconfig.yaml > deployment.yaml
60             python genDeploymentConfig.py -l labconfig.yaml > deployconfig.yaml
61             labname=`grep "maas_name" deployment.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
62         fi
63         ;;
64     * )
65         virtinstall=1
66         ;;
67 esac
68
69 # In the case of a virtual deployment get deployment.yaml and deployconfig.yaml
70 if [ "$virtinstall" -eq 1 ]; then
71     labname="default"
72     ./cleanvm.sh
73     cp ../labconfig/default/deployment.yaml ./
74     cp ../labconfig/default/labconfig.yaml ./
75     cp ../labconfig/default/deployconfig.yaml ./
76 fi
77
78 #
79 # Prepare local environment to avoid password asking
80 #
81
82 # make sure no password asked during the deployment.
83 echo "$USER ALL=(ALL) NOPASSWD:ALL" > 90-joid-init
84
85 if [ -e /etc/sudoers.d/90-joid-init ]; then
86     sudo cp /etc/sudoers.d/90-joid-init 91-joid-init
87     sudo chown $USER:$USER 91-joid-init
88     sudo chmod 660 91-joid-init
89     sudo cat 90-joid-init >> 91-joid-init
90     sudo chown root:root 91-joid-init
91     sudo mv 91-joid-init /etc/sudoers.d/
92 else
93     sudo chown root:root 90-joid-init
94     sudo mv 90-joid-init /etc/sudoers.d/
95 fi
96
97 if [ ! -e $HOME/.ssh/id_rsa ]; then
98     ssh-keygen -N '' -f $HOME/.ssh/id_rsa
99 fi
100
101 echo "... Deployment of maas Started ...."
102
103 #
104 # Virsh preparation
105 #
106
107 # define the pool and try to start even though its already exist.
108 # For fresh install this may or may not there.
109 sudo apt-get install libvirt-bin -y
110 sudo adduser $USER libvirtd
111 sudo virsh pool-define-as default --type dir --target /var/lib/libvirt/images/ || true
112 sudo virsh pool-start default || true
113 sudo virsh pool-autostart default || true
114
115 # In case of virtual install set network
116 if [ "$virtinstall" -eq 1 ]; then
117     sudo virsh net-dumpxml default > default-net-org.xml
118     sudo sed -i '/dhcp/d' default-net-org.xml
119     sudo sed -i '/range/d' default-net-org.xml
120     sudo virsh net-define default-net-org.xml
121     sudo virsh net-destroy default
122     sudo virsh net-start default
123 fi
124
125 # Ensure virsh can connect without ssh auth
126 cat $HOME/.ssh/id_rsa.pub >> $HOME/.ssh/authorized_keys
127
128
129 #
130 # Cleanup, juju init and config backup
131 #
132
133 # To avoid problem between apiclient/maas_client and apiclient from google
134 # we remove the package google-api-python-client from yardstick installer
135 if [ $(pip list |grep google-api-python-client |wc -l) == 1 ]; then
136     sudo pip uninstall google-api-python-client
137 fi
138
139 # Init Juju
140 juju init -f
141
142 #
143 # MAAS deploy
144 #
145
146 sudo maas-deployer -c deployment.yaml -d --force
147
148 sudo chown $USER:$USER environments.yaml
149
150 echo "... Deployment of maas finish ...."
151
152 # Backup deployment.yaml and deployconfig.yaml in .juju folder
153
154 cp ./environments.yaml ~/.juju/
155
156 if [ -e ./deployconfig.yaml ]; then
157     cp ./deployconfig.yaml ~/.juju/
158     cp ./labconfig.yaml ~/.juju/
159 fi
160
161 if [ -e ./deployment.yaml ]; then
162     cp ./deployment.yaml ~/.juju/
163 fi
164
165 #
166 # MAAS Customization
167 #
168
169 maas_ip=`grep " ip_address" deployment.yaml | cut -d ':' -f 2 | sed -e 's/ //'`
170 apikey=`grep maas-oauth: environments.yaml | cut -d "'" -f 2`
171 maas login maas http://${maas_ip}/MAAS/api/1.0 ${apikey}
172 maas maas sshkeys new key="`cat $HOME/.ssh/id_rsa.pub`"
173
174 #Added the Qtip public to run the Qtip test after install on bare metal nodes.
175 maas maas sshkeys new key="`cat ./maas/sshkeys/QtipKey.pub`"
176 maas maas sshkeys new key="`cat ./maas/sshkeys/DominoKey.pub`"
177
178 #adding compute and control nodes VM to MAAS for virtual deployment purpose.
179 if [ "$virtinstall" -eq 1 ]; then
180     # create two more VMs to do the deployment.
181     sudo virt-install --connect qemu:///system --name node1-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 node1-control
182
183     sudo virt-install --connect qemu:///system --name node2-compute --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 node2-compute
184
185     sudo virt-install --connect qemu:///system --name node5-compute --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 node5-compute
186
187     node1controlmac=`grep  "mac address" node1-control | head -1 | cut -d "'" -f 2`
188     node2computemac=`grep  "mac address" node2-compute | head -1 | cut -d "'" -f 2`
189     node5computemac=`grep  "mac address" node5-compute | head -1 | cut -d "'" -f 2`
190
191     sudo virsh -c qemu:///system define --file node1-control
192     sudo virsh -c qemu:///system define --file node2-compute
193     sudo virsh -c qemu:///system define --file node5-compute
194
195     maas maas tags new name='control'
196     maas maas tags new name='compute'
197
198     controlnodeid=`maas maas nodes new autodetect_nodegroup='yes' name='node1-control' tags='control' hostname='node1-control' power_type='virsh' mac_addresses=$node1controlmac power_parameters_power_address='qemu+ssh://'$USER'@192.168.122.1/system' architecture='amd64/generic' power_parameters_power_id='node1-control' | grep system_id | cut -d '"' -f 4 `
199
200     maas maas tag update-nodes control add=$controlnodeid
201
202     computenodeid=`maas maas nodes new autodetect_nodegroup='yes' name='node2-compute' tags='compute' hostname='node2-compute' power_type='virsh' mac_addresses=$node2computemac power_parameters_power_address='qemu+ssh://'$USER'@192.168.122.1/system' architecture='amd64/generic' power_parameters_power_id='node2-compute' | grep system_id | cut -d '"' -f 4 `
203
204     maas maas tag update-nodes compute add=$computenodeid
205
206     computenodeid=`maas maas nodes new autodetect_nodegroup='yes' name='node5-compute' tags='compute' hostname='node5-compute' power_type='virsh' mac_addresses=$node5computemac power_parameters_power_address='qemu+ssh://'$USER'@192.168.122.1/system' architecture='amd64/generic' power_parameters_power_id='node5-compute' | grep system_id | cut -d '"' -f 4 `
207
208     maas maas tag update-nodes compute add=$computenodeid
209 fi
210
211 #
212 # Functions for MAAS network customization
213 #
214
215 #Below function will mark the interfaces in Auto mode to enbled by MAAS
216 enableautomode() {
217     listofnodes=`maas maas nodes list | grep system_id | cut -d '"' -f 4`
218     for nodes in $listofnodes
219     do
220         maas maas interface link-subnet $nodes $1  mode=$2 subnet=$3
221     done
222 }
223
224 #Below function will mark the interfaces in Auto mode to enbled by MAAS
225 # using hostname of the node added into MAAS
226 enableautomodebyname() {
227     if [ ! -z "$4" ]; then
228         for i in `seq 1 7`;
229         do
230             nodes=`maas maas nodes list | grep system_id | cut -d '"' -f 4`
231             if [ ! -z "$nodes" ]; then
232                 maas maas interface link-subnet $nodes $1  mode=$2 subnet=$3
233             fi
234        done
235     fi
236 }
237
238 #Below function will create vlan and update interface with the new vlan
239 # will return the vlan id created
240 crvlanupdsubnet() {
241     newvlanid=`maas maas vlans create $2 name=$3 vid=$4 | grep resource | cut -d '/' -f 6 `
242     maas maas subnet update $5 vlan=$newvlanid
243     eval "$1"="'$newvlanid'"
244 }
245
246 #Below function will create interface with new vlan and bind to physical interface
247 crnodevlanint() {
248     listofnodes=`maas maas nodes list | grep system_id | cut -d '"' -f 4`
249
250     for nodes in $listofnodes
251     do
252         parentid=`maas maas interface read $nodes $2 | grep interfaces | cut -d '/' -f 8`
253         maas maas interfaces create-vlan $nodes vlan=$1 parent=$parentid
254      done
255  }
256
257 #
258 # VLAN customization
259 #
260
261 case "$labname" in
262     'intelpod9' )
263         maas refresh
264         crvlanupdsubnet vlan904 fabric-1 "MgmtNetwork" 904 2 || true
265         crvlanupdsubnet vlan905 fabric-2 "PublicNetwork" 905 3 || true
266         crnodevlanint $vlan905 eth1 || true
267         crnodevlanint $vlan905 eth3 || true
268         enableautomodebyname eth1.905 AUTO "10.9.15.0/24" || true
269         enableautomodebyname eth3.905 AUTO "10.9.15.0/24" || true
270         enableautomodebyname eth0 AUTO "10.9.12.0/24" || true
271         enableautomodebyname eth2 AUTO "10.9.12.0/24" || true
272         ;;
273 esac
274
275 #
276 # Enable MAAS nodes interfaces
277 #
278
279 #read interface needed in Auto mode and enable it. Will be rmeoved once auto enablement will be implemented in the maas-deployer.
280 if [ -e ~/.juju/deployconfig.yaml ]; then
281   cp ~/.juju/deployconfig.yaml ./deployconfig.yaml
282
283   enableiflist=`grep "interface-enable" deployconfig.yaml | cut -d ' ' -f 4 `
284   datanet=`grep "dataNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
285   stornet=`grep "storageNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
286   pubnet=`grep "publicNetwork" deployconfig.yaml | cut -d ' ' -f 4 | sed -e 's/ //'`
287
288   # split EXTERNAL_NETWORK=first ip;last ip; gateway;network
289
290   if [ "$datanet" != "''" ]; then
291       EXTNET=(${enableiflist//,/ })
292       i="0"
293       while [ ! -z "${EXTNET[i]}" ];
294       do
295           enableautomode ${EXTNET[i]} AUTO $datanet || true
296           i=$[$i+1]
297       done
298   fi
299   if [ "$stornet" != "''" ]; then
300       EXTNET=(${enableiflist//,/ })
301       i="0"
302       while [ ! -z "${EXTNET[i]}" ];
303       do
304           enableautomode ${EXTNET[i]} AUTO $stornet || true
305           i=$[$i+1]
306       done
307   fi
308   if [ "$pubnet" != "''" ]; then
309       EXTNET=(${enableiflist//,/ })
310       i="0"
311       while [ ! -z "${EXTNET[i]}" ];
312       do
313           enableautomode ${EXTNET[i]} AUTO $pubnet || true
314           i=$[$i+1]
315       done
316   fi
317 fi
318
319 #
320 # End of scripts
321 #
322 echo " .... MAAS deployment finished successfully ...."