Skip to content

Commit

Permalink
Adding filters for server hardware with/without profiles, improving (#…
Browse files Browse the repository at this point in the history
…150)

coverage
  • Loading branch information
Daniel Reed committed Aug 21, 2019
1 parent ef2959b commit 4a305fe
Show file tree
Hide file tree
Showing 12 changed files with 283 additions and 35 deletions.
8 changes: 0 additions & 8 deletions Dockerfile-core
Expand Up @@ -70,10 +70,6 @@ RUN npm install -g minimatch@^3.0.4; \
RUN npm install gulp; \
npm install gulp-task-listing@^1.1.0;

# To install avoid cross-device link not permitted...
#RUN cd /usr/lib/node_modules/npm; npm install fs-extra;
#RUN cd /usr/lib/node_modules/npm; sed -i -e s/graceful-fs/fs-extra/ -e s/fs.rename/fs.move/ ./lib/utils/rename.js;

###############################################################################
USER docker

Expand Down Expand Up @@ -102,10 +98,6 @@ WORKDIR /home/docker/hubot-core-org
RUN npm install -g minimatch@^3.0.4; \
npm install -g graceful-fs@^4.2.2;

# To install avoid cross-device link not permitted...
#RUN cd /usr/lib/node_modules/npm; npm install fs-extra;
#RUN cd /usr/lib/node_modules/npm; sed -i -e s/graceful-fs/fs-extra/ -e s/fs.rename/fs.move/ ./lib/utils/rename.js;

RUN npm install -g gulp; \
npm install; \
npm install gulp; \
Expand Down
32 changes: 32 additions & 0 deletions src/listener/server-hardware.js
Expand Up @@ -44,6 +44,8 @@ class ServerHardwareListener extends Listener {
this.LIST_POWER=/(?:get|list|show) (?:all ){0,1}(:<powerState>powered on|powered off*?) (?:server ){0,1}hardware\.$/i;
this.LIST_UUID_LIGHT=/(?:get|list|show) all (?:server ){0,1}hardware with uuid light (:<uuidlight>on|off*?)\.$/i;
this.LIST_ASSETTAG=/(?:get|list|show) (?:server ){0,1}hardware with asset tag (:<assettag>[a-zA-Z0-9_-]*?)\.$/i;
this.LIST_PROFILE_APPLIED=/(?:get|list|show) (?:server ){0,1}hardware with profiles\.$/i;
this.LIST_NO_PROFILE_APPLIED=/(?:get|list|show) (?:server ){0,1}hardware (?:without|with no) profiles\.$/i;
//TODO filter by model and sht

this.switchBoard = new Conversation(robot);
Expand Down Expand Up @@ -75,6 +77,12 @@ class ServerHardwareListener extends Listener {

this.respond(this.LIST_ASSETTAG, this.ListHardwareByAssetTag.bind(this));
this.capabilities.push(this.BULLET + "List (server) hardware by asset tag (e.g. show hardware with asset tag cluster1).");

this.respond(this.LIST_PROFILE_APPLIED, this.ListHardwareWithProfiles.bind(this));
this.capabilities.push(this.BULLET + "List (server) hardware with profiles (e.g. show hardware with profiles).");

this.respond(this.LIST_NO_PROFILE_APPLIED, this.ListHardwareWithNoProfiles.bind(this));
this.capabilities.push(this.BULLET + "Show (server) hardware without profiles (e.g. list hardware with no profiles).");
}

PowerOnHardware(msg) {
Expand Down Expand Up @@ -228,6 +236,30 @@ class ServerHardwareListener extends Listener {
});
}

ListHardwareWithProfiles(msg) {
this.client.ServerHardware.getHardwareWithFilter('state', 'ProfileApplied').then((res) => {
if (res.members.length === 0) {
return this.transform.text(msg, msg.message.user.name + ", I didn't find any hardware with profiles");
} else {
return this.pagination(msg, res, "Okay " + msg.message.user.name + ", the following hardware have profiles");
}
}).catch((err) => {
return this.transform.error(msg, err);
});
}

ListHardwareWithNoProfiles(msg) {
this.client.ServerHardware.getHardwareWithFilter('state', 'NoProfileApplied').then((res) => {
if (res.members.length === 0) {
return this.transform.text(msg, msg.message.user.name + ", I didn't find any hardware without profiles");
} else {
return this.pagination(msg, res, "Okay " + msg.message.user.name + ", the following hardware have no profiles applied");
}
}).catch((err) => {
return this.transform.error(msg, err);
});
}

