Merge "Fix obscure error message when no template given to OSC"
This commit is contained in:
@@ -31,15 +31,26 @@ def process_template_path(template_path, object_request=None, existing=False):
|
|||||||
"""Read template from template path.
|
"""Read template from template path.
|
||||||
|
|
||||||
Attempt to read template first as a file or url. If that is unsuccessful,
|
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:
|
try:
|
||||||
return get_template_contents(template_file=template_path,
|
return get_template_contents(template_file=template_path,
|
||||||
existing=existing)
|
existing=existing)
|
||||||
except error.URLError:
|
except error.URLError as template_file_exc:
|
||||||
return get_template_contents(template_object=template_path,
|
try:
|
||||||
object_request=object_request,
|
return get_template_contents(template_object=template_path,
|
||||||
existing=existing)
|
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,
|
def get_template_contents(template_file=None, template_url=None,
|
||||||
|
@@ -15,6 +15,7 @@ import base64
|
|||||||
import json
|
import json
|
||||||
from mox3 import mox
|
from mox3 import mox
|
||||||
import six
|
import six
|
||||||
|
from six.moves.urllib import error
|
||||||
from six.moves.urllib import request
|
from six.moves.urllib import request
|
||||||
import tempfile
|
import tempfile
|
||||||
import testtools
|
import testtools
|
||||||
@@ -567,6 +568,17 @@ class TestGetTemplateContents(testtools.TestCase):
|
|||||||
'Could not fetch template from file://%s' % tmpl_file.name,
|
'Could not fetch template from file://%s' % tmpl_file.name,
|
||||||
str(ex))
|
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(
|
||||||
|
"<urlopen error [Errno 2] No such file or directory: '%s'>"
|
||||||
|
% nonextant_file,
|
||||||
|
str(ex))
|
||||||
|
|
||||||
def test_get_template_contents_file_none(self):
|
def test_get_template_contents_file_none(self):
|
||||||
ex = self.assertRaises(
|
ex = self.assertRaises(
|
||||||
exc.CommandError,
|
exc.CommandError,
|
||||||
|
Reference in New Issue
Block a user