Merge "Optionaly require keypair on ng-launch-instance"

This commit is contained in:
Jenkins 2016-03-09 23:59:38 +00:00 committed by Gerrit Code Review
commit 68411394b3
3 changed files with 60 additions and 6 deletions

View File

@ -25,7 +25,8 @@
'horizon.dashboard.project.workflow.launch-instance.basePath',
'launchInstanceModel',
'$modal',
'horizon.framework.widgets.toast.service'
'horizon.framework.widgets.toast.service',
'horizon.app.core.openstack-service-api.settings'
];
/**
@ -34,7 +35,13 @@
* @description
* Allows selection of key pairs.
*/
function LaunchInstanceKeypairController(basePath, launchInstanceModel, $modal, toastService) {
function LaunchInstanceKeypairController(
basePath,
launchInstanceModel,
$modal,
toastService,
settingsService
) {
var ctrl = this;
ctrl.isKeypairCreated = false;
@ -46,6 +53,7 @@
ctrl.allocateNewKeyPair = allocateNewKeyPair;
ctrl.createKeyPair = createKeyPair;
ctrl.importKeyPair = importKeyPair;
ctrl.setKeypairRequired = setKeypairRequired;
ctrl.tableData = {
available: launchInstanceModel.keypairs,
@ -60,6 +68,12 @@
maxAllocation: 1
};
ctrl.isKeypairRequired = 0;
settingsService.getSetting(
'OPENSTACK_HYPERVISOR_FEATURES.requires_keypair'
).then(setKeypairRequired);
//////////
/**
@ -138,6 +152,17 @@
function getName(item) {
return item.name;
}
/**
* @ngdoc function
* @name setKeypairRequired
* @description
* Set if a KeyPair is required based on the settings
* @param {Boolean} setting The requires_keypair setting
*/
function setKeypairRequired(setting) {
ctrl.isKeypairRequired = setting ? 1 : 0;
}
}
})();

View File

@ -19,18 +19,35 @@
describe('Launch Instance Keypair Step', function() {
describe('LaunchInstanceKeypairController', function() {
var ctrl;
var ctrl, q, settings;
var $modal = { open: angular.noop };
var toastServiceMock = {add: angular.noop};
beforeEach(module('horizon.dashboard.project'));
beforeEach(function() {
settings = {
OPENSTACK_HYPERVISOR_FEATURES: {
requires_keypair: false
}
};
});
beforeEach(module(function ($provide) {
$provide.value('$modal', $modal);
$provide.value('horizon.framework.widgets.toast.service', toastServiceMock);
$provide.value('horizon.app.core.openstack-service-api.settings', {
getSetting: function(setting) {
setting = setting.split('.');
var deferred = q.defer();
deferred.resolve(settings[setting[0]][setting[1]]);
return deferred.promise;
}
});
}));
beforeEach(inject(function($controller) {
beforeEach(inject(function($controller, $q) {
q = $q;
var model = {
newInstanceSpec: {
key_pair: ['key1']
@ -157,6 +174,19 @@
expect(ctrl.tableData.allocated[0].name).toEqual("newKeypair");
});
it('defines isKeypairRequired', function() {
expect(ctrl.isKeypairRequired).toBeDefined();
expect(ctrl.isKeypairRequired).toBe(0);
});
it('sets isKeypairRequired properly', function() {
expect(ctrl.isKeypairRequired).toBeDefined();
ctrl.setKeypairRequired(true);
expect(ctrl.isKeypairRequired).toBe(1);
ctrl.setKeypairRequired(false);
expect(ctrl.isKeypairRequired).toBe(0);
});
});
});

View File

@ -31,7 +31,7 @@
limits="ctrl.tableLimits">
<!-- Key Pairs Allocated-->
<allocated>
<allocated validate-number-min="ctrl.isKeypairRequired" ng-model="ctrl.tableData.allocated.length">
<table st-table="ctrl.tableData.displayedAllocated"
st-safe-src="ctrl.tableData.allocated" hz-table
class="table table-striped table-rsp table-detail">
@ -129,6 +129,5 @@
</tbody>
</table>
</available>
</transfer-table> <!-- End Key Pairs Table -->
</div> <!-- End Controller -->