Skip to content

Commit

Permalink
Merge pull request #1017 from richbrowne/stable/newton
Browse files Browse the repository at this point in the history
 Virtual pool name unit tests assumptions should be updated
  • Loading branch information
pjbreaux authored Oct 6, 2017
2 parents 99697dd + e89adef commit 71ec7c7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
30 changes: 23 additions & 7 deletions f5_openstack_agent/lbaasv2/drivers/bigip/service_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def get_resource_description(self, resource):
def get_virtual(self, service):
listener = service["listener"]
loadbalancer = service["loadbalancer"]
pool = service.get('pool', None)

listener["use_snat"] = self.snat_mode()
if listener["use_snat"] and self.snat_count() > 0:
Expand All @@ -100,7 +99,9 @@ def get_virtual(self, service):
listener["session_persistence"] = \
service["pool"]["session_persistence"]

vip = self._map_virtual(loadbalancer, listener, pool=pool)
vip = self._map_virtual(
loadbalancer, listener, pool=service.get('pool', None))

self._add_bigip_items(listener, vip)
return vip

Expand All @@ -120,7 +121,12 @@ def _init_virtual_name(self, loadbalancer, listener):

def _init_virtual_name_with_pool(self, loadbalancer, listener, pool=None):
vip = self._init_virtual_name(loadbalancer, listener)
vip['pool'] = self.init_pool_name(loadbalancer, pool)
pool = self.init_pool_name(loadbalancer, pool)
if pool['name']:
vip['pool'] = pool['name']
else:
vip['pool'] = None

return vip

def get_traffic_group(self, service):
Expand All @@ -136,8 +142,13 @@ def get_vip_default_pool(self, service):
listener = service["listener"]
loadbalancer = service["loadbalancer"]
pool = service["pool"]
vip = self._init_virtual_name_with_pool(
loadbalancer, listener, pool=pool)
vip = self._init_virtual_name(
loadbalancer, listener)
if "default_pool_id" in listener:
p = self.init_pool_name(loadbalancer, pool)
vip["pool"] = p["name"]
else:
vip["pool"] = ""

return vip

Expand Down Expand Up @@ -346,8 +357,11 @@ def _get_lb_method(self, method):
return 'round-robin'

def _map_virtual(self, loadbalancer, listener, pool=None):
vip = self._init_virtual_name_with_pool(
loadbalancer, listener, pool=pool)
vip = self._init_virtual_name(loadbalancer, listener)

if pool:
p = self.init_pool_name(loadbalancer, pool)
vip["pool"] = p["name"]

vip["description"] = self.get_resource_description(listener)

Expand Down Expand Up @@ -386,6 +400,8 @@ def _map_virtual(self, loadbalancer, listener, pool=None):

if "pool" in listener:
vip["pool"] = listener["pool"]
else:
vip["pool"] = None

return vip

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,24 +166,28 @@ def test_init_virtual_name_with_pool(self, target, basic_service):
listener = basic_service['listener']
pool = basic_service['pools'][0]
target._init_virtual_name = Mock(return_value=dict())
target.init_pool_name = Mock(return_value='pool')
target.init_pool_name = Mock(return_value=dict(name='pool'))
assert target._init_virtual_name_with_pool(
loadbalancer, listener, pool) == dict(pool='pool')
loadbalancer, listener, pool) == {'pool': 'pool'}
target._init_virtual_name.assert_called_once_with(
loadbalancer, listener)
target.init_pool_name.assert_called_once_with(
loadbalancer, pool)
target.init_pool_name.return_value = dict(name='')
target._init_virtual_name.return_value = dict()
assert target._init_virtual_name_with_pool(
loadbalancer, listener, pool) == {'pool': None}

def test_get_vip_default_pool(self, target, basic_service):
pool = basic_service['pools'][0]
basic_service['pool'] = pool
loadbalancer = basic_service['loadbalancer']
listener = basic_service['listener']
vip = 'vip'
vip = {'name': "pre-_" + listener['id'],
'partition': "pre-_" + loadbalancer['tenant_id'],
'pool': ''}
target._init_virtual_name_with_pool = Mock(return_value=vip)
assert vip == target.get_vip_default_pool(basic_service)
target._init_virtual_name_with_pool.assert_called_once_with(
loadbalancer, listener, pool=pool)

def test_map_virtual(self, target, basic_service):
pool = basic_service['pools'][0]
Expand All @@ -197,6 +201,8 @@ def test_map_virtual(self, target, basic_service):
vip_address = loadbalancer['vip_address'].replace('%0', '')
listener['pool'] = pool
expected = dict(
name="pre-_" + listener['id'],
partition="pre-_" + loadbalancer['tenant_id'],
destination=vip_address + ':' + proto_port, ipProtocol='tcp',
connectionLimit=cx_limit, description=description, enabled=True,
pool=pool)
Expand Down

0 comments on commit 71ec7c7

Please sign in to comment.