pf-tools/pf-tools: 4 new changesets

parmelan-guest at users.alioth.debian.org parmelan-guest at users.alioth.debian.org
Tue Oct 25 20:24:55 UTC 2011


details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/a96f39e901ec
changeset: 1173:a96f39e901ec
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Thu Oct 13 14:45:27 2011 +0200
description:
Finish tests for get_host_config()

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/aaf14aa6b337
changeset: 1174:aaf14aa6b337
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Thu Oct 13 14:52:16 2011 +0200
description:
Add tests for get_mode_from_host_ref

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/492b43b9c89a
changeset: 1175:492b43b9c89a
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Thu Oct 13 14:58:08 2011 +0200
description:
Add tests for get_pkgtype_from_hostname()

details:   http://hg.debian.org/hg/pf-tools/pf-tools/rev/f5200d50f352
changeset: 1176:f5200d50f352
user:      Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date:      Thu Oct 13 15:09:40 2011 +0200
description:
Add tests for get_site_list_from_hostname()

diffstat:

 lib/PFTools/Structqueries.pm |    8 ++
 t/13.conf.t                  |  126 ++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 128 insertions(+), 6 deletions(-)

diffs (170 lines):

diff -r c2a3bab3aa84 -r f5200d50f352 lib/PFTools/Structqueries.pm
--- a/lib/PFTools/Structqueries.pm	Mon Mar 07 17:18:58 2011 +0100
+++ b/lib/PFTools/Structqueries.pm	Thu Oct 13 15:09:40 2011 +0200
@@ -293,6 +293,10 @@
 sub get_mode_from_host_ref {
     my ($host_ref) = @_;
 
+    if ( ref $host_ref ne 'HASH' ) {
+        croak q{ERROR: Invalid non-hash reference host_ref};
+    }
+
     return $host_ref->{'deployment'}->{'mode'};
 }
 
@@ -422,6 +426,10 @@
 
     @site_list = uniq @site_list;
 
+    if ( not @site_list ) {
+        croak qq{ERROR: Unknown hostname '$hostname'};
+    }
+
     return \@site_list;
 }
 
diff -r c2a3bab3aa84 -r f5200d50f352 t/13.conf.t
--- a/t/13.conf.t	Mon Mar 07 17:18:58 2011 +0100
+++ b/t/13.conf.t	Thu Oct 13 15:09:40 2011 +0200
@@ -1981,7 +1981,7 @@
     => q{Correct result for cbv4-rdeploy01}
     or note explain \@result;
 
-my $host_ref = get_host_config( q{cbv4-spawn01}, $global_config, q{cbv4-pfds} );
+$host_ref = get_host_config( q{cbv4-spawn01}, $global_config, q{cbv4-pfds} );
 @result = get_cmdline_from_host_ref($host_ref);
 @expected_result = ( q{}, q{bonding.mode=active-backup bonding.miimon=100} );
 is_deeply \@result, \@expected_result
@@ -2062,13 +2062,127 @@
 qr{ \A ERROR: [ ] Unknown [ ] hostname [ ] 'hostname' [ ] }xms
     => q{Unknown hostname};
 
-#$result = get_host_config( q{cbv4-rdeploy01}, $global_config, q{cbv4} );
-#$expected_result = q{lenny};
+$result = get_host_config( q{cbv4-rdeploy01}, $global_config, q{cbv4} );
+$expected_result = {
+    'boot' => {
+        'cmdline'     => 'pci=bfsort',
+        'console'     => 'default',
+        'kernel'      => 'vmlinuz-2.6.26.5-universal-grm2.1.12',
+        'kerneluml'   => 'linux-uml-elf-2.4.26-gr1.9.15',
+        'pxefilename' => 'pxelinux.0',
+    },
+    'deployment' => {
+        'arch'           => 'amd64',
+        'dhcpvlan'       => 'vlan-systeme',
+        'distrib'        => 'lenny',
+        'hostname_model' => 'cbv4-rdeploy%%',
+        'hosttype'       => 'cbv4-rdeploy',
+        'mode'           => 'debian',
+        'order'          => '1',
+    },
+    'dns' => {
+        'resolver' => 'nsprivate.private',
+    },
+    'interfaces' => {
+        'eth0' => {
+            'ipv4' => '10.1.167.1/16',
+            'mac'  => '00:1e:c9:ff:42:0b',
+            'vlan' => 'vlan-systeme',
+        },
+    },
+};
 
