Merge "Show better error when json fail to parse template"
This commit is contained in:
commit
e9897ff9b9
|
@ -11,7 +11,6 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import httplib2
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import six
|
import six
|
||||||
|
@ -19,6 +18,7 @@ import sys
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
import fixtures
|
import fixtures
|
||||||
|
import httplib2
|
||||||
import tempfile
|
import tempfile
|
||||||
import testscenarios
|
import testscenarios
|
||||||
import testtools
|
import testtools
|
||||||
|
@ -904,6 +904,21 @@ class ShellTestStandaloneToken(ShellTestUserPass):
|
||||||
# The StanaloneMode shouldn't need any keystoneclient stubbing
|
# The StanaloneMode shouldn't need any keystoneclient stubbing
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def test_bad_template_file(self):
|
||||||
|
failed_msg = 'Cannot parse template file:'
|
||||||
|
|
||||||
|
with tempfile.NamedTemporaryFile() as bad_json_file:
|
||||||
|
bad_json_file.write("{foo:}")
|
||||||
|
bad_json_file.flush()
|
||||||
|
self.shell_error("stack-create ts -f %s" % bad_json_file.name,
|
||||||
|
failed_msg)
|
||||||
|
|
||||||
|
with tempfile.NamedTemporaryFile() as bad_json_file:
|
||||||
|
bad_json_file.write('{"foo": None}')
|
||||||
|
bad_json_file.flush()
|
||||||
|
self.shell_error("stack-create ts -f %s" % bad_json_file.name,
|
||||||
|
failed_msg)
|
||||||
|
|
||||||
|
|
||||||
class ShellEnvironmentTest(TestCase):
|
class ShellEnvironmentTest(TestCase):
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,11 @@ def _set_template_fields(hc, args, fields):
|
||||||
if args.template_file:
|
if args.template_file:
|
||||||
tpl = open(args.template_file).read()
|
tpl = open(args.template_file).read()
|
||||||
if tpl.startswith('{'):
|
if tpl.startswith('{'):
|
||||||
fields['template'] = jsonutils.loads(tpl)
|
try:
|
||||||
|
fields['template'] = jsonutils.loads(tpl)
|
||||||
|
except ValueError as e:
|
||||||
|
raise exc.CommandError(
|
||||||
|
"Cannot parse template file: %s" % e)
|
||||||
else:
|
else:
|
||||||
fields['template'] = tpl
|
fields['template'] = tpl
|
||||||
elif args.template_url:
|
elif args.template_url:
|
||||||
|
@ -36,7 +40,11 @@ def _set_template_fields(hc, args, fields):
|
||||||
elif args.template_object:
|
elif args.template_object:
|
||||||
template_body = hc.http_client.raw_request('GET', args.template_object)
|
template_body = hc.http_client.raw_request('GET', args.template_object)
|
||||||
if template_body:
|
if template_body:
|
||||||
fields['template'] = jsonutils.loads(template_body)
|
try:
|
||||||
|
fields['template'] = jsonutils.loads(template_body)
|
||||||
|
except ValueError as e:
|
||||||
|
raise exc.CommandError(
|
||||||
|
"Cannot parse template file: %s" % e)
|
||||||
else:
|
else:
|
||||||
raise exc.CommandError('Could not fetch template from %s'
|
raise exc.CommandError('Could not fetch template from %s'
|
||||||
% args.template_object)
|
% args.template_object)
|
||||||
|
|
Loading…
Reference in New Issue