[node-patches] Change in ovirt-node[master]: OInly truncate logfiles upon start

fabiand at fedoraproject.org fabiand at fedoraproject.org
Mon Feb 11 19:39:21 UTC 2013


Fabian Deutsch has uploaded a new change for review.

Change subject: OInly truncate logfiles upon start
......................................................................

OInly truncate logfiles upon start

… and not on reconfiguration.

Change-Id: Ib665b79680e245a5d69f8e5a271d8bfc7586ca85
Signed-off-by: Fabian Deutsch <fabiand at fedoraproject.org>
---
M scripts/tui/src/ovirt/node/app.py
M scripts/tui/src/ovirt/node/utils/__init__.py
M scripts/tui/src/ovirt/node/utils/fs.py
3 files changed, 31 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/42/11942/1

diff --git a/scripts/tui/src/ovirt/node/app.py b/scripts/tui/src/ovirt/node/app.py
index a53cb06..df965c9 100644
--- a/scripts/tui/src/ovirt/node/app.py
+++ b/scripts/tui/src/ovirt/node/app.py
@@ -35,6 +35,9 @@
 """
 
 
+log_filename = "/tmp/ovirt.log"
+debug_log_filename = "/tmp/ovirt.debug.log"
+
 LOGGING = {
     'version': 1,
     'disable_existing_loggers': True,
@@ -52,15 +55,13 @@
             'level': 'INFO',
             'class': 'logging.FileHandler',
             'formatter': 'simple',
-            'filename': '/tmp/ovirt.log',
-            'mode': 'w'
+            'filename': log_filename,
         },
         'debug': {
             'level': 'DEBUG',
             'class': 'logging.FileHandler',
             'formatter': 'verbose',
-            'filename': '/tmp/ovirt.debug.log',
-            'mode': 'w'
+            'filename': debug_log_filename,
         },
         'stderr': {
             'level': 'ERROR',
@@ -80,15 +81,18 @@
     }
 }
 
+utils.fs.truncate(log_filename)
+utils.fs.truncate(debug_log_filename)
+logging.config.dictConfig(LOGGING)
+
 
 def configure_logging():
-    logging.config.dictConfig(LOGGING)
+    logdict = dict(LOGGING)
+    logging.config.dictConfig(logdict)
     #logging.basicConfig(level=logging.DEBUG,
     #                    filename="/tmp/app.log", filemode="w",
     #                    format="%(asctime)s %(levelname)s %(name)s " +
 #                               "%(message)s")
-
-configure_logging()
 
 
 class Application(base.Base):
diff --git a/scripts/tui/src/ovirt/node/utils/__init__.py b/scripts/tui/src/ovirt/node/utils/__init__.py
index 7603c09..cb33ac7 100644
--- a/scripts/tui/src/ovirt/node/utils/__init__.py
+++ b/scripts/tui/src/ovirt/node/utils/__init__.py
@@ -289,6 +289,10 @@
         def __repr__(self):
             return "<%s '%s'>" % (self.__class__.__name__, self.title)
 
+        def __call__(self):
+            self.prepare()
+            self.commit()
+
 
 class Timer(base.Base):
     started = 0
diff --git a/scripts/tui/src/ovirt/node/utils/fs.py b/scripts/tui/src/ovirt/node/utils/fs.py
index 8dcbbaf..875bfde 100644
--- a/scripts/tui/src/ovirt/node/utils/fs.py
+++ b/scripts/tui/src/ovirt/node/utils/fs.py
@@ -69,6 +69,13 @@
         raise e
 
 
+def truncate(filename):
+    """Truncate the given file to the length 0
+    """
+    with open(filename, "wb"):
+        pass
+
+
 class BackupedFiles(base.Base):
     """This context manager can be used to keep backup of files while messing
     with them.
@@ -175,21 +182,29 @@
 
 
 class Config(base.Base):
+    """oVirt Node specififc way to persist files
+    """
     basedir = "/config"
 
     def _config_path(self, fn=""):
         return os.path.join(self.basedir, fn.strip("/"))
 
     def persist(self, filename):
+        """Persist a file and bind mount it
+        """
         from ovirtnode import ovirtfunctions
         return ovirtfunctions.ovirt_store_config(filename)
 
     def unpersist(self, filename):
+        """Remove the persistent version of a file and remove the bind mount
+        """
         from ovirtnode import ovirtfunctions
         return ovirtfunctions.remove_config(filename)
 
     def exists(self, filename):
-        return os.path.exists(self._config_path(filename))
+        """Check if the given file is persisted
+        """
+        return filename and os.path.exists(self._config_path(filename))
 
     def is_enabled(self):
         return is_bind_mount(self.basedir)


--
To view, visit http://gerrit.ovirt.org/11942
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib665b79680e245a5d69f8e5a271d8bfc7586ca85
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>



More information about the node-patches mailing list