mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

gary_williams
27.16.2008 f5d1f32804f7aa34d071115ab51abab9ea3ff878
Issue 851: log archiving, reporting and results collection
1 files added
4 files modified
334 ■■■■■ changed files
opends/tests/staf-tests/functional-tests/shared/xsl/gen-logs.xsl 170 ●●●●● patch | view | raw | blame | history
opends/tests/staf-tests/functional-tests/shared/xsl/gen-suites-report.xsl 2 ●●● patch | view | raw | blame | history
opends/tests/staf-tests/shared/functions/utils.xml 147 ●●●● patch | view | raw | blame | history
opends/tests/staf-tests/shared/python/common.py 3 ●●●●● patch | view | raw | blame | history
opends/tests/staf-tests/shared/tests/runTestJob.xml 12 ●●●● patch | view | raw | blame | history
opends/tests/staf-tests/functional-tests/shared/xsl/gen-logs.xsl
New file
@@ -0,0 +1,170 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
 ! CDDL HEADER START
 !
 ! The contents of this file are subject to the terms of the
 ! Common Development and Distribution License, Version 1.0 only
 ! (the "License").  You may not use this file except in compliance
 ! with the License.
 !
 ! You can obtain a copy of the license at
 ! trunk/opends/resource/legal-notices/OpenDS.LICENSE
 ! or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 ! See the License for the specific language governing permissions
 ! and limitations under the License.
 !
 ! When distributing Covered Code, include this CDDL HEADER in each
 ! file and include the License file at
 ! trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 ! add the following below this CDDL HEADER, with the fields enclosed
 ! by brackets "[]" replaced with your own identifying information:
 !      Portions Copyright [yyyy] [name of copyright owner]
 !
 ! CDDL HEADER END
 !
 !      Copyright 2008 Sun Microsystems, Inc.
 ! -->
<xsl:output method="html" version="4.0" encoding="iso-8859-1" indent="yes"/>
<xsl:template match="/">
  <xsl:element name="html">
    <xsl:variable name="group" select="qa/logs/log/@group"/>
    <xsl:variable name="suite" select="qa/logs/log/@suite"/>
    <xsl:variable name="parent" select="qa/logs/log/@parent"/>
    <xsl:variable name="jobid" select="qa/logs/log/@jobid"/>
    <xsl:element name="head">
    <link rel="SHORTCUT ICON" href="https://opends.dev.java.net/public/images/opends_favicon.gif" />
    <style type="text/css">
      /* <![CDATA[ */
       @import "/branding/css/tigris.css";
       @import "/branding/css/inst.css";
       /* ]]> */
    </style>
    <link rel="stylesheet" type="text/css" href="/branding/css/print.css" media="print" />
    <link rel="stylesheet" href="https://opends.dev.java.net/public/css/opends.css" type="text/css" />
      <xsl:element name="title">
        <xsl:value-of select="concat('Logs for ', $suite, ' test suite')"/>
      </xsl:element>
    </xsl:element>
    <table class="tertmasttable" width="100%" cellspacing="0">
      <tbody>
        <tr>
          <td><div class="collectionheader"><xsl:value-of select="concat('Logs for ', $suite, ' test suite')"/></div></td>
          <td width="10%"><a href="https://opends.dev.java.net/"><img src="https://opends.dev.java.net/public/images/opends_logo_sm.png" alt="OpenDS Logo" width="104" height="33" border="0" align="middle" /></a> </td>
        </tr>
      </tbody>
    </table>
    <!-- Shaded Line -->
    <xsl:element name="hr">
      <xsl:attribute name="noshade">
        <xsl:value-of select="'noshade'"/>
      </xsl:attribute>
      <xsl:attribute name="size">
        <xsl:value-of select="1"/>
      </xsl:attribute>
    </xsl:element>
    <!-- Baby Table -->
    <xsl:element name="table">
      <xsl:attribute name="border">
        <xsl:value-of select="'1'"/>
      </xsl:attribute>
      <xsl:attribute name="cellpadding">
        <xsl:value-of select="'4'"/>
      </xsl:attribute>
      <xsl:element name="tr">
        <xsl:element name="td">
          <xsl:element name="b">
            <xsl:value-of select="'Test Group : '"/>
          </xsl:element>
          <xsl:value-of select="$group"/>
        </xsl:element>
        <xsl:element name="td">
          <xsl:element name="b">
            <xsl:value-of select="'Test Suite : '"/>
          </xsl:element>
          <xsl:value-of select="$suite"/>
        </xsl:element>
        <xsl:element name="td">
          <xsl:element name="b">
            <xsl:value-of select="'ParentID : '"/>
          </xsl:element>
          <xsl:value-of select="$parent"/>
        </xsl:element>
        <xsl:element name="td">
          <xsl:element name="b">
            <xsl:value-of select="'JobID : '"/>
          </xsl:element>
          <xsl:value-of select="$jobid"/>
        </xsl:element>
      </xsl:element>
    </xsl:element>
    <!-- Shaded Line -->
    <xsl:element name="hr">
      <xsl:attribute name="noshade">
        <xsl:value-of select="'noshade'"/>
      </xsl:attribute>
      <xsl:attribute name="size">
        <xsl:value-of select="1"/>
      </xsl:attribute>
    </xsl:element>
    <xsl:element name="body">
      <xsl:element name="table">
      <xsl:attribute name="border">
        <xsl:value-of select="'1'"/>
      </xsl:attribute>
      <xsl:element name="tr">
        <xsl:element name="th">
          <xsl:value-of select="'Timestamp'"/>
        </xsl:element>
        <xsl:element name="th">
          <xsl:value-of select="'Level'"/>
        </xsl:element>
        <xsl:element name="th">
          <xsl:value-of select="'Message'"/>
        </xsl:element>
      </xsl:element>
      <xsl:variable name="log" select="qa/logs/log"/>
      <xsl:for-each select="$log/line">
        <xsl:element name="tr">
          <xsl:element name="td">
            <xsl:value-of select="@timestamp"/>
          </xsl:element>
          <xsl:element name="td">
            <xsl:value-of select="@level"/>
          </xsl:element>
          <xsl:element name="td">
            <xsl:value-of select="@message"/>
          </xsl:element>
        </xsl:element>
      </xsl:for-each>
      </xsl:element>
    </xsl:element>
  </xsl:element>
