Check for empty sections in environment
Passing empty section like parameters in the environment can leave the user with a strange error message. This fixes the issue by providing a correct error. Change-Id: I766cd38e8a70c9f76cf10f540e22a929eaed3768 Closes-Bug: #1606148
This commit is contained in:
parent
7538c6d888
commit
9a248ad6c5
@ -138,10 +138,10 @@ class InstantiationData(object):
|
|||||||
env = {}
|
env = {}
|
||||||
if self.PARAM_ENVIRONMENT in self.data:
|
if self.PARAM_ENVIRONMENT in self.data:
|
||||||
env_data = self.data[self.PARAM_ENVIRONMENT]
|
env_data = self.data[self.PARAM_ENVIRONMENT]
|
||||||
if isinstance(env_data, dict):
|
|
||||||
env = env_data
|
|
||||||
else:
|
|
||||||
with self.parse_error_check('Environment'):
|
with self.parse_error_check('Environment'):
|
||||||
|
if isinstance(env_data, dict):
|
||||||
|
env = environment_format.validate(env_data)
|
||||||
|
else:
|
||||||
env = environment_format.parse(env_data)
|
env = environment_format.parse(env_data)
|
||||||
|
|
||||||
environment_format.default_for_missing(env)
|
environment_format.default_for_missing(env)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
# not use this file except in compliance with the License. You may obtain
|
# not use this file except in compliance with the License. You may obtain
|
||||||
# a copy of the License at
|
# a copy of the License at
|
||||||
@ -48,9 +47,15 @@ def parse(env_str):
|
|||||||
if not isinstance(env, dict):
|
if not isinstance(env, dict):
|
||||||
raise ValueError(_('The environment is not a valid '
|
raise ValueError(_('The environment is not a valid '
|
||||||
'YAML mapping data type.'))
|
'YAML mapping data type.'))
|
||||||
|
return validate(env)
|
||||||
|
|
||||||
|
|
||||||
|
def validate(env):
|
||||||
for param in env:
|
for param in env:
|
||||||
if param not in SECTIONS:
|
if param not in SECTIONS:
|
||||||
raise ValueError(_('environment has wrong section "%s"') % param)
|
raise ValueError(_('environment has wrong section "%s"') % param)
|
||||||
|
if env[param] is None:
|
||||||
|
raise ValueError(_('environment has empty section "%s"') % param)
|
||||||
|
|
||||||
return env
|
return env
|
||||||
|
|
||||||
|
@ -195,6 +195,12 @@ blarg: wibble
|
|||||||
data = stacks.InstantiationData(body)
|
data = stacks.InstantiationData(body)
|
||||||
self.assertEqual(expect, data.environment())
|
self.assertEqual(expect, data.environment())
|
||||||
|
|
||||||
|
def test_environment_empty_params(self):
|
||||||
|
env = {'parameters': None}
|
||||||
|
body = {'environment': env}
|
||||||
|
data = stacks.InstantiationData(body)
|
||||||
|
self.assertRaises(webob.exc.HTTPBadRequest, data.environment)
|
||||||
|
|
||||||
def test_environment_bad_format(self):
|
def test_environment_bad_format(self):
|
||||||
env = {'somethingnotsupported': {'blarg': 'wibble'}}
|
env = {'somethingnotsupported': {'blarg': 'wibble'}}
|
||||||
body = {'environment': json.dumps(env)}
|
body = {'environment': json.dumps(env)}
|
||||||
|
Loading…
Reference in New Issue
Block a user