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_LOG WHERE TAG_NAME=:TAG_NAME',(tag,))
52 cursor.execute(
'DELETE FROM TAG WHERE NAME=:NAME',(tag,))
57 baseFile =
'%s_%s.db' %(inputTag,startingSince)
58 baseFilePath = os.path.join(cwd,baseFile)
59 if os.path.exists( 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
72 metadataFile = os.path.join(cwd,
'%s.txt') %destTag
73 if os.path.exists( metadataFile ):
74 os.remove( metadataFile )
76 metadata[
"destinationDatabase" ] =
"oracle://cms_orcoff_prep/CMS_CONDITIONS" 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))
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')
94 if line.startswith(
'upload ended with code:'):
95 returnCode = line.split(
'upload ended with code:')[1].
strip()
99 with open(logFileName,
'a')
as logFile:
115 def upload( self, inputTag, baseFile, destTag, synchro, destSince, success, expectedAction ):
117 destFile =
'%s.db' %destTag
118 metaDestFile =
'%s.txt' %destTag
119 shutil.copyfile( baseFile, destFile )
120 self.
log(
'# ---------------------------------------------------------------------------')
121 self.
log(
'# Testing tag %s with synch=%s, destSince=%s - expecting ret=%s action=%s' %(destTag,synchro,destSince,success,expectedAction))
123 descr =
'Testing conditionsUpload with synch:%s - expected action: %s' %(synchro,expectedAction)
125 beforeUpload = datetime.datetime.utcnow()
128 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))
131 row = self.db.getLastInsertedSince( destTag, beforeUpload )
133 if expectedAction ==
'CREATE' or expectedAction ==
'INSERT' or expectedAction ==
'APPEND':
134 if destSince != row[0]:
135 self.
log(
'ERROR: the since inserted is %s, expected value is %s - expected action: %s' %(row[0],destSince,expectedAction))
138 self.
log(
'# OK: Found expected value for last since inserted: %s timestamp: %s' %(row[0],row[1]))
139 insertedSince = row[0]
140 elif expectedAction ==
'SYNCHRONIZE':
141 if destSince == row[0]:
142 self.
log(
'ERROR: the since inserted %s has not been synchronized with the FCSR - expected action: %s' %(row[0],expectedAction))
145 self.
log(
'# OK: Found synchronized value for the last since inserted: %s timestamp: %s' %(row[0],row[1]))
146 insertedSince = row[0]
148 self.
log(
'ERROR: found an appended since %s - expected action: %s' %(row[0],expectedAction))
152 self.
log(
'ERROR: found new insered since: %s timestamp: %s' %(row[0],row[1]))
154 if expectedAction !=
'FAIL':
155 self.
log(
'ERROR: Upload failed. Expected value: %s' %(destSince))
158 self.
log(
'# OK: Upload failed as expected.')
159 os.remove( destFile )
160 os.remove( metaDestFile )
166 serviceName =
'cms_orcoff_prep' 167 schemaName =
'CMS_CONDITIONS' 168 db =
DB(serviceName,schemaName)
170 inputTag =
'runinfo_31X_mc' 175 tag =
'test_CondUpload_any' 176 test.upload( inputTag, bfile0, tag,
'any', 1,
True,
'CREATE' )
177 test.upload( inputTag, bfile1, tag,
'any', 1,
False,
'FAIL' )
178 test.upload( inputTag, bfile0, tag,
'any', 200,
True,
'APPEND' )
179 test.upload( inputTag, bfile0, tag,
'any', 100,
True,
'INSERT')
180 test.upload( inputTag, bfile0, tag,
'any', 200,
True,
'INSERT')
183 tag =
'test_CondUpload_validation' 184 test.upload( inputTag, bfile0, tag,
'validation', 1,
True,
'CREATE')
185 db.setSynchronizationType( tag,
'validation' )
186 test.upload( inputTag, bfile0, tag,
'validation', 1,
True,
'INSERT')
187 test.upload( inputTag, bfile0, tag,
'validation', 200,
True,
'APPEND')
188 test.upload( inputTag, bfile0, tag,
'validation', 100,
True,
'INSERT')
191 tag =
'test_CondUpload_mc' 192 test.upload( inputTag, bfile1, tag,
'mc', 1,
False,
'FAIL')
193 test.upload( inputTag, bfile0, tag,
'mc', 1,
True,
'CREATE')
194 db.setSynchronizationType( tag,
'mc' )
195 test.upload( inputTag, bfile0, tag,
'mc', 1,
False,
'FAIL')
196 test.upload( inputTag, bfile0, tag,
'mc', 200,
False,
'FAIL')
199 tag =
'test_CondUpload_hlt' 200 test.upload( inputTag, bfile0, tag,
'hlt', 1,
True,
'CREATE')
201 db.setSynchronizationType( tag,
'hlt' )
202 test.upload( inputTag, bfile0, tag,
'hlt', 200,
True,
'SYNCHRONIZE')
203 fcsr = test.upload( inputTag, bfile0, tag,
'hlt', 100,
True,
'SYNCHRONIZE')
206 test.upload( inputTag, bfile0, tag,
'hlt', since,
True,
'APPEND')
208 test.upload( inputTag, bfile0, tag,
'hlt', since,
True,
'INSERT')
211 tag =
'test_CondUpload_express' 212 test.upload( inputTag, bfile0, tag,
'express', 1,
True,
'CREATE')
213 db.setSynchronizationType( tag,
'express' )
214 test.upload( inputTag, bfile0, tag,
'express', 200,
True,
'SYNCHRONIZE')
215 fcsr = test.upload( inputTag, bfile0, tag,
'express', 100,
True,
'SYNCHRONIZE')
218 test.upload( inputTag, bfile0, tag,
'express', since,
True,
'APPEND')
220 test.upload( inputTag, bfile0, tag,
'express', since,
True,
'INSERT')
223 tag =
'test_CondUpload_prompt' 224 test.upload( inputTag, bfile0, tag,
'prompt', 1,
True,
'CREATE')
225 db.setSynchronizationType( tag,
'prompt' )
226 test.upload( inputTag, bfile0, tag,
'prompt', 200,
True,
'SYNCHRONIZE')
227 fcsr = test.upload( inputTag, bfile0, tag,
'prompt', 100,
True,
'SYNCHRONIZE')
230 test.upload( inputTag, bfile0, tag,
'prompt', since,
True,
'APPEND')
232 test.upload( inputTag, bfile0, tag,
'prompt', since,
True,
'INSERT')
235 tag =
'test_CondUpload_pcl' 236 test.upload( inputTag, bfile0, tag,
'pcl', 1,
True,
'CREATE')
237 db.setSynchronizationType( tag,
'pcl' )
238 test.upload( inputTag, bfile0, tag,
'pcl', 200,
False,
'FAIL')
241 test.upload( inputTag, bfile0, tag,
'pcl', since,
True,
'APPEND')
243 test.upload( inputTag, bfile0, tag,
'pcl', since,
True,
'INSERT')
246 tag =
'test_CondUpload_offline' 247 test.upload( inputTag, bfile0, tag,
'offline', 1,
True,
'CREATE')
248 db.setSynchronizationType( tag,
'offline' )
249 test.upload( inputTag, bfile0, tag,
'offline', 1000,
True,
'APPEND')
250 test.upload( inputTag, bfile0, tag,
'offline', 500,
False,
'FAIL' )
251 test.upload( inputTag, bfile0, tag,
'offline', 1000,
False,
'FAIL' )
252 test.upload( inputTag, bfile0, tag,
'offline', 2000,
True,
'APPEND' )
255 tag =
'test_CondUpload_runmc' 256 test.upload( inputTag, bfile0, tag,
'runmc', 1,
True,
'CREATE')
257 db.setSynchronizationType( tag,
'runmc' )
258 test.upload( inputTag, bfile0, tag,
'runmc', 1000,
True,
'APPEND')
259 test.upload( inputTag, bfile0, tag,
'runmc', 500,
False,
'FAIL' )
260 test.upload( inputTag, bfile0, tag,
'runmc', 1000,
False,
'FAIL' )
261 test.upload( inputTag, bfile0, tag,
'runmc', 2000,
True,
'APPEND' )
265 print 'Done. Errors: %s' %test.errors
267 if __name__ ==
'__main__':
def upload(self, inputTag, baseFile, destTag, synchro, destSince, success, expectedAction)
def setSynchronizationType(self, tag, synchType)
def uploadFile(fileName, logFileName)
def makeMetadataFile(inputTag, destTag, since, description)
def __init__(self, serviceName, schemaName)
def makeBaseFile(inputTag, startingSince)
def getLastInsertedSince(self, tag, snapshot)