-#is $result, $expected_result
-#    => q{cbv4-rdeploy01}
-#    or diag explain $result;
+is_deeply $result, $expected_result
+    => q{cbv4-rdeploy01}
+    or diag explain $result;
 
+########################################################################
+note('Testing PFTools::Structqueries::get_mode_from_host_ref');
+can_ok( 'PFTools::Structqueries', qw( get_mode_from_host_ref ) );
+
+throws_ok { get_mode_from_host_ref(); }
+qr{ \A ERROR: [ ] Invalid [ ] non-hash [ ] reference [ ] host_ref }xms
+    => 'No argument';
+
+$host_ref = get_host_config( q{cbv4-rdeploy01}, $global_config, q{cbv4} );
+$result = get_mode_from_host_ref($host_ref);
+$expected_result = q{debian};
+
+is $result, $expected_result
+    => q{cbv4-rdeploy01}
+    or diag explain $result;
+
+########################################################################
+note('Testing PFTools::Structqueries::get_pkgtype_from_hostname');
+can_ok( 'PFTools::Structqueries', qw( get_pkgtype_from_hostname ) );
+
+ at args = ();
+throws_ok { get_pkgtype_from_hostname(@args); }
+qr{ \A ERROR: [ ] Invalid [ ] empty [ ] hostname }xms
+    => q{No arguments};
+
+ at args = ( {} );
+throws_ok { get_pkgtype_from_hostname(@args); }
+qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] hostname }xms
+    => q{Non-scalar hostname};
+
+ at args = qw( hostname );
+throws_ok { get_pkgtype_from_hostname(@args); }
+qr{ \A ERROR: [ ] Invalid [ ] non-hash [ ] reference [ ] global_config }xms
+    => q{No global_config};
+
+ at args = ( q{hostname}, q{global_config} );
+throws_ok { get_pkgtype_from_hostname(@args); }
+qr{ \A ERROR: [ ] Invalid [ ] non-hash [ ] reference [ ] global_config }xms
+    => q{No global_config};
+
+ at args = ( q{hostname}, $global_config, { site => q{name} } );
+throws_ok { get_pkgtype_from_hostname(@args); }
+qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] site_name }xms
+    => q{Non-scalar site_name};
+
+ at args = ( q{hostname}, $global_config );
+throws_ok { get_pkgtype_from_hostname(@args); }
+qr{ \A ERROR: [ ] Unknown [ ] hostname [ ] 'hostname' [ ] }xms
+    => q{Unknown hostname};
+
+$result = get_pkgtype_from_hostname( q{cbv4-rdeploy01}, $global_config, q{cbv4} );
+$expected_result = q{deb};
+
+is $result, $expected_result
+    => q{cbv4-rdeploy01}
+    or diag explain $result;
+
+########################################################################
+note('Testing PFTools::Structqueries::get_site_list_from_hostname');
+can_ok( 'PFTools::Structqueries', qw( get_site_list_from_hostname ) );
+
+throws_ok { get_site_list_from_hostname() }
+qr{ \A ERROR: [ ] Invalid [ ] empty [ ] hostname }xms
+    => 'Dies if no hostname';
+
+throws_ok { get_site_list_from_hostname( {} ) }
+qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] hostname }xms
+    => q{Dies if non-scalar $hostname};
+
+throws_ok { get_site_list_from_hostname('hostname') }
+qr{ \A ERROR: [ ] Invalid [ ] non-hash [ ] reference [ ] global_config }xms
+    => 'Dies if no global_config';
+
+throws_ok { get_site_list_from_hostname( 'hostname', 'global_config' ) }
+qr{ \A ERROR: [ ] Invalid [ ] non-hash [ ] reference [ ] global_config }xms
+    => q{Dies if non-hashref $global_config};
+
+throws_ok { get_site_list_from_hostname( 'hostname', {} ) }
+qr{ \A ERROR: [ ] Unknown [ ] hostname }xms
+    => q{Dies if unknown hostname};
+
+$expected_result
+    = get_site_list_from_hostname( 'cbv4-spawn00', $global_config );
+
+is_deeply $expected_result, [ q{cbv4-pfds} ]
+    => q{Returns the correct site list}
+    or diag explain $parsed_configuration;
 
 #TODO: {
 #    local $TODO = 'Depends on other, still failing, tests';



More information about the pf-tools-commits mailing list