pf-tools/pf-tools: 6 new changesets

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Thu Dec 23 19:10:18 UTC 2010


details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/5cdc8786e505
changeset: 1128:5cdc8786e505
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Tue Dec 21 19:36:06 2010 +0100
description:
__build_interfaces(): use check_*()

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/c4191d77f91a
changeset: 1129:c4191d77f91a
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Wed Dec 22 07:54:57 2010 +0100
description:
__build_resolv_conf(): use check_*()

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/b858eda5b8ba
changeset: 1130:b858eda5b8ba
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Wed Dec 22 08:06:40 2010 +0100
description:
__build_resolv_conf(): use a template

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/0fe6d139747d
changeset: 1131:0fe6d139747d
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Wed Dec 22 08:07:15 2010 +0100
description:
Unneeded comment

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/31e561e85dd8
changeset: 1132:31e561e85dd8
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Wed Dec 22 16:39:12 2010 +0100
description:
mk_sitezone: use the template

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/d1af4c8d4e57
changeset: 1133:d1af4c8d4e57
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Wed Dec 22 16:45:36 2010 +0100
description:
mk_resolvconf: use the template

diffstat:

4 files changed, 32 insertions(+), 4 deletions(-)
lib/PFTools/Utils.pm      |    6 +++---
t/20.files.t              |    1 -
templates/resolv.conf.tpl |    4 ++++
templates/zone.tpl        |   25 +++++++++++++++++++++++++

diffs (770 lines):

diff -r 918d6650a6d2 -r d1af4c8d4e57 lib/PFTools/Utils.pm
--- a/lib/PFTools/Utils.pm	Tue Dec 21 16:58:16 2010 +0100
+++ b/lib/PFTools/Utils.pm	Wed Dec 22 16:45:36 2010 +0100
@@ -1146,36 +1146,34 @@
     return [$content];
 }
 
-=head2 __build_interfaces($arguments_ref)
+=head2 __build_interfaces($args_ref)
 
 Builds the content for the I<interfaces> configuration file for I<hostname> at
 I<site_name>. I<global_config> is a reference to the global configuration
 hash. I<pf_config> is a referenfe to the pf-tools configuration hash. This
-function takes named arguments in I<%{$arguments_ref}> and returns a reference
+function takes named arguments in I<%{$args_ref}> and returns a reference
 to an array of lines.
 
 =cut
 
 # FIXME convert to a template?
 sub __build_interfaces {
-    my ($arguments_ref) = @_;
+    my ($args_ref) = @_;
+
+    check_mandatory_args_type(
+        $args_ref, q{},
+        qw( hostname site_name )
+    );
+    check_true_args(
+        $args_ref,
+        qw( hostname site_name )
+    );
+
+    check_mandatory_args_type( $args_ref, q{HASH},
+        qw( global_config pf_config ) );
 
     my ( $hostname, $global_config, $pf_config, $site_name )
-        = @{$arguments_ref}{qw( hostname global_config pf_config site_name )};
-
-    if ( not $hostname ) {
-        croak q{ERROR: Invalid empty $hostname};
-    }
-    if ( ref $hostname ) {
-        croak q{ERROR: Invalid non-scalar $hostname};
-    }
-
-    if ( not $global_config ) {
-        croak q{ERROR: Invalid empty $global_config};
-    }
-    if ( ref $global_config ne 'HASH' ) {
-        croak q{ERROR: Invalid non-hashref $global_config};
-    }
+        = @{$args_ref}{qw( hostname global_config pf_config site_name )};
 
     # This is not a complete check but it will catch obvious errors,
     # like $global_config referencing a non-config hash
@@ -1183,24 +1181,10 @@
         croak q{ERROR: Invalid $global_config hashref: no 'ZONE' key found};
     }
 
-    if ( not $pf_config ) {
-        croak q{ERROR: Invalid empty $pf_config};
-    }
-    if ( ref $pf_config ne 'HASH' ) {
-        croak q{ERROR: Invalid non-hashref $pf_config};
-    }
-
     # This is not a complete check but it will catch obvious errors,
     # like $pf_config referencing a non-config hash
     if ( not exists $pf_config->{'vcs'} ) {
         croak q{ERROR: Invalid $pf_config hashref: no 'vcs' key found};
-    }
-
-    if ( not $site_name ) {
-        croak q{ERROR: Invalid empty $site_name};
-    }
-    if ( ref $site_name ) {
-        croak q{ERROR: Invalid non-scalar $site_name};
     }
 
     my $host_ref = get_host_config( $hostname, $global_config, $site_name );
