Skip to content

Commit fa2d4e7

Browse files
committed
fix: Wrong bios value as array on win32 bios when using WMI in proxmox vm
test: Add related tests
1 parent 718f7e2 commit fa2d4e7

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

Diff for: Changes

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ inventory:
1818
'full-inventory-postpone' option to detect changes
1919
* Update glpi-agent script with --full-inventory-postpone option support
2020
* Update glpi-agent script with --full option support to force a full inventory
21+
* fix #611: Wrong bios value as array on win32 bios when using WMI in proxmox vm
2122

2223
netdiscovery/netinventory:
2324
* Keep device mac address found via snmp during netdiscovery as this is the one

Diff for: lib/GLPI/Agent/Task/Inventory/Win32/Bios.pm

+3-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ sub doInventory {
9696
$bios->{SSN} = $object->{SerialNumber}
9797
unless $bios->{SSN};
9898
}
99-
$bios->{MMODEL} = $object->{Product};
99+
$bios->{MMODEL} = $object->{Product};
100100
unless (empty($object->{Manufacturer})) {
101101
$bios->{MMANUFACTURER} = $object->{Manufacturer};
102102
$bios->{SMANUFACTURER} = $object->{Manufacturer}
@@ -105,6 +105,8 @@ sub doInventory {
105105
}
106106

107107
foreach (keys %$bios) {
108+
# Handle case we have an array of one string in place of the expected string
109+
$bios->{$_} = shift @{$bios->{$_}} if ref($bios->{$_}) eq 'ARRAY';
108110
$bios->{$_} =~ s/\s+$// if $bios->{$_};
109111
delete $bios->{$_} if isInvalidBiosValue($bios->{$_});
110112
}

Diff for: resources/win32/wmi/proxmox-Win32_Bios.wmi

1.37 KB
Binary file not shown.

Diff for: resources/win32/wmi/proxmox-Win32_ComputerSystem.wmi

88 Bytes
Binary file not shown.

Diff for: t/tasks/inventory/windows/bios.t

+43-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ use lib 't/lib';
88
use English qw(-no_match_vars);
99
use Test::More;
1010
use Test::MockModule;
11+
use Test::Deep;
12+
use Test::Exception;
1113
use UNIVERSAL::require;
1214

15+
use GLPI::Agent::Inventory;
1316
use GLPI::Test::Utils;
1417

1518
BEGIN {
@@ -28,13 +31,50 @@ Test::NoWarnings->use();
2831
GLPI::Agent::Task::Inventory::Win32::Bios->require();
2932

3033
my %tests = (
34+
"proxmox" => {
35+
BDATE => '04/01/2014',
36+
BIOSSERIAL => undef,
37+
BVERSION => 'BOCHS - 1',
38+
SSN => undef,
39+
SMODEL => 'BXPC____',
40+
SMANUFACTURER => 'BOCHS_',
41+
BMANUFACTURER => undef,
42+
},
43+
);
44+
45+
my %date_tests = (
3146
"20050927******.******+***" => "09/27/2005",
3247
"foobar" => "foobar"
3348
);
34-
plan tests => (scalar keys %tests) + 1;
3549

36-
foreach my $input (keys %tests) {
37-
my $result = $tests{$input};
50+
plan tests => (scalar keys %tests) +
51+
(scalar keys %date_tests) + 1;
52+
53+
my $inventory = GLPI::Agent::Inventory->new();
54+
55+
my $module = Test::MockModule->new(
56+
'GLPI::Agent::Task::Inventory::Win32::Bios'
57+
);
58+
59+
foreach my $test (keys %tests) {
60+
$module->mock(
61+
'getWMIObjects',
62+
mockGetWMIObjects($test)
63+
);
64+
65+
GLPI::Agent::Task::Inventory::Win32::Bios::doInventory(
66+
inventory => $inventory
67+
);
68+
my $bios = $inventory->getSection('BIOS');
69+
cmp_deeply(
70+
$bios,
71+
$tests{$test},
72+
"$test: BIOS parsing"
73+
);
74+
}
75+
76+
foreach my $input (keys %date_tests) {
77+
my $result = $date_tests{$input};
3878

3979
ok(GLPI::Agent::Task::Inventory::Win32::Bios::_dateFromIntString($input) eq $result, "_dateFromIntString($input)");
4080
}

0 commit comments

Comments
 (0)