Browse Source

[trac759] replace prints with logger messages

Jelte Jansen 14 years ago
parent
commit
91bab51181

+ 4 - 4
src/bin/cfgmgr/b10-cfgmgr.py.in

@@ -28,6 +28,7 @@ import os.path
 import isc.log
 import isc.log
 isc.log.init("b10-cfgmgr")
 isc.log.init("b10-cfgmgr")
 from isc.config.cfgmgr import ConfigManager, ConfigManagerDataReadError, logger
 from isc.config.cfgmgr import ConfigManager, ConfigManagerDataReadError, logger
+from isc.config.cfgmgr_messages import *
 
 
 isc.util.process.rename()
 isc.util.process.rename()
 
 
@@ -93,13 +94,12 @@ def main():
         cm.notify_boss()
         cm.notify_boss()
         cm.run()
         cm.run()
     except SessionError as se:
     except SessionError as se:
-        print("[b10-cfgmgr] Error creating config manager, "
-              "is the command channel daemon running?")
+        logger.error(CFGMGR_CC_SESSION_ERROR, str(se))
         return 1
         return 1
     except KeyboardInterrupt as kie:
     except KeyboardInterrupt as kie:
-        print("[b10-cfgmgr] Interrupted, exiting")
+        logger.info(CFGMGR_STOPPED_BY_KEYBOARD)
     except ConfigManagerDataReadError as cmdre:
     except ConfigManagerDataReadError as cmdre:
-        print("[b10-cfgmgr] " + str(cmdre))
+        logger.error(CFGMGR_DATA_READ_ERROR, str(cmdre))
         return 2
         return 2
     return 0
     return 0
 
 

+ 4 - 8
src/lib/python/isc/config/cfgmgr.py

@@ -32,6 +32,7 @@ from isc.config import ccsession, config_data, module_spec
 from isc.util.file import path_search
 from isc.util.file import path_search
 import bind10_config
 import bind10_config
 import isc.log
 import isc.log
+from isc.config.cfgmgr_messages import *
 
 
 logger = isc.log.Logger("cfgmgr")
 logger = isc.log.Logger("cfgmgr")
 
 
@@ -94,7 +95,7 @@ class ConfigManagerData:
                 elif file_config['version'] == 1:
                 elif file_config['version'] == 1:
                     # only format change, no other changes necessary
                     # only format change, no other changes necessary
                     file_config['version'] = 2
                     file_config['version'] = 2
-                    print("[b10-cfgmgr] Updating configuration database version from 1 to 2")
+                    logger.info(CFGMGR_AUTOMATIC_CONFIG_DATABASE_UPDATE, 1, 2)
                     config.data = file_config
                     config.data = file_config
                 else:
                 else:
                     if config_data.BIND10_CONFIG_DATA_VERSION > file_config['version']:
                     if config_data.BIND10_CONFIG_DATA_VERSION > file_config['version']:
@@ -136,12 +137,9 @@ class ConfigManagerData:
             else:
             else:
                 os.rename(filename, self.db_filename)
                 os.rename(filename, self.db_filename)
         except IOError as ioe:
         except IOError as ioe:
-            # TODO: log this (level critical)
-            print("[b10-cfgmgr] Unable to write configuration file; configuration not stored: " + str(ioe))
-            # TODO: debug option to keep file?
+            logger.error(CFGMGR_IOERROR_WHILE_WRITING_CONFIGURATION, str(ioe))
         except OSError as ose:
         except OSError as ose:
-            # TODO: log this (level critical)
-            print("[b10-cfgmgr] Unable to write configuration file; configuration not stored: " + str(ose))
+            logger.error(CFGMGR_OSERROR_WHILE_WRITING_CONFIGURATION, str(ose))
         try:
         try:
             if filename and os.path.exists(filename):
             if filename and os.path.exists(filename):
                 os.remove(filename)
                 os.remove(filename)
@@ -463,8 +461,6 @@ class ConfigManager:
             elif cmd == ccsession.COMMAND_SET_CONFIG:
             elif cmd == ccsession.COMMAND_SET_CONFIG:
                 answer = self._handle_set_config(arg)
                 answer = self._handle_set_config(arg)
             elif cmd == ccsession.COMMAND_SHUTDOWN:
             elif cmd == ccsession.COMMAND_SHUTDOWN:
-                # TODO: logging
-                #print("[b10-cfgmgr] Received shutdown command")
                 self.running = False
                 self.running = False
                 answer = ccsession.create_answer(0)
                 answer = ccsession.create_answer(0)
             elif cmd == ccsession.COMMAND_MODULE_SPEC:
             elif cmd == ccsession.COMMAND_MODULE_SPEC:

+ 33 - 0
src/lib/python/isc/config/cfgmgr_messages.mes

@@ -15,3 +15,36 @@
 # No namespace declaration - these constants go in the global namespace
 # No namespace declaration - these constants go in the global namespace
 # of the xfrin messages python module.
 # of the xfrin messages python module.
 
 
+% CFGMGR_AUTOMATIC_CONFIG_DATABASE_UPDATE Updating configuration database from version %1 to %2
+An older version of the configuration database has been found, from which
+there was an automatic upgrade path to the current version. These changes
+are now applied, and no action from the administrator is necessary.
+
+% CFGMGR_CC_SESSION_ERROR Error connecting to command channel: %1
+The configuration manager daemon was unable to connect to the messaging
+system. The most likely cause is that msgq is not running.
+
+% CFGMGR_DATA_READ_ERROR error reading configuration database from disk: %1
+There was a problem reading the persistent configuration data as stored
+on disk. The file may be corrupted, or it is of a version from where
+there is no automatic upgrade path. The file needs to be repaired or
+removed. The configuration manager daemon will now shut down.
+
+% CFGMGR_IOERROR_WHILE_WRITING_CONFIGURATION Unable to write configuration file; configuration not stored: %1
+There was an IO error from the system while the configuration manager
+was trying to write the configuration database to disk. The specific
+error is given. The most likely cause is that the directory where
+the file is stored does not exist, or is not writable. The updated
+configuration is not stored.
+
+% CFGMGR_OSERROR_WHILE_WRITING_CONFIGURATION Unable to write configuration file; configuration not stored: %1
+There was an OS error from the system while the configuration manager
+was trying to write the configuration database to disk. The specific
+error is given. The most likely cause is that the system does not have
+write access to the configuration database file. The updated
+configuration is not stored.
+
+% CFGMGR_STOPPED_BY_KEYBOARD keyboard interrupt, shutting down
+There was a keyboard interrupt signal to stop the cfgmgr daemon. The
+daemon will now shut down.
+