Handle None value for RoleConfig

RoleConfig can exist as a stack output, but have a value of None. That
case should be handled with a default value of {} where the value was
previously None.

Change-Id: I3caf31c00ab8c47d71a68eb82114fb398a47961b
Closes-Bug: #1748482
This commit is contained in:
James Slagle 2018-02-09 11:56:04 -05:00
parent 68256052d7
commit d384f4ecb6
3 changed files with 18 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
fixes:
- RoleConfig can exist as a stack output, but have a value of None. That case
is now handled with a default value of {} where the value was previously
None.

View File

@ -170,6 +170,13 @@ class TestConfig(base.TestCase):
expected = {'2af0a373': 'c1', '8269f736': 'c0', 'c8479674': 'c2'}
self.assertEqual(expected, server_names)
def test_get_role_config(self):
heat = mock.MagicMock()
self.config = ooo_config.Config(heat)
self.config.stack_outputs = {'RoleConfig': None}
role_config = self.config.get_role_config()
self.assertEqual({}, role_config)
def test_get_deployment_data(self):
heat = mock.MagicMock()
self.config = ooo_config.Config(heat)

View File

@ -95,6 +95,11 @@ class Config(object):
env.trim_blocks = True
return env, templates_path
def get_role_config(self):
role_config = self.stack_outputs.get('RoleConfig', {})
# RoleConfig can exist as a stack output but have a value of None
return role_config or {}
@staticmethod
def _open_file(path):
return os.fdopen(os.open(path,
@ -180,7 +185,7 @@ class Config(object):
yaml.safe_dump(data,
conf_file,
default_flow_style=False)
role_config = self.stack_outputs.get('RoleConfig', {})
role_config = self.get_role_config()
for config_name, config in six.iteritems(role_config):
conf_path = os.path.join(tmp_path, config_name + ".yaml")
with self._open_file(conf_path) as conf_file: