Skip to content

Commit

Permalink
Merge 0a7ef1d into c2d0d56
Browse files Browse the repository at this point in the history
  • Loading branch information
danielreed authored Nov 10, 2017
2 parents c2d0d56 + 0a7ef1d commit c22de66
Showing 1 changed file with 209 additions and 19 deletions.
228 changes: 209 additions & 19 deletions test/listener/server-profiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const OneViewBrain = require('../../src/middleware/ov-brain');
const OVClient = require('../../src/oneview-sdk/ov-client');
const ResourceTransforms = require('../../src/listener/utils/resource-transforms');
const NamedRegExp = require('../../src/listener/named-regexp');
const PromiseFeedback = require('../../src/oneview-sdk/utils/emitter');

const chai = require('chai');
const sinon = require('sinon');
Expand All @@ -35,26 +36,50 @@ const assert = chai.assert;

describe('ServerProfilesListener', () => {

const profileResponse = {
type: "ServerProfileV6",
uri: "/rest/server-profiles/1a94be5c",
name: "myprofile",
description: "",
serialNumber: "VCGLPVN007",
uuid: "1a94be5c",
serverHardwareUri: null,
hyperlink: "https://0.0.0.0/#/profiles/show/overview/r/rest/server-profiles/1a94be5c?s_sid=LTIyNDcK",
serverProfileTemplateHyperlink: "https://0.0.0.0/#/profile-templates/show/overview/r/rest/server-profile-templates/650449e6?s_sid=LTIyNDcK",
serverHardwareHyperlink: "https://0.0.0.0/#/server-hardware/show/overview/r/rest/server-hardware/37333036?s_sid=LTIyNDcK",
serverHardwareTypeHyperlink: "https://0.0.0.0/#/server-hardware-types/show/general/r/rest/server-hardware-types/30D74951?s_sid=LTIyNDcK",
enclosureGroupHyperlink: "https://0.0.0.0/#/enclosuregroups/show/interconectbayconfiguration/r/rest/enclosure-groups/dfebe3a3?s_sid=LTIyNDcK",
enclosureHyperlink: "https://0.0.0.0/#/enclosure/show/overview/r/rest/enclosures/09SGHX6J1?s_sid=LTIyNDcK",
taskHyperlink: "https://0.0.0.0/#/activity/r/rest/tasks/85EDF0DA?s_sid=LTIyNDcK",
status: "OK"
};

const profilesResponse = {
members: [
{
type: "ServerProfileV6",
uri: "/rest/server-profiles/1a94be5c",
name: "profile",
description: "",
serialNumber: "VCGLPVN007",
uuid: "1a94be5c",
hyperlink: "https://0.0.0.0/#/profiles/show/overview/r/rest/server-profiles/1a94be5c?s_sid=LTIyNDcK",
serverProfileTemplateHyperlink: "https://0.0.0.0/#/profile-templates/show/overview/r/rest/server-profile-templates/650449e6?s_sid=LTIyNDcK",
serverHardwareHyperlink: "https://0.0.0.0/#/server-hardware/show/overview/r/rest/server-hardware/37333036?s_sid=LTIyNDcK",
serverHardwareTypeHyperlink: "https://0.0.0.0/#/server-hardware-types/show/general/r/rest/server-hardware-types/30D74951?s_sid=LTIyNDcK",
enclosureGroupHyperlink: "https://0.0.0.0/#/enclosuregroups/show/interconectbayconfiguration/r/rest/enclosure-groups/dfebe3a3?s_sid=LTIyNDcK",
enclosureHyperlink: "https://0.0.0.0/#/enclosure/show/overview/r/rest/enclosures/09SGHX6J1?s_sid=LTIyNDcK",
taskHyperlink: "https://0.0.0.0/#/activity/r/rest/tasks/85EDF0DA?s_sid=LTIyNDcK"
}]
members: [profileResponse]
};

const profileCompliance = {
type: "ServerProfileCompliancePreviewV1",
isOnlineUpdate: false,
automaticUpdates: [
"Create a connection to network {\"name\":\"eth1\", \"uri\":\"/rest/ethernet-networks/95717f69\"} with id 2 on Mezzanine (Mezz) 3:2-a."
],
manualUpdates: []
};

const robot = {adapterName: 'shell', on: function () { }, listen: function () {}, respond: function () {}, listenerMiddleware: function() {}, logger: {debug: function () {}, error: function () {}, info: function () {}}};
const robot = {
name: 'bot',
adapterName: 'shell',
receive: function () {},
on: function () { },
listeners: [],
listen: function (matcher, options) {listeners.push(matcher, options)},
respond: function () {},
listenerMiddleware: function() {},
logger: {debug: function () {}, error: function () {}, info: function () {}}};

// capture dialog liseners
let listeners = []; //empty after test power on runs

const oneviewConfig = {
hosts: []
Expand All @@ -71,8 +96,36 @@ describe('ServerProfilesListener', () => {

const sh = new ServerHardwareListener(robot, client, transform, brain);

it('power on profile', (done) => {
let stub1 = sinon.stub(client.ServerProfiles, 'getServerProfile').returns(Bluebird.resolve(profileResponse));
let stub2 = sinon.stub(brain, 'getDeviceNameAndHyperLink').returns({ deviceName: 'myprofile', hyperlink: '' });

let msg = {
robot: robot,
message: {text: '@bot yes.', user: {name: 'name', id: '1234'}, room: 'room'},
send: function () {}
};
sinon.spy(msg, 'send');

const serverProfilesListener = new ServerProfilesListener(robot, client, transform, sh, brain);

serverProfilesListener.PowerOnServerProfile(msg);

listeners[3](msg); //call the dialog listener with the msg

//sleep a momemt to wait for results
setTimeout(() => {
assert(msg.send.callCount === 2);
"Ok name I am going to power on the server profile myprofile. Are you sure you want to do this?\n\t\u2022 @bot yes\n\t\u2022 @bot no.".should.equal(msg.send.args[0][0]);
'name, myprofile does not have any assigned server hardware to power on. Try assigning server hardware to the profile.'.should.equal(msg.send.args[1][0]);
stub1.restore();
stub2.restore();
done();
}, 10);
});

it('constructor', (done) => {
sinon.spy(robot, "respond");
let spy = sinon.spy(robot, "respond");
const serverProfilesListener = new ServerProfilesListener(robot, client, transform, sh, brain);

let rgx0 = new NamedRegExp(serverProfilesListener.LIST_ALL);
Expand Down Expand Up @@ -122,6 +175,7 @@ describe('ServerProfilesListener', () => {

assert(constructorArgs.length === 7);

spy.restore();
done();
});

Expand Down Expand Up @@ -170,7 +224,143 @@ describe('ServerProfilesListener', () => {
assert(msg.send.callCount === 1);
expectedJsonResults.should.equal(msg.send.args[0][0]);
done();
}, 100);
}, 10);
});

it('list profile', (done) => {
let stub = sinon.stub(client.ServerProfiles, 'getServerProfile').returns(Bluebird.resolve(profileResponse));

const serverProfilesListener = new ServerProfilesListener(robot, client, transform, sh, brain);

let msg = {
robot: {},
message: {TextMessage: {user: '', text: '@bot show server profile myprofile.'}},
count: 1,
send: function () {}
};
sinon.spy(msg, "send");

serverProfilesListener.ListServerProfile(msg);

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

//sleep a momemt to wait for results
setTimeout(() => {
assert(msg.send.callCount === 1);
expectedJsonResults.should.equal(msg.send.args[0][0]);
stub.restore();
done();
}, 10);
});

it('list profile compliance', (done) => {
sinon.stub(client.ServerProfiles, 'getServerProfileCompliancePreview').returns(Bluebird.resolve(profileCompliance));

const serverProfilesListener = new ServerProfilesListener(robot, client, transform, sh, brain);

let msg = {
robot: {},
message: {TextMessage: {user: '', text: '@bot show server profile myprofile compliance preview.'}},
count: 1,
send: function () {}
};
sinon.spy(msg, "send");

serverProfilesListener.ListServerProfileCompliancePreview(msg);

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

//sleep a momemt to wait for results
setTimeout(() => {
assert(msg.send.callCount === 1);
expectedJsonResults.should.equal(msg.send.args[0][0]);
done();
}, 10);
});

it('list profile by status', (done) => {
let stub = sinon.stub(client.ServerProfiles, 'getProfilesByStatus').returns(Bluebird.resolve(profilesResponse));

const serverProfilesListener = new ServerProfilesListener(robot, client, transform, sh, brain);

let msg = {
robot: {},
message: {TextMessage: {text: '@bot show all ok server profiles.'}, user: {name: 'name'}},
count: 1,
send: function () {},
status: "OK"
};
sinon.spy(msg, "send");

serverProfilesListener.ListProfilesByStatus(msg);

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

//sleep a momemt to wait for results
setTimeout(() => {
assert(msg.send.callCount === 2);
'Okay name, the following profiles have an OK status.'.should.equal(msg.send.args[0][0]);
expectedJsonResults.should.equal(msg.send.args[1][0]);
stub.restore();
done();
}, 10);
});

it('list profile by status, no results', (done) => {
let stub = sinon.stub(client.ServerProfiles, 'getProfilesByStatus').returns(Bluebird.resolve({members: []}));

const serverProfilesListener = new ServerProfilesListener(robot, client, transform, sh, brain);

let msg = {
robot: {},
message: {TextMessage: {text: '@bot show all critical server profiles.'}, user: {name: 'name'}},
count: 1,
send: function () {},
status: "Critical"
};
sinon.spy(msg, "send");

serverProfilesListener.ListProfilesByStatus(msg);

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

//sleep a momemt to wait for results
setTimeout(() => {
assert(msg.send.callCount === 1);
"name, I didn't find any profiles with a critical status.".should.equal(msg.send.args[0][0]);
stub.restore();
done();
}, 10);
});

it('make server profile compliant', (done) => {
let stub = sinon.stub(client.ServerProfiles, 'updateServerProfileCompliance').returns(
new PromiseFeedback((feedback) => {
return Bluebird.resolve(profileResponse);
})
);

const serverProfilesListener = new ServerProfilesListener(robot, client, transform, sh, brain);

let msg = {
robot: {},
message: {TextMessage: {text: '@bot make server profile myprofile compliant.'}, user: {name: 'name'}},
count: 1,
send: function () {}
};
sinon.spy(msg, "send");

serverProfilesListener.MakeServerProfileCompliant('123123', msg, false);

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

//sleep a momemt to wait for results
setTimeout(() => {
assert(msg.send.callCount === 2);
"Finished making myprofile compliant.".should.equal(msg.send.args[0][0]);
expectedJsonResults.should.equal(msg.send.args[1][0]);
stub.restore();
done();
}, 10);
});
});

0 comments on commit c22de66

Please sign in to comment.