From 9770f7f4522d14a3d24da9dcb4e9c02d5b4b24d8 Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Mon, 22 Apr 2019 07:48:36 +0300 Subject: [PATCH] NSX|P Fix different LBaaS issues Change-Id: I7e5454e12445864cb377488c29135169fe0c7f2a --- vmware_nsx/plugins/nsx_p/plugin.py | 4 ++-- vmware_nsx/services/fwaas/nsx_p/fwaas_callbacks_v2.py | 2 +- .../lbaas/nsx_p/implementation/healthmonitor_mgr.py | 5 +---- .../lbaas/nsx_p/implementation/l7policy_mgr.py | 10 ++++++---- .../services/lbaas/nsx_p/implementation/l7rule_mgr.py | 3 ++- .../services/lbaas/nsx_p/implementation/lb_utils.py | 9 +++++---- .../lbaas/nsx_p/implementation/listener_mgr.py | 6 ++---- .../lbaas/nsx_p/implementation/loadbalancer_mgr.py | 2 +- 8 files changed, 20 insertions(+), 21 deletions(-) diff --git a/vmware_nsx/plugins/nsx_p/plugin.py b/vmware_nsx/plugins/nsx_p/plugin.py index fc91b4ceec..e726864994 100644 --- a/vmware_nsx/plugins/nsx_p/plugin.py +++ b/vmware_nsx/plugins/nsx_p/plugin.py @@ -1461,7 +1461,7 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base): if update_firewall: self.update_router_firewall(context, router_id) - def delete_service_router(self, project_id, router_id): + def delete_service_router(self, router_id): try: # Disable standby relocation on this router self.nsxpolicy.tier1.set_standby_relocation( @@ -1574,7 +1574,7 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base): router_subnets, advertise_ipv6_subnets) if actions['remove_service_router']: - self.delete_service_router(router['project_id'], router_id) + self.delete_service_router(router_id) def _update_router_advertisement_rules(self, router_id, subnets, advertise_ipv6): diff --git a/vmware_nsx/services/fwaas/nsx_p/fwaas_callbacks_v2.py b/vmware_nsx/services/fwaas/nsx_p/fwaas_callbacks_v2.py index e384aedb95..65803ea9f3 100644 --- a/vmware_nsx/services/fwaas/nsx_p/fwaas_callbacks_v2.py +++ b/vmware_nsx/services/fwaas/nsx_p/fwaas_callbacks_v2.py @@ -350,7 +350,7 @@ class NsxpFwaasCallbacksV2(com_callbacks.NsxCommonv3FwaasCallbacksV2): # No other services that require service router: delete it # This also deleted the gateway policy. self.core_plugin.delete_service_router( - context, policy_constants.DEFAULT_DOMAIN, router_id) + context, router_id) sr_exists_on_backend = False if sr_exists_on_backend: diff --git a/vmware_nsx/services/lbaas/nsx_p/implementation/healthmonitor_mgr.py b/vmware_nsx/services/lbaas/nsx_p/implementation/healthmonitor_mgr.py index 1a9065e100..081ce8a4f9 100644 --- a/vmware_nsx/services/lbaas/nsx_p/implementation/healthmonitor_mgr.py +++ b/vmware_nsx/services/lbaas/nsx_p/implementation/healthmonitor_mgr.py @@ -108,10 +108,7 @@ class EdgeHealthMonitorManagerFromDict(base_mgr.NsxpLoadbalancerBaseManager): monitor_client = self._get_monitor_policy_client(new_hm) try: monitor_body = self._build_monitor_args(new_hm) - monitor_name = utils.get_name_and_uuid(new_hm['name'] or 'monitor', - new_hm['id']) - monitor_client.update(new_hm['id'], name=monitor_name, - **monitor_body) + monitor_client.update(new_hm['id'], **monitor_body) except nsxlib_exc.ManagerError as exc: completor(success=False) msg = _('Failed to update monitor %(monitor)s with exception' diff --git a/vmware_nsx/services/lbaas/nsx_p/implementation/l7policy_mgr.py b/vmware_nsx/services/lbaas/nsx_p/implementation/l7policy_mgr.py index b8a7c70343..727aff314e 100644 --- a/vmware_nsx/services/lbaas/nsx_p/implementation/l7policy_mgr.py +++ b/vmware_nsx/services/lbaas/nsx_p/implementation/l7policy_mgr.py @@ -34,12 +34,13 @@ class EdgeL7PolicyManagerFromDict(base_mgr.NsxpLoadbalancerBaseManager): vs_client = self.core_plugin.nsxpolicy.load_balancer.virtual_server policy_name = utils.get_name_and_uuid(policy['name'] or 'policy', policy['id']) - rule_body = lb_utils.convert_l7policy_to_lb_rule(policy) + rule_body = lb_utils.convert_l7policy_to_lb_rule( + self.core_plugin.nsxpolicy, policy) try: - + position = policy.get('position', 0) - 1 vs_client.add_lb_rule(policy['listener_id'], name=policy_name, - position=policy.get('position', 0) - 1, + position=position, **rule_body) except nsxlib_exc.ManagerError: with excutils.save_and_reraise_exception(): @@ -55,7 +56,8 @@ class EdgeL7PolicyManagerFromDict(base_mgr.NsxpLoadbalancerBaseManager): vs_client = self.core_plugin.nsxpolicy.load_balancer.virtual_server policy_name = utils.get_name_and_uuid(old_policy['name'] or 'policy', old_policy['id']) - rule_body = lb_utils.convert_l7policy_to_lb_rule(context, new_policy) + rule_body = lb_utils.convert_l7policy_to_lb_rule( + self.core_plugin.nsxpolicy, new_policy) try: vs_client.update_lb_rule( new_policy['listener_id'], diff --git a/vmware_nsx/services/lbaas/nsx_p/implementation/l7rule_mgr.py b/vmware_nsx/services/lbaas/nsx_p/implementation/l7rule_mgr.py index 4bb1412f70..5c144cdeb2 100644 --- a/vmware_nsx/services/lbaas/nsx_p/implementation/l7rule_mgr.py +++ b/vmware_nsx/services/lbaas/nsx_p/implementation/l7rule_mgr.py @@ -35,7 +35,8 @@ class EdgeL7RuleManagerFromDict(base_mgr.NsxpLoadbalancerBaseManager): lb_utils.remove_rule_from_policy(rule) else: lb_utils.update_rule_in_policy(rule) - rule_body = lb_utils.convert_l7policy_to_lb_rule(rule['policy']) + rule_body = lb_utils.convert_l7policy_to_lb_rule( + self.core_plugin.nsxpolicy, rule['policy']) try: vs_client.update_lb_rule(policy['listener_id'], name=policy_name, diff --git a/vmware_nsx/services/lbaas/nsx_p/implementation/lb_utils.py b/vmware_nsx/services/lbaas/nsx_p/implementation/lb_utils.py index 39d81c4f8b..36511c2ecc 100644 --- a/vmware_nsx/services/lbaas/nsx_p/implementation/lb_utils.py +++ b/vmware_nsx/services/lbaas/nsx_p/implementation/lb_utils.py @@ -69,12 +69,13 @@ def get_rule_match_conditions(policy): @log_helpers.log_method_call -def get_rule_actions(l7policy): +def get_rule_actions(nsxpolicy, l7policy): if l7policy['action'] == lb_const.L7_POLICY_ACTION_REDIRECT_TO_POOL: if l7policy['redirect_pool_id']: lb_pool_id = l7policy['redirect_pool_id'] + lb_pool_path = nsxpolicy.load_balancer.lb_pool.get_path(lb_pool_id) actions = [{'type': p_const.LB_SELECT_POOL_ACTION, - 'pool_id': lb_pool_id}] + 'pool_id': lb_pool_path}] else: msg = _('Failed to get LB pool binding from nsx db') raise n_exc.BadRequest(resource='lbaas-l7rule-create', @@ -95,10 +96,10 @@ def get_rule_actions(l7policy): @log_helpers.log_method_call -def convert_l7policy_to_lb_rule(policy): +def convert_l7policy_to_lb_rule(nsxpolicy, policy): return { 'match_conditions': get_rule_match_conditions(policy), - 'actions': get_rule_actions(policy), + 'actions': get_rule_actions(nsxpolicy, policy), 'phase': lb_const.LB_RULE_HTTP_FORWARDING, 'match_strategy': 'ALL' } diff --git a/vmware_nsx/services/lbaas/nsx_p/implementation/listener_mgr.py b/vmware_nsx/services/lbaas/nsx_p/implementation/listener_mgr.py index d27e5aa8ca..62d62c4936 100644 --- a/vmware_nsx/services/lbaas/nsx_p/implementation/listener_mgr.py +++ b/vmware_nsx/services/lbaas/nsx_p/implementation/listener_mgr.py @@ -167,12 +167,10 @@ class EdgeListenerManagerFromDict(base_mgr.NsxpLoadbalancerBaseManager): tags = self._get_listener_tags(context, new_listener) try: - vs_id = new_listener['id'] app_profile_id = new_listener['id'] updated_kwargs = self._get_virtual_server_kwargs( - context, new_listener, vs_name, tags, app_profile_id, - certificate) - vs_client.update(vs_id, **updated_kwargs) + context, new_listener, vs_name, tags, certificate) + vs_client.update(**updated_kwargs) if vs_name: app_client.update(app_profile_id, display_name=vs_name, tags=tags) diff --git a/vmware_nsx/services/lbaas/nsx_p/implementation/loadbalancer_mgr.py b/vmware_nsx/services/lbaas/nsx_p/implementation/loadbalancer_mgr.py index 8abec4632a..b9d21462b4 100644 --- a/vmware_nsx/services/lbaas/nsx_p/implementation/loadbalancer_mgr.py +++ b/vmware_nsx/services/lbaas/nsx_p/implementation/loadbalancer_mgr.py @@ -159,7 +159,7 @@ class EdgeLoadBalancerManagerFromDict(base_mgr.NsxpLoadbalancerBaseManager): service_client = self.core_plugin.nsxpolicy.load_balancer.lb_service vs_list = self._get_lb_virtual_servers(context, lb) try: - rsp = service_client.get_stats(lb['id']) + rsp = service_client.get_usage(lb['id']) if rsp: for vs in rsp.get('virtual_servers', []): # Skip the virtual server that doesn't belong