From 3bd13cded6a73971beaa46d8191c60f27b8d2d26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 3 Aug 2017 09:44:48 +0300 Subject: [PATCH] MXS-1300: Fix minor MaxCtrl bugs Fixed unresolved promises, wrong resources being requested and enabled strict mode so unknown arguments are not ignored. --- maxctrl/lib/cluster.js | 2 +- maxctrl/lib/common.js | 9 +++++---- maxctrl/lib/core.js | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/maxctrl/lib/cluster.js b/maxctrl/lib/cluster.js index 406a4b25d..a2e2e9679 100644 --- a/maxctrl/lib/cluster.js +++ b/maxctrl/lib/cluster.js @@ -193,7 +193,7 @@ exports.builder = function(yargs) { var promises = [] // Add new monitors getDifference(src.monitors.data, dest.monitors.data).forEach(function(i) { - promises.push(doAsyncRequest(host, 'servers', null, {method: 'POST', body: {data: i}})) + promises.push(doAsyncRequest(host, 'monitors', null, {method: 'POST', body: {data: i}})) }) return Promise.all(promises) }) diff --git a/maxctrl/lib/common.js b/maxctrl/lib/common.js index d13f240f8..01431903e 100644 --- a/maxctrl/lib/common.js +++ b/maxctrl/lib/common.js @@ -48,7 +48,9 @@ module.exports = function() { }) return Promise.all(promises) - .catch(function(err) { + .then(function() { + argv.resolve() + }, function(err) { argv.reject(err) }) }, function(err) { @@ -193,9 +195,9 @@ module.exports = function() { } }, function(err) { if (err.response && err.response.body) { - return error(JSON.stringify(err.response.body, null, 4)) + return error('Server responded with an error to resource request `' + resource + '`:' + JSON.stringify(err.response.body, null, 4)) } else if (err.statusCode) { - return error('Server responded with: ' + err.statusCode) + return error('Server responded with: ' + err.statusCode + 'to resource request `' + resource + '`') } else if (err.error) { return error(JSON.stringify(err.error, null, 4)) } else { @@ -206,7 +208,6 @@ module.exports = function() { this.doRequest = function(host, resource, cb, obj) { return doAsyncRequest(host, resource, cb, obj) - .then(this.argv.resolve, this.argv.reject) } this.error = function(err) { diff --git a/maxctrl/lib/core.js b/maxctrl/lib/core.js index 719f5d043..fd140d78d 100644 --- a/maxctrl/lib/core.js +++ b/maxctrl/lib/core.js @@ -18,6 +18,7 @@ const maxctrl_version = '1.0.0'; program .version(maxctrl_version) + .strict() .group(['u', 'p', 'h', 's', 't', 'q', 'tsv'], 'Global Options:') .option('u', { alias:'user',