summaryrefslogtreecommitdiff
path: root/cloudinit/distros
diff options
context:
space:
mode:
authorDaniel Watkins <oddbloke@ubuntu.com>2020-04-23 16:50:20 -0400
committerGitHub <noreply@github.com>2020-04-23 16:50:20 -0400
commit7276aa5240b8cb84671a56d795d811f15dfba8e2 (patch)
tree9570ff6187b309904bf38edd9d0e55effbc173ab /cloudinit/distros
parentc5b44e46c13b0940a30073dc36196e430f8d2acb (diff)
downloadvyos-cloud-init-7276aa5240b8cb84671a56d795d811f15dfba8e2.tar.gz
vyos-cloud-init-7276aa5240b8cb84671a56d795d811f15dfba8e2.zip
distros: handle a potential mirror filtering error case (#328)
As written, it's possible that the first transformation for a mirror hostname could be passed None if the parsed mirror URL didn't have a hostname component, when the defined interface is that the transformations will be passed strings. This isn't an error currently, because the first transformation happens to gracefully handle being passed None. It returns None, so the pipeline processing ends there. This was caught when testing out mypy on the cloud-init codebase.
Diffstat (limited to 'cloudinit/distros')
-rwxr-xr-xcloudinit/distros/__init__.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
index e63b8c7a..e99529df 100755
--- a/cloudinit/distros/__init__.py
+++ b/cloudinit/distros/__init__.py
@@ -750,6 +750,10 @@ def _apply_hostname_transformations_to_url(url: str, transformations: list):
# If we can't even parse the URL, we shouldn't use it for anything
return None
new_hostname = parts.hostname
+ if new_hostname is None:
+ # The URL given doesn't have a hostname component, so (a) we can't
+ # transform it, and (b) it won't work as a mirror; return None.
+ return None
for transformation in transformations:
new_hostname = transformation(new_hostname)