From 4d88b1f77a3b6de5ba10960879eeb9ce50442804 Mon Sep 17 00:00:00 2001 From: Drew Kerrigan Date: Wed, 25 Apr 2018 15:08:09 -0400 Subject: [PATCH] Address bug in config validation for invalid labels (#576) --- marathon_lb.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/marathon_lb.py b/marathon_lb.py index 8cede64f..b5f072ae 100755 --- a/marathon_lb.py +++ b/marathon_lb.py @@ -1240,6 +1240,10 @@ def writeConfigAndValidate( moveTempFile(haproxyTempConfigFile, config_file, "hap_cfg") return True else: + moveTempFile(haproxyTempConfigFile, 'haproxy_tmp_conf_fail', + 'haproxy_temp_config_fail') + removeTempFileIfExist(domain_temp_map_file) + removeTempFileIfExist(app_temp_map_file) return False @@ -1305,6 +1309,12 @@ def truncateMapFileIfExists(map_file): os.close(fd) +def removeTempFileIfExist(temp_file): + if os.path.isfile(temp_file): + logger.debug("delete tempfile %s", temp_file) + os.remove(temp_file) + + def generateAndValidateTempConfig(config, config_file, domain_map_array, app_map_array, haproxy_map): temp_config_file = "%s.tmp" % config_file @@ -1720,13 +1730,12 @@ def make_config_valid_and_regenerate(marathon, generated_config = config(apps, groups, bind_http_https, ssl_certs, templater, haproxy_map, domain_map_array, app_map_array, - config_file) + config_file, group_https_by_vhost) config_valid = generateAndValidateTempConfig(generated_config, config_file, domain_map_array, app_map_array, - haproxy_map, - group_https_by_vhost) + haproxy_map) if not config_valid: logger.warn( "invalid configuration caused by app %s; " @@ -1745,7 +1754,7 @@ def make_config_valid_and_regenerate(marathon, valid_config = config(apps, groups, bind_http_https, ssl_certs, templater, haproxy_map, domain_map_array, app_map_array, - config_file) + config_file, group_https_by_vhost) compareWriteAndReloadConfig(valid_config, config_file, domain_map_array,