From 57e6d5d480b99f57d426546c2a4cf84296403925 Mon Sep 17 00:00:00 2001 From: Axel Beckert Date: Mon, 7 May 2012 22:55:33 +0200 Subject: [PATCH 1/4] Use $ips instead of $IP_ADDRESSES to keep variable names consistent Update t/xt-create-xen-config.t to cope with the new variable --- bin/xen-create-image | 2 +- etc/xm.tmpl | 2 +- t/xt-create-xen-config.t | 14 +++++++------- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bin/xen-create-image b/bin/xen-create-image index df42c97..d41d528 100755 --- a/bin/xen-create-image +++ b/bin/xen-create-image @@ -3992,7 +3992,7 @@ sub runXenConfigCreation # # Make sure the template gets a list of all IPs # - $ENV{ 'IP_ADDRESSES' } = $IP_ADDRESSES; + $ENV{ 'ips' } = $IP_ADDRESSES; logprint("\nCreating Xen configuration file\n"); diff --git a/etc/xm.tmpl b/etc/xm.tmpl index c35d0de..e023560 100644 --- a/etc/xm.tmpl +++ b/etc/xm.tmpl @@ -135,7 +135,7 @@ name = '{$hostname}' $br = ",bridge=$bridge" } - $OUT .= "vif = [ 'ip=$IP_ADDRESSES"; + $OUT .= "vif = [ 'ip=$ips"; $OUT .= "$m"; $OUT .= "$vn"; $OUT .= "$br"; diff --git a/t/xt-create-xen-config.t b/t/xt-create-xen-config.t index 13539f5..e304f85 100755 --- a/t/xt-create-xen-config.t +++ b/t/xt-create-xen-config.t @@ -36,28 +36,28 @@ noMentionOf( "ip=", # is no mention of DHCP. # testOutputContains( "ip=192.168.1.1", - memory => 128, ip1 => '192.168.1.1', dir => '/tmp' ); + memory => 128, ips => '192.168.1.1', dir => '/tmp' ); noMentionOf( "dhcp", - memory => 128, ip1 => '192.168.1.1', dir => '/tmp' ); + memory => 128, ips => '192.168.1.1', dir => '/tmp' ); # # SCSI based systems: # testOutputContains( "xvda", - memory => 128, ip1 => '192.168.1.1', dir => '/tmp' ); + memory => 128, ips => '192.168.1.1', dir => '/tmp' ); testOutputContains( "/dev/xvda1 ro", - memory => 128, ip1 => '192.168.1.1', dir => '/tmp' ); + memory => 128, ips => '192.168.1.1', dir => '/tmp' ); noMentionOf( "hda1", - memory => 128, ip1 => '192.168.1.1', dir => '/tmp' ); + memory => 128, ips => '192.168.1.1', dir => '/tmp' ); # # IDE based systems # testOutputContains( "hda1", - memory => 128, ip1 => '192.168.1.1', dir => '/tmp', ide => 1 ); + memory => 128, ips => '192.168.1.1', dir => '/tmp', ide => 1 ); testOutputContains( "/dev/hda1 ro", - memory => 128, ip1 => '192.168.1.1', dir => '/tmp', ide => 1 ); + memory => 128, ips => '192.168.1.1', dir => '/tmp', ide => 1 ); From 7a01a08aa4b869c34039f9a8b1e70eb275d07345 Mon Sep 17 00:00:00 2001 From: Axel Beckert Date: Mon, 7 May 2012 22:56:33 +0200 Subject: [PATCH 2/4] Replace tabs with spaces --- bin/xen-create-nfs | 30 +++++++++---------- bin/xt-guess-suite-and-mirror | 56 +++++++++++++++++------------------ 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/bin/xen-create-nfs b/bin/xen-create-nfs index 5b1dc3a..a118c94 100755 --- a/bin/xen-create-nfs +++ b/bin/xen-create-nfs @@ -385,23 +385,23 @@ sub testArguments # this code is borrowed for now... if ( exists($CONFIG{ 'memory' }) and - defined($CONFIG{ 'memory' }) ) { + defined($CONFIG{ 'memory' }) ) { - # - # The memory size: Convert Gb -> Mb. - # - if ( $CONFIG{ 'memory' } =~ /^(\d+)Gb.*$/i ) - { - $CONFIG{ 'memory' } = $1 * 1024; - } + # + # The memory size: Convert Gb -> Mb. + # + if ( $CONFIG{ 'memory' } =~ /^(\d+)Gb.*$/i ) + { + $CONFIG{ 'memory' } = $1 * 1024; + } - # - # Remove any trailing Mb. - # - if ( $CONFIG{ 'memory' } =~ /^(\d+)Mb.*$/i ) - { - $CONFIG{ 'memory' } = $1; - } + # + # Remove any trailing Mb. + # + if ( $CONFIG{ 'memory' } =~ /^(\d+)Mb.*$/i ) + { + $CONFIG{ 'memory' } = $1; + } } # All OK. diff --git a/bin/xt-guess-suite-and-mirror b/bin/xt-guess-suite-and-mirror index 7bf4e16..a8bb8c3 100755 --- a/bin/xt-guess-suite-and-mirror +++ b/bin/xt-guess-suite-and-mirror @@ -69,7 +69,7 @@ my %fallback_suite = ( Debian => 'stable', # Where to look for the sources.list to parse my @sources_list_files = ( '/etc/apt/sources.list', - glob('/etc/apt/sources.list.d/*.list')); + glob('/etc/apt/sources.list.d/*.list')); use File::Slurp; use Getopt::Long; @@ -111,43 +111,43 @@ if ($want_manual) { all_sources_list_files: foreach my $sources_list_file (@sources_list_files) { if (-r $sources_list_file) { - # sources.list file exists, so it's something debianoid. + # sources.list file exists, so it's something debianoid. - # read sources.list and split it into lines - my @sources_list = read_file($sources_list_file); + # read sources.list and split it into lines + my @sources_list = read_file($sources_list_file); - # Find the first line which is a Debian or Ubuntu mirror but not - # an updates, backports, volatile or security mirror. - foreach my $sources_list_entry (@sources_list) { - # Normalize line - chomp($sources_list_entry); - $sources_list_entry =~ s/^\s*(.*?)\s*$/$1/; + # Find the first line which is a Debian or Ubuntu mirror but not + # an updates, backports, volatile or security mirror. + foreach my $sources_list_entry (@sources_list) { + # Normalize line + chomp($sources_list_entry); + $sources_list_entry =~ s/^\s*(.*?)\s*$/$1/; - # Skip definite non-entries - next if $sources_list_entry =~ /^\s*($|#)/; + # Skip definite non-entries + next if $sources_list_entry =~ /^\s*($|#)/; - # Split up into fields - my @source_components = split(/\s+/, $sources_list_entry); + # Split up into fields + my @source_components = split(/\s+/, $sources_list_entry); - # Minimum number of components is 4 - next if $#source_components < 3; + # Minimum number of components is 4 + next if $#source_components < 3; - # Don't use deb-src entries. - next if $source_components[0] eq 'deb-src'; + # Don't use deb-src entries. + next if $source_components[0] eq 'deb-src'; - # Skip updates, backports, volatile or security mirror. - next if $source_components[2] !~ /^[a-z]+$/; + # Skip updates, backports, volatile or security mirror. + next if $source_components[2] !~ /^[a-z]+$/; - if ($source_components[1] =~ m(/debian/?$|/ubuntu/?$)) { - # Seems a typical mirror. Let's use that one + if ($source_components[1] =~ m(/debian/?$|/ubuntu/?$)) { + # Seems a typical mirror. Let's use that one - $mirror = $source_components[1]; - $suite = $source_components[2]; + $mirror = $source_components[1]; + $suite = $source_components[2]; - $found = 1; - last all_sources_list_files; - } - } + $found = 1; + last all_sources_list_files; + } + } } } die "Couldn't find a useful entry in the sources.list files of the Dom0. Tried:\n ". From b5175f6f3b9290c8c19283f4fe59e90decba6c49 Mon Sep 17 00:00:00 2001 From: Axel Beckert Date: Mon, 7 May 2012 23:42:31 +0200 Subject: [PATCH 3/4] Properly set $FAIL instead of just calling die() --- bin/xen-create-image | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/bin/xen-create-image b/bin/xen-create-image index d41d528..959713c 100755 --- a/bin/xen-create-image +++ b/bin/xen-create-image @@ -1251,7 +1251,7 @@ sub testXenConfig # Read the configuration file. # open( CONFIG, "<", "/etc/xen/xend-config.sxp" ) or - die "Failed to read /etc/xen/xend-config.sxp: $!"; + fail("Failed to read /etc/xen/xend-config.sxp: $!"); while () { next if ( !$_ || !length($_) ); @@ -1451,7 +1451,7 @@ sub readConfigurationFile my $line = ""; - open( FILE, "<", $file ) or die "Cannot read file '$file' - $!"; + open( FILE, "<", $file ) or fail("Cannot read file '$file' - $!"); while ( defined( $line = ) ) { @@ -1640,7 +1640,7 @@ sub checkOption my $type = $optionsTypes{ $option }; # First, check if type exists - die unless exists $types{ $type }; + fail("Type $type does not exist") unless exists $types{ $type }; my $check = $types{ $type }{ 'check' }; if ( @@ -1656,7 +1656,7 @@ sub checkOption } } else { # Option did _not_ validate - die "ERROR: '$option' argument " . $types{ $type }{ 'message' }; + fail("ERROR: '$option' argument " . $types{ $type }{ 'message' }); } } } @@ -2940,7 +2940,7 @@ sub createLoopbackImages eval {mkpath( $output, 0, 0755 );}; if ($@) { - die "Cannot create directory tree $output - $@"; + fail("Cannot create directory tree $output - $@"); } } @@ -3759,7 +3759,7 @@ sub findIP # Open and read the file. # open( RANGE, "<", $CONFIG{ 'ipfile' } ) or - die "Failed to read $CONFIG{'ipfile'} - $!"; + fail("Failed to read $CONFIG{'ipfile'} - $!"); my @lines = ; my @updated; close(RANGE); @@ -3790,7 +3790,7 @@ sub findIP # Now write out the new entries. # open( RANGE, ">", $CONFIG{ 'ipfile' } ) or - die "Failed to write to $CONFIG{'ipfile'} - $!"; + fail("Failed to write to $CONFIG{'ipfile'} - $!"); print RANGE join( "\n", @updated ); close(RANGE); @@ -4063,7 +4063,7 @@ sub setupRootPassword } else { - die "oops... unknown hashing method, should not happen!"; + fail("oops... unknown hashing method, should not happen!"); } my $hash = crypt($PASSWORD, $hash_method . $salt); @@ -4074,8 +4074,8 @@ sub setupRootPassword # my $tmp_shadow_path = "$shadow_path.tmp"; cp("$shadow_path","$tmp_shadow_path"); - open(TMP, "<", $tmp_shadow_path) or die $!; - open(SHADOW, ">", $shadow_path) or die $!; + open(TMP, "<", $tmp_shadow_path) or fail($!); + open(SHADOW, ">", $shadow_path) or fail($!); my $line; while(defined($line = )) { @@ -4116,6 +4116,23 @@ sub generatePassword { } +=begin doc + + Properly set $FAIL on die + +=end doc + +=cut + +sub fail +{ + logprint(@_); + $FAIL = 1; + exit 127; +} + + + =begin doc Print the given string to the logfile. From 846266eedb7cefc929fa2d341c1fad4897a67cff Mon Sep 17 00:00:00 2001 From: Axel Beckert Date: Tue, 8 May 2012 00:11:23 +0200 Subject: [PATCH 4/4] Mention Alexander Mette in the changelog as he also sent a patch for #652110, just upstream --- debian/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 3c54ded..1ec1195 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,7 +10,7 @@ xen-tools (4.2.1+dev-1) UNRELEASED; urgency=low #648814) - Fix wildcard vs regexp in memory configuration parsing. - Fix misbehaviour if --ip option is passed multiple times (Closes: - #652110; Thanks Brian Bennett!) + #652110; Thanks Brian Bennett and Alexander Mette!) - Supports /etc/apt/sources.list.d/ (Closes: #650300) - xt-guess-suite-and-mirror exits with non-zero if no proper mirror could be extracted from /etc/apt/sources.list or