Browse Source

specify too new/too old in wrong config data error (even though too old *should* not occur)
also removed the nested try statement


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac294@2615 e5f2f494-b856-4b98-b285-d166d9295462

Jelte Jansen 15 years ago
parent
commit
8773382cbc
1 changed files with 25 additions and 20 deletions
  1. 25 20
      src/lib/python/isc/config/cfgmgr.py

+ 25 - 20
src/lib/python/isc/config/cfgmgr.py

@@ -63,31 +63,36 @@ class ConfigManagerData:
            the second exception, the best way is probably to report the
            the second exception, the best way is probably to report the
            error and stop loading the system."""
            error and stop loading the system."""
         config = ConfigManagerData(data_path, file_name)
         config = ConfigManagerData(data_path, file_name)
+        file = None
         try:
         try:
             file = open(config.db_filename, 'r')
             file = open(config.db_filename, 'r')
-            try:
+            file_config = json.loads(file.read())
-                file_config = json.loads(file.read())
+            # handle different versions here
-                # handle different versions here
+            # If possible, we automatically convert to the new
-                # 
+            # scheme and update the configuration
-                if 'version' in file_config:
+            # If not, we raise an exception
-                    if file_config['version'] == config_data.BIND10_CONFIG_DATA_VERSION:
+            if 'version' in file_config:
-                        config.data = file_config
+                if file_config['version'] == config_data.BIND10_CONFIG_DATA_VERSION:
-                    elif file_config['version'] == 1:
+                    config.data = file_config
-                        # only format change, no other changes necessary
+                elif file_config['version'] == 1:
-                        file_config['version'] = 2
+                    # only format change, no other changes necessary
-                        print("[b10-cfgmgr] Updating configuration database version from 1 to 2")
+                    file_config['version'] = 2
-                        config.data = file_config
+                    print("[b10-cfgmgr] Updating configuration database version from 1 to 2")
-                    else:
+                    config.data = file_config
-                        # We can put in a migration path here for old data
-                        raise ConfigManagerDataReadError("Old version of data found")
                 else:
                 else:
-                    raise ConfigManagerDataReadError("No version information in configuration file " + config.db_filename)
+                    if config_data.BIND10_CONFIG_DATA_VERSION > file_config['version']:
-            except:
+                        raise ConfigManagerDataReadError("Version of config data too old")
-                raise ConfigManagerDataReadError("Config file out of date or corrupt, please update or remove " + config.db_filename)
+                    else:
-            finally:
+                        raise ConfigManagerDataReadError("Version of config data too new")
-                file.close();
+            else:
+                raise ConfigManagerDataReadError("No version information in configuration file " + config.db_filename)
         except IOError as ioe:
         except IOError as ioe:
             raise ConfigManagerDataEmpty("No config file found")
             raise ConfigManagerDataEmpty("No config file found")
+        except:
+            raise ConfigManagerDataReadError("Config file out of date or corrupt, please update or remove " + config.db_filename)
+        finally:
+            if file:
+                file.close();
         return config
         return config
         
         
     def write_to_file(self, output_file_name = None):
     def write_to_file(self, output_file_name = None):