ListServerHardwareUtilization(msg) {
this.transform.send(msg, "Ok " + msg.message.user.name + " I'm going to create the CPU and network utilization charts. This can take quite some time.");

Expand Down
2 changes: 1 addition & 1 deletion src/middleware/utils/lexer.js
Expand Up @@ -21,7 +21,7 @@ THE SOFTWARE.
*/
const FuzzySet = require('fuzzyset.js');
const space = /\s+/;
const bladeName = /^(\D*)(.*?), bay (\d+)$/;
const bladeName = /^(\D*)(.*?) bay (\d+)$/;
const maxNgram = 10;
const minNgram = 3;
const fuzzySetThreshold = 0.83;//A fuzzy match that is less than this value is not considered a good enough match to replace
Expand Down
6 changes: 1 addition & 5 deletions test/charting/chart.js
Expand Up @@ -28,12 +28,8 @@ const chai = require('chai');

chai.should();

function relative(relPath) {
return path.resolve(__dirname, relPath);
}

describe('Chart', function() {
this.timeout(2700);
this.timeout(2900);

let networkMetricList = [
{metricName:'receiveKilobytesPerSec',metricSamples: [ '69', '69', '69']},
Expand Down
6 changes: 1 addition & 5 deletions test/charting/dashboard.js
Expand Up @@ -28,12 +28,8 @@ const chai = require('chai');

chai.should();

function relative(relPath) {
return path.resolve(__dirname, relPath);
}

describe('Dashboard', function() {
this.timeout(2700);
this.timeout(2900);

let aggregatedAlerts = {
members: [{
Expand Down
14 changes: 11 additions & 3 deletions test/listener/bot.js
Expand Up @@ -159,7 +159,10 @@ Server Profile help (e.g. sp help).\n\t\u2022 Server Profile Template help \
\n\t\u2022 List all critical/warning/ok/disabled (server) hardware (e.g. list all critical hardware).\
\n\t\u2022 List all powered on/off (server) hardware.\
\n\t\u2022 List all (server) hardware by UUID light state (e.g. list all hardware with UUID light on).\
\n\t\u2022 List (server) hardware by asset tag (e.g. show hardware with asset tag cluster1).'.should.equal(msg.send.args[0][0]);
\n\t\u2022 List (server) hardware by asset tag (e.g. show hardware with asset tag cluster1).\
\n\t\u2022 List (server) hardware with profiles (e.g. show hardware with profiles).\
\n\t\u2022 Show (server) hardware without profiles (e.g. list hardware with no profiles).'
.should.equal(msg.send.args[0][0]);
spy.restore();
done();
}, 100);
Expand Down Expand Up @@ -253,7 +256,10 @@ for a profile template (e.g. fix compliance for docker swarm).\nServer hardware
Encl1, bay 1 utilization).\n\t\u2022 List server hardware utilization (e.g. list Encl1, bay 1 utilization).\n\t\u2022 List server hardware by \
name (e.g. list Encl1, bay 1).\n\t\u2022 List all critical/warning/ok/disabled (server) hardware (e.g. list all critical hardware).\n\t\u2022 \
List all powered on/off (server) hardware.\n\t\u2022 List all (server) hardware by UUID light state (e.g. list all hardware with UUID light on).\n\t\u2022 \
List (server) hardware by asset tag (e.g. show hardware with asset tag cluster1).\n.'.should.equal(msg.send.args[0][0]);
List (server) hardware by asset tag (e.g. show hardware with asset tag cluster1).\n\t\u2022 \
List (server) hardware with profiles (e.g. show hardware with profiles).\n\t\u2022 \
Show (server) hardware without profiles (e.g. list hardware with no profiles).\n.'
.should.equal(msg.send.args[0][0]);
spy.restore();
done();
}, 100);
Expand Down Expand Up @@ -290,7 +296,9 @@ for a profile template (e.g. fix compliance for docker swarm).\nServer hardware
Encl1, bay 1 utilization).\n\t\u2022 List server hardware utilization (e.g. list Encl1, bay 1 utilization).\n\t\u2022 List server hardware by \
name (e.g. list Encl1, bay 1).\n\t\u2022 List all critical/warning/ok/disabled (server) hardware (e.g. list all critical hardware).\n\t\u2022 \
List all powered on/off (server) hardware.\n\t\u2022 List all (server) hardware by UUID light state (e.g. list all hardware with UUID light on).\n\t\u2022 \
List (server) hardware by asset tag (e.g. show hardware with asset tag cluster1).\n.'.should.equal(msg.send.args[0][0]);
List (server) hardware by asset tag (e.g. show hardware with asset tag cluster1).\n\t\u2022 \
List (server) hardware with profiles (e.g. show hardware with profiles).\n\t\u2022 \
Show (server) hardware without profiles (e.g. list hardware with no profiles).\n.'.should.equal(msg.send.args[0][0]);
spy.restore();
done();
}, 100);
Expand Down
5 changes: 3 additions & 2 deletions test/listener/dashboard.js
Expand Up @@ -32,7 +32,8 @@ const Bluebird = require('bluebird');
chai.should();
const assert = chai.assert;

describe('DashboardListener', () => {
describe('DashboardListener', function() {
this.timeout(10000);

const robot = {adapterName: 'shell', on: function () { }, listen: function () {}, respond: function () {}, listenerMiddleware: function() {}, logger: {debug: function () {}, error: function () {}, info: function () {}}};

Expand Down Expand Up @@ -132,7 +133,7 @@ describe('DashboardListener', () => {
stub3.restore();
stub4.restore();
done();
}, 100);
}, 2100);
});

it('show error', (done) => {
Expand Down
4 changes: 2 additions & 2 deletions test/listener/oneview.js
Expand Up @@ -25,7 +25,6 @@ const OVClient = require('../../src/oneview-sdk/ov-client');

const chai = require('chai');
const sinon = require('sinon');
const Bluebird = require('bluebird');

chai.should();
const assert = chai.assert;
Expand Down Expand Up @@ -53,7 +52,8 @@ describe('OVListener', () => {
it('constructor', (done) => {
let spy = sinon.spy(robot, 'respond');
listener(robot, client, brain);
assert(robot.respond.callCount === 33); // 33 listeners

assert(robot.respond.callCount === 35); // 35 listeners
spy.restore();
done();
});
Expand Down

0 comments on commit 4a305fe

Please sign in to comment.