Compare commits

...

11 Commits

Author SHA1 Message Date
heafalan
50704b8404 feat(xo-server-test/backupNg.spec.js): test on 'backupNg.importVmBackup'
See #4307
2019-08-12 15:04:03 +02:00
heafalan
341cdf6cba delete snapshot at the end of the test 2019-08-12 14:04:01 +02:00
heafalan
ced02de429 fixes tests for QA 2019-08-09 12:58:01 +02:00
heafalan
1745d61c1d requested changes 2019-08-08 14:08:23 +02:00
heafalan
fac2e6845c requested changes 2019-08-08 10:21:25 +02:00
heafalan
fd7eddb68c various changes 2019-08-07 13:09:08 +02:00
heafalan
23fb486a40 various changes 2019-08-05 16:27:15 +02:00
heafalan
9114aa5b11 add server 2019-08-02 12:39:50 +02:00
heafalan
fdb3368b44 Merge branch 'master' of http://github.com/vatesfr/xen-orchestra into deltaBackup-with2remotes 2019-08-02 12:09:42 +02:00
heafalan
c0949e9aef Merge branch 'master' of http://github.com/vatesfr/xen-orchestra into deltaBackup-with2remotes 2019-08-02 12:09:22 +02:00
heafalan
ae9b4126b1 feat(xo-server-test): delta backup test
See #4307
2019-07-31 15:52:37 +02:00
5 changed files with 631 additions and 2 deletions

View File

@@ -11,12 +11,18 @@
[vms]
default = ''
# vmToBackup = ''
[templates]
default = ''
templateWithoutDisks = ''
[srs]
default = ''
localSr = ''
sharedSr = ''
[remotes]
default = { name = '', url = '' }
remote1 = { name = '', url = '' }
# remote2 = { name = '', url = '' }

View File

