pf-tools/pf-tools: 2 new changesets

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Sun Sep 19 20:27:22 UTC 2010


details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/14c459002b4b
changeset: 785:14c459002b4b
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Sun Sep 19 22:11:51 2010 +0200
description:
Tests __Get_config_path()

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/b71a9ddb3137
changeset: 786:b71a9ddb3137
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Sun Sep 19 22:26:59 2010 +0200
description:
"make test" passes on both sid and lucid

The error message in Storable is "Can't create file" in sid,
but "can't create file" in Lucid => accept both.

diffstat:

3 files changed, 12 insertions(+), 4 deletions(-)
lib/PFTools/Conf.pm |   12 ++++++++++--
t/12.storable.t     |    2 +-
t/13.conf.t         |    2 +-

diffs (290 lines):

diff -r ab95d15f8a51 -r b71a9ddb3137 lib/PFTools/Conf.pm
--- a/lib/PFTools/Conf.pm	Sun Sep 19 01:23:40 2010 +0200
+++ b/lib/PFTools/Conf.pm	Sun Sep 19 22:26:59 2010 +0200
@@ -53,8 +53,28 @@
 
 our @EXPORT_OK = qw();
 
-#############################################################
-### Default value for configuration with new method
+=head1 NAME
+
+PFTools::Conf - PF-Tools Configuration handling
+
+=head1 DESCRIPTION
+
+This module exports functions handling the reading and parsing of the
+configuration files.
+
+=head1 INTERFACE
+
+This modules 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!
+
+=cut
+
 our $PF_CONFIG = {
     'path' => {
         'status_dir'     => '/var/lib/pftools',
@@ -118,7 +138,7 @@
     },
 };
 
-=head2 Subst_vars( $text, $variables_ref)
+=head2 Subst_vars( $text, $variables_ref )
 
 If $text is empty or undefined, just return it.
 If $variables_ref is not a valid hash reference, just return $text.
@@ -195,12 +215,12 @@
 sub Init_SUBST {
     my ( $hostname, $hosttype, $pf_config, $domainname ) = @_;
 
-    $hostname   ||= hostname;
+    $hostname ||= hostname;
 
     if ( $pf_config and ref $pf_config ne 'HASH' ) {
         croak q{ERROR: Invalid non-href $pf_config};
     }
-    $pf_config  ||= Init_PF_CONFIG();
+    $pf_config ||= Init_PF_CONFIG();
 
     $domainname ||= $pf_config->{'location'}->{'zone'} || hostdomain || q{};
 
@@ -257,7 +277,7 @@
     return $source unless $source;
 
     if ( $hash_subst and ref $hash_subst ne 'HASH' ) {
-	croak q{ERROR: Invalid non-href $hash_subst};
+        croak q{ERROR: Invalid non-href $hash_subst};
     }
 
     unless ($hash_subst) {
@@ -267,8 +287,9 @@
         $pf_config = $PF_CONFIG;
     }
 
-    my $vcs_work_dir = $pf_config->{'path'}->{'checkout_dir'};
-    my $module       = $pf_config->{'vcs'}->{'module'};
+    my $vcs_work_dir = $pf_config->{'path'}->{'checkout_dir'}
+        || q{};    # FIXME croak?
+    my $module = $pf_config->{'vcs'}->{'module'} || q{};    # FIXME croak?
 
     my $result = $source;
 
@@ -296,25 +317,38 @@
     return $result;
 }
 
