From f5d4721e5ff9ef1ff1bffec79ea8e024275d6798 Mon Sep 17 00:00:00 2001
From: Paul Breaux
Date: Sun, 1 May 2016 21:46:27 -0600
Subject: [PATCH] Fix obscure error message when no template given to OSC
This is an internal-only fix, as it does not change any external APIs. A
bit of obfuscation was occurring in the
'template_utils.process_template_path' function call. First we try to
retrieve the template from a urllib call. If that fails, then we try to
make a request with the custom request_object function. If the
request_object function failed to retrieve the template as well, it
would report back 'ERROR: None'. I left both of the calls in this
function, but I made the first exception bubble up back to the caller,
since it is more helpful to the user.
The new error message should report back the following when a template
cannot be found:
Closed Bug: #1570229
Change-Id: I29e19172322c18559aa476744f7ff3530e689bd0
---
heatclient/common/template_utils.py | 21 +++++++++++++++-----
heatclient/tests/unit/test_template_utils.py | 12 +++++++++++
2 files changed, 28 insertions(+), 5 deletions(-)
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,