pf-tools commit: r851 [ccaillet-guest] - in /branches/next-gen: debian/changelog lib/PFTools/Conf.pm lib/PFTools/Host.pm lib/PFTools/Logger.pm lib/PFTools/Update/Addmount.pm lib/PFTools/Utils.pm lib/PFTools/VCS.pm

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Fri Aug 27 08:31:30 UTC 2010


Author: ccaillet-guest
Date: Fri Aug 27 08:31:29 2010
New Revision: 851

URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=851
Log:
  - aborting when a depend is explicited but not defined
  - parameter for order sections list is now passed with an array ref instead
  of an array

Modified:
    branches/next-gen/debian/changelog
    branches/next-gen/lib/PFTools/Conf.pm
    branches/next-gen/lib/PFTools/Host.pm
    branches/next-gen/lib/PFTools/Logger.pm
    branches/next-gen/lib/PFTools/Update/Addmount.pm
    branches/next-gen/lib/PFTools/Utils.pm
    branches/next-gen/lib/PFTools/VCS.pm

Modified: branches/next-gen/debian/changelog
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/debian/changelog?rev=851&op=diff
==============================================================================
--- branches/next-gen/debian/changelog (original)
+++ branches/next-gen/debian/changelog Fri Aug 27 08:31:29 2010
@@ -23,6 +23,9 @@
   * lib/PFTools/Update.pm
     - splitting $FUNCTION and $DEPENDS to perl package under PFTools::Update::*
     - privatizing __Trie_prio and fix for action installpkg or purgepkg
+    - aborting when a depend is explicited but not defined
+    - parameter for order sections list is now passed with an array ref instead
+    of an array
   * lib/PFTools/Update/Common.pm
     - extracting common functions from Update.pm which are used by $FUNCTION
     and $DEPENDS in lib/PFTools/Update.pm
@@ -55,7 +58,7 @@
   * TODO
     - adding more TODOs :)
 
- -- Christophe Caillet <quadchris at free.fr>  Thu, 26 Aug 2010 12:40:25 +0200
+ -- Christophe Caillet <quadchris at free.fr>  Fri, 27 Aug 2010 10:27:11 +0200
 
 pf-tools (0.99.98-1) unstable; urgency=low
 

Modified: branches/next-gen/lib/PFTools/Conf.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Conf.pm?rev=851&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Conf.pm (original)
+++ branches/next-gen/lib/PFTools/Conf.pm Fri Aug 27 08:31:29 2010
@@ -49,6 +49,8 @@
 	Get_source
 	Get_config_for_hostname_on_site
 );
+
+our @EXPORT_OK = qw();
 
 ##########################
 ### Prototypes
@@ -222,35 +224,39 @@
 	'owner'				=> '([\d]+|[a-z\d\-]+)',
 	'group'				=> '([\d]+|[a-z\d\-]+)',
 	'mode'				=> '[0-7]?[0-7]{3}',
