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

Christophe Sovant
04.12.2009 5a6a88bd1e4831128c55f72923b18f5f771d45f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "../../shared/stax.dtd">
<!--
 ! 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 2006-2009 Sun Microsystems, Inc.
 ! -->
 
<stax>
  <defaultcall function="start_job"/>
  <function name="start_job">
 
    <sequence>
 
      <script>
        STAXLogMessage = 1
      </script>
 
      <if expr="not STAXJobScriptFiles">
        <sequence>
          <message>'No script file (config.py) is specified. Unable to run the tests.'</message>
          <return></return>
        </sequence>
      </if>
 
      <!-- Load in the local shared python objects -->
      <script>
        import sys,os
        import java.io.FileNotFoundException
        sys.path.append("%s/shared/python" % TESTS_ROOT )
        from common import *
      </script>
 
      <message>'PATH= %s' % sys.path</message>
 
      <!-- Check some of the optional variables from config.py -->
      <script>
        try:
          if TEST_OS_STRING:
            ServerOsString=TEST_OS_STRING
          else:
            ServerOsString='Unknown Operating System'
        except NameError,details:
            ServerOsString='Unknown Operating System'
 
        try:
          if TEST_JVM_STRING:
            ServerJVMString=TEST_JVM_STRING
          else:
            ServerJVMString='Unknown JVM'
        except NameError,details:
            ServerJVMString='Unknown JVM'
 
        try:
          if LOGS_URI:
            logsURI=LOGS_URI
          else:
            logsURI=''
        except NameError,details:
            logsURI=''
 
      </script>
 
      <job name="'Job: %s %s' % (STAF_REMOTE_HOSTNAME,ServerOsString) " monitor="1" clearlogs="'Enabled'" logtcstartstop="'Enabled'">
        <job-file>'%s/shared/tests/runTests.xml' % TESTS_ROOT</job-file>
        <job-scriptfiles machine="STAF_LOCAL_HOSTNAME"> STAXJobScriptFiles </job-scriptfiles>
        <job-action>
          <log>'Started sub-job %s on %s, %s' % (STAXSubJobID,STAF_REMOTE_HOSTNAME,ServerOsString )</log>
        </job-action>
      </job>
 
      <if expr="RC == 0">
        <sequence>
          <message>
            'Sub-job %s completed. Children: %s' % (STAXSubJobID, STAXResult)
          </message>
 
          <script>
            listOfChildren=STAXResult
          </script>
        </sequence>
        <else>
          <sequence>
            <message log="1" level="'Error'">
              'Sub-job %s could not be started. RC: %s Result: %s' % (STAXSubJobID,RC,STAFResult)
            </message>
            <return>1</return>
          </sequence>
        </else>
      </if>
 
      <!--- Import required shared xml libraries -->
      <import machine="STAF_LOCAL_HOSTNAME"
              file="'%s/stafcmd.xml' % TESTS_FUNCTIONS_DIR" />
 
      <!-- FixMe
        dirty workaround because utils.xml now depends on environment.xml
        to avoid loading environment.xml I'll just set the required vars here
        allegedly ugly
        -=arnaud=-
      -->
      <script>
        NO_CHECK = 'noCheck'
      </script>
      <import machine="STAF_LOCAL_HOSTNAME"
        file="'%s/utils.xml' % (TESTS_FUNCTIONS_DIR)" />
 
      <!-- Get Directory Server Variables -->
      <call function="'GetVar'">
        { 'location'  : STAF_REMOTE_HOSTNAME,
          'type'      : 'shared',
          'variable'  : 'Job%s_ServerInfo' % STAXSubJobID
        }
      </call>
 
      <if expr="RC != 0">
        <script>
          STAFResult='{}'
        </script>
      </if>
 
      <!-- Build the Servers Information Dictionary -->
      <script>
 
        ServersInfoDict=eval(STAFResult)
 
        ServerPath='%s/%s' % (DIRECTORY_INSTANCE_BIN,OPENDSNAME)
        ServerName='unknown'        
        ServerVersion='unknown'
        ServerBuildId='unknown'
        ServerJavaVersion='unknown'
        ServerJavaVendor='unknown'
        ServerJVMVersion='unknown'
        ServerJVMVendor='unknown'
        ServerJVMArchitecture='unknown'
        ServerJVMLabel='unknown'
        ServerSystemOS='unknown'
        ServerSystemName='unknown'
        ServerRevision='unknown'
        ServerPackage='%s/%s' % (ZIPPATH,ZIPNAME)
        ServerSNMPJarFile='%s' % SNMP_OPENDMK_JARFILE
        
        if ServersInfoDict.has_key(ServerPath):
          ServerInfoDict=ServersInfoDict[ServerPath]
 
          ServerName=OPENDSNAME
 
          ServerInfoKey='server version'
          if ServerInfoDict.has_key(ServerInfoKey):
            ServerVersion=ServerInfoDict[ServerInfoKey]
 
          ServerInfoKey='server buildid'
          if ServerInfoDict.has_key(ServerInfoKey):
            ServerBuildId=ServerInfoDict[ServerInfoKey]
 
          ServerInfoKey='java version'
          if ServerInfoDict.has_key(ServerInfoKey):
            ServerJavaVersion=ServerInfoDict[ServerInfoKey]
 
          ServerInfoKey='java vendor'
          if ServerInfoDict.has_key(ServerInfoKey):
            ServerJavaVendor=ServerInfoDict[ServerInfoKey]
 
          ServerInfoKey='jvm version'
          if ServerInfoDict.has_key(ServerInfoKey):
            ServerJVMVersion=ServerInfoDict[ServerInfoKey]
 
          ServerInfoKey='jvm vendor'
          if ServerInfoDict.has_key(ServerInfoKey):
            ServerJVMVendor=ServerInfoDict[ServerInfoKey]
 
          ServerInfoKey='jvm architecture'
          if ServerInfoDict.has_key(ServerInfoKey):
            ServerJVMArchitecture=ServerInfoDict[ServerInfoKey]
 
          ServerInfoKey='system os'
          if ServerInfoDict.has_key(ServerInfoKey):
            ServerSystemOS=ServerInfoDict[ServerInfoKey]
 
          ServerInfoKey='system name'
          if ServerInfoDict.has_key(ServerInfoKey):
            ServerSystemName=ServerInfoDict[ServerInfoKey]
 
          ServerInfoKey='svn revision'
          if ServerInfoDict.has_key(ServerInfoKey):
            ServerRevision=ServerInfoDict[ServerInfoKey]
 
        else:
          ServerInfoDict='No key found (%s)' % ServerPath
 
        if ServerOsString == 'Unknown Operating System':
          ServerOsString=ServerSystemOS
 
        if ServerJVMString == 'Unknown JVM':
          ServerJVMString=ServerJVMVersion
 
      </script>
 
      <message>'Server= %s' % ServerInfoDict </message>
 
      <!-- Build the DSML Gateway Information Dictionary -->
      <script>
        DSMLName='%s' % DSML_WARNAME
        DSMLPackage='%s' % DSML_WARPATH
        DSMLContainer='%s %s' % (WC_TYPE,WC_VERSION)
      </script>
 
      <!-- Get the location of where the test logs are -->
      <call function="'GetVar'">
        { 'location'  : STAF_REMOTE_HOSTNAME,
          'type'      : 'shared',
          'variable'  : 'Job%s_LogsDir' % STAXSubJobID
        }
      </call>
 
      <if expr="RC == 0">
        <script>
          logsDir=STAFResult
        </script>
      <else>
        <sequence>
          <message>
            'Unable to retrieve LogsDir variable, RC=%s,Result=%s.' % (RC,STAFResult)
          </message>
          <script>
            logsDir='%s' % TMPDIR
          </script>
        </sequence>
      </else>
      </if>
 
      <script>
        logsReportDir='%s/reports' % logsDir
        logsTestsDir='%s/testlogs' % logsDir
      </script>
 
      <call function="'createFolder'">
        { 'location'   : STAF_LOCAL_HOSTNAME,
          'foldername' : logsReportDir }
      </call>
 
      <script>
        resultQuery=[]
        textfile= '%s/results.txt' % logsReportDir
        txtfh=open(textfile,'w')
      </script>
 
      <!-- Defend against not having any test groups run -->
      <if expr="not listOfChildren">
        <sequence>
          <message log="1" level="'Warning'">
            'No test groups have been run.'
          </message>
        </sequence>
      <else>    
        <sequence>
          <iterate var="thisChild" in="listOfChildren">
            <sequence>                              
              <stafcmd name="'STAF Command: Log Query All'">
                <location>'%s' % STAF_LOCAL_HOSTNAME </location>
                <service>'log'</service>
                <request>
                  'QUERY ALL MACHINE %s LOGNAME STAX_Job_%s' % (STAXServiceMachine,thisChild)
                </request>
              </stafcmd>
    
              <if expr="RC == 0">
                <sequence>
                  <script>
                    resultQuery=STAFResult
                  </script>
                  <message>
                    'Log Query on STAX_Job_%s Completed. RC=%s' % (thisChild,RC)
                  </message>
                  <iterate var="line" in="resultQuery">
            
                    <script>
                     txtfh.write('%s\n' % line)
                    </script>
          
                  </iterate> 
                </sequence>
                <else>
                  <sequence>
                    <message log="1" level="'Error'">
                      'Unable to perform log query on STAX_Job_%s. RC: %s Result: %s' % (thisChild,RC,STAFResult)
                    </message>
                    <return>1</return>
                  </sequence>
                </else>
              </if>
    
            </sequence>
          </iterate>
        </sequence>
      </else>
      </if>
 
      <script>
        txtfh.close()
      </script>
 
      <!-- Write error File for results -->
      <script>
        import re
        errorfile= '%s/results.errors' % logsReportDir
        errorfh=open(errorfile,'w')
      </script>
 
      <!-- Build the test case dictionary object -->
      <script>
        testDict={}
        testCaseList=[]
        tcshortname=''
        try:
          txtfh=open(textfile,'r')
 
          try:
            for line in txtfh.readlines():
              element=eval(line)
 
              level=element['level']
              message=element['message']
              timestamp=element['timestamp']
 
              startValueDict={}
              stopValueDict={}
              failValueDict={}
              statusValueDict={}
 
              if level == 'Start':
                tcpattern=re.compile("(Testcase): (.*)")
                tcmatch = tcpattern.search(message)
                if tcmatch:
                  tctype=tcmatch.group(1)
                  tcname=tcmatch.group(2)
                  if testDict.has_key(tcname):
                    for key in testDict[tcname].keys():
                      value=testDict[tcname][key]
                      startValueDict[key]=value
 
                  startValueDict['start']=timestamp
                  testDict[tcname]=startValueDict
 
                  testCaseList.append(tcname.strip())
 
                else:
                  errorfh.write('Warning: No match Start element %s.\n' % element)
 
              elif level == 'Stop':
 
                tcpattern=re.compile("(Testcase): (.*), ElapsedTime: (.*)")
                tcmatch = tcpattern.search(message)
 
                if tcmatch:
                  tctype=tcmatch.group(1)
                  tcname=tcmatch.group(2)
                  tctime=tcmatch.group(3)
                  if testDict.has_key(tcname):
                    for key in testDict[tcname].keys():
                      value=testDict[tcname][key]
                      stopValueDict[key]=value
 
                  stopValueDict['stop']=timestamp
                  stopValueDict['duration']=tctime
                  testDict[tcname]=stopValueDict
 
                else:
                  errorfh.write('Warning: No match Stop element %s.\n' % element)
 
              elif level == 'Fail':
 
                tcpattern=re.compile("(Testcase): (.*),.*,.*, Last Status: fail, Message: KnownIssue: (.*)")
                tcmatch = tcpattern.search(message)
 
                if tcmatch:
                  tctype=tcmatch.group(1)
                  tcname=tcmatch.group(2)
                  tcissues=tcmatch.group(3)
                  if testDict.has_key(tcname):
                    for key in testDict[tcname].keys():
                      value=testDict[tcname][key]
                      failValueDict[key]=value
 
                  failValueDict['issue']=tcissues
                  testDict[tcname]=failValueDict
 
                else:
                  errorfh.write('Warning: No match Fail element %s.\n' % element)
 
              elif level == 'Status':
 
                tcpattern=re.compile("(Testcase): (.*), Pass: (.*), Fail: (.*), ElapsedTime: (.*), NumStarts: (.*)")
                tcmatch = tcpattern.search(message)
 
                if tcmatch:
                  tctype=tcmatch.group(1)
                  tcname=tcmatch.group(2)
                  tcpass=tcmatch.group(3)
                  tcfail=tcmatch.group(4)
                  tctime=tcmatch.group(5)
                  tcnums=tcmatch.group(6)
 
                  if testDict.has_key(tcname):
 
                    for key in testDict[tcname].keys():
                      value=testDict[tcname][key]
                      statusValueDict[key]=value
 
                  statusValueDict['pass']=tcpass
                  statusValueDict['fail']=tcfail
                  testDict[tcname]=statusValueDict
 
                else:
                  errorfh.write('Warning: No match Status element %s.\n' % element)
 
              elif level == 'Info':
                errorfh.write('Warning: Info element %s.\n' % element)
 
              else:
                errorfh.write('Error: Unknown element %s.\n' % element)
 
          finally:
            txtfh.close()
 
        except IOError:
          errorfh.write('Error: Unable to open %s. Reason IOError.' % textfile )
 
      </script>
 
      <message>'Starting to create results XML file.'</message>
      
      <script>
        # Create the objects
        localstaf =test_env.staf(STAF_LOCAL_HOSTNAME)
        remotestaf=test_env.staf(STAF_REMOTE_HOSTNAME)
 
        stax = test_env.stax(STAF_LOCAL_HOSTNAME)
        event = test_env.event(STAF_LOCAL_HOSTNAME)
        eventman = test_env.eventmanager(STAF_LOCAL_HOSTNAME)
        email = test_env.email(STAF_LOCAL_HOSTNAME)
        http = test_env.http(STAF_LOCAL_HOSTNAME)
        dsml = test_env.dsml(STAF_LOCAL_HOSTNAME)
 
        # Build the XML results file
        from xml.dom.minidom import Document
 
        def write_text_elements(parent,elements):
        
          for sutElement in elements:
            label,text = sutElement
            element = doc.createElement(label)
            parent.appendChild(element)
            try:
              element.appendChild(doc.createTextNode(text))
            except TypeError,details:
              element.appendChild(doc.createTextNode('TypeError: %s' % details))
 
        # Create the test results document
        doc = Document()
        
        # Create the qa base element
        qa = doc.createElement("qa")
        doc.appendChild(qa)
        
        # Create the functional-tests element
        ft = doc.createElement("%s" % TESTS_TYPE)
        qa.appendChild(ft)
        
        # Create the identification element
        id = doc.createElement("identification")
        ft.appendChild(id)
        
        # Create the sut opends element
        sut = doc.createElement("sut")
        sut.setAttribute("product", "opends")
        id.appendChild(sut)
                
        # Create the sut opends elements
        sutElementList=[]
        sutElementList.append(['name',ServerName])
        sutElementList.append(['path',ServerPath])
        sutElementList.append(['version',ServerVersion])
        sutElementList.append(['buildid',ServerBuildId])
        sutElementList.append(['revision',ServerRevision])
        sutElementList.append(['hostname',STAF_REMOTE_HOSTNAME])
        sutElementList.append(['platform',ServerSystemOS])
        sutElementList.append(['jvm-version',ServerJVMVersion])
        sutElementList.append(['jvm-label',ServerJVMString])
        sutElementList.append(['jvm-vendor',ServerJVMVendor])
        sutElementList.append(['jvm-arch',ServerJVMArchitecture])
        sutElementList.append(['jvm-args','TBD'])
        sutElementList.append(['jvm-home','TBD'])
        sutElementList.append(['jvm-bin','TBD'])
        sutElementList.append(['os-label',ServerOsString])
        sutElementList.append(['server-package',ServerPackage])
        sutElementList.append(['snmp-jarfile',ServerSNMPJarFile])
        sutElementList.append(['md5-sum','TDB'])
        
        write_text_elements(sut,sutElementList)
        
        # Create the sut dsml element
        sut = doc.createElement("sut")
        sut.setAttribute("product", "dsml")
        id.appendChild(sut)
        
        # Create the sut dsml elements
        sutElementList=[]
        sutElementList.append(['name',DSMLName])
        sutElementList.append(['dsml-container',DSMLContainer])
        sutElementList.append(['dsml-package',DSMLPackage])
        sutElementList.append(['md5-sum','TDB'])
        
        write_text_elements(sut,sutElementList)
        
        sutElementList=[]
        
        # Create the testware element
        testware = doc.createElement("testware")
        id.appendChild(testware)
        
        # Create the staf testware element
        staf = doc.createElement("staf")
        testware.appendChild(staf)
        
        # Create the staf local element
        local = doc.createElement("local")
        staf.appendChild(local)
        
        # Create the staf local testware elements
        testwareElementList=[]
        testwareElementList.append(['hostname',STAF_LOCAL_HOSTNAME])
        testwareElementList.append(['version',localstaf.version])
        testwareElementList.append(['rootdir',localstaf.root])
        
        write_text_elements(local,testwareElementList)
        
        # Create the staf remote testware element
        remote = doc.createElement("remote")
        staf.appendChild(remote)
        
        # Create the staf remote testware elements
        testwareElementList=[]
        testwareElementList.append(['hostname',STAF_REMOTE_HOSTNAME])
        testwareElementList.append(['version',remotestaf.version])
        testwareElementList.append(['rootdir',remotestaf.root])
        
        write_text_elements(remote,testwareElementList)
        
        for serviceType in [stax,event,eventman,email,http,dsml]:
        
          # Create the service testware element
          service = doc.createElement("service")
          service.setAttribute("name", serviceType.name)
          testware.appendChild(service)
        
          # Create the service testware elements
          testwareElementList=[]
          testwareElementList.append(['version',serviceType.version])
          testwareElementList.append(['library',serviceType.library])
          testwareElementList.append(['executable',serviceType.executable])
          testwareElementList.append(['options','%s' % serviceType.options])
          testwareElementList.append(['params','%s' % serviceType.params])
        
          write_text_elements(service,testwareElementList)
        
        testwareElementList=[]
        
        # Create the id elements
        idElementList=[]
        idElementList.append(['tests-dir',logsDir])
        idElementList.append(['tests-url',logsURI])
        idElementList.append(['mailto',SEND_MAIL_TO])
        
        write_text_elements(id,idElementList)
        
        idElementList=[]
        
        # Create the results element
        results = doc.createElement("results")
        ft.appendChild(results)
 
        # Create the results elements and attributes
        for tcname in testCaseList:
 
          print 'Processing %s' % tcname
 
          if testDict.has_key(tcname):
            tcnamesplit=tcname.split(":")
            if tcnamesplit[0]:
              tcgroup=tcnamesplit[0].strip()
              if tcnamesplit[1]:
                tcsuite=tcnamesplit[1].strip()
                try:
                  tcsuiteshort=tcsuite.split(".")[2].strip()
                except:
                  print 'Default test suite short name to %s.' % tcsuite
                  tcsuiteshort=tcsuite
              else:
                tcsuite=tcgroup
            else:
              tcgroup=tcname
              tcsuite=tcname
              tcsuiteshort=tcname
 
            if testDict[tcname].has_key('pass'):
              tcpass=testDict[tcname]['pass']
            else:
              tcpass='0'
 
            if testDict[tcname].has_key('fail'):
              tcfail=testDict[tcname]['fail']
            else:
              tcfail='0'
 
            if testDict[tcname].has_key('start'):
              tcstart=testDict[tcname]['start']
            else:
              tcstart='unknown'
 
            if testDict[tcname].has_key('stop'):
              tcstop=testDict[tcname]['stop']
            else:
              tcstop='unknown'
 
            if testDict[tcname].has_key('duration'):
              tcduration=testDict[tcname]['duration']
            else:
              tcduration='unknown'
 
            if testDict[tcname].has_key('issue'):
              tcissues=testDict[tcname]['issue']
            else:
              tcissues='unknown'
 
          else:
            errorfh.write('No key for testcase %s.\n' % tcname)
 
          if int(tcfail) == 0 and int(tcpass) > 0:
            tcresult='pass'
          elif int(tcfail) == 0 and int(tcpass) == 0:
            tcresult='unknown'
          else:
            tcresult='fail'
 
          tcshortname=get_test_name(tcname)
          tcdurationsecs=test_time().timeToSeconds(tcduration)
 
          # Create the testgroup element
          group = doc.createElement("testgroup")
          group.setAttribute("name", tcgroup.lower())
          results.appendChild(group)
          
          # Create the testsuite element
          suite = doc.createElement("testsuite")
          suite.setAttribute("name", tcsuite.lower())
          suite.setAttribute("shortname", tcsuiteshort.lower())
          group.appendChild(suite)
          
          # Create the testcase element
          case = doc.createElement("testcase")
          case.setAttribute("group", "%s" % tcgroup.lower())
          case.setAttribute("suite", "%s" % tcsuite.lower())
          case.setAttribute("name", "%s" % tcname.lower())
          case.setAttribute("shortname", "%s" % tcshortname.lower())
          case.setAttribute("result", "%s" % tcresult)
          case.setAttribute("start", "%s" % tcstart)
          case.setAttribute("stop", "%s" % tcstop)
          case.setAttribute("duration", "%s" % tcdurationsecs)
          if tcissues != 'unknown':
            issues = doc.createElement("issues")
            tcissuesList=eval(tcissues)
            for attr in tcissuesList:
              issue = doc.createElement("issue")
              issue.setAttribute("id", attr)
              issues.appendChild(issue)
            case.appendChild(issues)
          suite.appendChild(case)
 
        # Write out the results
        xmlfile= '%s/results.xml' % logsReportDir
        xmlfh=open(xmlfile,'w')
        xmlfh.writelines(doc.toprettyxml(indent="  "))
        xmlfh.close()
        errorfh.close()
      </script>
 
      <message>
        'XML Report Written to %s.' % xmlfile
      </message>
 
      <!-- Generate the standard test report showing all testcases -->
      <script>
        _message='Generated standard test report.'
        xslfile= '%s/gen-alltests-report.xsl' % TESTS_XSL_DIR
        htmlfile= '%s/results.html' % logsReportDir
 
        standardReport=report_generation()
 
        stringParamsDict={}
 
        try:
          standardReport.transformReport(xslfile,xmlfile,htmlfile,stringParamsDict)
        except java.io.FileNotFoundException,details:
          _message='Unable to generate standard test report %s.' % details
        except IOError,details:
          _message='Unable to generate standard test report %s.' % details
        except:
          _message='Unable to generate standard test report !!!'
      </script>
      <message>_message</message>
 
      <!-- Generate the test report by test groups-->
      <script>
        _message='Generated groups test report.'
        xslfile= '%s/gen-groups-report.xsl' % TESTS_XSL_DIR
        htmlfile= '%s/groups.html' % logsReportDir
        testslog= '%s/tests-log.xml' % logsTestsDir
        groupsReport=report_generation()
        stringParamsDict={}
 
        try:
          groupsReport.transformReport(xslfile,xmlfile,htmlfile,stringParamsDict)
        except java.io.FileNotFoundException,details:
          _message='Unable to generate groups test report %s.' % details
        except IOError,details:
          _message='Unable to generate groups test report %s.' % details
        except:
          _message='Unable to generate groups test report !!!'
      </script>
      <message>_message</message>
 
      <!-- Generate the test report by test suites -->
      <script>
        _message='Generated suites test reports.'
 
        testGroupDirsList=os.listdir(logsTestsDir)
        for testGroupName in testGroupDirsList:
 
          groupDir='%s/%s' % (logsTestsDir,testGroupName)
 
          if os.path.isdir(groupDir):
 
            xmlfile='%s/results.xml' % logsReportDir
            htmlfile='%s/%s.html' % (groupDir,testGroupName)
            xslfile= '%s/gen-suites-report.xsl' % TESTS_XSL_DIR
 
            suitesReport=report_generation()
            stringParamsDict={ 'group' : testGroupName }
 
            try:
              suitesReport.transformReport(xslfile,xmlfile,htmlfile,stringParamsDict)
            except java.io.FileNotFoundException,details:
              _message='Unable to generate suites test report %s.' % details
            except IOError,details:
              _message='Unable to generate suites test report %s.' % details
            except:
              _message='Unable to generate suites test report %s !!!' % groupDir
      </script>
      <message>_message</message>
 
      <!-- Generate the test case report by test suites -->
      <script>
        _message='Generated cases test reports.'
 
        testGroupDirsList=os.listdir(logsTestsDir)
        for testGroupName in testGroupDirsList:
 
          print 'group= %s' % testGroupName
 
          groupDir='%s/%s' % (logsTestsDir,testGroupName)
 
          if os.path.isdir(groupDir):
 
            import glob
            testSuiteFilesList=glob.glob('%s/*.xml' % groupDir)
 
            xmlfile='%s/results.xml' % logsReportDir
            xslfile= '%s/gen-tests-report.xsl' % TESTS_XSL_DIR
 
            for testSuiteFile in testSuiteFilesList:
 
              if os.path.isfile(testSuiteFile):            
                testSuiteName=os.path.basename(testSuiteFile.replace('-log.xml',''))
                try:
                  testSuiteShortName=testSuiteName.split('.')[2]
                except:
                  print 'Default test suite short name to %s.' % testSuiteName
                  testSuiteShortName=testSuiteName
 
                print 'suite= %s' %  testSuiteName
                
                htmlfile='%s/%s-report.html' % (groupDir,testSuiteShortName)
 
                stringParamsDict={ 'group' : testGroupName, 'suite' : testSuiteName, 'tests-log' : testslog }
 
                casesReport=report_generation()
    
                try:
                  casesReport.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 %s !!!' % groupDir
      </script>
      <message>_message</message>
      
      <!-- Generate the product identification report -->
       <script>
        _message='Generated product identification test report.' 
        xslfile= '%s/id.xsl' % TESTS_XSL_DIR
        htmlfile= '%s/id.html' % logsReportDir
 
        idReport=report_generation()
 
        stringParamsDict={}
 
        try:
          idReport.transformReport(xslfile,xmlfile,htmlfile,stringParamsDict)
        except java.io.FileNotFoundException,details:
          _message='Unable to generate product id test report %s.' % details
        except IOError,details:
          _message='Unable to generate product id test report %s.' % details
        except:
          _message='Unable to generate product id test report !!!'
      </script>
      <message>_message</message>
 
      <!-- Generate the summary text file -->
      <script>
        _message='Generated the summary text report'
        mysummaryxsl='%s/gen-text-summary.xsl' % TESTS_XSL_DIR
        mysummarytext='%s/summary.txt' % logsReportDir
        mysummaryxml=xmlfile
 
        summaryReport=report_generation()
 
        stringParamsDict={}
 
        try:
          summaryReport.transformReport(mysummaryxsl,mysummaryxml,mysummarytext,stringParamsDict)
        except IOError,details:
          _message='Unable to generate summary text file %s.' % details
      </script>
      <message>_message</message>
 
      <if expr="SEND_MAIL_AFTER_TEST_RUN == 'true'">
        <sequence>
          <message>
            'Sending Email Test Report to %s.' % SEND_MAIL_TO
          </message>
 
          <script>
            try:
              if SEND_MAIL_REPORT:
                MailSendReport=SEND_MAIL_REPORT
              else:
                MailSendReport='%s/groups.html' % logsReportDir
            except NameError,details:
                MailSendReport='%s/groups.html' % logsReportDir
 
            try:
              if SEND_MAIL_TO:
                MailToList= SEND_MAIL_TO.split(",")
              else:
                MailToList=[]
            except NameError,details:
                MailToList=[]
 
            try:
              if SEND_MAIL_SUBJECT:
                MailSubject= SEND_MAIL_SUBJECT
              else:
                MailSubject= 'OpenDS Test Report for %s' % STAF_REMOTE_HOSTNAME
            except NameError,details:
                MailSubject= 'OpenDS Test Report for %s' % STAF_REMOTE_HOSTNAME
 
            MailSendTo= ' '
          </script>
 
          <iterate var="Recipient" in="MailToList">
            <script>
             MailSendTo='to %s %s' % (Recipient,MailSendTo)
            </script>
          </iterate>
 
          <stafcmd name="'STAF Command: Send test report %s' % MailSendTo">
            <location>'%s' % STAF_LOCAL_HOSTNAME </location>
            <service>'email'</service>
            <request>
              'send %s contenttype "text/html" file %s subject "%s" noheader' % (MailSendTo,MailSendReport,MailSubject)
            </request>
          </stafcmd>
 
          <if expr="RC != 0">
            <message log="1" level="'Error'">
              'Send test report failed. RC: %s STAFResult: %s' % (RC,STAFResult)
            </message>
            <else>
              <message>
                'Send test report successful. RC: %s' % (RC)
              </message>
            </else>
          </if>
        </sequence>
      </if>
 
      <!-- Saving Staf/Stax logs -->
      <message>'Saving staf logs'</message>
 
      <call function="'ResolveVar'" >
        {
        'location' : STAF_LOCAL_HOSTNAME ,
        'type'     : 'STRING',
        'name'     : 'STAF/Config/STAFRoot'
        }
      </call>
      <if expr="RC != 0">
        <script>
          STAFResult = '{}'
        </script>
        <else>
          <script>
            STAFRoot = STAFResult
          </script>
        </else>
      </if>
 
      <script>
        listOfChildren2 = listOfChildren
        listOfChildren2.append(STAXJobID)
        listOfChildren2.append(STAXSubJobID)
      </script>
      <iterate var="thisChild" in="listOfChildren2">
        <sequence>
          <script>
            srcFile = '%s/logs/MACHINE/%s/GLOBAL/STAX_Job_%s.log' \
                      % (STAFRoot,STAF_LOCAL_HOSTNAME,thisChild)
            destFile = '%s/staf-logs/STAX_Job_%s.log' \
                       % (LOGS_ROOT,thisChild)
          </script>
          <process name="'Saving job logs.....'">
            <location>STAF_LOCAL_HOSTNAME</location>
            <command mode="'shell'">'%s/bin/fmtlog' % STAFRoot</command>
            <parms>'FORMAT LOGFILE %s NEWFILE %s' % (srcFile,destFile)</parms>
            <envs>'%s/lib' % STAFRoot</envs>
            <stderr mode="'stdout'"/>
            <returnstdout/>
          </process>
 
          <script>
            srcFile = '%s/logs/MACHINE/%s/GLOBAL/STAX_Job_%s_User.log' \
                      % (STAFRoot,STAF_LOCAL_HOSTNAME,thisChild)
            destFile = '%s/staf-logs/STAX_Job_%s_User.log' \
                       % (LOGS_ROOT,thisChild)
          </script>
          <process name="'Saving job user logs.....'">
            <location>STAF_LOCAL_HOSTNAME</location>
            <command mode="'shell'">'%s/bin/fmtlog' % STAFRoot</command>
            <parms>'FORMAT LOGFILE %s NEWFILE %s' % (srcFile,destFile)</parms>
            <envs>'%s/lib' % STAFRoot</envs>
            <stderr mode="'stdout'"/>
            <returnstdout/>
          </process>
        </sequence>
      </iterate>
 
    </sequence>
 
  </function>
</stax>