3 from __future__
import print_function
11 fileName =
'copy_test.db' 18 db = sqlite3.connect(fileName)
20 cursor.execute(
'UPDATE TAG SET SYNCHRONIZATION =? WHERE NAME =?',(synchType,tag,))
24 db = sqlite3.connect(fileName)
26 cursor.execute(
'SELECT SINCE, INSERTION_TIME FROM IOV WHERE TAG_NAME =? AND INSERTION_TIME >? ORDER BY INSERTION_TIME DESC',(tag,snapshot))
27 row = cursor.fetchone()
31 command =
"conddb --yes copy %s %s --destdb %s -f %s" %(inputTag,sourceTag,fileName,startingSince)
32 pipe = subprocess.Popen( command, shell=
True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
33 out = pipe.communicate()[0]
35 def copy( sourceTag, destTag, since, logFileName ):
36 command =
"conddb --yes --db %s copy %s %s -f %s --synchronize" %(fileName,sourceTag,destTag,since)
37 pipe = subprocess.Popen( command, shell=
True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
38 out = pipe.communicate()[0]
39 lines = out.split(
'\n')
43 with open(logFileName,
'a')
as logFile:
59 def execute( self, sourceTag, baseFile, destTag, synchro, destSince, success, expectedAction ):
61 metaDestFile =
'%s.txt' %destTag
63 self.
log(
'# ---------------------------------------------------------------------------')
64 self.
log(
'# Testing tag %s with synch=%s, destSince=%s - expecting ret=%s action=%s' %(destTag,synchro,destSince,success,expectedAction))
66 descr =
'Testing conditionsUpload with synch:%s - expected action: %s' %(synchro,expectedAction)
67 beforeUpload = datetime.datetime.utcnow()
70 self.
log(
'ERROR: the return value for the copy of tag %s with sychro %s was %s, while the expected result is %s' %(destTag,synchro,ret,success))
73 row = self.db.getLastInsertedSince( destTag, beforeUpload )
75 if expectedAction ==
'CREATE' or expectedAction ==
'INSERT' or expectedAction ==
'APPEND':
76 if destSince != row[0]:
77 self.
log(
'ERROR: the since inserted is %s, expected value is %s - expected action: %s' %(row[0],destSince,expectedAction))
80 self.
log(
'# OK: Found expected value for last since inserted: %s timestamp: %s' %(row[0],row[1]))
81 insertedSince = row[0]
82 elif expectedAction ==
'SYNCHRONIZE':
83 if destSince == row[0]:
84 self.
log(
'ERROR: the since inserted %s has not been synchronized with the FCSR - expected action: %s' %(row[0],expectedAction))
87 self.
log(
'# OK: Found synchronized value for the last since inserted: %s timestamp: %s' %(row[0],row[1]))
88 insertedSince = row[0]
90 self.
log(
'ERROR: found an appended since %s - expected action: %s' %(row[0],expectedAction))
94 self.
log(
'ERROR: found new insered since: %s timestamp: %s' %(row[0],row[1]))
96 if expectedAction !=
'FAIL':
97 self.
log(
'ERROR: Upload failed. Expected value: %s' %(destSince))
100 self.
log(
'# OK: Upload failed as expected.')
109 inputTag =
'runinfo_31X_mc' 110 inputTag0 =
'runinfo_0' 111 inputTag1 =
'runinfo_1' 116 tag =
'test_CondUpload_any' 117 test.execute( inputTag0, bfile0, tag,
'any', 1,
True,
'CREATE' )
118 test.execute( inputTag0, bfile0, tag,
'any', 200,
True,
'APPEND' )
119 test.execute( inputTag0, bfile0, tag,
'any', 100,
True,
'INSERT')
120 test.execute( inputTag0, bfile0, tag,
'any', 200,
True,
'INSERT')
122 tag =
'test_CondUpload_validation' 123 test.execute( inputTag0, bfile0, tag,
'validation', 1,
True,
'CREATE')
124 db.setSynchronizationType( tag,
'validation' )
125 test.execute( inputTag0, bfile0, tag,
'validation', 1,
True,
'INSERT')
126 test.execute( inputTag0, bfile0, tag,
'validation', 200,
True,
'APPEND')
127 test.execute( inputTag0, bfile0, tag,
'validation', 100,
True,
'INSERT')
129 tag =
'test_CondUpload_mc' 130 test.execute( inputTag0, bfile0, tag,
'mc', 1,
True,
'CREATE')
131 db.setSynchronizationType( tag,
'mc' )
132 test.execute( inputTag1, bfile1, tag,
'mc', 1,
False,
'FAIL')
133 test.execute( inputTag0, bfile0, tag,
'mc', 1,
False,
'FAIL')
134 test.execute( inputTag0, bfile0, tag,
'mc', 200,
False,
'FAIL')
136 tag =
'test_CondUpload_hlt' 137 test.execute( inputTag0, bfile0, tag,
'hlt', 1,
True,
'CREATE')
138 db.setSynchronizationType( tag,
'hlt' )
139 test.execute( inputTag0, bfile0, tag,
'hlt', 200,
True,
'SYNCHRONIZE')
140 fcsr = test.execute( inputTag0, bfile0, tag,
'hlt', 100,
True,
'SYNCHRONIZE')
143 test.execute( inputTag0, bfile0, tag,
'hlt', since,
True,
'APPEND')
145 test.execute( inputTag0, bfile0, tag,
'hlt', since,
True,
'INSERT')
147 tag =
'test_CondUpload_express' 148 test.execute( inputTag0, bfile0, tag,
'express', 1,
True,
'CREATE')
149 db.setSynchronizationType( tag,
'express' )
150 test.execute( inputTag0, bfile0, tag,
'express', 200,
True,
'SYNCHRONIZE')
151 fcsr = test.execute( inputTag0, bfile0, tag,
'express', 100,
True,
'SYNCHRONIZE')
154 test.execute( inputTag0, bfile0, tag,
'express', since,
True,
'APPEND')
156 test.execute( inputTag0, bfile0, tag,
'express', since,
True,
'INSERT')
158 tag =
'test_CondUpload_prompt' 159 test.execute( inputTag0, bfile0, tag,
'prompt', 1,
True,
'CREATE')
160 db.setSynchronizationType( tag,
'prompt' )
161 test.execute( inputTag0, bfile0, tag,
'prompt', 200,
True,
'SYNCHRONIZE')
162 fcsr = test.execute( inputTag0, bfile0, tag,
'prompt', 100,
True,
'SYNCHRONIZE')
165 test.execute( inputTag0, bfile0, tag,
'prompt', since,
True,
'APPEND')
167 test.execute( inputTag0, bfile0, tag,
'prompt', since,
True,
'INSERT')
169 tag =
'test_CondUpload_pcl' 170 test.execute( inputTag0, bfile0, tag,
'pcl', 1,
True,
'CREATE')
171 db.setSynchronizationType( tag,
'pcl' )
172 test.execute( inputTag0, bfile0, tag,
'pcl', 200,
False,
'FAIL')
175 test.execute( inputTag0, bfile0, tag,
'pcl', since,
True,
'APPEND')
177 test.execute( inputTag0, bfile0, tag,
'pcl', since,
True,
'INSERT')
179 tag =
'test_CondUpload_offline' 180 test.execute( inputTag0, bfile0, tag,
'offline', 1,
True,
'CREATE')
181 db.setSynchronizationType( tag,
'offline' )
182 test.execute( inputTag0, bfile0, tag,
'offline', 1000,
True,
'APPEND')
183 test.execute( inputTag0, bfile0, tag,
'offline', 500,
False,
'FAIL' )
184 test.execute( inputTag0, bfile0, tag,
'offline', 1000,
False,
'FAIL' )
185 test.execute( inputTag0, bfile0, tag,
'offline', 2000,
True,
'APPEND' )
187 tag =
'test_CondUpload_runmc' 188 test.execute( inputTag0, bfile0, tag,
'runmc', 1,
True,
'CREATE')
189 db.setSynchronizationType( tag,
'runmc' )
190 test.execute( inputTag0, bfile0, tag,
'runmc', 1000,
True,
'APPEND')
191 test.execute( inputTag0, bfile0, tag,
'runmc', 500,
False,
'FAIL' )
192 test.execute( inputTag0, bfile0, tag,
'runmc', 1000,
False,
'FAIL' )
193 test.execute( inputTag0, bfile0, tag,
'runmc', 2000,
True,
'APPEND' )
194 os.remove( fileName )
195 print(
'Done. Errors: %s' %test.errors)
198 if __name__ ==
'__main__':
def prepareFile(inputTag, sourceTag, startingSince)
def copy(sourceTag, destTag, since, logFileName)
def setSynchronizationType(self, tag, synchType)
def execute(self, sourceTag, baseFile, destTag, synchro, destSince, success, expectedAction)
S & print(S &os, JobReport::InputFile const &f)
def getLastInsertedSince(self, tag, snapshot)