Skip to content

Commit

Permalink
Merge pull request #591 from nortonluo/allnictolookup
Browse files Browse the repository at this point in the history
RAC-6724 Add all NICs MAC to lookup table
  • Loading branch information
iceiilin authored Apr 3, 2018
2 parents 3eca809 + 87fb356 commit 9b4f98c
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 24 deletions.
21 changes: 15 additions & 6 deletions lib/jobs/dell-wsman-update-lookups.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,23 @@ function updateWsmanLookupsJobFactory(
UpdateWsmanLookupsJob.prototype._run = function run() {
var self = this;
return waterline.catalogs.findLatestCatalogOfSource(self.nodeId, 'manager')
.then(function(smiData) {
if(!smiData || !smiData.data || !smiData.data.DCIM_IDRACCardView || !smiData.data.DCIM_IDRACCardView.PermanentMACAddress){
return Promise.reject(new Error('Could not find mac in SMI inventory!'));
}
return waterline.lookups.upsertNodeToMacAddress(self.nodeId, smiData.data.DCIM_IDRACCardView.PermanentMACAddress);
.then(function(smiManagerData){
if(!smiManagerData || !smiManagerData.data || !smiManagerData.data.DCIM_IDRACCardView || !smiManagerData.data.DCIM_IDRACCardView.PermanentMACAddress)
{return Promise.reject(new Error('Could not found management mac in SMI inventory!'));}
return waterline.lookups.upsertNodeToMacAddress(self.nodeId, smiManagerData.data.DCIM_IDRACCardView.PermanentMACAddress);
})
.then(function(){
return waterline.catalogs.findLatestCatalogOfSource(self.nodeId, 'nics');
})
.then(function(smiNicData) {
if(!smiNicData || !smiNicData.data){
return Promise.reject(new Error('Could not found nic mac in SMI inventory!'));}
return _.map(smiNicData.data, function(item){
return waterline.lookups.upsertNodeToMacAddress(self.nodeId, item.currentMACAddress);
});
})
.then(function() {
self._done();
return self._done();
})
.catch(function(err){
self._done(err);
Expand Down
73 changes: 55 additions & 18 deletions spec/lib/jobs/dell-wsman-update-lookups-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,35 @@
var uuid = require('node-uuid');

describe('wsman-update-lookups-job', function() {
var wsmanBmcCatalog = {
id: 'CatalogsId',
source: 'manager',
data: {
"DCIM_IDRACCardView": {
"DeviceDescription": "iDRAC",
"LANEnabledState": "1",
"PermanentMACAddress": "18:66:da:52:2c:9c",
"FQDD": "iDRAC.Embedded.1-1",
"DNSRacName": "idrac-ABCD123"
}
}
};
var wsmanNicCatalog = {
source: 'nics',
data: [{
name: 'nic1',
currentMACAddress: "18:66:da:52:2c:c2"
},
{
name: 'nic2',
currentMACAddress: '18:66:da:52:2c:c3'
},
{
name: 'nic3',
currentMACAddress: "18:66:da:52:2c:c4"
}]
};

var waterline = { catalogs: {}, lookups: {} },
UpdateWsmanLookupsJob,
job,
Expand All @@ -20,40 +49,38 @@ describe('wsman-update-lookups-job', function() {
});

beforeEach(function() {
wsmanCatalog = {
id: 'CatalogsId',
source: 'manager',
data: {
"DCIM_IDRACCardView": {
"DeviceDescription": "iDRAC",
"LANEnabledState": "1",
"PermanentMACAddress": "18:66:da:52:2c:9c",
"FQDD": "iDRAC.Embedded.1-1",
"DNSRacName": "idrac-ABCD123"
}
}
};
waterline.catalogs.findLatestCatalogOfSource = this.sandbox.stub().resolves(wsmanCatalog);
waterline.lookups.upsertNodeToMacAddress = this.sandbox.stub().resolves();
waterline.catalogs.findLatestCatalogOfSource = this.sandbox.stub();
waterline.lookups.upsertNodeToMacAddress = this.sandbox.stub();
job = new UpdateWsmanLookupsJob({}, { target: 'someNodeId'}, uuid.v4());
this.sandbox.restore();
});

afterEach(function() {
this.sandbox.restore();
});

it('should update lookups from inventory catalog', function() {
waterline.catalogs.findLatestCatalogOfSource.withArgs('someNodeId', 'manager').resolves(wsmanBmcCatalog);
waterline.catalogs.findLatestCatalogOfSource.withArgs('someNodeId', 'nics').resolves(wsmanNicCatalog);
return job._run()
.then(function() {
expect(waterline.lookups.upsertNodeToMacAddress).to.be.calledOnce;
expect(waterline.lookups.upsertNodeToMacAddress).to.be.called;
expect(waterline.lookups.upsertNodeToMacAddress).to.be
.calledWithExactly('someNodeId', '18:66:da:52:2c:9c');
.calledWith('someNodeId', '18:66:da:52:2c:9c');
expect(waterline.lookups.upsertNodeToMacAddress).to.be
.calledWith('someNodeId', '18:66:da:52:2c:c2');
expect(waterline.lookups.upsertNodeToMacAddress).to.be
.calledWith('someNodeId', '18:66:da:52:2c:c3');
expect(waterline.lookups.upsertNodeToMacAddress).to.be
.calledWith('someNodeId', '18:66:da:52:2c:c4');
});
});

it('should fail if lookups inserts fail', function() {
var error = new Error('some Waterline error');
waterline.lookups.upsertNodeToMacAddress.rejects(error);
waterline.catalogs.findLatestCatalogOfSource.withArgs('someNodeId', 'manager').resolves(wsmanBmcCatalog);
waterline.catalogs.findLatestCatalogOfSource.withArgs('someNodeId', 'nics').resolves(wsmanNicCatalog);
this.sandbox.stub(job, '_done').resolves();
return job._run()
.then(function() {
Expand All @@ -66,7 +93,17 @@ describe('wsman-update-lookups-job', function() {
this.sandbox.stub(job, '_done').resolves();
return job._run()
.then(function() {
expect(job._done.args[0][0]).to.deep.equal(new Error('Could not find mac in SMI inventory!'));
expect(job._done.args[0][0]).to.deep.equal(new Error('Could not find management mac in SMI inventory!'));
});
});

it('should fail if nic data is unavailable in catalog', function() {
waterline.catalogs.findLatestCatalogOfSource.withArgs('someNodeId', 'manager').resolves(wsmanBmcCatalog);
waterline.catalogs.findLatestCatalogOfSource.withArgs('someNodeId', 'nics').resolves(undefined);
this.sandbox.stub(job, '_done').resolves();
return job._run()
.then(function() {
expect(job._done.args[0][0]).to.deep.equal(new Error('Could not find nic mac in SMI inventory!'));
});
});
});

0 comments on commit 9b4f98c

Please sign in to comment.