</xsl:template>
</xsl:stylesheet>
opends/tests/staf-tests/functional-tests/shared/xsl/gen-suites-report.xsl
@@ -432,7 +432,7 @@
              </xsl:attribute>
              <xsl:element name="a">
                <xsl:attribute name="href">
                  <xsl:value-of select="concat($url,$tests-dir,'/testlogs/',$groupdir,'/',$suitename)"/>
                  <xsl:value-of select="concat($url,$tests-dir,'/testlogs/',$groupdir,'/',$suitename,'.html')"/>
                </xsl:attribute>
                <xsl:value-of select="@name"/>
              </xsl:element>
opends/tests/staf-tests/shared/functions/utils.xml
@@ -904,13 +904,13 @@
        FormattedTestsuite=FormattedTestcase.suite(ThisSuiteName)
             
        TestLogDir= '%s/%s' % (logs.tests,FormattedTestgroup)
        TestLogFile='%s/%s' % (TestLogDir,FormattedTestsuite)
        TestLogFile='%s/%s' % (TestLogDir,FormattedTestsuite)
      </script>
                  
      <call function="'WriteLogsForTestCase'">
        { 'starttime' : TestSuiteStartTime,
          'endtime'   : TestSuiteEndTime,
          'tofile'    : TestLogFile }
          'logFile' : TestLogFile }
      </call>
      <script>
@@ -1052,7 +1052,7 @@
    </sequence>
  </function>
  
  <function name="WriteLogsForTestCase">
  <function name="WriteLogsForTestCase" scope="local">
    <function-prolog>
      Queries the staf logs for the test case and write to file as text
@@ -1070,7 +1070,7 @@
        </function-arg-description>
        <function-arg-property name="type" value="timestamp"/>
      </function-arg-def>
      <function-arg-def name="tofile" type="required">
      <function-arg-def name="logFile" type="required">
        <function-arg-description>
          name of file to write the logs
        </function-arg-description>
@@ -1080,6 +1080,13 @@
    <sequence>
      <script>
        xmlFile   = '%s.xml' % logFile
        htmlFile  = '%s.html' % logFile
        xslFile   = '%s/xsl/gen-logs.xsl' % TESTS_SHARED_DIR
      </script>
      <!-- Query STAF to obtain the logs for the test case -->
      <call function="'queryLogs'">
        { 'location'  : STAXServiceMachine,
          'logname'   : 'STAX_Job_%s_User' % STAXJobID, 
@@ -1087,16 +1094,24 @@
          'endat'     : endtime }
      </call>
      <call function="'WriteLogs'">
      <!-- Write out the logs into an XML file -->
      <call function="'WriteXmlLogs'">
        { 'queryresult' : STAFResult, 
          'logfile'     : tofile }
          'output'      : xmlFile }
      </call>
      <!-- Transform the XML file into an HTML file -->
      <call function="'WriteHtmlLogs'">
        { 'input'       : xmlFile,
          'stylesheet'  : xslFile,
          'output'      : htmlFile }
      </call>
    </sequence>
  </function>
  <function name="WriteLogs">
  <function name="WriteXmlLogs" scope="local">
    <function-prolog>
      Process staf log query results and write them to a file
