[CalendarServer-changes] [11617] CalDAVTester/trunk

source_changes at macosforge.org source_changes at macosforge.org
Mon Aug 19 10:40:40 PDT 2013


Revision: 11617
          http://trac.calendarserver.org//changeset/11617
Author:   cdaboo at apple.com
Date:     2013-08-19 10:40:40 -0700 (Mon, 19 Aug 2013)
Log Message:
-----------
Add cdtdiagnose script to help collect data when CDT fails.

Modified Paths:
--------------
    CalDAVTester/trunk/QuickLook-All
    CalDAVTester/trunk/QuickLook-CalDAV
    CalDAVTester/trunk/QuickLook-CardDAV
    CalDAVTester/trunk/Validation-All
    CalDAVTester/trunk/Validation-CalDAV
    CalDAVTester/trunk/Validation-CardDAV
    CalDAVTester/trunk/src/caldavtest.py
    CalDAVTester/trunk/src/manager.py

Added Paths:
-----------
    CalDAVTester/trunk/cdtdiagnose.py

Modified: CalDAVTester/trunk/QuickLook-All
===================================================================
--- CalDAVTester/trunk/QuickLook-All	2013-08-19 17:38:32 UTC (rev 11616)
+++ CalDAVTester/trunk/QuickLook-All	2013-08-19 17:40:40 UTC (rev 11617)
@@ -20,7 +20,7 @@
 #
 
 export PYTHONPATH=/usr/share/caldavd/lib/python:/Applications/Server.app/Contents/ServerRoot/usr/share/caldavd/lib/python/
-./testcaldav.py $@ --ssl --print-details-onfail -s scripts/server/serverinfo-caldav.xml \
+./testcaldav.py $@ --ssl --print-details-onfail -s scripts/server/serverinfo-caldav.xml -o cdt.txt \
     CalDAV/caldavIOP.xml \
     CalDAV/errors.xml \
     CalDAV/get.xml \
@@ -34,4 +34,3 @@
     CardDAV/propfind.xml \
     CardDAV/put.xml \
     CardDAV/reports.xml
-

Modified: CalDAVTester/trunk/QuickLook-CalDAV
===================================================================
--- CalDAVTester/trunk/QuickLook-CalDAV	2013-08-19 17:38:32 UTC (rev 11616)
+++ CalDAVTester/trunk/QuickLook-CalDAV	2013-08-19 17:40:40 UTC (rev 11617)
@@ -20,7 +20,7 @@
 #
 
 export PYTHONPATH=/usr/share/caldavd/lib/python:/Applications/Server.app/Contents/ServerRoot/usr/share/caldavd/lib/python/
-./testcaldav.py $@ --ssl --print-details-onfail -s scripts/server/serverinfo-caldav.xml \
+./testcaldav.py $@ --ssl --print-details-onfail -s scripts/server/serverinfo-caldav.xml -o cdt.txt \
 	CalDAV/caldavIOP.xml \
 	CalDAV/errors.xml \
 	CalDAV/get.xml \

Modified: CalDAVTester/trunk/QuickLook-CardDAV
===================================================================
--- CalDAVTester/trunk/QuickLook-CardDAV	2013-08-19 17:38:32 UTC (rev 11616)
+++ CalDAVTester/trunk/QuickLook-CardDAV	2013-08-19 17:40:40 UTC (rev 11617)
@@ -20,7 +20,7 @@
 #
 
 export PYTHONPATH=/usr/share/caldavd/lib/python:/Applications/Server.app/Contents/ServerRoot/usr/share/caldavd/lib/python/
-./testcaldav.py $@ --ssl --print-details-onfail -s scripts/server/serverinfo-caldav.xml \
+./testcaldav.py $@ --ssl --print-details-onfail -s scripts/server/serverinfo-caldav.xml -o cdt.txt \
 	CardDAV/ab-client.xml \
 	CardDAV/errors.xml \
 	CardDAV/get.xml \

Modified: CalDAVTester/trunk/Validation-All
===================================================================
--- CalDAVTester/trunk/Validation-All	2013-08-19 17:38:32 UTC (rev 11616)
+++ CalDAVTester/trunk/Validation-All	2013-08-19 17:40:40 UTC (rev 11617)
@@ -21,10 +21,9 @@
 #
 
 export PYTHONPATH=/usr/share/caldavd/lib/python:/Applications/Server.app/Contents/ServerRoot/usr/share/caldavd/lib/python/
-./testcaldav.py $@ --ssl --print-details-onfail -s scripts/server/serverinfo-caldav.xml --all \
+./testcaldav.py $@ --ssl --print-details-onfail -s scripts/server/serverinfo-caldav.xml --all -o cdt.txt \
 	--exclude CalDAV/directory.xml \
 	--exclude CalDAV/proxyauthz.xml \
 	--exclude CalDAV/quota.xml \
  	--exclude CalDAV/timezonestdservice.xml \
  	--exclude CardDAV/directory.xml
- 
\ No newline at end of file

