Skip to content
This repository was archived by the owner on Apr 15, 2026. It is now read-only.

Commit 51b3e92

Browse files
authored
Merge pull request #2 from phelpdh/add-system-spec-tests
Add system spec tests
2 parents 76716c9 + 606614e commit 51b3e92

3 files changed

Lines changed: 305 additions & 65 deletions

File tree

lib/api/redfish-1.0/systems.js

Lines changed: 42 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ var listSystemProcessors = controller(function(req, res) {
289289

290290
return wsman.isDellSystem(identifier)
291291
.then(function(result){
292-
var node = result.node;
293292
if(result.isDell){
294293
return dataFactory(identifier, 'hardware').then(function(hardware) {
295294
options.hardware = hardware;
@@ -330,7 +329,6 @@ var getSystemProcessor = controller(function(req, res) {
330329

331330
return wsman.isDellSystem(identifier)
332331
.then(function(result){
333-
var node = result.node;
334332
if(result.isDell){
335333
return Promise.props({
336334
socketId: req.swagger.params.socket.value,
@@ -375,7 +373,6 @@ var listSimpleStorage = controller(function(req, res) {
375373

376374
return wsman.isDellSystem(identifier)
377375
.then(function(result){
378-
var node = result.node;
379376
if(result.isDell){
380377
return Promise.resolve(dataFactory(identifier, 'hardware'))
381378
.then(function(hardware) {
@@ -443,7 +440,6 @@ var getSimpleStorage = controller(function(req, res) {
443440

444441
return wsman.isDellSystem(identifier)
445442
.then(function(result){
446-
var node = result.node;
447443
if(result.isDell){
448444
return Promise.resolve(dataFactory(identifier, 'hardware'))
449445
.then(function(hardware) {
@@ -515,7 +511,6 @@ var listStorage = controller(function(req, res) {
515511

516512
return wsman.isDellSystem(identifier)
517513
.then(function(result){
518-
var node = result.node;
519514
if(result.isDell){
520515
return Promise.resolve(dataFactory(identifier, 'hardware'))
521516
.then(function(hardware) {
@@ -541,7 +536,7 @@ var listStorage = controller(function(req, res) {
541536
return redfish.handleError(error, res);
542537
});
543538
} else {
544-
return redfish.handleError(new Error("Not implemented for non-Dell hardware.", res));
539+
return redfish.handleError("Not implemented for non-Dell hardware.", res, null, 501);
545540
}
546541
});
547542
});
@@ -560,7 +555,6 @@ var getStorage = controller(function(req, res) {
560555

561556
return wsman.isDellSystem(identifier)
562557
.then(function(result){
563-
var node = result.node;
564558
if(result.isDell){
565559
return Promise.resolve(dataFactory(identifier, 'hardware'))
566560
.then(function(hardware) {
@@ -604,7 +598,7 @@ var getStorage = controller(function(req, res) {
604598
return redfish.handleError(error, res);
605599
});
606600
} else {
607-
return redfish.handleError(new Error("Not implemented for non-Dell hardware.", res));
601+
return redfish.handleError("Not implemented for non-Dell hardware.", res, null, 501);
608602
}
609603
});
610604
});
@@ -626,7 +620,6 @@ var getDrive = controller(function(req, res) {
626620

627621
return wsman.isDellSystem(identifier)
628622
.then(function(result){
629-
var node = result.node;
630623
if(result.isDell){
631624
return Promise.resolve(dataFactory(identifier, 'hardware'))
632625
.then(function(hardware) {
@@ -647,7 +640,7 @@ var getDrive = controller(function(req, res) {
647640
return redfish.handleError(error, res);
648641
});
649642
} else {
650-
return redfish.handleError(new Error("Not implemented for non-Dell hardware.", res));
643+
return redfish.handleError("Not implemented for non-Dell hardware.", res, null, 501);
651644
}
652645
});
653646
});
@@ -661,7 +654,6 @@ var listVolume = controller(function(req, res) {
661654
options.index = index;
662655
return wsman.isDellSystem(identifier)
663656
.then(function(result){
664-
var node = result.node;
665657
if(result.isDell){
666658
return Promise.resolve(dataFactory(identifier, 'hardware'))
667659
.then(function(hardware) {
@@ -678,7 +670,7 @@ var listVolume = controller(function(req, res) {
678670
return redfish.handleError(error, res);
679671
});
680672
} else {
681-
return redfish.handleError(new Error("Not implemented for non-Dell hardware.", res));
673+
return redfish.handleError("Not implemented for non-Dell hardware.", res, null, 501);
682674
}
683675
});
684676
});
@@ -700,7 +692,6 @@ var getVolume = controller(function(req, res) {
700692

701693
return wsman.isDellSystem(identifier)
702694
.then(function(result){
703-
var node = result.node;
704695
if(result.isDell){
705696
return Promise.resolve(dataFactory(identifier, 'hardware'))
706697
.then(function(hardware) {
@@ -723,7 +714,7 @@ var getVolume = controller(function(req, res) {
723714
return redfish.handleError(error, res);
724715
});
725716
} else {
726-
return redfish.handleError(new Error("Not implemented for non-Dell hardware.", res));
717+
return redfish.handleError("Not implemented for non-Dell hardware.", res, null, 501);
727718
}
728719
});
729720
});
@@ -737,12 +728,19 @@ var listLogService = controller(function(req, res) {
737728
var identifier = req.swagger.params.identifier.value;
738729
var options = redfish.makeOptions(req, res, identifier);
739730

740-
options.logSource = ['sel', 'lc'];
741-
return redfish.render('redfish.1.0.0.logservicecollection.json',
742-
'LogServiceCollection.json#/definitions/LogServiceCollection',
743-
options)
744-
.catch(function(error) {
745-
return redfish.handleError(error, res);
731+
return wsman.isDellSystem(identifier)
732+
.then(function(result){
733+
if(result.isDell){
734+
options.logSource = ['sel', 'lc'];
735+
} else {
736+
options.logSource = ['sel'];
737+
}
738+
return redfish.render('redfish.1.0.0.logservicecollection.json',
739+
'LogServiceCollection.json#/definitions/LogServiceCollection',
740+
options)
741+
.catch(function(error) {
742+
return redfish.handleError(error, res);
743+
});
746744
});
747745
});
748746

@@ -766,10 +764,8 @@ var getSelLogService = controller(function(req, res) {
766764
return wsman.getLog(node, options.type)
767765
.then(function(sel) {
768766
options.log.size = sel.length || 0;
769-
options.log.policy = sel.Overflow && sel.Overflow === 'false' ?
770-
'WrapsWhenFull' :
771-
'NeverOverWrites';
772-
options.log.lastWriteDate = sel.creationTimeStamp || 'Unknown';
767+
options.log.policy = 'WrapsWhenFull';
768+
options.log.lastWriteDate = sel.length > 0 ? sel[0].creationTimeStamp : 'Unknown';
773769
return redfish.render('redfish.1.0.0.logservice.1.0.0.json',
774770
'LogService.v1_0_3.json#/definitions/LogService',
775771
options);
@@ -921,18 +917,16 @@ var getLcLogService = controller(function(req, res) {
921917
return wsman.getLog(node, options.type)
922918
.then(function(lc) {
923919
options.log.size = lc.length || 0;
924-
options.log.policy = lc.Overflow && lc.Overflow === 'false' ?
925-
'WrapsWhenFull' :
926-
'NeverOverWrites';
927-
options.log.lastWriteDate = lc.creationTimeStamp || 'Unknown';
920+
options.log.policy = 'WrapsWhenFull';
921+
options.log.lastWriteDate = lc.length > 0 ? lc[0].creationTimeStamp : 'Unknown';
928922
return redfish.render('redfish.1.0.0.logservice.1.0.0.json',
929923
'LogService.v1_0_3.json#/definitions/LogService',
930924
options);
931925
}).catch(function(error) {
932926
return redfish.handleError(error, res);
933927
});
934928
} else {
935-
return redfish.handleError(new Error("Not implemented for non-Dell hardware.", res));
929+
return redfish.handleError("Not implemented for non-Dell hardware.", res, null, 501);
936930
}
937931
});
938932
});
@@ -962,7 +956,7 @@ var listLcLogServiceEntries = controller(function(req, res) {
962956
return redfish.handleError(error, res);
963957
});
964958
} else {
965-
return redfish.handleError(new Error("Not implemented for non-Dell hardware.", res));
959+
return redfish.handleError("Not implemented for non-Dell hardware.", res, null, 501);
966960
}
967961
});
968962
});
@@ -1003,7 +997,7 @@ var getLcLogServiceEntry = controller(function(req, res) {
1003997
return redfish.handleError(error, res);
1004998
});
1005999
} else {
1006-
return redfish.handleError(new Error("Not implemented for non-Dell hardware.", res));
1000+
return redfish.handleError("Not implemented for non-Dell hardware.", res, null, 501);
10071001
}
10081002
});
10091003
});
@@ -1163,11 +1157,9 @@ var deleteVolume = controller(function(req,res) {
11631157
};
11641158
return wsman.isDellSystem(identifier)
11651159
.then(function(result){
1166-
var node = result.node;
11671160
if(result.isDell){
11681161
return Promise.resolve(dataFactory(identifier, 'hardware'))
11691162
.then(function(hardware) {
1170-
if(!dellFound){throw "Delete volume not implemented for non-Dell hardware";}
11711163
graphOptions.defaults.volumeId = hardware.data.storage.virtualDisks[volumeIndex].fqdd;
11721164
graphOptions.defaults.ipAddress = hardware.data.id;
11731165
}).then(function(){
@@ -1183,7 +1175,7 @@ var deleteVolume = controller(function(req,res) {
11831175
return redfish.handleError(error, res);
11841176
});
11851177
} else {
1186-
return redfish.handleError(new Error("Not implemented for non-Dell hardware.", res));
1178+
return redfish.handleError("Not implemented for non-Dell hardware.", res, null, 501);
11871179
}
11881180
});
11891181
});
@@ -1203,33 +1195,34 @@ var addVolume = controller(function(req,res) {
12031195

12041196
return wsman.isDellSystem(identifier)
12051197
.then(function(result){
1206-
var node = result.node;
12071198
if(result.isDell){
12081199
return Promise.resolve(dataFactory(identifier, 'hardware'))
12091200
.then(function(hardware) {
1210-
if (!dellFound){throw "Add Volume not implemented for non-Dell hardware.";}
12111201
var driveIndices = [];
1212-
for(i = 0; i < payload.volume.Links.Drives.length; i++)
1202+
for(var i = 0; i < payload.volume.Links.Drives.length; i++)
12131203
{
12141204
var odataId = payload.volume.Links.Drives[i]['@odata.id'].split('/');
12151205
var ind = odataId[odataId.length - 1];
12161206
driveIndices.push(ind);
12171207
}
1218-
if (driveIndices.length === 0){ throw "No Drives specified for the Volume to use.";}
1208+
if (driveIndices.length === 0){
1209+
throw new Error("No Drives specified for the Volume to use.");
1210+
}
12191211
graphOptions.defaults.ipAddress = hardware.data.id;
12201212
graphOptions.defaults.name = payload.volume.Name;
1221-
if (graphOptions.defaults.name.indexOf(" ") !== -1){ throw "Virtual disk name cannot have spaces";}
1213+
if (graphOptions.defaults.name.indexOf(" ") !== -1){
1214+
throw new Error("Virtual disk name cannot have spaces");
1215+
}
12221216
graphOptions.defaults.sizeInBytes = payload.volume.CapacityBytes;
12231217
graphOptions.defaults.drives = "";
1224-
for(i = 0; i < driveIndices.length; i++)
1225-
{
1226-
if (driveIndices[i] >= hardware.data.storage.physicalDisks.length){
1227-
throw "No drive exists with id " + driveIndices[i];
1228-
}
1218+
for(var i = 0; i < driveIndices.length; i++) {
1219+
if (driveIndices[i] >= hardware.data.storage.physicalDisks.length){
1220+
throw "No drive exists with id " + driveIndices[i];
1221+
}
12291222
graphOptions.defaults.drives += hardware.data.storage.physicalDisks[driveIndices[i]].fqdd;
1230-
if (i+1 < driveIndices.length){
1231-
graphOptions.defaults.drives += ',';
1232-
}
1223+
if (i+1 < driveIndices.length){
1224+
graphOptions.defaults.drives += ',';
1225+
}
12331226
}
12341227
var raidLevel = payload.volume.VolumeType;
12351228
switch(raidLevel)
@@ -1265,7 +1258,7 @@ var addVolume = controller(function(req,res) {
12651258
return redfish.handleError(error, res);
12661259
});
12671260
} else {
1268-
return redfish.handleError(new Error("Not implemented for non-Dell hardware.", res));
1261+
return redfish.handleError("Not implemented for non-Dell hardware.", res, null, 501);
12691262
}
12701263
});
12711264
});
@@ -1290,11 +1283,9 @@ var addHotspare = controller(function(req,res) {
12901283
};
12911284
return wsman.isDellSystem(identifier)
12921285
.then(function(result){
1293-
var node = result.node;
12941286
if(result.isDell){
12951287
return Promise.resolve(dataFactory(identifier, 'hardware'))
12961288
.then(function(hardware) {
1297-
if(!dellFound){throw "Add hotspare not implemented for non-Dell hardware";}
12981289
graphOptions.defaults.driveId = hardware.data.storage.physicalDisks[driveIndex].fqdd;
12991290
graphOptions.defaults.ipAddress = hardware.data.id;
13001291
if(payload.hotspareType === 'dhs'){
@@ -1319,7 +1310,7 @@ var addHotspare = controller(function(req,res) {
13191310
return redfish.handleError(error, res);
13201311
});
13211312
} else {
1322-
return redfish.handleError(new Error("Not implemented for non-Dell hardware.", res));
1313+
return redfish.handleError("Not implemented for non-Dell hardware.", res, null, 501);
13231314
}
13241315
});
13251316
});

lib/services/wsman-service.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
'use strict';
44

55
var di = require('di');
6-
var ejs = require('ejs');
76
var urlParse = require('url-parse');
87

98
module.exports = wsmanServiceFactory;
@@ -13,14 +12,16 @@ di.annotate(wsmanServiceFactory,
1312
'Services.Waterline',
1413
'Services.Encryption',
1514
'Services.Configuration',
16-
'JobUtils.WsmanTool'
15+
'JobUtils.WsmanTool',
16+
'Errors'
1717
)
1818
);
1919
function wsmanServiceFactory(
2020
waterline,
2121
encryption,
2222
configuration,
23-
WsmanTool
23+
WsmanTool,
24+
errors
2425
) {
2526

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

@@ -57,7 +59,7 @@ function wsmanServiceFactory(
5759
address: obm.config.host,
5860
userName: obm.config.userName,
5961
password: encryption.decrypt(obm.config.password)
60-
}
62+
};
6163
});
6264
};
6365

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

7679
return self.wsman.clientRequest(url, 'POST', self.target)
7780
.then(function(response) {
78-
//logger.debug(JSON.stringify(response.body));
7981
return response.body;
80-
})
81-
})
82-
}
82+
});
83+
});
84+
};
8385

8486

8587
WsmanService.prototype.isDellSystem = function(identifier) {
8688
var result = {node: undefined, isDell: false, isRedfishCapable: false};
8789
return waterline.nodes.getNodeById(identifier)
8890
.then(function(node){
91+
if(!node){
92+
throw new errors.NotFoundError('invalid node id.');
93+
}
8994
result.node = node;
9095
for(var i=0; i<node.identifiers.length; i++) {
9196
if(/^[0-9|A-Z]{7}$/.test(node.identifiers[i])){
@@ -98,12 +103,12 @@ function wsmanServiceFactory(
98103
return waterline.obms.findByNode(node.id, 'redfish-obm-service', true)
99104
.then(function (obmSetting) {
100105
if(obmSetting){
101-
result.isRedfishCapable = false; // Change to true to enable southbound redfish
106+
result.isRedfishCapable = true;
102107
}
103108
return result;
104-
})
109+
});
105110
});
106-
}
111+
};
107112

108113
return new WsmanService();
109114
}

0 commit comments

Comments
 (0)