Browse Source

Catch up with horizon framework

* Use resource registry to reduce boilerplate
* Resolve resources before routing
* Better organization of the page structure

Change-Id: I9fdf0d1bc3389cac0f4cd955dcd76920b7c0f90b
Story: 1713855
Task: 5449
Story: 1713854
Task: 5219
Story: 1713853
Task: 5366
changes/49/523249/6
Jacky Hu 4 years ago
parent
commit
3594784322
  1. 65
      octavia_dashboard/api/rest/lbaasv2.py
  2. 56
      octavia_dashboard/static/app/core/openstack-service-api/lbaasv2.service.js
  3. 46
      octavia_dashboard/static/app/core/openstack-service-api/lbaasv2.service.spec.js
  4. 59
      octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/actions/create/create.action.service.js
  5. 83
      octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/actions/create/create.action.service.spec.js
  6. 3
      octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/actions/create/wizard.controller.js
  7. 71
      octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/actions/delete/delete.action.service.js
  8. 190
      octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/actions/delete/delete.action.service.spec.js
  9. 43
      octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/actions/edit/edit.action.service.js
  10. 75
      octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/actions/edit/edit.action.service.spec.js
  11. 81
      octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/actions/row-actions.service.js
  12. 51
      octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/actions/row-actions.service.spec.js
  13. 100
      octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/detail.controller.js
  14. 111
      octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/detail.controller.spec.js
  15. 48
      octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/detail.html
  16. 104
      octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/details/detail.controller.js
  17. 104
      octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/details/detail.controller.spec.js
  18. 53
      octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/details/detail.html
  19. 10
      octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/details/drawer.html
  20. 135
      octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/healthmonitors.module.js
  21. 43
      octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/healthmonitors.module.spec.js
  22. 217
      octavia_dashboard/static/dashboard/project/lbaasv2/lbaasv2.module.js
  23. 286
      octavia_dashboard/static/dashboard/project/lbaasv2/lbaasv2.module.spec.js
  24. 15
      octavia_dashboard/static/dashboard/project/lbaasv2/lbaasv2.scss
  25. 107
      octavia_dashboard/static/dashboard/project/lbaasv2/listeners/actions/batch-actions.service.js
  26. 105
      octavia_dashboard/static/dashboard/project/lbaasv2/listeners/actions/batch-actions.service.spec.js
  27. 69
      octavia_dashboard/static/dashboard/project/lbaasv2/listeners/actions/create/create.service.js
  28. 55
      octavia_dashboard/static/dashboard/project/lbaasv2/listeners/actions/create/create.service.spec.js
  29. 88
      octavia_dashboard/static/dashboard/project/lbaasv2/listeners/actions/delete/delete.action.service.js
  30. 56
      octavia_dashboard/static/dashboard/project/lbaasv2/listeners/actions/delete/delete.action.service.spec.js
  31. 69
      octavia_dashboard/static/dashboard/project/lbaasv2/listeners/actions/edit/edit.service.js
  32. 55
      octavia_dashboard/static/dashboard/project/lbaasv2/listeners/actions/edit/edit.service.spec.js
  33. 113
      octavia_dashboard/static/dashboard/project/lbaasv2/listeners/actions/row-actions.service.js
  34. 115
      octavia_dashboard/static/dashboard/project/lbaasv2/listeners/actions/row-actions.service.spec.js
  35. 92
      octavia_dashboard/static/dashboard/project/lbaasv2/listeners/detail.controller.js
  36. 104
      octavia_dashboard/static/dashboard/project/lbaasv2/listeners/detail.controller.spec.js
  37. 46
      octavia_dashboard/static/dashboard/project/lbaasv2/listeners/detail.html
  38. 101
      octavia_dashboard/static/dashboard/project/lbaasv2/listeners/details/detail.controller.js
  39. 101
      octavia_dashboard/static/dashboard/project/lbaasv2/listeners/details/detail.controller.spec.js
  40. 62
      octavia_dashboard/static/dashboard/project/lbaasv2/listeners/details/detail.html
  41. 9
      octavia_dashboard/static/dashboard/project/lbaasv2/listeners/details/drawer.html
  42. 149
      octavia_dashboard/static/dashboard/project/lbaasv2/listeners/listeners.module.js
  43. 43
      octavia_dashboard/static/dashboard/project/lbaasv2/listeners/listeners.module.spec.js
  44. 80
      octavia_dashboard/static/dashboard/project/lbaasv2/listeners/table.controller.js
  45. 97
      octavia_dashboard/static/dashboard/project/lbaasv2/listeners/table.controller.spec.js
  46. 124
      octavia_dashboard/static/dashboard/project/lbaasv2/listeners/table.html
  47. 1
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/actions/associate-ip/modal.controller.spec.js
  48. 5
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/actions/associate-ip/modal.service.js
  49. 7
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/actions/associate-ip/modal.service.spec.js
  50. 83
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/actions/batch-actions.service.spec.js
  51. 68
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/actions/create/create.service.js
  52. 56
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/actions/create/create.service.spec.js
  53. 1
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/actions/create/wizard.controller.spec.js
  54. 72
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/actions/delete/delete.action.service.js
  55. 50
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/actions/delete/delete.action.service.spec.js
  56. 10
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/actions/disassociate-ip/modal.service.js
  57. 7
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/actions/disassociate-ip/modal.service.spec.js
  58. 77
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/actions/edit/edit.service.js
  59. 63
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/actions/edit/edit.service.spec.js
  60. 1
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/actions/edit/wizard.controller.spec.js
  61. 123
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/actions/row-actions.service.js
  62. 101
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/actions/row-actions.service.spec.js
  63. 92
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/detail.controller.js
  64. 89
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/detail.controller.spec.js
  65. 61
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/detail.html
  66. 96
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/details/detail.controller.js
  67. 99
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/details/detail.controller.spec.js
  68. 66
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/details/detail.html
  69. 9
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/details/drawer.html
  70. 163
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/loadbalancers.module.js
  71. 45
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/loadbalancers.module.spec.js
  72. 165
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/loadbalancers.service.js
  73. 196
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/loadbalancers.service.spec.js
  74. 4
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/panel.html
  75. 80
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/table.controller.js
  76. 86
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/table.controller.spec.js
  77. 155
      octavia_dashboard/static/dashboard/project/lbaasv2/loadbalancers/table.html
  78. 73
      octavia_dashboard/static/dashboard/project/lbaasv2/members/actions/batch-actions.service.js
  79. 67
      octavia_dashboard/static/dashboard/project/lbaasv2/members/actions/batch-actions.service.spec.js
  80. 73
      octavia_dashboard/static/dashboard/project/lbaasv2/members/actions/delete/delete.action.service.js
  81. 187
      octavia_dashboard/static/dashboard/project/lbaasv2/members/actions/delete/delete.action.service.spec.js
  82. 43
      octavia_dashboard/static/dashboard/project/lbaasv2/members/actions/edit-member/modal.service.js
  83. 21
      octavia_dashboard/static/dashboard/project/lbaasv2/members/actions/edit-member/modal.service.spec.js
  84. 79
      octavia_dashboard/static/dashboard/project/lbaasv2/members/actions/row-actions.service.js
  85. 51
      octavia_dashboard/static/dashboard/project/lbaasv2/members/actions/row-actions.service.spec.js
  86. 48
      octavia_dashboard/static/dashboard/project/lbaasv2/members/actions/update-list/update-member-list.service.js
  87. 74
      octavia_dashboard/static/dashboard/project/lbaasv2/members/actions/update-list/update-member-list.service.spec.js
  88. 108
      octavia_dashboard/static/dashboard/project/lbaasv2/members/detail.controller.js
  89. 124
      octavia_dashboard/static/dashboard/project/lbaasv2/members/detail.controller.spec.js
  90. 48
      octavia_dashboard/static/dashboard/project/lbaasv2/members/detail.html
  91. 108
      octavia_dashboard/static/dashboard/project/lbaasv2/members/details/detail.controller.js
  92. 105
      octavia_dashboard/static/dashboard/project/lbaasv2/members/details/detail.controller.spec.js
  93. 55
      octavia_dashboard/static/dashboard/project/lbaasv2/members/details/detail.html
  94. 9
      octavia_dashboard/static/dashboard/project/lbaasv2/members/details/drawer.html
  95. 146
      octavia_dashboard/static/dashboard/project/lbaasv2/members/members.module.js
  96. 43
      octavia_dashboard/static/dashboard/project/lbaasv2/members/members.module.spec.js
  97. 87
      octavia_dashboard/static/dashboard/project/lbaasv2/members/table.controller.js
  98. 103
      octavia_dashboard/static/dashboard/project/lbaasv2/members/table.controller.spec.js
  99. 120
      octavia_dashboard/static/dashboard/project/lbaasv2/members/table.html
  100. 57
      octavia_dashboard/static/dashboard/project/lbaasv2/pools/actions/create/create.action.service.js