@@ -1354,47 +1338,34 @@
     return \@iface_lines;
 }
 
-=head2 __build_resolv_conf($arguments_ref)
+=head2 __build_resolv_conf($args_ref)
 
 Writes the I<resolv.conf> configuration for I<hostname> at I<site_name>.
 I<global_config> is a reference to the global configuration hash.  This
-function takes named arguments in I<%{$arguments_ref}> and returns a reference
+function takes named arguments in I<%{$args_ref}> and returns a reference
 to an array of lines.
 
 =cut
 
-# FIXME convert to template?
 sub __build_resolv_conf {
-    my ($arguments_ref) = @_;
+    my ($args_ref) = @_;
 
-    my ( $hostname, $global_config, $site_name )
-        = @{$arguments_ref}{qw( hostname global_config site_name )};
+    check_mandatory_args_type(
+        $args_ref, q{},
+        qw( hostname site_name template_filename )
+    );
+    check_true_args( $args_ref, qw( hostname site_name template_filename ) );
 
-    if ( not $hostname ) {
-        croak q{ERROR: Invalid empty $hostname};
-    }
-    if ( ref $hostname ) {
-        croak q{ERROR: Invalid non-scalar $hostname};
-    }
+    check_mandatory_args_type( $args_ref, q{HASH}, qw( global_config ) );
 
-    if ( not $global_config ) {
-        croak q{ERROR: Invalid empty $global_config};
-    }
-    if ( ref $global_config ne 'HASH' ) {
-        croak q{ERROR: Invalid non-hashref $global_config};
-    }
+    my ( $hostname, $global_config, $site_name, $template_filename )
+        = @{$args_ref}
+        {qw( hostname global_config site_name template_filename )};
 
     # This is not a complete check but it will catch obvious errors,
     # like $global_config referencing a non-config hash
     if ( not exists $global_config->{'ZONE'} ) {
         croak q{ERROR: Invalid $global_config hashref: no 'ZONE' key found};
-    }
-
-    if ( not $site_name ) {
-        croak q{ERROR: Invalid empty $site_name};
-    }
-    if ( ref $site_name ) {
-        croak q{ERROR: Invalid non-scalar $site_name};
     }
 
     my $host_props = get_host_config( $hostname, $global_config, $site_name );
@@ -1403,30 +1374,25 @@
 
     my @dns = split qr{ \s* [,] \s* }xms, $host_props->{'dns'}->{'resolver'};
 
-    my @lines = (
-        q{#},
-        q{# This file was auto-generated by mk_resolvconf -- DO NOT EDIT!},
-        q{#},
-        q{},
-        qq{search $domain},
-        q{},
-    );
-
+    my @nameservers = ();
     foreach my $ip_type (qw( ipv4 ipv6 )) {
         foreach my $dns (@dns) {
-            my $resolved = Resolv(
-                q{cnf}, $ip_type, $dns, $global_config,
-                $site_name
-            );
-            foreach my $ip ( @{$resolved} ) {
-                push @lines, qq{nameserver $ip};
-            }
+            my $resolved = Resolv( q{cnf}, $ip_type, $dns, $global_config,
+                $site_name );
+            push @nameservers, @{$resolved};
         }
     }
 
-    push @lines, q{};
+    my $vars_ref = {
+        domain    => $domain,
+        nameservers => \@nameservers,
+    };
+    my $lines_ref = [
+        split qr{ \n }xms,
+        __read_and_process_template( $template_filename, $vars_ref ), -1
+    ];
 
-    return \@lines;
+    return $lines_ref;
 }
 
 =head2 __build_zone($args_ref)
@@ -1491,10 +1457,13 @@
     # Merge private and public parts for a given zone_name
     my $merged_zone_ref = merge( $zone_part, $zone_ref->{'ALL_SITES'} );
 
+    # Networks
     my @networks      = ();
+
     my @network_order = @{ $zone_part->{'__network_order'} };
     push @network_order,
         @{ $zone_ref->{'ALL_SITES'}->{'__network_order'} };
+
     foreach my $network (@network_order) {
         my $network_ref = {
             name    => $network,
@@ -1516,14 +1485,15 @@
         push @networks, $network_ref;
     }
 
-    ### Servers
+    # Servers
+    my @servers = ();
+
     my @hostclass_order
         = uniq(
         @{ $zone_ref->{'BY_SITE'}->{$site_name}->{'__hostclass_order'} },
         @{ $zone_ref->{'ALL_SITES'}->{'__hostclass_order'} },
         );
 
-    my @servers = ();
     foreach my $server (@hostclass_order) {
         my $server_ref = {
             name    => $server,
diff -r 918d6650a6d2 -r d1af4c8d4e57 sbin/mk_resolvconf
--- a/sbin/mk_resolvconf	Tue Dec 21 16:58:16 2010 +0100
+++ b/sbin/mk_resolvconf	Wed Dec 22 16:45:36 2010 +0100
@@ -28,7 +28,7 @@
 use Sys::Hostname;
 
 use PFTools::Structqueries;
-use PFTools::Utils qw( Init_Tools make_resolv_conf_file );
+use PFTools::Utils qw( Init_TOOLS make_resolv_conf_file );
 
 #################################
 # VARS
@@ -40,6 +40,7 @@
     'config|c=s',
     'store=s',
     'output|o=s',
+    'template|t=s',
 );
 
 my $options = {
@@ -47,9 +48,6 @@
     'help'      => 0,
     'output'    => '/etc/resolv.conf',
 };
-
-my $PF_CONFIG         = {};
-my $GLOBAL_STRUCT     = {};
 
 my $program = basename $PROGRAM_NAME;
 
@@ -61,6 +59,7 @@
 
 Usage:	$program [options]
 	--help		: print help and exit
+    -t --template : template file
 	-h --host	: hostname for which we want to build interfaces file
 	-s --site	: site on which hostname is defined (optional)
 	-c --config	: file where pf-tools configuration is stored e.g. /etc/pf-tools.conf (optional)
@@ -81,23 +80,24 @@
     exit 0;
 }
 
-( $PF_CONFIG, $GLOBAL_STRUCT ) = Init_TOOLS(
+my ( $pf_config, $global_config ) = Init_TOOLS(
     $options->{'host'},
     $options->{'config'},
     $options->{'store'}
 );
 
-unless( $options->{'site'} ) {
-    $options->{'site'} = $PF_CONFIG->{'location'}->{'site'}
-        || get_uniq_site_from_hostname( $options->{'host'}, $GLOBAL_STRUCT );
-}
+# NOTE: get_uniq_site_from_hostname() will croak if the site_name
+# cannot be determined
+$options->{'site'} ||= $pf_config->{'location'}->{'site'}
+    || get_uniq_site_from_hostname( $options->{'host'}, $global_config );
 
 make_resolv_conf_file(
     {
-        hostname      => $options->{'host'},
-        global_config => $GLOBAL_STRUCT,
-        site_name     => $options->{'site'},
-        filename      => $options->{'output'},
+        hostname          => $options->{'host'},
+        global_config     => $global_config,
+        site_name         => $options->{'site'},
+        filename          => $options->{'output'},
+        template_filename => $options->{'template'},
     }
 );
 
diff -r 918d6650a6d2 -r d1af4c8d4e57 sbin/mk_sitezone
--- a/sbin/mk_sitezone	Tue Dec 21 16:58:16 2010 +0100
+++ b/sbin/mk_sitezone	Wed Dec 22 16:45:36 2010 +0100
@@ -26,6 +26,7 @@
 use Getopt::Long qw( :config ignore_case_always bundling );
 use IO::File;
 
+use PFTools::Structqueries;
 use PFTools::Utils qw( Init_TOOLS make_zone_file );
 
 #################################
@@ -37,15 +38,13 @@
     'config|c=s',
     'store=s',
     'output|o=s',
+    'template|t=s',
 );
 
 my $options = {
     'help'      => 0,
     'output'    => '-',
 };
-
-my $PF_CONFIG         = {};
-my $GLOBAL_STRUCT     = {};
 
 my $program = basename $PROGRAM_NAME;
 
@@ -57,6 +56,7 @@
 
 Usage:	$program [options]
 	--help		: print help and exit
+    -t --template : template file
 	-s --site	: site on which hostname is defined
 	--store		: file where global structure datas are in storable format (optional)
 	-c --config	: pf-tools config file (optional)
@@ -76,29 +76,27 @@
     exit 0;
 }
 
-( $PF_CONFIG, $GLOBAL_STRUCT ) = Init_TOOLS(
-    "",
+my ( $pf_config, $global_config ) = Init_TOOLS(
+    q{},
     $options->{'config'},
     $options->{'store'}
 );
 
+$options->{'site'} ||= $pf_config->{'location'}->{'site'};
 unless( $options->{'site'} ) {
-    $options->{'site'} = $PF_CONFIG->{'location'}->{'site'}
-        or die "A site MUST BE defined for building DNS zone forward";
+    die q{ERROR: No site specified and no default site in configuration};
 }
 
-unless ( $GLOBAL_STRUCT->{'DHCP'}->{'BY_SITE'}->{$options->{'site'}} ) {
-    die "Site $options->{'site'} is not defined into global configuration";
-}
+# NOTE: get_site_config() will croak if the site is unknown
+my $site_ref = get_site_config( $options->{'site'}, $global_config );
 
-my $zone_name
-    = $GLOBAL_STRUCT->{'SITE'}->{'BY_NAME'}->{ $options->{'site'} }->{'zone'};
 make_zone_file(
     {
-        zone_name     => $zone_name,
-        site_name     => $options->{'site'},
-        filename      => $options->{'output'},
-        global_config => $GLOBAL_STRUCT,
+        zone_name         => $site_ref->{'zone'},
+        site_name         => $options->{'site'},
+        template_filename => $options->{'template'},
+        filename          => $options->{'output'},
+        global_config     => $global_config,
     }
 );
 
diff -r 918d6650a6d2 -r d1af4c8d4e57 t/20.files.t
--- a/t/20.files.t	Tue Dec 21 16:58:16 2010 +0100
+++ b/t/20.files.t	Wed Dec 22 16:45:36 2010 +0100
@@ -207,9 +207,6 @@
     q{},
 ];
 
-use IO::File;
-my $toto = IO::File->new(q{test.zone.expected}, q{>});
-PFTools::Utils::__write_array_to_filehandle( $toto, q{test.zone.expected}, $expected_result, qq{\n} );
 is_deeply $result, $expected_result
     => q{Returns the expected result for zone 'private'}
     or note explain $result;
@@ -253,99 +250,76 @@
 qr{ \A ERROR: [ ] Invalid [ ] [\$] arguments_ref }xms
     => q{Dies if no args};
 
-throws_ok { make_resolv_conf_file( {} ); }
+$template_filename = q{templates/resolv.conf.tpl};
+$args_ref          = {
+    hostname          => q{cbv4-rdeploy01},
+    global_config     => $global_config,
+    site_name         => q{cbv4},
+    template_filename => $template_filename,
+};
+throws_ok { make_resolv_conf_file($args_ref); }
 qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] filename }xms
     => q{Dies if empty $filename};
 
-throws_ok { make_resolv_conf_file( { filename => {} } ); }
+$args_ref->{'filename'} = {};
+throws_ok { make_resolv_conf_file($args_ref); }
 qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] [\$] filename }xms
     => q{Dies if non-scalar $filename};
 
