From 1e39d6cd1e8bf9c77c6019247c71e6f03072398e Mon Sep 17 00:00:00 2001 From: Jacky Hu Date: Fri, 22 Sep 2017 19:37:11 -0400 Subject: [PATCH] Being able to change session persistence of pool Change-Id: I8e576795dfb45d558ace7006cb21e98f8251ca04 Story: 1713864 Task: 5371 Story: 1713862 Task: 5369 --- octavia_dashboard/api/rest/lbaasv2.py | 26 +++++++++ .../project/lbaasv2/workflow/model.service.js | 15 ++++- .../lbaasv2/workflow/model.service.spec.js | 58 ++++++++++++++++++- .../lbaasv2/workflow/pool/pool.help.html | 15 +++++ .../project/lbaasv2/workflow/pool/pool.html | 25 ++++++++ 5 files changed, 137 insertions(+), 2 deletions(-) diff --git a/octavia_dashboard/api/rest/lbaasv2.py b/octavia_dashboard/api/rest/lbaasv2.py index c67a28cb..ed039968 100644 --- a/octavia_dashboard/api/rest/lbaasv2.py +++ b/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')) diff --git a/octavia_dashboard/static/dashboard/project/lbaasv2/workflow/model.service.js b/octavia_dashboard/static/dashboard/project/lbaasv2/workflow/model.service.js index 8617b7a0..b980f7f2 100644 --- a/octavia_dashboard/static/dashboard/project/lbaasv2/workflow/model.service.js +++ b/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) { diff --git a/octavia_dashboard/static/dashboard/project/lbaasv2/workflow/model.service.spec.js b/octavia_dashboard/static/dashboard/project/lbaasv2/workflow/model.service.spec.js index 605f9e4c..823fbea2 100644 --- a/octavia_dashboard/static/dashboard/project/lbaasv2/workflow/model.service.spec.js +++ b/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() { diff --git a/octavia_dashboard/static/dashboard/project/lbaasv2/workflow/pool/pool.help.html b/octavia_dashboard/static/dashboard/project/lbaasv2/workflow/pool/pool.help.html index f0795e9c..26337e58 100644 --- a/octavia_dashboard/static/dashboard/project/lbaasv2/workflow/pool/pool.help.html +++ b/octavia_dashboard/static/dashboard/project/lbaasv2/workflow/pool/pool.help.html @@ -17,3 +17,18 @@

+

+ Session Persistence: + The type of session persistence for distributing traffic to the pool members. +

+

diff --git a/octavia_dashboard/static/dashboard/project/lbaasv2/workflow/pool/pool.html b/octavia_dashboard/static/dashboard/project/lbaasv2/workflow/pool/pool.html index b13cabdc..a54e3f83 100644 --- a/octavia_dashboard/static/dashboard/project/lbaasv2/workflow/pool/pool.html +++ b/octavia_dashboard/static/dashboard/project/lbaasv2/workflow/pool/pool.html @@ -21,6 +21,31 @@ +
+ +
+
+ + +
+
+ +
+
+ + +
+
+ +
+