From e7b710d43a3fbb8a14feae76562fc459d75c2748 Mon Sep 17 00:00:00 2001 From: Axel Beckert Date: Tue, 27 Nov 2012 13:23:28 +0100 Subject: [PATCH 1/6] No more refer to forking in the comments --- bin/xen-create-image | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/xen-create-image b/bin/xen-create-image index 6826e28..6a4c553 100755 --- a/bin/xen-create-image +++ b/bin/xen-create-image @@ -4371,7 +4371,7 @@ sub END $CONFIG{ 'output' } . "/" . $CONFIG{ 'hostname' } . $CONFIG{ 'extension' }; - # Child. + # Start the DomU system("$CONFIG{'xm'} create $cfg >/dev/null 2>/dev/null"); logprint("Started new Xen guest: $CONFIG{'hostname'} [$cfg]\n"); From b99ca853e1c3ae7c3d8bfe1b718bd4b0b80566ee Mon Sep 17 00:00:00 2001 From: Axel Beckert Date: Tue, 27 Nov 2012 15:59:59 +0100 Subject: [PATCH 2/6] Replace system() by runCommand() --- bin/xen-create-image | 7 +++---- debian/changelog | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/xen-create-image b/bin/xen-create-image index 6a4c553..d0effb6 100755 --- a/bin/xen-create-image +++ b/bin/xen-create-image @@ -3974,7 +3974,7 @@ sub setupRootPassword { if ( -x $MOUNT_POINT . "/usr/bin/passwd" ) { - system("chroot $MOUNT_POINT /usr/bin/passwd"); + runCommand("chroot $MOUNT_POINT /usr/bin/passwd"); } else { @@ -4372,7 +4372,7 @@ sub END $CONFIG{ 'extension' }; # Start the DomU - system("$CONFIG{'xm'} create $cfg >/dev/null 2>/dev/null"); + runCommand("$CONFIG{'xm'} create $cfg"); logprint("Started new Xen guest: $CONFIG{'hostname'} [$cfg]\n"); } @@ -4421,8 +4421,7 @@ sub END } if ($options) { - system('xen-delete-image', $options, - "--hostname=$CONFIG{'hostname'}"); + runCommand("xen-delete-image $options --hostname=$CONFIG{'hostname'}"); } else { die "Assertion that either --dir, --lvm, or --dir are given". " failed.\nThis is probably a bug, please report it."; diff --git a/debian/changelog b/debian/changelog index 0c7034c..097d492 100644 --- a/debian/changelog +++ b/debian/changelog @@ -11,6 +11,7 @@ xen-tools (4.3.1+dev-1) UNRELEASED; urgency=low - Default DomUs to use the noop scheduler (Closes: #693131) - Remove CVS revisions from --version output - Preliminary support for Debian Jessie and Ubuntu Raring + - xen-create-image: Consistently use runCommand() instead of system() * Add debian/gbp.conf to be able to to build xen-tools with git-buildpackage. * Install (manually generated) upstream ChangeLog only if it From b54d5b84f9e5363fdc3803aa64f61f2e72c6c15f Mon Sep 17 00:00:00 2001 From: Axel Beckert Date: Tue, 27 Nov 2012 18:26:47 +0100 Subject: [PATCH 3/6] Refactoring: Replace $options with $option as it contains just one option --- bin/xen-create-image | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/xen-create-image b/bin/xen-create-image index d0effb6..0d202ae 100755 --- a/bin/xen-create-image +++ b/bin/xen-create-image @@ -4411,17 +4411,17 @@ sub END logprint("Removing failed install: $CONFIG{'hostname'}\n"); if ($CONFIG{ 'hostname' }) { - my $options = ''; + my $option = ''; if ($CONFIG{ 'lvm' }) { - $options = "--lvm=$CONFIG{'lvm'}" + $option = "--lvm=$CONFIG{'lvm'}" } elsif ($CONFIG{ 'evms' }) { - $options = "--evms=$CONFIG{'evms'}" + $option = "--evms=$CONFIG{'evms'}" } elsif ($CONFIG{ 'dir' }) { - $options = "--dir=$CONFIG{'dir'}" + $option = "--dir=$CONFIG{'dir'}" } - if ($options) { - runCommand("xen-delete-image $options --hostname=$CONFIG{'hostname'}"); + if ($option) { + runCommand("xen-delete-image $option --hostname=$CONFIG{'hostname'}"); } else { die "Assertion that either --dir, --lvm, or --dir are given". " failed.\nThis is probably a bug, please report it."; From e57e7f16eba58c514ce024212f100c5be9c14481 Mon Sep 17 00:00:00 2001 From: Axel Beckert Date: Tue, 27 Nov 2012 22:24:52 +0100 Subject: [PATCH 4/6] Preliminary support for the Xen xl toolstack (xen-create-image supported only so far) --- TODO.markdown | 5 +++++ bin/xen-create-image | 38 ++++++++++++++++++++++++++++++++++++-- bin/xen-create-nfs | 2 +- bin/xt-create-xen-config | 2 +- debian/changelog | 1 + 5 files changed, 44 insertions(+), 4 deletions(-) diff --git a/TODO.markdown b/TODO.markdown index 14e25ff..033ccf0 100644 --- a/TODO.markdown +++ b/TODO.markdown @@ -169,6 +169,11 @@ Bugs to fix and features to add for 5.0 * Support `cpu_weight` and other features from http://wiki.xensource.com/xenwiki/CreditScheduler +* Make used Xen toolstack configurable, i.e. via --xen-toolstack=xl + +* Support Xen xl toolstack elsewhere than xen-create-image. Needs code + deduplication as mentioned below. + * Code Deduplication / Refactor the code for less code duplication `bin/x*` currently contain the same or similar code like e.g. in the diff --git a/bin/xen-create-image b/bin/xen-create-image index 0d202ae..e625d06 100755 --- a/bin/xen-create-image +++ b/bin/xen-create-image @@ -310,7 +310,7 @@ Install a new distribution. Run a collection of hook scripts to customise the freshly installed system. =item B -Create a Xen configuration file in so that xm can start the new domain. +Create a Xen configuration file in so that xm/xl can start the new domain. =back @@ -1282,7 +1282,7 @@ sub setupDefaultOptions # Paths and files. # $CONFIG{ 'dir' } = ''; - $CONFIG{ 'xm' } = findBinary("xm"); + $CONFIG{ 'xm' } = findXenToolstack(); $CONFIG{ 'kernel' } = ''; $CONFIG{ 'modules' } = ''; $CONFIG{ 'initrd' } = ''; @@ -1391,6 +1391,40 @@ sub setupDefaultOptions +=begin doc + + Find the right Xen toolstack. On Debian and derivatives there's a + script which tells you about the current toolstack. + +=end doc + +=cut + +sub findXenToolstack +{ + my $helper = '/usr/lib/xen-common/bin/xen-toolstack'; + + if (-x $helper) { + my $toolstack = `$helper`; + chomp($toolstack); + return $toolstack if $toolstack; + } + + my $xm = findBinary('xm'); + if ($xm and system("$xm list >/dev/null 2>/dev/null") == 0) { + return $xm; + } + + my $xl = findBinary('xl'); + if ($xl and system("$xl list >/dev/null 2>/dev/null") == 0) { + return $xl; + } + + return undef; +} + + + =begin doc Read the specified configuration file, and update our global configuration diff --git a/bin/xen-create-nfs b/bin/xen-create-nfs index 4f72c6f..2755551 100755 --- a/bin/xen-create-nfs +++ b/bin/xen-create-nfs @@ -472,7 +472,7 @@ sub setupAdminUsers open( SUDOERS, ">>", "/etc/sudoers" ) or warn "Failed to add user to sudoers file : $user - $!"; print SUDOERS - "$user ALL = NOPASSWD: /usr/sbin/xm, /usr/bin/xen-create-image\n"; + "$user ALL = NOPASSWD: /usr/sbin/xm, /usr/sbin/xl, /usr/bin/xen-create-image\n"; close(SUDOERS); } diff --git a/bin/xt-create-xen-config b/bin/xt-create-xen-config index 9ef8bf2..0905348 100755 --- a/bin/xt-create-xen-config +++ b/bin/xt-create-xen-config @@ -536,7 +536,7 @@ sub setupAdminUsers open( SUDOERS, ">>", "/etc/sudoers" ) or warn "Failed to add user to sudoers file : $user - $!"; print SUDOERS - "$user ALL = NOPASSWD: /usr/sbin/xm, /usr/bin/xen-create-image\n"; + "$user ALL = NOPASSWD: /usr/sbin/xm, /usr/sbin/xl, /usr/bin/xen-create-image\n"; close(SUDOERS); } diff --git a/debian/changelog b/debian/changelog index 097d492..9e59237 100644 --- a/debian/changelog +++ b/debian/changelog @@ -11,6 +11,7 @@ xen-tools (4.3.1+dev-1) UNRELEASED; urgency=low - Default DomUs to use the noop scheduler (Closes: #693131) - Remove CVS revisions from --version output - Preliminary support for Debian Jessie and Ubuntu Raring + - Preliminary support for xl toolstack (xen-create-image only so far) - xen-create-image: Consistently use runCommand() instead of system() * Add debian/gbp.conf to be able to to build xen-tools with git-buildpackage. From 8f1f29855160b6656e54f7ece978a74fc7f1f18c Mon Sep 17 00:00:00 2001 From: Axel Beckert Date: Tue, 27 Nov 2012 22:28:38 +0100 Subject: [PATCH 5/6] New option to dump contents of %CONFIG Probably only needed for debugging. --- bin/xen-create-image | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/bin/xen-create-image b/bin/xen-create-image index e625d06..1eceb88 100755 --- a/bin/xen-create-image +++ b/bin/xen-create-image @@ -17,6 +17,8 @@ xen-create-image - Easily create new Xen instances with networking and OpenSSH. --verbose Show useful debugging information. + --dumpconfig Show current configuration. + --version Show the version number and exit. @@ -784,7 +786,7 @@ use File::Temp qw/ tempdir /; use File::Copy qw/ mv cp /; use Getopt::Long; use Pod::Usage; - +use Data::Dumper; # @@ -1662,9 +1664,10 @@ sub checkOption =cut -my $HELP = 0; -my $MANUAL = 0; -my $VERSION = 0; +my $HELP = 0; +my $MANUAL = 0; +my $DUMPCONFIG = 0; +my $VERSION = 0; sub parseCommandLineArguments { @@ -1772,11 +1775,12 @@ sub parseCommandLineArguments "dontformat", \&checkOption, # Help options - "debug", \$CONFIG{ 'debug' }, - "help", \$HELP, - "manual", \$MANUAL, - "verbose", \$CONFIG{ 'verbose' }, - "version", \$VERSION + "debug", \$CONFIG{ 'debug' }, + "help", \$HELP, + "manual", \$MANUAL, + "dumpconfig", \$DUMPCONFIG, + "verbose", \$CONFIG{ 'verbose' }, + "version", \$VERSION ) ) { $FAIL = 2; @@ -1837,6 +1841,12 @@ sub parseCommandLineArguments $CONFIG{ 'swap-dev' } = $install{ 'swap-dev' } if ( defined( $install{ 'swap-dev' } ) ); } + + if ($DUMPCONFIG) + { + print Dumper \%CONFIG; + exit 0; + } } @@ -4337,7 +4347,7 @@ sub unMountImage sub END { - exit 0 if $VERSION || $HELP || $MANUAL; + exit 0 if $VERSION || $HELP || $MANUAL || $DUMPCONFIG; my $host_rsa_key = ''; # From 83eede665c39ed25ea315f13823ffa43204578f4 Mon Sep 17 00:00:00 2001 From: Axel Beckert Date: Tue, 27 Nov 2012 22:29:04 +0100 Subject: [PATCH 6/6] Fix warning about no_plan usage in t/hook-inittab.t --- t/hook-inittab.t | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/t/hook-inittab.t b/t/hook-inittab.t index ecfb7ed..b39fd11 100755 --- a/t/hook-inittab.t +++ b/t/hook-inittab.t @@ -7,7 +7,7 @@ # use strict; -use Test::More 'no_plan', skip_all => '/etc/inittab not present'; +use Test::More; use File::Temp; use File::Copy; @@ -41,6 +41,7 @@ SKIP: { } # SKIP +done_testing(); sub testHook {