From 8aef24de810b17cb65bed2aaf0884531a0f99027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Andr=C3=A9?= Date: Mon, 9 Oct 2017 18:04:31 +0100 Subject: [PATCH] Take all mounted config_volumes into account We need to account for all the mounted config volumes when generating the TRIPLEO_CONFIG_HASH in order for paunch to know to restart the container when any one of the config_volume gets updated. Change-Id: I473a71f49bd446694da48bb5b7b0a49126df7845 Closes-Bug: #1721306 --- docker/docker-puppet.py | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/docker/docker-puppet.py b/docker/docker-puppet.py index 5716b1e2fe..2bf9ca5bbb 100755 --- a/docker/docker-puppet.py +++ b/docker/docker-puppet.py @@ -83,16 +83,12 @@ def pull_image(name): log.debug(cmd_stderr) -def match_config_volume(prefix, config): - # Match the mounted config volume - we can't just use the +def match_config_volumes(prefix, config): + # Match the mounted config volumes - we can't just use the # key as e.g "novacomute" consumes config-data/nova volumes = config.get('volumes', []) - config_volume = None - for v in volumes: - if v.startswith(prefix): - config_volume = os.path.dirname(v.split(":")[0]) - break - return config_volume + return sorted([os.path.dirname(v.split(":")[0]) for v in volumes if + v.startswith(prefix)]) def get_config_hash(config_volume): @@ -371,14 +367,15 @@ for infile in infiles: infile_data = json.load(f) for k, v in infile_data.iteritems(): - config_volume = match_config_volume(config_volume_prefix, v) - if config_volume: - config_hash = get_config_hash(config_volume) - if config_hash: - env = v.get('environment', []) - env.append("TRIPLEO_CONFIG_HASH=%s" % config_hash) - log.debug("Updating config hash for %s, config_volume=%s hash=%s" % (k, config_volume, config_hash)) - infile_data[k]['environment'] = env + config_volumes = match_config_volumes(config_volume_prefix, v) + config_hashes = [get_config_hash(volume_path) for volume_path in config_volumes] + config_hashes = filter(None, config_hashes) + config_hash = '-'.join(config_hashes) + if config_hash: + env = v.get('environment', []) + env.append("TRIPLEO_CONFIG_HASH=%s" % config_hash) + log.debug("Updating config hash for %s, config_volume=%s hash=%s" % (k, config_volume, config_hash)) + infile_data[k]['environment'] = env outfile = os.path.join(os.path.dirname(infile), "hashed-" + os.path.basename(infile)) with open(outfile, 'w') as out_f: