Merge "Handle empty NetworkConfig"

This commit is contained in:
Zuul 2019-07-02 22:26:55 +00:00 committed by Gerrit Code Review
commit 2ef5685158
2 changed files with 30 additions and 10 deletions

View File

@ -807,3 +807,19 @@ class TestConfig(base.TestCase):
self.config = ooo_config.Config(heat)
self.assertRaises(yaml.scanner.ScannerError,
self.config.validate_config, stack_config, yaml_file)
@patch('tripleo_common.utils.config.Config.get_network_config_data')
def test_render_network_config_empty_dict(self,
mock_get_network_config_data):
heat = mock.MagicMock()
heat.stacks.get.return_value = fakes.create_tht_stack()
config_mock = mock.MagicMock()
config_mock.config = {}
heat.software_configs.get.return_value = config_mock
self.config = ooo_config.Config(heat)
stack = mock.Mock()
server_roles = dict(Controller='controller')
mock_get_network_config_data.return_value = dict(Controller='config')
config_dir = '/tmp/tht'
self.config.render_network_config(stack, config_dir, server_roles)

View File

@ -200,6 +200,19 @@ class Config(object):
"error {}".format(yaml_file, e))
raise e
def render_network_config(self, stack, config_dir, server_roles):
network_config = self.get_network_config_data(stack)
for server, config in network_config.items():
server_deployment_dir = os.path.join(
config_dir, server_roles[server], server)
self._mkdir(server_deployment_dir)
network_config_path = os.path.join(
server_deployment_dir, "NetworkConfig")
s_config = self.client.software_configs.get(config)
if getattr(s_config, 'config', ''):
with open(network_config_path, 'w') as f:
f.write(s_config.config)
def write_config(self, stack, name, config_dir, config_type=None):
# Get role data:
role_data = self.stack_outputs.get('RoleData', {})
@ -505,16 +518,7 @@ class Config(object):
f.write(template_data)
# Render NetworkConfig data
network_config = self.get_network_config_data(stack)
for server, config in network_config.items():
server_deployment_dir = os.path.join(
config_dir, server_roles[server], server)
self._mkdir(server_deployment_dir)
network_config_path = os.path.join(
server_deployment_dir, "NetworkConfig")
s_config = self.client.software_configs.get(config)
with open(network_config_path, 'w') as f:
f.write(s_config.config)
self.render_network_config(stack, config_dir, server_roles)
shutil.copyfile(
os.path.join(templates_path, 'deployments.yaml'),