Skip to content

Commit

Permalink
add I/O test code
Browse files Browse the repository at this point in the history
  • Loading branch information
kpedro88 committed Aug 30, 2021
1 parent b2599d2 commit 3d4bc05
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ __init__.py
*.zip
*.eps
*.tar.gz

# text files
*.stdout
*.stderr
*.condor
2 changes: 1 addition & 1 deletion test/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ checkVomsTar.sh
step1.sh
jobExecCondor.sh
jobExecCondor.jdl

jobExecCondorChain.sh
1 change: 1 addition & 0 deletions test/CACHEDIR.TAG
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Signature: 8a477f597d28d172789f06886806bc55\n# This file is a cache directory tag.\n# For information about cache directory tags, see:\n# http://www.brynosaurus.com/cachedir/
21 changes: 19 additions & 2 deletions test/jobSubmitterTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,27 @@ def __init__(self):
def addExtraOptions(self,parser):
super(jobSubmitterTest,self).addExtraOptions(parser)
parser.add_option("-N", "--nParts", dest="nParts", default=1, type="int", help="number of parts to process (default = %default)")
parser.add_option("--name", dest="name", default="test", help="job name (default = %default)")
parser.add_option("--io", dest="io", default=False, action="store_true", help="use I/O options (default = %default)")
parser.add_option("--indir", dest="indir", default="", help="input file directory (local or PFN) (default = %default)")
parser.add_option("--outdir", dest="outdir", default="", help="output file directory (local or PFN) (default = %default)")
parser.add_option("--inpre", dest="inpre", default="", help="input file prefix (default = %default)")
parser.add_option("--outpre", dest="outpre", default="", help="output file prefix (required) (default = %default)")
parser.add_option("--fail", dest="fail", default=0, help="fail with specified error code (default = %default)")

def checkExtraOptions(self,options,parser):
super(jobSubmitterTest,self).checkExtraOptions(options,parser)

if options.io:
# input is not necessarily required
if len(options.outdir)==0:
parser.error("Required option: --outdir [directory]")
if len(options.outpre)==0:
parser.error("Required option: --outpre [prefix]")

def generateSubmission(self):
job = protoJob()
job.name = "test"
job.name = self.name
self.generatePerJob(job)

for iJob in xrange(self.nParts):
Expand All @@ -26,5 +43,5 @@ def generateExtra(self,job):
job.patterns.update([
("JOBNAME",job.name+"_part$(Process)_$(Cluster)"),
("EXTRAINPUTS",""),
("EXTRAARGS",""),
("EXTRAARGS","-j "+job.name+(" -i "+self.indir if len(self.indir)>0 else "")+" -o "+self.outdir+(" -n "+self.inpre if len(self.inpre)>0 else "")+" -u "+self.outpre+" -f "+str(self.fail)+" -p $(Process)" if self.io else ""),
])
106 changes: 97 additions & 9 deletions test/test.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,101 @@
#!/bin/bash

echo "This is a test job. It will print the current directory, contents, and environment."
echo "Starting job on "`date` # to display the start date
echo "Running on "`uname -a` # to display the machine where the job is running
echo "System release "`cat /etc/redhat-release` # and the system release
echo ""
echo "Current directory:"
echo $PWD
echo ""
echo "Current directory listing:"
ls -ltha
echo ""
echo "Current environment:"
printenv

export JOBNAME=""
export PART=""
export INDIR=""
export OUTDIR=""
export INDPRE=""
export OUTPRE=""
export FAIL=0
export OPTIND=1
while [[ $OPTIND -le $# ]]; do
OPTOLD=$OPTIND
# getopts in silent mode, don't exit on errors
getopts ":j:p:i:o:n:u:f:" opt || status=$?
case "$opt" in
j) export JOBNAME=$OPTARG
;;
p) export PART=$OPTARG
;;
i) export INDIR=$OPTARG
;;
o) export OUTDIR=$OPTARG
;;
n) export INPRE=$OPTARG
;;
u) export OUTPRE=$OPTARG
;;
f) export FAIL=$OPTARG
;;
# keep going if getopts had an error, but make sure not to skip anything
\? | :) OPTIND=$((OPTOLD+1))
;;
esac
done

# default mode
if [ -z "$PART" ]; then
echo "This is a test job. It will print the current directory, contents, and environment."
echo ""
echo "Current directory:"
echo $PWD
echo ""
echo "Current directory listing:"
ls -ltha
echo ""
echo "Current environment:"
printenv
# IO mode
else
echo "parameter set:"
echo "JOBNAME: $JOBNAME"
echo "PART: $PART"
echo "INDIR: $INDIR"
echo "OUTDIR: $OUTDIR"
echo "INPRE: $INPRE"
echo "OUTPRE: $OUTPRE"

OUTFNAME=${OUTPRE}_${PART}.log
# get input if any
if [ -n "$INDIR" ]; then
INFNAME=${INPRE}_${PART}.log
if [[ "$INDIR" == "root://"* ]]; then
mkdir -p tmp
xrdcp ${INDIR}/${INFNAME} tmp/
INDIR=tmp
fi
cat ${INDIR}/${INFNAME} >> ${OUTFNAME}
fi

if [[ $FAIL -ne 0 ]]; then
echo "artificial failure $FAIL"
exit $FAIL
fi

# create output
echo "$JOBNAME $PART" >> ${OUTFNAME}

# check for gfal case
CMDSTR="xrdcp"
GFLAG=""
if [[ "$OUTDIR" == "gsiftp://"* ]]; then
CMDSTR="gfal-copy"
GFLAG="-g"
fi
# stageout
echo "$CMDSTR output for condor"
for FILE in *.log; do
echo "${CMDSTR} -f ${FILE} ${OUTDIR}/${FILE}"
stageOut ${GFLAG} -x "-f" -i ${FILE} -o ${OUTDIR}/${FILE} -r -c '*.log' 2>&1
XRDEXIT=$?
if [[ $XRDEXIT -ne 0 ]]; then
echo "exit code $XRDEXIT, failure in ${CMDSTR}"
exit $XRDEXIT
fi
done
fi

0 comments on commit 3d4bc05

Please sign in to comment.