diff --git a/vmware_nsx/plugins/nsx_v3/plugin.py b/vmware_nsx/plugins/nsx_v3/plugin.py index 14f2992ddc..3dba4d87a2 100644 --- a/vmware_nsx/plugins/nsx_v3/plugin.py +++ b/vmware_nsx/plugins/nsx_v3/plugin.py @@ -227,11 +227,6 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, else: nsxlib_utils.set_inject_headers_callback(inject_requestid_header) self.lbv2_driver = self._init_lbv2_driver() - # reinitialize the cluster upon fork for api workers to ensure each - # process has its own keepalive loops + state - registry.subscribe( - self.nsxlib.reinitialize_cluster, - resources.PROCESS, events.AFTER_INIT) registry.subscribe( self.on_subnetpool_address_scope_updated, @@ -267,10 +262,10 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, # init profiles on nsx backend self._init_nsx_profiles() - # Init the FWaaS support - registry.subscribe( - self._init_fwaas, - resources.PROCESS, events.AFTER_INIT) + self.init_is_complete = False + registry.subscribe(self.init_complete, + resources.PROCESS, + events.AFTER_INIT) # Include exclude NSGroup LOG.debug("Initializing NSX v3 Excluded Port NSGroup") @@ -303,6 +298,22 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, # Register NSXv3 trunk driver to support trunk extensions self.trunk_driver = trunk_driver.NsxV3TrunkDriver.create(self) + def init_complete(self, resource, event, trigger, payload=None): + with locking.LockManager.get_lock('plugin-init-complete'): + if self.init_is_complete: + # Should be called only once per worker + return + + # reinitialize the cluster upon fork for api workers to ensure + # each process has its own keepalive loops + state + self.nsxlib.reinitialize_cluster(resource, event, trigger, + payload=payload) + + # Init the FWaaS support + self._init_fwaas() + + self.init_is_complete = True + def _extend_fault_map(self): """Extends the Neutron Fault Map. @@ -323,7 +334,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, webob.exc.HTTPBadRequest, }) - def _init_fwaas(self, resource, event, trigger, **kwargs): + def _init_fwaas(self): self.fwaas_callbacks = None if fwaas_utils.is_fwaas_v1_plugin_enabled(): LOG.info("NSXv3 FWaaS v1 plugin enabled") diff --git a/vmware_nsx/services/fwaas/nsx_v3/edge_fwaas_driver_base.py b/vmware_nsx/services/fwaas/nsx_v3/edge_fwaas_driver_base.py index a5d0fffc84..820d46e983 100644 --- a/vmware_nsx/services/fwaas/nsx_v3/edge_fwaas_driver_base.py +++ b/vmware_nsx/services/fwaas/nsx_v3/edge_fwaas_driver_base.py @@ -42,10 +42,16 @@ class CommonEdgeFwaasV3Driver(fwaas_base.FwaasDriverBase): registry.subscribe( self.check_backend_version, resources.PROCESS, events.BEFORE_SPAWN) + self._core_plugin = None @property def core_plugin(self): - return directory.get_plugin() + if not self._core_plugin: + self._core_plugin = directory.get_plugin() + # make sure plugin init was completed + if not self._core_plugin.init_is_complete: + self._core_plugin.init_complete(None, None, {}) + return self._core_plugin @property def nsxlib(self): diff --git a/vmware_nsx/tests/unit/nsx_v3/test_fwaas_v1_driver.py b/vmware_nsx/tests/unit/nsx_v3/test_fwaas_v1_driver.py index 33b240b158..971b71b308 100644 --- a/vmware_nsx/tests/unit/nsx_v3/test_fwaas_v1_driver.py +++ b/vmware_nsx/tests/unit/nsx_v3/test_fwaas_v1_driver.py @@ -65,6 +65,7 @@ class Nsxv3FwaasTestCase(test_v3_plugin.NsxV3PluginTestCaseMixin): Nsxv3FwaasCallbacksV1(self.plugin.nsxlib) self.plugin.fwaas_callbacks.fwaas_enabled = True self.plugin.fwaas_callbacks.fwaas_driver = self.firewall + self.plugin.init_is_complete = True def _default_rule(self, drop=True): rule = DEFAULT_RULE diff --git a/vmware_nsx/tests/unit/nsx_v3/test_fwaas_v2_driver.py b/vmware_nsx/tests/unit/nsx_v3/test_fwaas_v2_driver.py index 10dd5190c2..de9f3674e4 100644 --- a/vmware_nsx/tests/unit/nsx_v3/test_fwaas_v2_driver.py +++ b/vmware_nsx/tests/unit/nsx_v3/test_fwaas_v2_driver.py @@ -65,6 +65,7 @@ class Nsxv3FwaasTestCase(test_v3_plugin.NsxV3PluginTestCaseMixin): Nsxv3FwaasCallbacksV2(self.plugin.nsxlib) self.plugin.fwaas_callbacks.fwaas_enabled = True self.plugin.fwaas_callbacks.fwaas_driver = self.firewall + self.plugin.init_is_complete = True def _default_rule(self): rule = DEFAULT_RULE