summaryrefslogtreecommitdiff
path: root/cloudinit/user_data.py
diff options
context:
space:
mode:
authorAndrew Jorgensen <ajorgens@amazon.com>2014-03-06 13:26:05 -0800
committerScott Moser <smoser@brickies.net>2017-11-13 12:45:59 -0500
commite10ad2d7854b87024b5d051db50166125fce2279 (patch)
tree4a306e2ff718d1f3ab4f6268e1d8889eba159e3e /cloudinit/user_data.py
parent22a14a6a6d45ae55d2c2307d7b097eef9863bb0c (diff)
downloadvyos-cloud-init-e10ad2d7854b87024b5d051db50166125fce2279.tar.gz
vyos-cloud-init-e10ad2d7854b87024b5d051db50166125fce2279.zip
Catch UrlError when #include'ing 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>
Diffstat (limited to 'cloudinit/user_data.py')
-rw-r--r--cloudinit/user_data.py28
1 files changed, 18 insertions, 10 deletions
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)