From 81041aff4bfecc686f77f56e302f020e5cb572a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Wed, 19 Dec 2012 13:45:42 +0100 Subject: [PATCH] no-inventory=0 should be ignored 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 --- lib/FusionInventory/Agent/Config.pm | 9 +++--- t/config.t | 46 +++++++++++++++++++++++++++++ t/config/sample1/agent.cfg | 3 ++ t/config/sample2/agent.cfg | 3 ++ t/config/sample3/agent.cfg | 1 + 5 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 t/config.t create mode 100644 t/config/sample1/agent.cfg create mode 100644 t/config/sample2/agent.cfg create mode 100644 t/config/sample3/agent.cfg diff --git a/lib/FusionInventory/Agent/Config.pm b/lib/FusionInventory/Agent/Config.pm index f1345da5be..4eb28f2ae9 100644 --- a/lib/FusionInventory/Agent/Config.pm +++ b/lib/FusionInventory/Agent/Config.pm @@ -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 = { @@ -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} : @@ -162,7 +162,6 @@ sub _loadFromRegistry { sub _loadFromFile { my ($self, $params) = @_; - my $file = $params->{file} ? $params->{file} : $params->{directory} . '/agent.cfg'; @@ -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 diff --git a/t/config.t b/t/config.t new file mode 100644 index 0000000000..bdf918faa9 --- /dev/null +++ b/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"); +# diff --git a/t/config/sample1/agent.cfg b/t/config/sample1/agent.cfg new file mode 100644 index 0000000000..95b6df329c --- /dev/null +++ b/t/config/sample1/agent.cfg @@ -0,0 +1,3 @@ +no-inventory=1 +no-task=snmpquery,wakeonlan +no-software=1 diff --git a/t/config/sample2/agent.cfg b/t/config/sample2/agent.cfg new file mode 100644 index 0000000000..461fb28d09 --- /dev/null +++ b/t/config/sample2/agent.cfg @@ -0,0 +1,3 @@ +no-inventory=0 +no-software=1 +no-category=printer diff --git a/t/config/sample3/agent.cfg b/t/config/sample3/agent.cfg new file mode 100644 index 0000000000..93a69afe11 --- /dev/null +++ b/t/config/sample3/agent.cfg @@ -0,0 +1 @@ +# no-inventory=1