From e10ad2d7854b87024b5d051db50166125fce2279 Mon Sep 17 00:00:00 2001 From: Andrew Jorgensen Date: Thu, 6 Mar 2014 13:26:05 -0800 Subject: Catch UrlError when #include'ing URLs Without this the entire stage can fail, which will leave an instance unaccessible. Reviewed-by: Tom Kirchner Reviewed-by: Matt Nierzwicki Reviewed-by: Ben Cressey --- cloudinit/user_data.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'cloudinit/user_data.py') diff --git a/cloudinit/user_data.py b/cloudinit/user_data.py index 88cb7f84..e163c722 100644 --- a/cloudinit/user_data.py +++ b/cloudinit/user_data.py @@ -19,6 +19,7 @@ import six from cloudinit import handlers from cloudinit import log as logging +from cloudinit.url_helper import UrlError from cloudinit import util LOG = logging.getLogger(__name__) @@ -222,16 +223,23 @@ class UserDataProcessor(object): if include_once_on and os.path.isfile(include_once_fn): content = util.load_file(include_once_fn) else: - resp = util.read_file_or_url(include_url, - ssl_details=self.ssl_details) - if include_once_on and resp.ok(): - util.write_file(include_once_fn, resp.contents, mode=0o600) - if resp.ok(): - content = resp.contents - else: - LOG.warning(("Fetching from %s resulted in" - " a invalid http code of %s"), - include_url, resp.code) + try: + resp = util.read_file_or_url(include_url, + ssl_details=self.ssl_details) + if include_once_on and resp.ok(): + util.write_file(include_once_fn, resp.contents, + mode=0o600) + if resp.ok(): + content = resp.contents + else: + LOG.warning(("Fetching from %s resulted in" + " a invalid http code of %s"), + include_url, resp.code) + except UrlError as urle: + LOG.warning(urle) + except IOError as ioe: + LOG.warning("Fetching from %s resulted in %s", + include_url, ioe) if content is not None: new_msg = convert_string(content) -- cgit v1.2.3 From 6ad23fe9b11f07e4404c8a1f2f1e9cba2640dceb Mon Sep 17 00:00:00 2001 From: Chad Smith Date: Thu, 16 Nov 2017 20:47:02 -0700 Subject: centos: Provide the failed #include url in error messages On python 2.7 and earlier (CentOS 6 & 7), UrlErrors raised by requests do not report the url which failed. In such cases, append the url if not present in the error message. This fixes nightly CI failures at https://jenkins.ubuntu.com/server/view/cloud-init/. --- cloudinit/user_data.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'cloudinit/user_data.py') diff --git a/cloudinit/user_data.py b/cloudinit/user_data.py index e163c722..cc55daf8 100644 --- a/cloudinit/user_data.py +++ b/cloudinit/user_data.py @@ -236,7 +236,12 @@ class UserDataProcessor(object): " a invalid http code of %s"), include_url, resp.code) except UrlError as urle: - LOG.warning(urle) + message = str(urle) + # Older versions of requests.exceptions.HTTPError may not + # include the errant url. Append it for clarity in logs. + if include_url not in message: + message += ' for url: {0}'.format(include_url) + LOG.warning(message) except IOError as ioe: LOG.warning("Fetching from %s resulted in %s", include_url, ioe) -- cgit v1.2.3