Modified: CalDAVTester/trunk/Validation-CalDAV
===================================================================
--- CalDAVTester/trunk/Validation-CalDAV	2013-08-19 17:38:32 UTC (rev 11616)
+++ CalDAVTester/trunk/Validation-CalDAV	2013-08-19 17:40:40 UTC (rev 11617)
@@ -20,10 +20,9 @@
 #
 
 export PYTHONPATH=/usr/share/caldavd/lib/python:/Applications/Server.app/Contents/ServerRoot/usr/share/caldavd/lib/python/
-./testcaldav.py $@ --ssl --print-details-onfail -s scripts/server/serverinfo-caldav.xml --all \
+./testcaldav.py $@ --ssl --print-details-onfail -s scripts/server/serverinfo-caldav.xml --all -o cdt.txt \
 	--subdir CalDAV \
 	--exclude CalDAV/directory.xml \
 	--exclude CalDAV/proxyauthz.xml \
 	--exclude CalDAV/quota.xml \
  	--exclude CalDAV/timezonestdservice.xml
-	
\ No newline at end of file

Modified: CalDAVTester/trunk/Validation-CardDAV
===================================================================
--- CalDAVTester/trunk/Validation-CardDAV	2013-08-19 17:38:32 UTC (rev 11616)
+++ CalDAVTester/trunk/Validation-CardDAV	2013-08-19 17:40:40 UTC (rev 11617)
@@ -20,7 +20,6 @@
 #
 
 export PYTHONPATH=/usr/share/caldavd/lib/python:/Applications/Server.app/Contents/ServerRoot/usr/share/caldavd/lib/python/
-./testcaldav.py $@ --ssl --print-details-onfail -s scripts/server/serverinfo-caldav.xml --all \
+./testcaldav.py $@ --ssl --print-details-onfail -s scripts/server/serverinfo-caldav.xml --all -o cdt.txt \
 	--subdir CardDAV \
-	--exclude CardDAV/directory.xml \
- 	
+	--exclude CardDAV/directory.xml

Added: CalDAVTester/trunk/cdtdiagnose.py
===================================================================
--- CalDAVTester/trunk/cdtdiagnose.py	                        (rev 0)
+++ CalDAVTester/trunk/cdtdiagnose.py	2013-08-19 17:40:40 UTC (rev 11617)
@@ -0,0 +1,123 @@
+#!/usr/bin/env python
+#
+##
+# Copyright (c) 2013 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+import os
+import datetime
+import shutil
+import sys
+from subprocess import Popen, PIPE
+
+server_root = "/Applications/Server.app/Contents/ServerRoot"
+os.environ["PATH"] = "%s/usr/bin:%s" % (server_root, os.environ["PATH"])
+library_root = "/Library/Server/Calendar and Contacts"
+
+directory_node = "/LDAPv3/127.0.0.1"
+
+
+def cmd(args, input=None, raiseOnFail=True):
+
+    if input:
+        p = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
+        result = p.communicate(input)
+    else:
+        p = Popen(args, stdout=PIPE, stderr=PIPE, shell=True)
+        result = p.communicate()
+
+    if raiseOnFail and p.returncode:
+        raise RuntimeError(result[1])
+    return result[0], p.returncode
+
+
+if __name__ == "__main__":
+
+    print "Running CDT diagnostics due to test failure."
+    log = []
+
+    def error(message, e):
+        log.append("CDT diagnostic: %s" % (message,))
+        log.append(str(e))
+        print "\n".join(log)
+        sys.exit(1)
+
+    now = datetime.datetime.now()
+    now = now.replace(microsecond=0)
+    dirname = "cdtdiagnose-%s" % (now.strftime("%Y%m%d-%H%M%S"),)
+    try:
+        os.mkdir(dirname)
+    except Exception as e:
+        error("Could not create archive directory: '%s'" % (dirname,), e)
+
+    # Copy CDT log file file
+    server_path = "cdt.txt"
+    archive_path = os.path.join(dirname, os.path.basename(server_path))
+    try:
+        shutil.copy(server_path, archive_path)
+    except Exception as e:
+        error("Could not copy cdt results file: '%s' to '%s'" % (server_path, archive_path,), e)
+
+    # Copy serverinfo file
+    server_path = "scripts/server/serverinfo-caldav.xml"
+    archive_path = os.path.join(dirname, os.path.basename(server_path))
+    try:
+        shutil.copy(server_path, archive_path)
+    except Exception as e:
+        error("Could not copy server info file: '%s' to '%s'" % (server_path, archive_path,), e)
+
+    # Get server logs
+    server_path = "/var/log/caldavd"
+    archive_path = os.path.join(dirname, "logs")
+    try:
+        shutil.copytree(server_path, archive_path)
+    except Exception as e:
+        error("Could not copy server logs: '%s' to '%s'" % (server_path, archive_path,), e)
+
+    # Get server config files
+    server_path = os.path.join(server_root, "etc", "caldavd")
+    archive_path = os.path.join(dirname, "etc")
+    try:
+        shutil.copytree(server_path, archive_path)
+    except Exception as e:
+        error("Could not copy server conf: '%s' to '%s'" % (server_path, archive_path,), e)
+
+    server_path = library_root
+    archive_path = os.path.join(dirname, "Library")
+    try:
+        shutil.copytree(server_path, archive_path)
+    except Exception as e:
+        error("Could not copy library items: '%s' to '%s'" % (server_path, archive_path,), e)
+
+    # Dump OD data
+    try:
+        results = ["*** Users"]
+        results.extend(cmd("dscl %s -readall Users" % (directory_node,))[0].splitlines())
+        results.append("\n\n*** Groups")
+        results.extend(cmd("dscl %s -readall Groups" % (directory_node,))[0].splitlines())
+        results.append("")
+
+        with open(os.path.join(dirname, "dscl_dump.txt"), "w") as f:
+            f.write("\n".join(results))
+    except Exception as e:
+        error("Could not dump OD data.", e)
+
+    # Now archive the diagnostics data
+    try:
+        archive_name = shutil.make_archive(dirname, "gztar", dirname)
+    except Exception as e:
+        error("Could not make diagnostics archive.", e)
+
+    print "Saved diagnostics to '%s'" % (archive_name,)


