pf-tools/pf-tools: 4 new changesets
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Tue Dec 21 16:00:42 UTC 2010
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/902e80cc8232
changeset: 1124:902e80cc8232
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Sat Dec 18 20:15:25 2010 +0100
description:
Add a tpl extension to the sources.list template
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/8c44f2ded5e2
changeset: 1125:8c44f2ded5e2
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Sat Dec 18 20:26:16 2010 +0100
description:
Move the dhcpd.conf template to the templates dir
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/927c1d12d713
changeset: 1126:927c1d12d713
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Tue Dec 21 07:49:47 2010 +0100
description:
__build_zone(): use the new check_* functions to check arguments
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/918d6650a6d2
changeset: 1127:918d6650a6d2
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Tue Dec 21 16:58:16 2010 +0100
description:
make_zone_file(), __build_zone(): use a template
diffstat:
7 files changed, 54 insertions(+), 125 deletions(-)
t/13.conf.cfg1/config-export/COMMON/private-network | 7
t/13.conf.t | 6
t/20.files.dhcpd.conf.tpl | 8 -
t/20.files.t | 138 ++++---------------
templates/dhcpd.conf.tpl | 8 +
templates/sources.list | 6
templates/sources.list.tpl | 6
diffs (982 lines):
diff -r ecbac7c44d67 -r 918d6650a6d2 lib/PFTools/Utils.pm
--- a/lib/PFTools/Utils.pm Sun Dec 12 19:40:42 2010 +0100
+++ b/lib/PFTools/Utils.pm Tue Dec 21 16:58:16 2010 +0100
@@ -26,6 +26,7 @@
use base qw( Exporter );
use Carp;
+use Clone qw( clone );
use Digest::MD5;
use English qw( -no_match_vars ); # Avoids regex performance penalty
use File::Basename;
@@ -1155,6 +1156,7 @@
=cut
+# FIXME convert to a template?
sub __build_interfaces {
my ($arguments_ref) = @_;
@@ -1361,6 +1363,7 @@
=cut
+# FIXME convert to template?
sub __build_resolv_conf {
my ($arguments_ref) = @_;
@@ -1426,41 +1429,41 @@
return \@lines;
}
-=head2 __build_zone($arguments_ref)
+=head2 __build_zone($args_ref)
-This function creates the zone file content for the I<zone_name> zone on site
-I<site_name>. I<global_config> references the global configuration hash. It
-takes named arguments in I<%{$arguments_ref}> and returns a reference to the
-array of lines.
+This function creates the zone file content for a given site. It returns a
+reference to the list of generated lines. The named arguments are:
+
+=over
+
+=item I<template_filename> the name of file containing the template to use
+
+=item I<zone_name> the zone name
+
+=item I<site_name> the site name
+
+=item I<global_config> a reference to the global configuration hash
+=back
=cut
sub __build_zone {
- my ($arguments_ref) = @_;
+ my ($args_ref) = @_;
- my ( $zone_name, $site_name, $global_config )
- = @{$arguments_ref}{qw( zone_name site_name global_config )};
+ check_mandatory_args_type(
+ $args_ref, q{},
+ qw( site_name zone_name template_filename )
+ );
+ check_true_args(
+ $args_ref,
+ qw( site_name zone_name template_filename )
+ );
- if ( not $zone_name ) {
- croak q{ERROR: Invalid empty $zone_name};
- }
- if ( ref $zone_name ) {
- croak q{ERROR: Invalid non-scalar $zone_name};
- }
+ check_mandatory_args_type( $args_ref, q{HASH}, qw( global_config ) );
- if ( not $site_name ) {
- croak q{ERROR: Invalid empty $site_name};
- }
- if ( ref $site_name ) {
- croak q{ERROR: Invalid non-scalar $site_name};
- }
-
- 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 ( $zone_name, $site_name, $global_config, $template_filename )
+ = @{$args_ref}
+ {qw( zone_name site_name global_config template_filename )};
# This is not a complete check but it will catch obvious errors,
# like $global_config referencing a non-config hash
@@ -1475,97 +1478,94 @@
my $zone_part = $zone_ref->{'BY_SITE'}->{$site_name};
if ( not $zone_part ) {
- croak qq{ERROR: Unknown site_name: $zone_name};
+ croak qq{ERROR: Unknown site_name: $site_name};
}
- # Build Header (SOA, NS an MX fields)
- my $header_lines_ref
- = __make_zone_header( $zone_name, $site_name, $zone_ref );
- my @lines = @{$header_lines_ref};
+ my $soa = $zone_ref->{'SOA'};
+ my $new_soa = clone($soa);
+ $new_soa->{'serial'}
+ = $soa->{'serial'} eq 'AUTO' ? time : $soa->{'serial'};
+ $new_soa->{'ns_list'} = $new_soa->{'@ns'};
+ $new_soa->{'mx_list'} = $new_soa->{'@mx'};
# Merge private and public parts for a given zone_name
my $merged_zone_ref = merge( $zone_part, $zone_ref->{'ALL_SITES'} );
- ### Build Networks part
- push @lines,
- q{;;},
- q{;; Networks},
- q{;;============================================================================},
- q{};
-
+ my @networks = ();
my @network_order = @{ $zone_part->{'__network_order'} };
push @network_order,
@{ $zone_ref->{'ALL_SITES'}->{'__network_order'} };
foreach my $network (@network_order) {
- my $head = qq{; $network};
- if ( $merged_zone_ref->{$network}->{'comment'} ) {
- $head .= ": $merged_zone_ref->{$network}->{'comment'}";
- }
+ my $network_ref = {
+ name => $network,
+ comment => $merged_zone_ref->{$network}->{'comment'},
+ };
- push @lines,
- $head,
- q{;----------------------------------------------------------------------------};
-
+ my @records = ();
foreach my $spec (qw( network netmask broadcast gateway )) {
my $value = $merged_zone_ref->{$network}->{$spec};
next unless defined $value;
- push @lines,
- sprintf( q{%-29s IN %s}, qq{$spec.$network}, $value );
+ push @records, {
+ name => qq{$spec.$network},
+ value => $value,
+ };
}
+ $network_ref->{'records'} = \@records;
- push @lines, q{};
+ push @networks, $network_ref;
}
### Servers
- push @lines,
- q{},
- q{},
- q{;;},
- q{;; Servers},
- q{;;============================================================================},
- q{};
-
my @hostclass_order
= uniq(
- @{ $zone_ref->{'BY_SITE'}->{$site_name}->{'__hostclass_order'} },
- @{ $zone_ref->{'ALL_SITES'}->{'__hostclass_order'} },
+ @{ $zone_ref->{'BY_SITE'}->{$site_name}->{'__hostclass_order'} },
+ @{ $zone_ref->{'ALL_SITES'}->{'__hostclass_order'} },
);
+ my @servers = ();
foreach my $server (@hostclass_order) {
- my $head = qq{; $server};
+ my $server_ref = {
+ name => $server,
+ comment => $merged_zone_ref->{$server}->{'comment'},
+ };
- if ( $merged_zone_ref->{$server}->{'comment'} ) {
- $head .= ": $merged_zone_ref->{$server}->{'comment'}";
- }
-
- push @lines,
- $head,
- q{;----------------------------------------------------------------------------};
-
+ my @records = ();
foreach my $field ( sort keys %{ $merged_zone_ref->{$server} } ) {
next if $field eq 'comment';
if ( ref $merged_zone_ref->{$server}->{$field} eq 'ARRAY' ) {
foreach my $elt ( @{ $merged_zone_ref->{$server}->{$field} } )
{
- push @lines,
- sprintf( q{%-29s IN %s}, $field, $elt );
+ push @records, { name => $field, value => $elt, };
}
}
else {
- push @lines,
- sprintf(
- q{%-29s IN %s},
- $field, $merged_zone_ref->{$server}->{$field}
- );
+ push @records, {
+ name => $field,
+ value => $merged_zone_ref->{$server}->{$field},
+ };
}
}
+ $server_ref->{'records'} = \@records;
- push @lines, q{};
+ push @servers, $server_ref;
+
}
- return \@lines;
+ my $vars_ref = {
+ zone_name => $zone_name,
+ site_name => $site_name,
+ soa => $new_soa,
+ networks => \@networks,
+ servers => \@servers,
+ };
+ my $lines_ref = [
+ split qr{ \n }xms,
+ __read_and_process_template( $template_filename, $vars_ref ), -1
+ ];
+
+ return $lines_ref;
}
=head2 __build_sources_list($arguments_ref)
@@ -1892,87 +1892,6 @@
return $md5sum;
}
-=head2 __make_zone_header( $zone_name, $site_name, $zone_part )
-
-This function creates the header lines for the I<$zone_name> zone file on site
-I<$site_name>. I<$zone_ref> references the hash describing I<$zone_name>. It
-returns a reference to the array of generated lines.
-
-=cut
-
-sub __make_zone_header {
- my ( $zone_name, $site_name, $zone_ref ) = @_;
-
- if ( not $zone_name ) {
- croak q{ERROR: Invalid empty $zone_name};
- }
- if ( ref $zone_name ) {
- croak q{ERROR: Invalid non-scalar $zone_name};
- }
-
- if ( not $site_name ) {
- croak q{ERROR: Invalid empty $site_name};
- }
- if ( ref $site_name ) {
- croak q{ERROR: Invalid non-scalar $site_name};
- }
-
- if ( not $zone_ref ) {
- croak q{ERROR: Invalid empty $zone_ref};
- }
- if ( ref $zone_ref ne 'HASH' ) {
- croak q{ERROR: Invalid non-hashref $zone_ref};
- }
-
- # This is not a complete check but it will catch obvious errors,
- # like $zone_ref referencing a non-zone hash
- if ( not exists $zone_ref->{'SOA'} ) {
- croak q{ERROR: Invalid $zone_ref hashref: no 'SOA' key found};
- }
-
- my $serial
- = $zone_ref->{'SOA'}->{'serial'} eq 'AUTO'
- ? time
- : $zone_ref->{'SOA'}->{'serial'};
-
- # SOA
- my @result = (
- q{;;},
- qq{;; BIND configuration file for zone: $zone_name},
- qq{;; Site: $site_name},
- q{;;},
- qq/;; $zone_ref->{'SOA'}->{'comment'}/,
- q{;;============================================================================},
- q{},
- sprintf( q{$TTL %s}, $zone_ref->{'SOA'}->{'ttl'} ),
- sprintf(
- qq{%-29s IN SOA\t%s %s (},
- q{@}, $zone_ref->{'SOA'}->{'soa'},
- $zone_ref->{'SOA'}->{'mail'},
- ),
- sprintf( "%-30s%s\t; Serial", q{}, $serial ),
- );
-
- foreach my $spec ( 'refresh', 'retry', 'expire', 'negttl' ) {
- push @result, sprintf( q{%-30s%s}, q{}, $zone_ref->{'SOA'}->{$spec} );
- }
- push @result, sprintf( qq{%-30s%s}, q{}, q{)} ), q{};
-
- # NS fields
- foreach my $nameserver ( @{ $zone_ref->{'SOA'}->{'@ns'} } ) {
- push @result, sprintf( qq{%-29s IN NS\t%s}, q{}, $nameserver );
- }
- push @result, q{};
-
- # MX fields
- foreach my $mx ( @{ $zone_ref->{'SOA'}->{'@mx'} } ) {
- push @result, sprintf( qq{%-29s IN MX\t%s}, q{}, $mx );
- }
- push @result, q{}, q{};
-
- return \@result;
-}
-
=head2 __move_if_different( $source, $destination )
Compares I<$source> and I<$destination>. If they differ, moves I<$source> to
diff -r ecbac7c44d67 -r 918d6650a6d2 t/13.conf.cfg1/config-export/COMMON/private-network
--- a/t/13.conf.cfg1/config-export/COMMON/private-network Sun Dec 12 19:40:42 2010 +0100
+++ b/t/13.conf.cfg1/config-export/COMMON/private-network Tue Dec 21 16:58:16 2010 +0100
@@ -3,19 +3,19 @@
[private]
type = zone
comment = Internal management zone
-serial = AUTO
+serial = 2010122101
soa = Deploy00.private.
mail = dnsmaster at private
-refresh = 6H ; Refresh (6 hours)
-retry = 1H ; Retry (1 hour)
-expire = 7D ; Expire (7 days)
-negttl = 1H ; Negative TTL (1 hours)
-ttl = 1D ; TTL (1 day)
+refresh = 6H ; Refresh (6 hours)
+retry = 1H ; Retry (1 hour)
+expire = 7D ; Expire (7 days)
+negttl = 1H ; Negative TTL (1 hours)
+ttl = 1D ; TTL (1 day)
@ns = deploy00.vlan-systeme.private.
@ns = deploy01.vlan-systeme.private.
- at mx = 1 mf.private.
- at mx = 2 mf00.private.
- at mx = 2 mf01.private.
+ at mx = 1 mf.private.
+ at mx = 2 mf00.private.
+ at mx = 2 mf01.private.
[cbv4-pfds]
type = site
diff -r ecbac7c44d67 -r 918d6650a6d2 t/13.conf.t
--- a/t/13.conf.t Sun Dec 12 19:40:42 2010 +0100
+++ b/t/13.conf.t Tue Dec 21 16:58:16 2010 +0100
@@ -530,23 +530,23 @@
},
'private' => {
'@mx' => [
- '1 mf.private.',
- '2 mf00.private.',
- '2 mf01.private.',
+ '1 mf.private.',
+ '2 mf00.private.',
+ '2 mf01.private.',
],
'@ns' => [
'deploy00.vlan-systeme.private.',
'deploy01.vlan-systeme.private.',
],
'comment' => 'Internal management zone',
- 'expire' => '7D ; Expire (7 days)',
+ 'expire' => '7D ; Expire (7 days)',
'mail' => 'dnsmaster at private',
- 'negttl' => '1H ; Negative TTL (1 hours)',
- 'refresh' => '6H ; Refresh (6 hours)',
- 'retry' => '1H ; Retry (1 hour)',
- 'serial' => 'AUTO',
+ 'negttl' => '1H ; Negative TTL (1 hours)',
+ 'refresh' => '6H ; Refresh (6 hours)',
+ 'retry' => '1H ; Retry (1 hour)',
+ 'serial' => '2010122101',
'soa' => 'Deploy00.private.',
- 'ttl' => '1D ; TTL (1 day)',
+ 'ttl' => '1D ; TTL (1 day)',
'type' => 'zone',
},
'vip-spawn' => {
@@ -1347,21 +1347,21 @@
'deploy00.vlan-systeme.private.',
'deploy01.vlan-systeme.private.'
],
- 'ttl' => '1D ; TTL (1 day)',
- 'serial' => 'AUTO',
+ 'ttl' => '1D ; TTL (1 day)',
+ 'serial' => '2010122101',
'@mx' => [
- '1 mf.private.',
- '2 mf00.private.',
- '2 mf01.private.'
+ '1 mf.private.',
+ '2 mf00.private.',
+ '2 mf01.private.'
],
- 'retry' => '1H ; Retry (1 hour)',
- 'negttl' => '1H ; Negative TTL (1 hours)',
+ 'retry' => '1H ; Retry (1 hour)',
+ 'negttl' => '1H ; Negative TTL (1 hours)',
'comment' => 'Internal management zone',
- 'refresh' => '6H ; Refresh (6 hours)',
+ 'refresh' => '6H ; Refresh (6 hours)',
'type' => 'zone',
'mail' => 'dnsmaster at private',
'soa' => 'Deploy00.private.',
- 'expire' => '7D ; Expire (7 days)'
+ 'expire' => '7D ; Expire (7 days)'
},
},
},
diff -r ecbac7c44d67 -r 918d6650a6d2 t/20.files.dhcpd.conf.tpl
--- a/t/20.files.dhcpd.conf.tpl Sun Dec 12 19:40:42 2010 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,16 +0,0 @@
-# Generated from a sample dhcpd.conf template
-
-[% FOREACH subnet IN subnets -%]
-subnet [% subnet.subnet %] netmask [% subnet.netmask %] {
-}
-
-[% END -%]
-
-[%- FOREACH host IN hosts -%]
-host [% host.hostname %] {
-[% FOREACH definition IN host.definitions -%]
- [% definition %]
-[% END -%]
-}
-
-[% END -%]
diff -r ecbac7c44d67 -r 918d6650a6d2 t/20.files.t
--- a/t/20.files.t Sun Dec 12 19:40:42 2010 +0100
+++ b/t/20.files.t Tue Dec 21 16:58:16 2010 +0100
@@ -25,277 +25,191 @@
my $global_config = Init_GLOBAL_NETCONFIG( q{COMMON:private-network}, $hash_subst );
-########################################################################
-note('Testing PFTools::Utils::__make_zone_header');
-can_ok( 'PFTools::Utils', qw( __make_zone_header ) );
-
-throws_ok { PFTools::Utils::__make_zone_header(); }
-qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] zone_name }xms
- => q{Dies if empty $zone_name};
-
-throws_ok { PFTools::Utils::__make_zone_header( {} ); }
-qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] [\$] zone_name }xms
- => q{Dies if non-scalar $zone_name};
-
-throws_ok { PFTools::Utils::__make_zone_header( q{name} ); }
-qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] site_name }xms
- => q{Dies if empty $site_name};
-
-throws_ok { PFTools::Utils::__make_zone_header( q{name}, {} ); }
-qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] [\$] site_name }xms
- => q{Dies if non-scalar $site_name};
-
-throws_ok { PFTools::Utils::__make_zone_header( q{name}, q{site} ); }
-qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] zone_ref }xms
- => q{Dies if empty $zone_ref};
-
-throws_ok { PFTools::Utils::__make_zone_header( q{name}, q{site}, q{ref} ); }
-qr{ \A ERROR: [ ] Invalid [ ] non-hashref [ ] [\$] zone_ref }xms
- => q{Dies if non-hashref $zone_ref};
-
-throws_ok { PFTools::Utils::__make_zone_header( q{name}, q{site}, {} ); }
-qr{ \A ERROR: [ ] Invalid [ ] [\$] zone_ref [ ] hashref:
- [ ] no [ ] 'SOA' [ ] key [ ] found }xms
- => q{Dies if non-zone hashref $zone_ref};
-
-
-my $zone_ref = $global_config->{'ZONE'}->{'BY_NAME'}->{'private'};
-$zone_ref->{'SOA'}->{'serial'} = '1289575205';
-my $result = PFTools::Utils::__make_zone_header( 'private', 'cbv4-pfds', $zone_ref );
-my $expected_result = [
- ';;',
- ';; BIND configuration file for zone: private',
- ';; Site: cbv4-pfds',
- ';;',
- ';; Internal management zone',
- ';;============================================================================',
- '',
- '$TTL 1D ; TTL (1 day)',
- '@ IN SOA' . qq{\t} . 'Deploy00.private. dnsmaster at private (',
- ' 1289575205' . qq{\t} . '; Serial',
- ' 6H ; Refresh (6 hours)',
- ' 1H ; Retry (1 hour)',
- ' 7D ; Expire (7 days)',
- ' 1H ; Negative TTL (1 hours)',
- ' )',
- '',
- ' IN NS' . qq{\t} . 'deploy00.vlan-systeme.private.',
- ' IN NS' . qq{\t} . 'deploy01.vlan-systeme.private.',
- '',
- ' IN MX' . qq{\t} . '1 mf.private.',
- ' IN MX' . qq{\t} . '2 mf00.private.',
- ' IN MX' . qq{\t} . '2 mf01.private.',
- '',
- '',
-];
-
-is_deeply $result, $expected_result
- => q{Returns the expected result for zone 'private'}
- or note explain $result;
-
########################################################################
note('Testing PFTools::Utils::__build_zone');
can_ok( 'PFTools::Utils', qw( __build_zone ) );
+my $template_filename = q{templates/zone.tpl};
+my $args_ref = {
+ zone_name => q{},
+ site_name => q{site_name},
+ template_filename => $template_filename,
+ global_config => $global_config,
+};
+
throws_ok { PFTools::Utils::__build_zone(); }
-qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] zone_name }xms
+qr{ \A ERROR: [ ] BUG: [ ] invalid [ ] args }xms
+ => q{Dies if no args};
+
+throws_ok { PFTools::Utils::__build_zone($args_ref); }
+qr{ \A ERROR: [ ] Invalid [ ] empty [ ] zone_name }xms
=> q{Dies if empty $zone_name};
-throws_ok { PFTools::Utils::__build_zone( { zone_name => {} } ); }
-qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] [\$] zone_name }xms
+$args_ref->{'zone_name'} = { foo => 0 };
+throws_ok { PFTools::Utils::__build_zone($args_ref); }
+qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] zone_name }xms
=> q{Dies if non-scalar $zone_name};
-throws_ok { PFTools::Utils::__build_zone( { zone_name => q{name} } ); }
-qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] site_name }xms
+$args_ref->{'zone_name'} = q{};
+$args_ref->{'site_name'} = q{};
+throws_ok { PFTools::Utils::__build_zone($args_ref); }
+qr{ \A ERROR: [ ] Invalid [ ] empty [ ] site_name }xms
=> q{Dies if empty $site_name};
-throws_ok {
- PFTools::Utils::__build_zone(
- {
- zone_name => q{name},
- site_name => {},
- }
- );
-}
-qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] [\$] site_name }xms
+$args_ref->{'zone_name'} = q{name};
+$args_ref->{'site_name'} = {};
+throws_ok { PFTools::Utils::__build_zone($args_ref); }
+qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] site_name }xms
=> q{Dies if non-scalar $site_name};
-throws_ok {
- PFTools::Utils::__build_zone(
- {
- zone_name => q{name},
- site_name => q{site},
- }
- );
-}
-qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] global_config }xms
- => q{Dies if empty $global_config};
+$args_ref->{'site_name'} = q{site};
+throws_ok { PFTools::Utils::__build_zone($args_ref); }
+qr{ \A ERROR: [ ] Unknown [ ] zone_name: [ ] name }xms
+ => q{Dies if unknown $zone_name};
-throws_ok {
- PFTools::Utils::__build_zone(
- {
- zone_name => q{name},
- site_name => q{site},
- global_config => q{ref},
- }
- );
-}
-qr{ \A ERROR: [ ] Invalid [ ] non-hashref [ ] [\$] global_config }xms
+$args_ref->{'zone_name'} = q{private};
+throws_ok { PFTools::Utils::__build_zone($args_ref); }
+qr{ \A ERROR: [ ] Unknown [ ] site_name: [ ] site }xms
+ => q{Dies if unknown site_name};
+
+$args_ref->{'site_name'} = q{cbv4-pfds};
+delete $args_ref->{'global_config'};
+throws_ok { PFTools::Utils::__build_zone($args_ref); }
+qr{ \A ERROR: [ ] Mandatory [ ] argument [ ] global_config [ ] not [ ] found }xms
+ => q{Dies if no $global_config};
+
+$args_ref->{'global_config'} = q{not a ref};
+throws_ok { PFTools::Utils::__build_zone($args_ref); }
+qr{ \A ERROR: [ ] Invalid [ ] non-hash [ ] reference [ ] global_config }xms
=> q{Dies if non-hashref $global_config};
-throws_ok {
- PFTools::Utils::__build_zone(
- {
- zone_name => q{name},
- site_name => q{site},
- global_config => {},
- }
- );
-}
+$args_ref->{'global_config'} = {};
+throws_ok { PFTools::Utils::__build_zone($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_zone(
- {
- zone_name => q{name},
- site_name => q{site},
- global_config => $global_config,
- }
- );
-}
-qr{ \A ERROR: [ ] Unknown [ ] zone_name: [ ] }xms
- => q{Dies if unknown zone_name};
+$args_ref->{'global_config'} = $global_config;
+delete $args_ref->{'template_filename'};
+throws_ok { PFTools::Utils::__build_zone($args_ref); }
+qr{ \A ERROR: [ ] Mandatory [ ] argument [ ] template_filename [ ] not [ ] found }xms
+ => q{Dies if no template_filename};
-throws_ok {
- PFTools::Utils::__build_zone(
- {
- zone_name => q{private},
- site_name => q{site},
- global_config => $global_config
- }
- );
-}
-qr{ \A ERROR: [ ] Unknown [ ] site_name: [ ] }xms
- => q{Dies if unknown site_name};
-
-$result = PFTools::Utils::__build_zone(
- {
- zone_name => q{private},
- site_name => q{cbv4-pfds},
- global_config => $global_config,
- }
-);
-$expected_result = [
- ';;',
- ';; BIND configuration file for zone: private',
- ';; Site: cbv4-pfds',
- ';;',
- ';; Internal management zone',
- ';;============================================================================',
- '',
- '$TTL 1D ; TTL (1 day)',
- '@ IN SOA Deploy00.private. dnsmaster at private (',
- ' 1289575205 ; Serial',
- ' 6H ; Refresh (6 hours)',
- ' 1H ; Retry (1 hour)',
- ' 7D ; Expire (7 days)',
- ' 1H ; Negative TTL (1 hours)',
- ' )',
- '',
- ' IN NS deploy00.vlan-systeme.private.',
- ' IN NS deploy01.vlan-systeme.private.',
- '',
- ' IN MX 1 mf.private.',
- ' IN MX 2 mf00.private.',
- ' IN MX 2 mf01.private.',
- '',
- '',
- ';;',
- ';; Networks',
- ';;============================================================================',
- '',
- '; vlan-systeme',
- ';----------------------------------------------------------------------------',
- 'network.vlan-systeme IN A 10.1.0.0',
- 'netmask.vlan-systeme IN A 255.255.0.0',
- 'broadcast.vlan-systeme IN A 10.1.255.255',
- '',
- '; vlan-pfds-int',
- ';----------------------------------------------------------------------------',
- 'network.vlan-pfds-int IN A 10.2.0.0',
- 'netmask.vlan-pfds-int IN A 255.255.0.0',
- 'broadcast.vlan-pfds-int IN A 10.2.255.255',
- '',
- '; vlan-admindsi',
- ';----------------------------------------------------------------------------',
- 'network.vlan-admindsi IN A 10.3.1.0',
- 'netmask.vlan-admindsi IN A 255.255.255.0',
- 'broadcast.vlan-admindsi IN A 10.3.1.255',
- 'gateway.vlan-admindsi IN A 10.3.1.254',
- '',
- '; vlan-middledsi',
- ';----------------------------------------------------------------------------',
- 'network.vlan-middledsi IN A 10.3.2.0',
- 'netmask.vlan-middledsi IN A 255.255.255.0',
- 'broadcast.vlan-middledsi IN A 10.3.2.255',
- 'gateway.vlan-middledsi IN A 10.3.2.254',
- '',
- '; vlan-pfds-ext',
- ';----------------------------------------------------------------------------',
- 'network.vlan-pfds-ext IN A 192.168.1.0',
- 'netmask.vlan-pfds-ext IN A 255.255.255.0',
- 'broadcast.vlan-pfds-ext IN A 192.168.1.255',
- 'gateway.vlan-pfds-ext IN A 192.168.1.254',
- '',
- '',
- '',
- ';;',
- ';; Servers',
- ';;============================================================================',
- '',
- '; vip-spawn',
- ';----------------------------------------------------------------------------',
- 'cvs IN CNAME vip-spawn.vlan-systeme',
- 'mf IN CNAME vip-spawn.vlan-systeme',
- 'mirrors IN CNAME vip-spawn.vlan-systeme',
- 'nscache IN CNAME vip-spawn.vlan-systeme',
- 'nsprivate IN CNAME vip-spawn.vlan-systeme',
- 'vip-deploy IN CNAME vip-spawn.vlan-systeme',
- 'vip-spawn.vlan-pfds-ext IN A 192.168.1.99',
- 'vip-spawn.vlan-systeme IN A 10.1.1.254',
- '',
- '; cbv4-pfds-filer',
- ';----------------------------------------------------------------------------',
- 'cbv4-pfds-filer00.vlan-systeme IN A 10.1.2.0',
- 'cbv4-pfds-filer01.vlan-systeme IN A 10.1.2.1',
- '',
- '; cbv4-spawn',
- ';----------------------------------------------------------------------------',
- 'cbv4-spawn IN CNAME cbv4-spawn.vlan-systeme',
- 'cbv4-spawn.vlan-systeme IN A 10.1.167.0',
- 'cbv4-spawn.vlan-systeme IN A 10.1.167.1',
- 'cbv4-spawn00.vlan-admindsi IN A 10.3.1.41',
- 'cbv4-spawn00.vlan-middledsi IN A 10.3.2.41',
- 'cbv4-spawn00.vlan-pfds-ext IN A 192.168.1.97',
- 'cbv4-spawn00.vlan-pfds-int IN A 10.2.167.0',
- 'cbv4-spawn00.vlan-systeme IN A 10.1.167.0',
- 'cbv4-spawn01.vlan-admindsi IN A 10.3.1.42',
- 'cbv4-spawn01.vlan-middledsi IN A 10.3.2.42',
- 'cbv4-spawn01.vlan-pfds-ext IN A 192.168.1.98',
- 'cbv4-spawn01.vlan-pfds-int IN A 10.2.167.1',
- 'cbv4-spawn01.vlan-systeme IN A 10.1.167.1',
- 'ntp IN CNAME cbv4-spawn.vlan-systeme',
- 'ntp00 IN CNAME cbv4-spawn00.vlan-systeme',
- 'ntp01 IN CNAME cbv4-spawn01.vlan-systeme',
- 'spawn IN CNAME cbv4-spawn.vlan-systeme',
- 'spawn00 IN CNAME cbv4-spawn00.vlan-systeme',
- 'spawn01 IN CNAME cbv4-spawn01.vlan-systeme',
- ''
+$args_ref->{'template_filename'} = $template_filename;
+my $result = PFTools::Utils::__build_zone($args_ref);
+my $expected_result = [
+ q{;;},
+ q{;; BIND configuration file for zone: private},
+ q{;; Site: cbv4-pfds},
+ q{;;},
+ q{;; Internal management zone},
+ q{;;============================================================================},
+ q{},
+ qq{\$TTL\t1D\t; TTL (1 day)},
+ q{@ IN SOA Deploy00.private. dnsmaster at private (},
+ qq{\t\t2010122101\t; Serial},
+ qq{\t\t6H\t; Refresh (6 hours)},
+ qq{\t\t1H\t; Retry (1 hour)},
+ qq{\t\t7D\t; Expire (7 days)},
+ qq{\t\t1H\t; Negative TTL (1 hours)},
+ qq{\t)},
+ q{},
+ qq{\tIN NS deploy00.vlan-systeme.private.},
+ qq{\tIN NS deploy01.vlan-systeme.private.},
+ q{},
+ qq{\tIN MX\t1\tmf.private.},
+ qq{\tIN MX\t2\tmf00.private.},
+ qq{\tIN MX\t2\tmf01.private.},
+ q{},
+ q{},
+ q{;;},
+ q{;; Networks},
+ q{;;============================================================================},
+ q{},
+ q{; vlan-systeme},
+ q{;----------------------------------------------------------------------------},
+ qq{network.vlan-systeme\tIN A\t10.1.0.0},
+ qq{netmask.vlan-systeme\tIN A\t255.255.0.0},
+ qq{broadcast.vlan-systeme\tIN A\t10.1.255.255},
+ q{},
+ q{; vlan-pfds-int},
+ q{;----------------------------------------------------------------------------},
+ qq{network.vlan-pfds-int\tIN A\t10.2.0.0},
+ qq{netmask.vlan-pfds-int\tIN A\t255.255.0.0},
+ qq{broadcast.vlan-pfds-int\tIN A\t10.2.255.255},
+ q{},
+ q{; vlan-admindsi},
+ q{;----------------------------------------------------------------------------},
+ qq{network.vlan-admindsi\tIN A\t10.3.1.0},
+ qq{netmask.vlan-admindsi\tIN A\t255.255.255.0},
+ qq{broadcast.vlan-admindsi\tIN A\t10.3.1.255},
+ qq{gateway.vlan-admindsi\tIN A\t10.3.1.254},
+ q{},
+ q{; vlan-middledsi},
+ q{;----------------------------------------------------------------------------},
+ qq{network.vlan-middledsi\tIN A\t10.3.2.0},
+ qq{netmask.vlan-middledsi\tIN A\t255.255.255.0},
+ qq{broadcast.vlan-middledsi\tIN A\t10.3.2.255},
+ qq{gateway.vlan-middledsi\tIN A\t10.3.2.254},
+ q{},
+ q{; vlan-pfds-ext},
+ q{;----------------------------------------------------------------------------},
+ qq{network.vlan-pfds-ext\tIN A\t192.168.1.0},
+ qq{netmask.vlan-pfds-ext\tIN A\t255.255.255.0},
+ qq{broadcast.vlan-pfds-ext\tIN A\t192.168.1.255},
+ qq{gateway.vlan-pfds-ext\tIN A\t192.168.1.254},
+ q{},
+ q{},
+ q{},
+ q{;;},
+ q{;; Servers},
+ q{;;============================================================================},
+ q{},
+ q{; vip-spawn},
+ q{;----------------------------------------------------------------------------},
+ qq{cvs\tIN CNAME\tvip-spawn.vlan-systeme},
+ qq{mf\tIN CNAME\tvip-spawn.vlan-systeme},
+ qq{mirrors\tIN CNAME\tvip-spawn.vlan-systeme},
+ qq{nscache\tIN CNAME\tvip-spawn.vlan-systeme},
+ qq{nsprivate\tIN CNAME\tvip-spawn.vlan-systeme},
+ qq{vip-deploy\tIN CNAME\tvip-spawn.vlan-systeme},
+ qq{vip-spawn.vlan-pfds-ext\tIN A\t192.168.1.99},
+ qq{vip-spawn.vlan-systeme\tIN A\t10.1.1.254},
+ q{},
+ q{; cbv4-pfds-filer},
+ q{;----------------------------------------------------------------------------},
+ qq{cbv4-pfds-filer00.vlan-systeme\tIN A\t10.1.2.0},
+ qq{cbv4-pfds-filer01.vlan-systeme\tIN A\t10.1.2.1},
+ q{},
+ q{; cbv4-spawn},
+ q{;----------------------------------------------------------------------------},
+ qq{cbv4-spawn\tIN CNAME\tcbv4-spawn.vlan-systeme},
+ qq{cbv4-spawn.vlan-systeme\tIN A\t10.1.167.0},
+ qq{cbv4-spawn.vlan-systeme\tIN A\t10.1.167.1},
+ qq{cbv4-spawn00.vlan-admindsi\tIN A\t10.3.1.41},
+ qq{cbv4-spawn00.vlan-middledsi\tIN A\t10.3.2.41},
+ qq{cbv4-spawn00.vlan-pfds-ext\tIN A\t192.168.1.97},
+ qq{cbv4-spawn00.vlan-pfds-int\tIN A\t10.2.167.0},
+ qq{cbv4-spawn00.vlan-systeme\tIN A\t10.1.167.0},
+ qq{cbv4-spawn01.vlan-admindsi\tIN A\t10.3.1.42},
+ qq{cbv4-spawn01.vlan-middledsi\tIN A\t10.3.2.42},
+ qq{cbv4-spawn01.vlan-pfds-ext\tIN A\t192.168.1.98},
+ qq{cbv4-spawn01.vlan-pfds-int\tIN A\t10.2.167.1},
+ qq{cbv4-spawn01.vlan-systeme\tIN A\t10.1.167.1},
+ qq{ntp\tIN CNAME\tcbv4-spawn.vlan-systeme},
+ qq{ntp00\tIN CNAME\tcbv4-spawn00.vlan-systeme},
+ qq{ntp01\tIN CNAME\tcbv4-spawn01.vlan-systeme},
+ qq{spawn\tIN CNAME\tcbv4-spawn.vlan-systeme},
+ qq{spawn00\tIN CNAME\tcbv4-spawn00.vlan-systeme},
+ qq{spawn01\tIN CNAME\tcbv4-spawn01.vlan-systeme},
+ q{},
+ 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;
@@ -312,10 +226,11 @@
my $test_output_file = q{test.zone};
$result = make_zone_file(
{
- zone_name => q{private},
- site_name => q{cbv4-pfds},
- filename => $test_output_file,
- global_config => $global_config,
+ zone_name => q{private},
+ site_name => q{cbv4-pfds},
+ filename => $test_output_file,
+ template_filename => $template_filename,
+ global_config => $global_config,
}
);
ok $result => q{Returns true on success};
@@ -770,11 +685,11 @@
=> q{Dies if non-scalar $hostname};
my $test_sections_ref = [qw(common uncommon)];
-my $args_ref = {
+$args_ref = {
hostname => q{cbv4-rdeploy01},
site_name => q{cbv4},
sections_ref => $test_sections_ref,
- template => q{templates/sources.list},
+ template => q{templates/sources.list.tpl},
global_config => $global_config,
pf_config => $pf_config,
};
@@ -1199,7 +1114,7 @@
note('Testing PFTools::Utils::__build_dhcpd_conf');
can_ok( 'PFTools::Utils', qw( PFTools::Utils::__build_dhcpd_conf ) );
-my $template_filename = q{t/20.files.dhcpd.conf.tpl};
+$template_filename = q{templates/dhcpd.conf.tpl};
$output_filename = q{/tmp/test.dhcpd.conf};
$site_name = q{foo-site};
$args_ref = {
diff -r ecbac7c44d67 -r 918d6650a6d2 templates/dhcpd.conf.tpl
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/dhcpd.conf.tpl Tue Dec 21 16:58:16 2010 +0100
@@ -0,0 +1,16 @@
+# Generated from a sample dhcpd.conf template
+
+[% FOREACH subnet IN subnets -%]
+subnet [% subnet.subnet %] netmask [% subnet.netmask %] {
+}
+
+[% END -%]
+
+[%- FOREACH host IN hosts -%]
+host [% host.hostname %] {
+[% FOREACH definition IN host.definitions -%]
+ [% definition %]
+[% END -%]
+}
+
+[% END -%]
diff -r ecbac7c44d67 -r 918d6650a6d2 templates/sources.list
--- a/templates/sources.list Sun Dec 12 19:40:42 2010 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,12 +0,0 @@
-#
-# Generated by mk_sourceslist -- DO NOT EDIT!
-#
-
-deb http://mirrors.private/[% mode %] [% distrib %] [% default_sections %]
-deb http://mirrors.private/[% mode %]-custom [% distrib %]-custom [% custom_sections %]
-deb http://mirrors.private/[% mode %]-security [% distrib %]/updates [% default_sections %]
-
-[% IF backports -%]
-deb http://mirrors.private/[% mode %]-backports [% distrib %]-backports [% default_sections %]
-
-[% END -%]
diff -r ecbac7c44d67 -r 918d6650a6d2 templates/sources.list.tpl
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/sources.list.tpl Tue Dec 21 16:58:16 2010 +0100
@@ -0,0 +1,12 @@
+#
+# Generated by mk_sourceslist -- DO NOT EDIT!
+#
+
+deb http://mirrors.private/[% mode %] [% distrib %] [% default_sections %]
+deb http://mirrors.private/[% mode %]-custom [% distrib %]-custom [% custom_sections %]
+deb http://mirrors.private/[% mode %]-security [% distrib %]/updates [% default_sections %]
+
+[% IF backports -%]
+deb http://mirrors.private/[% mode %]-backports [% distrib %]-backports [% default_sections %]
+
+[% END -%]
More information about the pf-tools-commits
mailing list