From 2ddeba6ea4f09ad9ba2a8ae0d66abdab924d600c Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Sun, 17 Sep 2017 11:05:22 +0300 Subject: [PATCH] NSX|V complete init of fwaas core plugin The FWaaS driver uses the core plugin. In some cases the init-complete callback was not yet issued for this plugin and should be called manually. Change-Id: Id64d7242e8aa7595a73d0af22fd44bf1119cb2a7 --- vmware_nsx/plugins/nsx_v/plugin.py | 35 +++++++++++-------- .../services/fwaas/nsx_v/edge_fwaas_driver.py | 7 +++- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/vmware_nsx/plugins/nsx_v/plugin.py b/vmware_nsx/plugins/nsx_v/plugin.py index 52311dd860..aa549d7f26 100644 --- a/vmware_nsx/plugins/nsx_v/plugin.py +++ b/vmware_nsx/plugins/nsx_v/plugin.py @@ -304,22 +304,27 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin, qos_driver.register(self) def init_complete(self, resource, event, trigger, **kwargs): - has_metadata_cfg = ( - cfg.CONF.nsxv.nova_metadata_ips - and cfg.CONF.nsxv.mgt_net_moid - and cfg.CONF.nsxv.mgt_net_proxy_ips - and cfg.CONF.nsxv.mgt_net_proxy_netmask) - if has_metadata_cfg: - # Init md_proxy handler per availability zone - self.metadata_proxy_handler = {} - for az in self.get_azs_list(): - # create metadata handler only if the az supports it. - # if not, the global one will be used - if az.supports_metadata(): - self.metadata_proxy_handler[az.name] = ( - nsx_v_md_proxy.NsxVMetadataProxyHandler(self, az)) + with locking.LockManager.get_lock('plugin-init-complete'): + if self.init_is_complete: + # Should be called only once per worker + return + has_metadata_cfg = ( + cfg.CONF.nsxv.nova_metadata_ips + and cfg.CONF.nsxv.mgt_net_moid + and cfg.CONF.nsxv.mgt_net_proxy_ips + and cfg.CONF.nsxv.mgt_net_proxy_netmask) + if has_metadata_cfg: + # Init md_proxy handler per availability zone + self.metadata_proxy_handler = {} + for az in self.get_azs_list(): + # create metadata handler only if the az supports it. + # if not, the global one will be used + if az.supports_metadata(): + self.metadata_proxy_handler[az.name] = ( + nsx_v_md_proxy.NsxVMetadataProxyHandler( + self, az)) - self.init_is_complete = True + self.init_is_complete = True def _validate_nsx_version(self): ver = self.nsx_v.vcns.get_version() diff --git a/vmware_nsx/services/fwaas/nsx_v/edge_fwaas_driver.py b/vmware_nsx/services/fwaas/nsx_v/edge_fwaas_driver.py index 4106372402..53220bac6c 100644 --- a/vmware_nsx/services/fwaas/nsx_v/edge_fwaas_driver.py +++ b/vmware_nsx/services/fwaas/nsx_v/edge_fwaas_driver.py @@ -34,7 +34,11 @@ class EdgeFwaasDriver(fwaas_base.FwaasDriverBase): @property def core_plugin(self): - return directory.get_plugin() + if not self._core_plugin: + self._core_plugin = directory.get_plugin() + if not self._core_plugin.init_is_complete: + self._core_plugin.init_complete(None, None, {}) + return self._core_plugin @property def edge_manager(self): @@ -44,6 +48,7 @@ class EdgeFwaasDriver(fwaas_base.FwaasDriverBase): LOG.debug("Loading FWaaS NsxVDriver.") super(EdgeFwaasDriver, self).__init__() self.driver_name = FWAAS_DRIVER_NAME + self._core_plugin = None def should_apply_firewall_to_router(self, router_data, raise_exception=True):