From d3310b0b387727aee17ff1dfe5679c24f8a7c878 Mon Sep 17 00:00:00 2001 From: Maurice Escher Date: Tue, 3 May 2022 18:19:25 +0200 Subject: [PATCH] [NetApp] Fix lack of retry HTTP requests The driver HTTP requester is not handling connection error with some retries for avoiding temporary network failure in name resolution. This patch adds a custom `HTTPAdapter` with 5 retries, according to urrlib3 documentation [1]. Also, the connection retry will be visible in the log [2]. [1] https://urllib3.readthedocs.io/en/latest/reference/urllib3.util.html#module-urllib3.util.retry [2] https://paste.opendev.org/show/bIcwjk91d4vy5Hnxxs4Z/ Closes-Bug: #1971542 Change-Id: Ic9ff8208f10df9dbed09717d6b218f6293d2338a --- manila/share/drivers/netapp/dataontap/client/api.py | 9 +++++++++ .../notes/netapp-retry-requests-0a77a31f5222d4b2.yaml | 8 ++++++++ 2 files changed, 17 insertions(+) create mode 100644 releasenotes/notes/netapp-retry-requests-0a77a31f5222d4b2.yaml diff --git a/manila/share/drivers/netapp/dataontap/client/api.py b/manila/share/drivers/netapp/dataontap/client/api.py index 26bc5db785..f2cf6533a1 100644 --- a/manila/share/drivers/netapp/dataontap/client/api.py +++ b/manila/share/drivers/netapp/dataontap/client/api.py @@ -25,7 +25,9 @@ from lxml import etree from oslo_log import log from oslo_serialization import jsonutils import requests +from requests.adapters import HTTPAdapter from requests import auth +from requests.packages.urllib3.util.retry import Retry from manila import exception from manila.i18n import _ @@ -227,6 +229,11 @@ class BaseClient(object): auth_handler = self._create_certificate_auth_handler() self._session = requests.Session() + + max_retries = Retry(total=5, connect=5, read=2, backoff_factor=1) + adapter = HTTPAdapter(max_retries=max_retries) + self._session.mount('%s://' % self._protocol, adapter) + self._session.auth = auth_handler self._session.verify = self._ssl_verify headers = self._build_headers() @@ -329,6 +336,8 @@ class ZapiClient(BaseClient): self._build_session() try: if hasattr(self, '_timeout'): + if self._timeout is None: + self._timeout = 10 response = self._session.post( self._get_url(), data=request_d, timeout=self._timeout) else: diff --git a/releasenotes/notes/netapp-retry-requests-0a77a31f5222d4b2.yaml b/releasenotes/notes/netapp-retry-requests-0a77a31f5222d4b2.yaml new file mode 100644 index 0000000000..8ae3d39b99 --- /dev/null +++ b/releasenotes/notes/netapp-retry-requests-0a77a31f5222d4b2.yaml @@ -0,0 +1,8 @@ +--- +fixes: + - | + Sometimes NetApp API call fails due to name resolution(DNS) issue. In + such case, a client will now make 5 retries on connect and 2 on read + calls. Also, the connection retry will be visible in the log. For more + details, please refer to + `launchpad bug #1971542 `_