-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #152 from keedya/master
Add new Task to run a UEFI application (if compute is running in UEFI)
- Loading branch information
Showing
6 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: {} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: {} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
|
||
}); |