From cff03595a12b74d578bf80619398ff2fed31acd2 Mon Sep 17 00:00:00 2001 From: Salvatore Orlando Date: Wed, 19 Jun 2019 14:13:05 -0700 Subject: [PATCH] [NSX-p] Check for a LB before enabling/disabling service router Change-Id: I7db94c9290dd4c7876f008f7cd82c66cbcd39d63 --- vmware_nsx/plugins/nsx_p/plugin.py | 3 ++- vmware_nsx/tests/unit/nsx_p/test_plugin.py | 3 +++ vmware_nsx/tests/unit/services/vpnaas/test_nsxp_vpnaas.py | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/vmware_nsx/plugins/nsx_p/plugin.py b/vmware_nsx/plugins/nsx_p/plugin.py index 540cb1c182..419a0f2fd5 100644 --- a/vmware_nsx/plugins/nsx_p/plugin.py +++ b/vmware_nsx/plugins/nsx_p/plugin.py @@ -1563,8 +1563,9 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base): router_subnets = self._find_router_subnets( context.elevated(), router_id) sr_currently_exists = self.verify_sr_at_backend(router_id) - lb_exist = False + lb_exist = self.service_router_has_loadbalancers(context, router_id) fw_exist = self._router_has_edge_fw_rules(context, router) + # TODO(asarfaty): Add vpnaas check here actions = self._get_update_router_gw_actions( org_tier0_uuid, orgaddr, org_enable_snat, new_tier0_uuid, newaddr, new_enable_snat, diff --git a/vmware_nsx/tests/unit/nsx_p/test_plugin.py b/vmware_nsx/tests/unit/nsx_p/test_plugin.py index 5e5f98ba3e..e0f990eaca 100644 --- a/vmware_nsx/tests/unit/nsx_p/test_plugin.py +++ b/vmware_nsx/tests/unit/nsx_p/test_plugin.py @@ -1435,6 +1435,9 @@ class NsxPTestL3NatTestCase(NsxPTestL3NatTest, def setUp(self, *args, **kwargs): super(NsxPTestL3NatTestCase, self).setUp(*args, **kwargs) + mock.patch.object(self.plugin.nsxpolicy, 'search_by_tags', + return_value={'results': []}).start() + def test__notify_gateway_port_ip_changed(self): self.skipTest('not supported') diff --git a/vmware_nsx/tests/unit/services/vpnaas/test_nsxp_vpnaas.py b/vmware_nsx/tests/unit/services/vpnaas/test_nsxp_vpnaas.py index 09f5d74225..80ada78db5 100644 --- a/vmware_nsx/tests/unit/services/vpnaas/test_nsxp_vpnaas.py +++ b/vmware_nsx/tests/unit/services/vpnaas/test_nsxp_vpnaas.py @@ -540,6 +540,9 @@ class TestVpnaasDriver(test_plugin.NsxPPluginTestCaseMixin): self.policy_vpn = self.plugin.nsxpolicy.ipsec_vpn self.l3plugin = self.plugin + mock.patch.object(self.plugin.nsxpolicy, 'search_by_tags', + return_value={'results': []}).start() + @contextlib.contextmanager def router(self, name='vpn-test-router', tenant_id=_uuid(), admin_state_up=True, **kwargs):