Skip to content

Commit

Permalink
Merge pull request #152 from keedya/master
Browse files Browse the repository at this point in the history
Add new Task to run a UEFI application (if compute is running in UEFI)
  • Loading branch information
zyoung51 committed Apr 1, 2016
2 parents f10e03d + 4c3f5cf commit 53926c2
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 0 deletions.
58 changes: 58 additions & 0 deletions lib/jobs/uefi-job.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2016, EMC, Inc.

'use strict';

var di = require('di');

module.exports = uefiJobFactory;
di.annotate(uefiJobFactory, new di.Provide('Job.Uefi'));
di.annotate(uefiJobFactory,
new di.Inject(
'Job.Base',
'Logger',
'Assert',
'Util'
)
);
function uefiJobFactory(BaseJob, Logger, assert, util) {
var logger = Logger.initialize(uefiJobFactory);

/**
*
* @param {Object} options
* @param {Object} context
* @param {String} taskId
* @constructor
*/
function UefiJob(options, context, taskId) {
UefiJob.super_.call(this, logger, options, context, taskId);
assert.string(options.uefitool);
assert.string(options.repo);
assert.string(options.profile);
this.nodeId = this.context.target;
this.profile = this.options.profile;
}
util.inherits(UefiJob, BaseJob);

UefiJob.prototype._run = function () {
var self = this;
self._subscribeRequestProfile(function () {
return self.profile;
});

self._subscribeRequestProperties(function () {
return self.options;
});

self._subscribeHttpResponse(function (data) {
assert.object(data);
if (199 < data.statusCode && data.statusCode < 300) {
if (data.url.indexOf(self.options.uefitool) > 0) {
self._done();
}
}
});
};

return UefiJob;
}
16 changes: 16 additions & 0 deletions lib/task-data/base-tasks/uefi-task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2016, EMC, Inc.

'use strict';

module.exports = {
friendlyName: 'base-uefi',
injectableName: 'Task.Base.uefi',
runJob: 'Job.Uefi',
requiredOptions: [
'profile',
'repo',
'uefitool'
],
requiredProperties: {},
properties: {}
};
16 changes: 16 additions & 0 deletions lib/task-data/tasks/run-uefi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2016, EMC, Inc.

'use strict';

module.exports = {
friendlyName: 'Run UEFI Application',
injectableName: 'Task.Run.Uefi',
implementsTask: 'Task.Base.uefi',
options: {
profile: 'run-uefi.ipxe',
repo: null,
uefitool: null,
args: ''
},
properties: {}
};
81 changes: 81 additions & 0 deletions spec/lib/jobs/uefi-job-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright 2016, EMC, Inc.
/* jshint node:true */

'use strict';

var uuid = require('node-uuid');

describe('Run a UEFI Application', function () {
var UefiJob;
var subscribeRequestProfileStub;
var subscribeRequestPropertiesStub;
var subscribeHttpResponseStub;
var job;

before(function () {
helper.setupInjector(
_.flattenDeep([
helper.require('/lib/jobs/base-job'),
helper.require('/lib/jobs/uefi-job')
])
);
UefiJob = helper.injector.get('Job.Uefi');
subscribeRequestProfileStub = sinon.stub(
UefiJob.prototype, '_subscribeRequestProfile');
subscribeRequestPropertiesStub = sinon.stub(
UefiJob.prototype, '_subscribeRequestProperties');
subscribeHttpResponseStub = sinon.stub(
UefiJob.prototype, '_subscribeHttpResponse');
});

beforeEach(function () {
subscribeRequestProfileStub.reset();
subscribeRequestPropertiesStub.reset();
subscribeHttpResponseStub.reset();
job = new UefiJob(
{
profile: 'testprofile',
repo: 'http://127.0.0.1:8080',
uefitool: 'testuefi.efi',
args: 'args'
},
{
target: 'testid'
},
uuid.v4());
});

after(function () {
subscribeRequestProfileStub.restore();
subscribeRequestPropertiesStub.restore();
subscribeHttpResponseStub.restore();
});

it("should have a nodeId value", function () {
expect(job.nodeId).to.equal('testid');
});

it("should have a profile value", function () {
expect(job.profile).to.equal('testprofile');
});

it("should set up message subscribers", function () {
var cb;
job._run();
expect(subscribeRequestProfileStub).to.have.been.called;
expect(subscribeRequestPropertiesStub).to.have.been.called;
expect(subscribeHttpResponseStub).to.have.been.called;

cb = subscribeRequestProfileStub.firstCall.args[0];
expect(cb).to.be.a.function;
expect(cb.call(job)).to.equal(job.profile);

cb = subscribeRequestPropertiesStub.firstCall.args[0];
expect(cb).to.be.a.function;
expect(cb.call(job)).to.equal(job.options);

cb = subscribeHttpResponseStub.firstCall.args[0];
expect(cb).to.be.a.function;
});

});
17 changes: 17 additions & 0 deletions spec/lib/task-data/base-tasks/uefi-task-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2016, EMC, Inc.
/* jshint node:true */

'use strict';

describe(require('path').basename(__filename), function () {
var base = require('./base-task-data-spec');

base.before(function (context) {
context.taskdefinition = helper.require('/lib/task-data/base-tasks/uefi-task.js');
});

describe('task-data', function () {
base.examples();
});

});
17 changes: 17 additions & 0 deletions spec/lib/task-data/tasks/run-uefi-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2016, EMC, Inc.
/* jshint node:true */

'use strict';

describe(require('path').basename(__filename), function () {
var base = require('./base-tasks-spec');

base.before(function (context) {
context.taskdefinition = helper.require('/lib/task-data/tasks/run-uefi.js');
});

describe('task-data', function () {
base.examples();
});

});

0 comments on commit 53926c2

Please sign in to comment.