From 3961e3b32bc8c2f6760ca89da34d8ab3bf5e29b5 Mon Sep 17 00:00:00 2001 From: Dan Prince Date: Fri, 27 Jan 2017 09:10:46 -0500 Subject: [PATCH] Add a check for legacy hiera element data The new heat 'hiera' hook is incompatible with the old tripleo-puppet-elements hiera element. The two formats should not coexist as they will overwrite each others config files (last hook to run would win). To make the end user experience nice we add an explicit check here. Note: this would require us to clean out old apply-config data from a prior run during an upgrade to make sure the check doesn't mistakenly prevent a new deployment from failing. Change-Id: I326a2816b6c47b2ba00c33a42ce6e452c5a74dce --- heat-config-hiera/install.d/hook-hiera.py | 32 +++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/heat-config-hiera/install.d/hook-hiera.py b/heat-config-hiera/install.d/hook-hiera.py index 077559b..adc6aba 100755 --- a/heat-config-hiera/install.d/hook-hiera.py +++ b/heat-config-hiera/install.d/hook-hiera.py @@ -15,12 +15,18 @@ import json import logging import os +import subprocess import sys HIERA_DATADIR = os.environ.get('HEAT_PUPPET_HIERA_DATADIR', '/etc/puppet/hieradata') HIERA_CONFIG = os.environ.get('HEAT_HIERA_CONFIG', '/etc/puppet/hiera.yaml') +HIERA_ELEMENT_CHECK_CMD = os.environ.get('HEAT_HIERA_ELEMENT_CHECK_CMD', + 'os-apply-config ' + '--key hiera.datafiles ' + '--type raw --key-default empty') + HIERA_CONFIG_BASE = """ --- @@ -37,6 +43,31 @@ def prepare_dir(path): os.makedirs(path, 0o700) +def exit_legacy_hiera_detected(): + try: + subproc = subprocess.Popen(HIERA_ELEMENT_CHECK_CMD.split(" "), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + stdout, stderr = subproc.communicate() + if stdout.rstrip() != 'empty': + err_msg = ('Legacy hieradata from os-apply-config has been ' + 'detected. Please update all of your interfaces ' + 'to use the new heat-agents hiera hook before ' + 'proceeding') + response = { + 'deploy_stdout': stdout, + 'deploy_stderr': err_msg, + 'deploy_status_code': 1, + } + + json.dump(response, sys.stdout) + sys.exit(0) + + except OSError: + # os-apply-config is not installed? Assume there is no legacy data. + pass + + def main(argv=sys.argv): log = logging.getLogger('heat-config') handler = logging.StreamHandler(sys.stderr) @@ -47,6 +78,7 @@ def main(argv=sys.argv): log.setLevel('DEBUG') c = json.load(sys.stdin)['config'] + exit_legacy_hiera_detected() prepare_dir(HIERA_DATADIR)