-throws_ok { make_resolv_conf_file( { filename => q{filename} } ); }
-qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] hostname }xms
-    => q{Dies if empty $hostname};
+$args_ref->{'filename'} = q{filename};
+delete $args_ref->{'hostname'};
+throws_ok { make_resolv_conf_file($args_ref); }
+qr{ \A ERROR: [ ] Mandatory [ ] argument [ ] hostname [ ] not [ ] found }xms
+    => q{Dies if no $hostname};
 
-throws_ok {
-    make_resolv_conf_file(
-        {
-            filename => q{filename},
-            hostname => {},
-        }
-    );
-}
-qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] [\$] hostname }xms
+$args_ref->{'hostname'} = {};
+throws_ok { make_resolv_conf_file($args_ref); }
+qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] hostname }xms
     => q{Dies if non-scalar $hostname};
 
-throws_ok {
-    make_resolv_conf_file(
-        {
-            filename => q{filename},
-            hostname => q{name},
-        }
-    );
-}
-qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] global_config}xms
-    => q{Dies if empty $global_config};
+$args_ref->{'hostname'} = q{name};
+throws_ok { make_resolv_conf_file($args_ref); }
+qr{ \A ERROR: [ ] Unknown [ ] hostname [ ] }xms
+    => q{Dies if unknown hostname};
 
