NSX|V: Support changing the position of LBAAS L7 policy
The neutron lbaas api support reordering the l7 policies. This patch adds this support to the vmware-nsx plugin Change-Id: I595a8cd16c46eb881b176e09ad452b3c9d371b3e
This commit is contained in:
parent
899cf3918a
commit
fc6d3b2ed4
@ -177,6 +177,35 @@ class EdgeL7PolicyManager(base_mgr.EdgeLoadbalancerBaseManager):
|
|||||||
# update the backend with the new configuration
|
# update the backend with the new configuration
|
||||||
self.vcns.update_vip(edge_id, vse_id, vse)
|
self.vcns.update_vip(edge_id, vse_id, vse)
|
||||||
|
|
||||||
|
def _update_app_rule_possition_in_virtual_server(self, edge_id, vse_id,
|
||||||
|
app_rule_id,
|
||||||
|
policy_position):
|
||||||
|
"""Move the new nsx application rule to another position"""
|
||||||
|
# Get the current virtual server configuration
|
||||||
|
vse = self.vcns.get_vip(edge_id, vse_id)[1]
|
||||||
|
|
||||||
|
# delete the policy (= application rule) from the list
|
||||||
|
if app_rule_id in vse['applicationRuleId']:
|
||||||
|
vse['applicationRuleId'].remove(app_rule_id)
|
||||||
|
|
||||||
|
# Add the policy (=application rule) in the correct position
|
||||||
|
# (position begins at 1)
|
||||||
|
if len(vse['applicationRuleId']) < policy_position:
|
||||||
|
vse['applicationRuleId'].append(app_rule_id)
|
||||||
|
else:
|
||||||
|
vse['applicationRuleId'].insert(policy_position - 1, app_rule_id)
|
||||||
|
|
||||||
|
# update the backend with the new configuration
|
||||||
|
self.vcns.update_vip(edge_id, vse_id, vse)
|
||||||
|
|
||||||
|
def _get_vse_id(self, context, pol):
|
||||||
|
lb_id = pol.listener.loadbalancer_id
|
||||||
|
list_id = pol.listener.id
|
||||||
|
listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
|
||||||
|
context.session, lb_id, list_id)
|
||||||
|
if listener_binding:
|
||||||
|
return listener_binding['vse_id']
|
||||||
|
|
||||||
@log_helpers.log_method_call
|
@log_helpers.log_method_call
|
||||||
def create(self, context, pol):
|
def create(self, context, pol):
|
||||||
# find out the edge to be updated, by the listener of this policy
|
# find out the edge to be updated, by the listener of this policy
|
||||||
@ -198,12 +227,10 @@ class EdgeL7PolicyManager(base_mgr.EdgeLoadbalancerBaseManager):
|
|||||||
|
|
||||||
# add the nsx application rule (neutron policy) to the nsx
|
# add the nsx application rule (neutron policy) to the nsx
|
||||||
# virtual server (neutron listener)
|
# virtual server (neutron listener)
|
||||||
listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
|
vse_id = self._get_vse_id(context, pol)
|
||||||
context.session, lb_id, pol.listener.id)
|
if vse_id:
|
||||||
if listener_binding:
|
|
||||||
self._add_app_rule_to_virtual_server(
|
self._add_app_rule_to_virtual_server(
|
||||||
edge_id, listener_binding['vse_id'], app_rule_id,
|
edge_id, vse_id, app_rule_id, pol.position)
|
||||||
pol.position)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
with excutils.save_and_reraise_exception():
|
with excutils.save_and_reraise_exception():
|
||||||
self.lbv2_driver.l7policy.failed_completion(context, pol)
|
self.lbv2_driver.l7policy.failed_completion(context, pol)
|
||||||
@ -234,6 +261,14 @@ class EdgeL7PolicyManager(base_mgr.EdgeLoadbalancerBaseManager):
|
|||||||
with locking.LockManager.get_lock(edge_id):
|
with locking.LockManager.get_lock(edge_id):
|
||||||
# update the backend application rule for the new policy
|
# update the backend application rule for the new policy
|
||||||
self.vcns.update_app_rule(edge_id, app_rule_id, app_rule)
|
self.vcns.update_app_rule(edge_id, app_rule_id, app_rule)
|
||||||
|
|
||||||
|
# if the position changed - update it too
|
||||||
|
if old_pol.position != new_pol.position:
|
||||||
|
vse_id = self._get_vse_id(context, new_pol)
|
||||||
|
if vse_id:
|
||||||
|
self._update_app_rule_possition_in_virtual_server(
|
||||||
|
edge_id, vse_id, app_rule_id, new_pol.position)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
with excutils.save_and_reraise_exception():
|
with excutils.save_and_reraise_exception():
|
||||||
self.lbv2_driver.l7policy.failed_completion(context, new_pol)
|
self.lbv2_driver.l7policy.failed_completion(context, new_pol)
|
||||||
@ -259,11 +294,8 @@ class EdgeL7PolicyManager(base_mgr.EdgeLoadbalancerBaseManager):
|
|||||||
with locking.LockManager.get_lock(edge_id):
|
with locking.LockManager.get_lock(edge_id):
|
||||||
try:
|
try:
|
||||||
# remove the nsx application rule from the virtual server
|
# remove the nsx application rule from the virtual server
|
||||||
lb_id = pol.listener.loadbalancer_id
|
vse_id = self._get_vse_id(context, pol)
|
||||||
listener_binding = nsxv_db.get_nsxv_lbaas_listener_binding(
|
if vse_id:
|
||||||
context.session, lb_id, pol.listener.id)
|
|
||||||
if listener_binding:
|
|
||||||
vse_id = listener_binding['vse_id']
|
|
||||||
self._del_app_rule_from_virtual_server(
|
self._del_app_rule_from_virtual_server(
|
||||||
edge_id, vse_id, app_rule_id)
|
edge_id, vse_id, app_rule_id)
|
||||||
|
|
||||||
|
@ -711,16 +711,26 @@ class TestEdgeLbaasV2L7Policy(BaseTestEdgeLbaasV2):
|
|||||||
action='REDIRECT_TO_URL',
|
action='REDIRECT_TO_URL',
|
||||||
redirect_url=url,
|
redirect_url=url,
|
||||||
listener=self.listener,
|
listener=self.listener,
|
||||||
position=1)
|
position=2)
|
||||||
|
|
||||||
with mock.patch.object(nsxv_db, 'get_nsxv_lbaas_l7policy_binding'
|
with mock.patch.object(nsxv_db, 'get_nsxv_lbaas_l7policy_binding'
|
||||||
) as mock_get_l7policy_binding, \
|
) as mock_get_l7policy_binding, \
|
||||||
mock.patch.object(nsxv_db, 'get_nsxv_lbaas_loadbalancer_binding'
|
mock.patch.object(nsxv_db, 'get_nsxv_lbaas_loadbalancer_binding'
|
||||||
) as mock_get_lb_binding, \
|
) as mock_get_lb_binding, \
|
||||||
|
mock.patch.object(nsxv_db, 'get_nsxv_lbaas_listener_binding'
|
||||||
|
) as mock_get_listener_binding, \
|
||||||
|
mock.patch.object(self.edge_driver.vcns, 'get_vip'
|
||||||
|
) as mock_get_vip, \
|
||||||
|
mock.patch.object(self.edge_driver.vcns, 'update_vip'
|
||||||
|
) as mock_upd_vip, \
|
||||||
mock.patch.object(self.edge_driver.vcns, 'update_app_rule'
|
mock.patch.object(self.edge_driver.vcns, 'update_app_rule'
|
||||||
) as mock_update_rule:
|
) as mock_update_rule:
|
||||||
mock_get_lb_binding.return_value = LB_BINDING
|
mock_get_lb_binding.return_value = LB_BINDING
|
||||||
mock_get_l7policy_binding.return_value = L7POL_BINDING
|
mock_get_l7policy_binding.return_value = L7POL_BINDING
|
||||||
|
mock_get_listener_binding.return_value = LISTENER_BINDING
|
||||||
|
edge_vip_def = EDGE_VIP_DEF.copy()
|
||||||
|
edge_vip_def['applicationRuleId'] = [EDGE_RULE_ID]
|
||||||
|
mock_get_vip.return_value = (None, edge_vip_def)
|
||||||
|
|
||||||
self.edge_driver.l7policy.update(self.context, self.l7policy,
|
self.edge_driver.l7policy.update(self.context, self.l7policy,
|
||||||
new_pol)
|
new_pol)
|
||||||
@ -729,6 +739,7 @@ class TestEdgeLbaasV2L7Policy(BaseTestEdgeLbaasV2):
|
|||||||
edge_rule_def['script'] = "redirect location %s if TRUE" % url
|
edge_rule_def['script'] = "redirect location %s if TRUE" % url
|
||||||
mock_update_rule.assert_called_with(
|
mock_update_rule.assert_called_with(
|
||||||
LB_EDGE_ID, EDGE_RULE_ID, edge_rule_def)
|
LB_EDGE_ID, EDGE_RULE_ID, edge_rule_def)
|
||||||
|
mock_upd_vip.assert_called()
|
||||||
mock_successful_completion = (
|
mock_successful_completion = (
|
||||||
self.lbv2_driver.l7policy.successful_completion)
|
self.lbv2_driver.l7policy.successful_completion)
|
||||||
mock_successful_completion.assert_called_with(self.context,
|
mock_successful_completion.assert_called_with(self.context,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user