diff options
| author | Andrew Jorgensen <ajorgens@amazon.com> | 2014-03-06 21:26:05 (GMT) |
|---|---|---|
| committer | Andrew Jorgensen <ajorgens@amazon.com> | 2017-06-13 23:09:39 (GMT) |
| commit | aaa626dd8aecc078210d3a48ff39faf3fd30cbdc (patch) | |
| tree | 1170d9c83b6590c5bdb1e4d248fd8f0396c2736f | |
| parent | bfa9f4239cce53c368dd36df63bb0e6e4f47e4fc (diff) | |
Catch UrlError when #includeing URLs
Without this the entire stage can fail, which will leave an instance
unaccessible.
Reviewed-by: Tom Kirchner <tjk@amazon.com>
Reviewed-by: Matt Nierzwicki <nierzwic@amazon.com>
Reviewed-by: Ben Cressey <bcressey@amazon.com>
[ajorgens@amazon.com: rebase onto 0.7.9]
| -rw-r--r-- | cloudinit/user_data.py | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/cloudinit/user_data.py b/cloudinit/user_data.py index cfe5aa2..e2681b4 100644 --- a/cloudinit/user_data.py +++ b/cloudinit/user_data.py @@ -20,6 +20,7 @@ import six from cloudinit import handlers from cloudinit import log as logging from cloudinit import util +from cloudinit.url_helper import UrlError LOG = logging.getLogger(__name__) @@ -221,16 +222,22 @@ 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.warn(("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: + raise UrlError(None, resp.code) + except UrlError as urle: + LOG.warning(("Fetching from %s resulted in" + " a invalid http code of %s"), + include_url, resp.code) + except IOError as ioe: + LOG.warning("Fetching from %s resulted in an IOError: %s", + include_url, ioe.strerror) if content is not None: new_msg = convert_string(content) |