-throws_ok {
-    make_resolv_conf_file(
-        {
-            filename      => q{filename},
-            hostname      => q{name},
-            global_config => q{global_config},
-        }
-    );
-}
-qr{ \A ERROR: [ ] Invalid [ ] non-hashref [ ] [\$] global_config [ ]}xms
+$args_ref->{'hostname'} = q{cbv4-rdeploy01};
+delete $args_ref->{'global_config'};
+throws_ok { make_resolv_conf_file($args_ref); }
+qr{ \A ERROR: [ ] Mandatory [ ] argument [ ] global_config [ ] not [ ] found }xms
+    => q{Dies if no $global_config};
+
+$args_ref->{'global_config'} = q{global_config};
+throws_ok { make_resolv_conf_file($args_ref); }
+qr{ \A ERROR: [ ] Invalid [ ] non-hash [ ] reference [ ] global_config [ ] }xms
     => q{Dies if non-hashref $global_config};
 
-throws_ok {
-    make_resolv_conf_file(
-        {
-            filename      => q{filename},
-            hostname      => q{name},
-            global_config => {},
-        }
-    );
-}
+$args_ref->{'global_config'} = {};
+throws_ok { make_resolv_conf_file($args_ref); }
 qr{ \A ERROR: [ ] Invalid [ ] [\$] global_config [ ] hashref:
     [ ] no [ ] 'ZONE' [ ] key [ ] found }xms
     => q{Dies if non-config hashref $global_config};
 
