Skip to content

Commit

Permalink
Merge remote-tracking branch 'forge/2.3.x' into 2.3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
guillomovitch committed Dec 24, 2012
2 parents f203666 + a2b58b5 commit e6f4d25
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/FusionInventory/Agent/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ my $default = {
'user' => undef,
# deprecated options
'stdout' => undef,
# multi-values options that will be converted to array ref
'httpd-trust' => "",
'no-task' => "",
'no-category' => ""
};

my $deprecated = {
Expand All @@ -56,7 +60,6 @@ sub new {
my $self = {};
bless $self, $class;
$self->_loadDefaults();

my $backend =
$params{options}->{'conf-file'} ? 'file' :
$params{options}->{config} ? $params{options}->{config} :
Expand Down Expand Up @@ -137,7 +140,6 @@ sub _loadFromRegistry {

sub _loadFromFile {
my ($self, $params) = @_;

my $file = $params->{file} ?
$params->{file} : $params->{directory} . '/agent.cfg';

Expand Down Expand Up @@ -190,6 +192,8 @@ sub _checkContent {
foreach my $old (keys %$deprecated) {
next unless defined $self->{$old};

next if $old =~ /^no-/ and !$self->{$old};

my $handler = $deprecated->{$old};

# notify user of deprecation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ sub doInventory {
$screen->{SERIAL} = $info->{SERIAL};

$screen->{BASE64} = encode_base64($screen->{edid});
}

if (defined($screen->{edid})) {
delete $screen->{edid};
}

Expand Down
42 changes: 42 additions & 0 deletions t/config.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/perl

use strict;
use warnings;
use lib 't';

use File::Temp;
use Test::More;

use FusionInventory::Agent::Config;

my %config = (
'sample1' => {
'no-task' => ['snmpquery', 'wakeonlan'],
'no-category' => [],
'httpd-trust' => []
},
'sample2' => {
'no-task' => [],
'no-category' => ['printer'],
'httpd-trust' => ['example', '127.0.0.1', 'foobar', '123.0.0.0/10']
},
'sample3' => {
'no-task' => [],
'no-category' => [],
'httpd-trust' => []
}

);

plan tests => (scalar keys %config) * 2;

foreach my $test (keys %config) {
my $c = FusionInventory::Agent::Config->new(options => {
'conf-file' => "t/config/$test/agent.cfg"
});

foreach my $k (qw/ no-task no-category httpd-trust /) {
is_deeply($c->{$k}, $config{$test}->{$k}, $test." ".$k);
}
}

3 changes: 3 additions & 0 deletions t/config/sample1/agent.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#no-inventory=1
no-task=snmpquery,wakeonlan
#no-software=1
4 changes: 4 additions & 0 deletions t/config/sample2/agent.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#no-inventory=0
#no-software=1
no-category=printer
httpd-trust=example,127.0.0.1,foobar,123.0.0.0/10
1 change: 1 addition & 0 deletions t/config/sample3/agent.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# no-inventory=1

0 comments on commit e6f4d25

Please sign in to comment.