Skip to content

Commit

Permalink
feat(backups): add Healthcheck to continuous replication (#6668)
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeauchamp committed Feb 24, 2023
1 parent 942b0f3 commit 3bbb828
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion @xen-orchestra/backups/writers/DeltaReplicationWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
1 change: 1 addition & 0 deletions @xen-orchestra/backups/writers/FullReplicationWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
40 changes: 40 additions & 0 deletions @xen-orchestra/backups/writers/_MixinReplicationWriter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,50 @@
'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 }) {
super(rest)

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))
}
}
)
}
}
3 changes: 2 additions & 1 deletion CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -33,7 +34,7 @@
<!--packages-start-->

- @xen-orchestra/backups patch
- @xen-orchestra/backups minor
- xen-api patch
- xo-cli minor
- xo-web minor
Expand Down

0 comments on commit 3bbb828

Please sign in to comment.