some bugfixes: ignore tmpfs in disc fill check, set daemon compatibly
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 13 Jan 2016 17:13:42 +0000 (18:13 +0100)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Wed, 13 Jan 2016 17:13:42 +0000 (18:13 +0100)
test_helpers.py

index 3942f0f..77c243e 100644 (file)
@@ -71,8 +71,10 @@ class DiscFillCheckerThread(Thread):
                                  :py:class:`DiscFullPreventionWarning` and
                                  :py:class:`DiscFullPreventionError`
         """
-        super(DiscFillCheckerThread, self).__init__(name='discFillChck',
-                                                    daemon=True)
+        super(DiscFillCheckerThread, self).__init__(name='discFillChck')
+
+        self.daemon = True   # works since python 2.6
+
         # set variables
         self.interval = interval
         if decision_function is None:
@@ -91,6 +93,10 @@ class DiscFillCheckerThread(Thread):
 
         internal helper called from __init__ and run
         """
+        if fs_state.name == 'tmpfs':
+            print('ignoring {0}'.format(fs_state))
+            return []
+
         buf = None
         try:
             buf = self._bufs[fs_state.name]
@@ -107,6 +113,11 @@ class DiscFillCheckerThread(Thread):
             sleep(self.interval)
             fs_states = get_filesystem_fill_states()
             for fs_state in fs_states:
+                # ignore tmpfs since is in memory or swap, so fill up is not
+                # as bad
+                if fs_state.name == 'tmpfs':
+                    continue
+
                 fill_states = self._internal_state_buffer(fs_state)
 
                 # estimate time until full (i.e. when available == 0)
@@ -116,7 +127,7 @@ class DiscFillCheckerThread(Thread):
 
                 # call user-defined function to decide
                 min_time = None
-                if any(times_until_empty > 0):
+                if any(time > 0 for time in times_until_empty):
                     min_time = min(time for time in times_until_empty
                                    if time>0)
                 avg_time = calc_time_until_zero(fill_states[0],
@@ -244,11 +255,14 @@ def pairwise(iterable):
 
 
 @contextlib.contextmanager
-def disc_fill_checked(path):
-    """ run test function while separate thread watches disc space """
+def disc_fill_checked(*args, **kwargs):
+    """ run test function while separate thread watches disc space
+
+    all args are forwarded to :py:class:`DiscFillCheckerThread` constructor
+    """
 
     # todo: add args and forward
-    DiscFillCheckerThread().start()
+    DiscFillCheckerThread(*args, **kwargs).start()
 
     try:
         yield