Skip to content

Commit

Permalink
Merge b147f1e into 2cc9133
Browse files Browse the repository at this point in the history
  • Loading branch information
danielreed committed Aug 19, 2019
2 parents 2cc9133 + b147f1e commit 962060e
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 51 deletions.
80 changes: 40 additions & 40 deletions Dockerfile-core
@@ -1,7 +1,7 @@
# Docker best practices/commands:
# https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/

FROM alpine:3.5
FROM alpine:3.8

RUN adduser -Ds /bin/bash docker

Expand Down Expand Up @@ -34,12 +34,12 @@ RUN apk --no-cache add \
sudo \
bash \
php5-curl
#RUN curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
#RUN curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
#RUN apk add --no-cache aptitude
#RUN aptitude install -y
RUN apk --no-cache add \
jq \
nodejs
RUN apk --no-cache add --update nodejs npm

RUN node -v

RUN npm config set proxy $http_proxy
RUN npm config set http-proxy $http_proxy
Expand All @@ -48,7 +48,7 @@ RUN npm config set https-proxy $http_proxy

# 3. Install Hubot

RUN npm install -g yo generator-hubot css-what css-select
RUN npm install -g yo generator-hubot

###############################################################################
USER docker
Expand All @@ -64,32 +64,32 @@ RUN echo "n" | yo hubot --defaults --name="bot" --adapter=slack
USER root

# Avoid warnings for deprecated dependencies:
RUN npm install -g minimatch@^3.0.2; \
npm install -g graceful-fs@^4.0.0;
RUN npm install -g minimatch@^3.0.4; \
npm install -g graceful-fs@^4.2.2;

RUN npm install gulp; \
npm install gulp-task-listing@^1.0.1;
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; \
sed -i -e s/graceful-fs/fs-extra/ -e s/fs.rename/fs.move/ ./lib/utils/rename.js
#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


RUN npm install hubot@2.x \
amqp@^0.2.6 \
d3@^4.2.7 \
jsdom@^9.8.0 \
svg2png@^4.0.0 \
fuzzyset.js@0.0.1 \
nlp_compromise@^6.5.0 \
request@^2.75.0 \
request-promise@^4.1.1;
RUN npm install hubot@3.x \
amqp@^0.2.7 \
d3@^5.9.7 \
jsdom@^15.1.1 \
svg2png@^4.1.1 \
fuzzyset.js@0.0.8 \
compromise@^11.14.2 \
request@^2.88.0 \
request-promise@^4.2.4;


RUN npm install del@^2.2.2;
RUN npm install del@^5.0.0;

###############################################################################
USER root
Expand All @@ -98,30 +98,30 @@ USER root

WORKDIR /home/docker/hubot-core-org

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

# Avoid warnings for deprecated dependencies:
RUN npm install minimatch@^3.0.2; \
npm install graceful-fs@^4.0.0;
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; \
npm install gulp-task-listing@^1.0.1; \
npm install gulp-util@^3.0.7

RUN npm install hubot@2.x \
amqp@^0.2.6 \
d3@^4.2.7 \
jsdom@^9.8.0 \
svg2png@^4.0.0 \
fuzzyset.js@0.0.1 \
nlp_compromise@^6.5.0 \
request@^2.75.0 \
request-promise@^4.1.1 \
del@^2.2.2;
npm install gulp-task-listing@^1.1.0; \
npm install fancy-log@^1.3.3

RUN npm install hubot@3.x \
amqp@^0.2.7 \
d3@^5.9.7 \
jsdom@^15.1.1 \
svg2png@^4.1.1 \
fuzzyset.js@0.0.8 \
compromise@^11.14.2 \
request@^2.88.0 \
request-promise@^4.2.4 \
del@^5.0.0;


# 5. Copy config file
Expand Down
18 changes: 18 additions & 0 deletions src/listener/server-hardware.js
Expand Up @@ -42,6 +42,7 @@ class ServerHardwareListener extends Listener {
this.LIST=/(?:get|list|show) (?!\/rest\/server-profiles\/)(:<host>.*?)(?:\/rest\/server-hardware\/)(:<serverId>[a-zA-Z0-9_-]*?)\.$/i;
this.LIST_STATUS=/(?:get|list|show) (?:all ){0,1}(:<status>critical|ok|disabled|warning*?) (?:server ){0,1}hardware\.$/i;
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.switchBoard = new Conversation(robot);

Expand All @@ -66,6 +67,9 @@ class ServerHardwareListener extends Listener {

this.respond(this.LIST_POWER, this.ListHardwareByPowerState.bind(this));
this.capabilities.push(this.BULLET + "List all powered on/off (server) hardware.");

this.respond(this.LIST_UUID_LIGHT, this.ListHardwareByUuidLight.bind(this));
this.capabilities.push(this.BULLET + "List all (server) hardware by UUID light state (e.g. list all hardware with UUID light on).");
}

PowerOnHardware(msg) {
Expand Down Expand Up @@ -193,6 +197,20 @@ class ServerHardwareListener extends Listener {
});
}

