@xen-orchestra/backups 0.35.0 → 0.36.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/HealthCheckVmBackup.js
CHANGED
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
const { Task } = require('./Task')
|
|
4
4
|
|
|
5
5
|
exports.HealthCheckVmBackup = class HealthCheckVmBackup {
|
|
6
|
-
#xapi
|
|
7
6
|
#restoredVm
|
|
7
|
+
#timeout
|
|
8
|
+
#xapi
|
|
8
9
|
|
|
9
|
-
constructor({ restoredVm, xapi }) {
|
|
10
|
+
constructor({ restoredVm, timeout = 10 * 60 * 1000, xapi }) {
|
|
10
11
|
this.#restoredVm = restoredVm
|
|
11
12
|
this.#xapi = xapi
|
|
13
|
+
this.#timeout = timeout
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
async run() {
|
|
@@ -23,7 +25,12 @@ exports.HealthCheckVmBackup = class HealthCheckVmBackup {
|
|
|
23
25
|
|
|
24
26
|
// remove vifs
|
|
25
27
|
await Promise.all(restoredVm.$VIFs.map(vif => xapi.callAsync('VIF.destroy', vif.$ref)))
|
|
26
|
-
|
|
28
|
+
const waitForScript = restoredVm.tags.includes('xo-backup-health-check-xenstore')
|
|
29
|
+
if (waitForScript) {
|
|
30
|
+
await restoredVm.set_xenstore_data({
|
|
31
|
+
'vm-data/xo-backup-health-check': 'planned',
|
|
32
|
+
})
|
|
33
|
+
}
|
|
27
34
|
const start = new Date()
|
|
28
35
|
// start Vm
|
|
29
36
|
|
|
@@ -34,7 +41,7 @@ exports.HealthCheckVmBackup = class HealthCheckVmBackup {
|
|
|
34
41
|
false // Skip pre-boot checks?
|
|
35
42
|
)
|
|
36
43
|
const started = new Date()
|
|
37
|
-
const timeout =
|
|
44
|
+
const timeout = this.#timeout
|
|
38
45
|
const startDuration = started - start
|
|
39
46
|
|
|
40
47
|
let remainingTimeout = timeout - startDuration
|
|
@@ -52,12 +59,52 @@ exports.HealthCheckVmBackup = class HealthCheckVmBackup {
|
|
|
52
59
|
remainingTimeout -= running - started
|
|
53
60
|
|
|
54
61
|
if (remainingTimeout < 0) {
|
|
55
|
-
throw new Error(`local xapi did not get
|
|
62
|
+
throw new Error(`local xapi did not get Running state for VM ${restoredId} after ${timeout / 1000} second`)
|
|
56
63
|
}
|
|
57
64
|
// wait for the guest tool version to be defined
|
|
58
65
|
await xapi.waitObjectState(restoredVm.guest_metrics, gm => gm?.PV_drivers_version?.major !== undefined, {
|
|
59
66
|
timeout: remainingTimeout,
|
|
60
67
|
})
|
|
68
|
+
|
|
69
|
+
const guestToolsReady = new Date()
|
|
70
|
+
remainingTimeout -= guestToolsReady - running
|
|
71
|
+
if (remainingTimeout < 0) {
|
|
72
|
+
throw new Error(`local xapi did not get he guest tools check ${restoredId} after ${timeout / 1000} second`)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (waitForScript) {
|
|
76
|
+
const startedRestoredVm = await xapi.waitObjectState(
|
|
77
|
+
restoredVm.$ref,
|
|
78
|
+
vm =>
|
|
79
|
+
vm?.xenstore_data !== undefined &&
|
|
80
|
+
(vm.xenstore_data['vm-data/xo-backup-health-check'] === 'success' ||
|
|
81
|
+
vm.xenstore_data['vm-data/xo-backup-health-check'] === 'failure'),
|
|
82
|
+
{
|
|
83
|
+
timeout: remainingTimeout,
|
|
84
|
+
}
|
|
85
|
+
)
|
|
86
|
+
const scriptOk = new Date()
|
|
87
|
+
remainingTimeout -= scriptOk - guestToolsReady
|
|
88
|
+
if (remainingTimeout < 0) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
`Backup health check script did not update vm-data/xo-backup-health-check of ${restoredId} after ${
|
|
91
|
+
timeout / 1000
|
|
92
|
+
} second, got ${
|
|
93
|
+
startedRestoredVm.xenstore_data['vm-data/xo-backup-health-check']
|
|
94
|
+
} instead of 'success' or 'failure'`
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (startedRestoredVm.xenstore_data['vm-data/xo-backup-health-check'] !== 'success') {
|
|
99
|
+
const message = startedRestoredVm.xenstore_data['vm-data/xo-backup-health-check-error']
|
|
100
|
+
if (message) {
|
|
101
|
+
throw new Error(`Backup health check script failed with message ${message} for VM ${restoredId} `)
|
|
102
|
+
} else {
|
|
103
|
+
throw new Error(`Backup health check script failed for VM ${restoredId} `)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
Task.info('Backup health check script successfully executed')
|
|
107
|
+
}
|
|
61
108
|
}
|
|
62
109
|
)
|
|
63
110
|
}
|
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "https://github.com/vatesfr/xen-orchestra.git"
|
|
10
10
|
},
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.36.1",
|
|
12
12
|
"engines": {
|
|
13
13
|
"node": ">=14.6"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
16
|
"postversion": "npm publish --access public",
|
|
17
|
-
"test": "node--test"
|
|
17
|
+
"test-integration": "node--test *.integ.js"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@kldzj/stream-throttle": "^1.1.1",
|
|
@@ -50,7 +50,8 @@ exports.DeltaReplicationWriter = class DeltaReplicationWriter extends MixinRepli
|
|
|
50
50
|
},
|
|
51
51
|
})
|
|
52
52
|
this.transfer = task.wrapFn(this.transfer)
|
|
53
|
-
this.cleanup = task.wrapFn(this.cleanup
|
|
53
|
+
this.cleanup = task.wrapFn(this.cleanup)
|
|
54
|
+
this.healthCheck = task.wrapFn(this.healthCheck, true)
|
|
54
55
|
|
|
55
56
|
return task.run(() => this._prepare())
|
|
56
57
|
}
|
|
@@ -80,7 +80,7 @@ exports.MixinBackupWriter = (BaseClass = Object) =>
|
|
|
80
80
|
assert.notStrictEqual(
|
|
81
81
|
this._metadataFileName,
|
|
82
82
|
undefined,
|
|
83
|
-
'Metadata file name should be defined before making a
|
|
83
|
+
'Metadata file name should be defined before making a health check'
|
|
84
84
|
)
|
|
85
85
|
return Task.run(
|
|
86
86
|
{
|