diff --git a/@xen-orchestra/backups/writers/DeltaReplicationWriter.js b/@xen-orchestra/backups/writers/DeltaReplicationWriter.js index 2e3088fee15..b1c2a072c65 100644 --- a/@xen-orchestra/backups/writers/DeltaReplicationWriter.js +++ b/@xen-orchestra/backups/writers/DeltaReplicationWriter.js @@ -102,7 +102,7 @@ exports.DeltaReplicationWriter = class DeltaReplicationWriter extends MixinRepli size: Object.values(sizeContainers).reduce((sum, { size }) => sum + size, 0), } }) - + this._targetVmRef = targetVmRef const targetVm = await xapi.getRecord('VM', targetVmRef) await Promise.all([ diff --git a/@xen-orchestra/backups/writers/FullReplicationWriter.js b/@xen-orchestra/backups/writers/FullReplicationWriter.js index 4794542cf48..beb104e1c76 100644 --- a/@xen-orchestra/backups/writers/FullReplicationWriter.js +++ b/@xen-orchestra/backups/writers/FullReplicationWriter.js @@ -66,6 +66,7 @@ exports.FullReplicationWriter = class FullReplicationWriter extends MixinReplica return { size: sizeContainer.size } }) + this._targetVmRef = targetVmRef const targetVm = await xapi.getRecord('VM', targetVmRef) await Promise.all([ diff --git a/@xen-orchestra/backups/writers/_MixinReplicationWriter.js b/@xen-orchestra/backups/writers/_MixinReplicationWriter.js index 88146721180..1bf7597e765 100644 --- a/@xen-orchestra/backups/writers/_MixinReplicationWriter.js +++ b/@xen-orchestra/backups/writers/_MixinReplicationWriter.js @@ -1,5 +1,17 @@ 'use strict' +const { Task } = require('../Task') +const assert = require('node:assert/strict') +const { HealthCheckVmBackup } = require('../HealthCheckVmBackup') + +function extractOpaqueRef(str) { + const OPAQUE_REF_RE = /OpaqueRef:[0-9a-z-]+/ + const matches = OPAQUE_REF_RE.exec(str) + if (!matches) { + throw new Error('no opaque ref found') + } + return matches[0] +} exports.MixinReplicationWriter = (BaseClass = Object) => class MixinReplicationWriter extends BaseClass { constructor({ sr, ...rest }) { @@ -7,4 +19,32 @@ exports.MixinReplicationWriter = (BaseClass = Object) => this._sr = sr } + + healthCheck(sr) { + assert.notEqual(this._targetVmRef, undefined, 'A vm should have been transfered to be health checked') + // copy VM + return Task.run( + { + name: 'health check', + }, + async () => { + const { $xapi: xapi } = sr + let clonedVm + try { + const baseVm = xapi.getObject(this._targetVmRef) ?? (await xapi.waitObject(this._targetVmRef)) + const clonedRef = await xapi + .callAsync('VM.clone', this._targetVmRef, `Health Check - ${baseVm.name_label}`) + .then(extractOpaqueRef) + clonedVm = xapi.getObject(clonedRef) ?? (await xapi.waitObject(clonedRef)) + + await new HealthCheckVmBackup({ + restoredVm: clonedVm, + xapi, + }).run() + } finally { + clonedVm && (await xapi.VM_destroy(clonedVm.$ref)) + } + } + ) + } } diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index ff394018e41..8a4202d81ab 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -8,6 +8,7 @@ > Users must be able to say: “Nice enhancement, I'm eager to test it” - [VM/Advanced] Warning message when enabling Windows update tools [#6627](https://github.com/vatesfr/xen-orchestra/issues/6627) (PR [#6681](https://github.com/vatesfr/xen-orchestra/issues/6681)) +- [Continuous Replication] : add HealthCheck support to Continuous Replication (PR [#6668](https://github.com/vatesfr/xen-orchestra/pull/6668)) ### Bug fixes @@ -33,7 +34,7 @@ -- @xen-orchestra/backups patch +- @xen-orchestra/backups minor - xen-api patch - xo-cli minor - xo-web minor