Perry Myers
2008-Nov-08 22:49 UTC
[Ovirt-devel] [PATCH node-image] Added script for creating fake oVirt Nodes for testing
Nodes are created via virt-install and are booted off of node ISO image present in the RPM Signed-off-by: Perry Myers <pmyers at redhat.com> --- Makefile.am | 3 +- create-ovirt-iso-nodes | 90 ++++++++++++++++++++++++++++++++++++++++++++++ ovirt-node-image.spec.in | 2 + 3 files changed, 94 insertions(+), 1 deletions(-) create mode 100755 create-ovirt-iso-nodes diff --git a/Makefile.am b/Makefile.am index a3d4828..8f7d7b9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -31,7 +31,8 @@ EXTRA_DIST = \ ovirt-flash \ ovirt-flash-static \ ovirt-node-image.ks \ - ovirt-pxe + ovirt-pxe \ + create-ovirt-iso-nodes DISTCLEANFILES = $(PACKAGE)-$(VERSION).tar.gz diff --git a/create-ovirt-iso-nodes b/create-ovirt-iso-nodes new file mode 100755 index 0000000..6cb76f6 --- /dev/null +++ b/create-ovirt-iso-nodes @@ -0,0 +1,90 @@ +#!/bin/bash +# +# Create fake oVirt Nodes for testing CDROM boot +# Copyright 2008 Red Hat, Inc. +# Written by Perry Myers <pmyers at redhat.com> +# +# 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 Library 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +PATH=$PATH:/sbin:/usr/sbin + +ME=$(basename "$0") +warn() { printf '%s: %s\n' "$ME" "$*" >&2; } +try_h() { printf "Try \`$ME -h' for more information.\n" >&2; } +die() { warn "$@"; try_h; exit 1; } + +BRIDGENAME=ovirtbr0 +IMGDIR_DEFAULT=/var/lib/libvirt/images +imgdir=$IMGDIR_DEFAULT + +gen_fake_managed_node() { + local num=$1 + local nodeimg=$2 + local last_mac=$(( 54 + $num )) + + echo "Creating fake node$num using $nodeimg..." + virsh destroy node$num > /dev/null 2>&1 + virsh undefine node$num > /dev/null 2>&1 + # FIXME: virt-install should be changed to have a --nostart parameter + # that just defines the VM w/o starting it. + virt-install --name=node$num --ram=512 --vcpus=1 \ + --disk path=$imgdir/node${i}-sda.raw,size=.15 \ + --cdrom=$nodeimg --livecd \ + --network=bridge:$BRIDGENAME --mac=00:16:3e:12:34:$last_mac \ + --vnc --accelerate --hvm --noautoconsole \ + --os-type=linux --os-variant=fedora9 \ + --force --noreboot + virsh destroy node$num > /dev/null 2>&1 + echo "node$num created" +} + +usage() { + case $# in 1) warn "$1"; try_h; exit 1;; esac + cat <<EOF +Usage: $ME [-d image_dir] -n node.iso + -n: node.iso to boot + -d: directory to place virtual disk (default: $IMGDIR_DEFAULT) + -h: display this help and exit +EOF +} + +err=0 help=0 +while getopts :d:n:h c; do + case $c in + n) nodeimg=$OPTARG;; + d) imgdir=$OPTARG;; + h) help=1;; + '?') err=1; warn "invalid option: \`-$OPTARG'";; + :) err=1; warn "missing argument to \`-$OPTARG' option";; + *) err=1; warn "internal error: \`-$OPTARG' not handled";; + esac +done +test $err = 1 && { try_h; exit 1; } +test $help = 1 && { usage; exit 0; } +test -z "$nodeimg" && { usage ; exit 1; } + +# first, check to see we are root +if [ $( id -u ) -ne 0 ]; then + die "Must run as root" +fi + +mkdir -p $imgdir + +test -f $nodeimg || die "could not find $nodeimg" +cp $nodeimg $imgdir + +# define the fake managed nodes we will use. +for i in `seq 3 5` ; do + gen_fake_managed_node $i $imgdir/$(basename $nodeimg) +done diff --git a/ovirt-node-image.spec.in b/ovirt-node-image.spec.in index 086dff6..138f4a4 100644 --- a/ovirt-node-image.spec.in +++ b/ovirt-node-image.spec.in @@ -67,6 +67,7 @@ mkdir %{buildroot} %{__install} -p -m0755 ovirt-pxe %{buildroot}%{_sbindir} %{__install} -p -m0755 ovirt-flash %{buildroot}%{_sbindir} %{__install} -p -m0755 ovirt-flash-static %{buildroot}%{_sbindir} +%{__install} -p -m0755 create-ovirt-iso-nodes %{buildroot}%{_sbindir} %clean %{__rm} -rf %{buildroot} @@ -81,6 +82,7 @@ cobbler sync > /dev/null 2>&1 || : %{_sbindir}/ovirt-pxe %{_sbindir}/ovirt-flash %{_sbindir}/ovirt-flash-static +%{_sbindir}/create-ovirt-iso-nodes %files pxe %defattr(-,root,root,0644) -- 1.6.0.3
Alan Pevec
2008-Nov-09 00:11 UTC
[Ovirt-devel] Re: [PATCH node-image] Added script for creating fake oVirt Nodes for testing
Perry Myers wrote:> Nodes are created via virt-install and are booted off of node ISO imageACK All: this requires updated python-virtinst 0.400 - so you need to: yum --enablerepo=ovirt update