Property changes on: CalDAVTester/trunk/cdtdiagnose.py
___________________________________________________________________
Added: svn:executable
   + *

Modified: CalDAVTester/trunk/src/caldavtest.py
===================================================================
--- CalDAVTester/trunk/src/caldavtest.py	2013-08-19 17:38:32 UTC (rev 11616)
+++ CalDAVTester/trunk/src/caldavtest.py	2013-08-19 17:40:40 UTC (rev 11617)
@@ -174,7 +174,6 @@
                     ignored += 1
             if self.manager.memUsage:
                 end_usage = self.manager.getMemusage()
-                print start_usage, end_usage
                 self.manager.log(manager.LOG_HIGH, "Mem. Usage: RSS=%s%% VSZ=%s%%" % (str(((end_usage[1] - start_usage[1]) * 100) / start_usage[1]), str(((end_usage[0] - start_usage[0]) * 100) / start_usage[0])))
         self.manager.log(manager.LOG_HIGH, "Suite Results: %d PASSED, %d FAILED, %d IGNORED" % (ok, failed, ignored), before=1, indent=4)
         if postgresCount is not None:

Modified: CalDAVTester/trunk/src/manager.py
===================================================================
--- CalDAVTester/trunk/src/manager.py	2013-08-19 17:38:32 UTC (rev 11616)
+++ CalDAVTester/trunk/src/manager.py	2013-08-19 17:40:40 UTC (rev 11617)
@@ -46,14 +46,15 @@
     LOG_MEDIUM = 3
     LOG_HIGH = 4
 
-    def __init__(self, text=True, level=LOG_HIGH, log_file=None):
+    def __init__(self, text=True, level=LOG_HIGH):
         self.server_info = serverinfo()
         self.tests = []
         self.textMode = text
         self.pid = 0
         self.memUsage = None
+        self.randomSeed = None
         self.logLevel = level
-        self.logFile = log_file
+        self.logFile = None
         self.digestCache = {}
         self.postgresLog = ""
         self.print_request = False
@@ -75,8 +76,7 @@
     def logit(self, str):
         if self.logFile:
             self.logFile.write(str)
-        else:
-            print str,
+        print str,
 
 
     def readXML(self, serverfile, testfiles, ssl, all, moresubs={}):
@@ -147,7 +147,7 @@
         random_seed = str(random.randint(0, 1000000))
         options, args = getopt.getopt(
             sys.argv[1:],
-            "s:mx:",
+            "s:mo:x:",
             [
                 "ssl",
                 "all",
@@ -179,6 +179,8 @@
                 excludes.add(value)
             elif option == "-m":
                 self.memUsage = True
+            elif option == "-o":
+                self.logFile = open(value, "w")
             elif option == "--pid":
                 pidfile = value
             elif option == "--postgres-log":
@@ -223,9 +225,9 @@
 
         # Randomize file list
         if random_order and len(fnames) > 1:
-            print "Randomizing order using seed '%s'" % (random_seed,)
             random.seed(random_seed)
             random.shuffle(fnames)
+            self.randomSeed = random_seed
 
         self.readXML(sname, fnames, ssl, all)
 
@@ -238,6 +240,10 @@
     def runAll(self):
 
         startTime = time.time()
+
+        if self.randomSeed is not None:
+            self.log(manager.LOG_LOW, "Randomizing order using seed '%s'" % (self.randomSeed,))
+
         ok = 0
         failed = 0
         ignored = 0
@@ -257,6 +263,9 @@
         self.log(manager.LOG_LOW, "Overall Results: %d PASSED, %d FAILED, %d IGNORED" % (ok, failed, ignored), before=2, indent=4)
         self.log(manager.LOG_LOW, "Total time: %.3f secs" % (endTime - startTime,))
 
+        if self.logFile is not None:
+            self.logFile.close()
+
         return failed, endTime - startTime
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130819/d1f75d70/attachment-0001.html>


More information about the calendarserver-changes mailing list