From patchwork Tue Jun 2 22:24:43 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Huff X-Patchwork-Id: 27572 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n52MQNOR012411 for ; Tue, 2 Jun 2009 22:26:24 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755209AbZFBWZf (ORCPT ); Tue, 2 Jun 2009 18:25:35 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755285AbZFBWZe (ORCPT ); Tue, 2 Jun 2009 18:25:34 -0400 Received: from mx2.redhat.com ([66.187.237.31]:56658 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755261AbZFBWZR (ORCPT ); Tue, 2 Jun 2009 18:25:17 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n52MPKE0004801 for ; Tue, 2 Jun 2009 18:25:20 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n52MPJcY030783; Tue, 2 Jun 2009 18:25:19 -0400 Received: from localhost.localdomain (dhcp231-89.rdu.redhat.com [10.11.231.89]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n52MPIJW032005; Tue, 2 Jun 2009 18:25:19 -0400 From: David Huff To: kvm@vger.kernel.org Cc: David Huff Subject: [PATCH][KVM_AUTOTEST] added script for unattended install Date: Tue, 2 Jun 2009 18:24:43 -0400 Message-Id: <1243981484-6391-2-git-send-email-dhuff@redhat.com> In-Reply-To: <1243981484-6391-1-git-send-email-dhuff@redhat.com> References: <1243981484-6391-1-git-send-email-dhuff@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org --- client/tests/kvm_runtest_2/scripts/unattended.sh | 220 ++++++++++++++++++++++ 1 files changed, 220 insertions(+), 0 deletions(-) create mode 100755 client/tests/kvm_runtest_2/scripts/unattended.sh diff --git a/client/tests/kvm_runtest_2/scripts/unattended.sh b/client/tests/kvm_runtest_2/scripts/unattended.sh new file mode 100755 index 0000000..7928117 --- /dev/null +++ b/client/tests/kvm_runtest_2/scripts/unattended.sh @@ -0,0 +1,220 @@ +#!/bin/bash +# +# unattended.sh - sets up environment for an unattended install for kvm_autotest +# +# Copyright (C) 2009 Red Hat, Inc. +# Written by: +# David Huff +# Darryl L. Pierce +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. A copy of the GNU General Public License is +# also available at http://www.gnu.org/copyleft/gpl.html. + + +ME=$(basename "$0") +warn() { printf '%s: %s\n' "$ME" "$*" >&2; } +die() { warn "$*"; exit 1; } +debug() { if $debugging; then log "[DEBUG] %s" "$*"; fi } + +set -e + +log () { + date=$(date) + printf "${date} $*\n" +} + +usage () { + cat < /dev/null 2>&1 + mkfs.msdos $filename + + #mount floppy disk image + mp=$(mktemp -d floppytmp.XXXXXX) + mount -t vfat -v -o loop $filename $mp + + #copy config file to disk + if [[ "$CONFIG" =~ \.ks\$ ]] || [["$CONFIG" =~ \.cfg\$ ]]; then + cp $CONFIG $mp/ks.cfg + else + cp $CONFIG $mp + fi + + #unmount floppy + df | grep $mp > /dev/null 2>&1 && umount -v $mp + rmdir $mp + + #change permissions + chmod 755 $filename +} + + +# setup pxeboot evironment +# $PXE - iso image +# $ARGS - kernel arguments +setup_pxeboot () { + local workdir=$PWD/tftpboot + local iso=$PXE + local pxedefault=$workdir/pxelinux.cfg/default + local pxelinux="/usr/lib/syslinux/pxelinux.0" + local cdlocation="images/pxeboot/" + + # Check pxelinux.0 exists. + if [ ! -f /usr/share/syslinux/pxelinux.0 -a ! -f /usr/lib/syslinux/pxelinux.0 ]; then + die "Warning: pxelinux.0 not found, Make sure syslinux or pxelinux is installed on this system." + fi + + #create clean tftpboot dir + if [ -d $workdir ]; then + log "$ME: subdirectory $workdir exists already. overwriting" + rm -rf $workdir + fi + + mkdir -p $workdir/pxelinux.cfg + + # pxelinux bootloader. + if [ -f /usr/share/syslinux/pxelinux.0 ]; then + cp /usr/share/syslinux/pxelinux.0 $workdir + elif [ -f /usr/lib/syslinux/pxelinux.0 ]; then + cp /usr/lib/syslinux/pxelinux.0 $workdir + else + die "Warning: pxelinux.0 not found, Make sure syslinux or pxelinux is installed on this system." + fi + + # get vmlinz and initrd form image + mp=$(mktemp -d cdtmp.XXXXXX) + mount -v -o loop "$iso" $mp + + # Does it look like an ISO? + if [ ! -d $mp/$cdlocation ]; then + die "The ISO image doesn't look like a ISO image to me." + fi + + cp $mp/$cdlocation/initrd.img $mp/$cdlocation/vmlinuz $workdir + df | grep $mp > /dev/null 2>&1 && umount -v $mp + rmdir $mp + + # set default kernel arguments if none were provided + if [ -z "$ARGS" ]; then + local $ARGS="" + fi + + local definition="DEFAULT pxeboot" + definition="${definition}\nTIMEOUT 20" + definition="${definition}\nPROMPT 0" + definition="${definition}\nLABEL pxeboot" + definition="${definition}\n KERNEL vmlinuz" + definition="${definition}\n IPAPPEND 2" + definition="${definition}\n APPEND initrd=initrd.img $ARGS" + + debug "pxeboot definition=\n${definition}" + printf "${definition}\n" > $pxedefault +} + +debugging=false +CONFIG= +NAME= +PXE= +ARGS= + +while getopts adc:n:p:k:vh c; do + case $c in + a) CONFIG=$KVM_TEST_unattended_file + NAME=$KVM_TEST_image + PXE=isos/$KVM_TEST_cdrom + ARGS=$KVM_TEST_kernel_args;; + d) debugging=true;; + c) CONFIG=$OPTARG;; + n) NAME=$OPTARG;; + p) PXE=$OPTARG;; + k) ARGS=$OPTARG;; + v) set -v;; + h) usage; exit 0;; + '?') die "invalid option \`-$OPTARG'";; + :) die "missing argument to \`-$OPTARG' option";; + *) die "internal error";; + esac +done + +shift $(($OPTIND - 1)) + +set +u +if [ $# -gt 0 -a -n "$1" ]; then RESULTS=$1; else RESULTS=unattended.log; fi +set -u + +# check to see we are root +if [ $( id -u ) -ne 0 ]; then + die "Must run as root" +fi + +log "$ME: Logging results to file: ${RESULTS}" + +# Require "-o OUTPUT_FILE" +if test -z $CONFIG; then + die "no config file for unattended install" +fi + +log "$ME: using unattended config file: $CONFIG" + +# create teh floppy image +create_floppy_disk $CONFIG +#create_virtual_floppy_disk $CONFIG + +#if [ $PXE ]; then + debug "$ME: using $PXE to set up pxe environmet" + setup_pxeboot +#fi