@@ -1108,9 +1123,9 @@
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>   
      <function-arg-def name="logfile" type="required">
      <function-arg-def name="output" type="required">
        <function-arg-description>
          name of the log file to where results are written
          name of the XML file to where results are written
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>          
@@ -1118,19 +1133,40 @@
    
    <sequence>
      <message>'Creating test log %s' % logfile</message>
      <script>
        NewLogDir=os.path.dirname(logfile)
        logFile=output
        NewLogDir=os.path.dirname(logFile)
      </script>
      <message>'Creating XML log file %s' % logFile</message>
      <call function="'createFolder'">
        { 'location'   : STAXServiceMachine, 
          'foldername' : NewLogDir }
      </call>
      <script>
        testlogfh=open(logfile,'w')
        from xml.dom.minidom import Document
        doc = Document()
        # Create the qa base element
        qa = doc.createElement("qa")
        doc.appendChild(qa)
        # Create the base element
        logs = doc.createElement("logs")
        qa.appendChild(logs)
        # Pass only the pretty print of the test suite name
        __main,__group,__suite=CurrentTestPath['suite'].split('.')
        # Create the log element
        log = doc.createElement("log")
        log.setAttribute("group", "%s" % CurrentTestPath['group'])
        log.setAttribute("suite", "%s" % __suite)
        log.setAttribute("jobid", "%s" % STAXJobID)
        log.setAttribute("parent", "%s" % STAXParentID)
        logs.appendChild(log)
      </script>
      
      <if expr="queryresult == '[]'">
@@ -1153,20 +1189,93 @@
            level=element['level'] 
            message=element['message']
            timestamp=element['timestamp']
            testlogfh.write('%s %s %s\n' % (timestamp,level,message))
            line = doc.createElement("line")
            line.setAttribute("timestamp", "%s" % timestamp)
            line.setAttribute("level", "%s" % level)
            line.setAttribute("message", "%s" % message)
            log.appendChild(line)
          </script>
        </iterate>
      </else>
      </if>
      
      <script>testlogfh.close()</script>
      <script>
        _message='Generated XML test case report.'
        testlogfh=open('%s' % logFile,'w')
        try:
          testlogfh.writelines(doc.toprettyxml(indent="  "))
        except AttributeError,details:
          _message='Unable to generate XML test case report %s.' % details
        except:
          _message='Unable to generate XML test case report !!!'
        testlogfh.close()
      </script>
      <message>_message</message>
    </sequence>
  </function>
  
  <function name="WriteHtmlLogs" scope="local">
    <function-prolog>
      Process XML file and transform that to an HTML file
    </function-prolog>
    <function-map-args>
      <function-arg-def name="input" type="required">
        <function-arg-description>
          name of the XML file to where results are obtained
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="output" type="required">
        <function-arg-description>
          name of the HTML file to where results are written
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
      <function-arg-def name="stylesheet" type="required">
        <function-arg-description>
          name of the XSL stylesheet used to transform results
        </function-arg-description>
        <function-arg-property name="type" value="string"/>
      </function-arg-def>
    </function-map-args>
    <sequence>
      <script>
        xmlFile=input
        htmlFile=output
        xslFile=stylesheet
      </script>
      <message>'Inputting XML file %s' % xmlFile</message>
      <message>'Transform XSL file %s' % xslFile</message>
      <message>'Creating HTML file %s' % htmlFile</message>
      <script>
        _message='Generated test case report.'
        testCaseReport=report_generation()
        stringParamsDict={}
        try:
          testCaseReport.transformReport(xslFile,xmlFile,htmlFile,stringParamsDict)
        except java.io.FileNotFoundException,details:
          _message='Unable to generate test case report %s.' % details
        except IOError,details:
          _message='Unable to generate test case report %s.' % details
        except:
          _message='Unable to generate test case report !!!'
      </script>
      <message>'%s' % _message</message>
    </sequence>
  </function>
   
  <function name="CheckMatches">
    <function-prolog>
opends/tests/staf-tests/shared/python/common.py
@@ -256,6 +256,9 @@
  def port(self,port):
    return port
  def adminport(self,port):
    return adminport
  def dn(self,dn):
    return dn
opends/tests/staf-tests/shared/tests/runTestJob.xml
@@ -636,12 +636,12 @@
          
          # Create the testcase element
          case = doc.createElement("testcase")
          case.setAttribute("group", "%s" %tcgroup)
          case.setAttribute("suite", "%s" %tcsuite)
          case.setAttribute("name", "%s" %tcname)
          case.setAttribute("result", "%s" %tcresult)
          case.setAttribute("start", "%s" %tcstart)
          case.setAttribute("stop", "%s" %tcstop)
          case.setAttribute("group", "%s" % tcgroup)
          case.setAttribute("suite", "%s" % tcsuite)
          case.setAttribute("name", "%s" % tcname)
          case.setAttribute("result", "%s" % tcresult)
          case.setAttribute("start", "%s" % tcstart)
          case.setAttribute("stop", "%s" % tcstop)
          case.setAttribute("duration", "%s" % tcdurationsecs)
          suite.appendChild(case)