pf-tools/pf-tools: 5 new changesets
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Thu Nov 18 16:04:24 UTC 2010
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/e01d34c52071
changeset: 1032:e01d34c52071
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Tue Nov 16 18:31:55 2010 +0100
description:
Rename Mk_zone_for_site() to make_zone_for_site(), and don't export it by default
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/e88147b7fd0e
changeset: 1033:e88147b7fd0e
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Tue Nov 16 18:37:11 2010 +0100
description:
Rename Mk_resolvconf() to make_resolv_conf(), don't export it by default.
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/957b81694389
changeset: 1034:957b81694389
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Tue Nov 16 19:11:31 2010 +0100
description:
Rename Mk_interfaces() to make_interfaces(), add tests, don't export by default
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/ef80c1ea537d
changeset: 1035:ef80c1ea537d
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Thu Nov 18 07:42:41 2010 +0100
description:
Renamed make_resolv_conf() to make_resolv_conf_file(), for consistency.
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/75b485e19166
changeset: 1036:75b485e19166
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Thu Nov 18 16:55:31 2010 +0100
description:
make_interfaces_file() + tests
diffstat:
1 file changed, 3 deletions(-)
lib/PFTools/Utils.pm | 3 ---
diffs (754 lines):
diff -r fadccbca083c -r 75b485e19166 lib/PFTools/Utils.pm
--- a/lib/PFTools/Utils.pm Wed Nov 17 11:07:02 2010 +0100
+++ b/lib/PFTools/Utils.pm Thu Nov 18 16:55:31 2010 +0100
@@ -46,17 +46,18 @@
Do_update_from_GLOBAL
Fix_hosts
Mk_dhcp
- Mk_interfaces
Mk_PXE_bootfile
Mk_sourceslist
- Mk_resolvconf
- Mk_zone_for_site
Change_kopt_for_hostname
Search_and_replace
);
-our @EXPORT_OK = qw();
+our @EXPORT_OK = qw(
+ make_interfaces_file
+ make_resolv_conf_file
+ make_zone_for_site
+);
########################################################################
# Exported functions
@@ -84,7 +85,7 @@
# FIXME VCS_checkout should croak by itself
if ( !VCS_checkout( $hostname, $pf_config, {} ) ) {
- croak q{ERROR: Unable to checkout configuration from VCS system"};
+ croak q{ERROR: Unable to checkout configuration from VCS system};
}
my $source
@@ -173,7 +174,7 @@
return $pxe_boot_file;
}
-=head2 Mk_zone_for_site( $zone_name, $site_name, $global_config )
+=head2 make_zone_for_site( $zone_name, $site_name, $global_config )
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
@@ -181,7 +182,7 @@
=cut
-sub Mk_zone_for_site {
+sub make_zone_for_site {
my ( $zone_name, $site_name, $global_config ) = @_;
if ( not $zone_name ) {
@@ -300,7 +301,7 @@
return $zone_result;
}
-=head2 Mk_resolvconf( $hostname, $global_config, $site_name, $filename );
+=head2 make_resolv_conf_file( $hostname, $global_config, $site_name, $filename );
Writes the I<resolv.conf> configuration for I<$hostname> at I<$site_name> to
I<$filename>. I<$global_config> is a reference to the global configuration
@@ -308,7 +309,7 @@
=cut
-sub Mk_resolvconf {
+sub make_resolv_conf_file {
my ( $hostname, $global_config, $site_name, $filename ) = @_;
if ( not $hostname ) {
@@ -645,131 +646,37 @@
return 1;
}
-#
-# VOID Mk_interfaces (STRING $host, STRING $fic_iface, HASHREF $Z)
-#
-# Construit le fichier de declaration d'interfaces $fic_iface pour la
-# machine $host a partir des informations contenues dans la structure $Z
-#
-#======================================================================================
-sub Mk_interfaces {
- my ( $hostname, $global_config, $pf_config, $site_name ) = @_;
+=head2 make_interfaces_file( $hostname, $global_config, $pf_config, $site_name, $filename );
- my $resolve = 0;
- my $host_ref = get_host_config( $hostname, $global_config, $site_name );
- my $interfaces = {};
- my $routes = {};
+Writes the I<interfaces> configuration for I<$hostname> at I<$site_name> to
+I<$filename>. I<$global_config> is a reference to the global configuration
+hash. I<$pf_config> is a reference to the pf-tools configuration hash.
- foreach my $iface ( 'lo', sort keys %{ $host_ref->{'interfaces'} } ) {
- push @{ $interfaces->{'__order'} }, $iface;
+=cut
- my $if_part = $host_ref->{'interfaces'}->{$iface};
- my $if_method
- = $if_part->{'method'}
- ? $if_part->{'method'}
- : $iface eq 'lo' ? q{loopback}
- : q{static};
- push @{ $interfaces->{$iface} },
- qq{auto $iface},
- qq{iface $iface inet $if_method};
+sub make_interfaces_file {
+ my ( $hostname, $global_config, $pf_config, $site_name, $filename ) = @_;
- if (( $if_part->{'method'} and $if_part->{'method'} eq 'dhcp' )
- or $iface eq 'lo'
- )
- {
- next;
- }
+ # NOTE: all parameters (except $filename) are properly checked by
+ # make_interfaces() => no need to check them twice
- foreach my $ip_type ( 'ipv4', 'ipv6' ) {
- next if not $pf_config->{'features'}->{$ip_type};
-
- my $ip = NetAddr::IP->new( $if_part->{$ip_type} );
- if ( $if_part->{'slaves'} ) {
- push @{ $interfaces->{$iface} },
- qq{\tslaves\t\t} . $if_part->{'slaves'};
- }
- push @{ $interfaces->{$iface} },
- qq{\taddress\t\t} . $ip->addr(),
- qq{\tnetmask\t\t} . $ip->mask(),
- qq{\tnetwork\t\t} . $ip->network()->addr(),
- qq{\tbroadcast\t} . $ip->broadcast()->addr();
-
- # Routes
- my $suffix = get_suffix_from_ip_type( $ip_type );
- foreach my $route ( @{ $if_part->{ '@route' . $suffix } } ) {
- if ( $route =~ m{ \A (\S+) \s* (?: via (?: \S+ ) )? \z }xms )
- {
- my $destination = $1;
- push @{ $routes->{$destination} }, qq{$iface $route};
- }
- }
-
- # 802.1Q VLAN ID
- if ( $iface =~ m{ \A ([^.]+) [.] \d+ \z }xms ) {
- my $raw_device = $1;
- push @{ $interfaces->{$iface} },
- qq{\tvlan_raw_device\t$raw_device};
-
- # Set MTU to 1496 unless told otherwise
- if ($if_part->{'iface_opt'}
- and $if_part->{'iface_opt'} !~ m{ mtu }xms
- )
- {
- $if_part->{'iface_opt'} .= q{, mtu 1496};
- }
- else {
- $if_part->{'iface_opt'} = q{mtu 1496};
- }
- }
-
- # Options
- if ( $if_part->{'iface_opt'} ) {
- foreach my $option (
- split qr{ \s* [,] \s* }xms,
- $if_part->{'iface_opt'}
- )
- {
- push @{ $interfaces->{$iface} },
- qq{\tup\t\t/sbin/ip link set $iface $option};
- }
- }
- }
+ if ( not $filename ) {
+ croak q{ERROR: Invalid empty $filename};
+ }
+ if ( ref $hostname ) {
+ croak q{ERROR: Invalid non-scalar $filename};
}
-DESTINATION:
- foreach my $dest ( keys %{$routes} ) {
+ my $lines_ref = __build_interfaces( $hostname, $global_config, $pf_config, $site_name );
- # Multiple routes
- if ( scalar @{ $routes->{$dest} } > 1 ) {
- foreach my $entry ( @{ $routes->{$dest} } ) {
- my ( $if, $dst, $via, $gw ) = split qr{ \s+ }xms, $entry;
- unless ( defined $gw ) {
- croak
- qq{ERROR: host $hostname: route to $dest needs a gateway};
- }
- push @{ $interfaces->{$if} },
- qq{\tup\t\t/sbin/ip route add $dst scope global via $gw dev $if};
- }
- next DESTINATION;
- }
-
- # Only one route
- my ($entry) = @{ $routes->{$dest} };
- my ( $if, $dst, $via, $gw ) = split qr{ \s+ }xms, $entry;
- if ( $dst eq 'default' ) {
- unless ( defined $gw ) {
- croak
- qq{ERROR: host $hostname: default route needs a gateway};
- }
- push @{ $interfaces->{$if} }, qq{\tgateway\t\t$gw};
- next DESTINATION;
- }
-
- push @{ $interfaces->{$if} },
- qq{\tup\t\t/sbin/ip route add $entry dev $if};
+ my $out_fh = IO::File->new( $filename, q{>} );
+ unless ($out_fh) {
+ croak qq{ERROR: open $filename: $OS_ERROR};
}
- return $interfaces;
+ __write_array_to_filehandle( $out_fh, $filename, $lines_ref, qq{\n} );
+
+ return 1;
}
# FIXME documentation
@@ -1108,6 +1015,185 @@
__move_if_different( $tmp_fn, $dst );
return $preseed_filename;
+}
+
+=head2 __build_interfaces( FIXME)
+
+FIXME
+
+=cut
+
+# FIXME more generic build_foo (using File::Tmp and __move_if_different, but also handling STDOUT)
+
+sub __build_interfaces {
+ my ( $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};
+ }
+
+ # 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 $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 $resolve = 0;
+ my $host_ref = get_host_config( $hostname, $global_config, $site_name );
+ my $interfaces = {};
+ my $routes = {};
+
+ foreach my $iface ( 'lo', sort keys %{ $host_ref->{'interfaces'} } ) {
+ push @{ $interfaces->{'__order'} }, $iface;
+
+ my $if_part = $host_ref->{'interfaces'}->{$iface};
+ my $if_method
+ = $if_part->{'method'}
+ ? $if_part->{'method'}
+ : $iface eq 'lo' ? q{loopback}
+ : q{static};
+ push @{ $interfaces->{$iface} },
+ qq{auto $iface},
+ qq{iface $iface inet $if_method};
+
+ if (( $if_part->{'method'} and $if_part->{'method'} eq 'dhcp' )
+ or $iface eq 'lo'
+ )
+ {
+ next;
+ }
+
+ foreach my $ip_type ( 'ipv4', 'ipv6' ) {
+ next if not $pf_config->{'features'}->{$ip_type};
+
+ my $ip = NetAddr::IP->new( $if_part->{$ip_type} );
+ if ( $if_part->{'slaves'} ) {
+ push @{ $interfaces->{$iface} },
+ qq{\tslaves\t\t} . $if_part->{'slaves'};
+ }
+ push @{ $interfaces->{$iface} },
+ qq{\taddress\t\t} . $ip->addr(),
+ qq{\tnetmask\t\t} . $ip->mask(),
+ qq{\tnetwork\t\t} . $ip->network()->addr(),
+ qq{\tbroadcast\t} . $ip->broadcast()->addr();
+
+ # Routes
+ my $suffix = get_suffix_from_ip_type( $ip_type );
+ foreach my $route ( @{ $if_part->{ '@route' . $suffix } } ) {
+ if ( $route =~ m{ \A (\S+) \s* (?: via (?: \S+ ) )? \z }xms )
+ {
+ my $destination = $1;
+ push @{ $routes->{$destination} }, qq{$iface $route};
+ }
+ }
+
+ # 802.1Q VLAN ID
+ if ( $iface =~ m{ \A ([^.]+) [.] \d+ \z }xms ) {
+ my $raw_device = $1;
+ push @{ $interfaces->{$iface} },
+ qq{\tvlan_raw_device\t$raw_device};
+
+ # Set MTU to 1496 unless told otherwise
+ if ($if_part->{'iface_opt'}
+ and $if_part->{'iface_opt'} !~ m{ mtu }xms
+ )
+ {
+ $if_part->{'iface_opt'} .= q{, mtu 1496};
+ }
+ else {
+ $if_part->{'iface_opt'} = q{mtu 1496};
+ }
+ }
+
+ # Options
+ if ( $if_part->{'iface_opt'} ) {
+ foreach my $option (
+ split qr{ \s* [,] \s* }xms,
+ $if_part->{'iface_opt'}
+ )
+ {
+ push @{ $interfaces->{$iface} },
+ qq{\tup\t\t/sbin/ip link set $iface $option};
+ }
+ }
+ }
+ }
+
+DESTINATION:
+ foreach my $dest ( keys %{$routes} ) {
+
+ # Multiple routes
+ if ( scalar @{ $routes->{$dest} } > 1 ) {
+ foreach my $entry ( @{ $routes->{$dest} } ) {
+ my ( $if, $dst, $via, $gw ) = split qr{ \s+ }xms, $entry;
+ unless ( defined $gw ) {
+ croak
+ qq{ERROR: host $hostname: route to $dest needs a gateway};
+ }
+ push @{ $interfaces->{$if} },
+ qq{\tup\t\t/sbin/ip route add $dst scope global via $gw dev $if};
+ }
+ next DESTINATION;
+ }
+
+ # Only one route
+ my ($entry) = @{ $routes->{$dest} };
+ my ( $if, $dst, $via, $gw ) = split qr{ \s+ }xms, $entry;
+ if ( $dst eq 'default' ) {
+ unless ( defined $gw ) {
+ croak
+ qq{ERROR: host $hostname: default route needs a gateway};
+ }
+ push @{ $interfaces->{$if} }, qq{\tgateway\t\t$gw};
+ next DESTINATION;
+ }
+
+ push @{ $interfaces->{$if} },
+ qq{\tup\t\t/sbin/ip route add $entry dev $if};
+ }
+
+ my @lines = (
+ q{#},
+ q{# This file was auto-generated by mk_interfaces -- DO NOT EDIT!},
+ q{#},
+ q{},
+ );
+
+ foreach my $iface ( @{ $interfaces->{'__order' } } ) {
+ push @lines, @{ $interfaces->{$iface} }, q{};
+ }
+
+ return \@lines;
}
=head2 __get_kpkg_from_kernel( $pxefilename, $deploymode )
@@ -1384,7 +1470,7 @@
# IO::File does not implement filename()
#my $filename = $fh->filename();
- unless ( $fh->print( join $line_separator, @{$array_ref} ) ) {
+ unless ( $fh->print( join( $line_separator, @{$array_ref}), $line_separator ) ) {
croak qq{ERROR: print $filename: $OS_ERROR};
}
diff -r fadccbca083c -r 75b485e19166 sbin/mk_interfaces
--- a/sbin/mk_interfaces Wed Nov 17 11:07:02 2010 +0100
+++ b/sbin/mk_interfaces Thu Nov 18 16:55:31 2010 +0100
@@ -30,7 +30,7 @@
use Sys::Hostname;
use PFTools::Structqueries;
-use PFTools::Utils;
+use PFTools::Utils qw( make_interfaces_file );
#################################
# VARS
@@ -53,11 +53,6 @@
my $PF_CONFIG = {};
my $GLOBAL_STRUCT = {};
-my @HEADER_DEST = (
- "#################################################",
- "# File was auto-generated with mk_interfaces tool",
- "#\n",
-);
my $program = basename $PROGRAM_NAME;
@@ -99,26 +94,13 @@
|| get_uniq_site_from_hostname( $options->{'host'}, $GLOBAL_STRUCT );
}
-my $iface = Mk_interfaces(
+make_interfaces_file(
$options->{'host'},
$GLOBAL_STRUCT,
$PF_CONFIG,
- $options->{'site'}
+ $options->{'site'},
+ $options->{'output'},
);
-unless( $iface ) {
- die "Error occured during building interfaces file";
-}
-
-my $output_fh = IO::File->new( '>' . $options->{'output'} )
- or die "Unable to open file $options->{'output'} : $OS_ERROR";
-$output_fh->print( join "\n", @HEADER_DEST )
- or die "Unable to write on file $options->{'output'} : $OS_ERROR";
-foreach my $if ( @{ $iface->{'__order'} } ) {
- unless( $output_fh->print( join "\n", @{ $iface->{$if} }, "\n" ) ) {
- die "Unable to write on file $options->{'output'} : $OS_ERROR";
- }
-}
-$output_fh->close()
- or die "Unable to close file $options->{'output'} : $OS_ERROR";
exit 0;
+
diff -r fadccbca083c -r 75b485e19166 sbin/mk_resolvconf
--- a/sbin/mk_resolvconf Wed Nov 17 11:07:02 2010 +0100
+++ b/sbin/mk_resolvconf Thu Nov 18 16:55:31 2010 +0100
@@ -28,7 +28,7 @@
use Sys::Hostname;
use PFTools::Structqueries;
-use PFTools::Utils;
+use PFTools::Utils qw( make_resolv_conf_file );
#################################
# VARS
@@ -93,7 +93,7 @@
}
unless(
- Mk_resolvconf(
+ make_resolv_conf_file(
$options->{'host'},
$GLOBAL_STRUCT,
$options->{'site'},
diff -r fadccbca083c -r 75b485e19166 sbin/mk_sitezone
--- a/sbin/mk_sitezone Wed Nov 17 11:07:02 2010 +0100
+++ b/sbin/mk_sitezone Thu Nov 18 16:55:31 2010 +0100
@@ -26,7 +26,7 @@
use Getopt::Long qw( :config ignore_case_always bundling );
use IO::File;
-use PFTools::Utils;
+use PFTools::Utils qw( make_zone_for_site );
#################################
# VARS
@@ -91,7 +91,7 @@
die "Site $options->{'site'} is not defined into global configuration";
}
-my $zone = Mk_zone_for_site(
+my $zone = make_zone_for_site(
$GLOBAL_STRUCT->{'SITE'}->{'BY_NAME'}->{$options->{'site'}}->{'zone'},
$options->{'site'},
$GLOBAL_STRUCT
diff -r fadccbca083c -r 75b485e19166 t/20.zone.t
--- a/t/20.zone.t Wed Nov 17 11:07:02 2010 +0100
+++ b/t/20.zone.t Thu Nov 18 16:55:31 2010 +0100
@@ -10,7 +10,7 @@
use Test::More qw( no_plan );
use PFTools::Conf;
-use PFTools::Utils;
+use PFTools::Utils qw( /^./ ); # import @EXPORT and @EXPORT_OK
# Let's go back to our test configuration
# FIXME: this depends on t/13.conf.t, but it probably should not.
@@ -92,47 +92,47 @@
########################################################################
-note('Testing PFTools::Utils::Mk_zone_for_site');
-can_ok( 'PFTools::Utils', qw( Mk_zone_for_site ) );
+note('Testing PFTools::Utils::make_zone_for_site');
+can_ok( 'PFTools::Utils', qw( make_zone_for_site ) );
-throws_ok { Mk_zone_for_site(); }
+throws_ok { make_zone_for_site(); }
qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] zone_name }xms
=> q{Dies if empty $zone_name};
-throws_ok { Mk_zone_for_site( {} ); }
+throws_ok { make_zone_for_site( {} ); }
qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] [\$] zone_name }xms
=> q{Dies if non-scalar $zone_name};
-throws_ok { Mk_zone_for_site( q{name} ); }
+throws_ok { make_zone_for_site( q{name} ); }
qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] site_name }xms
=> q{Dies if empty $site_name};
-throws_ok { Mk_zone_for_site( q{name}, {} ); }
+throws_ok { make_zone_for_site( q{name}, {} ); }
qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] [\$] site_name }xms
=> q{Dies if non-scalar $site_name};
-throws_ok { Mk_zone_for_site( q{name}, q{site} ); }
+throws_ok { make_zone_for_site( q{name}, q{site} ); }
qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] global_config }xms
=> q{Dies if empty $global_config};
-throws_ok { Mk_zone_for_site( q{name}, q{site}, q{ref} ); }
+throws_ok { make_zone_for_site( q{name}, q{site}, q{ref} ); }
qr{ \A ERROR: [ ] Invalid [ ] non-hashref [ ] [\$] global_config }xms
=> q{Dies if non-hashref $global_config};
-throws_ok { Mk_zone_for_site( q{name}, q{site}, {} ); }
+throws_ok { make_zone_for_site( q{name}, q{site}, {} ); }
qr{ \A ERROR: [ ] Invalid [ ] [\$] global_config [ ] hashref:
[ ] no [ ] 'ZONE' [ ] key [ ] found }xms
=> q{Dies if non-config hashref $global_config};
-throws_ok { Mk_zone_for_site( q{name}, q{site}, $global_config ); }
+throws_ok { make_zone_for_site( q{name}, q{site}, $global_config ); }
qr{ \A ERROR: [ ] Unknown [ ] zone_name: [ ] }xms
=> q{Dies if unknown zone_name};
-throws_ok { Mk_zone_for_site( q{private}, q{site}, $global_config ); }
+throws_ok { make_zone_for_site( q{private}, q{site}, $global_config ); }
qr{ \A ERROR: [ ] Unknown [ ] site_name: [ ] }xms
=> q{Dies if unknown site_name};
-$result = Mk_zone_for_site( q{private}, q{cbv4-pfds}, $global_config );
+$result = make_zone_for_site( q{private}, q{cbv4-pfds}, $global_config );
$expected_result = [
';;',
';; BIND configuration file for zone: private',
@@ -247,56 +247,56 @@
########################################################################
-note('Testing PFTools::Utils::Mk_resolvconf');
-can_ok( 'PFTools::Utils', qw( Mk_resolvconf ) );
+note('Testing PFTools::Utils::make_resolv_conf_file');
+can_ok( 'PFTools::Utils', qw( make_resolv_conf_file ) );
-throws_ok { Mk_resolvconf(); }
+throws_ok { make_resolv_conf_file(); }
qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] hostname }xms
=> q{Dies if empty $hostname};
-throws_ok { Mk_resolvconf( {} ); }
+throws_ok { make_resolv_conf_file( {} ); }
qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] [\$] hostname }xms
=> q{Dies if non-scalar $hostname};
-throws_ok { Mk_resolvconf( q{hostname} ); }
+throws_ok { make_resolv_conf_file( q{hostname} ); }
qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] global_config }xms
=> q{Dies if empty $global_config};
-throws_ok { Mk_resolvconf( q{hostname}, q{global_config} ); }
+throws_ok { make_resolv_conf_file( q{hostname}, q{global_config} ); }
qr{ \A ERROR: [ ] Invalid [ ] non-hashref [ ] [\$] global_config }xms
=> q{Dies if non-hashref $global_config};
-throws_ok { Mk_resolvconf( q{name}, {} ); }
+throws_ok { make_resolv_conf_file( q{name}, {} ); }
qr{ \A ERROR: [ ] Invalid [ ] [\$] global_config [ ] hashref:
[ ] no [ ] 'ZONE' [ ] key [ ] found }xms
=> q{Dies if non-config hashref $global_config};
-throws_ok { Mk_resolvconf( q{hostname}, $global_config ); }
+throws_ok { make_resolv_conf_file( q{hostname}, $global_config ); }
qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] site_name }xms
=> q{Dies if empty $site_name};
-throws_ok { Mk_resolvconf( q{hostname}, $global_config, {} ); }
+throws_ok { make_resolv_conf_file( q{hostname}, $global_config, {} ); }
qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] [\$] site_name }xms
=> q{Dies if non-scalar $site_name};
-throws_ok { Mk_resolvconf( q{hostname}, $global_config, q{site_name} ); }
+throws_ok { make_resolv_conf_file( q{hostname}, $global_config, q{site_name} ); }
qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] filename }xms
=> q{Dies if empty $filename};
-throws_ok { Mk_resolvconf( q{hostname}, $global_config, q{site_name}, {} ); }
+throws_ok { make_resolv_conf_file( q{hostname}, $global_config, q{site_name}, {} ); }
qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] [\$] filename }xms
=> q{Dies if non-scalar $filename};
-throws_ok { Mk_resolvconf( q{hostname}, $global_config, q{cbv4}, q{filename} ); }
+throws_ok { make_resolv_conf_file( q{hostname}, $global_config, q{cbv4}, q{filename} ); }
qr{ \A ERROR: [ ] Unknown [ ] hostname [ ] }xms
=> q{Dies if unknown $hostname};
-throws_ok { Mk_resolvconf( q{cbv4-spawn00}, $global_config, q{cbv4}, q{filename} ); }
+throws_ok { make_resolv_conf_file( q{cbv4-spawn00}, $global_config, q{cbv4}, q{filename} ); }
qr{ \A ERROR: [ ] Unknown [ ] hostname [ ] }xms
=> q{Dies if unknown $hostname};
my $test_resolv_conf_file = q{test.resolv.conf};
-$result = Mk_resolvconf( q{cbv4-rdeploy01}, $global_config, q{cbv4}, $test_resolv_conf_file );
+$result = make_resolv_conf_file( q{cbv4-rdeploy01}, $global_config, q{cbv4}, $test_resolv_conf_file );
ok $result => q{Returns true on success};
$result = PFTools::Utils::__read_file_in_array( $test_resolv_conf_file, 1 );
@@ -315,5 +315,93 @@
=> q{Returns the expected result for host cbv4-rdeploy01 site cbv4'}
or note explain $result;
-ok unlink($test_resolv_conf_file) => q{Removed the test-generated resolv.conf}
+ok unlink($test_resolv_conf_file)
+ => q{Removed the test-generated resolv.conf file};
+
+########################################################################
+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
+ => q{Dies if empty $hostname};
+
+throws_ok { PFTools::Utils::__build_interfaces( {} ); }
+qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] [\$] hostname }xms
+ => q{Dies if non-scalar $hostname};
+
+throws_ok { PFTools::Utils::__build_interfaces( q{hostname} ); }
+qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] global_config }xms
+ => q{Dies if empty $global_config};
+
+throws_ok { PFTools::Utils::__build_interfaces( q{hostname}, q{global_config} ); }
+qr{ \A ERROR: [ ] Invalid [ ] non-hashref [ ] [\$] global_config }xms
+ => q{Dies if non-hashref $global_config};
+
+throws_ok { PFTools::Utils::__build_interfaces( q{name}, {} ); }
+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( q{hostname}, $global_config ); }
+qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] pf_config }xms
+ => q{Dies if empty $pf_config};
+
+throws_ok { PFTools::Utils::__build_interfaces( q{hostname}, $global_config, q{pf_config} ); }
+qr{ \A ERROR: [ ] Invalid [ ] non-hashref [ ] [\$] pf_config }xms
+ => q{Dies if non-hashref $pf_config};
+
+throws_ok { PFTools::Utils::__build_interfaces( q{hostname}, $global_config, {} ); }
+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( q{hostname}, $global_config, $pf_config ); }
+qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] site_name }xms
+ => q{Dies if empty $site_name};
+
+throws_ok { PFTools::Utils::__build_interfaces( q{hostname}, $global_config, $pf_config, {} ); }
+qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] [\$] site_name }xms
+ => q{Dies if non-scalar $site_name};
+
+$result = PFTools::Utils::__build_interfaces( q{cbv4-rdeploy01}, $global_config, $pf_config, q{cbv4} );
+$expected_result = [
+ q{#},
+ q{# This file was auto-generated by mk_interfaces -- DO NOT EDIT!},
+ q{#},
+ q{},
+ q{auto lo},
+ q{iface lo inet loopback},
+ q{},
+ q{auto eth0},
+ q{iface eth0 inet static},
+ qq{\taddress\t\t10.1.167.1},
+ qq{\tnetmask\t\t255.255.0.0},
+ qq{\tnetwork\t\t10.1.0.0},
+ qq{\tbroadcast\t10.1.255.255},
+ q{},
+];
+
+is_deeply $result, $expected_result
+ => q{Returns the expected result for host cbv4-rdeploy01 site cbv4'}
+ or note explain $result;
+
+
+########################################################################
+note('Testing PFTools::Utils::make_interfaces_file');
+can_ok( 'PFTools::Utils', qw( make_interfaces_file ) );
+
+my $test_interfaces_file = q{test.interfaces};
+$result = make_interfaces_file( q{cbv4-rdeploy01}, $global_config, $pf_config, q{cbv4}, $test_interfaces_file );
+ok $result => q{Returns true on success};
+
+$result = PFTools::Utils::__read_file_in_array( $test_interfaces_file, 1 );
+
+is_deeply $result, $expected_result
+ => q{Returns the expected result for host cbv4-rdeploy01 site cbv4'}
+ or note explain $result;
+
+ok unlink($test_interfaces_file)
+ => q{Removed the test-generated interfaces file};
+
More information about the pf-tools-commits
mailing list