Merge "Allow disabling keepalive_section"

This commit is contained in:
Zuul 2020-02-27 23:56:58 +00:00 committed by Gerrit Code Review
commit 126e4e1be1
2 changed files with 26 additions and 8 deletions

View File

@ -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)

View File

@ -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