Update unit test: coverage:80.78%
This commit is contained in:
parent
712725e398
commit
de10b28642
@ -1,3 +1,5 @@
|
|||||||
|
// Copyright 2015, EMC, Inc.
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var url = require('url');
|
var url = require('url');
|
||||||
@ -6,12 +8,11 @@ var ironic = require('./../lib/api/openstack/ironic');
|
|||||||
var config = require('./../config.json');
|
var config = require('./../config.json');
|
||||||
var glance = require('./../lib/api/openstack/glance');
|
var glance = require('./../lib/api/openstack/glance');
|
||||||
var keystone = require('./../lib/api/openstack/keystone');
|
var keystone = require('./../lib/api/openstack/keystone');
|
||||||
var logger = require('./../lib/services/logger').Logger;
|
var logger = require('./../lib/services/logger').Logger('info');
|
||||||
var encryption = require('./../lib/services/encryption');
|
var encryption = require('./../lib/services/encryption');
|
||||||
var jsonfile = require('jsonfile');
|
var jsonfile = require('jsonfile');
|
||||||
var _ = require('underscore');
|
var _ = require('underscore');
|
||||||
var Promise = require('bluebird');
|
var Promise = require('bluebird');
|
||||||
|
|
||||||
var ironicConfig = config.ironic;
|
var ironicConfig = config.ironic;
|
||||||
var glanceConfig = config.glance;
|
var glanceConfig = config.glance;
|
||||||
|
|
||||||
@ -44,12 +45,8 @@ module.exports.driversGet = function driversGet(req, res, next) {
|
|||||||
return ironic.get_driver_list(token);
|
return ironic.get_driver_list(token);
|
||||||
}).
|
}).
|
||||||
then(function (result) {
|
then(function (result) {
|
||||||
if (typeof result !== 'undefined') {
|
res.setHeader('Content-Type', 'application/json');
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.end(result);
|
||||||
res.end(result);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
res.end();
|
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
logger.error({ message: err, path: req.url });
|
logger.error({ message: err, path: req.url });
|
||||||
@ -71,12 +68,8 @@ module.exports.ironicnodesGet = function ironicnodesGet(req, res, next) {
|
|||||||
return ironic.get_node_list(token);
|
return ironic.get_node_list(token);
|
||||||
}).
|
}).
|
||||||
then(function (result) {
|
then(function (result) {
|
||||||
if (typeof result !== 'undefined') {
|
res.setHeader('Content-Type', 'application/json');
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.end(result);
|
||||||
res.end(result);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
res.end();
|
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
logger.error({ message: err, path: req.url });
|
logger.error({ message: err, path: req.url });
|
||||||
@ -98,12 +91,8 @@ module.exports.ironicchassisGet = function ironicchassisGet(req, res, next) {
|
|||||||
return ironic.get_chassis_by_id(token, req.swagger.params.identifier.value);
|
return ironic.get_chassis_by_id(token, req.swagger.params.identifier.value);
|
||||||
}).
|
}).
|
||||||
then(function (result) {
|
then(function (result) {
|
||||||
if (typeof result !== 'undefined') {
|
res.setHeader('Content-Type', 'application/json');
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.end(result);
|
||||||
res.end(result);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
res.end();
|
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
logger.error({ message: err, path: req.url });
|
logger.error({ message: err, path: req.url });
|
||||||
@ -125,12 +114,8 @@ module.exports.ironicnodeGet = function ironicnodeGet(req, res, next) {
|
|||||||
return ironic.get_node(token, req.swagger.params.identifier.value);
|
return ironic.get_node(token, req.swagger.params.identifier.value);
|
||||||
}).
|
}).
|
||||||
then(function (result) {
|
then(function (result) {
|
||||||
if (typeof result !== 'undefined') {
|
res.setHeader('Content-Type', 'application/json');
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.end(result);
|
||||||
res.end(result);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
res.end();
|
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
logger.error({ message: err, path: req.url });
|
logger.error({ message: err, path: req.url });
|
||||||
@ -153,10 +138,8 @@ module.exports.ironicnodePatch = function ironicnodePatch(req, res, next) {
|
|||||||
return ironic.patch_node(token, req.swagger.params.identifier.value, data);
|
return ironic.patch_node(token, req.swagger.params.identifier.value, data);
|
||||||
}).
|
}).
|
||||||
then(function (result) {
|
then(function (result) {
|
||||||
if (result) {
|
res.setHeader('Content-Type', 'application/json');
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.end(result);
|
||||||
res.end(result);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
logger.error({ message: err, path: req.url });
|
logger.error({ message: err, path: req.url });
|
||||||
@ -173,12 +156,8 @@ module.exports.ironicnodePatch = function ironicnodePatch(req, res, next) {
|
|||||||
module.exports.catalogsGet = function catalogsGet(req, res, next) {
|
module.exports.catalogsGet = function catalogsGet(req, res, next) {
|
||||||
return monorail.request_catalogs_get(req.swagger.params.identifier.value).
|
return monorail.request_catalogs_get(req.swagger.params.identifier.value).
|
||||||
then(function (catalogs) {
|
then(function (catalogs) {
|
||||||
if (typeof catalogs !== 'undefined') {
|
res.setHeader('Content-Type', 'application/json');
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.end(catalogs);
|
||||||
res.end(catalogs);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
res.end();
|
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
logger.error({ message: err, path: req.url });
|
logger.error({ message: err, path: req.url });
|
||||||
@ -196,12 +175,8 @@ module.exports.catalogsbysourceGet = function catalogsbysourceGet(req, res, next
|
|||||||
return monorail.get_catalog_data_by_source(req.swagger.params.identifier.value,
|
return monorail.get_catalog_data_by_source(req.swagger.params.identifier.value,
|
||||||
req.swagger.params.source.value).
|
req.swagger.params.source.value).
|
||||||
then(function (catalogs) {
|
then(function (catalogs) {
|
||||||
if (typeof catalogs !== 'undefined') {
|
res.setHeader('Content-Type', 'application/json');
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.end(catalogs);
|
||||||
res.end(catalogs);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
res.end();
|
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
logger.error({ message: err, path: req.url });
|
logger.error({ message: err, path: req.url });
|
||||||
@ -218,12 +193,8 @@ module.exports.catalogsbysourceGet = function catalogsbysourceGet(req, res, next
|
|||||||
module.exports.nodeGet = function nodeGet(req, res, next) {
|
module.exports.nodeGet = function nodeGet(req, res, next) {
|
||||||
return monorail.request_node_get(req.swagger.params.identifier.value).
|
return monorail.request_node_get(req.swagger.params.identifier.value).
|
||||||
then(function (node) {
|
then(function (node) {
|
||||||
if (typeof node !== 'undefined') {
|
res.setHeader('Content-Type', 'application/json');
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.end(node);
|
||||||
res.end(node);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
res.end();
|
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
logger.error({ message: err, path: req.url });
|
logger.error({ message: err, path: req.url });
|
||||||
@ -244,12 +215,8 @@ module.exports.nodesGet = function nodesGet(req, res, next) {
|
|||||||
return monorail.lookupCatalog(node);
|
return monorail.lookupCatalog(node);
|
||||||
})
|
})
|
||||||
.then(function (discoveredNodes) {
|
.then(function (discoveredNodes) {
|
||||||
if (typeof discoveredNodes !== 'undefined') {
|
res.setHeader('Content-Type', 'application/json');
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.end(JSON.stringify(discoveredNodes));
|
||||||
res.end(JSON.stringify(discoveredNodes));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
res.end();
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
@ -267,21 +234,16 @@ module.exports.nodesGet = function nodesGet(req, res, next) {
|
|||||||
module.exports.getSeldata = function getSeldata(req, res, next) {
|
module.exports.getSeldata = function getSeldata(req, res, next) {
|
||||||
return monorail.request_poller_get(req.swagger.params.identifier.value).
|
return monorail.request_poller_get(req.swagger.params.identifier.value).
|
||||||
then(function (pollers) {
|
then(function (pollers) {
|
||||||
if (typeof pollers !== 'undefined') {
|
pollers = JSON.parse(pollers);
|
||||||
pollers = JSON.parse(pollers);
|
for (var i in pollers) {
|
||||||
for (var i in pollers) {
|
if (pollers[i]['config']['command'] === 'sel') {
|
||||||
if (pollers[i]['config']['command'] === 'sel') {
|
return monorail.request_poller_data_get(pollers[i]['id']).
|
||||||
return monorail.request_poller_data_get(pollers[i]['id']).
|
then(function (data) {
|
||||||
then(function (data) {
|
res.setHeader('Content-Type', 'application/json');
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.end(data);
|
||||||
res.end(data);
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
res.end();
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
logger.error({ message: err, path: req.url });
|
logger.error({ message: err, path: req.url });
|
||||||
@ -460,7 +422,6 @@ module.exports.unregisterdel = function unregisterdel(req, res, next) {
|
|||||||
res.setHeader('Content-Type', 'application/json');
|
res.setHeader('Content-Type', 'application/json');
|
||||||
res.end(JSON.stringify(err));
|
res.end(JSON.stringify(err));
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -567,7 +528,6 @@ function setConfig(keyValue, entry) {
|
|||||||
var content = (keyValue == null) ? output : output[keyValue];
|
var content = (keyValue == null) ? output : output[keyValue];
|
||||||
var filteredList = _.pick(content, Object.keys(entry));
|
var filteredList = _.pick(content, Object.keys(entry));
|
||||||
_.each(Object.keys(filteredList), function (key) {
|
_.each(Object.keys(filteredList), function (key) {
|
||||||
logger.info(key);
|
|
||||||
content[key] = entry[key];
|
content[key] = entry[key];
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -581,7 +541,6 @@ function setConfig(keyValue, entry) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -594,7 +553,6 @@ module.exports.configget = function configget(req, res, next) {
|
|||||||
var filename = 'config.json';
|
var filename = 'config.json';
|
||||||
jsonfile.readFile(filename, function (err, content) {
|
jsonfile.readFile(filename, function (err, content) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
delete content['key'];
|
delete content['key'];
|
||||||
if (content.ironic.hasOwnProperty("os_password")) {
|
if (content.ironic.hasOwnProperty("os_password")) {
|
||||||
content.ironic.os_password = '[REDACTED]';
|
content.ironic.os_password = '[REDACTED]';
|
||||||
@ -607,7 +565,8 @@ module.exports.configget = function configget(req, res, next) {
|
|||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
res.end();
|
res.setHeader('content-type', 'text/plain');
|
||||||
|
res.end('failed to get config');
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -624,12 +583,8 @@ module.exports.imagesGet = function imagesGet(req, res, next) {
|
|||||||
return glance.get_images(token);
|
return glance.get_images(token);
|
||||||
}).
|
}).
|
||||||
then(function (result) {
|
then(function (result) {
|
||||||
if (typeof result !== 'undefined') {
|
res.setHeader('Content-Type', 'application/json');
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.end(result);
|
||||||
res.end(result);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
res.end();
|
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
logger.error({ message: err, path: req.url });
|
logger.error({ message: err, path: req.url });
|
||||||
|
@ -1,26 +1,30 @@
|
|||||||
|
// Copyright 2015, EMC, Inc.
|
||||||
|
|
||||||
var winston = require('winston');
|
var winston = require('winston');
|
||||||
|
|
||||||
var logger = new (winston.Logger)({
|
module.exports.Logger = function Logger(level) {
|
||||||
levels: {
|
var logger = new (winston.Logger)({
|
||||||
verbose: 4,
|
levels: {
|
||||||
debug: 3,
|
verbose: 5,
|
||||||
info: 2,
|
debug: 4,
|
||||||
warn: 1,
|
info: 3,
|
||||||
error: 0
|
warn: 2,
|
||||||
},
|
error: 1,
|
||||||
colors: {
|
mask: 0
|
||||||
verbose: 'cyan',
|
},
|
||||||
debug: 'blue',
|
colors: {
|
||||||
info: 'green',
|
verbose: 'cyan',
|
||||||
warn: 'yellow',
|
debug: 'blue',
|
||||||
error: 'red'
|
info: 'green',
|
||||||
}
|
warn: 'yellow',
|
||||||
}).add(winston.transports.Console, {
|
error: 'red'
|
||||||
level: 'info',
|
}
|
||||||
prettyPrint: true,
|
}).add(winston.transports.Console, {
|
||||||
colorize: true,
|
level: level,
|
||||||
silent: false,
|
prettyPrint: true,
|
||||||
timestamp: true
|
colorize: true,
|
||||||
});
|
silent: false,
|
||||||
|
timestamp: true
|
||||||
exports.Logger = logger;
|
});
|
||||||
|
return logger;
|
||||||
|
}
|
@ -1,9 +1,11 @@
|
|||||||
|
// Copyright 2015, EMC, Inc.
|
||||||
|
|
||||||
var monorail = require('./../api/monorail/monorail');
|
var monorail = require('./../api/monorail/monorail');
|
||||||
var ironic = require('./../api/openstack/ironic');
|
var ironic = require('./../api/openstack/ironic');
|
||||||
var keystone = require('./../api/openstack/keystone');
|
var keystone = require('./../api/openstack/keystone');
|
||||||
var _ = require('underscore');
|
var _ = require('underscore');
|
||||||
var config = require('./../../config.json');
|
var config = require('./../../config.json');
|
||||||
var logger = require('./logger').Logger;
|
var logger = require('./logger').Logger('error');
|
||||||
|
|
||||||
module.exports = Poller;
|
module.exports = Poller;
|
||||||
var ironicConfig = config.ironic;
|
var ironicConfig = config.ironic;
|
||||||
@ -15,23 +17,23 @@ function Poller(timeInterval) {
|
|||||||
Poller.prototype.getToken = function () {
|
Poller.prototype.getToken = function () {
|
||||||
var self = this;
|
var self = this;
|
||||||
return keystone.authenticatePassword(ironicConfig.os_tenant_name,
|
return keystone.authenticatePassword(ironicConfig.os_tenant_name,
|
||||||
ironicConfig.os_username,ironicConfig.os_password).
|
ironicConfig.os_username, ironicConfig.os_password).
|
||||||
then(function (token) {
|
then(function (token) {
|
||||||
self._ironicToken = token = JSON.parse(token).access.token.id;
|
self._ironicToken = token = JSON.parse(token).access.token.id;
|
||||||
return token;
|
return token;
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
return null;
|
return (null);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Poller.prototype.stopServer = function () {
|
Poller.prototype.stopServer = function () {
|
||||||
try{
|
try {
|
||||||
clearInterval(this.timeObj);
|
clearInterval(this.timeObj);
|
||||||
this.timeObj = 0;
|
this.timeObj = 0;
|
||||||
}
|
}
|
||||||
catch(err){
|
catch (err) {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -46,9 +48,8 @@ function Poller(timeInterval) {
|
|||||||
|
|
||||||
Poller.prototype.searchIronic = function (ironic_node) {
|
Poller.prototype.searchIronic = function (ironic_node) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return ironic.get_node(self._ironicToken, ironic_node.uuid).
|
var node_data = ironic_node;
|
||||||
then(function (node_data) {
|
try {
|
||||||
node_data = JSON.parse(node_data);
|
|
||||||
if (node_data != undefined &&
|
if (node_data != undefined &&
|
||||||
node_data.extra && node_data.extra.timer) {
|
node_data.extra && node_data.extra.timer) {
|
||||||
if (!node_data.extra.timer.stop) {
|
if (!node_data.extra.timer.stop) {
|
||||||
@ -61,23 +62,23 @@ function Poller(timeInterval) {
|
|||||||
node_data.extra.timer.start = new Date().toJSON();
|
node_data.extra.timer.start = new Date().toJSON();
|
||||||
if (node_data.extra.timer.isDone) {
|
if (node_data.extra.timer.isDone) {
|
||||||
node_data.extra.timer.isDone = false;
|
node_data.extra.timer.isDone = false;
|
||||||
self.updateInfo(self._ironicToken, node_data).
|
return self.updateInfo(self._ironicToken, node_data).
|
||||||
then(function (data) {
|
then(function (data) {
|
||||||
return self.patchData(node_data.uuid, JSON.stringify(data));
|
return self.patchData(node_data.uuid, JSON.stringify(data));
|
||||||
}).
|
}).
|
||||||
then(function (result) {
|
then(function (result) {
|
||||||
return result;
|
return (result);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
return Promise.resolve(null);
|
||||||
.catch(function (err) {
|
}
|
||||||
|
catch (err) {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
return null;
|
return Promise.resolve(null);
|
||||||
});
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
Poller.prototype.getNodes = function (token) {
|
Poller.prototype.getNodes = function (token) {
|
||||||
@ -87,7 +88,7 @@ function Poller(timeInterval) {
|
|||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
return null;
|
return (null);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -97,21 +98,20 @@ function Poller(timeInterval) {
|
|||||||
then(function (result) {
|
then(function (result) {
|
||||||
result = JSON.parse(result);
|
result = JSON.parse(result);
|
||||||
if (result != undefined) {
|
if (result != undefined) {
|
||||||
return result.extra;
|
return (result.extra);
|
||||||
}
|
}
|
||||||
return null;
|
return (null);
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
return null;
|
return (null);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Poller.prototype.updateInfo = function (token, node_data) {
|
Poller.prototype.updateInfo = function (token, node_data) {
|
||||||
var self = this;
|
|
||||||
return this.getSeldata(node_data.extra.nodeid).
|
return this.getSeldata(node_data.extra.nodeid).
|
||||||
then(function (result) {
|
then(function (result) {
|
||||||
if (result != undefined) {
|
if (result != null) {
|
||||||
var lastEvent = {};
|
var lastEvent = {};
|
||||||
result = JSON.parse(result);
|
result = JSON.parse(result);
|
||||||
if (result[0] && result[0].hasOwnProperty('sel')) {
|
if (result[0] && result[0].hasOwnProperty('sel')) {
|
||||||
@ -131,11 +131,11 @@ function Poller(timeInterval) {
|
|||||||
node_data.extra.timer.isDone = true;
|
node_data.extra.timer.isDone = true;
|
||||||
node_data.extra.events = lastEvent;
|
node_data.extra.events = lastEvent;
|
||||||
var data = [{ 'path': '/extra', 'value': node_data.extra, 'op': 'replace' }];
|
var data = [{ 'path': '/extra', 'value': node_data.extra, 'op': 'replace' }];
|
||||||
return data;
|
return (data);
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
return null;
|
return (null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,19 +17,18 @@
|
|||||||
"should": "~7.0.1",
|
"should": "~7.0.1",
|
||||||
"mocha": "^2.1.0",
|
"mocha": "^2.1.0",
|
||||||
"sinon": "1.16.1",
|
"sinon": "1.16.1",
|
||||||
"sinon-as-promised": "^2.0.3",
|
|
||||||
"sinon-chai": "^2.7.0",
|
|
||||||
"supertest": "^0.15.0",
|
"supertest": "^0.15.0",
|
||||||
"underscore": "^1.8.3",
|
"underscore": "^1.8.3",
|
||||||
"xunit-file": "0.0.6",
|
"xunit-file": "0.0.6",
|
||||||
"winston": "2.1.1",
|
"winston": "2.1.1",
|
||||||
"jsonfile": "2.2.3",
|
"jsonfile": "2.2.3",
|
||||||
"crypto": "0.0.3",
|
"crypto": "0.0.3",
|
||||||
"istanbul": "0.4.1"
|
"istanbul": "0.4.1",
|
||||||
|
"nock": "3.6.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"postinstall": "scripts/post-install.sh",
|
"postinstall": "scripts/post-install.sh",
|
||||||
"start": "start shovel",
|
"start": "start shovel",
|
||||||
"test": "istanbul cover -x '**/test/**' ./node_modules/.bin/_mocha test/* && istanbul report cobertura"
|
"test": "istanbul cover -x '**/test/**' node_modules/mocha/bin/_mocha test/api/* test/services/* test/controllers/* && istanbul report cobertura"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
199
Shovel/test/api/client.js
Normal file
199
Shovel/test/api/client.js
Normal file
@ -0,0 +1,199 @@
|
|||||||
|
// Copyright 2015, EMC, Inc.
|
||||||
|
|
||||||
|
var should = require('should');
|
||||||
|
var client = require('./../../lib/api/client');
|
||||||
|
var Promise = require('bluebird');
|
||||||
|
var nock = require('nock');
|
||||||
|
Promise.promisifyAll(client);
|
||||||
|
|
||||||
|
describe('client with http requests', function () {
|
||||||
|
var option = { host: 'localhost', port: 7070, path: '/api/', token: '', data: '{"auth":{"tenantName":"admin" }}', api: '' };
|
||||||
|
it('get return data from targeted server', function (done) {
|
||||||
|
nock('http://localhost:7070/api')
|
||||||
|
.get('/')
|
||||||
|
.reply(200, { data: 'data from server' });
|
||||||
|
return client.GetAsync(option)
|
||||||
|
.then(function (result) {
|
||||||
|
JSON.parse(result).should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('get return data from targeted server with a token', function (done) {
|
||||||
|
nock('http://localhost:7070/api')
|
||||||
|
.get('/')
|
||||||
|
.reply(200, { data: 'data from server' });
|
||||||
|
option.token = '1234';
|
||||||
|
return client.GetAsync(option)
|
||||||
|
.then(function (result) {
|
||||||
|
JSON.parse(result).should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('get return data from targeted server', function (done) {
|
||||||
|
return client.GetAsync(option)
|
||||||
|
.catch(function (result) {
|
||||||
|
result.should.have.property('errorMessage');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('post return data from targeted server', function (done) {
|
||||||
|
nock('http://localhost:7070/api')
|
||||||
|
.post('/')
|
||||||
|
.reply(200, { data: 'data from server' });
|
||||||
|
|
||||||
|
return client.PostAsync(option)
|
||||||
|
.then(function (result) {
|
||||||
|
JSON.parse(result).should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('post return data from targeted server', function (done) {
|
||||||
|
nock('http://localhost:7070/api')
|
||||||
|
.post('/')
|
||||||
|
.reply(200, { data: 'data from server' });
|
||||||
|
option.token = '1234';
|
||||||
|
return client.PostAsync(option)
|
||||||
|
.then(function (result) {
|
||||||
|
JSON.parse(result).should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('post return data from targeted server', function (done) {
|
||||||
|
nock('http://localhost:7070/api')
|
||||||
|
.post('/')
|
||||||
|
.reply(200, { data: 'data from server' });
|
||||||
|
return client.PostAsync(option)
|
||||||
|
.then(function (result) {
|
||||||
|
JSON.parse(result).should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('post return data from targeted server', function (done) {
|
||||||
|
nock('http://localhost:7070/api')
|
||||||
|
.post('/')
|
||||||
|
.reply(200, { data: 'data from server' });
|
||||||
|
option.token = '1234';
|
||||||
|
return client.PostAsync(option)
|
||||||
|
.then(function (result) {
|
||||||
|
JSON.parse(result).should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('post return data from targeted server', function (done) {
|
||||||
|
return client.PostAsync(option)
|
||||||
|
.catch(function (result) {
|
||||||
|
result.should.have.property('errorMessage');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('delete return data from targeted server', function (done) {
|
||||||
|
nock('http://localhost:7070/api')
|
||||||
|
.delete('/')
|
||||||
|
.reply(200, { data: 'data from server' });
|
||||||
|
|
||||||
|
return client.DeleteAsync(option)
|
||||||
|
.then(function (result) {
|
||||||
|
JSON.parse(result).should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('delete return data from targeted server', function (done) {
|
||||||
|
nock('http://localhost:7070/api')
|
||||||
|
.delete('/')
|
||||||
|
.reply(200, { data: 'data from server' });
|
||||||
|
option.token = '1234';
|
||||||
|
return client.DeleteAsync(option)
|
||||||
|
.then(function (result) {
|
||||||
|
JSON.parse(result).should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('delete return data from targeted server', function (done) {
|
||||||
|
return client.DeleteAsync(option)
|
||||||
|
.catch(function (result) {
|
||||||
|
result.should.have.property('errorMessage');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('put return data from targeted server', function (done) {
|
||||||
|
nock('http://localhost:7070/api')
|
||||||
|
.put('/')
|
||||||
|
.reply(200, { data: 'data from server' });
|
||||||
|
|
||||||
|
return client.PutAsync(option)
|
||||||
|
.then(function (result) {
|
||||||
|
JSON.parse(result).should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('put return data from targeted server', function (done) {
|
||||||
|
nock('http://localhost:7070/api')
|
||||||
|
.put('/')
|
||||||
|
.reply(200, { data: 'data from server' });
|
||||||
|
option.token = '1234';
|
||||||
|
return client.PutAsync(option)
|
||||||
|
.then(function (result) {
|
||||||
|
JSON.parse(result).should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('put return data from targeted server', function (done) {
|
||||||
|
nock('http://localhost:7070/api')
|
||||||
|
.put('/')
|
||||||
|
.reply(200, { data: 'data from server' });
|
||||||
|
return client.PutAsync(option)
|
||||||
|
.then(function (result) {
|
||||||
|
JSON.parse(result).should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('put return data from targeted server', function (done) {
|
||||||
|
return client.PutAsync(option)
|
||||||
|
.catch(function (result) {
|
||||||
|
result.should.have.property('errorMessage');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('path return data from targeted server', function (done) {
|
||||||
|
nock('http://localhost:7070/api')
|
||||||
|
.patch('/')
|
||||||
|
.reply(200, { data: 'data from server' });
|
||||||
|
return client.PatchAsync(option)
|
||||||
|
.then(function (result) {
|
||||||
|
JSON.parse(result).should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('patch return data from targeted server', function (done) {
|
||||||
|
nock('http://localhost:7070/api')
|
||||||
|
.patch('/')
|
||||||
|
.reply(200, { data: 'data from server' });
|
||||||
|
option.token = '1234';
|
||||||
|
return client.PatchAsync(option)
|
||||||
|
.then(function (result) {
|
||||||
|
JSON.parse(result).should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('patch return data from targeted server', function (done) {
|
||||||
|
nock('http://localhost:7070/api')
|
||||||
|
.patch('/')
|
||||||
|
.reply(200, { data: 'data from server' });
|
||||||
|
return client.PatchAsync(option)
|
||||||
|
.then(function (result) {
|
||||||
|
JSON.parse(result).should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('patch return data from targeted server', function (done) {
|
||||||
|
return client.PatchAsync(option)
|
||||||
|
.catch(function (result) {
|
||||||
|
result.should.have.property('errorMessage');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
113
Shovel/test/api/ironic.js
Normal file
113
Shovel/test/api/ironic.js
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
// Copyright 2015, EMC, Inc.
|
||||||
|
|
||||||
|
var request = require('supertest');
|
||||||
|
var should = require('should');
|
||||||
|
var sinon = require('sinon');
|
||||||
|
var ironic = require('./../../lib/api/openstack/ironic');
|
||||||
|
var client = require('./../../lib/api/client');
|
||||||
|
var Promise = require('bluebird');
|
||||||
|
Promise.promisifyAll(client);
|
||||||
|
|
||||||
|
describe('****Ironic Lib****', function () {
|
||||||
|
beforeEach('set up mocks', function () {
|
||||||
|
var output = ({ data: 'ironic service' });
|
||||||
|
sinon.stub(client, 'GetAsync').returns(Promise.resolve(output));
|
||||||
|
sinon.stub(client, 'PostAsync').returns(Promise.resolve(output));
|
||||||
|
sinon.stub(client, 'PatchAsync').returns(Promise.resolve(output));
|
||||||
|
sinon.stub(client, 'PutAsync').returns(Promise.resolve(output));
|
||||||
|
sinon.stub(client, 'DeleteAsync').returns(Promise.resolve(output));
|
||||||
|
});
|
||||||
|
afterEach('teardown mocks', function () {
|
||||||
|
client['GetAsync'].restore();
|
||||||
|
client['PostAsync'].restore();
|
||||||
|
client['PatchAsync'].restore();
|
||||||
|
client['PutAsync'].restore();
|
||||||
|
client['DeleteAsync'].restore();
|
||||||
|
|
||||||
|
});
|
||||||
|
it('ironic.get_chassis return data from ironic', function (done) {
|
||||||
|
return ironic.get_chassis('123')
|
||||||
|
.then(function (result) {
|
||||||
|
result.should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('get_chassis_by_id return data from ironic', function (done) {
|
||||||
|
return ironic.get_chassis_by_id('123', '123')
|
||||||
|
.then(function (result) {
|
||||||
|
result.should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('get_chassis_by_id return data from ironic', function (done) {
|
||||||
|
return ironic.get_node_list('123')
|
||||||
|
.then(function (result) {
|
||||||
|
result.should.have.property('data');
|
||||||
|
done();
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('get_node return data from ironic', function (done) {
|
||||||
|
return ironic.get_node('123', '123')
|
||||||
|
.then(function (result) {
|
||||||
|
result.should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('patch_node return data from ironic', function (done) {
|
||||||
|
return ironic.patch_node('123', '123', {})
|
||||||
|
.then(function (result) {
|
||||||
|
result.should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('delete_node return data from ironic', function (done) {
|
||||||
|
return ironic.delete_node('123', '123')
|
||||||
|
.then(function (result) {
|
||||||
|
result.should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('get_port_list return data from ironic', function (done) {
|
||||||
|
return ironic.get_port_list('123')
|
||||||
|
.then(function (result) {
|
||||||
|
result.should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('get_port return data from ironic', function (done) {
|
||||||
|
return ironic.get_port('123', 'identifier')
|
||||||
|
.then(function (result) {
|
||||||
|
result.should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('set_power_state on return data from ironic', function (done) {
|
||||||
|
return ironic.set_power_state('123', 'identifier', 'on')
|
||||||
|
.then(function (result) {
|
||||||
|
result.should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('set_power_state off return data from ironic', function (done) {
|
||||||
|
return ironic.set_power_state('123', 'identifier', 'off')
|
||||||
|
.then(function (result) {
|
||||||
|
result.should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('set_power_state reboot return data from ironic', function (done) {
|
||||||
|
return ironic.set_power_state('123', 'identifier', 'reboot')
|
||||||
|
.then(function (result) {
|
||||||
|
result.should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('get_driver_list return data from ironic', function (done) {
|
||||||
|
return ironic.get_driver_list('123')
|
||||||
|
.then(function (result) {
|
||||||
|
result.should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -1,83 +1,76 @@
|
|||||||
var request = require('supertest');
|
// Copyright 2015, EMC, Inc.
|
||||||
|
|
||||||
var should = require('should');
|
var should = require('should');
|
||||||
var assert = require('assert');
|
|
||||||
var sinon = require('sinon');
|
var sinon = require('sinon');
|
||||||
var monorail = require('./../../lib/api/monorail/monorail');
|
var monorail = require('./../../lib/api/monorail/monorail');
|
||||||
var Promise = require('bluebird');
|
var Promise = require('bluebird');
|
||||||
var _ = require('underscore');
|
var _ = require('underscore');
|
||||||
|
var client = require('./../../lib/api/client');
|
||||||
|
var Promise = require('bluebird');
|
||||||
|
Promise.promisifyAll(client);
|
||||||
|
|
||||||
|
describe('****Monorail Lib****',function(){
|
||||||
|
var rackhdNode = [{ workflows: [], autoDiscover: false, identifiers: ["2c:60:0c:83:f5:d1"], name: "2c:60:0c:83:f5:d1", sku: null, type: "compute", id: "5668b6ad8bee16a10989e4e5" }];
|
||||||
|
var catalogSource = [{ source: 'dmi', data: {'Memory Device': [{ Size: '1 GB' }, { Size: '1 GB' }],
|
||||||
|
'Processor Information': [{}, {}] }}, { source: 'lsscsi', data: [{ peripheralType: 'disk', size: '1GB' }] }];
|
||||||
|
var rackhdNode =[ { workflows: [], autoDiscover: false, identifiers: ["2c:60:0c:83:f5:d1"], name: "2c:60:0c:83:f5:d1", sku: null, type: "compute", id: "5668b6ad8bee16a10989e4e5" }];
|
||||||
|
var identifier = '123456789';
|
||||||
|
|
||||||
var rackhdNode = [{ workflows: [], autoDiscover: false, identifiers: ["2c:60:0c:83:f5:d1"], name: "2c:60:0c:83:f5:d1", sku: null, type: "compute", id: "5668b6ad8bee16a10989e4e5" }];
|
describe('monorail nodeDiskSize get_node_memory_cpu', function () {
|
||||||
var catalogSource = [{ source: 'dmi', data: {'Memory Device': [{ Size: '1 GB' }, { Size: '1 GB' }],
|
describe('monorail get_node_memory_cpu', function () {
|
||||||
'Processor Information': [{}, {}] }}, { source: 'lsscsi', data: [{ peripheralType: 'disk', size: '1GB' }] }];
|
afterEach('teardown mocks', function () {
|
||||||
var rackhdNode =[ { workflows: [], autoDiscover: false, identifiers: ["2c:60:0c:83:f5:d1"], name: "2c:60:0c:83:f5:d1", sku: null, type: "compute", id: "5668b6ad8bee16a10989e4e5" }];
|
//monorail
|
||||||
var identifier = '123456789';
|
monorail['get_catalog_data_by_source'].restore();
|
||||||
|
});
|
||||||
|
|
||||||
describe('monorail nodeDiskSize', function () {
|
it('response should returns an integer with value equal to memory size 2000MB and cpus=2', function (done) {
|
||||||
|
sinon.stub(monorail, 'get_catalog_data_by_source').returns(Promise.resolve(JSON.stringify(catalogSource[0])));
|
||||||
|
return monorail.get_node_memory_cpu(rackhdNode).
|
||||||
|
then(function (result) {
|
||||||
|
result.cpus.should.be.exactly(2);
|
||||||
|
result.memory.should.be.exactly(2000);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('nodeDiskSize', function () {
|
||||||
|
beforeEach('set up mocks', function () {
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach('set up mocks', function () {
|
afterEach('teardown mocks', function () {
|
||||||
//monorail
|
//monorail
|
||||||
sinon.stub(monorail, 'get_catalog_data_by_source').returns(Promise.resolve(JSON.stringify(catalogSource[1])));
|
monorail['get_catalog_data_by_source'].restore();
|
||||||
|
});
|
||||||
|
it('response should returns an integer with value equal to disk size 1GB', function (done) {
|
||||||
|
//monorail
|
||||||
|
sinon.stub(monorail, 'get_catalog_data_by_source').returns(Promise.resolve(JSON.stringify(catalogSource[1])));
|
||||||
|
return monorail.nodeDiskSize(rackhdNode).
|
||||||
|
then(function (result) {
|
||||||
|
result.should.be.exactly(1);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
it('response should returns an integer with value equal to 0', function (done) {
|
||||||
|
//monorail
|
||||||
afterEach('teardown mocks', function () {
|
sinon.stub(monorail, 'get_catalog_data_by_source').returns(Promise.resolve(JSON.stringify({})));
|
||||||
//monorail
|
return monorail.nodeDiskSize(rackhdNode).
|
||||||
monorail['get_catalog_data_by_source'].restore();
|
then(function (result) {
|
||||||
});
|
result.should.be.exactly(0);
|
||||||
|
done();
|
||||||
describe('nodeDiskSize', function () {
|
});
|
||||||
it('response should returns an integer with value equal to disk size 1GB', function (done) {
|
|
||||||
return monorail.nodeDiskSize(rackhdNode).
|
|
||||||
then(function (result) {
|
|
||||||
result.should.be.exactly(1);
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('monorail get_node_memory_cpu', function () {
|
|
||||||
beforeEach('set up mocks', function () {
|
|
||||||
//monorail
|
|
||||||
sinon.stub(monorail, 'get_catalog_data_by_source').returns(Promise.resolve(JSON.stringify(catalogSource[0])));
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach('teardown mocks', function () {
|
|
||||||
//monorail
|
|
||||||
monorail['get_catalog_data_by_source'].restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('get_node_memory_cpu', function () {
|
|
||||||
it('response should returns an integer with value equal to memory size 2000MB and cpus=2', function (done) {
|
|
||||||
return monorail.get_node_memory_cpu(rackhdNode).
|
|
||||||
then(function (result) {
|
|
||||||
result.cpus.should.be.exactly(2);
|
|
||||||
result.memory.should.be.exactly(2000);
|
|
||||||
done();
|
|
||||||
})
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('lookupCatalog true', function () {
|
|
||||||
beforeEach('set up mocks', function () {
|
|
||||||
//monorail
|
|
||||||
sinon.stub(monorail, 'get_catalog_data_by_source').returns(Promise.resolve(JSON.stringify(catalogSource[0])));
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach('teardown mocks', function () {
|
|
||||||
//monorail
|
|
||||||
monorail['get_catalog_data_by_source'].restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('lookupCatalog', function () {
|
describe('lookupCatalog', function () {
|
||||||
|
afterEach('teardown mocks', function () {
|
||||||
|
//monorail
|
||||||
|
monorail['get_catalog_data_by_source'].restore();
|
||||||
|
});
|
||||||
it('lookupCatalog response should be equal to true', function (done) {
|
it('lookupCatalog response should be equal to true', function (done) {
|
||||||
|
sinon.stub(monorail, 'get_catalog_data_by_source').returns(Promise.resolve(JSON.stringify(catalogSource[0])));
|
||||||
return monorail.lookupCatalog(rackhdNode[0]).
|
return monorail.lookupCatalog(rackhdNode[0]).
|
||||||
then(function (result) {
|
then(function (result) {
|
||||||
console.log(result);
|
|
||||||
JSON.parse(result).should.be.exactly(true);
|
JSON.parse(result).should.be.exactly(true);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
@ -85,26 +78,10 @@ describe('lookupCatalog true', function () {
|
|||||||
throw err;
|
throw err;
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('lookupCatalog false', function () {
|
|
||||||
beforeEach('set up mocks', function () {
|
|
||||||
//monorail
|
|
||||||
sinon.stub(monorail, 'get_catalog_data_by_source').returns(Promise.resolve(JSON.stringify({})));
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach('teardown mocks', function () {
|
|
||||||
//monorail
|
|
||||||
monorail['get_catalog_data_by_source'].restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('lookupCatalog', function () {
|
|
||||||
it('lookupCatalog response should be equal to fasle if catalog does not have property data', function (done) {
|
it('lookupCatalog response should be equal to fasle if catalog does not have property data', function (done) {
|
||||||
|
sinon.stub(monorail, 'get_catalog_data_by_source').returns(Promise.resolve(JSON.stringify({})));
|
||||||
return monorail.lookupCatalog(rackhdNode[0]).
|
return monorail.lookupCatalog(rackhdNode[0]).
|
||||||
then(function (result) {
|
then(function (result) {
|
||||||
console.log(result);
|
|
||||||
JSON.parse(result).should.be.exactly(false);
|
JSON.parse(result).should.be.exactly(false);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
@ -113,7 +90,79 @@ describe('lookupCatalog false', function () {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('monorail with client get/post/patch/delete returns data', function () {
|
||||||
|
beforeEach('set up mocks', function () {
|
||||||
|
var output = ({ data: 'monorail service' });
|
||||||
|
sinon.stub(client, 'GetAsync').returns(Promise.resolve(output));
|
||||||
|
sinon.stub(client, 'PostAsync').returns(Promise.resolve(output));
|
||||||
|
sinon.stub(client, 'PatchAsync').returns(Promise.resolve(output));
|
||||||
|
sinon.stub(client, 'PutAsync').returns(Promise.resolve(output));
|
||||||
|
sinon.stub(client, 'DeleteAsync').returns(Promise.resolve(output));
|
||||||
|
});
|
||||||
|
afterEach('teardown mocks', function () {
|
||||||
|
client['GetAsync'].restore();
|
||||||
|
client['PostAsync'].restore();
|
||||||
|
client['PatchAsync'].restore();
|
||||||
|
client['PutAsync'].restore();
|
||||||
|
client['DeleteAsync'].restore();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('monorail.request_nodes_get return data from monorail', function (done) {
|
||||||
|
return monorail.request_nodes_get()
|
||||||
|
.then(function (result) {
|
||||||
|
result.should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('monorail.request_node_get return data from monorail', function (done) {
|
||||||
|
return monorail.request_node_get('123')
|
||||||
|
.then(function (result) {
|
||||||
|
result.should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('monorail.request_whitelist_set return data from monorail', function (done) {
|
||||||
|
return monorail.request_whitelist_set('123')
|
||||||
|
.then(function (result) {
|
||||||
|
result.should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('monorail.request_whitelist_del return data from monorail', function (done) {
|
||||||
|
return monorail.request_whitelist_del('123')
|
||||||
|
.then(function (result) {
|
||||||
|
result.should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('monorail.request_catalogs_get return data from monorail', function (done) {
|
||||||
|
return monorail.request_catalogs_get('123')
|
||||||
|
.then(function (result) {
|
||||||
|
result.should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('monorail.get_catalog_data_by_source return data from monorail', function (done) {
|
||||||
|
return monorail.get_catalog_data_by_source('123', 'bmc')
|
||||||
|
.then(function (result) {
|
||||||
|
result.should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('monorail.request_poller_get return data from monorail', function (done) {
|
||||||
|
return monorail.request_poller_get('123')
|
||||||
|
.then(function (result) {
|
||||||
|
result.should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('monorail.request_poller_data_get return data from monorail', function (done) {
|
||||||
|
return monorail.request_poller_data_get('123')
|
||||||
|
.then(function (result) {
|
||||||
|
result.should.have.property('data');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
@ -1,284 +1,242 @@
|
|||||||
|
// Copyright 2015, EMC, Inc.
|
||||||
|
|
||||||
var request = require('supertest');
|
var request = require('supertest');
|
||||||
var should = require('should');
|
var should = require('should');
|
||||||
var assert = require('assert');
|
|
||||||
var sinon = require('sinon');
|
var sinon = require('sinon');
|
||||||
var monorail = require('./../../lib/api/monorail/monorail');
|
var monorail = require('./../../lib/api/monorail/monorail');
|
||||||
var ironic = require('./../../lib/api/openstack/ironic');
|
var ironic = require('./../../lib/api/openstack/ironic');
|
||||||
var keystone = require('./../../lib/api/openstack/keystone');
|
var keystone = require('./../../lib/api/openstack/keystone');
|
||||||
|
var glance = require('./../../lib/api/openstack/glance');
|
||||||
var Promise = require('bluebird');
|
var Promise = require('bluebird');
|
||||||
var _ = require('underscore');
|
var _ = require('underscore');
|
||||||
var helper = require('./../helper');
|
var helper = require('./../helper');
|
||||||
var url = 'http://localhost:9008';
|
var url = 'http://localhost:9008';
|
||||||
|
|
||||||
|
|
||||||
|
describe('****SHOVEL API Interface****', function () {
|
||||||
|
|
||||||
|
var rackhdNode = [{ workflows: [], autoDiscover: false, identifiers: ["2c:60:0c:83:f5:d1"], name: "2c:60:0c:83:f5:d1", sku: null, type: "compute", id: "5668b6ad8bee16a10989e4e5" }];
|
||||||
|
var identifier = '9a761508-4eee-4065-b47b-45c22dff54c2';
|
||||||
var rackhdNode =[ { workflows: [], autoDiscover: false, identifiers: ["2c:60:0c:83:f5:d1"], name: "2c:60:0c:83:f5:d1", sku: null, type: "compute", id: "5668b6ad8bee16a10989e4e5" }];
|
var ironic_node_list = [{ uuid: "9a761508-4eee-4065-b47b-45c22dff54c2", extra: { name: "D51B-2U (dual 10G LoM)", eventre: "", nodeid: "564cefa014ee77be18e48efd",
|
||||||
var identifier = '9a761508-4eee-4065-b47b-45c22dff54c2';
|
timer: { start: "2015-11-30T21:14:11.753Z", finish: "2015-11-30T21:14:11.772Z", stop: false, isDone: true, timeInteval: 5000 }, eventcnt: 0 } } ];
|
||||||
var ironic_node_list = [ { uuid: "9a761508-4eee-4065-b47b-45c22dff54c2", extra: { name: "D51B-2U (dual 10G LoM)", eventre: "", nodeid: "564cefa014ee77be18e48efd",
|
var nodePollers = [{ config: { command: "sel" }, id: "564dd86285fb1e7c72721543" }];
|
||||||
timer: { start: "2015-11-30T21:14:11.753Z", finish: "2015-11-30T21:14:11.772Z", stop: false, isDone: true, timeInteval: 5000 }, eventcnt: 0 } }];
|
var _sel = { sel: [{ logId: "1", date: "12/03/2015", time: "08:54:11", sensorType: "Memory", sensorNumber: "#0x53", event: "Correctable ECC", value: "Asserted" }] };
|
||||||
var nodePollers = [{ config: { command: "sel" }, id: "564dd86285fb1e7c72721543" }];
|
var keyToken = { access: { token: { id: '123456' } } };
|
||||||
var _sel = { sel:[ { logId: "1", date: "12/03/2015", time: "08:54:11", sensorType: "Memory", sensorNumber: "#0x53", event: "Correctable ECC", value: "Asserted"} ] };
|
var selEvent = { message: "There is no cache record for the poller with ID 564cf02a4978dadc187976f5.Perhaps it has not been run yet?" };
|
||||||
var keyToken = { access:{ token:{id:'123456'} } };
|
var extraPatch = { extra: { name: "QuantaPlex T41S-2U", eventre: "Correctable ECC", nodeid: "565f3f3b4c95bce26f35c6a0",
|
||||||
var selEvent = { message: "There is no cache record for the poller with ID 564cf02a4978dadc187976f5.Perhaps it has not been run yet?" };
|
timer: { timeInterval: 15000, start: "2015-12-03T17:38:20.569Z", finish: "2015-12-03T17:38:20.604Z", stop: false, isDone: true } } };
|
||||||
var extraPatch = {extra: {name: "QuantaPlex T41S-2U", eventre: "Correctable ECC",nodeid: "565f3f3b4c95bce26f35c6a0",
|
var patchedData = [{ 'path': '/extra', 'value': extraPatch.extra, 'op': 'replace' }];
|
||||||
timer: {timeInterval: 15000, start: "2015-12-03T17:38:20.569Z",finish: "2015-12-03T17:38:20.604Z",stop: false,isDone: true} } };
|
var catalog = [{ node: "9a761508-4eee-4065-b47b-45c22dff54c2", source: "dmi", data: {} }];
|
||||||
var patchedData = [{ 'path': '/extra', 'value': extraPatch.extra, 'op': 'replace' }];
|
var ironicDrivers = { drivers: [{ "hosts": ["localhost"], "name": "pxe_ssh", "links": [] }] };
|
||||||
var catalog = [{ node: "9a761508-4eee-4065-b47b-45c22dff54c2", source: "dmi", data: {} }];
|
var ironicChassis = { uuid: "1ac07daf-264e-4bd5-b0c4-d53095c217ac", link: [], extra: {}, created_at: "", "nodes": [], description: "ironic test chassis" };
|
||||||
var ironicDrivers = { drivers: [{ "hosts": ["localhost"], "name": "pxe_ssh", "links": [] }] };
|
var catalogSource = [{ source: 'dmi', data: { 'Memory Device': [{ Size: '1 GB' }, { Size: '1 GB' }], 'Processor Information': [{}, {}] } },
|
||||||
var ironicChassis = { uuid: "1ac07daf-264e-4bd5-b0c4-d53095c217ac", link: [], extra: {}, created_at: "", "nodes": [], description: "ironic test chassis" };
|
{ source: 'lsscsi', data: [{ peripheralType: 'disk', size: '1GB' }] }];
|
||||||
var catalogSource = [{ source: 'dmi', data: {'Memory Device': [{ Size: '1 GB' }, { Size: '1 GB' }],
|
var glanceImages = { "images": [{ "name": "ir-deploy-pxe_ssh.initramfs", "container_format": "ari", "disk_format": "ari" }] };
|
||||||
'Processor Information': [{}, {}] }}, { source: 'lsscsi', data: [{ peripheralType: 'disk', size: '1GB' }] }];
|
|
||||||
|
|
||||||
describe('Shovel api unit testing', function () {
|
|
||||||
var dmiData = { cpus: 1, memory: 1 };
|
|
||||||
|
|
||||||
before('start HTTP server', function () {
|
before('start HTTP server', function () {
|
||||||
helper.startServer();
|
helper.startServer();
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach('set up mocks', function () {
|
|
||||||
//monorail
|
|
||||||
sinon.stub(monorail, 'request_node_get').returns(Promise.resolve(JSON.stringify(rackhdNode[0])));
|
|
||||||
sinon.stub(monorail, 'request_nodes_get').returns(Promise.resolve(JSON.stringify(rackhdNode)));
|
|
||||||
sinon.stub(monorail, 'lookupCatalog').returns(Promise.resolve(true));
|
|
||||||
sinon.stub(monorail, 'request_catalogs_get').returns(Promise.resolve(JSON.stringify(catalog)));
|
|
||||||
sinon.stub(monorail, 'request_poller_get').returns(Promise.resolve(JSON.stringify(nodePollers)));
|
|
||||||
sinon.stub(monorail, 'request_poller_data_get').returns(Promise.resolve(JSON.stringify(_sel)));
|
|
||||||
sinon.stub(monorail, 'request_whitelist_del').returns(Promise.resolve(''));
|
|
||||||
sinon.stub(monorail, 'nodeDiskSize').returns(Promise.resolve(0));
|
|
||||||
sinon.stub(monorail, 'get_node_memory_cpu').returns(Promise.resolve(dmiData));
|
|
||||||
sinon.stub(monorail, 'get_catalog_data_by_source').returns(Promise.resolve(JSON.stringify(catalogSource[0])));
|
|
||||||
//keystone
|
|
||||||
sinon.stub(keystone, 'authenticatePassword').returns(Promise.resolve(JSON.stringify(keyToken)));
|
|
||||||
//ironic
|
|
||||||
sinon.stub(ironic, 'get_driver_list').returns(Promise.resolve(JSON.stringify(ironicDrivers)));
|
|
||||||
sinon.stub(ironic, 'get_chassis_by_id').returns(Promise.resolve(JSON.stringify(ironicChassis)));
|
|
||||||
sinon.stub(ironic, 'patch_node').returns(Promise.resolve(JSON.stringify(extraPatch)));
|
|
||||||
sinon.stub(ironic, 'get_node_list').returns(Promise.resolve(JSON.stringify(ironic_node_list)));
|
|
||||||
sinon.stub(ironic, 'get_node').returns(Promise.resolve(JSON.stringify(ironic_node_list[0])));
|
|
||||||
sinon.stub(ironic, 'delete_node').returns(Promise.resolve(''));
|
|
||||||
});
|
|
||||||
|
|
||||||
afterEach('teardown mocks', function () {
|
|
||||||
//monorail
|
|
||||||
monorail['request_node_get'].restore();
|
|
||||||
monorail['request_nodes_get'].restore();
|
|
||||||
monorail['request_poller_get'].restore();
|
|
||||||
monorail['request_poller_data_get'].restore();
|
|
||||||
monorail['request_catalogs_get'].restore();
|
|
||||||
monorail['lookupCatalog'].restore();
|
|
||||||
monorail['request_whitelist_del'].restore();
|
|
||||||
monorail['nodeDiskSize'].restore();
|
|
||||||
monorail['get_node_memory_cpu'].restore();
|
|
||||||
monorail['get_catalog_data_by_source'].restore();
|
|
||||||
//ironic
|
|
||||||
ironic['patch_node'].restore();
|
|
||||||
ironic['get_node_list'].restore();
|
|
||||||
ironic['get_node'].restore();
|
|
||||||
ironic['get_chassis_by_id'].restore();
|
|
||||||
ironic['get_driver_list'].restore();
|
|
||||||
ironic['delete_node'].restore();
|
|
||||||
//keystone
|
|
||||||
keystone['authenticatePassword'].restore();
|
|
||||||
});
|
|
||||||
|
|
||||||
after('stop HTTP server', function () {
|
after('stop HTTP server', function () {
|
||||||
helper.stopServer();
|
helper.stopServer();
|
||||||
});
|
});
|
||||||
|
describe('Shovel api unit testing', function () {
|
||||||
|
var dmiData = { cpus: 1, memory: 1 };
|
||||||
|
|
||||||
describe('shovel-info', function () {
|
beforeEach('set up mocks', function () {
|
||||||
it('response should have property \'name\': \'shovel\'', function (done) {
|
//monorail
|
||||||
|
sinon.stub(monorail, 'request_node_get').returns(Promise.resolve(JSON.stringify(rackhdNode[0])));
|
||||||
|
sinon.stub(monorail, 'request_nodes_get').returns(Promise.resolve(JSON.stringify(rackhdNode)));
|
||||||
|
sinon.stub(monorail, 'lookupCatalog').returns(Promise.resolve(true));
|
||||||
|
sinon.stub(monorail, 'request_catalogs_get').returns(Promise.resolve(JSON.stringify(catalog)));
|
||||||
|
sinon.stub(monorail, 'request_poller_get').returns(Promise.resolve(JSON.stringify(nodePollers)));
|
||||||
|
sinon.stub(monorail, 'request_poller_data_get').returns(Promise.resolve(JSON.stringify(_sel)));
|
||||||
|
sinon.stub(monorail, 'request_whitelist_del').returns(Promise.resolve(''));
|
||||||
|
sinon.stub(monorail, 'nodeDiskSize').returns(Promise.resolve(0));
|
||||||
|
sinon.stub(monorail, 'get_node_memory_cpu').returns(Promise.resolve(dmiData));
|
||||||
|
sinon.stub(monorail, 'get_catalog_data_by_source').returns(Promise.resolve(JSON.stringify(catalogSource[0])));
|
||||||
|
//glance
|
||||||
|
sinon.stub(glance, 'get_images').returns(Promise.resolve(JSON.stringify(glanceImages)));
|
||||||
|
//keystone
|
||||||
|
sinon.stub(keystone, 'authenticatePassword').returns(Promise.resolve(JSON.stringify(keyToken)));
|
||||||
|
//ironic
|
||||||
|
sinon.stub(ironic, 'get_driver_list').returns(Promise.resolve(JSON.stringify(ironicDrivers)));
|
||||||
|
sinon.stub(ironic, 'get_chassis_by_id').returns(Promise.resolve(JSON.stringify(ironicChassis)));
|
||||||
|
sinon.stub(ironic, 'patch_node').returns(Promise.resolve(JSON.stringify(extraPatch)));
|
||||||
|
sinon.stub(ironic, 'get_node_list').returns(Promise.resolve(JSON.stringify(ironic_node_list)));
|
||||||
|
sinon.stub(ironic, 'get_node').returns(Promise.resolve(JSON.stringify(ironic_node_list[0])));
|
||||||
|
sinon.stub(ironic, 'delete_node').returns(Promise.resolve(''));
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach('teardown mocks', function () {
|
||||||
|
//monorail
|
||||||
|
monorail['request_node_get'].restore();
|
||||||
|
monorail['request_nodes_get'].restore();
|
||||||
|
monorail['request_poller_get'].restore();
|
||||||
|
monorail['request_poller_data_get'].restore();
|
||||||
|
monorail['request_catalogs_get'].restore();
|
||||||
|
monorail['lookupCatalog'].restore();
|
||||||
|
monorail['request_whitelist_del'].restore();
|
||||||
|
monorail['nodeDiskSize'].restore();
|
||||||
|
monorail['get_node_memory_cpu'].restore();
|
||||||
|
monorail['get_catalog_data_by_source'].restore();
|
||||||
|
//ironic
|
||||||
|
ironic['patch_node'].restore();
|
||||||
|
ironic['get_node_list'].restore();
|
||||||
|
ironic['get_node'].restore();
|
||||||
|
ironic['get_chassis_by_id'].restore();
|
||||||
|
ironic['get_driver_list'].restore();
|
||||||
|
ironic['delete_node'].restore();
|
||||||
|
//glance
|
||||||
|
glance['get_images'].restore();
|
||||||
|
//keystone
|
||||||
|
keystone['authenticatePassword'].restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shovel-info response should have property \'name\': \'shovel\'', function (done) {
|
||||||
request(url)
|
request(url)
|
||||||
.get('/api/1.1/info')
|
.get('/api/1.1/info')
|
||||||
// end handles the response
|
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
// this is should.js syntax, very clear
|
|
||||||
JSON.parse(res.text).should.have.property('name', 'shovel');
|
JSON.parse(res.text).should.have.property('name', 'shovel');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('shovel-catalogs/{identifier}', function () {
|
it('shovel-catalogs/{identifier} in case of a correct rackHD id, response should include property node, source and data', function (done) {
|
||||||
it('in case of a correct rackHD id, response should include property node, source and data', function (done) {
|
|
||||||
request(url)
|
request(url)
|
||||||
.get('/api/1.1/catalogs/' + identifier)
|
.get('/api/1.1/catalogs/' + identifier)
|
||||||
// end handles the response
|
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
// this is should.js syntax, very clear
|
|
||||||
JSON.parse(res.text)[0].should.have.property('node', identifier);
|
JSON.parse(res.text)[0].should.have.property('node', identifier);
|
||||||
JSON.parse(res.text)[0].should.have.property('data');
|
JSON.parse(res.text)[0].should.have.property('data');
|
||||||
JSON.parse(res.text)[0].should.have.property('source');
|
JSON.parse(res.text)[0].should.have.property('source');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('shovel-catalogs/{identifier}/source', function () {
|
it('shovel-catalogs/{identifier}/source in case of a correct rackHD id, response should include property source and data', function (done) {
|
||||||
it('in case of a correct rackHD id, response should include property source and data', function (done) {
|
|
||||||
request(url)
|
request(url)
|
||||||
.get('/api/1.1/catalogs/' + identifier + '/dmi')
|
.get('/api/1.1/catalogs/' + identifier + '/dmi')
|
||||||
// end handles the response
|
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
// this is should.js syntax, very clear
|
|
||||||
JSON.parse(res.text).should.have.property('data');
|
JSON.parse(res.text).should.have.property('data');
|
||||||
JSON.parse(res.text).should.have.property('source');
|
JSON.parse(res.text).should.have.property('source');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('shovel-nodes/{identifier}', function () {
|
it('shovel-nodes/{identifier} in case of correct id, response should include property: id,identifiers', function (done) {
|
||||||
it('in case of correct id, response should include property: id,identifiers', function (done) {
|
|
||||||
request(url)
|
request(url)
|
||||||
.get('/api/1.1/nodes/' + identifier)
|
.get('/api/1.1/nodes/' + identifier)
|
||||||
// end handles the response
|
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
// this is should.js syntax, very clear
|
|
||||||
JSON.parse(res.text).should.have.property('id');
|
JSON.parse(res.text).should.have.property('id');
|
||||||
JSON.parse(res.text).should.have.property('identifiers');
|
JSON.parse(res.text).should.have.property('identifiers');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('shovel-ironic/chassis/{identifier}', function () {
|
it('shovel-ironic/chassis/{identifier} in case of a correct id, response should include property: uuid , description ', function (done) {
|
||||||
it('in case of a correct id, response should include property: uuid , description ', function (done) {
|
|
||||||
request(url)
|
request(url)
|
||||||
.get('/api/1.1/ironic/chassis/' + identifier)
|
.get('/api/1.1/ironic/chassis/' + identifier)
|
||||||
// end handles the response
|
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
// this is should.js syntax, very clear
|
|
||||||
JSON.parse(res.text).should.have.property('uuid');
|
JSON.parse(res.text).should.have.property('uuid');
|
||||||
JSON.parse(res.text).should.have.property('description');
|
JSON.parse(res.text).should.have.property('description');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('shovel-ironic/drivers', function () {
|
it('shovel-ironic/drivers response should have property \'drivers\'', function (done) {
|
||||||
it('response should have property \'drivers\'', function (done) {
|
|
||||||
request(url)
|
request(url)
|
||||||
.get('/api/1.1/ironic/drivers')
|
.get('/api/1.1/ironic/drivers')
|
||||||
// end handles the response
|
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
// this is should.js syntax, very clear
|
|
||||||
JSON.parse(res.text).should.have.property('drivers');
|
JSON.parse(res.text).should.have.property('drivers');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('shovel-ironic/nodes', function () {
|
it('shovel-ironic/nodes response should have property \'uuid\'', function (done) {
|
||||||
it('response should have property \'uuid\'', function (done) {
|
|
||||||
request(url)
|
request(url)
|
||||||
.get('/api/1.1/ironic/nodes')
|
.get('/api/1.1/ironic/nodes')
|
||||||
// end handles the response
|
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
// this is should.js syntax, very clear
|
|
||||||
JSON.parse(res.text)[0].should.have.property('uuid');
|
JSON.parse(res.text)[0].should.have.property('uuid');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('shovel-ironic/nodes/identifier', function () {
|
it('shovel-ironic/nodes/identifier response should have property \'uuid\'', function (done) {
|
||||||
it('response should have property \'uuid\'', function (done) {
|
|
||||||
request(url)
|
request(url)
|
||||||
.get('/api/1.1/ironic/nodes/' + identifier)
|
.get('/api/1.1/ironic/nodes/' + identifier)
|
||||||
// end handles the response
|
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
// this is should.js syntax, very clear
|
|
||||||
JSON.parse(res.text).should.have.property('uuid');
|
JSON.parse(res.text).should.have.property('uuid');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('shovel-ironic/patch', function () {
|
it('shovel-ironic/patch response should have property nodeid timer', function (done) {
|
||||||
it('response should have property nodeid timer', function (done) {
|
|
||||||
var body = {};
|
var body = {};
|
||||||
request(url)
|
request(url)
|
||||||
.patch('/api/1.1/ironic/node/' + identifier)
|
.patch('/api/1.1/ironic/node/' + identifier)
|
||||||
.send(body)
|
.send(body)
|
||||||
// end handles the response
|
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
// this is should.js syntax, very clear
|
|
||||||
JSON.parse(res.text).extra.should.have.property('nodeid');
|
JSON.parse(res.text).extra.should.have.property('nodeid');
|
||||||
JSON.parse(res.text).extra.should.have.property('timer');
|
JSON.parse(res.text).extra.should.have.property('timer');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('shovel-nodes', function () {
|
it('shovel-nodes response should have property "identifiers"', function (done) {
|
||||||
it('response should have property "identifiers"', function (done) {
|
|
||||||
request(url)
|
request(url)
|
||||||
.get('/api/1.1/nodes')
|
.get('/api/1.1/nodes')
|
||||||
// end handles the response
|
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
// this is should.js syntax, very clear
|
|
||||||
for (item in JSON.parse(res.text)) {
|
for (item in JSON.parse(res.text)) {
|
||||||
JSON.parse(res.text)[item].should.have.property('identifiers');
|
JSON.parse(res.text)[item].should.have.property('identifiers');
|
||||||
}
|
}
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('shovel-unregister/{identifier}', function () {
|
it('shovel-unregister/{identifier} if ironic id exist, response should include property: result: success', function (done) {
|
||||||
it('if ironic id exist, response should include property: result: success', function (done) {
|
|
||||||
request(url)
|
request(url)
|
||||||
.delete('/api/1.1/unregister/' + identifier)
|
.delete('/api/1.1/unregister/' + identifier)
|
||||||
// end handles the response
|
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
// this is should.js syntax, very clear
|
|
||||||
JSON.parse(res.text).result.should.be.equal('success');
|
JSON.parse(res.text).result.should.be.equal('success');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('shovel-getconfig', function () {
|
it('shovel-getconfig return success', function (done) {
|
||||||
it('', function (done) {
|
|
||||||
request(url)
|
request(url)
|
||||||
.get('/api/1.1/shovel/config')
|
.get('/api/1.1/shovel/config')
|
||||||
// end handles the response
|
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@ -290,17 +248,14 @@ describe('Shovel api unit testing', function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('shovel-set ironic config', function () {
|
it('shovel-set ironic config return success', function (done) {
|
||||||
it('', function (done) {
|
|
||||||
var body = { httpHost: "localhost" };
|
var body = { httpHost: "localhost" };
|
||||||
request(url)
|
request(url)
|
||||||
.post('/api/1.1/shovel/ironic/set-config')
|
.post('/api/1.1/shovel/ironic/set-config')
|
||||||
.send(body)
|
.send(body)
|
||||||
.expect('Content-Type', /text/)
|
.expect('Content-Type', /text/)
|
||||||
.expect(200) //Status code
|
.expect(200)
|
||||||
// end handles the response
|
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@ -309,17 +264,14 @@ describe('Shovel api unit testing', function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('shovel-set monorail config', function () {
|
it('shovel-set monorail config return success', function (done) {
|
||||||
it('', function (done) {
|
|
||||||
var body = { httpHost: "localhost" };
|
var body = { httpHost: "localhost" };
|
||||||
request(url)
|
request(url)
|
||||||
.post('/api/1.1/shovel/monorail/set-config')
|
.post('/api/1.1/shovel/monorail/set-config')
|
||||||
.send(body)
|
.send(body)
|
||||||
.expect('Content-Type', /text/)
|
.expect('Content-Type', /text/)
|
||||||
.expect(200) //Status code
|
.expect(200)
|
||||||
// end handles the response
|
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@ -328,17 +280,14 @@ describe('Shovel api unit testing', function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('shovel-set glance config', function () {
|
it('shovel-set glance config return success', function (done) {
|
||||||
it('', function (done) {
|
|
||||||
var body = { httpHost: "localhost" };
|
var body = { httpHost: "localhost" };
|
||||||
request(url)
|
request(url)
|
||||||
.post('/api/1.1/shovel/glance/set-config')
|
.post('/api/1.1/shovel/glance/set-config')
|
||||||
.send(body)
|
.send(body)
|
||||||
.expect('Content-Type', /text/)
|
.expect('Content-Type', /text/)
|
||||||
.expect(200) //Status code
|
.expect(200)
|
||||||
// end handles the response
|
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@ -347,17 +296,14 @@ describe('Shovel api unit testing', function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('shovel-set keystone config', function () {
|
it('shovel-set keystone config return success', function (done) {
|
||||||
it('', function (done) {
|
|
||||||
var body = { httpHost: "localhost" };
|
var body = { httpHost: "localhost" };
|
||||||
request(url)
|
request(url)
|
||||||
.post('/api/1.1/shovel/keystone/set-config')
|
.post('/api/1.1/shovel/keystone/set-config')
|
||||||
.send(body)
|
.send(body)
|
||||||
.expect('Content-Type', /text/)
|
.expect('Content-Type', /text/)
|
||||||
.expect(200) //Status code
|
.expect(200)
|
||||||
// end handles the response
|
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
@ -366,35 +312,208 @@ describe('Shovel api unit testing', function () {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Shovel api register', function () {
|
it('/api/1.1/glance/images should return property name', function (done) {
|
||||||
var error_message = '{"error_message": "{\\"debuginfo\\": null, \\"faultcode\\": \\"Client\\", \\"faultstring\\": \\"A node with name 5668b42d8bee16a10989e4e4 already exists.\\"}"}';
|
request(url)
|
||||||
var body = { "id": identifier, "driver": "string", "ipmihost": "string", "ipmiusername": "string", "ipmipasswd": "string" };
|
.get('/api/1.1/glance/images')
|
||||||
|
.end(function (err, res) {
|
||||||
|
if (err) {
|
||||||
beforeEach('set up mocks', function () {
|
throw err;
|
||||||
//monorail
|
}
|
||||||
//keystone
|
JSON.parse(res.text).images[0].should.have.property('name');
|
||||||
sinon.stub(keystone, 'authenticatePassword').returns(Promise.resolve(JSON.stringify(keyToken)));
|
done();
|
||||||
//ironic
|
});
|
||||||
sinon.stub(ironic, 'create_node').returns(Promise.resolve(error_message));
|
});
|
||||||
});
|
|
||||||
|
|
||||||
afterEach('teardown mocks', function () {
|
|
||||||
//monorail
|
|
||||||
monorail['nodeDiskSize'].restore();
|
|
||||||
monorail['get_node_memory_cpu'].restore();
|
|
||||||
monorail['request_node_get'].restore();
|
|
||||||
//keystone
|
|
||||||
keystone['authenticatePassword'].restore();
|
|
||||||
//ironic
|
|
||||||
ironic['create_node'].restore();
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('shovel-resgister', function () {
|
describe('Shovel error handling test', function () {
|
||||||
|
var client = require('./../../lib/api/client');
|
||||||
|
Promise.promisifyAll(client);
|
||||||
|
var body = { "id": identifier, "driver": "string", "ipmihost": "string", "ipmiusername": "string", "ipmipasswd": "string" };
|
||||||
|
before('set up mocks', function () {
|
||||||
|
//set client to return an error
|
||||||
|
var output = ({ error: 'error_message' });
|
||||||
|
sinon.stub(client, 'GetAsync').returns(Promise.reject(output));
|
||||||
|
sinon.stub(client, 'PostAsync').returns(Promise.reject(output));
|
||||||
|
});
|
||||||
|
after('teardown mocks', function () {
|
||||||
|
client['GetAsync'].restore();
|
||||||
|
client['PostAsync'].restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('/api/1.1/nodes/identifier should return error message', function (done) {
|
||||||
|
request(url)
|
||||||
|
.get('/api/1.1/nodes/' + identifier)
|
||||||
|
.end(function (err, res) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
JSON.parse(res.text).should.have.property('error');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('/api/1.1/nodes/catalogs/identifier should return error message', function (done) {
|
||||||
|
request(url)
|
||||||
|
.get('/api/1.1/catalogs/' + identifier)
|
||||||
|
.end(function (err, res) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
JSON.parse(res.text).should.have.property('error');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('/catalogs/{identifier}/{source} should return error message', function (done) {
|
||||||
|
request(url)
|
||||||
|
.get('/api/1.1/catalogs/123/bmc')
|
||||||
|
.end(function (err, res) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
JSON.parse(res.text).should.have.property('error');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('/nodes/{identifier} should return error message', function (done) {
|
||||||
|
request(url)
|
||||||
|
.get('/api/1.1/nodes/123')
|
||||||
|
.end(function (err, res) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
JSON.parse(res.text).should.have.property('error');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('/api/1.1/nodes/123/sel should return error message', function (done) {
|
||||||
|
request(url)
|
||||||
|
.get('/api/1.1/nodes/123/sel')
|
||||||
|
.end(function (err, res) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
JSON.parse(res.text).should.have.property('error');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('/api/1.1/ironic/nodes should return error message', function (done) {
|
||||||
|
request(url)
|
||||||
|
.get('/api/1.1/ironic/nodes')
|
||||||
|
.end(function (err, res) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
JSON.parse(res.text).should.have.property('error');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('/api/1.1/ironic/chassis/123 should return error message', function (done) {
|
||||||
|
request(url)
|
||||||
|
.get('/api/1.1/ironic/chassis/123')
|
||||||
|
.end(function (err, res) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
JSON.parse(res.text).should.have.property('error');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('/api/1.1/ironic/nodes/123 should return error message', function (done) {
|
||||||
|
request(url)
|
||||||
|
.get('/api/1.1/ironic/nodes/123')
|
||||||
|
.end(function (err, res) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
JSON.parse(res.text).should.have.property('error');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('/api/1.1/ironic/drivers should return error message', function (done) {
|
||||||
|
request(url)
|
||||||
|
.get('/api/1.1/ironic/drivers')
|
||||||
|
.end(function (err, res) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
JSON.parse(res.text).should.have.property('error');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('/api/1.1/glance/images should return error message', function (done) {
|
||||||
|
request(url)
|
||||||
|
.get('/api/1.1/glance/images')
|
||||||
|
.end(function (err, res) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
JSON.parse(res.text).should.have.property('error');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('/api/1.1/register should have property error when cant connect to server', function (done) {
|
||||||
|
request(url)
|
||||||
|
.post('/api/1.1/register')
|
||||||
|
.send(body)
|
||||||
|
.expect('Content-Type', /json/)
|
||||||
|
.expect(200)
|
||||||
|
.end(function (err, res) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
JSON.parse(res.text).should.have.property('error');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('/api/1.1/unregister/ should fail if no connection to server', function (done) {
|
||||||
|
request(url)
|
||||||
|
.delete('/api/1.1/unregister/123')
|
||||||
|
.end(function (err, res) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
JSON.parse(res.text).should.have.property('error');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('/ironic/node/{identifier} should return error message', function (done) {
|
||||||
|
request(url)
|
||||||
|
.patch('/api/1.1/ironic/node/123')
|
||||||
|
.send([{}])
|
||||||
|
.expect(200)
|
||||||
|
.end(function (err, res) {
|
||||||
|
if (err) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
JSON.parse(res.text).should.have.property('error');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Shovel api unit test for register', function () {
|
||||||
|
var error_message = '{"error_message": "{\\"debuginfo\\": null, \\"faultcode\\": \\"Client\\", \\"faultstring\\": \\"A node with name 5668b42d8bee16a10989e4e4 already exists.\\"}"}';
|
||||||
|
var body = { "id": identifier, "driver": "string", "ipmihost": "string", "ipmiusername": "string", "ipmipasswd": "string" };
|
||||||
|
|
||||||
|
beforeEach('set up mocks', function () {
|
||||||
|
//monorail
|
||||||
|
//keystone
|
||||||
|
sinon.stub(keystone, 'authenticatePassword').returns(Promise.resolve(JSON.stringify(keyToken)));
|
||||||
|
//ironic
|
||||||
|
sinon.stub(ironic, 'create_node').returns(Promise.resolve(error_message));
|
||||||
|
});
|
||||||
|
afterEach('teardown mocks', function () {
|
||||||
|
//monorail
|
||||||
|
monorail['nodeDiskSize'].restore();
|
||||||
|
monorail['get_node_memory_cpu'].restore();
|
||||||
|
monorail['request_node_get'].restore();
|
||||||
|
//keystone
|
||||||
|
keystone['authenticatePassword'].restore();
|
||||||
|
//ironic
|
||||||
|
ironic['create_node'].restore();
|
||||||
|
|
||||||
|
});
|
||||||
it('response in register should have property error_message when any of node info equal to 0 ', function (done) {
|
it('response in register should have property error_message when any of node info equal to 0 ', function (done) {
|
||||||
sinon.stub(monorail, 'request_node_get').returns(Promise.resolve(JSON.stringify(rackhdNode[0])));
|
sinon.stub(monorail, 'request_node_get').returns(Promise.resolve(JSON.stringify(rackhdNode[0])));
|
||||||
sinon.stub(monorail, 'nodeDiskSize').returns(Promise.resolve(0));
|
sinon.stub(monorail, 'nodeDiskSize').returns(Promise.resolve(0));
|
||||||
@ -404,15 +523,12 @@ describe('Shovel api register', function () {
|
|||||||
.post('/api/1.1/register')
|
.post('/api/1.1/register')
|
||||||
.send(body)
|
.send(body)
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200) //Status code
|
.expect(200)
|
||||||
// end handles the response
|
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
// this is should.js syntax, very clear
|
|
||||||
JSON.parse(res.text).should.have.property('error_message');
|
JSON.parse(res.text).should.have.property('error_message');
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -425,18 +541,14 @@ describe('Shovel api register', function () {
|
|||||||
.post('/api/1.1/register')
|
.post('/api/1.1/register')
|
||||||
.send(body)
|
.send(body)
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200) //Status code
|
.expect(200)
|
||||||
// end handles the response
|
|
||||||
.end(function (err, res) {
|
.end(function (err, res) {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
// this is should.js syntax, very clear
|
|
||||||
JSON.parse(res.text).should.have.property('error_message');
|
JSON.parse(res.text).should.have.property('error_message');
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,16 @@
|
|||||||
|
// Copyright 2015, EMC, Inc.
|
||||||
|
|
||||||
var app = require('connect')();
|
var app = require('connect')();
|
||||||
var http = require('http');
|
var http = require('http');
|
||||||
var swaggerTools = require('swagger-tools');
|
var swaggerTools = require('swagger-tools');
|
||||||
|
var sinon = require('sinon');
|
||||||
|
var winston = require('winston');
|
||||||
|
var logger = require('./../lib/services/logger');
|
||||||
|
var loggerVar = new (winston.Logger)({
|
||||||
|
levels: { verbose: 5, debug: 4, info: 3, warn: 2, error: 1, mask: 0 },
|
||||||
|
colors: { verbose: 'cyan', debug: 'blue', info: 'green', warn: 'yellow', error: 'red' }
|
||||||
|
})
|
||||||
|
.add(winston.transports.Console, { level: 'mask' });
|
||||||
var options = {
|
var options = {
|
||||||
swaggerUi: '/swagger.json',
|
swaggerUi: '/swagger.json',
|
||||||
controllers: './controllers',
|
controllers: './controllers',
|
||||||
@ -9,7 +18,16 @@ var options = {
|
|||||||
};
|
};
|
||||||
var swaggerDoc = require('./../api/swagger.json');
|
var swaggerDoc = require('./../api/swagger.json');
|
||||||
|
|
||||||
|
module.exports.maskLogger = function maskLogger() {
|
||||||
|
sinon.stub(logger, 'Logger').returns(loggerVar);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.restoreLogger = function restoreLogger() {
|
||||||
|
logger['Logger'].restore();
|
||||||
|
};
|
||||||
|
|
||||||
module.exports.startServer = function startServer() {
|
module.exports.startServer = function startServer() {
|
||||||
|
this.maskLogger();
|
||||||
swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) {
|
swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) {
|
||||||
app.use(middleware.swaggerMetadata());
|
app.use(middleware.swaggerMetadata());
|
||||||
app.use(middleware.swaggerRouter(options));
|
app.use(middleware.swaggerRouter(options));
|
||||||
@ -17,11 +35,8 @@ module.exports.startServer = function startServer() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
module.exports.stopServer = function stopServer() {
|
module.exports.stopServer = function stopServer() {
|
||||||
|
this.restoreLogger();
|
||||||
var net = require('net');
|
var net = require('net');
|
||||||
var socket = net.createConnection(9008);
|
var socket = net.createConnection(9008);
|
||||||
socket.end();
|
socket.end();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,20 +1,24 @@
|
|||||||
var request = require('supertest');
|
// Copyright 2015, EMC, Inc.
|
||||||
|
|
||||||
var should = require('should');
|
var should = require('should');
|
||||||
var assert = require('assert');
|
|
||||||
var sinon = require('sinon');
|
var sinon = require('sinon');
|
||||||
var monorail = require('./../../lib/api/monorail/monorail');
|
var monorail = require('./../../lib/api/monorail/monorail');
|
||||||
var ironic = require('./../../lib/api/openstack/ironic');
|
var ironic = require('./../../lib/api/openstack/ironic');
|
||||||
var keystone = require('./../../lib/api/openstack/keystone');
|
var keystone = require('./../../lib/api/openstack/keystone');
|
||||||
var Promise = require('bluebird');
|
var Promise = require('bluebird');
|
||||||
var Poller = require('./../../lib/services/poller');
|
var client = require('./../../lib/api/client');
|
||||||
|
Promise.promisifyAll(client);
|
||||||
var _ = require('underscore');
|
var _ = require('underscore');
|
||||||
|
var helper = require('./../helper');
|
||||||
|
//lib to be tested
|
||||||
|
var Poller;
|
||||||
|
|
||||||
describe('Shovel poller unit testing', function () {
|
describe('*****Shovel poller Class****', function () {
|
||||||
|
|
||||||
var rackhdNode =[ { workflows: [], autoDiscover: false, identifiers: ["2c:60:0c:83:f5:d1"], name: "2c:60:0c:83:f5:d1", sku: null, type: "compute", id: "5668b6ad8bee16a10989e4e5" }];
|
var rackhdNode =[ { workflows: [], autoDiscover: false, identifiers: ["2c:60:0c:83:f5:d1"], name: "2c:60:0c:83:f5:d1", sku: null, type: "compute", id: "5668b6ad8bee16a10989e4e5" }];
|
||||||
var identifier = '9a761508-4eee-4065-b47b-45c22dff54c2';
|
var identifier = '9a761508-4eee-4065-b47b-45c22dff54c2';
|
||||||
var ironic_node_list = [ { uuid: "9a761508-4eee-4065-b47b-45c22dff54c2", extra: { name: "D51B-2U (dual 10G LoM)", eventre: "", nodeid: "564cefa014ee77be18e48efd",
|
var ironic_node_list = [ { uuid: "9a761508-4eee-4065-b47b-45c22dff54c2", extra: { name: "D51B-2U (dual 10G LoM)", eventre: "", nodeid: "564cefa014ee77be18e48efd",
|
||||||
timer: { start: "2015-11-30T21:14:11.753Z", finish: "2015-11-30T21:14:11.772Z", stop: false, isDone: true, timeInteval: 5000 }, eventcnt: 0 } }];
|
timer: { start: "2015-11-30T21:14:11.753Z", finish: "2015-11-30T21:14:11.753Z", stop: false, isDone: true, timeInterval: 500 }, eventcnt: 0}}];
|
||||||
var nodePollers = [{ config: { command: "sel" }, id: "564dd86285fb1e7c72721543" }];
|
var nodePollers = [{ config: { command: "sel" }, id: "564dd86285fb1e7c72721543" }];
|
||||||
var _sel = { sel:[ { logId: "1", date: "12/03/2015", time: "08:54:11", sensorType: "Memory", sensorNumber: "#0x53", event: "Correctable ECC", value: "Asserted"} ] };
|
var _sel = { sel:[ { logId: "1", date: "12/03/2015", time: "08:54:11", sensorType: "Memory", sensorNumber: "#0x53", event: "Correctable ECC", value: "Asserted"} ] };
|
||||||
var keyToken = { access:{ token:{id:'123456'} } };
|
var keyToken = { access:{ token:{id:'123456'} } };
|
||||||
@ -24,95 +28,198 @@ describe('Shovel poller unit testing', function () {
|
|||||||
var patchedData = [{ 'path': '/extra', 'value': extraPatch.extra, 'op': 'replace' }];
|
var patchedData = [{ 'path': '/extra', 'value': extraPatch.extra, 'op': 'replace' }];
|
||||||
var pollerInstance;
|
var pollerInstance;
|
||||||
|
|
||||||
before('start Poller service', function () {
|
before('mask logger', function () {
|
||||||
pollerInstance = new Poller(5000);//timeInterval to 5s
|
helper.maskLogger();
|
||||||
|
Poller = require('./../../lib/services/poller');
|
||||||
});
|
});
|
||||||
|
after('restore logger', function () {
|
||||||
beforeEach('set up mocks', function () {
|
helper.restoreLogger();
|
||||||
sinon.stub(monorail, 'request_poller_get').returns(Promise.resolve(JSON.stringify(nodePollers)));
|
|
||||||
sinon.stub(monorail, 'request_poller_data_get').returns(Promise.resolve(JSON.stringify(_sel)));
|
|
||||||
sinon.stub(ironic,'patch_node').returns(Promise.resolve(JSON.stringify(extraPatch)));
|
|
||||||
sinon.stub(keystone,'authenticatePassword').returns(Promise.resolve(JSON.stringify(keyToken)));
|
|
||||||
sinon.stub(ironic,'get_node_list').returns(Promise.resolve(JSON.stringify(ironic_node_list)));
|
|
||||||
});
|
});
|
||||||
|
describe('Poller unit tests', function () {
|
||||||
|
before('start Poller service', function () {
|
||||||
|
pollerInstance = new Poller(5000);//timeInterval to 5s
|
||||||
|
});
|
||||||
|
|
||||||
afterEach('teardown mocks', function () {
|
beforeEach('set up mocks', function () {
|
||||||
monorail['request_poller_get'].restore();
|
sinon.stub(monorail, 'request_poller_get').returns(Promise.resolve(JSON.stringify(nodePollers)));
|
||||||
monorail['request_poller_data_get'].restore();
|
sinon.stub(monorail, 'request_poller_data_get').returns(Promise.resolve(JSON.stringify(_sel)));
|
||||||
ironic['patch_node'].restore();
|
sinon.stub(ironic, 'patch_node').returns(Promise.resolve(JSON.stringify(extraPatch)));
|
||||||
keystone['authenticatePassword'].restore();
|
sinon.stub(keystone, 'authenticatePassword').returns(Promise.resolve(JSON.stringify(keyToken)));
|
||||||
ironic['get_node_list'].restore();
|
sinon.stub(ironic, 'get_node_list').returns(Promise.resolve(JSON.stringify(ironic_node_list)));
|
||||||
|
sinon.stub(ironic, 'get_node').returns(Promise.resolve(JSON.stringify(ironic_node_list[0])));
|
||||||
|
});
|
||||||
|
|
||||||
});
|
afterEach('teardown mocks', function () {
|
||||||
|
monorail['request_poller_get'].restore();
|
||||||
|
monorail['request_poller_data_get'].restore();
|
||||||
|
ironic['patch_node'].restore();
|
||||||
|
keystone['authenticatePassword'].restore();
|
||||||
|
ironic['get_node_list'].restore();
|
||||||
|
ironic['get_node'].restore();
|
||||||
|
|
||||||
it('pollerInstance.getSeldata()', function (done) {
|
});
|
||||||
return pollerInstance.getSeldata(identifier).
|
|
||||||
then(function (data) {
|
it('Poller.prototype.searchIronic have property name, timer', function (done) {
|
||||||
var result = JSON.parse(data);
|
return pollerInstance.searchIronic(ironic_node_list[0]).
|
||||||
result.should.have.property('sel');
|
then(function (result) {
|
||||||
_.each(result[0],function(item){
|
result.should.have.property('name');
|
||||||
console.info(item);
|
result.should.have.property('timer');
|
||||||
item.should.have.property('sensorNumber');
|
done();
|
||||||
item.should.have.property('event');
|
|
||||||
});
|
});
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch (function(err){
|
|
||||||
throw(err);
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('Poller.prototype.updateInfo',function(done){
|
it('start server should call get nodes once', function (done) {
|
||||||
return pollerInstance.updateInfo(identifier,extraPatch).
|
pollerInstance.startServer(0);
|
||||||
then(function(data){
|
pollerInstance.stopServer();
|
||||||
var result = data;
|
var callback = sinon.spy();
|
||||||
_.each(result,function(item){
|
pollerInstance.getNodes(callback);
|
||||||
item.should.have.property('path');
|
callback.should.be.calledOnce;
|
||||||
item.should.have.property('value');
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('start server should call runPoller once', function (done) {
|
||||||
|
pollerInstance.startServer(0);
|
||||||
|
pollerInstance.stopServer();
|
||||||
|
var callback = sinon.spy();
|
||||||
|
pollerInstance.runPoller(ironic_node_list, callback);
|
||||||
|
callback.should.be.calledOnce;
|
||||||
|
done();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('start server should call searchIronic once', function (done) {
|
||||||
|
pollerInstance.startServer(0);
|
||||||
|
pollerInstance.stopServer();
|
||||||
|
var callback = sinon.spy();
|
||||||
|
pollerInstance.searchIronic(ironic_node_list[0], callback);
|
||||||
|
callback.should.be.calledOnce;
|
||||||
|
done();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
it('pollerInstance.getSeldata() have property sensorNumber, event', function (done) {
|
||||||
|
return pollerInstance.getSeldata(identifier).
|
||||||
|
then(function (data) {
|
||||||
|
var result = JSON.parse(data);
|
||||||
|
result.should.have.property('sel');
|
||||||
|
_.each(result[0], function (item) {
|
||||||
|
item.should.have.property('sensorNumber');
|
||||||
|
item.should.have.property('event');
|
||||||
|
});
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
throw (err);
|
||||||
});
|
});
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(function(err){
|
|
||||||
throw err;
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('Poller.prototype.patchData',function(done){
|
it('Poller.prototype.updateInfo have property path, value', function (done) {
|
||||||
return Poller.prototype.patchData('uuid',JSON.stringify(patchedData)).
|
return pollerInstance.updateInfo(identifier, extraPatch).
|
||||||
then(function(data){
|
then(function (data) {
|
||||||
data.should.have.property('nodeid');
|
var result = data;
|
||||||
data.should.have.property('timer');
|
_.each(result, function (item) {
|
||||||
done();
|
item.should.have.property('path');
|
||||||
})
|
item.should.have.property('value');
|
||||||
.catch(function(err){
|
});
|
||||||
throw(err);
|
done();
|
||||||
done();
|
})
|
||||||
});
|
.catch(function (err) {
|
||||||
});
|
throw err;
|
||||||
|
|
||||||
it('Poller.prototype.getNodes',function(done){
|
|
||||||
return pollerInstance.getNodes().
|
|
||||||
then(function(result){
|
|
||||||
_.each(result,function(item){
|
|
||||||
item.should.have.property('uuid');
|
|
||||||
item.should.have.property('extra');
|
|
||||||
});
|
});
|
||||||
done();
|
|
||||||
})
|
|
||||||
.catch(function(err){
|
|
||||||
throw(err);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Poller.prototype.patchData should have property nodeid, timer', function (done) {
|
||||||
|
return Poller.prototype.patchData('uuid', JSON.stringify(patchedData)).
|
||||||
|
then(function (data) {
|
||||||
|
data.should.have.property('nodeid');
|
||||||
|
data.should.have.property('timer');
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
throw (err);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Poller.prototype.getNodes should have property uuid, extra', function (done) {
|
||||||
|
return pollerInstance.getNodes().
|
||||||
|
then(function (result) {
|
||||||
|
_.each(result, function (item) {
|
||||||
|
item.should.have.property('uuid');
|
||||||
|
item.should.have.property('extra');
|
||||||
|
});
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
throw (err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Poller.prototype.getToken should return token 123456', function (done) {
|
||||||
|
return pollerInstance.getToken().
|
||||||
|
then(function (token) {
|
||||||
|
token.should.be.equal('123456');
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
.catch(function (err) {
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
describe('client get/post returns error', function () {
|
||||||
it('Poller.prototype.getToken',function(done){
|
before('set up mocks', function () {
|
||||||
return pollerInstance.getToken().
|
//set client to return an error
|
||||||
then(function(token){
|
pollerInstance = new Poller(5000);//timeInterval to 5s
|
||||||
token.should.be.equal('123456');
|
var output = ({ error: 'error_message' });
|
||||||
done();
|
sinon.stub(client, 'GetAsync').returns(Promise.reject(output));
|
||||||
})
|
sinon.stub(client, 'PostAsync').returns(Promise.reject(output));
|
||||||
.catch(function(err){
|
sinon.stub(client, 'PatchAsync').returns(Promise.reject(output));
|
||||||
throw err;
|
sinon.stub(client, 'PutAsync').returns(Promise.reject(output));
|
||||||
|
sinon.stub(client, 'DeleteAsync').returns(Promise.reject(output));
|
||||||
|
});
|
||||||
|
after('teardown mocks', function () {
|
||||||
|
client['GetAsync'].restore();
|
||||||
|
client['PostAsync'].restore();
|
||||||
|
client['PatchAsync'].restore();
|
||||||
|
client['PutAsync'].restore();
|
||||||
|
client['DeleteAsync'].restore();
|
||||||
|
});
|
||||||
|
it('poller.get_token return null', function (done) {
|
||||||
|
return pollerInstance.getToken('123')
|
||||||
|
.then(function (result) {
|
||||||
|
(result === null).should.be.exactly(true);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('poller.getSeldata return null', function (done) {
|
||||||
|
return pollerInstance.getSeldata('123')
|
||||||
|
.then(function (result) {
|
||||||
|
(result === null).should.be.exactly(true);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('poller.updateInfo return json obj with property : path', function (done) {
|
||||||
|
return pollerInstance.updateInfo(identifier, extraPatch)
|
||||||
|
.then(function (result) {
|
||||||
|
result[0].should.have.property('path', '/extra');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('poller.patchData return null', function (done) {
|
||||||
|
return pollerInstance.patchData(identifier, extraPatch)
|
||||||
|
.then(function (result) {
|
||||||
|
(result === null).should.be.exactly(true);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it('poller.getNodes return null', function (done) {
|
||||||
|
return pollerInstance.getNodes()
|
||||||
|
.then(function (result) {
|
||||||
|
(result === null).should.be.exactly(true);
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user