ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/PRODREQUEST/injectRequest.py
Revision: 1.7
Committed: Thu May 10 17:36:10 2007 UTC (17 years, 11 months ago) by eulisse
Content type: text/x-python
Branch: MAIN
CVS Tags: V00-08-00, V00-07-09, V00-07-08, V00-07-07, V00-07-06, V00-07-05, V00-07-04, V00-07-03, V00-07-02, V00-07-01, V00-07-00, gePreProdManagerSupport, V00-06-08, V00-06-07, V00-06-06, V00-06-05, V00-06-04, V00-06-03, V00-06-02, V00-06-01, HEAD
Changes since 1.6: +1 -1 lines
Error occurred while calculating annotation data.
Log Message:
* PRODREQUEST changed ProdRequest
* submitRequest now points to the security module.
* ProdRequest moved to use the new SecurityModule from WEBTOOLS.
* ProdRequestDBS moved to use the new security Module.
* Now getGlobalProductionStatus () behaves correctly if no database is there.

File Contents

# Content
1 #!/usr/bin/env python
2 from os import getenv
3 from sys import argv
4 from xml.sax import parse
5 from xml.sax.handler import ContentHandler
6 from os.path import abspath, exists
7 from optparse import OptionParser
8
9 #from Utilities.InjectionUtilities import _call, createPSetHash, createPythonConfig
10
11 ###
12 ###
13 ###
14 import popen2
15 import sys
16
17 def createPSetHash(cfgFile):
18 hashFile = "%s.hash" % cfgFile
19 pop = popen2.Popen4("EdmConfigHash < %s > %s " % (cfgFile, hashFile))
20 pop.wait()
21 exitStatus = pop.poll()
22 if exitStatus:
23 msg = "Error creating PSet Hash file:\n"
24 msg += pop.fromchild.read()
25 raise RuntimeError, msg
26
27 content = file(hashFile).read()
28 return content.strip()
29
30 def createPythonConfig(cfgFile):
31 pycfgFile = cfgFile.replace(".cfg", ".pycfg")
32 pop = popen2.Popen4("EdmConfigToPython < %s > %s " % (cfgFile, pycfgFile))
33 pop.wait()
34 exitStatus = pop.poll()
35 if exitStatus:
36 msg = "Error creating Python cfg file:\n"
37 msg += pop.fromchild.read()
38 raise RuntimeError, msg
39
40 pop = popen2.Popen4("%s %s" % (sys.executable, pycfgFile))
41 pop.wait()
42 exitStatus = pop.poll()
43 if exitStatus:
44 msg = "Error importing Python cfg file:\n"
45 msg += pop.fromchild.read()
46 raise RuntimeError, msg
47
48 return pycfgFile
49
50 from cStringIO import StringIO
51 import urllib2
52 import gzip
53
54 def _encode(args):
55 boundary = '----------=_PRODREQUEST_CGI_BOUNDARY_=-----------'
56 (body, crlf) = ('', '\r\n')
57 for key, value in args.items():
58 body += '--' + boundary + crlf
59 body += ('Content-disposition: form-data; name="%s"' % key) + crlf
60 body += crlf + value + crlf
61 body += '--' + boundary + '--' + crlf + crlf
62 return ('multipart/form-data; boundary=' + boundary, body)
63
64 def _marshall(args, request):
65 (type, body) = _encode(args)
66 request.add_header ('Content-type', type)
67 request.add_header ('Content-length', str(len(body)))
68 request.add_data (body)
69
70 def _call (url, args):
71 try:
72 #request = urllib2.Request (self._cgiUrl, urllib.urlencode(args))
73 request = urllib2.Request (url)
74 request.add_header ('Accept-encoding', 'gzip')
75 _marshall (args, request)
76 result = urllib2.build_opener ().open (request)
77 data = result.read()
78 if result.headers.get ('Content-encoding', '') == 'gzip':
79 data = gzip.GzipFile (fileobj=StringIO(data)).read ()
80 return data
81 except:
82 pass
83
84 ###
85 ###
86 ###
87
88
89 class RelValContentHandler (ContentHandler):
90 def __init__ (self, version, relval, directory, hostAndPort):
91 ContentHandler.__init__ (self)
92 self.events = None
93 self.testStarted = False
94 self.workflowName = None
95 self.cfgFile = None
96 self.version = version
97 self.relval = relval
98 self.directory = directory
99 self.hostAndPort = hostAndPort
100
101 def startElement (self, name, attributes):
102 if name == "Test":
103 self.events = attributes.getValueByQName ("Events")
104 self.workflowName = attributes.getValueByQName ("Name")
105 self.testStarted = True
106
107 def characters (self, data):
108 if self.testStarted:
109 if data.strip (" \t\n") != "":
110 self.cfgFile = data.strip ("\n\t ")
111
112 def endElement (self, name):
113 if name == "Test":
114 print self.events
115 print self.workflowName
116 print self.cfgFile
117 self.inject ()
118 self.testStarted = False
119 pass
120
121 def inject (self):
122 prodrequestUrl="http://%s/ProdRequest/createPayloadWithEntry" % self.hostAndPort
123 cfgfile = "%s/%s" % (self.directory, self.cfgFile)
124
125 if not exists (cfgfile):
126 print cfgfile + " not found."
127 pass
128
129 cfg = file (cfgfile).read ()
130 pycfgfile = createPythonConfig(cfgfile)
131 pycfg = file (pycfgfile).read ()
132 psetHash = createPSetHash (cfgfile)
133
134 cfgname = "%s - %s" % (self.relval, self.version)
135 _call (prodrequestUrl,
136 {"name": self.workflowName,
137 "parameterset": cfg,
138 "parsed_parameterset": pycfg,
139 "pset_hash": psetHash,
140 "primary_dataset": self.workflowName,
141 "output_dataset": "output_dataset",
142 "workflowName": cfgname,
143 "version": self.version})
144
145
146 def injectRequest (confFilename, hostAndPort):
147 confFilename = abspath (confFilename)
148 print confFilename
149 directory = confFilename.rsplit ("/", 1)[0]
150 relval = confFilename.rsplit ("/", 1)[1].rsplit (".", 1)[0]
151 cmsswVersion = getenv ("CMSSW_VERSION")
152 if cmsswVersion:
153 print "CMSSW version is " + cmsswVersion
154 handler = RelValContentHandler (version=cmsswVersion, relval=relval, directory=directory, hostAndPort=hostAndPort)
155 parser = parse (confFilename, handler)
156
157 if __name__ == "__main__":
158 optionParser = OptionParser ()
159 optionParser.add_option ("-u", "--url", dest="url",
160 metavar="URL", default="localhost:8030",
161 help="ProdRequest url")
162 optlist, args = optionParser.parse_args ()
163 for i in args:
164 injectRequest (i, optlist.url)