From 7530b165137df4470f304f72d5d831e8a0ca7ad1 Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Wed, 29 Jan 2014 13:58:13 +0000 Subject: [PATCH] API tolerate None environment string If an API request has a None environment argument, we should not reject the request, but treat it the same as an empty environment. Change-Id: I812f308ef38833e89dfa2ce01263a297032f563a Closes-Bug: #1273993 --- heat/common/environment_format.py | 5 +++-- heat/tests/test_environment_format.py | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/heat/common/environment_format.py b/heat/common/environment_format.py index 694aa0f8e6..4a69b8d9ec 100644 --- a/heat/common/environment_format.py +++ b/heat/common/environment_format.py @@ -24,9 +24,10 @@ SECTIONS = (PARAMETERS, RESOURCE_REGISTRY) = \ def parse(env_str): ''' Takes a string and returns a dict containing the parsed structure. - This includes determination of whether the string is using the - JSON or YAML format. ''' + if env_str is None: + return {} + try: env = yaml.load(env_str, Loader=yaml_loader) except yaml.YAMLError as yea: diff --git a/heat/tests/test_environment_format.py b/heat/tests/test_environment_format.py index ef8c1b55f5..ec5a1e5eb7 100644 --- a/heat/tests/test_environment_format.py +++ b/heat/tests/test_environment_format.py @@ -45,6 +45,9 @@ parameters: } ''' self.assertRaises(ValueError, environment_format.parse, env) + def test_yaml_none(self): + self.assertEqual({}, environment_format.parse(None)) + class YamlParseExceptions(common.HeatTestCase):