[Zope-CVS] CVS: Packages/FunctionalTests/FunctionalTests -
ScenarioGenerator.py:1.5.2.1
Karl Anderson
cvs-admin at zope.org
Mon Nov 3 21:20:27 EST 2003
Update of /cvs-repository/Packages/FunctionalTests/FunctionalTests
In directory cvs.zope.org:/tmp/cvs-serv13643
Modified Files:
Tag: kra-misc-branch
ScenarioGenerator.py
Log Message:
ScenarioGenerator:
Added support to read response files as well as request files.
Default logfile prefixes and extensions match those of tcpwatch.
parseOptions():
Added knob to change response file extension.
ProcessFile():
Accept response file name argument. If not None, put it's response
header code into the result skeleton.
ProcessScenario():
Get response file names when they are present and match a read request
file, and send to processFile().
=== Packages/FunctionalTests/FunctionalTests/ScenarioGenerator.py 1.5 => 1.5.2.1 ===
--- Packages/FunctionalTests/FunctionalTests/ScenarioGenerator.py:1.5 Fri May 23 18:09:37 2003
+++ Packages/FunctionalTests/FunctionalTests/ScenarioGenerator.py Mon Nov 3 21:20:27 2003
@@ -66,8 +66,9 @@
_verbosity = 1
_capture_cookies = 0
_logfile_directory = '/tmp'
- _logfile_prefix = 'zft'
- _logfile_extension = 'out'
+ _logfile_prefix = 'watch'
+ _logfile_extension_req = 'request'
+ _logfile_extension_resp = 'response'
_output_file = None
_exclude_patterns = []
_exclude_file = None
@@ -105,8 +106,11 @@
-f, --logfile-prefix Prefix for log file names
(default '%(LOGFILE_PREFIX)s')
- -e, --logfile-extension Extension for log file names
- (default '%(LOGFILE_EXTENSION)s')
+ -e, --logfile-extension Extension for log file request names
+ (default '%(LOGFILE_EXTENSION_REQ)s')
+
+ -E, --logfile-response Extension for log file response names
+ (default '%(LOGFILE_EXTENSION_RESP)s')
-o, --output-file Write to 'file', instead of default
(%(LOGFILE_PREFIX)s.zft).
@@ -127,7 +131,8 @@
%(MESSAGE)s\n""" % { 'GENERATOR_EXE' : sys.argv[0]
, 'LOGFILE_DIRECTORY' : self._logfile_directory
, 'LOGFILE_PREFIX' : self._logfile_prefix
- , 'LOGFILE_EXTENSION' : self._logfile_extension
+ , 'LOGFILE_EXTENSION_REQ' : self._logfile_extension_req
+ , 'LOGFILE_EXTENSION_RESP' : self._logfile_extension_resp
, 'MESSAGE' : msg or ''
} )
sys.exit( 1 )
@@ -138,12 +143,13 @@
"""
verbosity = self._verbosity
capture_cookies = self._capture_cookies
- logfile_directory = logfile_prefix = logfile_extension = None
+ logfile_directory = logfile_prefix = None
+ logfile_extension_req = logfile_extension_resp = None
output_file = exclude_file = site_host = site_path = None
try:
opts, ignored = getopt.getopt( args
- , "?vqcCl:f:e:o:x:X:h:p:"
+ , "?vqcCl:f:e:E:o:x:X:h:p:"
, [ 'help'
, 'verbose'
, 'quiet'
@@ -152,6 +158,7 @@
, 'logfile-directory='
, 'logfile-prefix='
, 'logfile-extension='
+ , 'logfile-extension-response='
, 'output-file'
, 'exclude-pattern'
, 'exclude-file'
@@ -186,7 +193,10 @@
logfile_prefix = v
if o == '-e' or o == '--logfile-extension':
- logfile_extension = v
+ logfile_extension_req = v
+
+ if o == '-E' or o == '--logfile-extension-response':
+ logfile_extension_resp = v
if o == '-o' or o == '--output-file':
output_file = v
@@ -212,8 +222,11 @@
if logfile_prefix is not None:
self._logfile_prefix = logfile_prefix
- if logfile_extension is not None:
- self._logfile_extension = logfile_extension
+ if logfile_extension_req is not None:
+ self._logfile_extension_req = logfile_extension_req
+
+ if logfile_extension_resp is not None:
+ self._logfile_extension_resp = logfile_extension_resp
if site_host is not None:
self._site_host = site_host
@@ -330,24 +343,28 @@
return self._exclude_regex
def processFile( self
- , filename
+ , infilename
+ , outfilename
, request_num
, parms={}
, REQUEST_LINE=re.compile( r'^([^\s]+)\s+'
r'([^\s]+)\s+'
r'([^\s]+)$' )
+ , RESPONSE_LINE=re.compile( r'^([^\s]+)\s+'
+ r'([0-9][0-9][0-9])\s+'
+ r'(.*)$' )
):
"""
Process a single request file; record global context
in parms.
"""
- self._log( 'Scanning file: %s' % filename, 1 )
+ self._log( 'Scanning request file: %s' % infilename, 1 )
parms[ 'content_type' ] = None
parms[ 'header_count' ] = 0
parms[ 'cookie_count' ] = 0
- f = open( filename )
+ f = open( infilename )
all_text = f.read()
f.seek( 0 )
@@ -421,8 +438,19 @@
else:
handler( self, payload )
+ if outfilename:
+ self._log( 'Scanning response file: %s' % outfilename, 1 )
+ f = open( outfilename )
+ # could exclude here as well
+ status = f.readline().rstrip()
+ match = RESPONSE_LINE.match( status )
+ http_verb, code, reason = match.groups()
+ f.close()
+ else:
+ code = 200
+
self._print( _RESULT_SKELETON
- , RESULT_CODE=200 # TODO: Read from response?
+ , RESULT_CODE=int(code)
)
return request_num
@@ -430,16 +458,20 @@
def processScenario( self ):
"""
Read all files in '_logfile_directory' whose prefix
- matches '_logfile_prefix' and '_logfile_extension;
- create a scenario file with one section per request file,
- dumping to specified output file.
+ matches '_logfile_prefix', '_logfile_extension_req', and
+ '_logfile_extension_resp'; create a scenario file with one
+ section per request file, dumping to specified output file.
"""
self._print( _SCENARIO_SKELETON )
- glob_pattern = '%s/%s_*.%s' % ( self._logfile_directory
- , self._logfile_prefix
- , self._logfile_extension
- )
+ glob__in_pattern = '%s/%s_*.%s' % ( self._logfile_directory
+ , self._logfile_prefix
+ , self._logfile_extension_req
+ )
+ glob__out_pattern = '%s/%s_*.%s' % ( self._logfile_directory
+ , self._logfile_prefix
+ , self._logfile_extension_resp
+ )
request_num = 0
parms = { 'saw_authentication' : 0
@@ -447,11 +479,29 @@
, 'site_path' : self._site_path
}
- filenames = glob.glob( glob_pattern )
- filenames.sort()
- for filename in filenames:
- request_num = self.processFile( filename, request_num, parms )
-
+ infilenames = glob.glob( glob__in_pattern )
+ infilenames.sort()
+ outfilenames = glob.glob( glob__out_pattern )
+ outfilenames.sort()
+ for infilename in infilenames:
+ outfilename = re.sub( self._logfile_extension_req + '$'
+ , self._logfile_extension_resp
+ , infilename
+ )
+ # XXX error if missing? Optional outfile processing?
+ if outfilename in outfilenames:
+ request_num = self.processFile( infilename
+ , outfilename
+ , request_num
+ , parms
+ )
+ else:
+ request_num = self.processFile( infilename
+ , None
+ , request_num
+ , parms
+ )
+
self._print( _DEFAULT_SKELETON % parms )
if __name__ == '__main__':
More information about the Zope-CVS
mailing list