fix(xo-server/metadata): missing Xapis should trigger a failure job (#4283)

Fixes #4281
This commit is contained in:
badrAZ
2019-06-19 15:20:26 +02:00
committed by Julien Fontanet
parent 238e9cd8cc
commit f44447ce71
4 changed files with 31 additions and 15 deletions
+3
View File
@@ -7,7 +7,10 @@
### Bug fixes ### Bug fixes
- [Metadata backup] Missing XAPIs should trigger a failure job [#4281](https://github.com/vatesfr/xen-orchestra/issues/4281) (PR [#4283](https://github.com/vatesfr/xen-orchestra/pull/4283))
### Released packages ### Released packages
- xo-server-backup-reports v0.16.2
- xo-server v5.44.0 - xo-server v5.44.0
- xo-web v5.44.0 - xo-web v5.44.0
@@ -142,12 +142,14 @@ const getErrorMarkdown = task => {
const MARKDOWN_BY_TYPE = { const MARKDOWN_BY_TYPE = {
pool(task, { formatDate }) { pool(task, { formatDate }) {
const { pool, poolMaster = {} } = task.data const { id, pool = {}, poolMaster = {} } = task.data
const name = pool.name_label || poolMaster.name_label || UNKNOWN_ITEM const name = pool.name_label || poolMaster.name_label || UNKNOWN_ITEM
return { return {
body: [ body: [
`- **UUID**: ${pool.uuid}`, pool.uuid !== undefined
? `- **UUID**: ${pool.uuid}`
: `- **ID**: ${id}`,
...getTemporalDataMarkdown(task.end, task.start, formatDate), ...getTemporalDataMarkdown(task.end, task.start, formatDate),
getErrorMarkdown(task), getErrorMarkdown(task),
], ],
@@ -1,10 +1,8 @@
import ms from 'ms' import ms from 'ms'
import { forEach, isEmpty, iteratee, sortedIndexBy } from 'lodash' import { forEach, isEmpty, iteratee, sortedIndexBy } from 'lodash'
import { noSuchObject } from 'xo-common/api-errors'
const isSkippedError = error => const isSkippedError = error =>
error.message === 'no disks found' || error.message === 'no disks found' ||
noSuchObject.is(error) ||
error.message === 'no VMs match this pattern' || error.message === 'no VMs match this pattern' ||
error.message === 'unhealthy VDI chain' error.message === 'unhealthy VDI chain'
@@ -43,6 +43,20 @@ type MetadataBackupJob = {
xoMetadata?: boolean, xoMetadata?: boolean,
} }
const logInstantFailureTask = (logger, { data, error, message, parentId }) => {
const taskId = logger.notice(message, {
data,
event: 'task.start',
parentId,
})
logger.error(message, {
event: 'task.end',
result: serializeError(error),
status: 'failure',
taskId,
})
}
const createSafeReaddir = (handler, methodName) => (path, options) => const createSafeReaddir = (handler, methodName) => (path, options) =>
handler.list(path, options).catch(error => { handler.list(path, options).catch(error => {
if (error?.code !== 'ENOENT') { if (error?.code !== 'ENOENT') {
@@ -97,7 +111,7 @@ const deleteOldBackups = (handler, dir, retention, handleError) =>
// Task logs emitted in a metadata backup execution: // Task logs emitted in a metadata backup execution:
// //
// job.start(data: { reportWhen: ReportWhen }) // job.start(data: { reportWhen: ReportWhen })
// ├─ task.start(data: { type: 'pool', id: string, pool: <Pool />, poolMaster: <Host /> }) // ├─ task.start(data: { type: 'pool', id: string, pool?: <Pool />, poolMaster?: <Host /> })
// │ ├─ task.start(data: { type: 'remote', id: string }) // │ ├─ task.start(data: { type: 'remote', id: string })
// │ │ └─ task.end // │ │ └─ task.end
// │ └─ task.end // │ └─ task.end
@@ -527,16 +541,15 @@ export default class metadataBackup {
try { try {
xapi = this._app.getXapi(id) xapi = this._app.getXapi(id)
} catch (error) { } catch (error) {
logger.warning( logInstantFailureTask(logger, {
`unable to get the xapi associated to the pool (${id})`, data: {
{ type: 'pool',
event: 'task.warning', id,
taskId: runJobId, },
data: { error,
error, message: `unable to get the xapi associated to the pool (${id})`,
}, parentId: runJobId,
} })
)
} }
if (xapi !== undefined) { if (xapi !== undefined) {
promises.push( promises.push(