Adapt to new Keystone session creation timeouts

Following the inclusion of the connect and read timeouts for the
Keystone client in [1], this commit updates its use in the distcloud
repository. This way, it becomes faster to check if a subcloud is
online or offline by setting a shorter value to the connection timeout,
while keeping the read timeout longer.

[1] https://review.opendev.org/c/starlingx/upstream/+/921973

Test Plan:

- PASS: Build distributedcloud package
- PASS: Build ISO image
- PASS: Install and bootstrap a system controller
- PASS: Install and add a subcloud
- PASS: Manage the subcloud and verify it is in-sync
- PASS: Manual check of periodic audit shows no errors

Story: 2011106
Task: 50365

Change-Id: Ie334006cd63c615117c0d0918b7a63047e3a5fca
Signed-off-by: Lucas de Ataides <lucas.deataidesbarreto@windriver.com>
This commit is contained in:
Lucas de Ataides
2024-07-22 09:39:29 -03:00
committed by Lucas de Ataides Barreto
parent 2881eb47ee
commit 09315144e3
5 changed files with 45 additions and 16 deletions

View File

@@ -230,5 +230,8 @@ ANSIBLE_SUBCLOUD_ENROLL_PLAYBOOK = (
# Sysinv client default timeout
SYSINV_CLIENT_REST_DEFAULT_TIMEOUT = 600
# Keystone client connection timeout
KEYSTONE_SERVER_DISCOVERY_TIMEOUT = 5
SUBCLOUD_ISO_PATH = "/opt/platform/iso"
SUBCLOUD_FEED_PATH = "/var/www/pages/feed"

View File

@@ -217,9 +217,18 @@ class PeerKeystoneClient(base.DriverBase):
project_name=user_project,
project_domain_name=user_project_domain,
)
timeout = HTTP_CONNECT_TIMEOUT if timeout is None else timeout
if isinstance(timeout, tuple):
discovery_timeout = float(timeout[0])
read_timeout = float(timeout[1])
else:
discovery_timeout = consts.KEYSTONE_SERVER_DISCOVERY_TIMEOUT
read_timeout = HTTP_CONNECT_TIMEOUT if timeout is None else read_timeout
return session.Session(
auth=user_auth, additional_headers=consts.USER_HEADER, timeout=timeout
auth=user_auth,
additional_headers=consts.USER_HEADER,
timeout=(discovery_timeout, read_timeout),
)
def _create_keystone_client(self):

View File

@@ -239,7 +239,7 @@ class EndpointCache(object):
user_password: str,
user_project: str,
user_project_domain: str,
timeout: float = None,
timeout=None,
) -> session.Session:
"""Get the admin session.
@@ -255,8 +255,8 @@ class EndpointCache(object):
:type user_project: str
:param user_project_domain: The user project domain.
:type user_project_domain: str
:param timeout: The timeout.
:type timeout: int
:param timeout: The discovery and read timeouts.
:type timeout: Any
:return: The admin session.
:rtype: session.Session
"""
@@ -270,11 +270,20 @@ class EndpointCache(object):
project_domain_name=user_project_domain,
include_catalog=True,
)
timeout = (
CONF.endpoint_cache.http_connect_timeout if timeout is None else timeout
)
if isinstance(timeout, tuple):
discovery_timeout = float(timeout[0])
read_timeout = float(timeout[1])
else:
discovery_timeout = consts.KEYSTONE_SERVER_DISCOVERY_TIMEOUT
read_timeout = (
CONF.endpoint_cache.http_connect_timeout if timeout is None else timeout
)
return session.Session(
auth=user_auth, additional_headers=consts.USER_HEADER, timeout=timeout
auth=user_auth,
additional_headers=consts.USER_HEADER,
timeout=(discovery_timeout, read_timeout),
)
@staticmethod
@@ -364,7 +373,11 @@ class EndpointCache(object):
auth = loader.load_from_options(
auth_url=self.external_auth_url, token=token, project_id=project_id
)
return session.Session(auth=auth)
discovery_timeout = consts.KEYSTONE_SERVER_DISCOVERY_TIMEOUT
read_timeout = CONF.endpoint_cache.http_connect_timeout
return session.Session(auth=auth, timeout=(discovery_timeout, read_timeout))
@classmethod
@lockutils.synchronized(LOCK_NAME)

View File

@@ -120,13 +120,17 @@ class OrchestratorTestCase(base.BaseTestCase):
self.mock_keystone_client = mock_patch.start()
self.addCleanup(mock_patch.stop)
def _mock_endpoint_cache_from_keystone(self):
mock_patch = mock.patch("dccommon.drivers.openstack.keystone_v3.EndpointCache")
def _mock_keystone_endpoint_cache_get_admin_session(self):
mock_patch = mock.patch(
"dccommon.drivers.openstack.keystone_v3.EndpointCache.get_admin_session"
)
self.mock_endpoint_cache_from_keystone = mock_patch.start()
self.addCleanup(mock_patch.stop)
def _mock_endpoint_cache(self):
mock_patch = mock.patch("dccommon.endpoint_cache.EndpointCache")
def _mock_endpoint_cache_get_admin_session(self):
mock_patch = mock.patch(
"dccommon.endpoint_cache.EndpointCache.get_admin_session"
)
self.mock_endpoint_cache = mock_patch.start()
self.addCleanup(mock_patch.stop)

View File

@@ -30,8 +30,8 @@ class BaseTestIdentitySyncThread(OrchestratorTestCase, mixins.BaseMixin):
self._mock_openstack_driver()
self._mock_keystone_client()
self._mock_endpoint_cache_from_keystone()
self._mock_endpoint_cache()
self._mock_keystone_endpoint_cache_get_admin_session()
self._mock_endpoint_cache_get_admin_session()
self._mock_m_dbs_client()
self._mock_sc_dbs_client()
self._mock_rpc_client_subcloud_state_client()