parser.py revision d81978a0815d5b8a75633c35e3e1f8708d36f017
# 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
# 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
# information:
# Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2008 Sun Microsystems, Inc.
#============================================================================
#
# GLOBAL VARIABLES
# Warning : some of global variables are also defined in main_run.xml file
NOT_DEFINED = 'ERROR_not_defined'
TRUE = 0
FALSE = 1
#============================================================================
#
# CLASS DEFINITION
#
# Class for phases
#
class Phase:
"Describes the phase of a system test run"
def getStartTime(self):
def getStopTime(self):
def getPercentage(self):
return self.percentage
#
# Class for external tools
#
###########################
class ExtTools:
"Describes all the external tools needed"
def getJdmkrtPath(self):
return self.jdmkrtPath
def getJcommonPath(self):
return self.jcommonPath
def getJfreechartPath(self):
return self.jfreechartPath
#
# Class for suffix
#
###########################
class Scenario:
"Describes the scenario main informations"
def getDescription(self):
return self.description
def getDurationUnit(self):
return self.durationUnit
def getDurationTime(self):
return self.durationTime
def getJdmkrtPath(self):
return self.jdmkrtPath
def getJcommonPath(self):
return self.jcommonPath
def getJfreechartPath(self):
return self.jfreechartPath
###########################
class SubordinateTemplate:
"Describes entry data information for ldif file"
###########################
class Branch:
"""Describes branch data information for ldif file :
[name, [list_of_branch], [list_of_leaf]]"""
def getSubtrees(self):
def getSubordinateTemplates(self):
return self.subordinateTemplates
###########################
class SuffixTopology:
"Describes the topology (list of instances,..) of a suffix"
def getInstanceRef(self):
return self.instanceRef
def getInitRule(self):
def getInstanceSourceName(self):
return self.instanceSourceName
###########################
class Suffix:
"""Describes suffix information,
tree is a list of Branch objectclasses
topology is a list of SuffixTopology objectclasses"""
def getSuffixDn(self):
def getTopology(self):
"Return the instance objectclass of the instance name given in parameter"
break
def getNbOfEntries(self):
return self.nbOfEntries
def getLdifFile(self):
#
# Class for opendsTuning
#
###########################
class OpendsTuning:
"Describes tuning informations for OpenDS instance"
def getJavaArgs(self):
def getXxNewSize(self):
def getXxMaxNewSize(self):
return self.xxMaxNewSize
def getXxSurvivorRatio(self):
return self.xxSurvivorRatio
def getXxPermSize(self):
return self.xxPermSize
def getXxMaxPermSize(self):
return self.xxMaxPermSize
def getXxUseConcMarkSweepGC(self):
return self.xxUseConcMarkSweepGC
return self.databaseCachePercentage
def getReplicationPurgeDelay(self):
return self.replicationPurgeDelay
#
# Class for instance
#
###########################
class Instance:
"Describes a generic LDAP instance"
portLDAP):
def getProduct(self):
def getInstallDir(self):
return self.installDir
def getTarball(self):
def getLDAPPort(self):
def getBuildId(self):
def getSynchroDate(self):
return self.synchroDate
###########################
class OpendsInstance(Instance):
"Describes an opends Instance"
# from instance object
# specific to opends instance
def getLDAPSPort(self):
def getJMXPort(self):
def getREPLPort(self):
def getSNMPPort(self):
def getJVMPort(self):
def getJavaVersion(self):
return self.javaVersion
def getIsSslEnabled(self):
return self.sslEnabled
def getCertificate(self):
return self.certificate
def getIsStartTlsEnabled(self):
return self.startTlsEnabled
def getSecureReplication(self):
return self.secureReplication
#
# Class for client
#
###########################
class Client:
"Describes a ldap client"
def getDependency(self):
return self.dependency
def getStartDate(self):
def getStopDate(self):
###########################
class Module:
"Describes a module that contains clients"
def getEnabled(self):
def getClients(self):
#============================================================================
#
# FUNCTIONS
#
def _getPropValue(myNode):
"This function get the first node text value of a node"
try:
#out = '%s' % (myNode.getNodeName())
else:
out = 'ERROR node has not a text children node type or is empty, should be' % \
(myNode.getNodeName())
except AttributeError:
return out
else:
return cAttrValue
#============================================================================
#
# PARSER
#
#document = STAXResult
# Change code here to parse the document as you desire.
# The code shown here is just an example for parsing a STAX xml document
msg = ''
globalParameters = []
instances = []
suffix = []
clientPhases = []
cId = 0
cId += 1
#
# Parsing global parameters node
#
#
# Parsing instance node
#
if cName == NOT_DEFINED:
return [msg,[],[]]
if cProduct == NOT_DEFINED:
return [msg,[],[]]
if cRole == NOT_DEFINED:
return [msg,[],[]]
#
# opends instance parsing
#
if cProduct == 'opends':
else:
#
# Parsing suffix node
#
# restriction 1 suffix node
#
# Parsing scheduler node : should be only one node
#
#
# Parsing other nodes...
#
# Do nothing
continue
# End of parsing
#
# Set duration time and unit to scenario object
#
#
# Set replication server host/port/installdir used by this suffix
#
# end of main function
#============================================================================
#
# Parse children and get information for opends instance
#
msg = ''
cHost = 'localhost'
cPortLDAP = '1389'
cPortLDAPS = '1636'
cPortJMX = '1689'
cPortREPL = '1391'
cSslEnabled = 'false'
cStartTlsEnabled = 'false'
cSecureReplication = 'false'
cIsJava = 'false'
#
# Parsing second level : host,ports,...
#
if thisChild.hasChildNodes():
# Get instance port values
if thisSubChild.hasChildNodes():
if cPortJVM == '':
# must be at the end of the if case
# text node information,skip, no need
continue
else:
msg = '%s\n ERROR: instance %s : unknown port node name %s' % \
# Get tuning values
if thisSubChild.hasChildNodes():
cIsJava = 'true'
'xxSurvivorRatio')
'xxUseConcMarkSweepGC')
# must be at the end of the if case
# text node information,skip, no need
continue
else:
msg = '%s\n ERROR: instance %s : unknown instance property named %s' %\
# end for
#
# no second level
#
else:
msg = '%s\n ERROR: instance %s : no children for instance node' % \
#
# extract the name of zip and add it to the installDir path
#
# 1. Remove the file path
# 2. Get the name of the file without the extension
#============================================================================
#
# Parse children and get information for suffix node
#
msg = ''
#
# Parsing second level : instanceList,numberOfEntries,...
#
if thisChild.hasChildNodes():
cSuffixReplServers = []
# Get instance names
if thisSubChild.hasChildNodes():
'instanceSourceName')
if cInstanceSourceName == NOT_DEFINED:
# must be at the end of the if case
# text node information,skip, no need
continue
else:
msg = '%s\n ERROR: parseSuffix(): unknown node named %s' % \
else:
msg = '%s\n ERROR: parseSuffix(): %s node should have child node %s'%\
# parsing suffix TREE
if thisSubChild.hasChildNodes():
else:
msg = '%s\n ERROR: parseSuffix(): %s node should have child node %s'%\
# must be at the end of the if case
# text node information,skip, no need
continue
else:
msg = '%s\n ERROR: parseSuffix(): unknown suffix property named %s' % \
#
# no subchildren for suffix node
#
else:
#============================================================================
#
# Get tree information
# a branch has :
# a name
# some branches (0 or more)
# some subordinateTemplate (0 or more)
msg = ''
# cSubordinateTemplates is a list of subordinateTemplates a node can have
# cBranches is a list of branches a node can have
cBranches = []
# get subordinateTemplate if exist
# if percentage, calculate the nb of entries,
# else get nb of entries directly
if cPerc != NOT_DEFINED:
else:
# must be at the end of the if case
# text node information,skip, no need
continue
else:
msg = '%s\n ERROR: getSuffixTree() : unknown node named %s' % \
if cBranches == []:
cBranches = [NOT_DEFINED]
if cSubordinateTemplates == []:
#============================================================================
#
# displayTree : display the data tree of a suffix with XML format
msg = ''
if cBranchName == 'root':
else:
# leaf
# subBranches
for cSubBranch in subBranches:
if cBranchName == 'root':
else:
return msg
#============================================================================
#
# getSuffixDataForMakeLDIF : display the data tree of a suffix
# using makedlif format
msg = ''
if cBranchName == 'root':
# leaf
# subBranches
for cSubBranch in subBranches:
return msg
#============================================================================
#
# Parse children and get information for scheduler node
#
def parseScheduler(thisChild):
msg = ''
scheduler = []
#
# Parsing second level : duration,module,...
#
if thisChild.hasChildNodes():
cClients = []
# must be at the end of the if case
# text node information,skip, no need
continue
else:
msg = '%s\n ERROR: parseScheduler() : unknown property named %s' % \
#
# no subchildren
#
else:
#============================================================================
#
# Parse children and get information for a list of clients
#
def parseClients(thisChild):
msg = ''
clients = []
#
# Parsing second level : phase,...
#
if thisChild.hasChildNodes():
params = []
# Get phase sub-nodes information
if thisSubChild.hasChildNodes():
# must be at the end of the if case
# text node information,skip, no need
continue
else:
msg = '%s\n ERROR: parseClients(): unknown node named %s' % \
else:
msg = '%s\n ERROR: parseClients(): %s node should have child %s' % \
if (start == NOT_DEFINED):
else:
if (stop != NOT_DEFINED):
if (dependency != NOT_DEFINED):
# must be at the end of the if case
# text node information,skip, no need
continue
else:
msg = '%s\n ERROR: parseClients() : unknown property named %s' % \
#
# no subchildren for suffix node
#
else:
#============================================================================
#
# Parse global parameters node
#
msg = ''
result = []
#
# Parsing second level
#
if thisChild.hasChildNodes():
# must be at the end of the if case
# text node information,skip, no need
continue
else:
msg = '%s\n ERROR: parseGlobalParameters(): unknown node named %s' % \
#
# no subchildren for globalParameters node
#
else:
if (opendsZip == NOT_DEFINED):
#============================================================================
#
# Parse global parameters node
#
def parseScenario(thisChild):
preMsg = 'ERROR: parseScenario():'
msg = ''
#
# Parsing second level
#
if thisChild.hasChildNodes():
# must be at the end of the if case
# text node information,skip, no need
continue
else:
msg = '%s\n %s: unknown node named %s' % \
#
# no subchildren for globalParameters node
#
else:
if (name == NOT_DEFINED):
if (description == NOT_DEFINED):
#============================================================================
#
# Parse global parameters node
#
def parseExternalTools(thisChild):
preMsg = 'ERROR: parseExternalTools():'
msg = ''
#
# Parsing second level
#
if thisChild.hasChildNodes():
# must be at the end of the if case
# text node information,skip, no need
continue
else:
msg = '%s\n %s: unknown node named %s' % \
#
# no subchildren for globalParameters node
#
else:
if (cJdmkrtPath != NOT_DEFINED):
if (cJfreeChartPath != NOT_DEFINED):
if (cJcommonPath != NOT_DEFINED):