65
octavia_dashboard/api/rest/lbaasv2.py

@ -661,6 +661,24 @@ class Pools(generic.View):
"""
url_regex = r'lbaas/pools/$'
@rest_utils.ajax()
def get(self, request):
"""List of pools for the current project.
The listing result is an object with property "items".
"""
loadbalancer_id = request.GET.get('loadbalancerId')
listener_id = request.GET.get('listenerId')
conn = _get_sdk_connection(request)
pool_list = _sdk_object_to_list(conn.load_balancer.pools(
project_id=request.user.project_id))
if loadbalancer_id or listener_id:
pool_list = self._filter_pools(pool_list,
loadbalancer_id,
listener_id)
return {'items': pool_list}
@rest_utils.ajax()
def post(self, request):
"""Create a new pool.
@ -672,6 +690,24 @@ class Pools(generic.View):
'listener_id': request.DATA.get('parentResourceId')}
return create_pool(request, **kwargs)
def _filter_pools(self, pool_list, loadbalancer_id, listener_id):
filtered_pools = []
for pool in pool_list:
if loadbalancer_id:
if pool['loadbalancers'][0]['id'] == loadbalancer_id:
if listener_id:
if (pool['listeners'] and
pool['listeners'][0]['id'] == listener_id):
filtered_pools.append(pool)
else:
filtered_pools.append(pool)
elif (pool['listeners'] and
pool['listeners'][0]['id'] == listener_id):
filtered_pools.append(pool)
return filtered_pools
@urls.register
class Pool(generic.View):
@ -819,6 +855,26 @@ class HealthMonitors(generic.View):
"""
url_regex = r'lbaas/healthmonitors/$'
@rest_utils.ajax()
def get(self, request):
"""List of health monitors for the current project.
The listing result is an object with property "items".
"""
pool_id = request.GET.get('poolId')
conn = _get_sdk_connection(request)
health_monitor_list = _sdk_object_to_list(
conn.load_balancer.health_monitors(
project_id=request.user.project_id
)
)
if pool_id:
health_monitor_list = self._filter_health_monitors(
health_monitor_list,
pool_id)
return {'items': health_monitor_list}
@rest_utils.ajax()
def post(self, request):
"""Create a new health monitor.
@ -828,6 +884,15 @@ class HealthMonitors(generic.View):
'pool_id': request.DATA.get('parentResourceId')}
return create_health_monitor(request, **kwargs)
def _filter_health_monitors(self, health_monitor_list, pool_id):
filtered_health_monitors = []
for health_monitor in health_monitor_list:
if health_monitor['pools'][0]['id'] == pool_id:
filtered_health_monitors.append(health_monitor)
return filtered_health_monitors
@urls.register
class HealthMonitor(generic.View):

56
octavia_dashboard/static/app/core/openstack-service-api/lbaasv2.service.js

