fix(xo-server/listReplicatedVms): dont use snapshot_time (#3394)

It is not always set on VMs imported from snapshots, add a new metadata in `other_config` and use the timestamp in the name_label a fallback.

Fixes #3391
This commit is contained in:
Julien Fontanet 2018-09-07 11:31:57 +02:00 committed by GitHub
parent 8213601df6
commit bcab6bb584
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -19,6 +19,7 @@
- [New VM] Selecting multiple VMs and clicking Create then Cancel used to redirect to Home [#3268](https://github.com/vatesfr/xen-orchestra/issues/3268) (PR [#3371](https://github.com/vatesfr/xen-orchestra/pull/3371))
- [Remotes] `cannot read 'properties' of undefined` error (PR [#3382](https://github.com/vatesfr/xen-orchestra/pull/3382))
- [Servers] Various issues when adding a new server [#3385](https://github.com/vatesfr/xen-orchestra/issues/3385) (PR [#3388](https://github.com/vatesfr/xen-orchestra/pull/3388))
- [Backup NG] Always delete the correct old replications [#3391](https://github.com/vatesfr/xen-orchestra/issues/3391) (PR [#3394](https://github.com/vatesfr/xen-orchestra/pull/3394))
### Released packages

View File

@ -104,6 +104,16 @@ type Metadata = MetadataDelta | MetadataFull
const compareSnapshotTime = (a: Vm, b: Vm): number =>
a.snapshot_time < b.snapshot_time ? -1 : 1
const getReplicatedVmDatetime = (vm: Vm) => {
const {
'xo:backup:datetime': datetime = vm.name_label.slice(-17, -1),
} = vm.other_config
return datetime
}
const compareReplicatedVmDatetime = (a: Vm, b: Vm): number =>
getReplicatedVmDatetime(a) < getReplicatedVmDatetime(b) ? -1 : 1
const compareTimestamp = (a: Metadata, b: Metadata): number =>
a.timestamp - b.timestamp
@ -183,9 +193,7 @@ const listReplicatedVms = (
}
}
// the replicated VMs have been created from a snapshot, therefore we can use
// `snapshot_time` as the creation time
return values(vms).sort(compareSnapshotTime)
return values(vms).sort(compareReplicatedVmDatetime)
}
const importers: $Dict<
@ -762,6 +770,7 @@ export default class BackupNg {
parentId: taskId,
},
xapi._updateObjectMapProperty(vm, 'other_config', {
'xo:backup:datetime': null,
'xo:backup:job': null,
'xo:backup:schedule': null,
'xo:backup:vm': null,
@ -873,6 +882,7 @@ export default class BackupNg {
parentId: taskId,
},
xapi._updateObjectMapProperty(snapshot, 'other_config', {
'xo:backup:datetime': snapshot.snapshot_time,
'xo:backup:job': jobId,
'xo:backup:schedule': scheduleId,
'xo:backup:vm': vmUuid,