Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/jobs/ucs-discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ function UcsDiscoveryJobFactory(
id = [config.ucs, data.path];
}

config.dn = data.path;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change a better variable name, dn is too short and never tell anything.

var obm = {
config: config,
service: 'ucs-obm-service'
Expand Down
116 changes: 116 additions & 0 deletions lib/services/ucs-obm-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// Copyright 2017, EMC, Inc.

'use strict';

var di = require('di'),
util = require('util');

module.exports = UcsObmServiceFactory;

di.annotate(UcsObmServiceFactory,
new di.Provide('ucs-obm-service')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the new obm service into schema https://github.com/RackHD/on-tasks/blob/master/lib/task-data/base-tasks/obm.js#L30, otherwise this obm will not pass the basic validation.

);
di.annotate(UcsObmServiceFactory,
new di.Inject(
'OBM.base',
'Promise',
'Services.Waterline',
'Assert',
'_',
'JobUtils.UcsTool',
'HttpTool'
)
);
function UcsObmServiceFactory(
BaseObmService,
Promise,
waterline,
assert,
_,
UcsTool
) {
function UcsObmService(options) {
BaseObmService.call(this, options);
this.requiredKeys = ['uri'];
this.params = options.params;
this.config = options.config;
this.ucs = this.initClient(this.config);

}
util.inherits(UcsObmService, BaseObmService);

UcsObmService.prototype.initClient = function(settings) {
var ucs = new UcsTool();
ucs.settings = settings;
return ucs;
};

UcsObmService.prototype.powerOn = function() {
return this._runInternal('on');
};

UcsObmService.prototype.powerOff = function() {
return this._runInternal('off');
};

UcsObmService.prototype.reboot = function() {
return this._runInternal('cycle-immediate');
};

UcsObmService.prototype.reset = function() {
return this.reboot();
};

UcsObmService.prototype.powerButton = function() {
return this._runInternal('ipmi-reset');
};

UcsObmService.prototype.powerStatus = function() {
var self = this;
var dn = self.ucs.settings.dn;
var url= "/power?identifier=" + dn;
return self.ucs.clientRequest(url)
.then(function(res) {
assert.object(res, 'Response');
if (res.body.serverState === "down"){
return false;
}
else if(res.body.serverState === "up"){
return true;
}
else {
throw new Error(
'Unknown Power State: ' + self.config.root
);
}
});
};

UcsObmService.prototype._runInternal = function (action) {
return this.run({
action:action
});
};

UcsObmService.prototype.run = function (options) {
var self = this;
return Promise.try(function(){
assert.object(options);
assert.string(options.action);
var action = options.action;
var nodeId = self.options.nodeId;
return waterline.nodes.findOne(nodeId)
.then(function(data){
var url= "/power?" + "identifier=" + data.name + "&action=" + action;
return self.ucs.clientRequest(url, "POST");
});
});
};


UcsObmService.create = function(options) {
return BaseObmService.create(UcsObmService, options);
};

return UcsObmService;
}
3 changes: 2 additions & 1 deletion lib/task-data/base-tasks/obm.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ module.exports = {
"redfish-obm-service",
"servertech-obm-service",
"vbox-obm-service",
"vmrun-obm-service"
"vmrun-obm-service",
"ucs-obm-service"
]
},
},
Expand Down
1 change: 1 addition & 0 deletions spec/lib/services/base-obm-services-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ var base = {
.finally(function() {
// exclude noop and redfish services that don't use run()
if (service.constructor.name !== 'NoopObmService' &&
service.constructor.name !== 'UcsObmService' &&
service.constructor.name !== 'RedfishObmService') {
expect(service.run.callCount).to.be.above(0);
}
Expand Down
93 changes: 93 additions & 0 deletions spec/lib/services/ucs-obm-service-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright 2017, EMC, Inc.
/* jshint node: true */

'use strict';

var base = require('./base-obm-services-spec');


describe('UCS OBM Service', function() {
var servicePath = [ '/lib/services/ucs-obm-service',
'/lib/utils/job-utils/ucs-tool'],
sandbox = sinon.sandbox.create(),
testOptions = {
config: {
'uri': 'localhost',
'ucs-user': 'test',
'ucs-password': 'test'
},
params: {
target: '/sys/chassis-3/blade-3'
},
dn : "/sys/chassis-3/blade-3"
},
testSystem = {
body: {
PowerState : 'On'
}
},

waterline = {};
var node = {
id: 'abc',
type: 'enclosure',
name: 'Node',
identifiers: [],
relations: [
{
relationType: 'encloses',
targets: ['/fake']
},
{
relationType: 'enclosedBy',
targets: ['/fake']
}
]
};

before(function() {
helper.setupInjector([
helper.di.simpleWrapper(waterline,'Services.Waterline')
]);
waterline.nodes = {
findOne: sandbox.stub().resolves(node)
};
});

after(function() {
sandbox.restore();
});

var tool = {
clientRequest: sandbox.stub(),
settings : {
dn : "dn"
}
};

describe('base', function() {
var waterline;
base.before('UCSObmService before', servicePath, function(self) {
waterline = helper.injector.get('Services.Waterline');
waterline.nodes = {
findOne: sandbox.stub().resolves(node)
};
self.serviceOptions = testOptions;
self.Service = helper.injector.get('ucs-obm-service');

sandbox.stub(self.Service.prototype, 'initClient')
.returns(tool);
tool.clientRequest.resolves(testSystem);
});

base.beforeEach('UcsObmService beforeEach');
base.after('UcsObmService after');
base.runInterfaceTestCases(['powerOn',
'powerOff',
'reboot',
'NMI',
'powerButton',
'powerStatus']);
});

});