fix(xo-server-netbox): properly delete all interfaces that don't have a UUID (#7153)

Fixes zammad#18812

Introduced by 3b1bcc67ae

The first step of synchronizing VIFs with Netbox interfaces is to clean up any interface attached to the Netbox VM that isn't found on the XO VM, *based on their UUID*, including the interfaces that don't have a UUID at all (`uuid` is `null`).

But by looping over the keyed-by-UUID collection, we could only ever delete at most *one* null-UUID interface, the other ones being dropped by `keyBy`.

Using the flat-array collection instead makes sure all the interfaces are handled.
This commit is contained in:
Pierre Donias 2023-11-06 10:28:43 +01:00 committed by GitHub
parent db99a22244
commit 457fec0bc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -12,6 +12,7 @@
> Users must be able to say: “I had this issue, happy to know it's fixed”
- [Netbox] Fix VMs' `site` property being unnecessarily updated on some versions of Netbox (PR [#7145](https://github.com/vatesfr/xen-orchestra/pull/7145))
- [Netbox] Fix "400 Bad Request" error (PR [#7153](https://github.com/vatesfr/xen-orchestra/pull/7153))
### Packages to release

View File

@ -550,10 +550,12 @@ class Netbox {
continue
}
// Start by deleting old interfaces attached to this Netbox VM
Object.entries(nbIfs).forEach(([id, nbIf]) => {
if (nbIf.virtual_machine.id === nbVm.id && !xoVm.VIFs.includes(nbIf.custom_fields.uuid)) {
// Loop over the array to make sure interfaces with a `null` UUID also get deleted
nbIfsList.forEach(nbIf => {
const xoVifId = nbIf.custom_fields.uuid
if (nbIf.virtual_machine.id === nbVm.id && !xoVm.VIFs.includes(xoVifId)) {
ifsToDelete.push({ id: nbIf.id })
delete nbIfs[id]
delete nbIfs[xoVifId]
}
})