From 53e94378aec90ed9c97c19659f3b3d81f4d46f36 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Tue, 5 May 2015 18:55:46 +0200 Subject: [PATCH] Correctly handle patch upload error. --- src/xapi.js | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/xapi.js b/src/xapi.js index 0ce3393f4..180890033 100644 --- a/src/xapi.js +++ b/src/xapi.js @@ -183,29 +183,31 @@ export default class Xapi extends XapiBase { async _installHostPatch (host, stream, length) { const taskRef = await this._createTask('Patch upload from XO') - got.put('http://' + host.address + '/pool_patch_upload', { - body: stream, - query: { - session_id: this.sessionId, - task_id: taskRef - }, - headers: { - 'content-length': length - } - }) + await Promise.all([ + gotPromise('http://' + host.address + '/pool_patch_upload', { + method: 'put', + body: stream, + query: { + session_id: this.sessionId, + task_id: taskRef + }, + headers: { + 'content-length': length + } + }), + this._watchTask(taskRef).then( + (patchRef) => { + debug('patch upload succeeded') - await this._watchTask(taskRef).then( - (patchRef) => { - debug('patch upload succeeded') + return this.call('pool_patch.apply', patchRef, host.ref) + }, + (error) => { + debug('patch upload failed', error.stack || error) - return this.call('pool_patch.apply', patchRef, host.ref) - }, - (error) => { - debug('patch upload failed', error.stack || error) - - throw error - } - ) + throw error + } + ) + ]) } async installHostPatchFromUrl (host, patchUrl) {