[CalendarServer-changes] [15325] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Tue Nov 17 08:32:00 PST 2015


Revision: 15325
          http://trac.calendarserver.org//changeset/15325
Author:   cdaboo at apple.com
Date:     2015-11-17 08:31:59 -0800 (Tue, 17 Nov 2015)
Log Message:
-----------
Report schema check as failed if the check itself never gets to run because of some other fatal error.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tap/util.py
    CalendarServer/trunk/calendarserver/tools/upgrade.py
    CalendarServer/trunk/txdav/common/datastore/sql.py

Modified: CalendarServer/trunk/calendarserver/tap/util.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/util.py	2015-11-16 21:03:24 UTC (rev 15324)
+++ CalendarServer/trunk/calendarserver/tap/util.py	2015-11-17 16:31:59 UTC (rev 15325)
@@ -1148,24 +1148,15 @@
         return succeed(result)
 
 
-    def defaultStepWithFailure(self, failure):
+    def defaultStepWithFailure(self, failure, step):
         if failure.type not in (
             NotAllowedToUpgrade, ConfigurationError,
             OpenSSL.SSL.Error
         ):
-            log.failure("Step failure", failure=failure)
+            log.failure("Step failure: {name}", name=step.__class__.__name__, failure=failure)
         return failure
 
-    # def protectStep(self, callback):
-    #     def _protected(result):
-    #         try:
-    #             return callback(result)
-    #         except Exception, e:
-    #             # TODO: how to turn Exception into Failure
-    #             return Failure()
-    #     return _protected
 
-
     def start(self, result=None):
         """
         Begin executing the added steps in sequence.  If a step object
@@ -1188,11 +1179,13 @@
                 callBack = self.defaultStepWithResult
             if hasattr(step, "stepWithFailure"):
                 errBack = step.stepWithFailure
+                errbackArgs = ()
             else:
                 errBack = self.defaultStepWithFailure
+                errbackArgs = (step,)
 
             # Add callbacks to the Deferred
-            self.deferred.addCallbacks(callBack, errBack)
+            self.deferred.addCallbacks(callBack, errBack, errbackArgs=errbackArgs)
 
         # Get things going
         self.deferred.callback(result)

Modified: CalendarServer/trunk/calendarserver/tools/upgrade.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/upgrade.py	2015-11-16 21:03:24 UTC (rev 15324)
+++ CalendarServer/trunk/calendarserver/tools/upgrade.py	2015-11-17 16:31:59 UTC (rev 15325)
@@ -27,7 +27,7 @@
 from txdav.common.datastore.sql import CommonDataStore
 
 from twisted.internet.defer import succeed
-from twisted.logger import LogLevel, formatEvent
+from twisted.logger import LogLevel, formatEvent, formatTime
 from twisted.logger import FilteringLogObserver, LogLevelFilterPredicate
 from twisted.python.text import wordWrap
 from twisted.python.usage import Options, UsageError
@@ -150,10 +150,14 @@
         if self.options["status"]:
             self.output.write("Database OK.\n")
         elif self.options["check"]:
-            if hasattr(CommonDataStore, "checkSchemaResults"):
-                self.output.write("Database check failed:\n{}\n".format("\n".join(CommonDataStore.checkSchemaResults))) #@UndefinedVariable
+            checkResult = getattr(CommonDataStore, "checkSchemaResults", None)
+            if checkResult is not None:
+                if checkResult:
+                    self.output.write("Database check FAILED:\n{}\n".format("\n".join(checkResult)))
+                else:
+                    self.output.write("Database check OK.\n")
             else:
-                self.output.write("Database check OK.\n")
+                self.output.write("Database check FAILED.\n")
         else:
             self.output.write("Upgrade complete, shutting down.\n")
         UpgraderService.started = True
@@ -167,10 +171,14 @@
         if self.options["status"]:
             self.output.write("Upgrade needed.\n")
         elif self.options["check"]:
-            if hasattr(CommonDataStore, "checkSchemaResults"):
-                self.output.write("Database check failed:\n{}\n".format("\n".join(CommonDataStore.checkSchemaResults))) #@UndefinedVariable
+            checkResult = getattr(CommonDataStore, "checkSchemaResults", None)
+            if checkResult is not None:
+                if checkResult:
+                    self.output.write("Database check FAILED:\n{}\n".format("\n".join(checkResult)))
+                else:
+                    self.output.write("Database check OK.\n")
             else:
-                self.output.write("Database check OK.\n")
+                self.output.write("Database check FAILED.\n")
         else:
             self.output.write("Upgrade failed.\n")
         UpgraderService.started = True
@@ -230,7 +238,7 @@
 
     def onlyUpgradeEvents(eventDict):
         text = formatEvent(eventDict)
-        output.write(logDateString() + " " + text + "\n")
+        output.write(formatTime(eventDict.get("log_time", time.time())) + " " + text + "\n")
         output.flush()
 
     if not options["status"] and not options["check"]:
@@ -263,28 +271,5 @@
     utilityMain(options["config"], makeService, reactor, customServiceMaker, patchConfig=_patchConfig, onShutdown=_onShutdown, verbose=options["debug"])
 
 
-
-def logDateString():
-    logtime = time.localtime()
-    Y, M, D, h, m, s = logtime[:6]
-    tz = computeTimezoneForLog(time.timezone)
-
-    return '%02d-%02d-%02d %02d:%02d:%02d%s' % (Y, M, D, h, m, s, tz)
-
-
-
-def computeTimezoneForLog(tz):
-    if tz > 0:
-        neg = 1
-    else:
-        neg = 0
-        tz = -tz
-    h, rem = divmod(tz, 3600)
-    m, rem = divmod(rem, 60)
-    if neg:
-        return '-%02d%02d' % (h, m)
-    else:
-        return '+%02d%02d' % (h, m)
-
 if __name__ == '__main__':
     main()

Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py	2015-11-16 21:03:24 UTC (rev 15324)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py	2015-11-17 16:31:59 UTC (rev 15325)
@@ -404,9 +404,8 @@
         try:
             actual_schema = yield dumpSchema(txn, "actual", schema_name)
             results = actual_schema.compare(expected_schema)
+            self.__class__.checkSchemaResults = results
             if results:
-                if not hasattr(self.__class__, "checkSchemaResults"):
-                    self.__class__.checkSchemaResults = results
                 log.warn("Schema comparison mismatch:\n{}".format("\n".join(results)))
             else:
                 log.warn("Schema comparison match")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20151117/2e5ef431/attachment-0001.html>


More information about the calendarserver-changes mailing list