+	'on_config'			=> 'undefined',
 	'before_change'		=> 'undefined',
 	'on_noaction'		=> 'undefined',
 	'after_change'		=> 'undefined'
 };
 $DEF_SECTIONS->{'config'}->{'createfile'} = {
-	'depends'			=> 'undefined',
-	'source'			=> 'undefined',
-	'filter'			=> 'undefined',
-	'owner'				=> '([\d]+|[a-z\d\-]+)',
-	'group'				=> '([\d]+|[a-z\d\-]+)',
-	'mode'				=> '[0-7]?[0-7]{3}',
-	'before_change'		=> 'undefined',
-	'on_noaction'		=> 'undefined',
-	'after_change'		=> 'undefined'
+	'depends'		=> 'undefined',
+	'source'		=> 'undefined',
+	'filter'		=> 'undefined',
+	'owner'			=> '([\d]+|[a-z\d\-]+)',
+	'group'			=> '([\d]+|[a-z\d\-]+)',
+	'mode'			=> '[0-7]?[0-7]{3}',
+	'on_config'		=> 'undefined',
+	'before_change'	=> 'undefined',
+	'on_noaction'	=> 'undefined',
+	'after_change'	=> 'undefined'
 };
 $DEF_SECTIONS->{'config'}->{'removefile'} = {
 
 };
 $DEF_SECTIONS->{'config'}->{'mkdir'} = {
-	'owner'				=> '([\d]+|[a-z\d\-]+)',
-	'group'				=> '([\d]+|[a-z\d\-]+)',
-	'mode'				=> '0?[0-7]{3}',
-	'before_change'		=> 'undefined',
-	'on_noaction'		=> 'undefined',
-	'after_change'		=> 'undefined'
+	'owner'			=> '([\d]+|[a-z\d\-]+)',
+	'group'			=> '([\d]+|[a-z\d\-]+)',
+	'mode'			=> '0?[0-7]{3}',
+	'on_config'		=> 'undefined',
+	'before_change'	=> 'undefined',
+	'on_noaction'	=> 'undefined',
+	'after_change'	=> 'undefined'
 };
 $DEF_SECTIONS->{'config'}->{'addlink'} = {
 	'MANDATORY_KEYS'	=> [ 'source' ],
 	'source'			=> 'undefined',
+	'on_config'			=> 'undefined',
 	'before_change'		=> 'undefined',
 	'on_noaction'		=> 'undefined',
 	'after_change'		=> 'undefined'
@@ -264,9 +270,10 @@
 	'mode'				=> '0?[0-7]{3}'
 };
 $DEF_SECTIONS->{'config'}->{'apt-get'} = {
-	'before_change'		=> 'undefined',
-	'on_noaction'		=> 'undefined',
-	'after_change'		=> 'undefined'
+	'on_config'		=> 'undefined',
+	'before_change'	=> 'undefined',
+	'on_noaction'	=> 'undefined',
+	'after_change'	=> 'undefined'
 };
 $DEF_SECTIONS->{'config'}->{'installpkg'} = $DEF_SECTIONS->{'config'}->{'apt-get'};
 $DEF_SECTIONS->{'config'}->{'dpkg-purge'} = $DEF_SECTIONS->{'config'}->{'apt-get'};
@@ -274,7 +281,12 @@
 	'MANDATORY_KEYS'	=> [ 'filter' ],
 	'filter'			=> 'undefined'
 };
-our @EXPORT_OK = qw();
+$DEF_SECTIONS->{'config'}->{'group'} = {
+	'on_config'		=> 'undefined',
+	'before_change'	=> 'undefined',
+	'on_noaction'	=> 'undefined',
+	'after_change'	=> 'undefined'
+};
 
 my $DEBUG	= 0 ;
 