@@ -157,6 +157,52 @@ class XoConnection extends Xo {
return find(await this.call('schedule.getAll'), predicate)
}
async runBackupJob(jobId, scheduleId, { remotes, nExecutions = 1 }) {
for (let i = 0; i < nExecutions; i++) {
await xo.call('backupNg.runJob', { id: jobId, schedule: scheduleId })
}
const backups = {}
if (remotes !== undefined) {
const backupsByRemote = await xo.call('backupNg.listVmBackups', {
remotes,
})
forOwn(backupsByRemote, (backupsByVm, remoteId) => {
backups[remoteId] = []
forOwn(backupsByVm, vmBackups => {
vmBackups.forEach(
({ jobId: backupJobId, scheduleId: backupScheduleId, id }) => {
if (jobId === backupJobId && scheduleId === backupScheduleId) {
this._tempResourceDisposers.push('backupNg.deleteVmBackup', {
id,
})
backups[remoteId].push(id)
}
}
)
})
})
for (const id in this.objects.all) {
if (this.objects.all[id].other) {
const { 'xo:backup:schedule': snapshotSchedule } = this.objects.all[
id
].other
if (snapshotSchedule === scheduleId) {
this._tempResourceDisposers.push('vm.delete', {
id,
})
}
}
}
}
return backups
}
async importVmBackup(params) {
const id = await xo.call('backupNg.importVmBackup', params)
this._tempResourceDisposers.push('vm.delete', { id })
return id
}
async _cleanDisposers(disposers) {
for (let n = disposers.length - 1; n > 0; ) {
const params = disposers[n--]

View File

@@ -127,6 +127,375 @@ Object {
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 1`] = `
Object {
"data": Object {
"mode": "delta",
"reportWhen": "never",
},
"end": Any<Number>,
"id": Any<String>,
"jobId": Any<String>,
"message": "backup",
"scheduleId": Any<String>,
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 2`] = `
Object {
"data": Object {
"id": Any<String>,
"type": "VM",
},
"end": Any<Number>,
"id": Any<String>,
"message": Any<String>,
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 3`] = `
Object {
"end": Any<Number>,
"id": Any<String>,
"message": "snapshot",
"result": Any<String>,
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 4`] = `
Object {
"data": Object {
"id": Any<String>,
"isFull": true,
"type": "remote",
},
"end": Any<Number>,
"id": Any<String>,
"message": Any<String>,
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 5`] = `
Object {
"end": Any<Number>,
"id": Any<String>,
"message": Any<String>,
"result": Object {
"size": Any<Number>,
},
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 6`] = `
Object {
"end": Any<Number>,
"id": Any<String>,
"message": Any<String>,
"result": Object {
"size": Any<Number>,
},
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 7`] = `
Object {
"data": Object {
"id": Any<String>,
"isFull": true,
"type": "remote",
},
"end": Any<Number>,
"id": Any<String>,
"message": Any<String>,
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 8`] = `
Object {
"end": Any<Number>,
"id": Any<String>,
"message": Any<String>,
"result": Object {
"size": Any<Number>,
},
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 9`] = `
Object {
"end": Any<Number>,
"id": Any<String>,
"message": Any<String>,
"result": Object {
"size": Any<Number>,
},
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 10`] = `
Object {
"data": Object {
"mode": "delta",
"reportWhen": "never",
},
"end": Any<Number>,
"id": Any<String>,
"jobId": Any<String>,
"message": "backup",
"scheduleId": Any<String>,
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 11`] = `
Object {
"data": Object {
"id": Any<String>,
"type": "VM",
},
"end": Any<Number>,
"id": Any<String>,
"message": Any<String>,
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 12`] = `
Object {
"end": Any<Number>,
"id": Any<String>,
"message": "snapshot",
"result": Any<String>,
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 13`] = `
Object {
"data": Object {
"id": Any<String>,
"isFull": false,
"type": "remote",
},
"end": Any<Number>,
"id": Any<String>,
"message": Any<String>,
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 14`] = `
Object {
"end": Any<Number>,
"id": Any<String>,
"message": Any<String>,
"result": Object {
"size": Any<Number>,
},
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 15`] = `
Object {
"end": Any<Number>,
"id": Any<String>,
"message": Any<String>,
"result": Object {
"size": Any<Number>,
},
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 16`] = `
Object {
"data": Object {
"id": Any<String>,
"isFull": false,
"type": "remote",
},
"end": Any<Number>,
"id": Any<String>,
"message": Any<String>,
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 17`] = `
Object {
"end": Any<Number>,
"id": Any<String>,
"message": Any<String>,
"result": Object {
"size": Any<Number>,
},
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 18`] = `
Object {
"end": Any<Number>,
"id": Any<String>,
"message": Any<String>,
"result": Object {
"size": Any<Number>,
},
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 19`] = `
Object {
"data": Object {
"mode": "delta",
"reportWhen": "never",
},
"end": Any<Number>,
"id": Any<String>,
"jobId": Any<String>,
"message": "backup",
"scheduleId": Any<String>,
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 20`] = `
Object {
"data": Object {
"id": Any<String>,
"type": "VM",
},
"end": Any<Number>,
"id": Any<String>,
"message": Any<String>,
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 21`] = `
Object {
"end": Any<Number>,
"id": Any<String>,
"message": "snapshot",
"result": Any<String>,
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 22`] = `
Object {
"data": Object {
"id": Any<String>,
"isFull": true,
"type": "remote",
},
"end": Any<Number>,
"id": Any<String>,
"message": Any<String>,
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 23`] = `
Object {
"end": Any<Number>,
"id": Any<String>,
"message": Any<String>,
"result": Object {
"size": Any<Number>,
},
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 24`] = `
Object {
"end": Any<Number>,
"id": Any<String>,
"message": Any<String>,
"result": Object {
"size": Any<Number>,
},
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 25`] = `
Object {
"data": Object {
"id": Any<String>,
"isFull": true,
"type": "remote",
},
"end": Any<Number>,
"id": Any<String>,
"message": Any<String>,
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 26`] = `
Object {
"end": Any<Number>,
"id": Any<String>,
"message": Any<String>,
"result": Object {
"size": Any<Number>,
},
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval 27`] = `
Object {
"end": Any<Number>,
"id": Any<String>,
"message": Any<String>,
"result": Object {
"size": Any<Number>,
},
"start": Any<Number>,
"status": "success",
}
`;
exports[`backupNg execute three times a rolling snapshot with 2 as retention & revert to an old state 1`] = `
Object {
"data": Object {

View File

@@ -1,5 +1,6 @@
/* eslint-env jest */
import { forOwn } from 'lodash'
import { noSuchObject } from 'xo-common/api-errors'
import config from '../_config'
@@ -11,6 +12,60 @@ const DEFAULT_SCHEDULE = {
cron: '0 * * * * *',
}
const validateRootTask = (log, props) =>
expect(log).toMatchSnapshot({
end: expect.any(Number),
id: expect.any(String),
jobId: expect.any(String),
scheduleId: expect.any(String),
start: expect.any(Number),
...props,
})
const validateVmTask = (task, vmId, props = {}) => {
expect(task).toMatchSnapshot({
data: {
id: expect.any(String),
},
end: expect.any(Number),
id: expect.any(String),
message: expect.any(String),
start: expect.any(Number),
...props,
})
expect(task.data.id).toBe(vmId)
}
const validateSnapshotTask = (task, props) =>
expect(task).toMatchSnapshot({
end: expect.any(Number),
id: expect.any(String),
result: expect.any(String),
start: expect.any(Number),
...props,
})
const validateExportTask = (task, srOrRemoteIds, props) => {
expect(task).toMatchSnapshot({
end: expect.any(Number),
id: expect.any(String),
message: expect.any(String),
start: expect.any(Number),
...props,
})
expect(srOrRemoteIds).toContain(task.data.id)
}
const validateOperationTask = (task, props) => {
expect(task).toMatchSnapshot({
end: expect.any(Number),
id: expect.any(String),
message: expect.any(String),
start: expect.any(Number),
...props,
})
}
describe('backupNg', () => {
let defaultBackupNg
@@ -174,7 +229,7 @@ describe('backupNg', () => {
const vmIdWithoutDisks = await xo.createTempVm({
name_label: 'XO Test Without Disks',
name_description: 'Creating a vm without disks',
template: config.templates.default,
template: config.templates.templateWithoutDisks,
})
const scheduleTempId = randomId()
@@ -389,4 +444,157 @@ describe('backupNg', () => {
})
expect(vmTask.data.id).toBe(vmId)
})
test('execute three times a delta backup with 2 remotes, 2 as retention and 2 as fullInterval', async () => {
jest.setTimeout(6e4)
const {
vms: { default: defaultVm, vmToBackup = defaultVm },
remotes: { default: defaultRemote, remote1, remote2 = defaultRemote },
srs: { localSr, sharedSr },
servers: { default: defaultServer },
} = config
expect(vmToBackup).not.toBe(undefined)
expect(remote1).not.toBe(undefined)
expect(remote2).not.toBe(undefined)
expect(localSr).not.toBe(undefined)
expect(sharedSr).not.toBe(undefined)
await xo.createTempServer(defaultServer)
const { id: remoteId1 } = await xo.createTempRemote(remote1)
const { id: remoteId2 } = await xo.createTempRemote(remote2)
const remotes = [remoteId1, remoteId2]
const exportRetention = 2
const fullInterval = 2
const scheduleTempId = randomId()
const { id: jobId } = await xo.createTempBackupNgJob({
mode: 'delta',
remotes: {
id: {
__or: remotes,
},
},
schedules: {
[scheduleTempId]: DEFAULT_SCHEDULE,
},
settings: {
'': {
reportWhen: 'never',
fullInterval,
},
[remoteId1]: { deleteFirst: true },
[scheduleTempId]: { exportRetention },
},
vms: {
id: vmToBackup,
},
})
const schedule = await xo.getSchedule({ jobId })
expect(typeof schedule).toBe('object')
const nExecutions = 3
const backupsByRemote = await xo.runBackupJob(jobId, schedule.id, {
remotes,
nExecutions,
})
forOwn(backupsByRemote, backups =>
expect(backups.length).toBe(exportRetention)
)
const backupLogs = await xo.call('backupNg.getLogs', {
jobId,
scheduleId: schedule.id,
})
expect(backupLogs.length).toBe(nExecutions)
backupLogs.forEach(({ tasks, ...log }, key) => {
validateRootTask(log, {
data: {
mode: 'delta',
reportWhen: 'never',
},
message: 'backup',
status: 'success',
})
const numberOfTasks = {
export: 0,
merge: 0,
snapshot: 0,
transfer: 0,
vm: 0,
}
tasks.forEach(({ tasks, ...vmTask }) => {
if (vmTask.data !== undefined && vmTask.data.type === 'VM') {
validateVmTask(vmTask, vmToBackup, { status: 'success' })
numberOfTasks.vm++
tasks.forEach(({ tasks, ...subTask }) => {
if (subTask.message === 'snapshot') {
validateSnapshotTask(subTask, { status: 'success' })
numberOfTasks.snapshot++
}
if (subTask.message === 'export') {
validateExportTask(subTask, remotes, {
data: {
id: expect.any(String),
isFull: key % fullInterval === 0,
type: 'remote',
},
status: 'success',
})
numberOfTasks.export++
let mergeTaskKey, transferTaskKey
tasks.forEach((operationTask, key) => {
if (
operationTask.message === 'transfer' ||
operationTask.message === 'merge'
) {
validateOperationTask(operationTask, {
result: { size: expect.any(Number) },
status: 'success',
})
if (operationTask.message === 'transfer') {
mergeTaskKey = key
numberOfTasks.merge++
} else {
transferTaskKey = key
numberOfTasks.transfer++
}
}
})
expect(
subTask.data.id === remoteId1
? mergeTaskKey > transferTaskKey
: mergeTaskKey < transferTaskKey
).toBe(true)
}
})
}
})
expect(numberOfTasks).toEqual({
export: 2,
merge: 2,
snapshot: 1,
transfer: 2,
vm: 1,
})
})
const vmBackupOnLocalSr = await xo.importVmBackup({
id: backupsByRemote[remoteId1][0],
sr: localSr,
})
const vmBackupOnSharedSr = await xo.importVmBackup({
id: backupsByRemote[remoteId2][0],
sr: sharedSr,
})
expect(xo.objects.all[vmBackupOnLocalSr]).not.toBe(undefined)
expect(xo.objects.all[vmBackupOnSharedSr]).not.toBe(undefined)
await xo.call('vm.start', { id: vmBackupOnLocalSr })
await xo.call('vm.start', { id: vmBackupOnSharedSr })
})
})

View File

@@ -209,7 +209,7 @@ describe('job', () => {
})
it('runs a job', async () => {
jest.setTimeout(7e3)
jest.setTimeout(7e4)
await xo.createTempServer(config.servers.default)
const jobId = await xo.createTempJob(defaultJob)
const snapshots = xo.objects.all[config.vms.default].snapshots