22 pipe = subprocess.Popen( command, shell=
True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
23 out = pipe.communicate()[0]
28 if c !=
' ' and c !=
'\n':
33 db = cx_Oracle.connect(self.
connStr)
36 cursor.execute(
'UPDATE TAG SET SYNCHRONIZATION =:SYNCH WHERE NAME =:NAME',(synchType,tag,))
40 db = cx_Oracle.connect(self.
connStr)
42 cursor.execute(
'SELECT SINCE, INSERTION_TIME FROM IOV WHERE TAG_NAME =:TAG_NAME AND INSERTION_TIME >:TIME ORDER BY INSERTION_TIME DESC',(tag,snapshot))
43 row = cursor.fetchone()
47 db = cx_Oracle.connect(self.
connStr)
50 cursor.execute(
'DELETE FROM IOV WHERE TAG_NAME =:TAG_NAME',(tag,))
51 cursor.execute(
'DELETE FROM TAG WHERE NAME=:NAME',(tag,))
56 baseFile =
'%s_%s.db' %(inputTag,startingSince)
57 baseFilePath = os.path.join(cwd,baseFile)
58 if os.path.exists( baseFile ):
60 command =
"conddb_import -c sqlite_file:%s -f oracle://cms_orcon_adg/CMS_CONDITIONS -i %s -t %s -b %s" %(baseFile,inputTag,inputTag,startingSince)
61 pipe = subprocess.Popen( command, shell=
True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
62 out = pipe.communicate()[0]
63 if not os.path.exists( baseFile ):
64 msg =
'ERROR: base file has not been created: %s' %out
71 metadataFile = os.path.join(cwd,
'%s.txt') %destTag
72 if os.path.exists( metadataFile ):
73 os.remove( metadataFile )
75 metadata[
"destinationDatabase" ] =
"oracle://cms_orcoff_prep/CMS_CONDITIONS"
77 tagList[ destTag ] = {
"dependencies": {},
"synchronizeTo":
"any" }
78 metadata[
"destinationTags" ] = tagList
79 metadata[
"inputTag" ] = inputTag
80 metadata[
"since" ] = since
81 metadata[
"userText" ] = description
82 fileName = destTag+
".txt"
83 with open( fileName,
"w" )
as file:
84 file.write(json.dumps(metadata,file,indent=4,sort_keys=
True))
87 command =
"uploadConditions.py %s" %fileName
88 pipe = subprocess.Popen( command, shell=
True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
89 out = pipe.communicate()[0]
90 lines = out.split(
'\n')
93 if line.startswith(
'\t '):
94 if line.startswith(
'\t status : -2'):
95 print 'ERROR: upload of file %s failed.' %fileName
96 if line.startswith(
'\t %s' %fileName):
97 returnCode = line.split(
'\t %s :' %fileName)[1].strip()
98 if returnCode ==
'True':
100 with open(logFileName,
'a')
as logFile:
116 def upload( self, inputTag, baseFile, destTag, synchro, destSince, success, expectedAction ):
118 destFile =
'%s.db' %destTag
119 metaDestFile =
'%s.txt' %destTag
120 shutil.copyfile( baseFile, destFile )
121 self.
log(
'# ---------------------------------------------------------------------------')
122 self.
log(
'# Testing tag %s with synch=%s, destSince=%s - expecting ret=%s action=%s' %(destTag,synchro,destSince,success,expectedAction))
124 descr =
'Testing conditionsUpload with synch:%s - expected action: %s' %(synchro,expectedAction)
126 beforeUpload = datetime.datetime.utcnow()
129 self.
log(
'ERROR: the return value for the upload of tag %s with sychro %s was %s, while the expected result is %s' %(destTag,synchro,ret,success))
132 row = self.db.getLastInsertedSince( destTag, beforeUpload )
134 if expectedAction ==
'CREATE' or expectedAction ==
'INSERT' or expectedAction ==
'APPEND':
135 if destSince != row[0]:
136 self.
log(
'ERROR: the since inserted is %s, expected value is %s - expected action: %s' %(row[0],destSince,expectedAction))
139 self.
log(
'# OK: Found expected value for last since inserted: %s timestamp: %s' %(row[0],row[1]))
140 insertedSince = row[0]
141 elif expectedAction ==
'SYNCHRONIZE':
142 if destSince == row[0]:
143 self.
log(
'ERROR: the since inserted %s has not been synchronized with the FCSR - expected action: %s' %(row[0],expectedAction))
146 self.
log(
'# OK: Found synchronized value for the last since inserted: %s timestamp: %s' %(row[0],row[1]))
147 insertedSince = row[0]
149 self.
log(
'ERROR: found an appended since %s - expected action: %s' %(row[0],expectedAction))
153 self.
log(
'ERROR: found new insered since: %s timestamp: %s' %(row[0],row[1]))
155 if expectedAction !=
'FAIL':
156 self.
log(
'ERROR: Upload failed. Expected value: %s' %(destSince))
159 self.
log(
'# OK: Upload failed as expected.')
160 os.remove( destFile )
161 os.remove( metaDestFile )
167 serviceName =
'cms_orcoff_prep'
168 schemaName =
'CMS_CONDITIONS'
169 db =
DB(serviceName,schemaName)
171 inputTag =
'runinfo_31X_mc'
176 tag =
'test_CondUpload_any'
177 test.upload( inputTag, bfile0, tag,
'any', 1,
True,
'CREATE' )
178 test.upload( inputTag, bfile1, tag,
'any', 1,
False,
'FAIL' )
179 test.upload( inputTag, bfile0, tag,
'any', 200,
True,
'APPEND' )
180 test.upload( inputTag, bfile0, tag,
'any', 100,
True,
'INSERT')
181 test.upload( inputTag, bfile0, tag,
'any', 200,
True,
'INSERT')
184 tag =
'test_CondUpload_validation'
185 test.upload( inputTag, bfile0, tag,
'validation', 1,
True,
'CREATE')
186 db.setSynchronizationType( tag,
'validation' )
187 test.upload( inputTag, bfile0, tag,
'validation', 1,
True,
'INSERT')
188 test.upload( inputTag, bfile0, tag,
'validation', 200,
True,
'APPEND')
189 test.upload( inputTag, bfile0, tag,
'validation', 100,
True,
'INSERT')
192 tag =
'test_CondUpload_mc'
193 test.upload( inputTag, bfile1, tag,
'mc', 1,
False,
'FAIL')
194 test.upload( inputTag, bfile0, tag,
'mc', 1,
True,
'CREATE')
195 db.setSynchronizationType( tag,
'mc' )
196 test.upload( inputTag, bfile0, tag,
'mc', 1,
False,
'FAIL')
197 test.upload( inputTag, bfile0, tag,
'mc', 200,
False,
'FAIL')
200 tag =
'test_CondUpload_hlt'
201 test.upload( inputTag, bfile0, tag,
'hlt', 1,
True,
'CREATE')
202 db.setSynchronizationType( tag,
'hlt' )
203 test.upload( inputTag, bfile0, tag,
'hlt', 200,
True,
'SYNCHRONIZE')
204 fcsr = test.upload( inputTag, bfile0, tag,
'hlt', 100,
True,
'SYNCHRONIZE')
207 test.upload( inputTag, bfile0, tag,
'hlt', since,
True,
'APPEND')
209 test.upload( inputTag, bfile0, tag,
'hlt', since,
True,
'INSERT')
212 tag =
'test_CondUpload_express'
213 test.upload( inputTag, bfile0, tag,
'express', 1,
True,
'CREATE')
214 db.setSynchronizationType( tag,
'express' )
215 test.upload( inputTag, bfile0, tag,
'express', 200,
True,
'SYNCHRONIZE')
216 fcsr = test.upload( inputTag, bfile0, tag,
'express', 100,
True,
'SYNCHRONIZE')
219 test.upload( inputTag, bfile0, tag,
'express', since,
True,
'APPEND')
221 test.upload( inputTag, bfile0, tag,
'express', since,
True,
'INSERT')
224 tag =
'test_CondUpload_prompt'
225 test.upload( inputTag, bfile0, tag,
'prompt', 1,
True,
'CREATE')
226 db.setSynchronizationType( tag,
'prompt' )
227 test.upload( inputTag, bfile0, tag,
'prompt', 200,
True,
'SYNCHRONIZE')
228 fcsr = test.upload( inputTag, bfile0, tag,
'prompt', 100,
True,
'SYNCHRONIZE')
231 test.upload( inputTag, bfile0, tag,
'prompt', since,
True,
'APPEND')
233 test.upload( inputTag, bfile0, tag,
'prompt', since,
True,
'INSERT')
236 tag =
'test_CondUpload_pcl'
237 test.upload( inputTag, bfile0, tag,
'pcl', 1,
True,
'CREATE')
238 db.setSynchronizationType( tag,
'pcl' )
239 test.upload( inputTag, bfile0, tag,
'pcl', 200,
False,
'FAIL')
242 test.upload( inputTag, bfile0, tag,
'pcl', since,
True,
'APPEND')
244 test.upload( inputTag, bfile0, tag,
'pcl', since,
True,
'INSERT')
247 tag =
'test_CondUpload_offline'
248 test.upload( inputTag, bfile0, tag,
'offline', 1,
True,
'CREATE')
249 db.setSynchronizationType( tag,
'offline' )
250 test.upload( inputTag, bfile0, tag,
'offline', 1000,
True,
'APPEND')
251 test.upload( inputTag, bfile0, tag,
'offline', 500,
False,
'FAIL' )
252 test.upload( inputTag, bfile0, tag,
'offline', 1000,
False,
'FAIL' )
253 test.upload( inputTag, bfile0, tag,
'offline', 2000,
True,
'APPEND' )
256 tag =
'test_CondUpload_runmc'
257 test.upload( inputTag, bfile0, tag,
'runmc', 1,
True,
'CREATE')
258 db.setSynchronizationType( tag,
'runmc' )
259 test.upload( inputTag, bfile0, tag,
'runmc', 1000,
True,
'APPEND')
260 test.upload( inputTag, bfile0, tag,
'runmc', 500,
False,
'FAIL' )
261 test.upload( inputTag, bfile0, tag,
'runmc', 1000,
False,
'FAIL' )
262 test.upload( inputTag, bfile0, tag,
'runmc', 2000,
True,
'APPEND' )
266 print 'Done. Errors: %s' %test.errors
268 if __name__ ==
'__main__':
def setSynchronizationType