Browse Source

Merge "LBaaS Layer4 TCP VIP should use LVS"

changes/87/264187/9
Jenkins 6 years ago
committed by Gerrit Code Review
parent
commit
8254529a06
  1. 6
      vmware_nsx/db/nsxv_db.py
  2. 10
      vmware_nsx/services/lbaas/nsx_v/lbaas_common.py
  3. 10
      vmware_nsx/services/lbaas/nsx_v/v1/edge_loadbalancer_driver.py
  4. 4
      vmware_nsx/services/lbaas/nsx_v/v2/loadbalancer_mgr.py
  5. 8
      vmware_nsx/tests/unit/nsx_v/test_edge_loadbalancer_driver_v2.py

6
vmware_nsx/db/nsxv_db.py

@ -582,6 +582,12 @@ def get_nsxv_lbaas_loadbalancer_binding(session, loadbalancer_id):
return
def get_nsxv_lbaas_loadbalancer_binding_by_edge(session, edge_id):
return session.query(
nsxv_models.NsxvLbaasLoadbalancerBinding).filter_by(
edge_id=edge_id).all()
def del_nsxv_lbaas_loadbalancer_binding(session, loadbalancer_id):
return (session.query(nsxv_models.NsxvLbaasLoadbalancerBinding).
filter_by(loadbalancer_id=loadbalancer_id).delete())

10
vmware_nsx/services/lbaas/nsx_v/lbaas_common.py

@ -249,3 +249,13 @@ def get_lbaas_fw_section_id(vcns):
fw_section_id = et.fromstring(sect).attrib['id']
return fw_section_id
def enable_edge_acceleration(vcns, edge_id):
with locking.LockManager.get_lock(edge_id, external=True):
config = {
'accelerationEnabled': True,
'enabled': True,
'featureType': 'loadbalancer_4.0'}
vcns.enable_service_loadbalancer(edge_id, config)

10
vmware_nsx/services/lbaas/nsx_v/v1/edge_loadbalancer_driver.py

@ -188,6 +188,12 @@ class EdgeLbDriver(object):
'No suitable Edge found for subnet %s') % pool['subnet_id']
raise n_exc.BadRequest(resource='edge-lbaas', msg=msg)
# If Edge appliance is used for the 1st time for LB,
# enable LB acceleration
if not self.is_edge_in_use(context,
edge_id):
lb_common.enable_edge_acceleration(self.vcns, edge_id)
edge_pool = convert_lbaas_pool(pool)
try:
with locking.LockManager.get_lock(edge_id, external=True):
@ -617,8 +623,8 @@ class EdgeLbDriver(object):
'active_connections': 0,
'total_connections': 0}
def is_edge_in_use(self, edge_id):
return self.lbv1_driver.is_edge_in_use(edge_id)
def is_edge_in_use(self, context, edge_id):
return self.lbv1_driver.is_edge_in_use(context, edge_id)
def is_subnet_in_use(self, context, subnet_id):
plugin = self._get_lb_plugin()

4
vmware_nsx/services/lbaas/nsx_v/v2/loadbalancer_mgr.py

@ -37,6 +37,10 @@ class EdgeLoadBalancerManager(base_mgr.EdgeLoadbalancerBaseManager):
edge_id = lb_common.get_lbaas_edge_id_for_subnet(
context, self.core_plugin, lb.vip_subnet_id)
if not nsxv_db.get_nsxv_lbaas_loadbalancer_binding_by_edge(
context.session, edge_id):
lb_common.enable_edge_acceleration(self.vcns, edge_id)
lb_common.add_vip_as_secondary_ip(self.vcns, edge_id,
lb.vip_address)
edge_fw_rule_id = lb_common.add_vip_fw_rule(

8
vmware_nsx/tests/unit/nsx_v/test_edge_loadbalancer_driver_v2.py

@ -138,10 +138,16 @@ class TestEdgeLbaasV2Loadbalancer(BaseTestEdgeLbaasV2):
) as mock_vip_sec_ip, \
mock.patch.object(lb_common, 'add_vip_fw_rule'
) as mock_add_vip_fwr, \
mock.patch.object(lb_common, 'enable_edge_acceleration'
) as mock_enable_edge_acceleration, \
mock.patch.object(nsxv_db,
'get_nsxv_lbaas_loadbalancer_binding_by_edge'
) as mock_get_lb_binding_by_edge, \
mock.patch.object(nsxv_db, 'add_nsxv_lbaas_loadbalancer_binding'
) as mock_db_binding:
mock_get_edge.return_value = LB_EDGE_ID
mock_add_vip_fwr.return_value = LB_VIP_FWR_ID
mock_get_lb_binding_by_edge.return_value = []
self.edge_driver.loadbalancer.create(self.context, self.lb)
@ -161,6 +167,8 @@ class TestEdgeLbaasV2Loadbalancer(BaseTestEdgeLbaasV2):
self.lbv2_driver.load_balancer.successful_completion)
mock_successful_completion.assert_called_with(self.context,
self.lb)
mock_enable_edge_acceleration.assert_called_with(
self.edge_driver.vcns, LB_EDGE_ID)
def test_update(self):
new_lb = lb_models.LoadBalancer(LB_ID, 'yyy-yyy', 'lb-name', 'heh-huh',

Loading…
Cancel
Save