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 1/4] 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 From 806a1ee41373ecced9211eaa857aa73ed55d8dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Wed, 19 Dec 2012 13:49:34 +0100 Subject: [PATCH 2/4] do not set an empty edid key defined != true --- .../Agent/Task/Inventory/Input/Generic/Screen.pm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/FusionInventory/Agent/Task/Inventory/Input/Generic/Screen.pm b/lib/FusionInventory/Agent/Task/Inventory/Input/Generic/Screen.pm index 7846745eb8..a9590e288a 100644 --- a/lib/FusionInventory/Agent/Task/Inventory/Input/Generic/Screen.pm +++ b/lib/FusionInventory/Agent/Task/Inventory/Input/Generic/Screen.pm @@ -37,6 +37,9 @@ sub doInventory { $screen->{SERIAL} = $info->{SERIAL}; $screen->{BASE64} = encode_base64($screen->{edid}); + } + + if (defined($screen->{edid})) { delete $screen->{edid}; } From bb1ccedb1bc1b20cc2dbb89c0f5c191660bd5eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Wed, 19 Dec 2012 14:04:50 +0100 Subject: [PATCH 3/4] also test httpd-trust --- t/config.t | 23 +++++++++-------------- t/config/sample2/agent.cfg | 1 + 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/t/config.t b/t/config.t index 818c213a49..67ff1a6ba4 100644 --- a/t/config.t +++ b/t/config.t @@ -12,15 +12,18 @@ use FusionInventory::Agent::Config; my %config = ( 'sample1' => { 'no-task' => ['snmpquery', 'wakeonlan'], - 'no-category' => [] + 'no-category' => [], + 'httpd-trust' => [] }, 'sample2' => { 'no-task' => [], - 'no-category' => ['printer'] + 'no-category' => ['printer'], + 'httpd-trust' => ['example', '127.0.0.1', 'foobar', '123.0.0.0/10'] }, 'sample3' => { 'no-task' => [], - 'no-category' => [] + 'no-category' => [], + 'httpd-trust' => [] } ); @@ -32,15 +35,7 @@ foreach my $test (keys %config) { '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"); + foreach my $k (qw/ no-task no-category httpd-trust /) { + is_deeply($c->{$k}, $config{$test}->{$k}, $test." ".$k); + } } - -#$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/sample2/agent.cfg b/t/config/sample2/agent.cfg index 5ab6b31054..98b5d58b7c 100644 --- a/t/config/sample2/agent.cfg +++ b/t/config/sample2/agent.cfg @@ -1,3 +1,4 @@ #no-inventory=0 #no-software=1 no-category=printer +httpd-trust=example,127.0.0.1,foobar,123.0.0.0/10 From 443e5d4e5177b0fc89a5ecc32517e9d712b120c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Wed, 19 Dec 2012 14:05:14 +0100 Subject: [PATCH 4/4] clean up --- t/config.t | 8 -------- 1 file changed, 8 deletions(-) diff --git a/t/config.t b/t/config.t index bdf918faa9..ff94cb270d 100644 --- a/t/config.t +++ b/t/config.t @@ -36,11 +36,3 @@ foreach my $test (keys %config) { 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"); -#