pf-tools/pf-tools: get_hostshort_hostvlan_from_fqdn(): new $zone...
parmelan-guest at users.alioth.debian.org
parmelan-guest at users.alioth.debian.org
Mon Jan 3 11:05:56 UTC 2011
details: http://hg.debian.org/hg/pf-tools/pf-tools/rev/418635e2d6eb
changeset: 1161:418635e2d6eb
user: Thomas Parmelan <tom+pf-tools at ankh.fr.EU.org>
date: Mon Jan 03 12:05:47 2011 +0100
description:
get_hostshort_hostvlan_from_fqdn(): new $zone optional parameter, was mistakenly omitted in the initial version
diffstat:
2 files changed, 5 insertions(+), 1 deletion(-)
lib/PFTools/Structqueries.pm | 2 +-
t/13.conf.t | 4 ++++
diffs (101 lines):
diff -r 8fab735a6f9e -r 418635e2d6eb lib/PFTools/Structqueries.pm
--- a/lib/PFTools/Structqueries.pm Mon Jan 03 09:02:28 2011 +0100
+++ b/lib/PFTools/Structqueries.pm Mon Jan 03 12:05:47 2011 +0100
@@ -53,10 +53,12 @@
our @EXPORT_OK = qw ();
-=head2 get_hostshort_hostvlan_from_fqdn($fqdn)
+=head2 get_hostshort_hostvlan_from_fqdn($fqdn, $zone)
Returns an array containing the hostshort, hostvlan and zone (or undefined
-values if there's no match).
+values if there's no complete match). If $zone is specified, it must match
+correctly. If nothing is matched, an empty array is returned (instead of three
+undef elements).
Example: the result for rdeploy00.vlan-systeme.private would be the following
array:
@@ -66,7 +68,7 @@
=cut
sub get_hostshort_hostvlan_zone_from_fqdn {
- my ($fqdn) = @_;
+ my ($fqdn, $zone) = @_;
if ( not $fqdn ) {
croak q{ERROR: Invalid false fqdn};
@@ -75,6 +77,15 @@
if ( ref $fqdn ) {
croak q{ERROR: Invalid non-scalar fqdn};
}
+
+ if ( ref $zone ) {
+ croak q{ERROR: Invalid non-scalar zone};
+ }
+
+ my $zone_regexp
+ = $zone
+ ? qr{ \Q$zone\E }xms
+ : qr{ [^.]+ }xms; # or just .+ to allow subzones?
my @return
= $fqdn =~ m{
@@ -91,7 +102,7 @@
(?:
[.]
( # -> $zone
- [^.]+ # or just .+ to allow subzones?
+ $zone_regexp
)
)?
\z
@@ -319,7 +330,8 @@
my $site_ref = get_site_config( $site_name, $global_config );
my $zone = $site_ref->{'zone'};
- my ($hostshort) = get_hostshort_hostvlan_zone_from_fqdn($hostname);
+ my ($hostshort)
+ = get_hostshort_hostvlan_zone_from_fqdn( $hostname, $zone );
if ( not $hostshort ) {
croak
qq{ERROR: Unable to get hostshort from hostname $hostname};
diff -r 8fab735a6f9e -r 418635e2d6eb t/13.conf.t
--- a/t/13.conf.t Mon Jan 03 09:02:28 2011 +0100
+++ b/t/13.conf.t Mon Jan 03 12:05:47 2011 +0100
@@ -1918,11 +1918,15 @@
qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] fqdn }xms
=> q{Dies if non-scalar fqdn};
+throws_ok { get_hostshort_hostvlan_zone_from_fqdn( q{fqdn}, {} ) }
+qr{ \A ERROR: [ ] Invalid [ ] non-scalar [ ] zone }xms
+ => q{Dies if non-scalar zone};
+
my @result = get_hostshort_hostvlan_zone_from_fqdn( q{rdeploy00.vlan-systeme.private} );
my @expected_result = qw( rdeploy00 vlan-systeme private );
is_deeply \@result, \@expected_result
=> q{Returns the correct result for rdeploy00.vlan-systeme.private}
- or note explain $result;
+ or note explain @result;
@result = get_hostshort_hostvlan_zone_from_fqdn( q{cbv4-rdeploy00.vlan-systeme.private} );
@expected_result = qw( cbv4-rdeploy00 vlan-systeme private );
@@ -1940,6 +1944,18 @@
@expected_result = ( q{cbv4-rdeploy00}, undef, undef );
is_deeply \@result, \@expected_result
=> q{Returns the correct result for cbv4-rdeploy00}
+ or note explain @result;
+
+ at result = get_hostshort_hostvlan_zone_from_fqdn( q{rdeploy00.vlan-systeme.private}, q{private} );
+ at expected_result = qw( rdeploy00 vlan-systeme private );
+is_deeply \@result, \@expected_result
+ => q{Returns the correct result for rdeploy00.vlan-systeme.private with explicit correct zone }
+ or note explain @result;
+
+ at result = get_hostshort_hostvlan_zone_from_fqdn( q{rdeploy00.vlan-systeme.private}, q{public} );
+ at expected_result = ();
+is_deeply \@result, \@expected_result
+ => q{Returns the correct result for rdeploy00.vlan-systeme.private with incorrect zone }
or note explain @result;
More information about the pf-tools-commits
mailing list