pf-tools/pf-tools: 5 new changesets
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Fri Oct 22 10:16:28 UTC 2010
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/e22cbf870092
changeset: 908:e22cbf870092
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Thu Oct 21 18:26:11 2010 +0200
description:
Use oct() to correctly specify umask
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/f4e00aeee0dd
changeset: 909:f4e00aeee0dd
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Thu Oct 21 18:41:08 2010 +0200
description:
Style
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/f5336eb79bec
changeset: 910:f5336eb79bec
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Thu Oct 21 18:48:16 2010 +0200
description:
More "return unless" -> croak() conversions.
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/13f3753a223a
changeset: 911:13f3753a223a
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Fri Oct 22 12:09:48 2010 +0200
description:
Bugfix: Init_PF_CONFIG() allways reinitialized $PF_CONFIG to the default
configuration if no $config_file was specified, instead of returning the
current $PF_CONFIG.
New function: reset_pf_config()
Style: Get_hosttype_from_hostname() croaks instead of returning nothing for
unknown hostnames.
Style: Get_host_config_from_CONFIG() croaks on more error cases.
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/c85304f3069d
changeset: 912:c85304f3069d
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Fri Oct 22 12:13:37 2010 +0200
description:
Remove dead debug code.
diffstat:
2 files changed, 4 insertions(+), 3 deletions(-)
t/12.storable.t | 5 +++--
t/13.conf.t | 2 +-
diffs (771 lines):
diff -r f042e7c5d7f3 -r c85304f3069d lib/PFTools/Conf.pm
--- a/lib/PFTools/Conf.pm Thu Oct 21 14:54:45 2010 +0200
+++ b/lib/PFTools/Conf.pm Fri Oct 22 12:13:37 2010 +0200
@@ -54,6 +54,7 @@
Get_config_for_hostname_on_site
get_default_pf_config
get_current_pf_config
+ reset_pf_config
);
our @EXPORT_OK = qw();
@@ -69,14 +70,7 @@
=head1 INTERFACE
-This module defines the following variables and functions:
-
-=head2 $PF_CONFIG
-
-This hash describes the default configuration. Each key can be overrided from
-the configuration file (the default configuration file is /etc/pf-tools.conf).
-
-FIXME documentation!
+This module defines the following functions:
=cut
@@ -147,7 +141,12 @@
=head2 get_default_pf_config()
-Returns the default (and read-only) pf_config.
+Returns the default (and read-only) pf_config (internally stored in
+$DEFAULT_PF_CONFIG). It is a hash describing the default configuration. Each
+element can be overrided from the configuration file (the default
+configuration file is /etc/pf-tools.conf).
+
+FIXME document the default configuration itself
=cut
@@ -157,12 +156,25 @@
=head2 get_current_pf_config()
-Returns the current (and writable) pf_config.
+Returns the current (and writable) pf_config (internally stored in
+$PF_CONFIG). This hash is initialized from the default configuration and
+further modified by Load_conf().
=cut
sub get_current_pf_config {
return $PF_CONFIG;
+}
+
+=head2 reset_pf_config()
+
+Resets the current pf_config, so that is can be reinitialized to the default
+configuration.
+
+=cut
+
+sub reset_pf_config {
+ $PF_CONFIG = {};
}
=head2 Subst_vars( $text, $variables_ref )
@@ -198,9 +210,17 @@
sub Init_PF_CONFIG {
my ($config_file) = @_;
- $PF_CONFIG = clone($DEFAULT_PF_CONFIG);
+ # Initialize $PF_CONFIG with the default configuration if it is empty
+ # (that means it had not been initialized yet)
+ unless ( keys %{ $PF_CONFIG } ) {
+ $PF_CONFIG = clone($DEFAULT_PF_CONFIG);
+ }
- return $PF_CONFIG unless $config_file;
+ # Return the current (possibly default) configuration if no config_file
+ # was specified
+ unless ( $config_file ) {
+ return $PF_CONFIG;
+ }
unless ( -e $config_file ) {
croak qq{ERROR: $config_file: no such file};
@@ -209,17 +229,23 @@
my $st = stat $config_file;
# FIXME also check that $uid == 0 && $gid == 0 ?
- unless ( S_IMODE($st->mode) == 0600 and S_ISREG($st->mode) ) {
+ unless ( S_IMODE( $st->mode ) == 0600 and S_ISREG( $st->mode ) ) {
croak
qq{ERROR: weak rights for $config_file (check owner/group/mode)};
}
my $conf_parsed = parse_ini($config_file);
+ # Reset $PF_CONFIG to the default configuration, then update it from the
+ # parsed config_file.
+ # NOTE: Only update known sections and keys.
+ $PF_CONFIG = clone($DEFAULT_PF_CONFIG);
foreach my $section ( keys %{$DEFAULT_PF_CONFIG} ) {
next if !defined $conf_parsed->{$section};
+
foreach my $key ( keys %{ $DEFAULT_PF_CONFIG->{$section} } ) {
next if !defined $conf_parsed->{$section}->{$key};
+
$PF_CONFIG->{$section}->{$key} = $conf_parsed->{$section}->{$key};
}
}
@@ -229,10 +255,10 @@
=head2 Init_SUBST( $hostname, $host_type, $pf_config, $domainname )
-Initialize a hash structure with all the substitution variables needed
-to handle $hostname (default: the local host).
+Initializes a hash structure with all the substitution variables needed to
+handle $hostname (default: the local host).
-FIXME document the variables
+FIXME document the available variables
=cut
@@ -282,13 +308,13 @@
=head2 Get_source( $source, $hostname, $hash_subst, $pf_config )
-If $source is defined, resolve macros and variables found in $source and return
-the result.
+If $source is defined, resolves macros and variables found in $source and
+returns the result.
Optional parameters $hostname, $hash_subst and $pf_config will be computed if
not specified.
-FIXME document the macros
+FIXME document the available macros
The variables are defined by $hash_subst (defaults to the result of
Init_SUBST()). See also Subst_vars().
@@ -298,8 +324,12 @@
sub Get_source {
my ( $source, $hostname, $hash_subst, $pf_config ) = @_;
- return unless defined $source;
- return $source unless $source;
+ if ( ref $source ) {
+ croak q{ERROR: Invalid non-scalar $source};
+ }
+ if ( not $source ) {
+ croak q{ERROR: Invalid empty $source};
+ }
if ( $hash_subst and ref $hash_subst ne 'HASH' ) {
croak q{ERROR: Invalid non-href $hash_subst};
@@ -347,27 +377,32 @@
=head2 Load_conf( $file, $hash_subst, $context, $pf_config )
Reads configuration from $file in context $context.
-Returns undef if empty or undefined arguments.
-Croaks on other errors.
-FIXME add more documentation here
+FIXME add more documentation here (at least, explain $context)
=cut
sub Load_conf {
my ( $file, $hash_subst, $context, $pf_config ) = @_;
- return unless $file and $hash_subst and $context and $pf_config;
-
if ( ref $file ) {
croak q{ERROR: Invalid non-scalar $file};
}
+ if ( not $file ) {
+ croak q{ERROR: Invalid empty $file};
+ }
+
+ if ( ref $hash_subst ne 'HASH' ) {
+ croak q{ERROR: Invalid non-hashref $hash_subst};
+ }
+
if ( ref $context ) {
croak q{ERROR: Invalid non-scalar $context};
}
- if ( ref $hash_subst ne 'HASH' ) {
- croak q{ERROR: Invalid non-hashref $hash_subst};
+ if ( not $context ) {
+ croak q{ERROR: Invalid empty $context};
}
+
if ( ref $pf_config ne 'HASH' ) {
croak q{ERROR: Invalid non-hashref $pf_config};
}
@@ -464,16 +499,18 @@
sub Init_GLOBAL_NETCONFIG {
my ( $start_file, $hash_subst, $pf_config ) = @_;
- return unless $start_file and $hash_subst;
-
- $pf_config ||= $PF_CONFIG; # default
-
if ( ref $start_file ) {
croak q{ERROR: Invalid non-scalar $start_file};
}
+ if ( not $start_file ) {
+ croak q{ERROR: Invalid empty $start_file};
+ }
+
if ( ref $hash_subst ne 'HASH' ) {
croak q{ERROR: Invalid non-hashref $hash_subst};
}
+
+ $pf_config ||= $PF_CONFIG; # default
if ( ref $pf_config ne 'HASH' ) {
croak q{ERROR: Invalid non-hashref $pf_config};
}
@@ -494,7 +531,7 @@
my $net_parsed
= Load_conf( $start_file, $hash_subst, 'network', $pf_config );
my @sortnetkeys
- = sort { __Sort_net_section( $net_parsed, $a, $b ) }
+ = sort { __sort_net_section( $net_parsed, $a, $b ) }
@{ $net_parsed->{'__sections_order'} };
foreach my $section (@sortnetkeys) {
if ( $net_parsed->{$section}->{'type'} eq 'zone' ) {
@@ -564,9 +601,18 @@
sub Flush2disk_GLOBAL {
my ( $global_config, $pf_config, $flush_file ) = @_;
- return unless $global_config and $pf_config;
+ if ( ref $global_config ne 'HASH' ) {
+ croak q{ERROR: Invalid non-hashref $global_config};
+ }
+
+ if ( ref $pf_config ne 'HASH' ) {
+ croak q{ERROR: Invalid non-hashref $pf_config};
+ }
$flush_file ||= $pf_config->{'path'}->{'global_struct'};
+ if ( ref $flush_file ) {
+ croak q{ERROR: Invalid non-scalar $flush_file};
+ }
my $ret = eval { store( $global_config, $flush_file ); };
if ($EVAL_ERROR) {
@@ -588,7 +634,12 @@
sub Retrieve_GLOBAL {
my ($path_global_file) = @_;
- return unless $path_global_file;
+ if ( ref $path_global_file ) {
+ croak q{ERROR: Invalid non-scalar $path_global_file};
+ }
+ if ( not $path_global_file ) {
+ croak q{ERROR: Invalid empty $path_global_file};
+ }
my $ret = eval { retrieve($path_global_file); };
if ($EVAL_ERROR) {
@@ -611,29 +662,29 @@
sub Get_config_for_hostname_on_site {
my ( $hostname, $site, $hash_subst, $global_config, $pf_config ) = @_;
- if (ref $hostname) {
+ if ( ref $hostname ) {
croak q{ERROR: Invalid non-scalar $hostname};
}
- if (not $hostname) {
+ if ( not $hostname ) {
croak q{ERROR: Invalid empty or undefined $hostname};
}
- if (ref $site) {
+ if ( ref $site ) {
croak q{ERROR: Invalid non-scalar $site};
}
- if (not $site) {
+ if ( not $site ) {
croak q{ERROR: Invalid empty or undefined $site};
}
- if (ref $hash_subst ne 'HASH') {
+ if ( ref $hash_subst ne 'HASH' ) {
croak q{ERROR: Invalid non-hashref $hash_subst};
}
- if (ref $global_config ne 'HASH') {
+ if ( ref $global_config ne 'HASH' ) {
croak q{ERROR: Invalid non-hashref $global_config};
}
- if (ref $pf_config ne 'HASH') {
+ if ( ref $pf_config ne 'HASH' ) {
croak q{ERROR: Invalid non-hashref $pf_config};
}
@@ -651,10 +702,10 @@
}
# Hosttype configuration file e.g. update-<hosttype>
- my $hosttype_file = __Get_config_path( $hosttype, $pf_config, $site );
+ my $hosttype_file = __get_config_path( $hosttype, $pf_config, $site );
# Hostname configuration file e.g. update-<hostname>
- my $hostname_file = __Get_config_path( $hostname, $pf_config, $site );
+ my $hostname_file = __get_config_path( $hostname, $pf_config, $site );
foreach my $file ( $hosttype_file, $hostname_file ) {
next unless $file;
@@ -673,11 +724,11 @@
=head1 INTERNAL INTERFACE
-This module defines the following internal (not exported) variables and functions:
+This module defines the following internal (not exported) functions:
=cut
-=head2 __Get_config_path( $host_value, $pf_config, $site ) -- NOT EXPORTED
+=head2 __get_config_path( $host_value, $pf_config, $site )
Given a host value (host name or host type) and a site, returns the path to the
site-specific configuration file for this host value if it exists, or to the
@@ -688,7 +739,7 @@
=cut
-sub __Get_config_path {
+sub __get_config_path {
my ( $host_value, $pf_config, $site ) = @_;
return unless $host_value and $pf_config and $site;
@@ -713,11 +764,22 @@
return;
}
-# FIXME doc and tests
+=head2 __Merge_host_config( $hash_to_merge, $hash_subst )
+
+FIXME doc and tests
+
+=cut
+
sub __Merge_host_config {
my ( $hash_to_merge, $hash_subst ) = @_;
- return unless $hash_to_merge and $hash_subst;
+ if ( ref $hash_to_merge ne 'HASH' ) {
+ croak q{ERROR: Invalid non-hashref $hash_to_merge};
+ }
+
+ if ( ref $hash_subst ne 'HASH' ) {
+ croak q{ERROR: Invalid non-hashref $hash_subst};
+ }
my $merge = {};
if ( $hash_to_merge->{'hostgroup'}->{'__model'} ) {
@@ -745,14 +807,33 @@
$merge->{$section} = $hash_to_merge->{$section};
}
}
+
return $merge;
}
-# FIXME doc and tests
+=head2 __Merge_conf_includes( $hash_to_merge, $hash_subst, $context )
+
+FIXME doc and tests
+
+=cut
+
sub __Merge_conf_includes {
my ( $hash_to_merge, $hash_subst, $context ) = @_;
- return unless $hash_to_merge and $hash_subst and $context;
+ if ( ref $hash_to_merge ne 'HASH' ) {
+ croak q{ERROR: Invalid non-hashref $hash_to_merge};
+ }
+
+ if ( ref $hash_subst ne 'HASH' ) {
+ croak q{ERROR: Invalid non-hashref $hash_subst};
+ }
+
+ if ( ref $context ) {
+ croak q{ERROR: Invalid non-scalar $context};
+ }
+ if ( not $context ) {
+ croak q{ERROR: Invalid empty $context};
+ }
if ( $context =~ /^host|model$/ ) {
return __Merge_host_config( $hash_to_merge, $hash_subst );
@@ -808,14 +889,14 @@
return $global_parsed;
}
-=head2 __Sort_net_section( $net, $a, $b )
+=head2 __sort_net_section( $net, $a, $b )
This function is used to sort the network configuration sections by section
type. It always returns -1, 0 or 1, as every sort subroutine.
=cut
-sub __Sort_net_section {
+sub __sort_net_section {
my ( $net_parsed, $a, $b ) = @_;
return -1 unless defined $a and defined $b; # => no warnings
diff -r f042e7c5d7f3 -r c85304f3069d lib/PFTools/Structqueries.pm
--- a/lib/PFTools/Structqueries.pm Thu Oct 21 14:54:45 2010 +0200
+++ b/lib/PFTools/Structqueries.pm Fri Oct 22 12:13:37 2010 +0200
@@ -88,7 +88,7 @@
Get_hosttype_from_hostname ( $hostname, $global_config, $site )
-Returns the hosttype, or nothing.
+Returns the hosttype.
=cut
@@ -130,7 +130,7 @@
}
}
- return;
+ croak qq{ERROR: Unable to get hosttype from hostname $hostname on site } . ($site ? $site : q{});
}
#########################################################################
@@ -171,9 +171,6 @@
my ( $hostname, $global_config ) = @_;
my $hostclass = Get_hosttype_from_hostname( $hostname, $global_config );
- unless( $hostclass ) {
- croak qq{ERROR: Unable to get hosttype from unknown $hostname};
- }
my $site = Get_uniq_site_from_hostname ( $hostname, $global_config );
return $global_config->{'SITE'}->{'BY_NAME'}->{$site}->{'HOST'}
->{'BY_NAME'}->{$hostclass}->{'deployment'}
@@ -263,15 +260,19 @@
sub Get_host_config_from_CONFIG {
my ( $hostname, $global_config, $site ) = @_;
- unless( $site ) {
- $site = Get_uniq_site_from_hostname( $hostname, $global_config );
- }
+ $site ||= Get_uniq_site_from_hostname( $hostname, $global_config );
+
+ my $hosttype = Get_hosttype_from_hostname( $hostname, $global_config, $site );
+
my $site_part = $global_config->{'SITE'}->{'BY_NAME'}->{$site};
my $zone = $site_part->{'zone'};
- $hostname =~ m{\A ([^.]+)(\.([^.]+))?(\.$zone)? \Z}xms;
- my ( $hostshort, $hostvlan ) = ( $1, $3 );
- my $hosttype = Get_hosttype_from_hostname( $hostname, $global_config );
- return $site_part->{'HOST'}->{'BY_NAME'}->{$hosttype}->{$hostshort};
+ my ( $hostshort, $hostvlan ) = $hostname =~ m{\A ([^.]+)(\.([^.]+))?(\.$zone)? \Z}xms;
+ unless ($hostshort) {
+ croak qq{ERROR: Unable to get hostshort/hostvlan from hostname $hostname};
+ }
+
+ my $host_config = $site_part->{'HOST'}->{'BY_NAME'}->{$hosttype}->{$hostshort};
+ return $host_config;
}
sub Get_pkgtype_from_hostname {
@@ -316,6 +317,10 @@
sub Get_distrib_from_hostprops {
my ($host_props) = @_;
+
+ if ( ref $host_props ne 'HASH' ) {
+ croak q{ERROR: Invalid non-hashref $host_props};
+ }
return $host_props->{'deployment'}->{'distrib'};
}
diff -r f042e7c5d7f3 -r c85304f3069d lib/PFTools/VCS/CVS.pm
--- a/lib/PFTools/VCS/CVS.pm Thu Oct 21 14:54:45 2010 +0200
+++ b/lib/PFTools/VCS/CVS.pm Fri Oct 22 12:13:37 2010 +0200
@@ -64,7 +64,7 @@
}
my $ret;
- my $umask = umask( $pf_config->{'vcs'}->{'umask'} );
+ my $umask = umask( oct( $pf_config->{'vcs'}->{'umask'} ) );
$ENV{'CVS_RSH'} = $pf_config->{'vcs'}->{'rsh'}
if ( $pf_config->{'vcs'}->{'method'} eq 'rsh' );
diff -r f042e7c5d7f3 -r c85304f3069d lib/PFTools/VCS/SVN.pm
--- a/lib/PFTools/VCS/SVN.pm Thu Oct 21 14:54:45 2010 +0200
+++ b/lib/PFTools/VCS/SVN.pm Fri Oct 22 12:13:37 2010 +0200
@@ -69,7 +69,7 @@
}
my $ret;
- my $umask = umask( $pf_config->{'vcs'}->{'umask'} );
+ my $umask = umask( oct( $pf_config->{'vcs'}->{'umask'} ) );
unless ( $svn_cmd ne "" ) {
$svn_cmd
diff -r f042e7c5d7f3 -r c85304f3069d t/12.storable.t
--- a/t/12.storable.t Thu Oct 21 14:54:45 2010 +0200
+++ b/t/12.storable.t Fri Oct 22 12:13:37 2010 +0200
@@ -12,11 +12,17 @@
note('Testing PFTools::Conf::Flush2disk_GLOBAL');
-ok !defined( Flush2disk_GLOBAL() )
- => 'Returns undef if no args';
+throws_ok { Flush2disk_GLOBAL() }
+ qr{ \A ERROR: [ ] Invalid [ ] non-hashref [ ] [\$] global_config }xms
+ => q{Dies on non-hashref global_config};
-ok !defined( Flush2disk_GLOBAL(undef, undef, undef) )
- => 'Returns undef if undef args';
+throws_ok { Flush2disk_GLOBAL( {} ) }
+ qr{ \A ERROR: [ ] Invalid [ ] non-hashref [ ] [\$] pf_config }xms
+ => q{Dies on non-hashref pf_config};
+
+throws_ok { Flush2disk_GLOBAL( {}, {}, {} ) }
+ qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] [\$] flush_file }xms
+ => q{Dies on non-scalar flush_file};
my $global_config = {
some => [
@@ -62,12 +68,16 @@
qr{\A ERROR: [ ] [Cc]an't [ ] create }xms
=> 'Dies if cannot create';
+
note('Testing PFTools::Conf::Retrieve_GLOBAL');
-ok !defined( Retrieve_GLOBAL() )
- => 'Returns undef if no args';
-ok !defined( Retrieve_GLOBAL(undef) )
- => 'Returns undef if undef args';
+throws_ok { Retrieve_GLOBAL( {} ) }
+ qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] [\$] path_global_file }xms
+ => q{Dies on non-scalar flush_file};
+
+throws_ok { Retrieve_GLOBAL() }
+ qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] path_global_file }xms
+ => q{Dies on empty flush_file};
throws_ok { Retrieve_GLOBAL($store3) }
qr{\A ERROR: }xms
diff -r f042e7c5d7f3 -r c85304f3069d t/13.conf.t
--- a/t/13.conf.t Thu Oct 21 14:54:45 2010 +0200
+++ b/t/13.conf.t Fri Oct 22 12:13:37 2010 +0200
@@ -17,12 +17,12 @@
use PFTools::Structqueries;
########################################################################
-note('Testing PFTools::Conf::__Sort_net_section');
+note('Testing PFTools::Conf::__sort_net_section');
-is PFTools::Conf::__Sort_net_section(), -1
+is PFTools::Conf::__sort_net_section(), -1
=> 'Returns -1 if no arg';
-is PFTools::Conf::__Sort_net_section( {}, 'foo', 'bar' ), 0
+is PFTools::Conf::__sort_net_section( {}, 'foo', 'bar' ), 0
=> 'Returns 0 if invalid parsed_net arg';
my $parsed_net = {
@@ -34,13 +34,13 @@
},
};
-is PFTools::Conf::__Sort_net_section( $parsed_net, 'foo', 'foo' ), 0
+is PFTools::Conf::__sort_net_section( $parsed_net, 'foo', 'foo' ), 0
=> 'Returns 0 if same order';
-is PFTools::Conf::__Sort_net_section( $parsed_net, 'foo', 'bar' ), 1
+is PFTools::Conf::__sort_net_section( $parsed_net, 'foo', 'bar' ), 1
=> 'Returns 1 if inversed order';
-my @ordered = sort { PFTools::Conf::__Sort_net_section( $parsed_net, $a, $b ) } qw( foo bar baz );
+my @ordered = sort { PFTools::Conf::__sort_net_section( $parsed_net, $a, $b ) } qw( foo bar baz );
my @expected_order = qw( bar foo baz );
is_deeply \@ordered, \@expected_order
=> 'Sorts correctly';
@@ -112,6 +112,11 @@
=> 'Correctly sets $PF_CONFIG'
or note explain $current_pf_config;
+$parsed_configuration = Init_PF_CONFIG( );
+is_deeply $parsed_configuration, $expected_configuration
+ => q{Correctly returns the real configuration on subsequent implicit calls}
+ or note explain $parsed_configuration;
+
unlink $test_config_file
or die "unlink $test_config_file: $OS_ERROR";
@@ -149,8 +154,13 @@
=> qq{File $test_config_file correctly merged with the default configuration}
or note explain $parsed_configuration;
+########################################################################
+note('Testing PFTools::Conf::reset_pf_config');
+can_ok( 'PFTools::Conf', qw( reset_pf_config ) );
+
# Restore the default configuration for the other tests
-$parsed_configuration = Init_PF_CONFIG();
+reset_pf_config();
+$parsed_configuration = Init_PF_CONFIG( );
is_deeply $parsed_configuration, $default_pf_config
=> q{Correctly restores the default configuration}
or note explain $parsed_configuration;
@@ -229,24 +239,18 @@
note('Testing PFTools::Conf::Get_source');
can_ok( 'PFTools::Conf', qw( Get_source ) );
-ok !defined( Get_source() )
- => 'Returns undef if no args';
-
-ok !defined( Get_source(undef) )
- => 'Returns undef if undef string';
-
-is Get_source( q{}, {} ),
- q{}
- => 'Returns empty string if $text is empty';
+throws_ok { Get_source() }
+ qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] source }xms
+ => 'Dies if empty/undef $source';
throws_ok { Get_source( q{foo bar baz}, undef, q{non-hashref $hash_subst} ) }
-qr{ \A ERROR: [ ] Invalid [ ] non-href [ ] [\$] hash_subst }xms
+ qr{ \A ERROR: [ ] Invalid [ ] non-href [ ] [\$] hash_subst }xms
=> q{Dies on non-hashref $hash_subst};
throws_ok {
Get_source( q{foo bar baz}, undef, undef, q{non-hashref $pf_config} );
}
-qr{ \A ERROR: [ ] Invalid [ ] non-href [ ] [\$] pf_config }xms
+ qr{ \A ERROR: [ ] Invalid [ ] non-href [ ] [\$] pf_config }xms
=> q{Dies on non-hashref $pf_config};
throws_ok {
@@ -319,21 +323,21 @@
=> q{Good result for CONFIG:};
########################################################################
-note('Testing PFTools::Conf::__Get_config_path');
-can_ok( 'PFTools::Conf', qw( __Get_config_path ) );
+note('Testing PFTools::Conf::__get_config_path');
+can_ok( 'PFTools::Conf', qw( __get_config_path ) );
-ok !defined PFTools::Conf::__Get_config_path()
+ok !defined PFTools::Conf::__get_config_path()
=> 'Returns undef if no args';
-throws_ok { PFTools::Conf::__Get_config_path( { foo => 'bar' }, { pf => 'config' }, 'site' ) }
+throws_ok { PFTools::Conf::__get_config_path( { foo => 'bar' }, { pf => 'config' }, 'site' ) }
qr{ \A ERROR: }xms
=> q{Dies if non-scalar $host_value};
-throws_ok { PFTools::Conf::__Get_config_path( 'host_value', { pf => 'config' }, { foo => 'bar' } ) }
+throws_ok { PFTools::Conf::__get_config_path( 'host_value', { pf => 'config' }, { foo => 'bar' } ) }
qr{ \A ERROR: }xms
=> q{Dies if non-scalar $site};
-throws_ok { PFTools::Conf::__Get_config_path( 'host_value', 'pf_config', 'site' ) }
+throws_ok { PFTools::Conf::__get_config_path( 'host_value', 'pf_config', 'site' ) }
qr{ \A ERROR: }xms
=> q{Dies if non-href $pf_config};
@@ -347,7 +351,7 @@
},
};
my $pf_config = clone_merge( $default_pf_config, $pf_config_overrides );
-ok !defined PFTools::Conf::__Get_config_path( 'unknown-host', $pf_config, 'unknown-site' )
+ok !defined PFTools::Conf::__get_config_path( 'unknown-host', $pf_config, 'unknown-site' )
=> q{Returns undef if no matching file found};
make_path( qw(
@@ -366,13 +370,13 @@
$fh->close
or die "close $site_config_file: $OS_ERROR";
-is PFTools::Conf::__Get_config_path( 'mytest', $pf_config, 'test-site' ),
+is PFTools::Conf::__get_config_path( 'mytest', $pf_config, 'test-site' ),
$site_config_file
=> q{Returns the site specific file if it exists};
my $global_config_file = q{/tmp/pftools-conf-test/checkout_dir/config/CONFIG/update-mytest};
move( $site_config_file, $global_config_file );
-is PFTools::Conf::__Get_config_path( 'mytest', $pf_config, 'test-site' ),
+is PFTools::Conf::__get_config_path( 'mytest', $pf_config, 'test-site' ),
$global_config_file
=> q{Returns the global file if no site-specific file found};
unlink $global_config_file;
@@ -383,17 +387,13 @@
note('Testing PFTools::Conf::Load_conf');
can_ok( 'PFTools::Conf', qw( Load_conf ) );
-ok !defined Load_conf()
- => 'Returns undef if no args';
+throws_ok { Load_conf() }
+ qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] file }xms
+ => q{Dies if empty $file};
-ok !defined Load_conf( 'file' )
- => 'Returns undef if only one arg';
-
-ok !defined Load_conf( 'file', {} )
- => 'Returns undef if only two args';
-
-ok !defined Load_conf( 'file', {}, 'context' )
- => 'Returns undef if only three args';
+throws_ok { Load_conf( 'file', {} ) }
+ qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] context }xms
+ => q{Dies if empty $context};
throws_ok { Load_conf( {}, {}, 'context', {} ) }
qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] [\$] file }xms
@@ -706,13 +706,11 @@
note('Testing PFTools::Conf::Init_GLOBAL_NETCONFIG');
can_ok( 'PFTools::Conf', qw( Init_GLOBAL_NETCONFIG ) );
-ok !defined Init_GLOBAL_NETCONFIG()
- => 'Returns undef if no args';
+throws_ok { Init_GLOBAL_NETCONFIG() }
+ qr{ \A ERROR: [ ] Invalid [ ] empty [ ] [\$] start_file }xms
+ => q{Dies if empty $start_file};
-ok !defined Init_GLOBAL_NETCONFIG( 'start_file' )
- => 'Returns undef if only one arg';
-
-throws_ok { Init_GLOBAL_NETCONFIG( {}, {} ) }
+throws_ok { Init_GLOBAL_NETCONFIG( {} ) }
qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] [\$] start_file }xms
=> q{Dies if non-scalar $start_file};
@@ -1208,19 +1206,23 @@
qr{ \A ERROR: [ ] Invalid [ ] non-hashref [ ] [\$] global_config }xms
=> q{Dies if non-hashref $global_config};
-# $site is optional
-lives_ok { Get_hosttype_from_hostname( 'hostname', {} ) }
- 'OK if no $site';
-
throws_ok { Get_hosttype_from_hostname( 'hostname', {}, {} ) }
qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] [\$] site }xms
=> q{Dies if non-scalar $site};
+
+throws_ok { Get_hosttype_from_hostname( 'hostname', {} ) }
+ qr{ \A ERROR: [ ] Unable [ ] to [ ] get [ ] hosttype [ ] from [ ] hostname }xms
+ => q{Dies if unknown hostname};
$parsed_configuration = Get_hosttype_from_hostname( 'cbv4-spawn00',
$global_config, 'cbv4-pfds' );
is $parsed_configuration, q{cbv4-spawn}
=> q{Returns the correct hosttype}
or diag explain $parsed_configuration;
+
+# $site is optional
+lives_ok { Get_hosttype_from_hostname( 'cbv4-spawn00', $global_config ) }
+ 'OK if no $site';
########################################################################
More information about the pf-tools-commits
mailing list