From: Tomas Sedovic Date: Tue, 24 Apr 2012 14:41:35 +0000 (+0200) Subject: Make cfn-hup configuration handling closer to aws X-Git-Tag: 2014.1~1923^2~14 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=9b23e2dc355e9a6e4d7a1cd1dbd2bc89ff9c8ba1;p=openstack-build%2Fheat-build.git Make cfn-hup configuration handling closer to aws We now enforce the presence of the [main] configuration section, check that the credentials file exists and ensure that there is at least one hook defined. --- diff --git a/heat/cfntools/cfn-hup b/heat/cfntools/cfn-hup index 61e1fb6e..2d0c1cbf 100755 --- a/heat/cfntools/cfn-hup +++ b/heat/cfntools/cfn-hup @@ -77,11 +77,20 @@ if args.config_dir and os.path.exists(args.config_dir): logging.exception(exc) if not config_files: - logging.error('No hooks found at %s or %s' % (hooks_conf_path, - args.config_dir)) + logging.error('No hook files found at %s or %s' % (hooks_conf_path, + args.config_dir)) exit(1) -mainconfig = HupConfig([main_config_file] + config_files) +try: + mainconfig = HupConfig([main_config_file] + config_files) +except Exception as ex: + logging.error('Cannot load configuration: %s' % str(ex)) + exit(1) + +if not mainconfig.unique_resources_get(): + logging.error('No hooks were found. Add some to %s or %s' % (hooks_conf_path, + args.config_dir)) + exit(1) for r in mainconfig.unique_resources_get(): print r diff --git a/heat/cfntools/cfn_helper.py b/heat/cfntools/cfn_helper.py index 51a65be8..2267646f 100644 --- a/heat/cfntools/cfn_helper.py +++ b/heat/cfntools/cfn_helper.py @@ -50,21 +50,27 @@ class HupConfig(object): for fp in fp_list: self.config.readfp(fp) + self.load_main_section() + self.hooks = {} for s in self.config.sections(): - if s == 'main': - self.get_main_section() - else: + if s != 'main': self.hooks[s] = Hook(s, self.config.get(s, 'triggers'), self.config.get(s, 'path'), self.config.get(s, 'runas'), self.config.get(s, 'action')) - def get_main_section(self): + def load_main_section(self): # required values self.stack = self.config.get('main', 'stack') self.credential_file = self.config.get('main', 'credential-file') + try: + with open(self.credential_file) as f: + self.credentials = f.read() + except: + raise Exception("invalid credentials file %s" % + self.credential_file) # optional values try: