Enable OS Deployement using rackHD

- Allow user to deploy OS using rackHD graphs
- OS supproted are ESXI, CentOS, Ubuntu, RedHat
- Allow user to monitor the active workflow on certain node
- Add hooks in shovel to post/get/and delete node workflow in rackhd

Implements: blueprint shovel-deployment-capability
Change-Id: I9411be06de64f76496412e77ecfa6ebfdd9ce3cd
This commit is contained in:
Andre Keedy 2016-02-18 11:12:04 -05:00
parent af687f8c0d
commit 9449f7a443
5 changed files with 960 additions and 682 deletions

View File

@ -12,7 +12,7 @@
"/info": { "/info": {
"get": { "get": {
"x-swagger-router-controller": "Shovel", "x-swagger-router-controller": "Shovel",
"tags": [ "GET" ], "tags": [ "Shovel Config" ],
"operationId": "infoGet", "operationId": "infoGet",
"summary": "Get nodes info", "summary": "Get nodes info",
"responses": { "responses": {
@ -30,7 +30,7 @@
"/shovel/config": { "/shovel/config": {
"get": { "get": {
"x-swagger-router-controller": "Shovel", "x-swagger-router-controller": "Shovel",
"tags": [ "GET" ], "tags": [ "Shovel Config" ],
"operationId": "configget", "operationId": "configget",
"summary": "Get shovel config file", "summary": "Get shovel config file",
"responses": { "responses": {
@ -48,7 +48,7 @@
"/shovel/set-config": { "/shovel/set-config": {
"post": { "post": {
"x-swagger-router-controller": "Shovel", "x-swagger-router-controller": "Shovel",
"tags": [ "POST" ], "tags": [ "Shovel Config" ],
"operationId": "configset", "operationId": "configset",
"summary": "set shovel config file", "summary": "set shovel config file",
"parameters": [ "parameters": [
@ -77,7 +77,7 @@
"/shovel/monorail/set-config": { "/shovel/monorail/set-config": {
"post": { "post": {
"x-swagger-router-controller": "Shovel", "x-swagger-router-controller": "Shovel",
"tags": [ "POST" ], "tags": [ "Shovel Config" ],
"operationId": "configsetmono", "operationId": "configsetmono",
"summary": "set shovel- monorail info", "summary": "set shovel- monorail info",
"parameters": [ "parameters": [
@ -106,7 +106,7 @@
"/shovel/ironic/set-config": { "/shovel/ironic/set-config": {
"post": { "post": {
"x-swagger-router-controller": "Shovel", "x-swagger-router-controller": "Shovel",
"tags": [ "POST" ], "tags": [ "Shovel Config" ],
"operationId": "configsetironic", "operationId": "configsetironic",
"summary": "set shovel ironic info", "summary": "set shovel ironic info",
"parameters": [ "parameters": [
@ -135,7 +135,7 @@
"/shovel/glance/set-config": { "/shovel/glance/set-config": {
"post": { "post": {
"x-swagger-router-controller": "Shovel", "x-swagger-router-controller": "Shovel",
"tags": [ "POST" ], "tags": [ "Shovel Config" ],
"operationId": "configsetglance", "operationId": "configsetglance",
"summary": "set shovel glance info", "summary": "set shovel glance info",
"parameters": [ "parameters": [
@ -164,7 +164,7 @@
"/shovel/keystone/set-config": { "/shovel/keystone/set-config": {
"post": { "post": {
"x-swagger-router-controller": "Shovel", "x-swagger-router-controller": "Shovel",
"tags": [ "POST" ], "tags": [ "Shovel Config" ],
"operationId": "configsetkeystone", "operationId": "configsetkeystone",
"summary": "set shovel Keystone info", "summary": "set shovel Keystone info",
"parameters": [ "parameters": [
@ -193,13 +193,13 @@
"/catalogs/{identifier}": { "/catalogs/{identifier}": {
"get": { "get": {
"x-swagger-router-controller": "Shovel", "x-swagger-router-controller": "Shovel",
"tags": [ "GET" ], "tags": [ "RackHD API Wrappers" ],
"operationId": "catalogsGet", "operationId": "catalogsGet",
"parameters": [ "parameters": [
{ {
"name": "identifier", "name": "identifier",
"in": "path", "in": "path",
"description": "Onrack node ID", "description": "rackhd node ID",
"required": true, "required": true,
"type": "string" "type": "string"
} }
@ -220,13 +220,13 @@
"/catalogs/{identifier}/{source}": { "/catalogs/{identifier}/{source}": {
"get": { "get": {
"x-swagger-router-controller": "Shovel", "x-swagger-router-controller": "Shovel",
"tags": [ "GET" ], "tags": [ "RackHD API Wrappers" ],
"operationId": "catalogsbysourceGet", "operationId": "catalogsbysourceGet",
"parameters": [ "parameters": [
{ {
"name": "identifier", "name": "identifier",
"in": "path", "in": "path",
"description": "Onrack node ID", "description": "rackhd node ID",
"required": true, "required": true,
"type": "string" "type": "string"
}, },
@ -254,13 +254,13 @@
"/nodes/{identifier}": { "/nodes/{identifier}": {
"get": { "get": {
"x-swagger-router-controller": "Shovel", "x-swagger-router-controller": "Shovel",
"tags": [ "GET" ], "tags": [ "RackHD API Wrappers" ],
"operationId": "nodeGet", "operationId": "nodeGet",
"parameters": [ "parameters": [
{ {
"name": "identifier", "name": "identifier",
"in": "path", "in": "path",
"description": "Onrack node ID", "description": "rackhd node ID",
"required": true, "required": true,
"type": "string" "type": "string"
} }
@ -281,9 +281,9 @@
"/nodes": { "/nodes": {
"get": { "get": {
"x-swagger-router-controller": "Shovel", "x-swagger-router-controller": "Shovel",
"tags": [ "GET" ], "tags": [ "RackHD API Wrappers" ],
"operationId": "nodesGet", "operationId": "nodesGet",
"summary": "get All OnRack Nodes", "summary": "get All rackhd Nodes that been discovered with BMC,DMI information",
"responses": { "responses": {
"200": { "200": {
@ -299,7 +299,7 @@
"/nodes/{identifier}/sel": { "/nodes/{identifier}/sel": {
"get": { "get": {
"x-swagger-router-controller": "Shovel", "x-swagger-router-controller": "Shovel",
"tags": [ "GET" ], "tags": [ "RackHD API Wrappers" ],
"operationId": "getSeldata", "operationId": "getSeldata",
"parameters": [ "parameters": [
{ {
@ -325,7 +325,7 @@
"/ironic/nodes": { "/ironic/nodes": {
"get": { "get": {
"x-swagger-router-controller": "Shovel", "x-swagger-router-controller": "Shovel",
"tags": [ "GET" ], "tags": [ "Ironic API Wrappers" ],
"operationId": "ironicnodesGet", "operationId": "ironicnodesGet",
"summary": "get All ironic Nodes", "summary": "get All ironic Nodes",
"responses": { "responses": {
@ -343,7 +343,7 @@
"/ironic/node/{identifier}": { "/ironic/node/{identifier}": {
"patch": { "patch": {
"x-swagger-router-controller": "Shovel", "x-swagger-router-controller": "Shovel",
"tags": [ "PATCH" ], "tags": [ "Ironic API Wrappers" ],
"operationId": "ironicnodePatch", "operationId": "ironicnodePatch",
"summary": "patch specified ironic node", "summary": "patch specified ironic node",
"parameters": [ "parameters": [
@ -378,7 +378,7 @@
"/ironic/chassis/{identifier}": { "/ironic/chassis/{identifier}": {
"get": { "get": {
"x-swagger-router-controller": "Shovel", "x-swagger-router-controller": "Shovel",
"tags": [ "GET" ], "tags": [ "Ironic API Wrappers" ],
"operationId": "ironicchassisGet", "operationId": "ironicchassisGet",
"summary": "get Ironic chassis by id", "summary": "get Ironic chassis by id",
"parameters": [ "parameters": [
@ -405,7 +405,7 @@
"/ironic/nodes/{identifier}": { "/ironic/nodes/{identifier}": {
"get": { "get": {
"x-swagger-router-controller": "Shovel", "x-swagger-router-controller": "Shovel",
"tags": [ "GET" ], "tags": [ "Ironic API Wrappers" ],
"operationId": "ironicnodeGet", "operationId": "ironicnodeGet",
"summary": "get Ironic node by name", "summary": "get Ironic node by name",
"parameters": [ "parameters": [
@ -432,9 +432,9 @@
"/register": { "/register": {
"post": { "post": {
"x-swagger-router-controller": "Shovel", "x-swagger-router-controller": "Shovel",
"tags": [ "POST" ], "tags": [ "Shoveling" ],
"operationId": "registerpost", "operationId": "registerpost",
"summary": "Register an OnRack node in Ironic", "summary": "Register an rackhd node in Ironic",
"parameters": [ "parameters": [
{ {
"name": "Node Info", "name": "Node Info",
@ -461,7 +461,7 @@
"/unregister/{identifier}": { "/unregister/{identifier}": {
"delete": { "delete": {
"x-swagger-router-controller": "Shovel", "x-swagger-router-controller": "Shovel",
"tags": [ "DEL" ], "tags": [ "Shoveling" ],
"operationId": "unregisterdel", "operationId": "unregisterdel",
"summary": "UnRegister a node from Ironic", "summary": "UnRegister a node from Ironic",
"parameters": [ "parameters": [
@ -488,7 +488,7 @@
"/ironic/drivers": { "/ironic/drivers": {
"get": { "get": {
"x-swagger-router-controller": "Shovel", "x-swagger-router-controller": "Shovel",
"tags": [ "GET" ], "tags": [ "Ironic API Wrappers" ],
"operationId": "driversGet", "operationId": "driversGet",
"summary": "Get all the drivers used in Ironic", "summary": "Get all the drivers used in Ironic",
"responses": { "responses": {
@ -511,7 +511,7 @@
"/glance/images": { "/glance/images": {
"get": { "get": {
"x-swagger-router-controller": "Shovel", "x-swagger-router-controller": "Shovel",
"tags": [ "GET" ], "tags": [ "Glance API Wrappers" ],
"operationId": "imagesGet", "operationId": "imagesGet",
"summary": "Get all the images in Glance", "summary": "Get all the images in Glance",
"responses": { "responses": {
@ -530,6 +530,65 @@
} }
} }
} }
},
"/deployos/{identifier}/": {
"post": {
"x-swagger-router-controller": "Shovel",
"tags": [ "Nodes Provisionning" ],
"operationId": "deployOS",
"summary": "Deploy OS to a specific node",
"parameters": [
{
"name": "identifier",
"in": "path",
"description": "rackHD node ID",
"required": true,
"type": "string"
},
{
"name": "Config",
"in": "body",
"description": "OS Configuration",
"required": true,
"schema": {
"$ref": "#/definitions/deployos"
}
}
],
"responses": {
"200": {
"description": "Not Implemented"
},
"default": {
"description": "unexpected error"
}
}
}
},
"/worflow-status/{identifier}": {
"get": {
"x-swagger-router-controller": "Shovel",
"tags": [ "Nodes Provisionning" ],
"operationId": "workflowStatus",
"summary": "Get status of an active worflow running on a certain node in rackHD",
"parameters": [
{
"name": "identifier",
"in": "path",
"description": "rackHD node ID",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "Not Implemented"
},
"default": {
"description": "unexpected error"
}
}
}
} }
}, },
"definitions": { "definitions": {
@ -684,6 +743,86 @@
"items": { "items": {
"type": "object" "type": "object"
} }
},
"deployos": {
"type": "object",
"required": [
"name",
"options"
],
"properties": {
"name": {
"type": "string",
"example":"Graph.InstallCentOS"
},
"options": {
"type": "object",
"required": [
"defaults"
],
"properties": {
"defaults": {
"type": "object",
"properties": {
"obmServiceName": {
"type": "string",
"example": "ipmi-obm-service"
}
}
},
"install-os": {
"type": "object",
"properties": {
"repo": {
"type": "string"
},
"rootPassword": {
"type": "string"
},
"users": {
"type": "array",
"items": {
"type": "object",
"required": [
"name",
"password"
],
"properties": {
"name": {
"type": "string"
},
"password": {
"type": "string"
},
"uid": {
"type": "integer"
}
}
}
},
"networkDevices": {
"type": "array",
"items": {
"type": "object",
"required": [
"device",
"ipv4"
],
"properties": {
"device": {
"type": "string"
},
"ipv4": {
"type": "object"
}
}
}
}
}
}
}
}
}
} }
} }
} }

View File

@ -628,3 +628,38 @@ module.exports.imagesGet = function imagesGet(req, res) {
res.end(JSON.stringify(err)); res.end(JSON.stringify(err));
}); });
}; };
/*
* @api {post} /api/1.1/deployOS/identifier / POST /
* @apiDescription deploy OS to specific node
*/
module.exports.deployOS = function deployOS(req, res) {
'use strict';
res.setHeader('Content-Type', 'application/json');
return monorail.runWorkFlow(req.swagger.params.identifier.value,
req.body.name,req.body)
.then(function(data) {
res.end(data);
})
.catch(function(err) {
res.end(JSON.stringify(err));
});
};
/*
* @api {get} /api/1.1/workflow-status/identifier / GET /
* @apiDescription Get status of an active worflow running on a node in rackHD
*/
module.exports.workflowStatus = function workflowStatus(req,res) {
'use strict';
res.setHeader('Content-Type', 'application/json');
return monorail.getWorkFlowActive(req.swagger.params.identifier.value)
.then(function(data) {
if (data) {
res.end(JSON.stringify({'jobStatus':'Running'}));
} else {
res.end(JSON.stringify({'jobStatus':'Currently there is no job running on this node'}));
}
})
.catch(function(err) {
res.end(JSON.stringify(err));
});
};

View File

@ -145,7 +145,22 @@ var MonorailWrapper = {
.catch(function (err) { .catch(function (err) {
throw err; throw err;
}); });
},
runWorkFlow: function runWorkFlow(hwaddr,graphName,content) {
'use strict';
request.path = pfx + '/nodes/' + hwaddr + '/workflows/?name=' + graphName;
request.data = JSON.stringify(content);
return client.PostAsync(request);
},
getWorkFlowActive: function getWorkFlowActive(hwaddr) {
'use strict';
request.path = pfx + '/nodes/' + hwaddr + '/workflows/active';
return client.GetAsync(request);
},
deleteWorkFlowActive: function deleteWorkFlowActive(hwaddr) {
'use strict';
request.path = pfx + '/nodes/' + hwaddr + '/workflows/active';
return client.DeleteAsync(request);
} }
}; };
module.exports = Object.create(MonorailWrapper); module.exports = Object.create(MonorailWrapper);

View File

@ -164,5 +164,26 @@ describe('****Monorail Lib****',function(){
done(); done();
}); });
}); });
it('monorail.runWorkFlow return data from monorail', function (done) {
return monorail.runWorkFlow('123','Graph.Name',{})
.then(function (result) {
result.should.have.property('data');
done();
});
});
it('monorail.getWorkFlowActive return data from monorail', function (done) {
return monorail.getWorkFlowActive('123')
.then(function (result) {
result.should.have.property('data');
done();
});
});
it('monorail.deleteWorkFlowActive return data from monorail', function (done) {
return monorail.deleteWorkFlowActive('123')
.then(function (result) {
result.should.have.property('data');
done();
});
});
}); });
}); });

View File

@ -41,7 +41,7 @@ describe('****SHOVEL API Interface****', function () {
}); });
describe('Shovel api unit testing', function () { describe('Shovel api unit testing', function () {
var dmiData = { cpus: 1, memory: 1 }; var dmiData = { cpus: 1, memory: 1 };
var getWorkflow;
beforeEach('set up mocks', function () { beforeEach('set up mocks', function () {
//monorail //monorail
sinon.stub(monorail, 'request_node_get').returns(Promise.resolve(JSON.stringify(rackhdNode[0]))); sinon.stub(monorail, 'request_node_get').returns(Promise.resolve(JSON.stringify(rackhdNode[0])));
@ -54,6 +54,8 @@ describe('****SHOVEL API Interface****', function () {
sinon.stub(monorail, 'nodeDiskSize').returns(Promise.resolve(0)); sinon.stub(monorail, 'nodeDiskSize').returns(Promise.resolve(0));
sinon.stub(monorail, 'getNodeMemoryCpu').returns(Promise.resolve(dmiData)); sinon.stub(monorail, 'getNodeMemoryCpu').returns(Promise.resolve(dmiData));
sinon.stub(monorail, 'get_catalog_data_by_source').returns(Promise.resolve(JSON.stringify(catalogSource[0]))); sinon.stub(monorail, 'get_catalog_data_by_source').returns(Promise.resolve(JSON.stringify(catalogSource[0])));
sinon.stub(monorail, 'runWorkFlow').returns(Promise.resolve('{"definition":{}}'));
getWorkflow = sinon.stub(monorail,'getWorkFlowActive');
//glance //glance
sinon.stub(glance, 'get_images').returns(Promise.resolve(JSON.stringify(glanceImages))); sinon.stub(glance, 'get_images').returns(Promise.resolve(JSON.stringify(glanceImages)));
//keystone //keystone
@ -79,6 +81,8 @@ describe('****SHOVEL API Interface****', function () {
monorail['nodeDiskSize'].restore(); monorail['nodeDiskSize'].restore();
monorail['getNodeMemoryCpu'].restore(); monorail['getNodeMemoryCpu'].restore();
monorail['get_catalog_data_by_source'].restore(); monorail['get_catalog_data_by_source'].restore();
monorail['runWorkFlow'].restore();
monorail['getWorkFlowActive'].restore();
//ironic //ironic
ironic['patch_node'].restore(); ironic['patch_node'].restore();
ironic['get_node_list'].restore(); ironic['get_node_list'].restore();
@ -324,6 +328,45 @@ describe('****SHOVEL API Interface****', function () {
done(); done();
}); });
}); });
it('/api/1.1/deployos/ should return property definition', function (done) {
request(url)
.post('/api/1.1/deployos/123')
.send({"name": "Graph.InstallCentOS","options": { "defaults": {"obmServiceName": "ipmi-obm-service"}}})
.end(function (err, res) {
if (err) {
console.log('hey yo');
throw err;
}
console.log('hello' + res.text)
JSON.parse(res.text).should.have.property('definition');
done();
});
});
it('/api/1.1/worflow-status/{identifier} should return property jobStatus', function (done) {
getWorkflow.returns(Promise.resolve('{"node":"123", "_status": "valid"}'))
request(url)
.get('/api/1.1/worflow-status/123')
.end(function (err, res) {
if (err) {
throw err;
}
console.log(res.text);
JSON.parse(res.text).should.have.property('jobStatus');
done();
});
});
it('/api/1.1/worflow-status/{identifier} should return property jobStatus even if no job is running', function (done) {
getWorkflow.returns(Promise.resolve());
request(url)
.get('/api/1.1/worflow-status/123')
.end(function (err, res) {
if (err) {
throw err;
}
JSON.parse(res.text).should.have.property('jobStatus');
done();
});
});
}); });
@ -490,6 +533,31 @@ describe('****SHOVEL API Interface****', function () {
done(); done();
}); });
}); });
it('/deployos/{identifier} should return error message', function (done) {
request(url)
.post('/api/1.1/deployos/123')
.send([{}])
.expect(200)
.end(function (err, res) {
if (err) {
throw err;
}
JSON.parse(res.text).should.have.property('error');
done();
});
});
it('/worflow-status/{identifier} should return error message', function (done) {
request(url)
.get('/api/1.1/worflow-status/123')
.expect(200)
.end(function (err, res) {
if (err) {
throw err;
}
JSON.parse(res.text).should.have.property('error');
done();
});
});
}); });
describe('Shovel api unit test for register', function () { describe('Shovel api unit test for register', function () {