common.py revision 3855
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#
3232N/A# Copyright 2007-2008 Sun Microsystems, Inc.
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",
3818N/A "staf_service" ]
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
2788N/A def getServerVersion(self,string):
2788N/A return string.replace("OpenDS Directory Server ","")
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 import re
3621N/A
3818N/A handle = STAFHandle("varHandle")
3621N/A res = handle.submit2(host, "VAR", "GET SYSTEM VAR STAF/Config/OS/Name")
3621N/A
3621N/A winPattern=re.compile('win', re.IGNORECASE)
3621N/A if (winPattern.search(res.result) != None):
3621N/A return Boolean.TRUE
3621N/A else:
3621N/A return Boolean.FALSE
3626N/A
3626N/Adef create_property_table(output, separator):
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):
3666N/A import re
3666N/A
3666N/A result = ''
3666N/A
3666N/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
3666N/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=''
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
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'
3816N/A def __init__(self,dir):
3816N/A self.directory=dir
3816N/A self.data='%s/functional-tests/shared/data' % dir
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
3816N/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