From 49598f470177ed9478979c9efe3ca079caa4c8cc Mon Sep 17 00:00:00 2001 From: Shawn Wang Date: Wed, 26 Feb 2020 15:13:12 -0800 Subject: [PATCH] Allow disabling keepalive_section In case validate_connection_method already has the effect to keep alive, it should be allowed to not perform any extra keep-alive requests. Currently in MP the default keepalive section is transport-zones, which is deemed to degrade in performance a lot in scale setup. As a more light-weighted path reverse-proxy/node/health is already used, we should allow configuring keepalive section to be disabled. Change-Id: I26c0af67f90b62533a39827ca5111832d306a153 --- vmware_nsxlib/tests/unit/v3/test_cluster.py | 15 +++++++++++++++ vmware_nsxlib/v3/cluster.py | 19 +++++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/vmware_nsxlib/tests/unit/v3/test_cluster.py b/vmware_nsxlib/tests/unit/v3/test_cluster.py index 15e4ea5c..1927d52a 100644 --- a/vmware_nsxlib/tests/unit/v3/test_cluster.py +++ b/vmware_nsxlib/tests/unit/v3/test_cluster.py @@ -184,6 +184,21 @@ class RequestsHTTPProviderTestCase(unittest.TestCase): return_value={'result_count': 1}): provider.validate_connection(mock_cluster, mock_ep, mock_conn) + def test_validate_connection_no_keep_alive(self): + mock_conn = mocks.MockRequestSessionApi() + mock_conn.default_headers = {} + mock_ep = mock.Mock() + mock_ep.provider.url = 'https://1.2.3.4' + mock_cluster = mock.Mock() + mock_cluster.nsxlib_config = mock.Mock() + mock_cluster.nsxlib_config.url_base = 'abc' + mock_cluster.nsxlib_config.keepalive_section = None + provider = cluster.NSXRequestsHTTPProvider() + + with mock.patch.object(client.JSONRESTClient, "get") as mock_get: + provider.validate_connection(mock_cluster, mock_ep, mock_conn) + mock_get.assert_not_called() + def _validate_con_mocks(self, nsx_version): nsxlib_config = nsxlib_testcase.get_default_nsxlib_config() nsxlib = v3.NsxLib(nsxlib_config) diff --git a/vmware_nsxlib/v3/cluster.py b/vmware_nsxlib/v3/cluster.py index ccf904ab..dc17b3d7 100644 --- a/vmware_nsxlib/v3/cluster.py +++ b/vmware_nsxlib/v3/cluster.py @@ -198,14 +198,17 @@ class NSXRequestsHTTPProvider(AbstractHTTPProvider): # If keeplive section returns a list, it is assumed to be non-empty keepalive_section = cluster_api.nsxlib_config.keepalive_section - result = client.get(keepalive_section, silent=True) - if not result or result.get('result_count', 1) <= 0: - msg = _("No %(section)s found " - "for '%(url)s'") % {'section': keepalive_section, - 'url': endpoint.provider.url} - LOG.warning(msg) - raise exceptions.ResourceNotFound( - manager=endpoint.provider.url, operation=msg) + # When validate connection also has the effect of keep-alive, + # keepalive_section can be disabled by passing in an empty value + if keepalive_section: + result = client.get(keepalive_section, silent=True) + if not result or result.get('result_count', 1) <= 0: + msg = _("No %(section)s found " + "for '%(url)s'") % {'section': keepalive_section, + 'url': endpoint.provider.url} + LOG.warning(msg) + raise exceptions.ResourceNotFound( + manager=endpoint.provider.url, operation=msg) def new_connection(self, cluster_api, provider): config = cluster_api.nsxlib_config