pf-tools commit: r860 [ccaillet-guest] - in /branches/next-gen/lib/PFTools: Conf.pm Conf/Syntax.pm

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Sun Aug 29 16:26:48 UTC 2010


Author: ccaillet-guest
Date: Sun Aug 29 16:26:39 2010
New Revision: 860

URL: http://svn.debian.org/wsvn/pf-tools/?sc=1&rev=860
Log:
FIX: there are no mandatory keys for hostgroup section in model context

Modified:
    branches/next-gen/lib/PFTools/Conf.pm
    branches/next-gen/lib/PFTools/Conf/Syntax.pm

Modified: branches/next-gen/lib/PFTools/Conf.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Conf.pm?rev=860&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Conf.pm (original)
+++ branches/next-gen/lib/PFTools/Conf.pm Sun Aug 29 16:26:39 2010
@@ -223,6 +223,8 @@
 	}
 	my $vcs_work_dir	= $pf_config->{'path'}->{'checkout_dir'};
 	my $module			= $pf_config->{'vcs'}->{'module'};
+	$source	=~ s!^MODSITE_([^:]+):!$vcs_work_dir/$module/SITE/$1/MODEL!;
+	$source	=~ s!^MOD:!$vcs_work_dir/$module/MODEL!;
 	$source	=~ s!^CONFSITE_([^:]+):!$vcs_work_dir/$module/SITE/$1/CONFIG!;
 	$source	=~ s!^CONF:!$vcs_work_dir/$module/CONFIG!;
 	$source	=~ s!^SITE_([^:]+):!$vcs_work_dir/$module/SITE/$1!;
@@ -246,48 +248,49 @@
 	return undef;
 }
 
+sub __Merge_host_config ($$) {
+	my ( $hash_to_merge, $hash_subst ) = @_;
+	my $merge = {};
+
+	if ( $hash_to_merge->{'hostgroup'}->{'__model'} ) {
+		$merge = $hash_to_merge->{'hostgroup'}->{'__model'};
+	}
+	foreach my $section ( @{$hash_to_merge->{'__sections_order'}} ) {
+		if ( defined $merge->{$section} ) {
+			foreach my $key ( keys %{$hash_to_merge->{$section}} ) {
+				next if ( $section eq 'hostgroup' && $key eq '__model' );
+				# Adding key if not defined into model else overriding it
+				if ( $key =~ /^\@/ ) {
+					push ( @{$merge->{$section}->{$key}}, @{$hash_to_merge->{$section}->{$key}} );
+				}
+				else {
+					$merge->{$section}->{$key} = $hash_to_merge->{$section}->{$key};
+				}
+			}
+		}
+		else {
+			push ( @{$merge->{'__sections_order'}}, $section );
+			$merge->{$section} = $hash_to_merge->{$section};
+		}
+	}
+	return $merge;
+}
+
+# sub __Merge_other_context 
+
 sub __Merge_conf_includes ($$$) {
 	my ( $hash_to_merge, $hash_subst, $context ) = @_;
+	my $host_context = 0;
 	my $global_order = [];
 	my $global_parsed = {};
 
 	if ( $context =~ /^host|model$/ ) {
-		if ( defined $hash_to_merge->{'hostgroup'}->{'__model'} ) {
-			$global_parsed = $hash_to_merge->{'hostgroup'}->{'__model'};
-		}
-		foreach my $section ( @{$hash_to_merge->{'__sections_order'}} ) {
-			if ( defined $global_parsed->{$section} ) {
-				foreach my $key ( keys %{$hash_to_merge->{$section}} ) {
-					# Adding key if not defined into model else overriding it
-					if ( $key =~ /^\@/ ) {
-						push ( @{$global_parsed->{$section}->{$key}}, @{$hash_to_merge->{$section}->{$key}} );
-					}
-					else {
-						$global_parsed->{$section}->{$key} = $hash_to_merge->{$section}->{$key};
-					}
-				}
-			}
-			else {
-				push ( @{$global_parsed->{'__sections_order'}}, $section );
-				$global_parsed->{$section} = $hash_to_merge->{$section};
-			}
-		}
-		undef $global_parsed->{'hostgroup'}->{'__model'};
+		return __Merge_host_config ( $hash_to_merge, $hash_subst );
 	}
 	else {
 		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};
 			}
@@ -316,7 +319,6 @@
 	return $global_parsed;
 }
 
