From dac4adc9e540fefd2db66545dc6c2a06ba57020c Mon Sep 17 00:00:00 2001 From: Aaron Rosen Date: Thu, 16 Oct 2014 04:11:42 -0700 Subject: [PATCH] NSX: Make conn_idle_timeout configurable If there is a loadbalancer that sits between NSX and neutron usually it has a default http_timeout on long lived http_connections. This can cause connections that have not been used from neutron to nsx to be reset after sometime. This patch makes the amount time we wait to reconnect the connection configurable so one can set it to match the balancer timeout to avoid having to try the connection if the loadbalaner has already timed it out. closes-bug #1382000 Change-Id: Ifca76ca6c24a2002b46b1935fbb4fc63f15c5af1 --- etc/neutron/plugins/vmware/nsx.ini | 3 +++ neutron/plugins/vmware/api_client/base.py | 6 +++--- neutron/plugins/vmware/common/config.py | 4 ++++ neutron/tests/unit/vmware/test_nsx_opts.py | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/etc/neutron/plugins/vmware/nsx.ini b/etc/neutron/plugins/vmware/nsx.ini index baca73b86..a9bf5c5e0 100644 --- a/etc/neutron/plugins/vmware/nsx.ini +++ b/etc/neutron/plugins/vmware/nsx.ini @@ -41,6 +41,9 @@ # interface name was not specified # default_interface_name = breth0 +# Reconnect connection to nsx if not used within this amount of time. +# conn_idle_timeout = 900 + [quotas] # number of network gateways allowed per tenant, -1 means unlimited # quota_network_gateway = 5 diff --git a/neutron/plugins/vmware/api_client/base.py b/neutron/plugins/vmware/api_client/base.py index e8998b5cd..c1c5da3c8 100644 --- a/neutron/plugins/vmware/api_client/base.py +++ b/neutron/plugins/vmware/api_client/base.py @@ -19,6 +19,8 @@ import httplib import six import time +from oslo.config import cfg + from neutron.openstack.common import log as logging from neutron.plugins.vmware import api_client @@ -33,8 +35,6 @@ DEFAULT_CONNECT_TIMEOUT = 5 class ApiClientBase(object): """An abstract baseclass for all API client implementations.""" - CONN_IDLE_TIMEOUT = 60 * 15 - def _create_connection(self, host, port, is_ssl): if is_ssl: return httplib.HTTPSConnection(host, port, @@ -106,7 +106,7 @@ class ApiClientBase(object): LOG.debug(_("[%d] Waiting to acquire API client connection."), rid) priority, conn = self._conn_pool.get() now = time.time() - if getattr(conn, 'last_used', now) < now - self.CONN_IDLE_TIMEOUT: + if getattr(conn, 'last_used', now) < now - cfg.CONF.conn_idle_timeout: LOG.info(_("[%(rid)d] Connection %(conn)s idle for %(sec)0.2f " "seconds; reconnecting."), {'rid': rid, 'conn': api_client.ctrl_conn_to_str(conn), diff --git a/neutron/plugins/vmware/common/config.py b/neutron/plugins/vmware/common/config.py index 6fde0b402..01735ae10 100644 --- a/neutron/plugins/vmware/common/config.py +++ b/neutron/plugins/vmware/common/config.py @@ -124,6 +124,10 @@ connection_opts = [ cfg.ListOpt('nsx_controllers', deprecated_name='nvp_controllers', help=_("Lists the NSX controllers in this cluster")), + cfg.IntOpt('conn_idle_timeout', + default=900, + help=_('Reconnect connection to nsx if not used within this ' + 'amount of time.')), ] cluster_opts = [ diff --git a/neutron/tests/unit/vmware/test_nsx_opts.py b/neutron/tests/unit/vmware/test_nsx_opts.py index 2b1537384..2f0e65d4a 100644 --- a/neutron/tests/unit/vmware/test_nsx_opts.py +++ b/neutron/tests/unit/vmware/test_nsx_opts.py @@ -129,6 +129,7 @@ class ConfigurationTest(base.BaseTestCase): self.assertIsNone(cfg.CONF.default_l3_gw_service_uuid) self.assertIsNone(cfg.CONF.default_l2_gw_service_uuid) self.assertEqual('breth0', cfg.CONF.default_interface_name) + self.assertEqual(900, cfg.CONF.conn_idle_timeout) def test_load_api_extensions(self): self.config_parse(args=['--config-file', BASE_CONF_PATH, -- 2.45.2