Migrate node-details controller tests to new framework

Previously, the node-details controller tests used a locally defined mock
of the ironic-api. With this change the tests now use the recently
developed common backend mock.

Change-Id: Ibbae1f48e1c2f592fab5b9cde6a7b3712460e8a9
Co-Authored-By: Anup Navare <anup.d.navare@intel.com>
This commit is contained in:
Peter Piela 2017-07-24 14:04:31 -04:00 committed by Anup Navare
parent 4315f1e64a
commit 36790d4d6c
2 changed files with 156 additions and 127 deletions

View File

@ -514,10 +514,6 @@
return [responseCode.SUCCESS, {}]; return [responseCode.SUCCESS, {}];
}); });
// Get the ports belonging to a specified node
$httpBackend.whenGET(/\/api\/ironic\/ports/)
.respond(responseCode.SUCCESS, []);
// Get boot device // Get boot device
$httpBackend.whenGET(/\/api\/ironic\/nodes\/([^\/]+)\/boot_device$/, $httpBackend.whenGET(/\/api\/ironic\/nodes\/([^\/]+)\/boot_device$/,
undefined, undefined,
@ -603,9 +599,9 @@
}); });
// Get ports // Get ports
$httpBackend.whenGET(/\/api\/ironic\/ports\/$/) $httpBackend.whenGET(/\/api\/ironic\/ports\//)
.respond(function(method, url, data) { .respond(function(method, url, data, header, params) {
var nodeId = JSON.parse(data).node_id; var nodeId = params.node_id;
var status = responseCode.RESOURCE_NOT_FOUND; var status = responseCode.RESOURCE_NOT_FOUND;
var ports = []; var ports = [];
if (angular.isDefined(nodes[nodeId])) { if (angular.isDefined(nodes[nodeId])) {
@ -624,9 +620,9 @@
}); });
// Get portgroups. This function is not fully implemented. // Get portgroups. This function is not fully implemented.
$httpBackend.whenGET(/\/api\/ironic\/ports\/$/) $httpBackend.whenGET(/\/api\/ironic\/portgroups\//)
.respond(function(method, url, data) { .respond(function(method, url, data, header, params) {
var nodeId = JSON.parse(data).node_id; var nodeId = params.node_id;
var status = responseCode.RESOURCE_NOT_FOUND; var status = responseCode.RESOURCE_NOT_FOUND;
var portgroups = []; var portgroups = [];
if (angular.isDefined(nodes[nodeId])) { if (angular.isDefined(nodes[nodeId])) {

View File

@ -18,80 +18,8 @@
'use strict'; 'use strict';
describe('horizon.dashboard.admin.ironic.node-details', function () { describe('horizon.dashboard.admin.ironic.node-details', function () {
var ctrl, $q, nodeStateTransitionService; var nodeStateTransitionService, $controller, $location,
var nodeUuid = "0123abcd-0123-4567-abcd-0123456789ab"; ironicBackendMockService, $rootScope, ironicAPI;
var nodeName = "herp";
var numPorts = 2;
var bootDevice = {boot_device: 'pxe', persistent: true};
var consoleEnabled = true;
var consoleInfo = "console-info";
function portUuid(nodeUuid, index) {
return '' + index + index + nodeUuid.substring(2);
}
function portMacAddr(index) {
var mac = '' + index + index;
for (var i = 0; i < 5; i++) {
mac += ':' + index + index;
}
return mac;
}
function createPort(nodeUuid, index, extra) {
var port = {uuid: portUuid(nodeUuid, index),
address: portMacAddr(index)};
port.id = port.uuid;
port.name = port.address;
if (angular.isDefined(extra)) {
port.extra = extra;
}
return port;
}
function createNode(name, uuid) {
return {name: name,
uuid: uuid,
provision_state: 'enroll'};
}
var ironicAPI = {
getNode: function (uuid) {
var node = createNode(nodeName, uuid);
return $q.when(node);
},
getPortsWithNode: function (uuid) {
var ports = [];
for (var i = 0; i < numPorts; i++) {
ports.push(createPort(uuid, i));
}
return $q.when(ports);
},
getPortgroups: function() {
return $q.when([]);
},
getBootDevice: function () {
return $q.when(bootDevice);
},
validateNode: function() {
return $q.when({});
},
nodeGetConsole: function() {
return $q.when({console_enabled: consoleEnabled,
console_info: consoleInfo});
}
};
var nodeActions = {
getPowerTransitions: function() {
return [];
}
};
beforeEach(module(function($provide) { beforeEach(module(function($provide) {
$provide.value('$uibModal', jasmine.createSpy()); $provide.value('$uibModal', jasmine.createSpy());
@ -99,16 +27,15 @@
beforeEach(module('horizon.dashboard.admin.ironic')); beforeEach(module('horizon.dashboard.admin.ironic'));
beforeEach(module(function($provide) { beforeEach(module('horizon.framework.util'));
$provide.value('horizon.app.core.openstack-service-api.ironic',
ironicAPI);
}));
beforeEach(module(function($provide) { beforeEach(module(function($provide) {
$provide.value('horizon.framework.widgets.toast.service', $provide.value('horizon.framework.widgets.toast.service',
{}); {add: function() {}});
})); }));
beforeEach(module('horizon.app.core.openstack-service-api'));
beforeEach(module(function($provide) { beforeEach(module(function($provide) {
$provide.value('horizon.dashboard.admin.ironic.edit-node.service', $provide.value('horizon.dashboard.admin.ironic.edit-node.service',
{}); {});
@ -120,89 +47,195 @@
})); }));
beforeEach(inject(function ($injector, _$rootScope_, _$location_) { beforeEach(inject(function ($injector, _$rootScope_, _$location_) {
var scope = _$rootScope_.$new(); $location = _$location_;
$q = $injector.get('$q'); $controller = $injector.get('$controller');
var controller = $injector.get('$controller'); $rootScope = _$rootScope_;
var $location = _$location_;
$location.path('/admin/ironic/' + nodeUuid + '/');
nodeStateTransitionService = $injector.get( nodeStateTransitionService = $injector.get(
'horizon.dashboard.admin.ironic.node-state-transition.service'); 'horizon.dashboard.admin.ironic.node-state-transition.service');
ctrl = controller( ironicBackendMockService =
$injector.get('horizon.dashboard.admin.ironic.backend-mock.service');
ironicBackendMockService.init();
ironicAPI =
$injector.get('horizon.app.core.openstack-service-api.ironic');
}));
function createNode() {
return ironicAPI.createNode(
{driver: ironicBackendMockService.params.defaultDriver})
.then(function(response) {
return response.data;
});
}
function createController(node) {
$location.path('/admin/ironic/' + node.uuid + '/');
var nodeActions = {
getPowerTransitions: function() {
return [];
}
};
return $controller(
'horizon.dashboard.admin.ironic.NodeDetailsController', 'horizon.dashboard.admin.ironic.NodeDetailsController',
{$scope: scope, {$scope: $rootScope.$new(),
$location: $location, $location: $location,
'horizon.dashboard.admin.ironic.edit-port.service': {}, 'horizon.dashboard.admin.ironic.edit-port.service': {},
'horizon.dashboard.admin.ironic.actions': nodeActions}); 'horizon.dashboard.admin.ironic.actions': nodeActions});
}
scope.$apply();
}));
it('controller should be defined', function () { it('controller should be defined', function () {
expect(ctrl).toBeDefined(); createNode()
.then(function(node) {
var ctrl = createController(node);
expect(ctrl).toBeDefined();
});
ironicBackendMockService.flush();
}); });
it('should have a basePath', function () { it('should have a basePath', function () {
expect(ctrl.basePath).toBeDefined(); createNode()
.then(function(node) {
var ctrl = createController(node);
expect(ctrl.basePath).toBeDefined();
});
ironicBackendMockService.flush();
}); });
it('should have a node', function () { it('should have a node', function () {
expect(ctrl.node).toBeDefined(); var node, ctrl;
var node = createNode(nodeName, nodeUuid); createNode()
node.id = node.uuid; .then(function(createdNode) {
node.bootDevice = bootDevice; node = createdNode;
node.console_enabled = consoleEnabled; ctrl = createController(node);
node.console_info = consoleInfo; })
expect(ctrl.node).toEqual(node); .catch(function() {
fail();
});
ironicBackendMockService.flush();
// The controller augments the base node with additional attributes
var ctrlNode = ironicBackendMockService.getNode(node.uuid);
ctrlNode.id = node.uuid;
ironicAPI.nodeGetConsole(node.uuid)
.then(function(consoleInfo) {
ctrlNode.console_info = consoleInfo.console_info;
})
.then(function() {
ironicAPI.getBootDevice(node.uuid)
.then(function(bootDevice) {
ctrlNode.bootDevice = bootDevice;
});
})
.catch(function() {
fail();
});
ironicBackendMockService.flush();
expect(ctrl.node).toEqual(ctrlNode);
}); });
it('should have ports', function () { it('should have ports', function () {
expect(ctrl.portsSrc).toBeDefined(); var portAddress = '11:22:33:44:55:66';
expect(ctrl.portsSrc.length).toEqual(numPorts); var port, ctrl;
var ports = []; createNode()
for (var i = 0; i < numPorts; i++) { .then(function(node) {
var port = createPort(ctrl.node.uuid, i); return ironicAPI.createPort({node_uuid: node.uuid,
port.id = port.uuid; address: portAddress})
port.name = port.address; .then(function(port) {
ports.push(port); return {node: node, port: port};
} });
expect(ctrl.portsSrc).toEqual(ports); })
.then(function(data) {
port = data.port;
ctrl = createController(data.node);
})
.catch(function() {
fail();
});
ironicBackendMockService.flush();
var ctrlPort = ironicBackendMockService.getPort(port.uuid);
ctrlPort.id = ctrlPort.uuid;
ctrlPort.name = ctrlPort.address;
expect(ctrl.portsSrc.length).toEqual(1);
expect(ctrl.portsSrc[0].address).toBe(portAddress);
expect(ctrl.portsSrc[0]).toEqual(ctrlPort);
}); });
it('should have a uuid regular expression pattern', function () { it('should have a uuid regular expression pattern', function () {
var ctrl;
createNode()
.then(function(node) {
ctrl = createController(node);
})
.catch(function() {
fail();
});
ironicBackendMockService.flush();
expect(ctrl.re_uuid).toBeDefined(); expect(ctrl.re_uuid).toBeDefined();
}); });
it('should have an isUuid function', function () { it('should have an isUuid function', function () {
var ctrl;
createNode()
.then(function(node) {
ctrl = createController(node);
})
.catch(function() {
fail();
});
ironicBackendMockService.flush();
expect(ctrl.isUuid).toBeDefined(); expect(ctrl.isUuid).toBeDefined();
expect(ctrl.isUuid(ctrl.node.uuid)).toEqual(true); expect(ctrl.isUuid(ctrl.node.uuid)).toEqual(true);
expect(ctrl.isUuid("not a uuid")).toEqual(false); expect(ctrl.isUuid("not a uuid")).toEqual(false);
}); });
it('should have a getVifPortId function', function () { it('should have a getVifPortId function', function () {
var ctrl;
createNode()
.then(function(node) {
ctrl = createController(node);
});
ironicBackendMockService.flush();
expect(ctrl.getVifPortId).toBeDefined(); expect(ctrl.getVifPortId).toBeDefined();
expect(ctrl.getVifPortId(createPort(ctrl.node.uuid, 1))).toEqual("");
var extra = {vif_port_id: "port_uuid"};
expect(ctrl.getVifPortId(createPort(ctrl.node.uuid, 1, extra))).
toEqual("port_uuid");
}); });
it('should have node-state-transitions', function () { it('should have node-state-transitions', function () {
var ctrl;
createNode()
.then(function(node) {
ctrl = createController(node);
});
ironicBackendMockService.flush();
expect(ctrl.nodeStateTransitions).toBeDefined(); expect(ctrl.nodeStateTransitions).toBeDefined();
expect(ctrl.nodeStateTransitions).toEqual( expect(ctrl.nodeStateTransitions).toEqual(
nodeStateTransitionService.getTransitions(ctrl.node.provision_state)); nodeStateTransitionService.getTransitions(ctrl.node.provision_state));
}); });
it('should have node-validation', function () { it('should have node-validation', function () {
var ctrl;
createNode()
.then(function(node) {
ctrl = createController(node);
})
.catch(function() {
fail();
});
ironicBackendMockService.flush();
expect(ctrl.nodeValidation).toBeDefined(); expect(ctrl.nodeValidation).toBeDefined();
expect(ctrl.nodeValidation).toEqual([]); expect(ctrl.nodeValidation).toEqual([]);
}); });
it('should have a boot device', function () {
expect(ctrl.node.bootDevice).toBeDefined();
expect(ctrl.node.bootDevice).toEqual(bootDevice);
});
}); });
})(); })();