summaryrefslogtreecommitdiff
path: root/cloudinit/sources/helpers/azure.py
diff options
context:
space:
mode:
authorChris Patterson <cpatterson@microsoft.com>2022-02-11 23:40:45 -0500
committerGitHub <noreply@github.com>2022-02-11 22:40:45 -0600
commit0b41b359a70bbbf3a648862a9b849d60b9ff6c3b (patch)
treec53959a1e5346db352e5b5a14a47180092c3e3c4 /cloudinit/sources/helpers/azure.py
parenta62d04e081831be82b3d26c94fee5aa40d7c0802 (diff)
downloadvyos-cloud-init-0b41b359a70bbbf3a648862a9b849d60b9ff6c3b.tar.gz
vyos-cloud-init-0b41b359a70bbbf3a648862a9b849d60b9ff6c3b.zip
sources/azure: address mypy/pyright typing complaints (#1245)
Raise runtime errors for unhandled cases which would cause other exceptions. Ignore types for a few cases where a non-trivial refactor would be required to prevent the warning. Signed-off-by: Chris Patterson <cpatterson@microsoft.com>
Diffstat (limited to 'cloudinit/sources/helpers/azure.py')
-rwxr-xr-xcloudinit/sources/helpers/azure.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/cloudinit/sources/helpers/azure.py b/cloudinit/sources/helpers/azure.py
index ec6ab80c..d07dc3c0 100755
--- a/cloudinit/sources/helpers/azure.py
+++ b/cloudinit/sources/helpers/azure.py
@@ -334,12 +334,10 @@ def _get_dhcp_endpoint_option_name():
@azure_ds_telemetry_reporter
-def http_with_retries(url, **kwargs) -> str:
+def http_with_retries(url, **kwargs) -> url_helper.UrlResponse:
"""Wrapper around url_helper.readurl() with custom telemetry logging
that url_helper.readurl() does not provide.
"""
- exc = None
-
max_readurl_attempts = 240
default_readurl_timeout = 5
sleep_duration_between_retries = 5
@@ -374,16 +372,18 @@ def http_with_retries(url, **kwargs) -> str:
return ret
except Exception as e:
- exc = e
if attempt % periodic_logging_attempts == 0:
report_diagnostic_event(
"Failed HTTP request with Azure endpoint %s during "
"attempt %d with exception: %s" % (url, attempt, e),
logger_func=LOG.debug,
)
- time.sleep(sleep_duration_between_retries)
+ if attempt == max_readurl_attempts:
+ raise
+
+ time.sleep(sleep_duration_between_retries)
- raise exc
+ raise RuntimeError("Failed to return in http_with_retries")
def build_minimal_ovf(
@@ -433,14 +433,16 @@ class AzureEndpointHttpClient:
"x-ms-guest-agent-public-x509-cert": certificate,
}
- def get(self, url, secure=False):
+ def get(self, url, secure=False) -> url_helper.UrlResponse:
headers = self.headers
if secure:
headers = self.headers.copy()
headers.update(self.extra_secure_headers)
return http_with_retries(url, headers=headers)
- def post(self, url, data=None, extra_headers=None):
+ def post(
+ self, url, data=None, extra_headers=None
+ ) -> url_helper.UrlResponse:
headers = self.headers
if extra_headers is not None:
headers = self.headers.copy()