test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Functions
conditionUploadTest Namespace Reference

Classes

class  DB
 
class  UploadTest
 

Functions

def main
 
def makeBaseFile
 
def makeMetadataFile
 
def uploadFile
 

Function Documentation

def conditionUploadTest.main ( )

Definition at line 165 of file conditionUploadTest.py.

References makeBaseFile().

166 def main():
167  print 'Testing...'
168  serviceName = 'cms_orcoff_prep'
169  schemaName = 'CMS_CONDITIONS'
170  db = DB(serviceName,schemaName)
171  db.connect()
172  inputTag = 'runinfo_31X_mc'
173  bfile0 = makeBaseFile( inputTag,1)
174  bfile1 = makeBaseFile( inputTag,100)
175  test = UploadTest( db )
176  # test with synch=any
177  tag = 'test_CondUpload_any'
178  test.upload( inputTag, bfile0, tag, 'any', 1, True, 'CREATE' )
179  test.upload( inputTag, bfile1, tag, 'any', 1, False, 'FAIL' )
180  test.upload( inputTag, bfile0, tag, 'any', 200, True, 'APPEND' )
181  test.upload( inputTag, bfile0, tag, 'any', 100, True, 'INSERT')
182  test.upload( inputTag, bfile0, tag, 'any', 200, True, 'INSERT')
183  db.removeTag( tag )
184  # test with synch=validation
185  tag = 'test_CondUpload_validation'
186  test.upload( inputTag, bfile0, tag, 'validation', 1, True, 'CREATE')
187  db.setSynchronizationType( tag, 'validation' )
188  test.upload( inputTag, bfile0, tag, 'validation', 1, True, 'INSERT')
189  test.upload( inputTag, bfile0, tag, 'validation', 200, True, 'APPEND')
190  test.upload( inputTag, bfile0, tag, 'validation', 100, True, 'INSERT')
191  db.removeTag( tag )
192  # test with synch=mc
193  tag = 'test_CondUpload_mc'
194  test.upload( inputTag, bfile1, tag, 'mc', 1, False, 'FAIL')
195  test.upload( inputTag, bfile0, tag, 'mc', 1, True, 'CREATE')
196  db.setSynchronizationType( tag, 'mc' )
197  test.upload( inputTag, bfile0, tag, 'mc', 1, False, 'FAIL')
198  test.upload( inputTag, bfile0, tag, 'mc', 200, False, 'FAIL')
199  db.removeTag( tag )
200  # test with synch=hlt
201  tag = 'test_CondUpload_hlt'
202  test.upload( inputTag, bfile0, tag, 'hlt', 1, True, 'CREATE')
203  db.setSynchronizationType( tag, 'hlt' )
204  test.upload( inputTag, bfile0, tag, 'hlt', 200, True, 'SYNCHRONIZE')
205  fcsr = test.upload( inputTag, bfile0, tag, 'hlt', 100, True, 'SYNCHRONIZE')
206  if not fcsr is None:
207  since = fcsr + 200
208  test.upload( inputTag, bfile0, tag, 'hlt', since, True, 'APPEND')
209  since = fcsr + 100
210  test.upload( inputTag, bfile0, tag, 'hlt', since, True, 'INSERT')
211  db.removeTag( tag )
212  # test with synch=express
213  tag = 'test_CondUpload_express'
214  test.upload( inputTag, bfile0, tag, 'express', 1, True, 'CREATE')
215  db.setSynchronizationType( tag, 'express' )
216  test.upload( inputTag, bfile0, tag, 'express', 200, True, 'SYNCHRONIZE')
217  fcsr = test.upload( inputTag, bfile0, tag, 'express', 100, True, 'SYNCHRONIZE')
218  if not fcsr is None:
219  since = fcsr + 200
220  test.upload( inputTag, bfile0, tag, 'express', since, True, 'APPEND')
221  since = fcsr + 100
222  test.upload( inputTag, bfile0, tag, 'express', since, True, 'INSERT')
223  db.removeTag( tag )
224  # test with synch=prompt
225  tag = 'test_CondUpload_prompt'
226  test.upload( inputTag, bfile0, tag, 'prompt', 1, True, 'CREATE')
227  db.setSynchronizationType( tag, 'prompt' )
228  test.upload( inputTag, bfile0, tag, 'prompt', 200, True, 'SYNCHRONIZE')
229  fcsr = test.upload( inputTag, bfile0, tag, 'prompt', 100, True, 'SYNCHRONIZE')
230  if not fcsr is None:
231  since = fcsr + 200
232  test.upload( inputTag, bfile0, tag, 'prompt', since, True, 'APPEND')
233  since = fcsr + 100
234  test.upload( inputTag, bfile0, tag, 'prompt', since, True, 'INSERT')
235  db.removeTag( tag )
236  # test with synch=pcl
237  tag = 'test_CondUpload_pcl'
238  test.upload( inputTag, bfile0, tag, 'pcl', 1, True, 'CREATE')
239  db.setSynchronizationType( tag, 'pcl' )
240  test.upload( inputTag, bfile0, tag, 'pcl', 200, False, 'FAIL')
241  if not fcsr is None:
242  since = fcsr + 200
243  test.upload( inputTag, bfile0, tag, 'pcl', since, True, 'APPEND')
244  since = fcsr + 100
245  test.upload( inputTag, bfile0, tag, 'pcl', since, True, 'INSERT')
246  db.removeTag( tag )
247  # test with synch=offline
248  tag = 'test_CondUpload_offline'
249  test.upload( inputTag, bfile0, tag, 'offline', 1, True, 'CREATE')
250  db.setSynchronizationType( tag, 'offline' )
251  test.upload( inputTag, bfile0, tag, 'offline', 1000, True, 'APPEND')
252  test.upload( inputTag, bfile0, tag, 'offline', 500, False, 'FAIL' )
253  test.upload( inputTag, bfile0, tag, 'offline', 1000, False, 'FAIL' )
254  test.upload( inputTag, bfile0, tag, 'offline', 2000, True, 'APPEND' )
255  db.removeTag( tag )
256  # test with synch=runmc
257  tag = 'test_CondUpload_runmc'
258  test.upload( inputTag, bfile0, tag, 'runmc', 1, True, 'CREATE')
259  db.setSynchronizationType( tag, 'runmc' )
260  test.upload( inputTag, bfile0, tag, 'runmc', 1000, True, 'APPEND')
261  test.upload( inputTag, bfile0, tag, 'runmc', 500, False, 'FAIL' )
262  test.upload( inputTag, bfile0, tag, 'runmc', 1000, False, 'FAIL' )
263  test.upload( inputTag, bfile0, tag, 'runmc', 2000, True, 'APPEND' )
264  db.removeTag( tag )
265  os.remove( bfile0 )
266  os.remove( bfile1 )
267  print 'Done. Errors: %s' %test.errors
def conditionUploadTest.makeBaseFile (   inputTag,
  startingSince 
)

