Changeset 6891
- Timestamp:
- Apr 24, 2009, 9:35:25 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_validation/automated_validation_tests/patong_beach_validation/validate.py
r6890 r6891 106 106 # try each mirror when getting file 107 107 for mirror in mirrors: 108 log. info('Fetching remote file %s from mirror %s'109 % (remote, mirror))108 log.debug('Fetching remote file %s from mirror %s' 109 % (remote, mirror)) 110 110 111 111 remote_url = mirror + remote + cache_defeat 112 log.debug('Trying to fetching file %s' % remote_url) 113 new_auth = get_web_file(remote_url, local, auth=auth) 114 if new_auth != False and not is_html(local): 112 (result, auth) = get_web_file(remote_url, local, auth=auth) 113 if result and is_html(local)==False: 115 114 log.debug('Success fetching file %s' % remote_url) 116 return new_auth117 118 log.info('Could not fetch file %s' % remote_url)119 return None115 return (True, auth) 116 117 log.info('Could not fetch file %s' % local) 118 return (False, auth) 120 119 121 120 … … 139 138 '''Update object 'obj' using authentication tuple 'auth'. 140 139 141 Return updated auth object (success) or None (failure). 140 Return (True, <updated_auth>) if all went well, 141 else (False, <updated_auth>). 142 142 ''' 143 143 … … 156 156 if not os.path.exists(local_digest) or not os.path.exists(local_file): 157 157 # no digest or no object, download both digest and object 158 auth= get_remote_from_mirrors(obj_digest, local_digest, auth, mirrors)159 if auth:160 auth= get_remote_from_mirrors(obj, local_file, auth, mirrors)158 (res, auth) = get_remote_from_mirrors(obj_digest, local_digest, auth, mirrors) 159 if res: 160 (res, auth) = get_remote_from_mirrors(obj, local_file, auth, mirrors) 161 161 else: 162 162 # download object digest to remote data directory 163 auth= get_remote_from_mirrors(obj_digest, remote_digest, auth, mirrors)164 if auth:163 (res, auth) = get_remote_from_mirrors(obj_digest, remote_digest, auth, mirrors) 164 if res: 165 165 if not files_same(local_data_digest, remote_data_digest): 166 166 # digests differ, refresh object 167 log.info('Local file %s is out of date ' % obj)167 log.info('Local file %s is out of date, refreshing ...' % obj) 168 168 shutil.move(remote_digest, local_digest) 169 auth= get_remote_from_mirrors(obj, local_file, auth, mirrors)169 (res, auth) = get_remote_from_mirrors(obj, local_file, auth, mirrors) 170 170 171 return auth171 return (res, auth) 172 172 173 173 # create local data directory if required … … 183 183 # success, refresh local files 184 184 auth = None 185 for data_object in Mandatory_Data_Objects:186 auth = refresh_object(data_object, auth, mirrors)187 if auth is None:188 log.debug('Failed fetching %s, returning None' % data_object)189 return None190 for data_object in Optional_Data_Objects:191 auth = refresh_object(data_object, auth, mirrors)192 if auth is None:193 log.debug('Failed fetching %s, returning None' % data_object)194 re turn None195 196 log.info('Local data has been refreshed .')197 return True185 result = True 186 for data_object in data_objects: 187 log.debug('refresh_local_data: getting %s from mirrors, auth=%s' 188 % (data_object, str(auth))) 189 (res, auth) = refresh_object(data_object, auth, mirrors) 190 log.debug('refresh_local_data: returned (res,auth)=%s,%s' 191 % (str(res), str(auth))) 192 if res == False: 193 log.debug('Failed fetching %s, returning False' % data_object) 194 result = False 195 196 log.info('Local data has been refreshed, result=%s.' % str(result)) 197 return result 198 198 199 199 … … 208 208 log.critical('Checking if you have the required files to run:') 209 209 210 have_mandatory_files = True210 # get max width of object name string 211 211 max_width = 0 212 212 for obj in Mandatory_Data_Objects: … … 215 215 max_width = max(len(obj), max_width) 216 216 217 # if we don't have all mandatory object, can't run 217 # if we don't have *all* mandatory object, can't run 218 have_mandatory_files = True 218 219 for obj in Mandatory_Data_Objects: 219 220 obj_path = os.path.join(Local_Data_Directory, obj) … … 224 225 have_mandatory_files = False 225 226 226 # one or moreof these must exist227 have_optional_files = True227 # at least *one* of these must exist 228 have_optional_files = False 228 229 for obj in Optional_Data_Objects: 229 230 obj_path = os.path.join(Local_Data_Directory, obj) 230 231 if os.path.exists(obj_path): 232 have_optional_files = True 231 233 log.info('\t%s found' % obj.ljust(max_width)) 232 234 else: 233 235 log.info('\t%s MISSING!' % obj.ljust(max_width)) 234 have_optional_files = False235 236 236 237 if not have_mandatory_files or not have_optional_files: … … 244 245 245 246 246 def run_simulation(vtype, sim_obj): 247 '''Run the Patong simulation.''' 248 249 # now untar file/directory objects 250 for obj in Mandatory_Data_Objects: 251 tar_path = os.path.join(Local_Data_Directory, obj) 252 log.info('Untarring %s in directory %s ...' 253 % (tar_path, Local_Data_Directory)) 254 untar_file(tar_path, target_dir=Local_Data_Directory) 255 256 # untar the vtype object 257 tar_path = os.path.join(Local_Data_Directory, sim_obj) 258 log.info('Untarring %s in directory %s ...' 259 % (tar_path, Local_Data_Directory)) 260 untar_file(tar_path, target_dir=Local_Data_Directory) 261 247 def set_environment(): 262 248 # modify environment so we use the local data 263 249 new_inundationhome = os.path.join(Local_Data_Directory, '') … … 265 251 new_muxhome = os.path.join(Local_Data_Directory, 'data') 266 252 os.environ['MUXHOME'] = new_muxhome 253 254 255 def run_simulation(vtype, sim_obj): 256 '''Run a simulation. 257 258 Returns True if all went well, else False. 259 ''' 260 261 # untar the object 262 tar_path = os.path.join(Local_Data_Directory, sim_obj) 263 log.info('Untarring %s in directory %s ...' 264 % (tar_path, Local_Data_Directory)) 265 untar_file(tar_path, target_dir=Local_Data_Directory) 267 266 268 267 # modify project.py template … … 279 278 fd.close() 280 279 281 # We import here, _after_ environment variables are set280 # import new project.py 282 281 import project 283 282 … … 285 284 log.critical('Running Patong simulation ...') 286 285 cmd = 'python run_model.py > %s' % RUNMODEL_STDOUT 286 log.debug("run_simulation: doing '%s'" % cmd) 287 287 res = os.system(cmd) 288 assert res == 0 288 log.debug("run_simulation: res=%d" % res) 289 290 # 'unimport' project.py 291 del project 292 293 # check result 294 if res != 0: 295 log.critical('Simulation failed, check log') 296 297 return res == 0 289 298 290 299 def check_that_output_is_as_expected(): … … 316 325 return 1 317 326 327 log.debug('check_that_output_is_as_expected: output_directory=%s' 328 % output_directory) 329 318 330 # compare SWW files here and there 319 331 new_output_sww = os.path.join(output_directory, OUTPUT_SWW) 320 332 cmd = 'python cmpsww.py %s %s > cmpsww.stdout' % (local_sww, new_output_sww) 333 log.debug("check_that_output_is_as_expected: doing '%s'" % cmd) 321 334 res = os.system(cmd) 335 log.debug("check_that_output_is_as_expected: res=%d" % res) 322 336 if res == 0: 323 337 log.info('Simulation results are as expected.') … … 332 346 def teardown(): 333 347 '''Clean up after validation run.''' 334 335 # clear all data objects from local data directory 336 for data_object in Local_Data_Objects: 337 obj_path = os.path.join(Local_Data_Directory, data_object) 338 if os.path.isfile(obj_path): 339 os.remove(obj_path) 340 else: 341 shutil.rmtree(obj_path, ignore_errors=True) 348 349 log.debug('teardown: called') 350 351 ## # clear all data objects from local data directory 352 ## for data_object in Local_Data_Objects: 353 ## obj_path = os.path.join(Local_Data_Directory, data_object) 354 ## if os.path.isfile(obj_path): 355 ## os.remove(obj_path) 356 ## else: 357 ## shutil.rmtree(obj_path, ignore_errors=True) 342 358 343 359 # remove remote directory and stdout capture file … … 355 371 # set logging levels 356 372 log.console_logging_level = log.INFO 373 log.log_logging_level = log.DEBUG 357 374 setup() 358 375 … … 377 394 378 395 # make sure local data is up to date 379 data_objects = [] 380 for o in Mandatory_Data_Objects: 381 data_objects.append(o) 382 for o in Optional_Data_Objects: 383 data_objects.append(o) 384 385 if not refresh_local_data(data_objects, Local_Data_Directory, MIRRORS): 396 all_objects = Mandatory_Data_Objects + Optional_Data_Objects 397 if not refresh_local_data(all_objects, Local_Data_Directory, MIRRORS): 386 398 if not can_we_run(): 387 399 log.critical("Can't refresh via the internet and you don't have the " … … 395 407 sys.exit(10) 396 408 409 # now untar mandatory objects 410 for obj in Mandatory_Data_Objects: 411 tar_path = os.path.join(Local_Data_Directory, obj) 412 log.info('Untarring %s in directory %s ...' 413 % (tar_path, Local_Data_Directory)) 414 untar_file(tar_path, target_dir=Local_Data_Directory) 415 416 # set required environment variables 417 set_environment() 418 397 419 # now run what simulations we can and check output is as expected 398 420 for odo in Optional_Data_Objects: 399 421 (_, vtype, _) = odo.rsplit('.', 2) 400 422 vtype = vtype.lower() 401 print "Running Patong '%s' validation" % vtype402 run_simulation(vtype, odo)403 check_that_output_is_as_expected(vtype, odo)423 log.critical("Running Patong '%s' validation ..." % vtype) 424 if run_simulation(vtype, odo): 425 check_that_output_is_as_expected(vtype, odo) 404 426 405 427 # clean up 406 #teardown()428 teardown()
Note: See TracChangeset
for help on using the changeset viewer.