Commit d7d5d5c2 authored by Nicolo Magini's avatar Nicolo Magini
Browse files

Adding script to test remote StageOut from WN to reference remote SRMs

parent e8221993
#!/usr/bin/env python2.6
"""
_RuntimeSAMRemoteStageOut_
Test script to determine remote stage out to reference storage elements
is working properly at a site
"""
import time
import os
import sys
from WMCore.Storage.Registry import retrieveStageOutImpl
import WMCore.Storage.Backends
import WMCore.Storage.Plugins
class StageOutDiagnostic:
"""
_StageOutDiagnostic_
Object to test the remote stage out details step by step
"""
def __init__(self):
self.summary = {}
self.summary.setdefault('RemoteStageOut' , "NotRun")
self.summary.setdefault('CleanUp' , "NotRun")
self.status = 0
# Force srmv2 protocol and lcg-cp
self.command = 'srmv2-lcg'
self.protocol = 'srmv2'
self.options = None
self.datestamp = time.asctime(time.localtime(time.time()))
self.datestamp = self.datestamp.replace(" ", "-").replace(":", "_")
# FIXME: change target directory from magini to test
self.testLFN = "/store/user/magini/SAM/RemoteStageOutTest-%i-%s" % (os.getpid(), self.datestamp)
# TODO: define list of additional target endpoints
self.testLFNprefixes = [ "srm://srm-eoscms.cern.ch:8443/srm/v2/server?SFN=/eos/cms" ]
def __call__(self):
"""
_operator()_
Invoke step by step tests and create the summary
"""
try:
self.testRemoteStageOut()
except Exception, ex:
print str(ex)
self.status = 1
self.complete()
return
def complete(self):
"""
_complete_
Print summary after tests
"""
msg = "==== StageOut Test Summary ====\n"
if self.status != 0:
msg += "Status: FAILED: %s\n" % self.status
else:
msg += "Test Successful\n"
for key, val in self.summary.items():
msg += " Test: %s : %s\n" % (key, val)
print msg
return
def testRemoteStageOut(self):
"""
_testRemoteStageOut_
Test remote stage out
"""
wasSuccessful = False
msg = ""
handle = open("TEST-FILE", 'w')
for i in range(0, 1000):
handle.write("This is a test file\n")
handle.close()
sourcePFN = os.path.join(os.getcwd(), "TEST-FILE")
try:
impl = retrieveStageOutImpl(self.command)
except Exception, ex:
msg += "Unable to retrieve impl for remote stage out:\n"
msg += "Error retrieving StageOutImpl for command named: %s\n" % (
self.command,)
self.summary['RemoteStageOut'] = \
"Failure: Cant retrieve StageOut Impl"
raise RuntimeError, msg
self.summary['RemoteStageOut'] = ""
self.summary['CleanUp'] = ""
# Try remote stageout to all target PFNs in the list
for lfnPrefix in self.testLFNprefixes:
targetPFN = lfnPrefix + self.testLFN
print "Staging out to %s\n" \
% targetPFN
try:
impl.retryPause = 15
impl(self.protocol, sourcePFN, targetPFN, self.options)
wasSuccessful = True
except Exception, ex:
msg += "Failure for remote stage out to %s :\n" \
% targetPFN
msg += str(ex)
self.summary['RemoteStageOut'] += \
"Failure: Remote Stage Out to %s Failed\n" \
% targetPFN
print "Cleaning up remote file %s\n" \
% targetPFN
# Clean up the file
try:
impl.removeFile(targetPFN)
except Exception, ex:
msg += "Error performing Cleanup command "
msg += "On PFN: %s\n" % targetPFN
msg += str(ex)
self.summary['CleanUp'] += "Failure: Cleanup operation of %s Failed\n" \
% targetPFN
if wasSuccessful:
return
# All remote PFNs failed, raise error
raise RuntimeError, msg
if __name__ == '__main__':
diagnostic = StageOutDiagnostic()
diagnostic()
sys.exit(diagnostic.status)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment