diff options
Diffstat (limited to 'fuel/deploy/functions')
-rwxr-xr-x | fuel/deploy/functions/common.sh | 109 | ||||
-rwxr-xr-x | fuel/deploy/functions/install_iso.sh | 62 | ||||
-rw-r--r-- | fuel/deploy/functions/isolinux.cfg.patch | 14 | ||||
-rw-r--r-- | fuel/deploy/functions/ks.cfg.patch | 19 | ||||
-rwxr-xr-x | fuel/deploy/functions/patch-iso.sh | 69 |
5 files changed, 273 insertions, 0 deletions
diff --git a/fuel/deploy/functions/common.sh b/fuel/deploy/functions/common.sh new file mode 100755 index 0000000..f6cceb4 --- /dev/null +++ b/fuel/deploy/functions/common.sh @@ -0,0 +1,109 @@ +############################################################################## +# Copyright (c) 2015 Ericsson AB and others. +# stefan.k.berg@ericsson.com +# jonas.bjurel@ericsson.com +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +# Common functions + +error_exit () { + echo "Error: $@" >&2 + exit 1 +} + +ssh() { + SSHPASS="r00tme" sshpass -e ssh -o UserKnownHostsFile=/dev/null \ + -o StrictHostKeyChecking=no -o ConnectTimeout=15 "$@" +} + +scp() { + SSHPASS="r00tme" sshpass -e scp -o UserKnownHostsFile=/dev/null \ + -o StrictHostKeyChecking=no -o ConnectTimeout=15 "$@" +} + +noNodesUp () { + fuel node | grep True | wc -l +} + +fuel () { + ssh root@10.20.0.2 "fuel $@" +} + +# Return MAC id for virsh node +getNodeId() { + virsh dumpxml $1 | grep "mac address" | head -1 | sed "s/.*'..:..:..:..:\(.*\)'.*/\1/" +} + +# Wait for node with virtid name to come up +waitForHost() { + mac=`getNodeId $1` + + while true + do + fuel node --node-id $mac 2>/dev/null | grep -q True && break + sleep 3 + echo -n "." + done + echo -e "\n" +} + +# Currently not used! +# Wait for node count to increase +waitForNode() { + local cnt + local initCnt + local expectCnt + + initCnt=`noNodesUp` + expectCnt=$[initCnt+1] + while true + do + cnt=`noNodesUp` + if [ $cnt -eq $expectCnt ]; then + break + elif [ $cnt -lt $initCnt ]; then + error_exit "Node count decreased while waiting, $initCnt -> $cnt" + elif [ $cnt -gt $expectCnt ]; then + error_exit "Node count exceeded expect count, $cnt > $expectCnt" + fi + sleep 3 + echo -n "." + done + echo -e "\n" +} + +bootorder_dvdhd() { + virsh dumpxml $1 | grep -v "<boot.*>" | \ + sed "/<\/os>/i\ + <boot dev='cdrom'/\>\n\ + <boot dev='hd'/\>\n\ + <bootmenu enable='no'/\>" > $tmpdir/vm.xml || error_exit "Could not set bootorder" + virsh define $tmpdir/vm.xml || error_exit "Could not set bootorder" +} + +bootorder_hddvd() { + virsh dumpxml $1 | grep -v "<boot.*>" | \ + sed "/<\/os>/i\ + <boot dev='hd'/\>\n\ + <boot dev='cdrom'/\>\n\ + <bootmenu enable='no'/\>" > $tmpdir/vm.xml || error_exit "Could not set bootorder" + virsh define $tmpdir/vm.xml || error_exit "Could not set bootorder" +} + +addisofile() { + virsh dumpxml $1 | grep -v '\.iso' | sed "s/<.*device='cdrom'.*/<disk type='file' device='cdrom'>/" | \ + sed "/<.*device='cdrom'.*/a <source file='$2'/>" > $tmpdir/vm.xml \ + || error_exit "Could not add isofile" + virsh define $tmpdir/vm.xml || error_exit "Could not add isofile" +} + +removeisofile() { + virsh dumpxml $1 | grep -v '\.iso' | sed "s/<.*device='cdrom'.*/<disk type='block' device='cdrom'>/" \ + > $tmpdir/vm.xml \ + || error_exit "Could not remove isofile" + virsh define $tmpdir/vm.xml || error_exit "Could not remove isofile" +} diff --git a/fuel/deploy/functions/install_iso.sh b/fuel/deploy/functions/install_iso.sh new file mode 100755 index 0000000..0a92cd5 --- /dev/null +++ b/fuel/deploy/functions/install_iso.sh @@ -0,0 +1,62 @@ +############################################################################## +# Copyright (c) 2015 Ericsson AB and others. +# stefan.k.berg@ericsson.com +# jonas.bjurel@ericsson.com +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +# Recreate disk - needed for the reboot to work +fueldisk=`virsh dumpxml fuel-master | \ + grep fuel-master.raw | sed "s/.*'\(.*\)'.*/\1/"` +disksize=`ls -l $fueldisk | awk '{ print $5 }'` +rm -f $fueldisk +fallocate -l $disksize $fueldisk + +bootorder_hddvd fuel-master +sleep 3 +addisofile fuel-master $isofile +sleep 3 +virsh start fuel-master + +# wait for node up +echo "Waiting for Fuel master to accept SSH" +while true +do + ssh root@10.20.0.2 date 2>/dev/null + if [ $? -eq 0 ]; then + break + fi + sleep 10 +done + +# Wait until fuelmenu is up +echo "Waiting for fuelmenu to come up" +menuPid="" +while [ -z "$menuPid" ] +do + menuPid=`ssh root@10.20.0.2 "ps -ef" 2>&1 | grep fuelmenu | grep -v grep | awk '{ print $2 }'` + sleep 10 +done + +# This is where we would inject our own astute.yaml + +echo "Found menu as PID $menuPid, now killing it" +ssh root@10.20.0.2 "kill $menuPid" 2>/dev/null + +# Wait until installation complete +echo "Waiting for bootstrap of Fuel node to complete" +while true +do + ssh root@10.20.0.2 "ps -ef" 2>/dev/null \ + | grep -q /usr/local/sbin/bootstrap_admin_node + if [ $? -ne 0 ]; then + break + fi + sleep 10 +done + +echo "Waiting two minutes for Fuel to stabilize" +sleep 2m diff --git a/fuel/deploy/functions/isolinux.cfg.patch b/fuel/deploy/functions/isolinux.cfg.patch new file mode 100644 index 0000000..298a057 --- /dev/null +++ b/fuel/deploy/functions/isolinux.cfg.patch @@ -0,0 +1,14 @@ +*** isolinux/isolinux.cfg.orig 2015-04-15 08:29:52.026868322 -0400 +--- isolinux/isolinux.cfg 2015-04-15 08:30:34.350868343 -0400 +*************** +*** 19,22 **** + menu label Fuel Install (^Static IP) + menu default + kernel vmlinuz +! append initrd=initrd.img biosdevname=0 ks=cdrom:/ks.cfg ip=10.20.0.2 gw=10.20.0.1 dns1=10.20.0.1 netmask=255.255.255.0 hostname=fuel.domain.tld showmenu=no +--- 19,22 ---- + menu label Fuel Install (^Static IP) + menu default + kernel vmlinuz +! append initrd=initrd.img biosdevname=0 ks=cdrom:/ks.cfg ip=10.20.0.2 gw=10.20.0.1 dns1=10.20.0.1 netmask=255.255.255.0 hostname=fuel.domain.tld showmenu=yes + diff --git a/fuel/deploy/functions/ks.cfg.patch b/fuel/deploy/functions/ks.cfg.patch new file mode 100644 index 0000000..1896957 --- /dev/null +++ b/fuel/deploy/functions/ks.cfg.patch @@ -0,0 +1,19 @@ +*** ks.cfg.orig Wed Apr 15 21:47:09 2015 +--- ks.cfg Wed Apr 15 21:47:24 2015 +*************** +*** 35,41 **** + default_drive=`echo ${drives} ${removable_drives} | awk '{print $1}'` + + installdrive="undefined" +! forceformat="no" + for I in `cat /proc/cmdline`; do case "$I" in *=*) eval $I;; esac ; done + + set ${drives} ${removable_drives} +--- 35,41 ---- + default_drive=`echo ${drives} ${removable_drives} | awk '{print $1}'` + + installdrive="undefined" +! forceformat="yes" + for I in `cat /proc/cmdline`; do case "$I" in *=*) eval $I;; esac ; done + + set ${drives} ${removable_drives} diff --git a/fuel/deploy/functions/patch-iso.sh b/fuel/deploy/functions/patch-iso.sh new file mode 100755 index 0000000..782737e --- /dev/null +++ b/fuel/deploy/functions/patch-iso.sh @@ -0,0 +1,69 @@ +#!/bin/bash +############################################################################## +# Copyright (c) 2015 Ericsson AB and others. +# stefan.k.berg@ericsson.com +# jonas.bjurel@ericsson.com +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +# This is a temporary script - this should be rolled into a separate +# build target "make ci-iso" instead! + +exit_handler() { + rm -Rf $tmpnewdir + fusermount -u $tmporigdir 2>/dev/null + test -d $tmporigdir && mdir $tmporigdir +} + +trap exit_handler exit + +error_exit() { + echo "$@" + exit 1 +} + + +top=$(cd `dirname $0`; pwd) +origiso=$(cd `dirname $1`; echo `pwd`/`basename $1`) +newiso=$(cd `dirname $2`; echo `pwd`/`basename $2`) +tmpdir=$3 +tmporigdir=/${tmpdir}/origiso +tmpnewdir=/${tmpdir}/newiso + +test -f $origiso || error_exit "Could not find origiso $origiso" +test -d $tmpdir || error_exit "Could not find tmpdir $tmpdir" + + +if [ "`whoami`" != "root" ]; then + error_exit "You need be root to run this script" +fi + +echo "Copying..." +rm -Rf $tmporigdir $tmpnewdir +mkdir -p $tmporigdir $tmpnewdir +fuseiso $origiso $tmporigdir || error_exit "Failed fuseiso" +cd $tmporigdir +find . | cpio -pd $tmpnewdir +cd $tmpnewdir +fusermount -u $tmporigdir +rmdir $tmporigdir +chmod -R 755 $tmpnewdir + +echo "Patching..." +cd $tmpnewdir +# Patch ISO to make it suitable for automatic deployment +cat $top/ks.cfg.patch | patch -p0 || error_exit "Failed patch 1" +cat $top/isolinux.cfg.patch | patch -p0 || error_exit "Failed patch 2" +rm -rf .rr_moved + +echo "Creating iso $newiso" +mkisofs -quiet -r \ + -J -R -b isolinux/isolinux.bin \ + -no-emul-boot \ + -boot-load-size 4 -boot-info-table \ + --hide-rr-moved \ + -x "lost+found" -o $newiso . || error_exit "Failed making iso" + |