+=head2 __Get_config_path( $host_value, $pf_config, $site ) -- NOT EXPORTED
+
+Given a host value (host name or host type) and a site, returns the path to the
+site-specific configuration file this host value if it exists, or to the
+non-site-specific configuration file for this host value if it exists.
+
+Returns an undefined value on invalid arguments or if no suitable find was
+found.
+
+=cut
+
 sub __Get_config_path {
-    my ( $hostvalue, $pf_config, $site ) = @_;
+    my ( $host_value, $pf_config, $site ) = @_;
 
-    return unless $hostvalue and $pf_config and $site;
+    return unless $host_value and $pf_config and $site;
+    if ( ref $host_value or ref $site ) {
+        croak q{ERROR: Invalid non-scalar value for $host_value or $site};
+    }
+    if ( ref $pf_config ne 'HASH' ) {
+        croak q{ERROR: Invalid non-hashref value for $pf_config};
+    }
 
-    my $site_conf_file = Get_source(
-        "CONFSITE_${site}:/update-${hostvalue}",
-        $hostvalue, {}, $pf_config
+    my @sources = (
+        "CONFSITE_${site}:/update-${host_value}",
+        "CONFIG:/update-${host_value}",
     );
-    return $site_conf_file
-        if -e $site_conf_file;
 
-    my $default_conf_file
-        = Get_source(
-        "CONFIG:/update-${hostvalue}", $hostvalue, {},
-        $pf_config
-        );
-    return $default_conf_file
-        if -e $default_conf_file;
+    foreach my $source (@sources) {
+        my $file = Get_source( $source, $host_value, {}, $pf_config );
+        return $file
+            if -e $file;
+    }
 
     return;
 }
diff -r ab95d15f8a51 -r b71a9ddb3137 t/12.storable.t
--- a/t/12.storable.t	Sun Sep 19 01:23:40 2010 +0200
+++ b/t/12.storable.t	Sun Sep 19 22:26:59 2010 +0200
@@ -57,9 +57,9 @@
     => 'Stores something in explicit path even if empty $pf_config';
 
 throws_ok { Flush2disk_GLOBAL($global_config, $pf_config, $store3) }
-    qr{\A ERROR: [ ] Can't [ ] create }xms
+    # "Can't" case differs for some versions of Perl
+    qr{\A ERROR: [ ] [Cc]an't [ ] create }xms
     => 'Dies if cannot create';
-
 
 note('Testing PFTools::Conf::Retrieve_GLOBAL');
 ok !defined( Retrieve_GLOBAL() )
diff -r ab95d15f8a51 -r b71a9ddb3137 t/13.conf.t
--- a/t/13.conf.t	Sun Sep 19 01:23:40 2010 +0200
+++ b/t/13.conf.t	Sun Sep 19 22:26:59 2010 +0200
@@ -21,10 +21,10 @@
 # FIXME add a more complex/complete test
 my $parsed_net = {
     foo => {
-	type => 'server',
+        type => 'server',
     },
     bar => {
-	type => 'network',
+        type => 'network',
     },
 };
 
@@ -73,8 +73,8 @@
 
 my $test_configuration = {
     debian => {
-	# fake => 'value', # this one ignored: unknown key
-	preseed => 'mypreseed',
+        # fake => 'value', # this one ignored: unknown key
+        preseed => 'mypreseed',
     },
 };
 
@@ -119,43 +119,43 @@
 # FIXME: add real tests for HOSTCLUSTER et HOSTNODEINDEX
 my $expected_subst_for = {
     'abv1-ncdn-lvs00' => {
-	'HOSTMINUTE' => 0,
-	'HOSTDIGITS' => '00',
-	'HOSTNUM' => 0,
-	'HOSTNAME' => 'abv1-ncdn-lvs00',
-	'HOSTNODEINDEX' => '',
-	'DOMAINNAME' => 'private',
-	'OS_RELEASE' => $os_release,
-	'HOSTHOUR' => 0,
-	'HOSTTYPE' => 'abv1-ncdn-lvs',
-	'HOSTCLUSTER' => '00',
-	'POPNAME' => 'abv1'
+        'HOSTMINUTE' => 0,
+        'HOSTDIGITS' => '00',
+        'HOSTNUM' => 0,
+        'HOSTNAME' => 'abv1-ncdn-lvs00',
+        'HOSTNODEINDEX' => '',
+        'DOMAINNAME' => 'private',
+        'OS_RELEASE' => $os_release,
+        'HOSTHOUR' => 0,
+        'HOSTTYPE' => 'abv1-ncdn-lvs',
+        'HOSTCLUSTER' => '00',
+        'POPNAME' => 'abv1'
     },
     'cor1-spawn00' => {
-	'HOSTMINUTE' => 0,
-	'HOSTDIGITS' => '00',
-	'HOSTNUM' => 0,
-	'HOSTNAME' => 'cor1-spawn00',
-	'HOSTNODEINDEX' => '',
-	'DOMAINNAME' => 'private',
-	'OS_RELEASE' => $os_release,
-	'HOSTHOUR' => 0,
-	'HOSTTYPE' => 'cor1-spawn',
-	'HOSTCLUSTER' => '00',
-	'POPNAME' => 'cor1'
+        'HOSTMINUTE' => 0,
+        'HOSTDIGITS' => '00',
+        'HOSTNUM' => 0,
+        'HOSTNAME' => 'cor1-spawn00',
+        'HOSTNODEINDEX' => '',
+        'DOMAINNAME' => 'private',
+        'OS_RELEASE' => $os_release,
+        'HOSTHOUR' => 0,
+        'HOSTTYPE' => 'cor1-spawn',
+        'HOSTCLUSTER' => '00',
+        'POPNAME' => 'cor1'
     },
     'cor1-spawn01' => {
-	'HOSTMINUTE' => 1,
-	'HOSTDIGITS' => '01',
-	'HOSTNUM' => 1,
-	'HOSTNAME' => 'cor1-spawn01',
-	'HOSTNODEINDEX' => '',
-	'DOMAINNAME' => 'private',
-	'OS_RELEASE' => $os_release,
-	'HOSTHOUR' => 1,
-	'HOSTTYPE' => 'cor1-spawn',
-	'HOSTCLUSTER' => '01',
-	'POPNAME' => 'cor1'
+        'HOSTMINUTE' => 1,
+        'HOSTDIGITS' => '01',
+        'HOSTNUM' => 1,
+        'HOSTNAME' => 'cor1-spawn01',
+        'HOSTNODEINDEX' => '',
+        'DOMAINNAME' => 'private',
+        'OS_RELEASE' => $os_release,
+        'HOSTHOUR' => 1,
+        'HOSTTYPE' => 'cor1-spawn',
+        'HOSTCLUSTER' => '01',
+        'POPNAME' => 'cor1'
     },
 };
 
@@ -163,8 +163,8 @@
     # we must fake the 'private' domainname
     my $got = Init_SUBST($hostname, undef, undef, 'private');
     is_deeply $got, $expected_subst_for->{$hostname}
-	=> qq{Returns the correct information for host $hostname}
-	or note explain $got;
+        => qq{Returns the correct information for host $hostname}
+        or note explain $got;
 }
 
 ########################################################################
@@ -245,4 +245,27 @@
     q{/var/lib/cvsguest/config/GLOBAL/my/path/to/file}
     => q{Good result for CONFIG:};
 
+########################################################################
+note('Testing PFTools::Conf::__Get_config_path');
+can_ok( 'PFTools::Conf', qw( __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' ) }
+    qr{ \A ERROR: }xms
+    => q{Dies if non-scalar $host_value};
+
+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' ) }
+    qr{ \A ERROR: }xms
+    => q{Dies if non-href $pf_config};
+
+ok !defined PFTools::Conf::__Get_config_path( 'unknown-host', {}, 'unknown-site' )
+    => q{Returns undef if no matching file found};
+
+diag( 'FIXME: add the two good cases!' );
+



More information about the pf-tools-commits mailing list