common.py revision 5582
2788N/A#!/usr/bin/python
2788N/A
2788N/A# CDDL HEADER START
2788N/A#
2788N/A# The contents of this file are subject to the terms of the
2788N/A# Common Development and Distribution License, Version 1.0 only
2788N/A# (the "License"). You may not use this file except in compliance
2788N/A# with the License.
2788N/A#
2788N/A# You can obtain a copy of the license at
2788N/A# trunk/opends/resource/legal-notices/OpenDS.LICENSE
2788N/A# or https://OpenDS.dev.java.net/OpenDS.LICENSE.
2788N/A# See the License for the specific language governing permissions
2788N/A# and limitations under the License.
2788N/A#
2788N/A# When distributing Covered Code, include this CDDL HEADER in each
2788N/A# file and include the License file at
2788N/A# trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
2788N/A# add the following below this CDDL HEADER, with the fields enclosed
2788N/A# information:
2788N/A# Portions Copyright [yyyy] [name of copyright owner]
2788N/A#
2788N/A# CDDL HEADER END
2788N/A#
2788N/A#
4116N/A# Copyright 2007-2009 Sun Microsystems, Inc.
5429N/A# Portions Copyright 2011 ForgeRock AS.
2788N/A
2788N/A__version__ = "$Revision$"
2788N/A# $Source$
2788N/A
2788N/A# public symbols
3621N/A__all__ = [ "format_testcase",
3621N/A "directory_server_information",
3621N/A "test_time",
3621N/A "report_generation",
3621N/A "compare_file",
3621N/A "is_windows_platform",
3626N/A "create_property_table",
3666N/A "compare_property_table",
3816N/A "exception_thrown",
3816N/A "directory_server",
3818N/A "test_env",
3903N/A "staf_service",
4116N/A "get_test_name",
4116N/A "parse_stax_result",
4116N/A "dn2list",
4116N/A "list2dn",
4495N/A "dn2rfcmailaddr",
4777N/A "java_properties",
4974N/A "xmldoc_service" ,
4974N/A "xml_create_report" ,
5429N/A "group_to_run" ,
5429N/A "get_last_attr_from_entry" ,
5429N/A "list_matches" ,
5540N/A "count_attr" ,
5544N/A "host_is_localhost" ,
5544N/A "md5_hash"]
2788N/A
2788N/Aclass format_testcase:
2898N/A 'Format the Test name objects'
2788N/A def group(self,string):
2788N/A self.group=string.lower()
2788N/A self.group=self.group.strip()
2788N/A return '%s' % self.group
2788N/A def suite(self,string):
2788N/A self.suite=string.lower()
2788N/A self.suite=self.suite.strip()
2788N/A self.suite=self.suite.replace(' ','-')
2788N/A return '%s' % self.suite
2788N/A def name(self,string):
2788N/A self.name=string.strip()
2788N/A self.name=self.name.replace(' ','-')
2788N/A return '%s' % self.name
2788N/A
2788N/Aclass directory_server_information:
2898N/A 'Container for Information about Directory Servers'
2788N/A def __init__(self):
2788N/A self.line=''
2788N/A self.key=''
2788N/A self.value=''
2788N/A self.VersionList=[]
2788N/A self.SystemList=[]
2788N/A self.ServerDict={}
2788N/A self.SystemDict={}
2788N/A
4716N/A def getServerVersion(self,string,productname):
4716N/A return string.replace("%s " % productname,"")
2788N/A
2788N/A def getServerBuildId(self,string):
2788N/A return string.replace("Build ","")
2788N/A
2788N/A def getServerOSName(self,string):
2788N/A return string[0:string.find(' ')].strip()
2788N/A
2788N/A def getServerArch(self,string):
2788N/A return string[string.rfind(' ') +1:len(string)].strip()
2788N/A
2788N/A def getServerJavaMajorMinor(self,string):
2788N/A return string[0:string.rfind('.')]
2788N/A
2788N/A def getServerValueFromString(self,string):
2788N/A return string[string.find(':') +1:len(string)].strip()
2788N/A
2788N/A def getServerValueFromKey(self,string,result):
2788N/A return result[string]
2788N/A
2898N/Aclass test_time:
2898N/A 'Simple time related manipulation objects'
2898N/A def __init__(self):
2898N/A self.seconds=0
2898N/A self.minutes=0
2898N/A self.hours=0
2898N/A
2898N/A def timeToSeconds(self,clocktime):
2898N/A self.hours,self.minutes,self.seconds=clocktime.split(':')
2898N/A return int(self.hours)*7200+int(self.minutes)*60+int(self.seconds)
2898N/A
3032N/Aclass basic_utils:
3032N/A 'Some simple basic utilities'
3032N/A def printKey(self,keypair):
3032N/A self.key=keypair.keys()[0]
3032N/A return self.key
3032N/A def printKeyValue(self,keypair):
3032N/A self.key=keypair.keys()[0]
3032N/A self.keyvalue=keypair[self.key]
3032N/A return self.keyvalue
3032N/A
2898N/Aclass report_generation:
2898N/A 'Test Report Generation'
3032N/A
3292N/A def transformReport(self,stylesheet,xml,output,params):
2898N/A from java.io import FileInputStream
2898N/A from java.io import FileOutputStream
2898N/A from java.io import ByteArrayOutputStream
2898N/A
2898N/A from javax.xml.transform import TransformerFactory
2898N/A from javax.xml.transform.stream import StreamSource
2898N/A from javax.xml.transform.stream import StreamResult
2898N/A
3176N/A self.xsl = FileInputStream("%s" % stylesheet)
3176N/A self.xml = FileInputStream("%s" % xml)
3176N/A self.html = FileOutputStream("%s" % output)
2898N/A
3176N/A try:
3176N/A self.xslSource = StreamSource(self.xsl)
3176N/A self.tfactory = TransformerFactory.newInstance()
3176N/A self.xslTemplate = self.tfactory.newTemplates(self.xslSource)
3176N/A self.transformer = self.xslTemplate.newTransformer()
2898N/A
3176N/A self.source = StreamSource(self.xml)
3176N/A self.result = StreamResult(self.html)
3176N/A
3292N/A for self.key,self.value in params.items():
3292N/A self.transformer.setParameter(self.key, self.value)
3292N/A
3176N/A self.transformer.transform(self.source, self.result)
3826N/A
3176N/A finally:
3176N/A self.xsl.close()
3176N/A self.xml.close()
3176N/A self.html.close()
2898N/A
3292N/Aclass exception_thrown:
3292N/A 'User defined exceptions handlers'
3292N/A def __init__(self):
3292N/A self.message = ''
3292N/A self.flag = ''
3032N/A
3287N/Aclass compare_file:
3287N/A 'Compare two files'
3287N/A
3287N/A def __init__(self, file1, file2, diffFile):
3287N/A self.file1 = file1
3287N/A self.file2 = file2
3287N/A self.diffFile = diffFile
3287N/A
3287N/A def genDiff(self):
3287N/A from org.tmatesoft.svn.core.wc import *
3287N/A from java.io import File
3287N/A from java.io import FileOutputStream
3287N/A
3287N/A diff = DefaultSVNDiffGenerator()
3287N/A diff.displayFileDiff("",
3287N/A File("%s" % self.file1),
3287N/A File("%s" % self.file2),
3287N/A self.file1,
3287N/A self.file2,
3287N/A "text/plain",
3287N/A "text/plain",
3287N/A FileOutputStream(File("%s" % self.diffFile)))
3287N/A
3287N/A try:
3287N/A ret_str = ""
3287N/A diff_file = open(self.diffFile, "r")
3287N/A for line in diff_file.readlines():
3287N/A ret_str = ret_str + line
3287N/A return ret_str
3287N/A finally:
3287N/A diff_file.close()
3621N/A
3621N/Adef is_windows_platform(host):
3621N/A from java.lang import Boolean
3621N/A from com.ibm.staf import STAFHandle
3621N/A from com.ibm.staf import STAFResult
3621N/A
3818N/A handle = STAFHandle("varHandle")
3621N/A res = handle.submit2(host, "VAR", "GET SYSTEM VAR STAF/Config/OS/Name")
3621N/A
4865N/A winLower = res.result.lower()
4865N/A winNdx = winLower.find("win")
4865N/A if winNdx != -1:
4865N/A return res.result[winNdx:]
3621N/A else:
3621N/A return Boolean.FALSE
3626N/A
3626N/Adef create_property_table(output, separator):
4495N/A 'Create a table from an output'
4495N/A
3626N/A table = {}
3626N/A
3626N/A for line in output.splitlines():
3626N/A key = line.split(separator)[0].strip()
3626N/A try:
3626N/A value = line.split(separator)[1].strip()
3626N/A except IndexError:
3666N/A value = ''
3626N/A table[key] = value
3626N/A
3626N/A return table
3666N/A
3666N/Adef compare_property_table(refTable, newTable):
4495N/A 'Compare two tables'
4495N/A
3666N/A import re
3666N/A
3666N/A result = ''
3666N/A
4495N/A refKeys = newTable.keys()
3666N/A for refKey in refKeys:
3666N/A if not refTable.has_key(refKey):
3666N/A result = result + 'ERROR: Entry ' + refKey + ' does not exists'
3666N/A result = result + ' in the reference table.\n'
3666N/A
4495N/A refKeys = refTable.keys()
3666N/A for refKey in refKeys:
3666N/A if not newTable.has_key(refKey):
3666N/A result = result + 'ERROR: Entry ' + refKey + ' does not exists'
3666N/A result = result + ' in the new table.\n'
3666N/A else:
3666N/A result = result + refKey + '=> expected: ' + refTable[refKey]
3666N/A result = result + ' , result: ' + newTable[refKey] + '\n'
3666N/A
3666N/A if refTable[refKey] != newTable[refKey]:
3666N/A result = result + 'ERROR: Value for ' + refKey
3666N/A result = result + ' should be the same.\n'
3666N/A
3666N/A return result
3816N/A
3816N/Aclass directory_server:
3816N/A 'Container to hold DS instance objects'
3816N/A def __init__(self):
3816N/A self.location=''
3816N/A self.host=''
3816N/A self.port=''
3816N/A self.dn=''
3816N/A self.password=''
4618N/A self.suffix=''
4116N/A self.backend=''
3816N/A
3816N/A def location(self,location):
3816N/A return location
3816N/A
3816N/A def host(self,name):
3816N/A return name
3816N/A
3816N/A def port(self,port):
3816N/A return port
3816N/A
3855N/A def adminport(self,port):
3855N/A return adminport
3855N/A
3816N/A def dn(self,dn):
3816N/A return dn
3816N/A
3816N/A def password(self,pswd):
3816N/A return pswd
3816N/A
3816N/A def suffix(self,sfx):
3816N/A return sfx
3816N/A
4116N/A def backend(self,be):
4116N/A return be
4116N/A
3818N/Aclass staf_service:
3834N/A 'Container to hold staf service instance objects'
3818N/A def __init__(self,host,name):
3818N/A from com.ibm.staf import STAFHandle
3818N/A from com.ibm.staf import STAFResult
3818N/A from com.ibm.staf import STAFMarshallingContext
3818N/A
3834N/A self.name=name
3834N/A self.library='Unknown'
3834N/A self.executable='Unknown'
3834N/A self.options='Unknown'
3834N/A self.params='Unknown'
3834N/A
3834N/A try:
3834N/A __handle = STAFHandle("varHandle")
3834N/A except STAFException, e:
3834N/A pass
3818N/A
3818N/A __cmd = 'QUERY SERVICE %s' % name
3818N/A __res = __handle.submit2(host, "SERVICE", __cmd)
3834N/A
3834N/A if (__res.rc == 0):
3834N/A
3834N/A __context = STAFMarshallingContext.unmarshall(__res.result)
3834N/A __entryMap = __context.getRootObject()
3818N/A
3834N/A self.name=__entryMap['name']
3834N/A self.library=__entryMap['library']
3834N/A self.executable=__entryMap['executable']
3834N/A self.options=__entryMap['options']
3834N/A self.params=__entryMap['parameters']
3818N/A
3818N/A def get_library(self):
3818N/A return self.library
3818N/A
3818N/A def get_name(self):
3818N/A return self.name
3818N/A
3818N/A def get_executable(self):
3818N/A return self.executable
3818N/A
3818N/A def get_options(self):
3818N/A return self.options
3818N/A
3826N/A def get_params(self):
3826N/A return self.params
3818N/A
3816N/Aclass test_env:
3816N/A 'Container to hold test environment instance objects'
3816N/A def __init__(self):
3816N/A self.environment=''
3818N/A
3818N/A class staf:
3818N/A 'Container to hold staf objects'
3818N/A def __init__(self,host):
3818N/A from com.ibm.staf import STAFHandle
3818N/A from com.ibm.staf import STAFResult
3818N/A
3818N/A __handle = STAFHandle("varHandle")
3818N/A __cmd = 'Version'
3818N/A __res = __handle.submit2(host, "MISC", __cmd)
3818N/A self.version=__res.result
3818N/A
3818N/A self.name='STAF'
3818N/A
3818N/A __cmd = 'GET SYSTEM VAR STAF/Config/STAFRoot'
3818N/A __res = __handle.submit2(host, "VAR", __cmd)
3818N/A self.root=__res.result
3818N/A
3818N/A def get_version(self):
3818N/A return self.version
3818N/A
3818N/A def get_name(self):
3818N/A return self.name
3818N/A
3818N/A def get_root(self):
3818N/A return self.version
3818N/A
3818N/A class stax(staf_service):
3818N/A 'Container to hold stax service objects'
3818N/A def __init__(self,host,name='STAX'):
3818N/A from com.ibm.staf import STAFHandle
3818N/A from com.ibm.staf import STAFResult
3818N/A
3818N/A if hasattr(staf_service, '__init__'):
3818N/A staf_service.__init__(self,host,name)
3818N/A
3818N/A __handle = STAFHandle("varHandle")
3818N/A
3818N/A __cmd = 'Version'
3818N/A __res = __handle.submit2(host, "STAX", __cmd)
3818N/A self.version=__res.result
3818N/A
3818N/A def get_version(self):
3818N/A return self.version
3818N/A
3818N/A class event(staf_service):
3818N/A 'Container to hold event service objects'
3818N/A def __init__(self,host,name='EVENT'):
3818N/A from com.ibm.staf import STAFHandle
3818N/A from com.ibm.staf import STAFResult
3818N/A
3818N/A if hasattr(staf_service, '__init__'):
3818N/A staf_service.__init__(self,host,name)
3818N/A
3818N/A __handle = STAFHandle("varHandle")
3818N/A __cmd = 'Version'
3818N/A __res = __handle.submit2(host, "EVENT", __cmd)
3818N/A self.version=__res.result
3818N/A
3818N/A def get_version(self):
3818N/A return self.version
3818N/A
3818N/A class eventmanager(staf_service):
3818N/A 'Container to hold event manager service objects'
3818N/A def __init__(self,host,name='EVENTMANAGER'):
3818N/A from com.ibm.staf import STAFHandle
3818N/A from com.ibm.staf import STAFResult
3818N/A
3818N/A if hasattr(staf_service, '__init__'):
3818N/A staf_service.__init__(self,host,name)
3818N/A
3818N/A __handle = STAFHandle("varHandle")
3818N/A __cmd = 'Version'
3818N/A __res = __handle.submit2(host, "EVENTMANAGER", __cmd)
3818N/A self.version=__res.result
3818N/A
3818N/A def get_version(self):
3818N/A return self.version
3818N/A
3818N/A class email(staf_service):
3818N/A 'Container to hold email service objects'
3818N/A def __init__(self,host,name='EMAIL'):
3818N/A from com.ibm.staf import STAFHandle
3818N/A from com.ibm.staf import STAFResult
3818N/A from com.ibm.staf import STAFMarshallingContext
3818N/A
3818N/A if hasattr(staf_service, '__init__'):
3818N/A staf_service.__init__(self,host,name)
3818N/A
3818N/A __handle = STAFHandle("varHandle")
3818N/A __cmd = 'Version'
3818N/A __res = __handle.submit2(host, "EMAIL", __cmd)
3818N/A self.version=__res.result
3818N/A self.recipients= 'TODO: get from config.py'
3818N/A
3818N/A __res = __handle.submit2(host, "EMAIL", "LIST SETTINGS")
3818N/A __context = STAFMarshallingContext.unmarshall(__res.result)
3818N/A __entryMap = __context.getRootObject()
3818N/A
3818N/A self.server=__entryMap['mailServer']
3818N/A self.port=__entryMap['port']
3818N/A
3818N/A def get_version(self):
3818N/A return self.version
3818N/A
3818N/A def get_recipients(self):
3818N/A return self.recipients
3818N/A
3818N/A def get_server(self):
3818N/A return self.server
3818N/A
3818N/A def get_port(self):
3818N/A return self.port
3818N/A
3818N/A class http(staf_service):
3818N/A 'Container to hold http service objects'
3818N/A def __init__(self,host,name='HTTP'):
3818N/A from com.ibm.staf import STAFHandle
3818N/A from com.ibm.staf import STAFResult
3818N/A
3818N/A if hasattr(staf_service, '__init__'):
3818N/A staf_service.__init__(self,host,name)
3818N/A
3818N/A __handle = STAFHandle("varHandle")
3818N/A __res = __handle.submit2(host, "HTTP", "Version")
3818N/A self.version=__res.result
3818N/A
3818N/A def get_version(self):
3818N/A return self.version
3818N/A
3818N/A class dsml(staf_service):
3818N/A 'Container to hold dsml service objects'
3818N/A def __init__(self,host,name='DSML'):
3818N/A from com.ibm.staf import STAFHandle
3818N/A from com.ibm.staf import STAFResult
3818N/A
3818N/A if hasattr(staf_service, '__init__'):
3818N/A staf_service.__init__(self,host,name)
3818N/A
3818N/A __handle = STAFHandle("varHandle")
3818N/A
3818N/A self.version='Unknown'
3818N/A
3818N/A def get_version(self):
3818N/A return self.version
3816N/A
3816N/A class source:
3816N/A 'Container to hold source data instance objects'
4259N/A def __init__(self,dir,tests_type):
3816N/A self.directory=dir
4259N/A self.data='%s/%s/shared/data' % (dir,tests_type)
3816N/A self.common='%s/shared' % dir
3816N/A self.java='%s/java' % self.common
3816N/A
3816N/A def get_directory(self):
3816N/A return self.directory
3816N/A
3816N/A def get_data(self):
3816N/A return self.data
3816N/A
3816N/A def get_common(self):
3816N/A return self.common
3816N/A
3816N/A def get_java(self):
3816N/A return self.java
3816N/A
3816N/A class logs:
3816N/A 'Container to hold test log instance objects'
3816N/A def __init__(self,dir):
3816N/A self.directory=dir
3816N/A self.tests='%s/testlogs' % dir
3816N/A self.reports='%s/reports' % dir
3816N/A self.sut='%s/sutlogs' % dir
3816N/A
3816N/A def get_directory(self):
3816N/A return self.directory
3816N/A
3816N/A def get_tests(self):
3816N/A return self.tests
3816N/A
3816N/A def get_reports(self):
3816N/A return self.reports
3816N/A
3816N/A def get_sut(self):
3816N/A return self.sut
3816N/A
3816N/A class data:
3816N/A 'Container to hold local and remote test data instance objects'
3816N/A def __init__(self,dir):
3816N/A self.directory=dir
5540N/A self.testdata='%s/testdata' % dir
3816N/A self.java='%s/java' % self.testdata
3816N/A self.data='%s/data' % self.testdata
3816N/A self.temp='%s/temp' % dir
3816N/A self.reldatadir='testdata/data'
3816N/A self.reljavadir='testdata/java'
3816N/A
3816N/A def get_directory(self):
3816N/A return self.directory
3816N/A
3816N/A def get_testdata(self):
3816N/A return self.testdata
3816N/A
3816N/A def get_java(self):
3816N/A return self.java
3816N/A
3816N/A def get_data(self):
3816N/A return self.data
3816N/A
3816N/A def get_temp(self):
3816N/A return self.temp
3816N/A
3816N/A def get_reldatadir(self):
3816N/A return self.directory
3816N/A
3816N/A def get_reljavadir(self):
3816N/A return self.directory
3816N/A
5540N/A def set_data(self,dir):
5540N/A self.data=dir
5540N/A
3903N/Adef get_test_name(name):
3903N/A i=2
3903N/A __name=''
3903N/A __tn=name.split(':')
3903N/A while i < len(__tn):
3903N/A __name += '%s:' % __tn[i]
3903N/A i=i+1
3903N/A return __name[0:-1].strip()
3903N/A
4116N/Adef parse_stax_result(result):
3903N/A
4116N/A import org.python.core
3903N/A
4116N/A if result.__class__ is org.python.core.PyList:
4116N/A _unwrapResult=result[1][0]
4116N/A
4116N/A try:
4116N/A _functionString=_unwrapResult[1]
4116N/A except AttributeError:
4116N/A _functionString='Unable to parse result.'
4116N/A elif result.__class__ is org.python.core.PyString:
4116N/A _functionString=STAXResult
4116N/A else:
4116N/A _functionString='Unable to parse result.'
4116N/A
4116N/A return _functionString
4116N/A
4116N/Adef dn2list(dn):
4116N/A __list=dn.split(',')
4116N/A return __list
4116N/A
4116N/Adef list2dn(list):
4116N/A return ",".join(list)
4116N/A
4116N/Adef dn2rfcmailaddr(dn):
4116N/A __addr=[]
4116N/A __list=dn.split(',')
4116N/A for __rdn in __list:
4116N/A __rhside=__rdn.split('=')[1]
4116N/A __addr.append(__rhside)
4116N/A return ".".join(__addr).lower()
4116N/A
4495N/Adef java_properties(propFile, toolsName, optionList):
4495N/A 'Update java.properties file'
4495N/A
4495N/A import fileinput
4495N/A import string
4495N/A import sys
4495N/A
4495N/A try:
4495N/A file = open(propFile, "r")
4495N/A content = file.read()
4495N/A file.close()
4495N/A
4495N/A newfile = open(propFile, "w")
4495N/A for line in content.splitlines():
4495N/A if line.startswith(toolsName):
4495N/A newline = line.split("=")[0] + "="
4495N/A for item in optionList:
4495N/A newline = newline + item + " "
4495N/A newfile.write("%s\n" % newline)
4495N/A else:
4495N/A newfile.write("%s\n" % line)
4495N/A newfile.close()
4495N/A
4495N/A return 0
4495N/A except:
4495N/A print "Exception:", sys.exc_info()[0]
4495N/A
4495N/A return 1
4777N/A
4777N/Aclass xmldoc_service:
4777N/A
4777N/A def __init__(self):
4777N/A self.testgroup=''
4777N/A self.testsuite=''
4777N/A self.testcase=''
4865N/A self.issues=''
4865N/A self.issue=''
4777N/A
4777N/A def createBlankDocument(self):
4777N/A try:
4777N/A import sys, traceback
4777N/A from javax.xml.parsers import DocumentBuilderFactory
4777N/A builderFactory=DocumentBuilderFactory.newInstance()
4777N/A return builderFactory.newDocumentBuilder()
4777N/A except:
4777N/A print "exception: %s" % traceback.format_exception(*sys.exc_info())
4777N/A
4777N/A def writeXMLfile(self,doc,xmlfile):
4777N/A try:
4777N/A import sys, traceback
4777N/A from java.io import File
4777N/A from javax.xml.transform import TransformerFactory
4777N/A from javax.xml.transform import OutputKeys
4777N/A from javax.xml.transform.stream import StreamResult
4777N/A from javax.xml.transform.dom import DOMSource
4777N/A tranFactory = TransformerFactory.newInstance();
4777N/A aTransformer = tranFactory.newTransformer();
4777N/A aTransformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1")
4777N/A aTransformer.setOutputProperty(OutputKeys.INDENT, "yes")
4777N/A
4777N/A src = DOMSource(doc);
4777N/A dest = StreamResult(File(xmlfile));
4777N/A aTransformer.transform(src, dest);
4777N/A except:
4777N/A print "exception: %s" % traceback.format_exception(*sys.exc_info())
4777N/A
5582N/A def printXMLfile(self,doc):
5582N/A try:
5582N/A from javax.xml.transform import TransformerFactory
5582N/A from javax.xml.transform import OutputKeys
5582N/A from javax.xml.transform.stream import StreamSource
5582N/A from javax.xml.transform.stream import StreamResult
5582N/A from javax.xml.transform.dom import DOMSource
5582N/A from java.io import StringWriter
5582N/A
5582N/A xmlInput = DOMSource(doc);
5582N/A xmlOutput = StreamResult(StringWriter());
5582N/A
5582N/A tranFactory = TransformerFactory.newInstance();
5582N/A aTransformer = tranFactory.newTransformer();
5582N/A aTransformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1")
5582N/A aTransformer.setOutputProperty(OutputKeys.INDENT, "yes");
5582N/A aTransformer.transform(xmlInput, xmlOutput);
5582N/A
5582N/A print xmlOutput.getWriter().toString()
5582N/A except:
5582N/A print "exception: %s" % traceback.format_exception(*sys.exc_info())
5582N/A
4777N/A def parseXMLfile(self,xmlfile):
4777N/A try:
4777N/A import sys, traceback
4777N/A from java.io import FileInputStream
4777N/A self.builder= self.createBlankDocument()
4777N/A self.input = FileInputStream(xmlfile)
4777N/A self.doc = self.builder.parse(self.input)
4777N/A self.input.close()
4777N/A return self.doc
4777N/A except:
4777N/A print "exception: %s" % traceback.format_exception(*sys.exc_info())
4777N/A
4777N/A def createAttr(self,doc,tag,attr,value):
4777N/A try:
4777N/A import sys, traceback
4777N/A newAttribute= doc.createAttribute(attr)
4777N/A newAttribute.setValue('%s' % value)
4777N/A tag.setAttributeNode(newAttribute)
4777N/A except:
4777N/A print "exception: %s" % traceback.format_exception(*sys.exc_info())
4974N/A
4974N/Adef xml_add_text_node(doc,parent,name,ntext):
4974N/A
4974N/A node = doc.createElement(name)
4974N/A text = doc.createTextNode('%s' % ntext)
4974N/A node.appendChild(text)
4974N/A parent.appendChild(node)
4974N/A
4974N/Adef xml_create_report(pname,type,path,info,misc,testdir,report):
4974N/A
4974N/A xml=xmldoc_service()
4974N/A
4974N/A builder = xml.createBlankDocument()
4974N/A
4974N/A doc = builder.newDocument()
4974N/A root = doc.createElement("qa")
4974N/A doc.appendChild(root)
4974N/A ft = doc.createElement("%s" % type)
4974N/A root.appendChild(ft);
4974N/A
4974N/A # Identification
4974N/A id = doc.createElement("identification")
4974N/A ft.appendChild(id)
4974N/A
4974N/A sut = doc.createElement("sut")
4974N/A xml.createAttr(doc,sut,"product","opends")
4974N/A id.appendChild(sut)
4974N/A
4974N/A xml_add_text_node(doc,sut,'name',pname)
4974N/A xml_add_text_node(doc,sut,'path',path)
4974N/A xml_add_text_node(doc,sut,'version',info['server version'])
4974N/A xml_add_text_node(doc,sut,'buildid',info['server buildid'])
4974N/A xml_add_text_node(doc,sut,'revision',info['svn revision'])
4974N/A xml_add_text_node(doc,sut,'hostname',info['system name'])
4974N/A xml_add_text_node(doc,sut,'platform',info['system os'])
4974N/A xml_add_text_node(doc,sut,'jvm-version',info['jvm version'])
4974N/A xml_add_text_node(doc,sut,'jvm-label',misc['jvm label'])
4974N/A xml_add_text_node(doc,sut,'jvm-vendor',info['jvm vendor'])
4974N/A xml_add_text_node(doc,sut,'jvm-arch',info['jvm architecture'])
4974N/A xml_add_text_node(doc,sut,'jvm-args','TBD')
4974N/A xml_add_text_node(doc,sut,'jvm-home','TBD')
4974N/A xml_add_text_node(doc,sut,'jvm-bin','TDB')
4974N/A xml_add_text_node(doc,sut,'os-label',misc['os label'])
4974N/A xml_add_text_node(doc,sut,'server-package',misc['server package'])
4974N/A xml_add_text_node(doc,sut,'snmp-jarfile',misc['snmp jarfile'])
4974N/A xml_add_text_node(doc,sut,'md5-sum','TBD')
4974N/A
4974N/A xml_add_text_node(doc,id,'tests-dir',testdir)
4974N/A
4974N/A # Test Results
4974N/A results = doc.createElement("results")
4974N/A ft.appendChild(results)
4974N/A
4974N/A xml.writeXMLfile(doc,report)
4974N/A
4974N/Aclass group_to_run:
4974N/A def __init__(self, name):
4974N/A self.name = name
4974N/A
4974N/A def getName(self):
4974N/A return self.name
4974N/A
5429N/Adef get_last_attr_from_entry(result,attribute):
5429N/A
5429N/A changeEntry=result[0][1].split("\n")
5429N/A
5475N/A attrVal=''
5429N/A for changeAttr in changeEntry:
5429N/A #print changeAttr
5429N/A if changeAttr.startswith(attribute):
5475N/A #print 'get_last_attr_from_entry: %s' % changeAttr
5475N/A attrVal = changeAttr.replace('%s: ' % attribute,'')
5429N/A
5475N/A if attrVal != '' and attrVal[len(attrVal)-1] == ';' :
5475N/A lastAttr = attrVal[0:len(attrVal)-1]
5475N/A else:
5475N/A lastAttr = attrVal
5475N/A
5475N/A print 'get_last_attr_from_entry: %s' % lastAttr
5475N/A return lastAttr
5429N/A
5429N/Adef list_matches(mylist):
5429N/A
5429N/A mycomp = 'True'
5429N/A itemnum = 0
5429N/A
5429N/A for item in mylist:
5429N/A if not item:
5429N/A # TODO: list item is empty do WARNING or ERROR
5429N/A print "list_matches: WARNING: list item %s is empty." % itemnum
5429N/A if item != mylist[0]:
5429N/A print "list_matches: False. Match=(%s), Item=(%s)" % (mylist[0],item)
5429N/A mycomp = 'False'
5429N/A itemnum += 1
5429N/A
5429N/A return mycomp
5429N/A
5429N/Adef count_attr(result):
5429N/A
5429N/A attrnum = 0
5429N/A if result != None:
5429N/A
5429N/A for attr in result[0][1].split('\n'):
5429N/A if attr.startswith('dn:'):
5429N/A print "Hit: attr (%s)" % attr
5429N/A attrnum += 1
5429N/A
5429N/A return attrnum
5429N/A
5540N/Adef host_is_localhost(hostname):
5540N/A from socket import gethostbyname
5540N/A if gethostbyname(hostname).startswith('127.0'):
5540N/A return 1
5540N/A else:
5540N/A return 0
5540N/A
5540N/Adef hosts_are_same(hostname1,hostname2):
5540N/A from socket import gethostbyname
5540N/A if hostname1 == hostname2:
5540N/A return 1
5540N/A else:
5540N/A return 0
5540N/A
5544N/Adef md5_hash():
5544N/A try:
5544N/A import hashlib
5544N/A m = hashlib.md5()
5544N/A except ImportError:
5544N/A import md5
5544N/A m = md5.new()
5544N/A return m