@@ -580,6 +592,16 @@
 		my $select = ( $context eq 'config' ) ? 'action' : 'type';
 		foreach my $section ( @{$hash_to_merge->{'__sections_order'}} ) {
 			if ( $hash_to_merge->{$section}->{$select} ne 'include' ) {
+				my $group = $hash_to_merge->{$section}->{'group'} || "";
+				if ( $context eq 'config' && $group ne '' ) {
+					$global_parsed->{'__triggers'} = {} if ( ! defined $global_parsed->{'__triggers'} );
+					if ( ! defined $global_parsed->{'__triggers'}->{$group} ) {
+						$global_parsed->{'__triggers'}->{$group} = 1;
+					}
+					else {
+						$global_parsed->{'__triggers'}->{$group}++;
+					}
+				}
 				push ( @{$global_parsed->{'__sections_order'}}, $section );
 				$global_parsed->{$section} = $hash_to_merge->{$section};
 			}
@@ -627,7 +649,7 @@
 
 	# Basic checks
 	foreach my $section ( keys %{$parsed} ) {
-		next if ( $section eq '__sections_order' );
+		next if ( $section =~ /^__/ );
 		if ( $context =~ /^host|model$/ ) {
 			$section =~ /^([^:]+)(::.+)?$/;
 			$sect_type = $1;
@@ -654,7 +676,7 @@
 
 	# Basic checks
 	foreach my $section ( keys %{$parsed} ) {
-		next if ( $section eq '__sections_order' );
+		next if ( $section =~ /^__/ );
 		if ( $context =~ /^(host|model)$/ ) {
 			$section =~ /^([^:]+)(::(.+))?$/;
 			$sect_type = $1;

Modified: branches/next-gen/lib/PFTools/Host.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Host.pm?rev=851&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Host.pm (original)
+++ branches/next-gen/lib/PFTools/Host.pm Fri Aug 27 08:31:29 2010
@@ -760,9 +760,10 @@
 								}
 							}
 							$dhcp_part->{$dhcpvlan}->{$hostclass} = {} if ( ! defined $dhcp_part->{$dhcpvlan}->{$hostclass} );
+							my $fixed_addr = $if2add->{$ip_type}; $fixed_addr =~ s!/[\d]+$!!;
 							$dhcp_part->{$dhcpvlan}->{$hostclass}->{$hostname} = [
 								'hardware ethernet '.$if2add->{'mac'}.';',
-								'fixed-address '.$if2add->{$ip_type}.';',
+								'fixed-address '.$fixed_addr.';',
 								'filename '.$host2add->{'boot'}->{'pxefilename'}.';',
 								'option domain-name-servers '.$resolver.';'
 							];

Modified: branches/next-gen/lib/PFTools/Logger.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Logger.pm?rev=851&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Logger.pm (original)
+++ branches/next-gen/lib/PFTools/Logger.pm Fri Aug 27 08:31:29 2010
@@ -122,18 +122,18 @@
     $deferbuffer = <STDOUT>;
 
     if ( defined( $sortie->{'_stdout'} ) ) {
-	local *REAL_STDOUT;
-	*REAL_STDOUT = $sortie->{'_stdout'};
-	open( STDOUT, ">&REAL_STDOUT" ) or warn "Can't restore STDOUT: $!
-    +";
-	undef( $sortie->{'_stdout'} );
+		local *REAL_STDOUT;
+		*REAL_STDOUT = $sortie->{'_stdout'};
+		open( STDOUT, ">&REAL_STDOUT" ) or warn "Can't restore STDOUT: $!
+		+";
+		undef( $sortie->{'_stdout'} );
     }
     if ( defined( $sortie->{'_stderr'} ) ) {
-	local *REAL_STDERR;
-	*REAL_STDERR = $sortie->{'_stderr'};
-	open( STDERR, ">&REAL_STDERR" ) or warn "Can't restore STDERR: $!
-    +";
-	undef( $sortie->{'_stderr'} );
+		local *REAL_STDERR;
+		*REAL_STDERR = $sortie->{'_stderr'};
+		open( STDERR, ">&REAL_STDERR" ) or warn "Can't restore STDERR: $!
+		+";
+		undef( $sortie->{'_stderr'} );
     }
     select STDERR;
     $| = 1;

Modified: branches/next-gen/lib/PFTools/Update/Addmount.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Update/Addmount.pm?rev=851&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Update/Addmount.pm (original)
+++ branches/next-gen/lib/PFTools/Update/Addmount.pm Fri Aug 27 08:31:29 2010
@@ -41,7 +41,6 @@
 use PFTools::Conf;
 use PFTools::Net;
 use PFTools::Disk;
-use PFTools::Utils;
 use PFTools::Structqueries;
 use PFTools::Update::Common;
 use PFTools::Update::Mkdir;

Modified: branches/next-gen/lib/PFTools/Utils.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Utils.pm?rev=851&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Utils.pm (original)
+++ branches/next-gen/lib/PFTools/Utils.pm Fri Aug 27 08:31:29 2010
@@ -44,8 +44,6 @@
 	Search_and_replace
 );
 
-our @EXPORT_OK = qw();
-
 use Fcntl ':mode';
 use POSIX qw(ceil floor);
 
@@ -53,7 +51,6 @@
 use PFTools::Structqueries;
 use PFTools::Net;
 use PFTools::Conf;
-use PFTools::Host;
 use PFTools::Update;
 use PFTools::VCS;
 use Data::Dumper;
@@ -63,10 +60,14 @@
 use Digest::MD5;
 use Net::DNS;
 
+our @EXPORT_OK = qw();
+
+
+
 #########################################################################
 # Prototypes : needed by recursive calls
 
-sub __Do_updateloop ($$$$@);
+sub __Do_updateloop ($$$$$);
 
 #########################################################################
 # Functions
@@ -796,11 +797,11 @@
 	return $interfaces;
 }
 
-sub __Do_updateloop ($$$$@) {
-    my ( $host_config, $options, $hash_subst, $global_config, @sortedkeys ) = @_;
+sub __Do_updateloop ($$$$$) {
+    my ( $host_config, $options, $hash_subst, $global_config, $sortedkeys ) = @_;
     my $errorcount = 0;
 
-    foreach my $section (@sortedkeys) {
+    foreach my $section (@{$sortedkeys}) {
 		if (
 			! defined( $host_config->{$section}->{'doing'} )
 			&& ! defined( $host_config->{$section}->{'done'} )
@@ -808,10 +809,8 @@
 			$host_config->{$section}->{'doing'} = 1;
 # 			Get_depends_for_action ( $host_config->{$section}->{'action'}, $host_config->{$section}, $section, $options );
 			if ( defined( $host_config->{$section}->{'depends'} ) ) {
-				my @dependsraw;
-				my @depends;
-				my $d;
-				@dependsraw = split( /[ ,]+/, $host_config->{$section}->{'depends'} );
+				my $depends;
+				my @dependsraw = split( /\s+/, $host_config->{$section}->{'depends'} );
 				foreach my $depend (@dependsraw) {
 					if ( defined($depend) && $depend ne "" && defined( $host_config->{$depend} ) ) {
 						if ( $depend eq $section ) {
@@ -820,17 +819,21 @@
 							FlushLog();
 							next;
 						}
-						push @depends, $depend;
+						push @{$depends}, $depend;
 						if ( $host_config->{$depend}->{'action'} eq 'addmount' ) {
 							Warn( $CODE->{'OPEN'},
 								"[".$section."] depends on addmount [".$depend."], it may not work during install!" );
 							FlushLog();
 						}
 					}
-				}
-				if ( $#depends >= 0 ) {
-					Log ( "<".$section."> ".join( ' ', @depends ) );
-					$errorcount += __Do_updateloop( $host_config, $options, $hash_subst, $global_config, @depends );
+					else {
+						Abort ( $CODE->{'UNDEF_KEY'},
+							"[".$section."] depends on [".$depend."] which is not defined" );
+					}
+				}
+				if ( scalar @{$depends} ) {
+					Log ( "<".$section."> ".join( ' ', @{$depends} ) );
+					$errorcount += __Do_updateloop( $host_config, $options, $hash_subst, $global_config, $depends );
 				}
 			}
 			Log( "[".$section."]" );
@@ -875,10 +878,11 @@
 			"Unable to update configuration : update feature is deactivated in pf-tools configuration file" );
 	}
 
-	my @sortedkeys = sort { Trie_dependances( $host_config, $a, $b ) } @{$host_config->{'__sections_order'}};
+	my $sortedkeys;
+	@{$sortedkeys} = sort { Trie_dependances( $host_config, $a, $b ) } @{$host_config->{'__sections_order'}};
 
 	$| = 1;
-	$errorcount = __Do_updateloop ( $host_config, $options, $hash_subst, $global_config, @sortedkeys );
+	$errorcount = __Do_updateloop ( $host_config, $options, $hash_subst, $global_config, $sortedkeys );
 
 	Log( $errorcount . " error(s) detected." );
 	FlushLog();

Modified: branches/next-gen/lib/PFTools/VCS.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/VCS.pm?rev=851&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/VCS.pm (original)
+++ branches/next-gen/lib/PFTools/VCS.pm Fri Aug 27 08:31:29 2010
@@ -54,9 +54,9 @@
 	}
 
 	my $ret;
- 	my $umask = umask ( $pf_config->{'vcs'}->{'umask'} );
+	my $umask = umask ( $pf_config->{'vcs'}->{'umask'} );
 
-    $ENV{'CVS_RSH'} = $pf_config->{'vcs'}->{'rsh'} if ( $pf_config->{'vcs'}->{'method'} eq 'rsh' );
+	$ENV{'CVS_RSH'} = $pf_config->{'vcs'}->{'rsh'} if ( $pf_config->{'vcs'}->{'method'} eq 'rsh' );
 
 	unless ( $cvs_cmd ne "" ) {
 		if ( $hostname =~ /^$pf_config->{'regex'}->{'deploy_hosts'}/ ) {
@@ -72,22 +72,22 @@
 		$cvs_cmd .= ' -r '.$options->{'branch'} if ( $options->{'branch'} ne "" );
 		$cvs_cmd .= $pf_config->{'vcs'}->{'module'};
 	}
-    print $cvs_cmd."\n" if ( $options->{'debug'} || $options->{'verbose'} );
+	print $cvs_cmd."\n" if ( $options->{'debug'} || $options->{'verbose'} );
 
 	my $co_dir = $pf_config->{'path'}->{'checkout_dir'};
 	if ( ! -d  $co_dir ) {
 		system ( "/bin/mkdir -p '".$co_dir. "' 2>/dev/null" );
 	}
     
-    $ret = deferredlogsystem ( "cd '".$co_dir."';".$cvs_cmd );
-    if ($ret) {
+	$ret = deferredlogsystem ( "cd '".$co_dir."';".$cvs_cmd );
+	if ($ret) {
 		FlushLog();
-    }
-    else {
+	}
+	else {
 		DelLog();
-    }
-    umask($umask);
-    return $ret;
+	}
+	umask($umask);
+	return $ret;
 }
 
 sub VCS_update ($$$) {




More information about the pf-tools-commits mailing list