Skip to content

Commit

Permalink
Update virtual machines comment; closes #17517
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Jul 30, 2024
1 parent 5b9ed1f commit 2ceb4fb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
36 changes: 36 additions & 0 deletions phpunit/functional/Glpi/Inventory/Assets/VirtualMachineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}
2 changes: 1 addition & 1 deletion src/Inventory/Asset/VirtualMachine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down

0 comments on commit 2ceb4fb

Please sign in to comment.