]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Better error messages for cfn-hup configuration
authorTomas Sedovic <tomas@sedovic.cz>
Tue, 24 Apr 2012 12:56:15 +0000 (14:56 +0200)
committerTomas Sedovic <tomas@sedovic.cz>
Tue, 24 Apr 2012 12:56:15 +0000 (14:56 +0200)
heat/cfntools/cfn-hup

index 978f8fa5640b2997e97900b9ee780b80f4882442..61e1fb6e6ddde04cb49c4a0e6e979c28cc89d776 100755 (executable)
@@ -53,18 +53,22 @@ if args.verbose:
 else:
     logging.basicConfig(format=log_format, level=logging.INFO)
 
-config_files = []
+main_conf_path = '/etc/cfn/cfn-hup.conf'
 try:
-    config_files.append(open('/etc/cfn/cfn-hup.conf'))
+    main_config_file = open(main_conf_path)
 except IOError as exc:
-    logging.exception(exc)
+    logging.error('Could not open main configuration at %s' % main_conf_path)
+    exit(1)
 
-try:
-    config_files.append(open('/etc/cfn/hooks.conf'))
-except IOError as exc:
-    logging.exception(exc)
+config_files = []
+hooks_conf_path = '/etc/cfn/hooks.conf'
+if os.path.exists(hooks_conf_path):
+    try:
+        config_files.append(open(hooks_conf_path))
+    except IOError as exc:
+        logging.exception(exc)
 
-if args.config_dir:
+if args.config_dir and os.path.exists(args.config_dir):
     try:
         for f in os.listdir(args.config_dir):
             config_files.append(open(os.path.join(args.config_dir, f)))
@@ -72,7 +76,12 @@ if args.config_dir:
     except OSError as exc:
         logging.exception(exc)
 
-mainconfig = HupConfig(config_files)
+if not config_files:
+    logging.error('No hooks found at %s or %s' % (hooks_conf_path,
+                                                  args.config_dir))
+    exit(1)
+
+mainconfig = HupConfig([main_config_file] + config_files)
 
 for r in mainconfig.unique_resources_get():
     print r