-throws_ok {
-    make_resolv_conf_file(
-        {
-            filename      => q{filename},
-            hostname      => q{hostname},
-            global_config => $global_config,
-        }
-    );
-}
-qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] site_name }xms
+$args_ref->{'global_config'} = $global_config;
+$args_ref->{'site_name'} = q{};
+throws_ok { make_resolv_conf_file($args_ref); }
+qr{ \A ERROR: [ ] Invalid [ ] empty [ ] site_name }xms
     => q{Dies if empty $site_name};
 
-throws_ok {
-    make_resolv_conf_file(
-        {
-            filename      => q{filename},
-            hostname      => q{name},
-            global_config => $global_config,
-            site_name     => {},
-        }
-    );
-}
-qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] [\$] site_name }xms
+$args_ref->{'site_name'} = {};
+throws_ok { make_resolv_conf_file($args_ref); }
+qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] site_name }xms
     => q{Dies if non-scalar $site_name};
 
+$args_ref->{'site_name'} = q{cbv4};
+delete $args_ref->{'template_filename'};
+throws_ok { make_resolv_conf_file($args_ref); }
+qr{ \A ERROR: [ ] Mandatory [ ] argument [ ] template_filename [ ] not [ ] found }xms
+    => q{Dies if no template_filename};
+
 $test_output_file = q{test.resolv.conf};
-$result           = make_resolv_conf_file(
-    {
-        hostname      => q{cbv4-rdeploy01},
-        global_config => $global_config,
-        site_name     => q{cbv4},
-        filename      => $test_output_file,
-    }
-);
+$args_ref->{'filename'} = $test_output_file;
+$args_ref->{'template_filename'} = $template_filename;
+$result = make_resolv_conf_file($args_ref);
 ok $result => q{Returns true on success};
 
 $result = PFTools::Utils::__read_file_in_array( $test_output_file, 1 );
@@ -373,112 +347,84 @@
 note('Testing PFTools::Utils::__build_interfaces');
 can_ok( 'PFTools::Utils', qw( __build_interfaces ) );
 
-throws_ok { PFTools::Utils::__build_interfaces(); }
-qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] hostname }xms
+$args_ref = {
+    site_name => q{cbv4-pfds},
+    global_config => $global_config,
+    pf_config => $pf_config,
+};
+
+throws_ok { PFTools::Utils::__build_interfaces($args_ref); }
+qr{ \A ERROR: [ ] Mandatory [ ] argument [ ] hostname [ ] not [ ] found }xms
+    => q{Dies if no $hostname};
+
+$args_ref->{'hostname'} = {};
+throws_ok { PFTools::Utils::__build_interfaces($args_ref); }
+qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] hostname }xms
+    => q{Dies if non-scalar $hostname};
+
+$args_ref->{'hostname'} = q{};
+throws_ok { PFTools::Utils::__build_interfaces($args_ref); }
+qr{ \A ERROR: [ ] Invalid [ ] empty [ ] hostname }xms
     => q{Dies if empty $hostname};
 
-throws_ok { PFTools::Utils::__build_interfaces( { hostname => {} } ); }
-qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] [\$] hostname }xms
-    => q{Dies if non-scalar $hostname};
+$args_ref->{'hostname'} = q{cbv4-spawn01};
+delete $args_ref->{'global_config'};
+throws_ok { PFTools::Utils::__build_interfaces($args_ref); }
+qr{ \A ERROR: [ ] Mandatory [ ] argument [ ] global_config [ ] not [ ] found }xms
+    => q{Dies if no $global_config};
 
-throws_ok {
-    PFTools::Utils::__build_interfaces( { hostname => q{hostname} } );
-}
-qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] global_config }xms
-    => q{Dies if empty $global_config};
-
-throws_ok {
-    PFTools::Utils::__build_interfaces(
-        {
-            hostname      => q{hostname},
-            global_config => q{global_config},
-        }
-    );
-}
-qr{ \A ERROR: [ ] Invalid [ ] non-hashref [ ] [\$] global_config }xms
+$args_ref->{'global_config'} = q{global_config};
+throws_ok { PFTools::Utils::__build_interfaces($args_ref); }
+qr{ \A ERROR: [ ] Invalid [ ] non-hash [ ] reference [ ] global_config }xms
     => q{Dies if non-hashref $global_config};
 
-throws_ok {
-    PFTools::Utils::__build_interfaces(
-        {
-            hostname      => q{name},
-            global_config => {},
-        }
-    );
-}
+$args_ref->{'global_config'} = {};
+throws_ok { PFTools::Utils::__build_interfaces($args_ref); }
 qr{ \A ERROR: [ ] Invalid [ ] [\$] global_config [ ] hashref:
     [ ] no [ ] 'ZONE' [ ] key [ ] found }xms
     => q{Dies if non-config hashref $global_config};
 
-throws_ok {
-    PFTools::Utils::__build_interfaces(
-        {
-            hostname      => q{hostname},
-            global_config => $global_config,
-        }
-    );
-}
-qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] pf_config }xms
-    => q{Dies if empty $pf_config};
+$args_ref->{'global_config'} = $global_config;
+delete $args_ref->{'pf_config'};
+throws_ok { PFTools::Utils::__build_interfaces($args_ref); }
+qr{ \A ERROR: [ ] Mandatory [ ] argument [ ] pf_config [ ] not [ ] found }xms
+    => q{Dies if no $pf_config};
 
-throws_ok {
-    PFTools::Utils::__build_interfaces(
-        {
-            hostname      => q{hostname},
-            global_config => $global_config,
-            pf_config     => q{pf_config},
-        }
-    );
-}
-qr{ \A ERROR: [ ] Invalid [ ] non-hashref [ ] [\$] pf_config }xms
+$args_ref->{'pf_config'} = q{pf_config};
+throws_ok { PFTools::Utils::__build_interfaces($args_ref); }
+qr{ \A ERROR: [ ] Invalid [ ] non-hash [ ] reference [ ] pf_config }xms
     => q{Dies if non-hashref $pf_config};
 
-throws_ok {
-    PFTools::Utils::__build_interfaces(
-        {
-            hostname      => q{hostname},
-            global_config => $global_config,
-            pf_config     => {},
-        }
-    );
-}
-qr{ \A ERROR: [ ] Invalid [ ] [\$] pf_config [ ] hashref:
-    [ ] no [ ] 'vcs' [ ] key [ ] found }xms
+$args_ref->{'pf_config'} = {};
+throws_ok { PFTools::Utils::__build_interfaces($args_ref); }
+qr{ \A ERROR: [ ] Invalid [ ] [\$] pf_config [ ] hashref: [ ] no [ ] 'vcs' [ ] key [ ] found }xms
     => q{Dies if non-config hashref $pf_config};
 
