From bbf48e9c69ba9c67ca5ddb88fdfc5ee83f57d2f7 Mon Sep 17 00:00:00 2001 From: Adit Sarfaty <asarfaty@vmware.com> Date: Mon, 8 Jan 2018 08:33:32 +0200 Subject: [PATCH] TVD: move plugins init_complete code to the end of init If the nsx-v/v3 init fails, the registration to init_complete should not be done, since the init_complete method might fail too. Change-Id: I2b9550394f67f4dfb79dba9455f2d75af5d28802 --- vmware_nsx/plugins/nsx_v/plugin.py | 11 +++++++---- vmware_nsx/plugins/nsx_v3/plugin.py | 12 +++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/vmware_nsx/plugins/nsx_v/plugin.py b/vmware_nsx/plugins/nsx_v/plugin.py index 69eac467e4..91bccfedee 100644 --- a/vmware_nsx/plugins/nsx_v/plugin.py +++ b/vmware_nsx/plugins/nsx_v/plugin.py @@ -223,6 +223,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin, floatingip=l3_db_models.FloatingIP) def __init__(self): self._is_sub_plugin = tvd_utils.is_tvd_core_plugin() + self.init_is_complete = False self.housekeeper = None super(NsxVPluginV2, self).__init__() if self._is_sub_plugin: @@ -233,10 +234,6 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin, extension_drivers=extension_drivers) # Bind the dummy L3 notifications self.l3_rpc_notifier = l3_rpc_agent_api.L3NotifyAPI() - self.init_is_complete = False - registry.subscribe(self.init_complete, - resources.PROCESS, - events.AFTER_INIT) self._extension_manager.initialize() self.supported_extension_aliases.extend( self._extension_manager.extension_aliases()) @@ -323,6 +320,12 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin, # Bind QoS notifications qos_driver.register(self) + # subscribe the init complete method last, so it will be called only + # if init was successful + registry.subscribe(self.init_complete, + resources.PROCESS, + events.AFTER_INIT) + @staticmethod def plugin_type(): return projectpluginmap.NsxPlugins.NSX_V diff --git a/vmware_nsx/plugins/nsx_v3/plugin.py b/vmware_nsx/plugins/nsx_v3/plugin.py index e79d38e7d6..d47d18191a 100644 --- a/vmware_nsx/plugins/nsx_v3/plugin.py +++ b/vmware_nsx/plugins/nsx_v3/plugin.py @@ -214,6 +214,7 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, floatingip=l3_db_models.FloatingIP) def __init__(self): self._is_sub_plugin = tvd_utils.is_tvd_core_plugin() + self.init_is_complete = False nsxlib_utils.set_is_attr_callback(validators.is_attr_set) self._extend_fault_map() if self._is_sub_plugin: @@ -271,11 +272,6 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, # init profiles on nsx backend self._init_nsx_profiles() - 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") self._excluded_port_nsgroup = None @@ -307,6 +303,12 @@ class NsxV3Plugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, # Register NSXv3 trunk driver to support trunk extensions self.trunk_driver = trunk_driver.NsxV3TrunkDriver.create(self) + # subscribe the init complete method last, so it will be called only + # if init was successful + registry.subscribe(self.init_complete, + resources.PROCESS, + events.AFTER_INIT) + @staticmethod def plugin_type(): return projectpluginmap.NsxPlugins.NSX_T