Skip to content

Commit

Permalink
Merge pull request #2 from phelpdh/add-system-spec-tests
Browse files Browse the repository at this point in the history
Add system spec tests
  • Loading branch information
phelpdh authored May 26, 2017
2 parents 76716c9 + 606614e commit 51b3e92
Show file tree
Hide file tree
Showing 3 changed files with 305 additions and 65 deletions.
93 changes: 42 additions & 51 deletions lib/api/redfish-1.0/systems.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ var listSystemProcessors = controller(function(req, res) {

return wsman.isDellSystem(identifier)
.then(function(result){
var node = result.node;
if(result.isDell){
return dataFactory(identifier, 'hardware').then(function(hardware) {
options.hardware = hardware;
Expand Down Expand Up @@ -330,7 +329,6 @@ var getSystemProcessor = controller(function(req, res) {

return wsman.isDellSystem(identifier)
.then(function(result){
var node = result.node;
if(result.isDell){
return Promise.props({
socketId: req.swagger.params.socket.value,
Expand Down Expand Up @@ -375,7 +373,6 @@ var listSimpleStorage = controller(function(req, res) {

return wsman.isDellSystem(identifier)
.then(function(result){
var node = result.node;
if(result.isDell){
return Promise.resolve(dataFactory(identifier, 'hardware'))
.then(function(hardware) {
Expand Down Expand Up @@ -443,7 +440,6 @@ var getSimpleStorage = controller(function(req, res) {

return wsman.isDellSystem(identifier)
.then(function(result){
var node = result.node;
if(result.isDell){
return Promise.resolve(dataFactory(identifier, 'hardware'))
.then(function(hardware) {
Expand Down Expand Up @@ -515,7 +511,6 @@ var listStorage = controller(function(req, res) {

return wsman.isDellSystem(identifier)
.then(function(result){
var node = result.node;
if(result.isDell){
return Promise.resolve(dataFactory(identifier, 'hardware'))
.then(function(hardware) {
Expand All @@ -541,7 +536,7 @@ var listStorage = controller(function(req, res) {
return redfish.handleError(error, res);
});
} else {
return redfish.handleError(new Error("Not implemented for non-Dell hardware.", res));
return redfish.handleError("Not implemented for non-Dell hardware.", res, null, 501);
}
});
});
Expand All @@ -560,7 +555,6 @@ var getStorage = controller(function(req, res) {

return wsman.isDellSystem(identifier)
.then(function(result){
var node = result.node;
if(result.isDell){
return Promise.resolve(dataFactory(identifier, 'hardware'))
.then(function(hardware) {
Expand Down Expand Up @@ -604,7 +598,7 @@ var getStorage = controller(function(req, res) {
return redfish.handleError(error, res);
});
} else {
return redfish.handleError(new Error("Not implemented for non-Dell hardware.", res));
return redfish.handleError("Not implemented for non-Dell hardware.", res, null, 501);
}
});
});
Expand All @@ -626,7 +620,6 @@ var getDrive = controller(function(req, res) {

return wsman.isDellSystem(identifier)
.then(function(result){
var node = result.node;
if(result.isDell){
return Promise.resolve(dataFactory(identifier, 'hardware'))
.then(function(hardware) {
Expand All @@ -647,7 +640,7 @@ var getDrive = controller(function(req, res) {
return redfish.handleError(error, res);
});
} else {
return redfish.handleError(new Error("Not implemented for non-Dell hardware.", res));
return redfish.handleError("Not implemented for non-Dell hardware.", res, null, 501);
}
});
});
Expand All @@ -661,7 +654,6 @@ var listVolume = controller(function(req, res) {
options.index = index;
return wsman.isDellSystem(identifier)
.then(function(result){
var node = result.node;
if(result.isDell){
return Promise.resolve(dataFactory(identifier, 'hardware'))
.then(function(hardware) {
Expand All @@ -678,7 +670,7 @@ var listVolume = controller(function(req, res) {
return redfish.handleError(error, res);
});
} else {
return redfish.handleError(new Error("Not implemented for non-Dell hardware.", res));
return redfish.handleError("Not implemented for non-Dell hardware.", res, null, 501);
}
});
});
Expand All @@ -700,7 +692,6 @@ var getVolume = controller(function(req, res) {

return wsman.isDellSystem(identifier)
.then(function(result){
var node = result.node;
if(result.isDell){
return Promise.resolve(dataFactory(identifier, 'hardware'))
.then(function(hardware) {
Expand All @@ -723,7 +714,7 @@ var getVolume = controller(function(req, res) {
return redfish.handleError(error, res);
});
} else {
return redfish.handleError(new Error("Not implemented for non-Dell hardware.", res));
return redfish.handleError("Not implemented for non-Dell hardware.", res, null, 501);
}
});
});
Expand All @@ -737,12 +728,19 @@ var listLogService = controller(function(req, res) {
var identifier = req.swagger.params.identifier.value;
var options = redfish.makeOptions(req, res, identifier);

options.logSource = ['sel', 'lc'];
return redfish.render('redfish.1.0.0.logservicecollection.json',
'LogServiceCollection.json#/definitions/LogServiceCollection',
options)
.catch(function(error) {
return redfish.handleError(error, res);
return wsman.isDellSystem(identifier)
.then(function(result){
if(result.isDell){
options.logSource = ['sel', 'lc'];
} else {
options.logSource = ['sel'];
}
return redfish.render('redfish.1.0.0.logservicecollection.json',
'LogServiceCollection.json#/definitions/LogServiceCollection',
options)
.catch(function(error) {
return redfish.handleError(error, res);
});
});
});

Expand All @@ -766,10 +764,8 @@ var getSelLogService = controller(function(req, res) {
return wsman.getLog(node, options.type)
.then(function(sel) {
options.log.size = sel.length || 0;
options.log.policy = sel.Overflow && sel.Overflow === 'false' ?
'WrapsWhenFull' :
'NeverOverWrites';
options.log.lastWriteDate = sel.creationTimeStamp || 'Unknown';
options.log.policy = 'WrapsWhenFull';
options.log.lastWriteDate = sel.length > 0 ? sel[0].creationTimeStamp : 'Unknown';
return redfish.render('redfish.1.0.0.logservice.1.0.0.json',
'LogService.v1_0_3.json#/definitions/LogService',
options);
Expand Down Expand Up @@ -921,18 +917,16 @@ var getLcLogService = controller(function(req, res) {
return wsman.getLog(node, options.type)
.then(function(lc) {
options.log.size = lc.length || 0;
options.log.policy = lc.Overflow && lc.Overflow === 'false' ?
'WrapsWhenFull' :
'NeverOverWrites';
options.log.lastWriteDate = lc.creationTimeStamp || 'Unknown';
options.log.policy = 'WrapsWhenFull';
options.log.lastWriteDate = lc.length > 0 ? lc[0].creationTimeStamp : 'Unknown';
return redfish.render('redfish.1.0.0.logservice.1.0.0.json',
'LogService.v1_0_3.json#/definitions/LogService',
options);
}).catch(function(error) {
return redfish.handleError(error, res);
});
} else {
return redfish.handleError(new Error("Not implemented for non-Dell hardware.", res));
return redfish.handleError("Not implemented for non-Dell hardware.", res, null, 501);
}
});
});
Expand Down Expand Up @@ -962,7 +956,7 @@ var listLcLogServiceEntries = controller(function(req, res) {
return redfish.handleError(error, res);
});
} else {
return redfish.handleError(new Error("Not implemented for non-Dell hardware.", res));
return redfish.handleError("Not implemented for non-Dell hardware.", res, null, 501);
}
});
});
Expand Down Expand Up @@ -1003,7 +997,7 @@ var getLcLogServiceEntry = controller(function(req, res) {
return redfish.handleError(error, res);
});
} else {
return redfish.handleError(new Error("Not implemented for non-Dell hardware.", res));
return redfish.handleError("Not implemented for non-Dell hardware.", res, null, 501);
}
});
});
Expand Down Expand Up @@ -1163,11 +1157,9 @@ var deleteVolume = controller(function(req,res) {
};
return wsman.isDellSystem(identifier)
.then(function(result){
var node = result.node;
if(result.isDell){
return Promise.resolve(dataFactory(identifier, 'hardware'))
.then(function(hardware) {
if(!dellFound){throw "Delete volume not implemented for non-Dell hardware";}
graphOptions.defaults.volumeId = hardware.data.storage.virtualDisks[volumeIndex].fqdd;
graphOptions.defaults.ipAddress = hardware.data.id;
}).then(function(){
Expand All @@ -1183,7 +1175,7 @@ var deleteVolume = controller(function(req,res) {
return redfish.handleError(error, res);
});
} else {
return redfish.handleError(new Error("Not implemented for non-Dell hardware.", res));
return redfish.handleError("Not implemented for non-Dell hardware.", res, null, 501);
}
});
});
Expand All @@ -1203,33 +1195,34 @@ var addVolume = controller(function(req,res) {

return wsman.isDellSystem(identifier)
.then(function(result){
var node = result.node;
if(result.isDell){
return Promise.resolve(dataFactory(identifier, 'hardware'))
.then(function(hardware) {
if (!dellFound){throw "Add Volume not implemented for non-Dell hardware.";}
var driveIndices = [];
for(i = 0; i < payload.volume.Links.Drives.length; i++)
for(var i = 0; i < payload.volume.Links.Drives.length; i++)
{
var odataId = payload.volume.Links.Drives[i]['@odata.id'].split('/');
var ind = odataId[odataId.length - 1];
driveIndices.push(ind);
}
if (driveIndices.length === 0){ throw "No Drives specified for the Volume to use.";}
if (driveIndices.length === 0){
throw new Error("No Drives specified for the Volume to use.");
}
graphOptions.defaults.ipAddress = hardware.data.id;
graphOptions.defaults.name = payload.volume.Name;
if (graphOptions.defaults.name.indexOf(" ") !== -1){ throw "Virtual disk name cannot have spaces";}
if (graphOptions.defaults.name.indexOf(" ") !== -1){
throw new Error("Virtual disk name cannot have spaces");
}
graphOptions.defaults.sizeInBytes = payload.volume.CapacityBytes;
graphOptions.defaults.drives = "";
for(i = 0; i < driveIndices.length; i++)
{
if (driveIndices[i] >= hardware.data.storage.physicalDisks.length){
throw "No drive exists with id " + driveIndices[i];
}
for(var i = 0; i < driveIndices.length; i++) {
if (driveIndices[i] >= hardware.data.storage.physicalDisks.length){
throw "No drive exists with id " + driveIndices[i];
}
graphOptions.defaults.drives += hardware.data.storage.physicalDisks[driveIndices[i]].fqdd;
if (i+1 < driveIndices.length){
graphOptions.defaults.drives += ',';
}
if (i+1 < driveIndices.length){
graphOptions.defaults.drives += ',';
}
}
var raidLevel = payload.volume.VolumeType;
switch(raidLevel)
Expand Down Expand Up @@ -1265,7 +1258,7 @@ var addVolume = controller(function(req,res) {
return redfish.handleError(error, res);
});
} else {
return redfish.handleError(new Error("Not implemented for non-Dell hardware.", res));
return redfish.handleError("Not implemented for non-Dell hardware.", res, null, 501);
}
});
});
Expand All @@ -1290,11 +1283,9 @@ var addHotspare = controller(function(req,res) {
};
return wsman.isDellSystem(identifier)
.then(function(result){
var node = result.node;
if(result.isDell){
return Promise.resolve(dataFactory(identifier, 'hardware'))
.then(function(hardware) {
if(!dellFound){throw "Add hotspare not implemented for non-Dell hardware";}
graphOptions.defaults.driveId = hardware.data.storage.physicalDisks[driveIndex].fqdd;
graphOptions.defaults.ipAddress = hardware.data.id;
if(payload.hotspareType === 'dhs'){
Expand All @@ -1319,7 +1310,7 @@ var addHotspare = controller(function(req,res) {
return redfish.handleError(error, res);
});
} else {
return redfish.handleError(new Error("Not implemented for non-Dell hardware.", res));
return redfish.handleError("Not implemented for non-Dell hardware.", res, null, 501);
}
});
});
Expand Down
31 changes: 18 additions & 13 deletions lib/services/wsman-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
'use strict';

var di = require('di');
var ejs = require('ejs');
var urlParse = require('url-parse');

module.exports = wsmanServiceFactory;
Expand All @@ -13,14 +12,16 @@ di.annotate(wsmanServiceFactory,
'Services.Waterline',
'Services.Encryption',
'Services.Configuration',
'JobUtils.WsmanTool'
'JobUtils.WsmanTool',
'Errors'
)
);
function wsmanServiceFactory(
waterline,
encryption,
configuration,
WsmanTool
WsmanTool,
errors
) {

//var logger = Logger.initialize(wsmanServiceFactory);
Expand All @@ -36,7 +37,8 @@ function wsmanServiceFactory(
if (!obm) { throw new errors.NotFoundError('Failed to find Wsman obm settings'); }
self.dellConfigs = configuration.get('dell');
if (!self.dellConfigs) {
throw new errors.NotFoundError('Configuration for WSMan web services is not defined in wsmanConfig.json.');
throw new errors.NotFoundError(
'Configuration for WSMan web services is not defined in wsmanConfig.json.');
}
var parse = urlParse(self.dellConfigs.gateway);

Expand All @@ -57,7 +59,7 @@ function wsmanServiceFactory(
address: obm.config.host,
userName: obm.config.userName,
password: encryption.decrypt(obm.config.password)
}
};
});
};

Expand All @@ -68,24 +70,27 @@ function wsmanServiceFactory(
return self.init(node)
.then(function(){
if (!self.dellConfigs.services.inventory.logs) {
throw new errors.NotFoundError('Dell Configuration (INVENTORY.LOGS) web service is not defined in wsmanConfig.json.');
throw new errors.NotFoundError(
'Dell inventory.logs web service is not defined in wsmanConfig.json.');
}
var url = self.dellConfigs.services.inventory.logs;
url = url.replace(/{type}/, logType.toUpperCase());

return self.wsman.clientRequest(url, 'POST', self.target)
.then(function(response) {
//logger.debug(JSON.stringify(response.body));
return response.body;
})
})
}
});
});
};


WsmanService.prototype.isDellSystem = function(identifier) {
var result = {node: undefined, isDell: false, isRedfishCapable: false};
return waterline.nodes.getNodeById(identifier)
.then(function(node){
if(!node){
throw new errors.NotFoundError('invalid node id.');
}
result.node = node;
for(var i=0; i<node.identifiers.length; i++) {
if(/^[0-9|A-Z]{7}$/.test(node.identifiers[i])){
Expand All @@ -98,12 +103,12 @@ function wsmanServiceFactory(
return waterline.obms.findByNode(node.id, 'redfish-obm-service', true)
.then(function (obmSetting) {
if(obmSetting){
result.isRedfishCapable = false; // Change to true to enable southbound redfish
result.isRedfishCapable = true;
}
return result;
})
});
});
}
};

return new WsmanService();
}
Loading

0 comments on commit 51b3e92

Please sign in to comment.