support directories in client configuration directory to separate deploy options
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 29 Sep 2009 19:28:24 +0000 (19:28 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 29 Sep 2009 19:28:24 +0000 (19:28 +0000)
lib/PXElator/client.pm
lib/PXElator/t/client.t

index 4a51714..7d49920 100644 (file)
@@ -64,6 +64,7 @@ sub conf {
                $value = $default;
        } elsif ( -f $path ) {
                $value = read_file $path;
+               chomp $value;
        } else {
                warn "# $name missing $path\n" if $debug;
        }
@@ -74,10 +75,10 @@ sub all_conf {
        my $ip = shift;
        my $path = ip_path $ip || return;
        my $conf;
-       foreach my $file ( glob("$path/*") ) {
+       foreach my $file ( glob("$path/*"), glob("$path/*/*") ) {
                my $name = $file;
-               $name =~ s{^.+/([^/]+)$}{$1};
-               $conf->{ $name } = read_file $file;
+               $name =~ s{^$path/+}{} || die "can't remove $path from $name";
+               $conf->{ $name } = read_file $file if -f $file;
        }
        return $conf;
 }
@@ -173,7 +174,6 @@ sub all_ips {
 
 sub remove {
        my $ip = shift;
-       unlink $_ foreach grep { -e $_ } ( glob "$server::conf/ip/$ip/*" );
        if ( my $mac = mac_from_ip $ip ) {
                unlink "$server::conf/mac/$mac";
        }
index 75b1f90..4d7f54a 100755 (executable)
@@ -4,7 +4,7 @@ use warnings;
 use strict;
 use autodie;
 
-use Test::More tests => 20;
+use Test::More tests => 22;
 use Data::Dump qw/dump/;
 use English;
 
@@ -21,6 +21,9 @@ cmp_ok( client::conf( $host => 'test' ), 'eq', 'default', 'default' );
 ok( client::conf( $host => 'test' => 'value' ), 'conf set' );
 cmp_ok( client::conf( $host => 'test' ), 'eq', 'value', 'value' );
 
+ok( client::conf( $host => 'dir/test' => 'in_dir' ), 'conf test/dir' );
+cmp_ok( client::conf( $host => 'dir/test' ), 'eq', 'in_dir', 'value' );
+
 ok( ! client::conf( $host => 'non-existing' ), 'conf non-existing' );
 
 ok( client::remove( $host ), "remove $host" );