Skip to content

Commit

Permalink
feat(@xen-orchestra/backups): add Healthcheck to continuous replication
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeauchamp committed Feb 20, 2023
1 parent 5419957 commit 849beef
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion @xen-orchestra/backups/writers/DeltaReplicationWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,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 @@ -63,6 +63,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
37 changes: 37 additions & 0 deletions @xen-orchestra/backups/writers/_MixinReplicationWriter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,47 @@
'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 clonedRef = await xapi.callAsync('VM.clone', this._targetVmRef, 'cloning').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: 3 additions & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

> Users must be able to say: “Nice enhancement, I'm eager to test it”
- [Continuous Replication] : add HealthCheck support to Continuous Replication (PR [#6668](https://github.com/vatesfr/xen-orchestra/pull/6668))

### Bug fixes

> Users must be able to say: “I had this issue, happy to know it's fixed”
Expand All @@ -30,6 +32,7 @@
<!--packages-start-->

- @xen-orchestra/backups minor
- xen-api patch
- xo-server patch

Expand Down

0 comments on commit 849beef

Please sign in to comment.