@ -46,6 +46,7 @@
createListener: createListener,
editListener: editListener,
deleteListener: deleteListener,
getPools: getPools,
getPool: getPool,
createPool: createPool,
editPool: editPool,
@ -54,6 +55,7 @@
getMember: getMember,
deleteMember: deleteMember,
editMember: editMember,
getHealthMonitors: getHealthMonitors,
getHealthMonitor: getHealthMonitor,
deleteHealthMonitor: deleteHealthMonitor,
createHealthMonitor: createHealthMonitor,
@ -242,6 +244,38 @@
// Pools
/**
* @name horizon.app.core.openstack-service-api.lbaasv2.getPools
* @description
* Get the list of pools.
* If a loadbalancer ID is passed as a parameter, the returning list of
* pools will be filtered to include only those pools under the
* specified loadbalancer.
* @param {string} loadbalancerId
* Specifies the id of the loadbalancer to request pools for.
* @param {string} listenerId
* Specifies the id of the listener to request pools for.
*
* The listing result is an object with property "items". Each item is
* a pool.
*/
function getPools(loadbalancerId, listenerId) {
var params = $.extend({},
{
loadbalancerId: loadbalancerId,
listenerId: listenerId
}
);
if (!$.isEmptyObject(params)) {
params = { params: params };
}
return apiService.get('/api/lbaas/pools/', params)
.error(function () {
toastService.add('error', gettext('Unable to retrieve pools.'));
});
}
/**
* @name horizon.app.core.openstack-service-api.lbaasv2.getPool
* @description
@ -408,6 +442,28 @@
* Specifies the id of the health monitor.
*/
/**
* @name horizon.app.core.openstack-service-api.lbaasv2.getHealthMonitors
* @description
* Get the list of healthmonitors.
* If a pool ID is passed as a parameter, the returning list of
* healthmonitors will be filtered to include only those healthmonitors under the
* specified pool.
* @param {string} id
* Specifies the id of the pool to request healthmonitors for.
*
* The listing result is an object with property "items". Each item is
* a healthmonitor.
*/
function getHealthMonitors(id) {
var params = id ? {params: {poolId: id}} : {};
return apiService.get('/api/lbaas/healthmonitors/', params)
.error(function () {
toastService.add('error', gettext('Unable to retrieve health monitors.'));
});
}
function getHealthMonitor(monitorId) {
return apiService.get('/api/lbaas/healthmonitors/' + monitorId + '/')
.error(function () {

46
octavia_dashboard/static/app/core/openstack-service-api/lbaasv2.service.spec.js

@ -90,6 +90,37 @@
error: 'Unable to retrieve listener.',
testInput: [ '1234', false ]
},
{
func: 'getPools',
method: 'get',
path: '/api/lbaas/pools/',
error: 'Unable to retrieve pools.',
testInput: [ '1234' ],
data: { params: { loadbalancerId: '1234' } }
},
{
func: 'getPools',
method: 'get',
path: '/api/lbaas/pools/',
error: 'Unable to retrieve pools.',
testInput: [ '1234', '5678' ],
data: { params: { loadbalancerId: '1234', listenerId: '5678' } }
},
{
func: 'getPools',
method: 'get',
path: '/api/lbaas/pools/',
error: 'Unable to retrieve pools.',
testInput: [ undefined, '5678' ],
data: { params: { listenerId: '5678' } }
},
{
func: 'getPools',
method: 'get',
path: '/api/lbaas/pools/',
data: {},
error: 'Unable to retrieve pools.'
},
{
func: 'getPool',
method: 'get',
@ -142,6 +173,21 @@
data: { weight: 2 },
testInput: [ '1234', '5678', { weight: 2 } ]
},
{
func: 'getHealthMonitors',
method: 'get',
path: '/api/lbaas/healthmonitors/',
error: 'Unable to retrieve health monitors.',
testInput: [ '1234' ],
data: { params: { poolId: '1234' } }
},
{
func: 'getHealthMonitors',
method: 'get',
path: '/api/lbaas/healthmonitors/',
data: {},
error: 'Unable to retrieve health monitors.'
},
{
func: 'getHealthMonitor',
method: 'get',

59
octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/actions/create/create.action.service.js

@ -1,5 +1,6 @@
/*
* Copyright 2016 IBM Corp.
* Copyright 2017 Walmart.
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
@ -21,68 +22,46 @@
.factory('horizon.dashboard.project.lbaasv2.healthmonitors.actions.create', createService);
createService.$inject = [
'$q',
'$location',
'horizon.dashboard.project.lbaasv2.healthmonitors.resourceType',
'horizon.framework.util.actions.action-result.service',
'horizon.dashboard.project.lbaasv2.workflow.modal',
'horizon.app.core.openstack-service-api.policy',
'horizon.framework.util.i18n.gettext',
'horizon.framework.util.q.extensions'
'horizon.framework.util.i18n.gettext'
];
/**
* @ngDoc factory
* @name horizon.dashboard.project.lbaasv2.healthmonitors.actions.createService
*
* @description
* Provides the service for creating a health monitor resource.
* @param $q The angular service for promises.
* @param $location The angular $location service.
*
* @param resourceType The health monitor resource type.
* @param actionResultService The horizon action result service.
* @param workflowModal The LBaaS workflow modal service.
* @param policy The horizon policy service.
* @param gettext The horizon gettext function for translation.
* @param qExtensions Horizon extensions to the $q service.
*
* @returns The health monitor create service.
*/
function createService($q, $location, workflowModal, policy, gettext, qExtensions) {
var loadbalancerId, listenerId, poolId, statePromise;
var create = workflowModal.init({
function createService(resourceType, actionResultService, workflowModal, policy, gettext) {
return workflowModal.init({
controller: 'CreateHealthMonitorWizardController',
message: gettext('A new health monitor is being created.'),
handle: onCreate,
handle: handle,
allowed: allowed
});
var service = {
init: init,
create: create
};
return service;
//////////////
function init(_loadbalancerId_, _listenerId_, _statePromise_) {
loadbalancerId = _loadbalancerId_;
listenerId = _listenerId_;
statePromise = _statePromise_;
return service;
function allowed() {
return policy.ifAllowed({ rules: [['neutron', 'create_health_monitor']] });
}
function allowed(pool) {
poolId = pool.id;
return $q.all([
statePromise,
qExtensions.booleanAsPromise(!pool.health_monitor_id),
policy.ifAllowed({ rules: [['neutron', 'create_health_monitor']] })
]);
function handle(response) {
var newHealthMonitor = response.data;
return actionResultService.getActionResult()
.created(resourceType, newHealthMonitor.id)
.result;
}
function onCreate(response) {
var healthMonitorId = response.data.id;
$location.path('project/load_balancer/' + loadbalancerId + '/listeners/' +
listenerId + '/pools/' + poolId + '/healthmonitors/' + healthMonitorId);
}
}
})();

83
octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/actions/create/create.action.service.spec.js

@ -1,5 +1,6 @@
/*
* Copyright 2016 IBM Corp.
* Copyright 2017 Walmart.
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
@ -17,89 +18,25 @@
'use strict';
describe('LBaaS v2 Create Health Monitor Action Service', function() {
var scope, $q, $location, policy, init, service, loadBalancerState;
var policy, service;
function allowed(item) {
spyOn(policy, 'ifAllowed').and.returnValue(true);
var promise = service.create.allowed(item);
var allowed;
promise.then(function() {
allowed = true;
}, function() {
allowed = false;
});
scope.$apply();
expect(policy.ifAllowed).toHaveBeenCalledWith(
{rules: [['neutron', 'create_health_monitor']]});
return allowed;
}
beforeEach(module('horizon.framework.util'));
beforeEach(module('horizon.framework.conf'));
beforeEach(module('horizon.framework.widgets'));
beforeEach(module('horizon.app.core.openstack-service-api'));
beforeEach(module('horizon.dashboard.project.lbaasv2'));
beforeEach(module(function($provide) {
$provide.value('$uibModal', {
open: function() {
return {
result: {
then: function(func) {
func({ data: { id: 'healthmonitor1' } });
}
}
};
}
});
}));
beforeEach(inject(function ($injector) {
scope = $injector.get('$rootScope').$new();
$q = $injector.get('$q');
policy = $injector.get('horizon.app.core.openstack-service-api.policy');
$location = $injector.get('$location');
service = $injector.get('horizon.dashboard.project.lbaasv2.healthmonitors.actions.create');
init = service.init;
loadBalancerState = $q.defer();
}));
it('should define the correct service properties', function() {
expect(service.init).toBeDefined();
expect(service.create).toBeDefined();
});
it('should have the "allowed" and "perform" functions', function() {
expect(service.create.allowed).toBeDefined();
expect(service.create.perform).toBeDefined();
});
it('should allow creating a health monitor under an ACTIVE load balancer', function() {
loadBalancerState.resolve();
init('active', '1', loadBalancerState.promise);
expect(allowed({})).toBe(true);
});
it('should not allow creating a health monitor under a NON-ACTIVE load balancer', function() {
loadBalancerState.reject();
init('non-active', '1', loadBalancerState.promise);
expect(allowed({})).toBe(false);
});
it('should not allow creating a health monitor if one already exists', function() {
loadBalancerState.resolve();
init('active', '1', loadBalancerState.promise);
expect(allowed({ health_monitor_id: '1234' })).toBe(false);
it('should check policy to allow creating a health monitor', function() {
spyOn(policy, 'ifAllowed').and.returnValue(true);
expect(service.allowed()).toBe(true);
expect(policy.ifAllowed)
.toHaveBeenCalledWith({rules: [['neutron', 'create_health_monitor']]});
});
it('should redirect after create', function() {
loadBalancerState.resolve();
spyOn($location, 'path').and.callThrough();
init('loadbalancer1', 'listener1', loadBalancerState.promise).create.allowed({id: 'pool1'});
service.create.perform();
expect($location.path).toHaveBeenCalledWith(
'project/load_balancer/loadbalancer1/listeners/listener1/pools/pool1/' +
'healthmonitors/healthmonitor1');
it('should handle the action result properly', function() {
var result = service.handle({data: {id: 1}});
expect(result.created[0].id).toBe(1);
});
});

3
octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/actions/create/wizard.controller.js

@ -32,6 +32,7 @@
$scope, $routeParams, model, workflowService, gettext
) {
var loadbalancerId = $routeParams.loadbalancerId;
var poolId = $routeParams.poolId;
var scope = $scope;
scope.model = model;
scope.submit = scope.model.submit;
@ -40,7 +41,7 @@
'fa fa-cloud-download',
['monitor']
);
scope.model.initialize('monitor', false, loadbalancerId, scope.launchContext.id);
scope.model.initialize('monitor', false, loadbalancerId, poolId);
}
})();

71
octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/actions/delete/delete.action.service.js

@ -1,5 +1,6 @@
/*
* Copyright 2016 IBM Corp.
* Copyright 2017 Walmart.
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
@ -21,9 +22,9 @@
.factory('horizon.dashboard.project.lbaasv2.healthmonitors.actions.delete', deleteService);
deleteService.$inject = [
'$q',
'horizon.dashboard.project.lbaasv2.healthmonitors.resourceType',
'horizon.framework.util.actions.action-result.service',
'$location',
'$route',
'horizon.framework.widgets.modal.deleteModalService',
'horizon.app.core.openstack-service-api.lbaasv2',
'horizon.app.core.openstack-service-api.policy',
@ -33,24 +34,27 @@
/**
* @ngDoc factory
* @name horizon.dashboard.project.lbaasv2.healthmonitors.actions.deleteService
*
* @description
* Brings up the delete health monitor confirmation modal dialog.
* On submit, deletes selected health monitor.
* On cancel, does nothing.
* @param $q The angular service for promises.
*
* @param resourceType The health monitor resource type.
* @param actionResultService The horizon action result service.
* @param $location The angular $location service.
* @param $route The angular $route service.
* @param deleteModal The horizon delete modal service.
* @param api The LBaaS v2 API service.
* @param policy The horizon policy service.
* @param gettext The horizon gettext function for translation.
*
* @returns The health monitor delete service.
*/
function deleteService(
$q, $location, $route, deleteModal, api, policy, gettext
resourceType, actionResultService, $location, deleteModal, api, policy, gettext
) {
var loadbalancerId, listenerId, poolId, statePromise;
var loadbalancerId, listenerId, poolId;
var context = {
labels: {
title: gettext('Confirm Delete Health Monitor'),
@ -68,50 +72,51 @@
var service = {
perform: perform,
allowed: allowed,
init: init
deleteResult: deleteResult // exposed just for testing
};
return service;
//////////////
function init(_loadbalancerId_, _listenerId_, _poolId_, _statePromise_) {
loadbalancerId = _loadbalancerId_;
listenerId = _listenerId_;
poolId = _poolId_;
statePromise = _statePromise_;
return service;
}
function perform(item) {
deleteModal.open({ $emit: actionComplete }, [item], context);
}
function allowed(/*item*/) {
return $q.all([
statePromise,
// This rule is made up and should therefore always pass. I assume at some point there
// will be a valid rule similar to this that we will want to use.
policy.ifAllowed({ rules: [['neutron', 'delete_health_monitor']] })
]);
// This rule is made up and should therefore always pass. I assume at some point there
// will be a valid rule similar to this that we will want to use.
return policy.ifAllowed({ rules: [['neutron', 'delete_health_monitor']] });
}
function deleteItem(id) {
return api.deleteHealthMonitor(id, true);
function perform(items, scope) {
var healthMonitors = angular.isArray(items) ? items : [items];
healthMonitors.map(function(item) {
loadbalancerId = item.loadbalancerId;
listenerId = item.listenerId;
poolId = item.poolId;
});
return deleteModal.open(scope, healthMonitors, context).then(deleteResult);
}
function actionComplete(eventType) {
if (eventType === context.failedEvent) {
// Error, reload page
$route.reload();
} else {
// Success, go back to pool details page
function deleteResult(deleteModalResult) {
// To make the result of this action generically useful, reformat the return
// from the deleteModal into a standard form
var actionResult = actionResultService.getActionResult();
deleteModalResult.pass.forEach(function markDeleted(item) {
actionResult.deleted(resourceType, item.context.id);
});
deleteModalResult.fail.forEach(function markFailed(item) {
actionResult.failed(resourceType, item.context.id);
});
if (actionResult.result.failed.length === 0 && actionResult.result.deleted.length > 0) {
var path = 'project/load_balancer/' + loadbalancerId +
'/listeners/' + listenerId +
'/pools/' + poolId;
$location.path(path);
}
return actionResult.result;
}
function deleteItem(id) {
return api.deleteHealthMonitor(id, true);
}
}
})();

190
octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/actions/delete/delete.action.service.spec.js

@ -1,5 +1,6 @@
/*
* Copyright 2016 IBM Corp.
* Copyright 2017 Walmart.
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
@ -17,140 +18,87 @@
'use strict';
describe('LBaaS v2 Health Monitor Delete Service', function() {
var service, policy, modal, lbaasv2Api, $scope, $location, $q, toast, monitor;
function allowed(item) {
spyOn(policy, 'ifAllowed').and.returnValue(makePromise());
var promise = service.allowed(item);
var allowed;
promise.then(function() {
allowed = true;
}, function() {
allowed = false;
});
$scope.$apply();
expect(policy.ifAllowed)
.toHaveBeenCalledWith({rules: [['neutron', 'delete_health_monitor']]});
return allowed;
}
function makePromise(reject) {
var def = $q.defer();
def[reject ? 'reject' : 'resolve']();
return def.promise;
}
function isActionable(id) {
if (id === 'active') {
return $q.when();
} else {
return $q.reject();
}
}
beforeEach(module('horizon.framework.util'));
beforeEach(module('horizon.framework.conf'));
beforeEach(module('horizon.framework.widgets'));
beforeEach(module('horizon.app.core.openstack-service-api'));
beforeEach(module('horizon.app.core'));
beforeEach(module('horizon.dashboard.project.lbaasv2'));
beforeEach(module('horizon.framework'));
beforeEach(function() {
monitor = { id: '1', name: 'HealthMonitor1' };
});
beforeEach(module(function($provide) {
$provide.value('$uibModal', {
open: function() {
return {
result: makePromise()
};
}
});
$provide.value('horizon.app.core.openstack-service-api.lbaasv2', {
deleteHealthMonitor: function() {
return makePromise();
}
});
$provide.value('$location', {
path: function() {
return '';
}
});
}));
var deleteModalService, service, lbaasv2API, policyAPI, $location;
beforeEach(inject(function ($injector) {
policy = $injector.get('horizon.app.core.openstack-service-api.policy');
lbaasv2Api = $injector.get('horizon.app.core.openstack-service-api.lbaasv2');
modal = $injector.get('horizon.framework.widgets.modal.deleteModalService');
$scope = $injector.get('$rootScope').$new();
$location = $injector.get('$location');
$q = $injector.get('$q');
toast = $injector.get('horizon.framework.widgets.toast.service');
beforeEach(inject(function($injector) {
service = $injector.get('horizon.dashboard.project.lbaasv2.healthmonitors.actions.delete');
service.init('1', '2', '3', isActionable('active'));
$scope.$apply();
lbaasv2API = $injector.get('horizon.app.core.openstack-service-api.lbaasv2');
deleteModalService = $injector.get('horizon.framework.widgets.modal.deleteModalService');
policyAPI = $injector.get('horizon.app.core.openstack-service-api.policy');
$location = $injector.get('$location');
}));
it('should have the "allowed" and "perform" functions', function() {
expect(service.allowed).toBeDefined();
expect(service.perform).toBeDefined();
});
it('should allow deleting health monitor from load balancer in ACTIVE state', function() {
expect(allowed()).toBe(true);
});
it('should not allow deleting health monitor from load balancer in PENDING state', function() {
service.init('1', '2', '3', isActionable('pending'));
expect(allowed()).toBe(false);
});
describe('perform method', function() {
beforeEach(function () {
// just need for this to return something that looks like a promise but does nothing
spyOn(deleteModalService, 'open').and.returnValue({then: angular.noop});
});
it('should open the delete modal', function() {
spyOn(modal, 'open');
service.perform(monitor);
$scope.$apply();
expect(modal.open.calls.count()).toBe(1);
var args = modal.open.calls.argsFor(0);
expect(args.length).toBe(3);
expect(args[0]).toEqual({ $emit: jasmine.any(Function) });
expect(args[1]).toEqual([monitor]);
expect(args[2]).toEqual(jasmine.objectContaining({
labels: jasmine.any(Object),
deleteEntity: jasmine.any(Function)
}));
expect(args[2].labels.title).toBe('Confirm Delete Health Monitor');
});
it('should open the modal with correct label', function () {
service.perform({name: 'spam'});
var labels = deleteModalService.open.calls.argsFor(0)[2].labels;
expect(deleteModalService.open).toHaveBeenCalled();
angular.forEach(labels, function eachLabel(label) {
expect(label.toLowerCase()).toContain('health monitor');
});
});
it('should pass function to modal that deletes the health monitor', function() {
spyOn(modal, 'open').and.callThrough();
spyOn(lbaasv2Api, 'deleteHealthMonitor').and.callThrough();
service.perform(monitor);
$scope.$apply();
expect(lbaasv2Api.deleteHealthMonitor.calls.count()).toBe(1);
expect(lbaasv2Api.deleteHealthMonitor).toHaveBeenCalledWith('1', true);
});
it('should open the delete modal with correct entities', function () {
service.perform([{name: 'one'}, {name: 'two'}]);
var entities = deleteModalService.open.calls.argsFor(0)[1];
expect(deleteModalService.open).toHaveBeenCalled();
expect(entities.length).toEqual(2);
});
it('should show message if any items fail to be deleted', function() {
spyOn(modal, 'open').and.callThrough();
spyOn(lbaasv2Api, 'deleteHealthMonitor').and.returnValue(makePromise(true));
spyOn(toast, 'add');
service.perform(monitor);
$scope.$apply();
expect(modal.open).toHaveBeenCalled();
expect(lbaasv2Api.deleteHealthMonitor.calls.count()).toBe(1);
expect(toast.add).toHaveBeenCalledWith('error', 'The following health monitor could not ' +
'be deleted: HealthMonitor1.');
it('should pass in a function that deletes a health monitor', function () {
spyOn(lbaasv2API, 'deleteHealthMonitor').and.callFake(angular.noop);
service.perform({id: 1, name: 'one'});
var contextArg = deleteModalService.open.calls.argsFor(0)[2];
var deleteFunction = contextArg.deleteEntity;
deleteFunction(1);
expect(lbaasv2API.deleteHealthMonitor).toHaveBeenCalledWith(1, true);
});
});
it('should return to pool details after delete', function() {
var path = 'project/load_balancer/1/listeners/2/pools/3';
it('should handle the action result properly', function() {
spyOn($location, 'path');
spyOn(toast, 'add');
service.perform(monitor);
$scope.$apply();
spyOn(deleteModalService, 'open').and.returnValue({then: angular.noop});
spyOn(lbaasv2API, 'deleteHealthMonitor').and.callFake(angular.noop);
service.perform({loadbalancerId: 1, listenerId: 2, poolId: 3, id: 1, name: 'one'});
var result = service.deleteResult({
fail: [],
pass: [{
context: {
id: 1
}
}]
});
var path = 'project/load_balancer/1/listeners/2/pools/3';
expect($location.path).toHaveBeenCalledWith(path);
expect(toast.add).toHaveBeenCalledWith('success', 'Deleted health monitor: HealthMonitor1.');
expect(result.deleted[0].id).toBe(1);
result = service.deleteResult({
pass: [],
fail: [{
context: {
id: 1
}
}]
});
expect(result.failed[0].id).toBe(1);
});
});
describe('allow method', function() {
it('should use default policy if batch action', function () {
spyOn(policyAPI, 'ifAllowed');
service.allowed();
expect(policyAPI.ifAllowed).toHaveBeenCalled();
});
}); // end of allowed
}); // end of delete
})();

43
octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/actions/edit/edit.action.service.js

@ -1,5 +1,6 @@
/*
* Copyright 2016 IBM Corp.
* Copyright 2017 Walmart.
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
@ -21,8 +22,8 @@
.factory('horizon.dashboard.project.lbaasv2.healthmonitors.actions.edit', editService);
editService.$inject = [
'$q',
'$route',
'horizon.dashboard.project.lbaasv2.healthmonitors.resourceType',
'horizon.framework.util.actions.action-result.service',
'horizon.dashboard.project.lbaasv2.workflow.modal',
'horizon.app.core.openstack-service-api.policy',
'horizon.framework.util.i18n.gettext'
@ -31,50 +32,36 @@
/**
* @ngDoc factory
* @name horizon.dashboard.project.lbaasv2.healthmonitors.actions.editService
*
* @description
* Provides the service for editing a health monitor resource.
* @param $q The angular service for promises.
* @param $route The angular $route service.
*
* @param resourceType The health monitor resource type.
* @param actionResultService The horizon action result service.
* @param workflowModal The LBaaS workflow modal service.
* @param policy The horizon policy service.
* @param gettext The horizon gettext function for translation.
*
* @returns The health monitor edit service.
*/
function editService($q, $route, workflowModal, policy, gettext) {
var statePromise;
function editService(resourceType, actionResultService, workflowModal, policy, gettext) {
var edit = workflowModal.init({
return workflowModal.init({
controller: 'EditHealthMonitorWizardController',
message: gettext('The health monitor has been updated.'),
handle: handle,
allowed: allowed
});
var service = {
init: init,
edit: edit
};
return service;
//////////////
function init(_statePromise_) {
statePromise = _statePromise_;
return service;
}
function allowed(/*healthmonitor*/) {
return $q.all([
statePromise,
policy.ifAllowed({ rules: [['neutron', 'update_health_monitor']] })
]);
return policy.ifAllowed({ rules: [['neutron', 'update_health_monitor']] });
}
function handle(/*response*/) {
$route.reload();
function handle(response) {
return actionResultService.getActionResult()
.updated(resourceType, response.config.data.monitor.id)
.result;
}
}
})();

75
octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/actions/edit/edit.action.service.spec.js

@ -1,5 +1,6 @@
/*
* Copyright 2016 IBM Corp.
* Copyright 2017 Walmart.
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
@ -17,81 +18,25 @@
'use strict';
describe('LBaaS v2 Edit Health Monitor Action Service', function() {
var scope, $q, $route, policy, init, service, loadBalancerState;
var policy, service;
function allowed(item) {
spyOn(policy, 'ifAllowed').and.returnValue(true);
var promise = service.edit.allowed(item);
var allowed;
promise.then(function() {
allowed = true;
}, function() {
allowed = false;
});
scope.$apply();
expect(policy.ifAllowed).toHaveBeenCalledWith(
{rules: [['neutron', 'update_health_monitor']]});
return allowed;
}
beforeEach(module('horizon.framework.util'));
beforeEach(module('horizon.framework.conf'));
beforeEach(module('horizon.framework.widgets'));
beforeEach(module('horizon.app.core.openstack-service-api'));
beforeEach(module('horizon.dashboard.project.lbaasv2'));
beforeEach(module(function($provide) {
$provide.value('$uibModal', {
open: function() {
return {
result: {
then: function(func) {
func({ data: { id: 'healthmonitor1' } });
}
}
};
}
});
}));
beforeEach(inject(function ($injector) {
scope = $injector.get('$rootScope').$new();
$q = $injector.get('$q');
policy = $injector.get('horizon.app.core.openstack-service-api.policy');
$route = $injector.get('$route');
service = $injector.get('horizon.dashboard.project.lbaasv2.healthmonitors.actions.edit');
init = service.init;
loadBalancerState = $q.defer();
}));
it('should define the correct service properties', function() {
expect(service.init).toBeDefined();
expect(service.edit).toBeDefined();
});
it('should have the "allowed" and "perform" functions', function() {
expect(service.edit.allowed).toBeDefined();
expect(service.edit.perform).toBeDefined();
});
it('should allow edit a health monitor under an ACTIVE load balancer', function() {
loadBalancerState.resolve();
init(loadBalancerState.promise);
expect(allowed({})).toBe(true);
});
it('should not allow editing a health monitor under a NON-ACTIVE load balancer', function() {
loadBalancerState.reject();
init(loadBalancerState.promise);
expect(allowed({})).toBe(false);
it('should check policy to allow editing a health monitor', function() {
spyOn(policy, 'ifAllowed').and.returnValue(true);
expect(service.allowed()).toBe(true);
expect(policy.ifAllowed)
.toHaveBeenCalledWith({rules: [['neutron', 'update_health_monitor']]});
});
it('should reload page after edit', function() {
loadBalancerState.resolve();
spyOn($route, 'reload');
init(loadBalancerState.promise).edit.allowed({});
service.edit.perform();
expect($route.reload).toHaveBeenCalled();
it('should handle the action result properly', function() {
var result = service.handle({config: {data: {monitor: {id: 1}}}});
expect(result.updated[0].id).toBe(1);
});
});

81
octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/actions/row-actions.service.js

@ -1,81 +0,0 @@
/*
* Copyright 2016 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function() {
'use strict';
angular
.module('horizon.dashboard.project.lbaasv2.healthmonitors')
.factory('horizon.dashboard.project.lbaasv2.healthmonitors.actions.rowActions',
rowActions);
rowActions.$inject = [
'horizon.framework.util.i18n.gettext',
'horizon.dashboard.project.lbaasv2.loadbalancers.service',
'horizon.dashboard.project.lbaasv2.healthmonitors.actions.edit',
'horizon.dashboard.project.lbaasv2.healthmonitors.actions.delete'
];
/**
* @ngdoc service
* @ngname horizon.dashboard.project.lbaasv2.healthmonitors.actions.rowActions
*
* @description
* Provides the service for the health monitor row actions.
*
* @param gettext The horizon gettext function for translation.
* @param loadBalancersService The LBaaS v2 load balancers service.
* @param editService The LBaaS v2 health monitor edit service.
* @param deleteService The LBaaS v2 health monitor delete service.
* @returns Health monitor row actions service object.
*/
function rowActions(gettext, loadBalancersService, editService, deleteService) {
var loadBalancerIsActionable, loadbalancerId, listenerId, poolId;
var service = {
actions: actions,
init: init
};
return service;
///////////////
function init(_loadbalancerId_, _listenerId_, _poolId_) {
loadbalancerId = _loadbalancerId_;
listenerId = _listenerId_;
poolId = _poolId_;
loadBalancerIsActionable = loadBalancersService.isActionable(loadbalancerId);
return service;
}
function actions() {
return [{
service: editService.init(loadBalancerIsActionable).edit,
template: {
text: gettext('Edit')
}
},{
service: deleteService.init(loadbalancerId, listenerId, poolId, loadBalancerIsActionable),
template: {
text: gettext('Delete Health Monitor'),
type: 'delete'
}
}];
}
}
})();

51
octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/actions/row-actions.service.spec.js

@ -1,51 +0,0 @@
/*
* Copyright 2016 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function() {
'use strict';
describe('LBaaS v2 Health Monitor Row Actions Service', function() {
var actions;
beforeEach(module('horizon.framework.util'));
beforeEach(module('horizon.framework.conf'));
beforeEach(module('horizon.framework.widgets'));
beforeEach(module('horizon.app.core.openstack-service-api'));
beforeEach(module('horizon.dashboard.project.lbaasv2'));
beforeEach(inject(function ($injector) {
var rowActionsService = $injector.get(
'horizon.dashboard.project.lbaasv2.healthmonitors.actions.rowActions');
actions = rowActionsService.init('1', '2', '3').actions();
var loadbalancerService = $injector.get(
'horizon.dashboard.project.lbaasv2.loadbalancers.service');
spyOn(loadbalancerService, 'isActionable').and.returnValue(true);
}));
it('should define correct table row actions', function() {
expect(actions.length).toBe(2);
expect(actions[0].template.text).toBe('Edit');
expect(actions[1].template.text).toBe('Delete Health Monitor');
});
it('should have the "allowed" and "perform" functions', function() {
actions.forEach(function(action) {
expect(action.service.allowed).toBeDefined();
expect(action.service.perform).toBeDefined();
});
});
});
})();

100
octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/detail.controller.js

@ -1,100 +0,0 @@
/*
* Copyright 2016 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function() {
'use strict';
angular
.module('horizon.dashboard.project.lbaasv2.healthmonitors')
.controller('HealthMonitorDetailController', HealthMonitorDetailController);
HealthMonitorDetailController.$inject = [
'horizon.app.core.openstack-service-api.lbaasv2',
'horizon.dashboard.project.lbaasv2.healthmonitors.actions.rowActions',
'$routeParams',
'$q'
];
/**
* @ngdoc controller
* @name HealthMonitorDetailController
*
* @description
* Controller for the LBaaS v2 health monitor detail page.
*
* @param api The LBaaS v2 API service.
* @param rowActions The LBaaS v2 health monitor row actions service.
* @param $routeParams The angular $routeParams service.
* @param $q The angular service for promises.
* @returns undefined
*/
function HealthMonitorDetailController(api, rowActions, $routeParams, $q) {
var ctrl = this;
ctrl.loading = true;
ctrl.error = false;
ctrl.actions = rowActions.init($routeParams.loadbalancerId,
$routeParams.listenerId,
$routeParams.poolId).actions;
init();
////////////////////////////////
function init() {
ctrl.healthmonitor = null;
ctrl.pool = null;
ctrl.listener = null;
ctrl.loadbalancer = null;
ctrl.loading = true;
ctrl.error = false;
$q.all([
api.getHealthMonitor($routeParams.healthmonitorId)
.then(success('healthmonitor'), fail('healthmonitor')),
api.getPool($routeParams.poolId)
.then(success('pool'), fail('pool')),
api.getListener($routeParams.listenerId)
.then(success('listener'), fail('listener')),
api.getLoadBalancer($routeParams.loadbalancerId)
.then(success('loadbalancer'), fail('loadbalancer'))
]).then(postInit, initError);
}
function success(property) {
return angular.bind(null, function setProp(property, response) {
ctrl[property] = response.data;
}, property);
}
function fail(property) {
return angular.bind(null, function setProp(property, error) {
ctrl[property] = null;
throw error;
}, property);
}
function postInit() {
ctrl.loading = false;
}
function initError() {
ctrl.loading = false;
ctrl.error = true;
}
}
})();

111
octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/detail.controller.spec.js

@ -1,111 +0,0 @@
/*
* Copyright 2016 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
(function() {
'use strict';
describe('LBaaS v2 Healthmonitor Detail Controller', function() {
var lbaasv2API, $controller, apiFail, qAllFail;
function fakePromise(data, reject) {
return {
then: function(success, fail) {
if (reject) {
fail();
} else {
success({ data: data });
}
return fakePromise();
}
};
}
function fakeAPI() {
return fakePromise('foo', apiFail);
}
function loadbalancerAPI() {
return fakePromise({ provisioning_status: 'ACTIVE' });
}
function qAll() {
return fakePromise(null, qAllFail);
}
function createController() {
return $controller('HealthMonitorDetailController', {
$routeParams: {
loadbalancerId: 'loadbalancerId',
listenerId: 'listenerId',
poolId: 'poolId',
healthmonitorId: 'healthmonitorId'
}
});
}
///////////////////////
beforeEach(module('horizon.framework.util'));
beforeEach(module('horizon.framework.widgets'));
beforeEach(module('horizon.framework.conf'));
beforeEach(module('horizon.app.core.openstack-service-api'));
beforeEach(module('horizon.dashboard.project.lbaasv2'));
beforeEach(module(function($provide) {
apiFail = false;
qAllFail = false;
$provide.value('$q', { all: qAll });
}));
beforeEach(inject(function($injector) {
lbaasv2API = $injector.get('horizon.app.core.openstack-service-api.lbaasv2');
spyOn(lbaasv2API, 'getHealthMonitor').and.callFake(fakeAPI);
spyOn(lbaasv2API, 'getPool').and.callFake(fakeAPI);
spyOn(lbaasv2API, 'getListener').and.callFake(fakeAPI);
spyOn(lbaasv2API, 'getLoadBalancer').and.callFake(loadbalancerAPI);
$controller = $injector.get('$controller');
}));
it('should invoke lbaasv2 apis', function() {
var ctrl = createController();
expect(lbaasv2API.getHealthMonitor).toHaveBeenCalledWith('healthmonitorId');
expect(lbaasv2API.getPool).toHaveBeenCalledWith('poolId');
expect(lbaasv2API.getListener).toHaveBeenCalledWith('listenerId');
expect(lbaasv2API.getLoadBalancer).toHaveBeenCalledWith('loadbalancerId');
expect(ctrl.loadbalancer).toEqual({ provisioning_status: 'ACTIVE' });
expect(ctrl.listener).toBe('foo');
expect(ctrl.pool).toBe('foo');
expect(ctrl.healthmonitor).toBe('foo');
});
it('should throw error on API fail', function() {
apiFail = true;
var init = function() {
createController();
};
expect(init).toThrow();
});
it('should set error state if any APIs fail', function() {
qAllFail = true;
var ctrl = createController();
expect(ctrl.loading).toBe(false);
expect(ctrl.error).toBe(true);
});
});
})();

48
octavia_dashboard/static/dashboard/project/lbaasv2/healthmonitors/detail.html

@ -1,48 +0,0 @@
<div ng-controller="HealthMonitorDetailController as ctrl">
<detail-status loading="ctrl.loading" error="ctrl.error"></detail-status>
<div ng-if="!ctrl.loading && !ctrl.error">
<div class="page-header">
<actions allowed="ctrl.actions" type="row" item="ctrl.healthmonitor"
ng-if="ctrl.healthmonitor" class="actions_column pull-right"></actions>
<ol class="breadcrumb">
<li><a href="project/load_balancer/"><translate>Load Balancers</translate></a></li>
<li><a href="project/load_balancer/{$ ::ctrl.loadbalancer.id $}">{$ ::(ctrl.loadbalancer.name || ctrl.loadbalancer.id) $}</a></li>
<li><a href="project/load_balancer/{$ ::ctrl.loadbalancer.id $}/listeners/{$ ::ctrl.listener.id $}">{$ ::(ctrl.listener.name || ctrl.listener.id) $}</a></li>
<li><a href="project/load_balancer/{$ ::ctrl.loadbalancer.id $}/listeners/{$ ::ctrl.listener.id $}/pools/{$ ::ctrl.pool.id $}">{$ ::(ctrl.pool.name || ctrl.pool.id) $}</a></li>
<li class="active">{$ ::(ctrl.healthmonitor.name || ctrl.healthmonitor.id) $}</li>
</ol>
</div>
<div class="row">
<div class="col-md-6 detail">
<dl class="dl-horizontal">
<dt translate>Type</dt>
<dd>{$ ::ctrl.healthmonitor.type $}</dd>
<dt translate>Delay</dt>
<dd>{$ ::ctrl.healthmonitor.delay $}</dd>
<dt translate>Max Retries</dt>
<dd>{$ ::ctrl.healthmonitor.max_retries $}</dd>
<dt translate>Max Retries Down</dt>
<dd>{$ ::ctrl.healthmonitor.max_retries_down $}</dd>
<dt translate>Timeout</dt>
<dd>{$ ::ctrl.healthmonitor.timeout $}</dd>
<dt translate ng-if="::ctrl.healthmonitor.http_method">HTTP Method</dt>
<dd ng-if="::ctrl.healthmonitor.http_method">{$ ::ctrl.healthmonitor.http_method $}</dd>
<dt translate ng-if="::ctrl.healthmonitor.expected_codes">Expected Codes</dt>
<dd ng-if="::ctrl.healthmonitor.expected_codes">{$ ::ctrl.healthmonitor.expected_codes $}</dd>
<dt translate ng-if="::ctrl.healthmonitor.url_path">URL Path</dt>
<dd ng-if="::ctrl.healthmonitor.url_path">{$ ::ctrl.healthmonitor.url_path $}</dd>
<dt translate>Admin State Up</dt>
<dd>{$ ctrl.healthmonitor.admin_state_up | yesno $}</dd>
<dt translate>Monitor ID</dt>
<dd>{$ ::ctrl.healthmonitor.id $}</dd>
<dt translate>Project ID</dt>
<dd>{$ ::ctrl.healthmonitor.project_id $}</dd>
<dt translate>Created At</dt>
<dd>{$ ::ctrl.healthmonitor.created_at $}</dd>
<dt translate>Updated At</dt>
<dd>{$ ::ctrl.healthmonitor.updated_at $}</dd>
</dl>
</div>