-throws_ok {
-    PFTools::Utils::__build_interfaces(
-        {
-            hostname      => q{hostname},
-            global_config => $global_config,
-            pf_config     => $pf_config,
-        }
-    );
-}
-qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] site_name }xms
-    => q{Dies if empty $site_name};
+$args_ref->{'pf_config'} = $pf_config;
+delete $args_ref->{'site_name'};
+throws_ok { PFTools::Utils::__build_interfaces($args_ref); }
+qr{ \A ERROR: [ ] Mandatory [ ] argument [ ] site_name [ ] not [ ] found }xms
+    => q{Dies if no $site_name};
 
-throws_ok {
-    PFTools::Utils::__build_interfaces(
-        {
-            hostname      => q{hostname},
-            global_config => $global_config,
-            pf_config     => $pf_config,
-            site_name     => {},
-        }
-    );
-}
-qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] [\$] site_name }xms
+$args_ref->{'site_name'} = {};
+throws_ok { PFTools::Utils::__build_interfaces($args_ref); }
+qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] site_name }xms
     => q{Dies if non-scalar $site_name};
 
-$result = PFTools::Utils::__build_interfaces(
-    {
-        hostname      => q{cbv4-spawn01},
-        global_config => $global_config,
-        pf_config     => $pf_config,
-        site_name     => q{cbv4-pfds},
-    }
-);
+$args_ref->{'hostname'} = q{foo};
+$args_ref->{'site_name'} = q{cbv4-pfds};
+throws_ok { PFTools::Utils::__build_interfaces($args_ref); }
+qr{ \A ERROR: [ ] Unknown [ ] hostname [ ] foo [ ] on [ ] site [ ] cbv4-pfds }xms
+    => q{Dies if unknown $site_name};
+
+$args_ref->{'hostname'} = q{cbv4-spawn01};
+$args_ref->{'site_name'} = q{foo};
+throws_ok { PFTools::Utils::__build_interfaces($args_ref); }
+qr{ \A ERROR: [ ] Unknown [ ] hostname [ ] cbv4-spawn01 [ ] on [ ] site [ ] foo }xms
+    => q{Dies if unknown $site_name};
+
+$args_ref->{'site_name'} = q{cbv4-pfds};
+$result = PFTools::Utils::__build_interfaces($args_ref);
 $expected_result = [
     qq{#},
     qq{# This file was auto-generated by mk_interfaces -- DO NOT EDIT!},
diff -r 918d6650a6d2 -r d1af4c8d4e57 templates/resolv.conf.tpl
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/resolv.conf.tpl	Wed Dec 22 16:45:36 2010 +0100
@@ -0,0 +1,9 @@
+#
+# This file was auto-generated by mk_resolvconf -- DO NOT EDIT!
+#
+
+search [% domain %]
+
+[% FOREACH ns IN nameservers -%]
+nameserver [% ns %]
+[% END -%]
diff -r 918d6650a6d2 -r d1af4c8d4e57 templates/zone.tpl
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/zone.tpl	Wed Dec 22 16:45:36 2010 +0100
@@ -0,0 +1,51 @@
+;;
+;; BIND configuration file for zone: [% zone_name %]
+;; Site: [% site_name %]
+;;
+;; [% soa.comment %]
+;;============================================================================
+
+$TTL	[% soa.ttl %]
+@	IN SOA	[% soa.soa %] [% soa.mail %] (
+		[% soa.serial %]	; Serial
+		[% soa.refresh %]
+		[% soa.retry %]
+		[% soa.expire %]
+		[% soa.negttl %]
+	)
+
+[% FOREACH ns IN soa.ns_list -%]
+	IN NS	[% ns %]
+[% END -%]
+
+[% FOREACH mx IN soa.mx_list -%]
+	IN MX	[% mx %]
+[% END -%]
+
+
+;;
+;; Networks
+;;============================================================================
+
+[% FOREACH network IN networks -%]
+; [% network.name %][% IF network.comment %]: network.comment[% END %]
+;----------------------------------------------------------------------------
+[% FOREACH rr IN network.records -%]
+[% rr.name %]	IN [% rr.value %]
+[% END -%]
+
+[% END -%]
+
+
+;;
+;; Servers
+;;============================================================================
+
+[% FOREACH server IN servers -%]
+; [% server.name %][% IF server.comment %]: server.comment[% END %]
+;----------------------------------------------------------------------------
+[% FOREACH rr IN server.records -%]
+[% rr.name %]	IN [% rr.value %]
+[% END -%]
+
+[% END -%]



More information about the pf-tools-commits mailing list