Skip to content

Commit

Permalink
no-inventory=0 should be ignored
Browse files Browse the repository at this point in the history
If no-inventory=1 or any other deprecated no-XXX is set in agent.cfg, it
should be ignored. Only no-inventory=1 is valid.

Reported-by: Fabien Raux <vega@rulezlan.org>
  • Loading branch information
Gonéri Le Bouder committed Dec 19, 2012
1 parent b8658ec commit 81041af
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/FusionInventory/Agent/Config.pm
Expand Up @@ -15,8 +15,9 @@ my $default = {
'backend-collect-timeout' => 30,
'httpd-port' => 62354,
'timeout' => 180,
'no-task' => [],
'no-category' => []
# multi-values options that will be converted to array ref
'no-task' => "",
'no-category' => ""
};

my $deprecated = {
Expand Down Expand Up @@ -86,7 +87,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 @@ -162,7 +162,6 @@ sub _loadFromRegistry {

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

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

Expand Down Expand Up @@ -209,6 +208,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
46 changes: 46 additions & 0 deletions t/config.t
@@ -0,0 +1,46 @@
#!/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', 'inventory'],
'no-category' => ['software']
},
'sample2' => {
'no-task' => [],
'no-category' => ['printer', 'software']
},
'sample3' => {
'no-task' => [],
'no-category' => []
}

);

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"
});

is_deeply($c->{'no-task'}, $config{$test}->{'no-task'}, "no-task");
is_deeply($c->{'no-category'}, $config{$test}->{'no-category'}, "no-category");
}

#$config = FusionInventory::Agent::Config->new(options => {
# 'conf-file' => 't/config/sample2/agent.cfg'
#
#});
#
#is_deeply($config->{'no-task'}, , "no-task");
#is_deeply($config->{'no-category'}, , "no-category is not empty");
#
3 changes: 3 additions & 0 deletions t/config/sample1/agent.cfg
@@ -0,0 +1,3 @@
no-inventory=1
no-task=snmpquery,wakeonlan
no-software=1
3 changes: 3 additions & 0 deletions t/config/sample2/agent.cfg
@@ -0,0 +1,3 @@
no-inventory=0
no-software=1
no-category=printer
1 change: 1 addition & 0 deletions t/config/sample3/agent.cfg
@@ -0,0 +1 @@
# no-inventory=1

0 comments on commit 81041af

Please sign in to comment.