diff --git a/phpunit/functional/Glpi/Inventory/Assets/VirtualMachineTest.php b/phpunit/functional/Glpi/Inventory/Assets/VirtualMachineTest.php index ad0d13f615e..40c43eb990a 100644 --- a/phpunit/functional/Glpi/Inventory/Assets/VirtualMachineTest.php +++ b/phpunit/functional/Glpi/Inventory/Assets/VirtualMachineTest.php @@ -804,4 +804,40 @@ public function testDefaultStatusForRelatedComputer() 'states_id' => $inv_states_id ])); } + + public function testUpdateVirtualMachineComment() + { + //inventory + $source = json_decode('{"content":{"hardware":{"dns":"10.100.230.2\\/10.100.230.4","memory":130625,"name":"ESX-03-DMZ","uuid":"8c8c8944-0074-5632-7452-b2c04f564712","vmsystem":"Physical","workgroup":"teclib.fr"},"versionclient":"GLPI-Agent_v1.4-1","virtualmachines":[{"comment":"Computer VM","mac":"00:50:56:90:43:42","memory":1024,"name":"SRV-DMZ-EZ","status":"running","uuid":"420904FE-6a92-95e8-13f9-a37fc3607c14","vcpu":1,"vmtype":"vmware"}]},"deviceid":"ESX-03-DMZ.insep.fr-2023-02-02-11-34-53","action":"inventory","itemtype":"Computer"}'); + $inventory = $this->doInventory($source); + + $id_first = $inventory->getItem()->fields['id']; + $this->assertGreaterThan(0, $id_first); + + //one VM + $vm = new \ComputerVirtualMachine(); + $this->assertCount(1, $vm->find()); + + //get ComputervirtualMachine + $vm = new \ComputerVirtualMachine(); + $this->assertTrue($vm->getFromDBByCrit([ + 'uuid' => '420904fe-6a92-95e8-13f9-a37fc3607c14', + 'computers_id' => $id_first + ])); + + $this->assertSame('Computer VM', $vm->fields['comment']); + + //change comment, do inventory again + $source = json_decode('{"content":{"hardware":{"dns":"10.100.230.2\\/10.100.230.4","memory":130625,"name":"ESX-03-DMZ","uuid":"8c8c8944-0074-5632-7452-b2c04f564712","vmsystem":"Physical","workgroup":"teclib.fr"},"versionclient":"GLPI-Agent_v1.4-1","virtualmachines":[{"comment":"Edited Computer VM","mac":"00:50:56:90:43:42","memory":1024,"name":"SRV-DMZ-EZ","status":"running","uuid":"420904FE-6a92-95e8-13f9-a37fc3607c14","vcpu":1,"vmtype":"vmware"}]},"deviceid":"ESX-03-DMZ.insep.fr-2023-02-02-11-34-53","action":"inventory","itemtype":"Computer"}'); + $this->doInventory($source); + + //still one VM + $this->assertCount(1, $vm->find()); + + $this->assertTrue($vm->getFromDBByCrit([ + 'uuid' => '420904fe-6a92-95e8-13f9-a37fc3607c14', + 'computers_id' => $id_first + ])); + $this->assertSame('Edited Computer VM', $vm->fields['comment']); + } } diff --git a/src/Inventory/Asset/VirtualMachine.php b/src/Inventory/Asset/VirtualMachine.php index 8a4bf9dc211..57d4a13bb56 100644 --- a/src/Inventory/Asset/VirtualMachine.php +++ b/src/Inventory/Asset/VirtualMachine.php @@ -243,7 +243,7 @@ public function handle() 'is_dynamic' => 1 ]; - foreach (['vcpu', 'ram', 'virtualmachinetypes_id', 'virtualmachinestates_id'] as $prop) { + foreach (['vcpu', 'ram', 'virtualmachinetypes_id', 'virtualmachinestates_id', 'comment'] as $prop) { if (property_exists($val, $prop)) { $input[$prop] = $handled_input[$prop]; }