-
 sub Load_conf ($$$$) {
 	my ( $file, $hash_subst, $context, $pf_config ) = @_;
 	my ( $sect_type, $iface_name );
@@ -333,27 +335,24 @@
 		Abort ( $CODE->{'PARSING'}, "Parsing error for file ".$file );
 	}
 
-	# Basic checks
-	foreach my $section ( keys %{$parsed} ) {
-		next if ( $section =~ /^__/ );
-		if ( $context =~ /^host|model$/ ) {
-			$section =~ /^([^:]+)(::.+)?$/;
-			$sect_type = $1;
-			if ( $sect_type eq 'hostgroup' && defined $parsed->{$section}->{'model'} ) {
-				my $model_parsed = Load_conf ( Get_source ( $parsed->{$section}->{'model'}, "", $hash_subst, $pf_config ), $hash_subst, 'model', $pf_config );
-				$parsed->{$section}->{'__model'} = $model_parsed;
-			}
-		}
-		else {
-			my $select = ( $context eq 'config' ) ? 'action' : 'type';
+	if ( $context =~ /^(model|host)$/ ) {
+		if ( defined $parsed->{'hostgroup'}->{'model'} ) {
+			$parsed->{'hostgroup'}->{'__model'} = 
+				Load_conf ( Get_source ( $parsed->{'hostgroup'}->{'model'}, "", $hash_subst, $pf_config ), $hash_subst, 'model', $pf_config );
+		}
+	}
+	else {
+		my $select = ( $context eq 'config' ) ? 'action' : 'type';
+		foreach my $section ( keys %{$parsed} ) {
+			next if ( $section =~ /^__/ );
 			if ( ! defined $parsed->{$section}->{$select} ) {
 				Abort ( $CODE->{'UNDEF_KEY'}, "Key ".$select." on section ".$section." from file ".$file." MUST BE defined" ); 
 			}
 			$sect_type = $parsed->{$section}->{$select};
 			if ( $sect_type eq 'include' ) {
 				# We need to dive into deep ...
-				my $inc_parsed = Load_conf ( Get_source ( $section, "", $hash_subst, $pf_config ), $hash_subst, $context, $pf_config );
-				$parsed->{$section}->{'__content'} = $inc_parsed;
+				$parsed->{$section}->{'__content'} =
+					Load_conf ( Get_source ( $section, "", $hash_subst, $pf_config ), $hash_subst, $context, $pf_config );
 			}
 		}
 	}
@@ -376,14 +375,11 @@
 			}
 			$sect_type = $parsed->{$section}->{$select};
 		}
-		if ( $sect_type ne 'include' ) {
-# 			my ( $code, $msg ) = __Chk_section_struct ( $section, $sect_type, $parsed->{$section}, $context );
-			my ( $code, $msg ) = Chk_section_struct ( $section, $sect_type, $parsed->{$section}, $context );
-			if ( $code > 1 ) {
-				Warn ( $code, "Errors occur during parsing model from file ". $file );
-				Abort ( $code, $msg );
-			} 
-		}
+		my ( $code, $msg ) = Chk_section_struct ( $section, $sect_type, $parsed->{$section}, $context );
+		if ( $code > 1 ) {
+			Warn ( $code, "Errors occur during parsing model from file ". $file );
+			Abort ( $code, $msg );
+		} 
 	}
 	return $parsed;
 }

Modified: branches/next-gen/lib/PFTools/Conf/Syntax.pm
URL: http://svn.debian.org/wsvn/pf-tools/branches/next-gen/lib/PFTools/Conf/Syntax.pm?rev=860&op=diff
==============================================================================
--- branches/next-gen/lib/PFTools/Conf/Syntax.pm (original)
+++ branches/next-gen/lib/PFTools/Conf/Syntax.pm Sun Aug 29 16:26:39 2010
@@ -327,6 +327,7 @@
 			next if ( $iface_type eq 'eth' && $key eq 'slaves' );
 			next if ( $key =~ /^ipv/ && $context eq 'model' );
 		}
+		last if ( $sect_type eq 'hostgroup' && $context eq 'model' );
 		return ( $CODE->{'UNDEF_KEY'}, 
 			"Mandatory key ".$key." MUST BE defined on section "
 			.$sect_name." in context ".$context ) if ( ! defined ( $sect_tmp->{$key} ) );




More information about the pf-tools-commits mailing list