[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[minion-cvs] Pinger starts without crashing



Update of /home/minion/cvsroot/src/minion/lib/mixminion/server
In directory moria.mit.edu:/tmp/cvs-serv25669/lib/mixminion/server

Modified Files:
	Pinger.py 
Log Message:
Pinger starts without crashing

Index: Pinger.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/Pinger.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- Pinger.py	27 Jul 2004 23:33:18 -0000	1.3
+++ Pinger.py	28 Jul 2004 00:04:06 -0000	1.4
@@ -21,7 +21,9 @@
 import cPickle
 import os
 import re
+import string
 import struct
+import sys
 import threading
 import time
 
@@ -227,8 +229,9 @@
         pend = pr.pendingPings
         pr.pendingPings=None
         # separate these for space savings.
-        writePickled(fname+".pend.gz",pend,gzipped=1)
-        writePickled(fname+".stat.gz",pr,gzipped=1)
+        writePickled(os.path.join(fname+".pend.gz"),
+                     pend,gzipped=1)
+        writePickled(os.path.join(fname+".stat.gz"),pr,gzipped=1)
 
     def _rescanImpl(self):
         # hold lock; restore pingStatus.
@@ -266,6 +269,7 @@
 
     def _loadPingStatus(self):
         # lock is held if any refs to objects are held.
+        LOG.info("Loading ping status from disk")
         dateSet = {}
         for fn in os.listdir(self.location):
             date, tp = self._parseFname(fn)
@@ -278,12 +282,14 @@
         lastStat = None
         for d in dates:
             l,s=dateSet[d].get('log'), dateSet[d].get('stat')
-            if not l or l == self.fname:
+            if not l or os.path.join(self.location,l) == self.fname:
                 continue
-            if not s:
+            if not s and not rescan:
+                LOG.info("Ping-log file %s without ping-stats file; rescanning.", l)
                 rescan = 1
             lastStat = d
         if lastStat and not dateSet[lastStat].has_key('pend'):
+            LOG.info("No pending-pings file to match last ping-stats file; rescanning.")
             rescan = 1
 
         if rescan:
@@ -305,7 +311,7 @@
             else:
                 rescan = self._loadPingStatusImpl(None,None,self.fname)
         except (cPickle.UnpicklingError, OSError, ValueError):
-            rescan = 1
+            LOG.error_exc(sys.exc_info(), "Error while loading ping status")
 
         if rescan:
             #XXXX duplicate code.
@@ -328,7 +334,7 @@
             date, tp = self._parseFname(fn)
             if tp != 'stat': continue
             if date < cutoff: continue
-            if fn == self.fname: continue
+            if os.path.join(self.location,fn) == self.fname: continue
             stats.append((date,
                        readPickled(os.path.join(self.location,fn),gzipped=1)))
         stats.sort()
@@ -378,9 +384,10 @@
             continue
         gr = m.groups()
         # parse time, event; make sure right # of args.
-        tm = calendar.timegm(*gr[:6])
+        tm = calendar.timegm(map(string.atoi, gr[:6]))
         event = tuple(gr[6].split())
         if _EVENT_ARGS.get(event[0]) != len(event)-1:
+            # warn unknown, warn bad n args
             continue
         func(tm, event)
 
@@ -527,7 +534,7 @@
                 m[nickname] = liveAt-tLast
 
         if self.lastUpdated is not None and self.lastUpdated < liveAt:
-            self.liveness += liveAt-self.last
+            self.liveness += liveAt-self.lastUpdated
 
         self.lastUpdated = liveAt
 
@@ -721,11 +728,11 @@
         self.pingLog = pingLog
         self.keyring = keyring
     def scheduleAllPings(self, now=None):
-        raise NotImplemented()
+        raise NotImplemented
     def _getPeriodStart(self, t):
-        raise NotImplemented()
+        raise NotImplemented
     def _getPingInterval(self, path):
-        raise NotImplemented()
+        raise NotImplemented
     def _schedulePing(self,path,now=None):
         if now is None: now = time.time()
         periodStart = self._getPeriodStart(now)
@@ -751,7 +758,7 @@
         else:
             return None
 
-class OneHopPingGenerator(PingGenerator,_PingScheduler):
+class OneHopPingGenerator(_PingScheduler,PingGenerator):
     """DOCDOC"""
     #XXXX008 make this configurable, but not less than 2 hours.
     PING_INTERVAL = 2*60*60
@@ -772,7 +779,7 @@
     def _getPeriodStart(self, t):
         return previousMidnight(t)
 
-    def _getInterval(self, path):
+    def _getPingInterval(self, path):
         return self.PING_INTERVAL
 
     def sendPings(self, now=None):
@@ -798,7 +805,7 @@
             self._sendOnePing([n], [myDescriptor])
             self._schedulePing((n,), now+60)
 
-class TwoHopPingGenerator:
+class TwoHopPingGenerator(_PingScheduler, PingGenerator):
     """DOCDOC"""
     #XXXX008 make this configurable, but not less than 2 hours.
     DULL_INTERVAL = 4*ONE_DAY