3 from __future__
import print_function
23 pipe = subprocess.Popen( command, shell=
True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
24 out = pipe.communicate()[0]
29 if c !=
' ' and c !=
'\n':
34 db = cx_Oracle.connect(self.
connStr)
37 cursor.execute(
'UPDATE TAG SET SYNCHRONIZATION =:SYNCH WHERE NAME =:NAME',(synchType,tag,))
41 db = cx_Oracle.connect(self.
connStr)
43 cursor.execute(
'SELECT SINCE, INSERTION_TIME FROM IOV WHERE TAG_NAME =:TAG_NAME AND INSERTION_TIME >:TIME ORDER BY INSERTION_TIME DESC',(tag,snapshot))
44 row = cursor.fetchone()
48 db = cx_Oracle.connect(self.
connStr)
51 cursor.execute(
'DELETE FROM IOV WHERE TAG_NAME =:TAG_NAME',(tag,))
52 cursor.execute(
'DELETE FROM TAG_LOG WHERE TAG_NAME=:TAG_NAME',(tag,))
53 cursor.execute(
'DELETE FROM TAG WHERE NAME=:NAME',(tag,))
58 baseFile =
'%s_%s.db' %(inputTag,startingSince)
59 baseFilePath = os.path.join(cwd,baseFile)
60 if os.path.exists( baseFile ):
62 command =
"conddb_import -c sqlite_file:%s -f oracle://cms_orcon_adg/CMS_CONDITIONS -i %s -t %s -b %s" %(baseFile,inputTag,inputTag,startingSince)
63 pipe = subprocess.Popen( command, shell=
True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
64 out = pipe.communicate()[0]
65 if not os.path.exists( baseFile ):
66 msg =
'ERROR: base file has not been created: %s' %out
73 metadataFile = os.path.join(cwd,
'%s.txt') %destTag
74 if os.path.exists( metadataFile ):
75 os.remove( metadataFile )
77 metadata[
"destinationDatabase" ] =
"oracle://cms_orcoff_prep/CMS_CONDITIONS"
79 tagList[ destTag ] = {
"dependencies": {},
"synchronizeTo":
"any" }
80 metadata[
"destinationTags" ] = tagList
81 metadata[
"inputTag" ] = inputTag
82 metadata[
"since" ] = since
83 metadata[
"userText" ] = description
84 fileName = destTag+
".txt"
85 with open( fileName,
"w" )
as file:
86 file.write(json.dumps(metadata,file,indent=4,sort_keys=
True))
89 command =
"uploadConditions.py %s" %fileName
90 pipe = subprocess.Popen( command, shell=
True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
91 out = pipe.communicate()[0]
92 lines = out.split(
'\n')
95 if line.startswith(
'upload ended with code:'):
96 returnCode = line.split(
'upload ended with code:')[1].
strip()
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
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)