]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Make cfn-hup configuration handling closer to aws
authorTomas Sedovic <tomas@sedovic.cz>
Tue, 24 Apr 2012 14:41:35 +0000 (16:41 +0200)
committerTomas Sedovic <tomas@sedovic.cz>
Tue, 24 Apr 2012 14:41:35 +0000 (16:41 +0200)
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.

heat/cfntools/cfn-hup
heat/cfntools/cfn_helper.py

index 61e1fb6e6ddde04cb49c4a0e6e979c28cc89d776..2d0c1cbfd29508e7e0af4d29fc15267359ba9431 100755 (executable)
@@ -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
index 51a65be85a17ab947ec50ce0f615dd19dd4a609d..2267646fd9219b4e54965437fd8e4357d2c58086 100644 (file)
@@ -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: