1 |
#!/usr/bin/env python
|
2 |
import sys
|
3 |
import os
|
4 |
import traceback
|
5 |
import exceptions
|
6 |
import shutil
|
7 |
import stat
|
8 |
#
|
9 |
path = os.getcwd()
|
10 |
#
|
11 |
script = ""
|
12 |
schclassad = ""
|
13 |
#
|
14 |
try:
|
15 |
args=sys.argv
|
16 |
script = os.path.abspath( args[1] );
|
17 |
except :
|
18 |
print "Submit script not provided"
|
19 |
print "Usage:\n\tbossSubmitScript_tester.py <submission script> <schclassad>\n"
|
20 |
sys.exit()
|
21 |
try :
|
22 |
schclassad = os.path.abspath( args[2] );
|
23 |
if not os.path.exists( schclassad ) :
|
24 |
print "schclassad provided does not exist : " + schclassad
|
25 |
print "skipping..."
|
26 |
except :
|
27 |
pass
|
28 |
#
|
29 |
if not os.path.exists( script ) :
|
30 |
print "File not found : ", script
|
31 |
#
|
32 |
# Boss task ID
|
33 |
task_id=1
|
34 |
# common sandbox
|
35 |
commonSandbox = "BossArchive_1_g0.tgz";
|
36 |
# logfile prefix
|
37 |
log = "jobExecutor"
|
38 |
# jobId list file
|
39 |
jobList = "submit_1"
|
40 |
# logfile prefix
|
41 |
logFile = "test_logFile.log"
|
42 |
#
|
43 |
# preparing tarball
|
44 |
#
|
45 |
subdir = "BossSubmissionTest"
|
46 |
os.mkdir( subdir )
|
47 |
os.chdir( subdir )
|
48 |
shutil.copy( os.path.expandvars("$BOSS_ROOT/Examples/in"), "in")
|
49 |
shutil.copy( os.path.expandvars("$BOSS_ROOT/Examples/test.pl"), "test.pl")
|
50 |
shutil.copy( os.path.expandvars("$BOSS_ROOT/bin/programExecutor"), "programExecutor")
|
51 |
shutil.copyfile( os.path.expandvars("$BOSS_ROOT/BossWrapper/bin/linearChainer"), "ch_tool")
|
52 |
os.chmod( "test.pl", stat.S_IEXEC | stat.S_IREAD )
|
53 |
os.chmod( "programExecutor", stat.S_IEXEC | stat.S_IREAD )
|
54 |
os.chmod( "ch_tool", stat.S_IEXEC | stat.S_IREAD )
|
55 |
#
|
56 |
f = open( jobList, 'w' )
|
57 |
f.write( "1:1:1\n" )
|
58 |
f.close()
|
59 |
#
|
60 |
f = open( "ch_config.clad", 'w' )
|
61 |
f.write(
|
62 |
"""
|
63 |
[
|
64 |
TASK_ID = 1;
|
65 |
CHAIN_ID = 1;
|
66 |
PROGRAM_LIST = 1,;
|
67 |
]
|
68 |
"""
|
69 |
)
|
70 |
f.close()
|
71 |
#
|
72 |
f = open( "BossWrapperSTDIN_1_1_1.clad", 'w' )
|
73 |
f.write(
|
74 |
"""
|
75 |
[
|
76 |
ARCHIVE = BossArchive_1_g0.tgz;
|
77 |
BOSS_MAX_RETRY = 3;
|
78 |
BOSS_MAX_UPD_INT = 180;
|
79 |
BOSS_MIN_UPD_INT = 30;
|
80 |
BOSS_PROGRAM_INFO_1 = [
|
81 |
1\tPROGRAM\tARGS\t100
|
82 |
1\tPROGRAM\tCHAIN_ID\t1
|
83 |
1\tPROGRAM\tEXEC\ttest.pl
|
84 |
1\tPROGRAM\tID\t1
|
85 |
1\tPROGRAM\tINFILES\tin,test.pl
|
86 |
1\tPROGRAM\tOUTFILES\terr,out,test.pl.log
|
87 |
1\tPROGRAM\tOUTTOPDIR\t
|
88 |
1\tPROGRAM\tPROGRAM_TYPE\tstdjob
|
89 |
1\tPROGRAM\tSTDERR\terr
|
90 |
1\tPROGRAM\tSTDIN\tin
|
91 |
1\tPROGRAM\tSTDOUT\tout
|
92 |
1\tPROGRAM\tTASK_ID\t1
|
93 |
]
|
94 |
;
|
95 |
BOSS_TMP_DIR = /tmp/;
|
96 |
CHAIN_ID = 1;
|
97 |
CLIENT_ID = 55329644-a5e4-44cd-ad33-2a36e5bca522;
|
98 |
CP_COMM = NONE;
|
99 |
CP_LOC_PREF = .;
|
100 |
CP_REM_PREF = .;
|
101 |
ID = 1;
|
102 |
INFILES = in,test.pl;
|
103 |
JOB_ID_ENV_VAR = GLITE_WMS_JOBID;
|
104 |
ML_URL = ;
|
105 |
NO_OUTPUT_TRANSFER = N;
|
106 |
OUTFILES = err,out,test.pl.log;
|
107 |
PROGRAM_LIST = 1,;
|
108 |
SUB_USER = codispot;
|
109 |
TASK_ID = 1;
|
110 |
TASK_NAME = Test-BossTask;
|
111 |
TOP_WORK_DIR = .;
|
112 |
]
|
113 |
"""
|
114 |
)
|
115 |
#
|
116 |
if len ( schclassad ) != 0 :
|
117 |
shutil.copy( schclassad, "BossClassAdFile_1" )
|
118 |
else :
|
119 |
f = open( "BossClassAdFile_1", 'w' )
|
120 |
f.write('VirtualOrganisation = "cms";')
|
121 |
f.close()
|
122 |
#
|
123 |
os.system("tar cvzf " + commonSandbox + " in test.pl ch_tool programExecutor ch_config.clad")
|
124 |
#
|
125 |
tmp_dir = 'tmp_files/'
|
126 |
os.mkdir( tmp_dir )
|
127 |
shutil.copy( commonSandbox, tmp_dir)
|
128 |
os.remove( "in" )
|
129 |
os.remove( "test.pl" )
|
130 |
os.remove( "ch_tool" )
|
131 |
os.remove( "programExecutor" )
|
132 |
os.remove( "ch_config.clad" )
|
133 |
#
|
134 |
command = script + ' ' \
|
135 |
+ str(task_id) + ' ' \
|
136 |
+ commonSandbox + ' ' \
|
137 |
+ log + ' ' \
|
138 |
+ jobList + ' ' \
|
139 |
+ logFile
|
140 |
#
|
141 |
stdin,stdout=os.popen4( command )
|
142 |
#
|
143 |
print "STDOUT : "
|
144 |
print stdout.read()
|
145 |
shutil.move( "BossClassAdFile_1", tmp_dir)
|
146 |
shutil.move( "submit_1", tmp_dir)
|
147 |
# print "\n\n\nSTERR : "
|
148 |
# print stderr.read()
|
149 |
|
150 |
|
151 |
|