diff --git a/heatclient/common/template_utils.py b/heatclient/common/template_utils.py index a1b176c3..2a6504ca 100644 --- a/heatclient/common/template_utils.py +++ b/heatclient/common/template_utils.py @@ -31,15 +31,26 @@ def process_template_path(template_path, object_request=None, existing=False): """Read template from template path. Attempt to read template first as a file or url. If that is unsuccessful, - try again to assuming path is to a template object. + try again assuming path is to a template object. + + :param template_path: local or uri path to template + :param object_request: custom object request function used to get template + if local or uri path fails + :param existing: if the current stack's template should be used + :returns: get_file dict and template contents + :raises: error.URLError """ try: return get_template_contents(template_file=template_path, existing=existing) - except error.URLError: - return get_template_contents(template_object=template_path, - object_request=object_request, - existing=existing) + except error.URLError as template_file_exc: + try: + return get_template_contents(template_object=template_path, + object_request=object_request, + existing=existing) + except exc.HTTPNotFound: + # The initial exception gives the user better failure context. + raise template_file_exc def get_template_contents(template_file=None, template_url=None, diff --git a/heatclient/tests/unit/test_template_utils.py b/heatclient/tests/unit/test_template_utils.py index 551f4636..a1cac5ea 100644 --- a/heatclient/tests/unit/test_template_utils.py +++ b/heatclient/tests/unit/test_template_utils.py @@ -15,6 +15,7 @@ import base64 import json from mox3 import mox import six +from six.moves.urllib import error from six.moves.urllib import request import tempfile import testtools @@ -566,6 +567,17 @@ class TestGetTemplateContents(testtools.TestCase): 'Could not fetch template from file://%s' % tmpl_file.name, str(ex)) + def test_get_template_file_nonextant(self): + nonextant_file = '/template/dummy/file/path/and/name.yaml' + ex = self.assertRaises( + error.URLError, + template_utils.get_template_contents, + nonextant_file) + self.assertEqual( + "" + % nonextant_file, + str(ex)) + def test_get_template_contents_file_none(self): ex = self.assertRaises( exc.CommandError,