def replicate(remotepath, *args, **kwargs): """Replicate files to a storage element.""" _check_path(remotepath) bringonline = kwargs.pop('bringonline', False) if bringonline: timeout = 2 else: timeout = 60 * 60 * 6 ret = dm.replicate(remotepath, *args, bringonline_timeout=timeout, **kwargs) if ret is False: return 1 else: return 0
def replicate(remotepath, *args, **kwargs): """Replicate files to a storage element.""" bringonline = kwargs.pop('bringonline', False) verbose = kwargs.pop('verbose', False) kwargs['verbose'] = verbose if bringonline: timeout = 2 else: timeout = 60 * 60 * 6 ret = t2kdm.replicate(remotepath, *args, bringonline_timeout=timeout, **kwargs) if ret is False: return 1 else: return 0
def run_read_write_tests(): print_("Testing replicate...") with no_output(): assert (t2kdm.interactive.replicate(testdir, testSEs[1], recursive=r'^test[1]\.t.t$', verbose=True) == 0) assert (t2kdm.interactive.replicate(testdir, testSEs[1], recursive=r'^test[2]\.t.t$', source=testSEs[2], verbose=True) == 0) print_("Testing put...") with temp_dir() as tempdir: tempf = 'thisfileshouldnotbehereforlong.txt' filename = os.path.join(tempdir, tempf) remotename = posixpath.join(testdir, tempf) # Make sure the file does not exist try: for SE in storage.SEs: t2kdm.remove(remotename, SE.name, final=True) except backends.DoesNotExistException: pass # Prepare something to upload with open(filename, 'wt') as f: f.write("This is testfile #3.\n") t2kdm.put(filename, testdir + '/', destination=testSEs[0]) print_("Testing disk SEs...") # Replicate test file to all SEs, to see if they all work for SE in storage.SEs: if SE.type == 'tape' or 'TRIUMF' in SE.name: # These SEs do not seem to cooperate continue print_(SE.name) assert (t2kdm.replicate(remotename, SE.name) == True) assert (SE.has_replica(remotename) == True) print_("Testing remove...") t2kdm.remove(testdir, testSEs[1], recursive=True) # Remove everything from SE1 # Remove uploaded file from previous test try: # This should fail! for SE in storage.SEs: t2kdm.remove(remotename, SE.name) except backends.BackendException as e: assert ("Only one" in e.args[0]) else: raise Exception("The last copy should not have been removed!") # With the `final` argument it should work try: for SE in storage.SEs: t2kdm.remove(remotename, SE.name, final=True) assert (SE.has_replica(remotename) == False) for SE in storage.SEs: t2kdm.remove(remotename, SE.name, final=True) except backends.DoesNotExistException: # The command will fail when the file no longer exists pass else: raise Exception( "This should have raised a DoesNotExistException at some point.")
def fix_missing_files(remotepath, verbose=False): """Fix missing files on the storage elements. Helps when a replica is registered in the catalogue, but not actually present on the SE. """ success = True replicas = t2kdm.replicas(remotepath) existing = [] for rep in replicas: se = storage.get_SE(rep) if se is not None and se.is_blacklisted(): if verbose: print_("WARNING: Skipping replica on blacklisted SE: " + rep) print_("Will assume it exists for now.") exists = True success = False else: try: exists = t2kdm.exists(rep) except backends.BackendException: if verbose: print_( "WARNING: Could not check whether replica exists: " + rep) print_("Will assume it does for now.") exists = True success = False existing.append(exists) # Check that there is at least one replica actually present if not any(existing): if verbose: print_("WARNING: There is not a single replica actually present!") print_("Doing nothing.") return False # Remove the replicas that are not present and remember which SEs those were ses = [] for replica, exists in zip(replicas, existing): if not exists: if verbose: print_("Found missing file. Unregistering replica: " + replica) se = storage.get_SE(replica) if se is not None: ses.append(se) try: t2kdm.backend.unregister(replica, remotepath, verbose=verbose) except backends.BackendException(): if verbose: print_("Failed to unregister replica.") success = False else: print_("Cannot identify storage element of replica.") success = False # Replicate the file for se in ses: if verbose: print_("Replicating missing replica on " + se.name) try: t2kdm.replicate(remotepath, se, verbose=verbose) except backends.BackendException(): if verbose: print_("Failed to replicate File.") success = False return success
def fix_checksum_errors(remotepath, verbose=False): """Fix replicas with differing checksums. This can only be done for files that can be checked for corruption. Otherwise there is no way to decide which file is actually the correct one. """ replicas = dm.replicas(remotepath) checksums = [dm.checksum(r) for r in replicas] if len(set(checksums)) == 1 and '?' not in checksums[0]: # Nothing to do here return True if verbose: print_("Found faulty checksums.") if not remotepath.endswith('.gz'): if verbose: print_("WARNING: Can only check file consistency of *.gz files!") print_("Doing nothing.") return False good_replicas = [] bad_replicas = [] for replica in replicas: if _test_replica(replica, verbose=verbose): good_replicas.append(replica) else: bad_replicas.append(replica) if len(good_replicas) == 0: if verbose: print_("WARNING: Not a single good replica present!") print_("Doing nothing.") return False if len(bad_replicas) == 0: if verbose: print_("WARNING: Not a single bad replica present!") print_("This should not happen, since the checksums are different.") print_("Doing nothing.") return False bad_SEs = [] for replica in bad_replicas: SE = storage.get_SE(replica) if SE is None: if verbose: print_("WARNING: Could not find storage element for replica: "+replica) continue bad_SEs.append(SE) success = True for SE in bad_SEs: if verbose: print_("Removing bad replica from %s."%(SE.name,)) try: dm.remove(remotepath, SE, verbose=verbose) except: success = False for SE in bad_SEs: if verbose: print_("Re-replicating file on %s."%(SE.name,)) try: dm.replicate(remotepath, SE, verbose=verbose) except: success = False return success