ListHardwareByUuidLight(msg) {
let uuidlight = msg.uuidlight.toLowerCase();
this.client.ServerHardware.getHardwareByUuidLight(uuidlight).then((res) => {
if (res.members.length === 0) {
return this.transform.text(msg, msg.message.user.name + ", I didn't find any hardware with the UUID light " + uuidlight.toUpperCase());
} else {
return this.pagination(msg, res, "Okay " + msg.message.user.name + ", the following hardware have the UUID light " + uuidlight.toUpperCase());
}
}).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
20 changes: 19 additions & 1 deletion src/oneview-sdk/server-hardware.js
@@ -1,5 +1,5 @@
/*
(c) Copyright 2016-2017 Hewlett Packard Enterprise Development LP
(c) Copyright 2016-2019 Hewlett Packard Enterprise Development LP
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -101,6 +101,24 @@ class ServerHardware {
});
}

getHardwareByUuidLight(lightState) {
let promises = [];
let resObj = {'members': []};

for (let connection of this.connections.values()) {
promises.push(connection.get(uri + "?filter=\"uidState=" + lightState + "\""));
}

return Promise.all(promises).then(response => {
for (let res of response) {
resObj.members.push(...res.members);
}
return new Promise((resolve) => {
resolve(resObj);
});
});
}

/*
This function returns a response that contains both the server's interconnect port
statistics and the telemetry configurations for the port.
Expand Down
2 changes: 1 addition & 1 deletion test/charting/chart.js
Expand Up @@ -33,7 +33,7 @@ function relative(relPath) {
}

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

let networkMetricList = [
{metricName:'receiveKilobytesPerSec',metricSamples: [ '69', '69', '69']},
Expand Down
2 changes: 1 addition & 1 deletion test/charting/dashboard.js
Expand Up @@ -33,7 +33,7 @@ function relative(relPath) {
}

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

let aggregatedAlerts = {
members: [{
Expand Down
9 changes: 5 additions & 4 deletions test/listener/bot.js
@@ -1,5 +1,5 @@
/*
(c) Copyright 2016-2017 Hewlett Packard Enterprise Development LP
(c) Copyright 2016-2019 Hewlett Packard Enterprise Development LP
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -157,7 +157,8 @@ Server Profile help (e.g. sp help).\n\t\u2022 Server Profile Template help \
\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.'.should.equal(msg.send.args[0][0]);
\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).'.should.equal(msg.send.args[0][0]);
spy.restore();
done();
}, 100);
Expand Down Expand Up @@ -250,7 +251,7 @@ for a profile template (e.g. fix compliance for docker swarm).\nServer hardware
(e.g. turn on Encl1, bay 1).\n\t• List all (server) hardware (e.g. list all hardware).\n\t\u2022 List server hardware utilization (e.g. list \
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.'.should.equal(msg.send.args[0][0]);
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.'.should.equal(msg.send.args[0][0]);
spy.restore();
done();
}, 100);
Expand Down Expand Up @@ -286,7 +287,7 @@ for a profile template (e.g. fix compliance for docker swarm).\nServer hardware
(e.g. turn on Encl1, bay 1).\n\t• List all (server) hardware (e.g. list all hardware).\n\t\u2022 List server hardware utilization (e.g. list \
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.'.should.equal(msg.send.args[0][0]);
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.'.should.equal(msg.send.args[0][0]);
spy.restore();
done();
}, 100);
Expand Down
4 changes: 2 additions & 2 deletions test/listener/oneview.js
@@ -1,5 +1,5 @@
/*
(c) Copyright 2016-2017 Hewlett Packard Enterprise Development LP
(c) Copyright 2016-2019 Hewlett Packard Enterprise Development LP
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -54,7 +54,7 @@ describe('OVListener', () => {
let spy = sinon.spy(robot, 'respond');
listener(robot, client, brain);

assert(robot.respond.callCount === 31); // 31 listeners
assert(robot.respond.callCount === 32); // 32 listeners
spy.restore();
done();
});
Expand Down
60 changes: 59 additions & 1 deletion test/listener/server-hardware.js
@@ -1,5 +1,5 @@
/*
(c) Copyright 2016-2017 Hewlett Packard Enterprise Development LP
(c) Copyright 2016-2019 Hewlett Packard Enterprise Development LP
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -52,6 +52,7 @@ describe('ServerHardware', function() {
name: "0000A6610EE, bay 5",
powerState: "Off",
status: "Ok",
uuidState: "On",
uri: "/rest/server-hardware/eb13eab8-adsf",
model: "BL460c Gen8 1",
serialNumber: "1234",
Expand Down Expand Up @@ -152,6 +153,7 @@ describe('ServerHardware', function() {
let rgx5 = new NamedRegExp(serverHardwareListener.LIST);
let rgx6 = new NamedRegExp(serverHardwareListener.LIST_STATUS);
let rgx7 = new NamedRegExp(serverHardwareListener.LIST_POWER);
let rgx8 = new NamedRegExp(serverHardwareListener.LIST_UUID_LIGHT);

let constructorArgs = robot.respond.getCalls();

Expand Down Expand Up @@ -195,6 +197,11 @@ describe('ServerHardware', function() {
'bound ListHardwareByPowerState'.should.equal(constructorArgs[7].args[2].name);
assert.isFalse(constructorArgs[7].args[2].hasOwnProperty('prototype'));

rgx8.should.deep.equal(constructorArgs[8].args[0]);
assert(typeof constructorArgs[7].args[2] === 'function');
'bound ListHardwareByUuidLight'.should.equal(constructorArgs[8].args[2].name);
assert.isFalse(constructorArgs[8].args[2].hasOwnProperty('prototype'));

spy.restore();
done();
});
Expand All @@ -210,6 +217,7 @@ describe('ServerHardware', function() {
let rgx5 = new NamedRegExp(serverHardwareListener.LIST);
let rgx6 = new NamedRegExp(serverHardwareListener.LIST_STATUS);
let rgx7 = new NamedRegExp(serverHardwareListener.LIST_POWER);
let rgx8 = new NamedRegExp(serverHardwareListener.LIST_UUID_LIGHT);

assert.isTrue(rgx0.test('@bot power on /rest/server-hardware/eb13eab8-adsf.'));
assert.isTrue(rgx1.test('@bot power off /rest/server-hardware/eb13eab8-adsf.'));
Expand All @@ -219,6 +227,7 @@ describe('ServerHardware', function() {
assert.isTrue(rgx5.test('@bot list /rest/server-hardware/eb13eab8-adsf.'));
assert.isTrue(rgx6.test('@bot list all critical hardware.'));
assert.isTrue(rgx7.test('@bot list all powered on hardware.'));
assert.isTrue(rgx8.test('@bot show all hardware with uuid light off.'));

done();
});
Expand Down Expand Up @@ -819,4 +828,53 @@ describe('ServerHardware', function() {
}, 9900);
});

it('list by uuid on', (done) => {
let stub = sinon.stub(client.ServerHardware, 'getHardwareByUuidLight').returns(Bluebird.resolve(serverHardwaresResponseOk));
const serverHardwareListener = new ServerHardwareListener(robot, client, transform, brain);

let msg = {
robot: robot,
uuidlight: 'on',
message: {text: '@bot show all hardware with uuid light on.', user: {name: 'name', id: '1234'}, room: 'room'},
send: function () {}
};
let spy = sinon.spy(msg, "send");

serverHardwareListener.ListHardwareByUuidLight(msg);

const expectedJsonResults = JSON.stringify(serverHardwaresResponseOk, null, ' ');

setTimeout(() => {
assert(msg.send.callCount === 2);
"Okay name, the following hardware have the UUID light ON.".should.equal(msg.send.args[0][0]);
expectedJsonResults.should.equal(msg.send.args[1][0]);
stub.restore();
spy.restore();
done();
}, 10);
});

it('list by uuid no results', (done) => {
let stub = sinon.stub(client.ServerHardware, 'getHardwareByUuidLight').returns(Bluebird.resolve({members: []}));
const serverHardwareListener = new ServerHardwareListener(robot, client, transform, brain);

let msg = {
robot: robot,
uuidlight: 'on',
message: {text: '@bot show all hardware with uuid light on.', user: {name: 'name', id: '1234'}, room: 'room'},
send: function () {}
};
let spy = sinon.spy(msg, "send");

serverHardwareListener.ListHardwareByUuidLight(msg);

setTimeout(() => {
assert(msg.send.callCount === 1);
"name, I didn't find any hardware with the UUID light ON.".should.equal(msg.send.args[0][0]);
stub.restore();
spy.restore();
done();
}, 10);
});

});

0 comments on commit 962060e

Please sign in to comment.