Definition at line 54 of file conditionUploadTest.py.

Referenced by main().

54 
55 def makeBaseFile( inputTag, startingSince ):
56  cwd = os.getcwd()
57  baseFile = '%s_%s.db' %(inputTag,startingSince)
58  baseFilePath = os.path.join(cwd,baseFile)
59  if os.path.exists( baseFile ):
60  os.remove( baseFile )
61  command = "conddb_import -c sqlite_file:%s -f oracle://cms_orcon_adg/CMS_CONDITIONS -i %s -t %s -b %s" %(baseFile,inputTag,inputTag,startingSince)
62  pipe = subprocess.Popen( command, shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
63  out = pipe.communicate()[0]
64  if not os.path.exists( baseFile ):
65  msg = 'ERROR: base file has not been created: %s' %out
66  raise Exception( msg )
67  return baseFile
68 
def conditionUploadTest.makeMetadataFile (   inputTag,
  destTag,
  since,
  description 
)

Definition at line 69 of file conditionUploadTest.py.

Referenced by conditionUploadTest.UploadTest.upload().

69 
70 def makeMetadataFile( inputTag, destTag, since, description ):
71  cwd = os.getcwd()
72  metadataFile = os.path.join(cwd,'%s.txt') %destTag
73  if os.path.exists( metadataFile ):
74  os.remove( metadataFile )
75  metadata = {}
76  metadata[ "destinationDatabase" ] = "oracle://cms_orcoff_prep/CMS_CONDITIONS"
77  tagList = {}
78  tagList[ destTag ] = { "dependencies": {}, "synchronizeTo": "any" }
79  metadata[ "destinationTags" ] = tagList
80  metadata[ "inputTag" ] = inputTag
81  metadata[ "since" ] = since
82  metadata[ "userText" ] = description
83  fileName = destTag+".txt"
84  with open( fileName, "w" ) as file:
85  file.write(json.dumps(metadata,file,indent=4,sort_keys=True))
def conditionUploadTest.uploadFile (   fileName,
  logFileName 
)

Definition at line 86 of file conditionUploadTest.py.

Referenced by conditionUploadTest.UploadTest.upload().

86 
87 def uploadFile( fileName, logFileName ):
88  command = "uploadConditions.py %s" %fileName
89  pipe = subprocess.Popen( command, shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
90  out = pipe.communicate()[0]
91  lines = out.split('\n')
92  ret = False
93  for line in lines:
94  if line.startswith('\t '):
95  if line.startswith('\t status : -2'):
96  print 'ERROR: upload of file %s failed.' %fileName
97  if line.startswith('\t %s' %fileName):
98  returnCode = line.split('\t %s :' %fileName)[1].strip()
99  if returnCode == 'True':
100  ret = True
101  with open(logFileName,'a') as logFile:
102  logFile.write(out)
103  return ret