From e6a1b694cf9044de9a31e6675a29987cb0efd0e1 Mon Sep 17 00:00:00 2001 From: Adit Sarfaty Date: Sun, 26 May 2019 11:14:19 +0300 Subject: [PATCH] TVD: Retry on pluging initialization Change-Id: I0c6a10a35d333115065c2d7442885f716fc6118f --- vmware_nsx/common/config.py | 4 ++++ vmware_nsx/plugins/nsx/plugin.py | 17 ++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/vmware_nsx/common/config.py b/vmware_nsx/common/config.py index be3212934b..a1d20ece64 100644 --- a/vmware_nsx/common/config.py +++ b/vmware_nsx/common/config.py @@ -1003,6 +1003,10 @@ nsx_tvd_opts = [ help=_("The default availability zones that will be used for " "NSX-V3 networks and routers creation under the TVD " "plugin.")), + cfg.IntOpt('init_retries', + default=3, + help=_('Maximum number of times a particular plugin ' + 'initialization should be retried')), ] # Register the configuration options diff --git a/vmware_nsx/plugins/nsx/plugin.py b/vmware_nsx/plugins/nsx/plugin.py index 7f1523ae4c..b9b070f50a 100644 --- a/vmware_nsx/plugins/nsx/plugin.py +++ b/vmware_nsx/plugins/nsx/plugin.py @@ -53,6 +53,7 @@ from vmware_nsx.common import config from vmware_nsx.common import exceptions as nsx_exc from vmware_nsx.common import locking from vmware_nsx.common import managers as nsx_managers +from vmware_nsx.common import utils as com_utils from vmware_nsx.db import ( routertype as rt_rtr) from vmware_nsx.db import db as nsx_db @@ -134,6 +135,16 @@ class NsxTVDPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, def is_tvd_plugin(): return True + @com_utils.retry_upon_exception(Exception, 0.5, 2, + cfg.CONF.nsx_tvd.init_retries) + def _call_plugin_init_with_retry(self, map_type, plugin_class): + try: + self.plugins[map_type] = plugin_class() + except Exception as e: + with excutils.save_and_reraise_exception(): + LOG.warning("%s plugin failed to initialized: %s", + map_type.upper(), e) + def _init_plugin(self, map_type, plugin_class): if map_type not in cfg.CONF.nsx_tvd.enabled_plugins: # skip this plugin @@ -141,10 +152,10 @@ class NsxTVDPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin, map_type.upper()) return try: - self.plugins[map_type] = plugin_class() + self._call_plugin_init_with_retry(map_type, plugin_class) except Exception as e: - LOG.warning("%s plugin will not be supported: %s", - map_type.upper(), e) + LOG.warning("%s plugin will not be supported", + map_type.upper()) if map_type == self.default_plugin: msg = (_("The default plugin %(def)s failed to start. " "Reason: %(reason)s") % {'def': self.default_plugin,