Skip to content

Commit

Permalink
Merge pull request #489 from uppalk1/combine-dell-firmware-upgrade-ra…
Browse files Browse the repository at this point in the history
…cadm-catalog

Add a flag to be able to updateExistingCatalog
  • Loading branch information
geoff-reid committed Aug 2, 2017
2 parents 4ca8215 + 3d11734 commit f2300e1
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 12 deletions.
44 changes: 35 additions & 9 deletions lib/jobs/racadm-catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function racadmCatalogJobFactory(

this.nodeId = this.context.target;
this.action = options.action;
this.updateExistingCatalog = options.updateExistingCatalog;
}
util.inherits(RacadmCatalogJob, BaseJob);

Expand Down Expand Up @@ -66,25 +67,51 @@ function racadmCatalogJobFactory(

RacadmCatalogJob.prototype.handleResponse = function(result) {
var self = this;

return Promise.resolve(result)
.then(function() {
var addCatalogPromises = [];

if (result.error) {
logger.error("Failed to get catalog for " + result.source, {
error: result.error,
result: result
});
} else {
if (result.store) {
addCatalogPromises.push(
Promise.resolve(waterline.catalogs.create({
var dataToSave = {
node: self.nodeId,
source: result.source || 'unknown',
data: result.data
};
if (self.updateExistingCatalog === true) {
var query = {
node: self.nodeId,
source: result.source,
data: result.data
}))
);
source: result.source
};
return waterline.catalogs.count(query)
.then(function(count) {
if (count) {
addCatalogPromises.push(
Promise.resolve(waterline.catalogs.update(query, dataToSave))
);
} else {
addCatalogPromises.push(
Promise.resolve(waterline.catalogs.create({
node: self.nodeId,
source: result.source,
data: result.data
}))
);
}
});
} else{
addCatalogPromises.push(
Promise.resolve(waterline.catalogs.create({
node: self.nodeId,
source: result.source,
data: result.data
}))
);
}
} else {
logger.debug("Catalog result for " + result.source +
" has not been marked as significant. Not storing.");
Expand All @@ -99,6 +126,5 @@ function racadmCatalogJobFactory(
});
});
};

return RacadmCatalogJob;
}
61 changes: 58 additions & 3 deletions spec/lib/jobs/racadm-catalog-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,81 @@ describe(require('path').basename(__filename), function () {
});

beforeEach('Dell Racadm Catalog Job handle response beforeEach', function() {
job = new RacadmCatalogJob({action: 'getConfigCatalog'}, {}, uuid.v4());
job = new RacadmCatalogJob({action: 'getConfigCatalog', updateExistingCatalog: true}, {}, uuid.v4());

mockWaterline.catalogs.create = function(){};

this.sandbox = sinon.sandbox.create();
this.sandbox.stub(mockWaterline.catalogs,'create');

mockWaterline.catalogs.update = function(){};
this.sandbox = sinon.sandbox.create();
this.sandbox.stub(mockWaterline.catalogs,'update');

mockWaterline.catalogs.count = function(){};
this.sandbox = sinon.sandbox.create();
this.sandbox.stub(mockWaterline.catalogs,'count');
});

afterEach('Dell Racadm Catalog Job input validation', function(){
this.sandbox = sinon.sandbox.restore();
});

it('should create catalog entries for response data if store is set to true', function() {
it('should create catalog entries if store, updateExistingCatalog are ' +
'true and no copy of catalog exists', function() {
var catalog;
catalog = {
store: true,
source: 'idrac-racadm-configure',
data: 'test data 1'
};
var count = 0;
mockWaterline.catalogs.count.resolves(count);
return job.handleResponse(catalog)
.then(function() {
// Make sure we only catalog objects with store: true and no error
expect(waterline.catalogs.create).to.have.been.calledOnce;
expect(waterline.catalogs.create).to.have.been.calledWith({
node: job.nodeId,
source: 'idrac-racadm-configure',
data: 'test data 1'
});
});
});

it('should update catalog entries if store, updateExistingCatalog are ' +
'true and a copy of catalog exists', function() {
var catalog;
catalog = {
store: true,
source: 'idrac-racadm-configure',
data: 'test data 1'
};
var query = {
node: job.nodeId,
source: 'idrac-racadm-configure'
};
var count = 1;
mockWaterline.catalogs.count.resolves(count);
return job.handleResponse(catalog)
.then(function() {
// Make sure we only catalog objects with store: true and no error
expect(waterline.catalogs.update).to.have.been.calledOnce;
expect(waterline.catalogs.update).to.have.been.calledWith(query, {
node: job.nodeId,
source: 'idrac-racadm-configure',
data: 'test data 1'
});
});
});

it('should create catalog entries if store is true, updateExistingCatalog is false ', function() {
var catalog;
catalog = {
store: true,
source: 'idrac-racadm-configure',
data: 'test data 1'
};
job.updateExistingCatalog = "false";
return job.handleResponse(catalog)
.then(function() {
// Make sure we only catalog objects with store: true and no error
Expand Down

0 comments on commit f2300e1

Please sign in to comment.