Browse Source

Being able to change session persistence of pool

Change-Id: I8e576795dfb45d558ace7006cb21e98f8251ca04
Story: 1713864
Task: 5371
Story: 1713862
Task: 5369
changes/07/506807/3
Jacky Hu 4 years ago
parent
commit
1e39d6cd1e
  1. 26
      octavia_dashboard/api/rest/lbaasv2.py
  2. 15
      octavia_dashboard/static/dashboard/project/lbaasv2/workflow/model.service.js
  3. 58
      octavia_dashboard/static/dashboard/project/lbaasv2/workflow/model.service.spec.js
  4. 15
      octavia_dashboard/static/dashboard/project/lbaasv2/workflow/pool/pool.help.html
  5. 25
      octavia_dashboard/static/dashboard/project/lbaasv2/workflow/pool/pool.html

26
octavia_dashboard/api/rest/lbaasv2.py

@ -170,10 +170,23 @@ def create_pool(request, **kwargs):
"""
data = request.DATA
session_persistence_type = data['pool'].get('type')
if session_persistence_type is None:
session_persistence = None
else:
cookie = data['pool'].get('cookie')
if session_persistence_type != 'APP_COOKIE':
cookie = None
session_persistence = {
'type': session_persistence_type,
'cookie_name': cookie
}
conn = _get_sdk_connection(request)
pool = conn.load_balancer.create_pool(
protocol=data['pool']['protocol'],
lb_algorithm=data['pool']['method'],
session_persistence=session_persistence,
listener_id=kwargs['listener_id'],
name=data['pool'].get('name'),
description=data['pool'].get('description'))
@ -331,10 +344,23 @@ def update_pool(request, **kwargs):
pool_id = data['pool'].get('id')
loadbalancer_id = data.get('loadbalancer_id')
session_persistence_type = data['pool'].get('type')
if session_persistence_type is None:
session_persistence = None
else:
cookie = data['pool'].get('cookie')
if session_persistence_type != 'APP_COOKIE':
cookie = None
session_persistence = {
'type': session_persistence_type,
'cookie_name': cookie
}
conn = _get_sdk_connection(request)
pool = conn.load_balancer.update_pool(
pool=pool_id,
lb_algorithm=data['pool']['method'],
session_persistence=session_persistence,
name=data['pool'].get('name'),
description=data['pool'].get('description'))

15
octavia_dashboard/static/dashboard/project/lbaasv2/workflow/model.service.js

@ -87,6 +87,7 @@
members: [],
listenerProtocols: ['HTTP', 'TCP', 'TERMINATED_HTTPS'],
methods: ['LEAST_CONNECTIONS', 'ROUND_ROBIN', 'SOURCE_IP'],
types: ['SOURCE_IP', 'HTTP_COOKIE', 'APP_COOKIE'],
monitorTypes: ['HTTP', 'PING', 'TCP'],
monitorMethods: ['GET', 'HEAD'],
certificates: [],
@ -152,7 +153,9 @@
name: gettext('Pool 1'),
description: null,
protocol: null,
method: null
method: null,
type: null,
cookie: null
},
monitor: {
id: null,
@ -634,6 +637,16 @@
spec.description = pool.description;
spec.protocol = pool.protocol;
spec.method = pool.lb_algorithm;
if (angular.isObject(pool.session_persistence)) {
var type = pool.session_persistence.type;
var cookie = pool.session_persistence.cookie_name;
if (type) {
spec.type = type;
}
if (type === 'APP_COOKIE' && cookie) {
spec.cookie = cookie;
}
}
}
function setMembersSpec(membersList) {

58
octavia_dashboard/static/dashboard/project/lbaasv2/workflow/model.service.spec.js

@ -39,6 +39,10 @@
name: 'Pool 1',
protocol: 'HTTP',
lb_algorithm: 'ROUND_ROBIN',
session_persistence: {
type: 'APP_COOKIE',
cookie_name: 'cookie_name'
},
description: 'pool description'
},
members: [
@ -340,6 +344,10 @@
expect(model.methods).toEqual(['LEAST_CONNECTIONS', 'ROUND_ROBIN', 'SOURCE_IP']);
});
it('has array of pool session persistence types', function() {
expect(model.types).toEqual(['SOURCE_IP', 'HTTP_COOKIE', 'APP_COOKIE']);
});
it('has array of monitor types', function() {
expect(model.monitorTypes).toEqual(['HTTP', 'PING', 'TCP']);
});
@ -548,6 +556,8 @@
expect(model.spec.pool.description).toBeNull();
expect(model.spec.pool.protocol).toBeNull();
expect(model.spec.pool.method).toBeNull();
expect(model.spec.pool.type).toBeNull();
expect(model.spec.pool.cookie).toBeNull();
});
it('should initialize monitor model spec properties', function() {
@ -687,6 +697,8 @@
expect(model.spec.pool.description).toBe('pool description');
expect(model.spec.pool.protocol).toBe('HTTP');
expect(model.spec.pool.method).toBe('ROUND_ROBIN');
expect(model.spec.pool.type).toBe('APP_COOKIE');
expect(model.spec.pool.cookie).toBe('cookie_name');
});
it('should initialize all monitor properties', function() {
@ -767,6 +779,8 @@
expect(model.spec.pool.description).toBe('pool description');
expect(model.spec.pool.protocol).toBe('HTTP');
expect(model.spec.pool.method).toBe('ROUND_ROBIN');
expect(model.spec.pool.type).toBe('APP_COOKIE');
expect(model.spec.pool.cookie).toBe('cookie_name');
});
it('should initialize all monitor properties', function() {
@ -847,6 +861,8 @@
expect(model.spec.pool.description).toBe('pool description');
expect(model.spec.pool.protocol).toBe('HTTP');
expect(model.spec.pool.method).toBe('ROUND_ROBIN');
expect(model.spec.pool.type).toBe('APP_COOKIE');
expect(model.spec.pool.cookie).toBe('cookie_name');
});
it('should initialize all monitor properties to null', function() {
@ -926,7 +942,7 @@
expect(Object.keys(model.spec).length).toBe(8);
expect(Object.keys(model.spec.loadbalancer).length).toBe(4);
expect(Object.keys(model.spec.listener).length).toBe(5);
expect(Object.keys(model.spec.pool).length).toBe(5);
expect(Object.keys(model.spec.pool).length).toBe(7);
expect(Object.keys(model.spec.monitor).length).toBe(8);
expect(model.spec.members).toEqual([]);
});
@ -1167,6 +1183,7 @@
model.spec.pool.name = 'pool name';
model.spec.pool.description = 'pool description';
model.spec.pool.method = 'LEAST_CONNECTIONS';
model.spec.pool.type = 'SOURCE_IP';
model.spec.members = [{
address: { ip: '1.2.3.4', subnet: '1' },
addresses: [{ ip: '1.2.3.4', subnet: '1' },
@ -1220,6 +1237,7 @@
expect(finalSpec.pool.description).toBe('pool description');
expect(finalSpec.pool.protocol).toBe('TCP');
expect(finalSpec.pool.method).toBe('LEAST_CONNECTIONS');
expect(finalSpec.pool.type).toBe('SOURCE_IP');
expect(finalSpec.members.length).toBe(3);
expect(finalSpec.members[0].address).toBe('1.2.3.4');
@ -1840,6 +1858,8 @@
expect(finalSpec.pool.description).toBe('pool description');
expect(finalSpec.pool.protocol).toBe('HTTP');
expect(finalSpec.pool.method).toBe('ROUND_ROBIN');
expect(finalSpec.pool.type).toBe('APP_COOKIE');
expect(finalSpec.pool.cookie).toBe('cookie_name');
expect(finalSpec.members.length).toBe(2);
expect(finalSpec.members[0].id).toBe('1234');
@ -1879,6 +1899,8 @@
expect(finalSpec.pool.description).toBe('pool description');
expect(finalSpec.pool.protocol).toBe('HTTP');
expect(finalSpec.pool.method).toBe('ROUND_ROBIN');
expect(finalSpec.pool.type).toBe('APP_COOKIE');
expect(finalSpec.pool.cookie).toBe('cookie_name');
expect(finalSpec.members.length).toBe(2);
expect(finalSpec.members[0].id).toBe('1234');
@ -1920,6 +1942,8 @@
expect(finalSpec.pool.description).toBe('pool description');
expect(finalSpec.pool.protocol).toBe('HTTP');
expect(finalSpec.pool.method).toBe('ROUND_ROBIN');
expect(finalSpec.pool.type).toBe('APP_COOKIE');
expect(finalSpec.pool.cookie).toBe('cookie_name');
expect(finalSpec.members.length).toBe(2);
expect(finalSpec.members[0].id).toBe('1234');
@ -1983,6 +2007,38 @@
});
});
describe('Model visible resources (edit pool, no session persistence type)', function() {
beforeEach(function() {
includeChildResources = true;
delete listenerResources.listener;
delete listenerResources.monitor;
delete listenerResources.pool.session_persistence.type;
model.initialize('pool', 'poolId', 'loadbalancerId');
scope.$apply();
});
it('should only show pool and monitor details', function() {
expect(model.visibleResources).toEqual(['pool', 'members']);
});
});
describe('Model visible resources (edit pool, no session persistence cookie name)', function() {
beforeEach(function() {
includeChildResources = true;
delete listenerResources.listener;
delete listenerResources.monitor;
delete listenerResources.pool.session_persistence.cookie_name;
model.initialize('pool', 'poolId', 'loadbalancerId');
scope.$apply();
});
it('should only show pool and monitor details', function() {
expect(model.visibleResources).toEqual(['pool', 'members']);
});
});
describe('Model submit function (edit health monitor)', function() {
beforeEach(function() {

15
octavia_dashboard/static/dashboard/project/lbaasv2/workflow/pool/pool.help.html

@ -17,3 +17,18 @@
</li>
</ul>
</p>
<p translate>
<strong>Session Persistence:</strong>
The type of session persistence for distributing traffic to the pool members.
<ul>
<li>
SOURCE_IP: Session persistence based on source ip.
</li>
<li>
HTTP_COOKIE: Session persistence based on http cookie.
</li>
<li>
APP_COOKIE: Session persistence based on application cookie.
</li>
</ul>
</p>

25
octavia_dashboard/static/dashboard/project/lbaasv2/workflow/pool/pool.html

@ -21,6 +21,31 @@
</div>
<div class="row">
<div class="col-xs-12 col-sm-8 col-md-6">
<div class="form-group">
<label translate class="control-label" for="type">
Session Persistence
</label>
<select class="form-control" name="type" id="type"
ng-options="type for type in model.types"
ng-model="model.spec.pool.type">
<option value="">None</option>
</select>
</div>
</div>
<div class="col-xs-12 col-sm-8 col-md-6" ng-if="model.spec.pool.type === 'APP_COOKIE'">
<div class="form-group">
<label translate class="control-label" for="cookie">Cookie</label>
<input name="cookie" id="cookie" type="text" class="form-control"
ng-model="model.spec.pool.cookie">
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-8 col-md-6">

Loading…
Cancel
Save