30
30
import time
31
31
import urllib2
32
32
33
- # Fill in release details here:
34
- RELEASE_URL = "http://people.apache.org/~pwendell /spark-1.0.0 -rc1/"
35
- RELEASE_KEY = "9E4FE3AF"
36
- RELEASE_REPOSITORY = "https://repository.apache.org/content/repositories/orgapachespark-1006/ "
37
- RELEASE_VERSION = "1.0.0 "
33
+ # Note: The following variables must be set before use!
34
+ RELEASE_URL = "http://people.apache.org/~andrewor14 /spark-1.1.1 -rc1/"
35
+ RELEASE_KEY = "XXXXXXXX" # Your 8-digit hex
36
+ RELEASE_REPOSITORY = "https://repository.apache.org/content/repositories/orgapachespark-1033 "
37
+ RELEASE_VERSION = "1.1.1 "
38
38
SCALA_VERSION = "2.10.4"
39
39
SCALA_BINARY_VERSION = "2.10"
40
- #
41
40
41
+ # Do not set these
42
42
LOG_FILE_NAME = "spark_audit_%s" % time .strftime ("%h_%m_%Y_%I_%M_%S" )
43
43
LOG_FILE = open (LOG_FILE_NAME , 'w' )
44
44
WORK_DIR = "/tmp/audit_%s" % int (time .time ())
45
45
MAVEN_CMD = "mvn"
46
46
GPG_CMD = "gpg"
47
+ SBT_CMD = "sbt -Dsbt.log.noformat=true"
47
48
48
- print "Starting tests, log output in %s. Test results printed below:" % LOG_FILE_NAME
49
-
50
- # Track failures
49
+ # Track failures to print them at the end
51
50
failures = []
52
51
52
+ # Log a message. Use sparingly because this flushes every write.
53
+ def log (msg ):
54
+ LOG_FILE .write (msg + "\n " )
55
+ LOG_FILE .flush ()
53
56
57
+ def log_and_print (msg ):
58
+ print msg
59
+ log (msg )
60
+
61
+ # Prompt the user to delete the scratch directory used
54
62
def clean_work_files ():
55
- print "OK to delete scratch directory '%s'? (y/N): " % WORK_DIR
56
- response = raw_input ()
63
+ response = raw_input ("OK to delete scratch directory '%s'? (y/N) " % WORK_DIR )
57
64
if response == "y" :
58
65
shutil .rmtree (WORK_DIR )
59
- print "Should I delete the log output file '%s'? (y/N): " % LOG_FILE_NAME
60
- response = raw_input ()
61
- if response == "y" :
62
- os .unlink (LOG_FILE_NAME )
63
-
64
66
67
+ # Run the given command and log its output to the log file
65
68
def run_cmd (cmd , exit_on_failure = True ):
66
- print >> LOG_FILE , "Running command: %s" % cmd
69
+ log ( "Running command: %s" % cmd )
67
70
ret = subprocess .call (cmd , shell = True , stdout = LOG_FILE , stderr = LOG_FILE )
68
71
if ret != 0 and exit_on_failure :
69
- print "Command failed: %s" % cmd
72
+ log_and_print ( "Command failed: %s" % cmd )
70
73
clean_work_files ()
71
74
sys .exit (- 1 )
72
75
return ret
73
76
74
-
75
77
def run_cmd_with_output (cmd ):
76
- print >> sys . stderr , "Running command: %s" % cmd
78
+ log_and_print ( "Running command: %s" % cmd )
77
79
return subprocess .check_output (cmd , shell = True , stderr = LOG_FILE )
78
80
81
+ # Test if the given condition is successful
82
+ # If so, print the pass message; otherwise print the failure message
83
+ def test (cond , msg ):
84
+ return passed (msg ) if cond else failed (msg )
79
85
80
- def test (bool , str ):
81
- if bool :
82
- return passed (str )
83
- failed (str )
84
-
85
-
86
- def passed (str ):
87
- print "[PASSED] %s" % str
88
-
89
-
90
- def failed (str ):
91
- failures .append (str )
92
- print "[**FAILED**] %s" % str
86
+ def passed (msg ):
87
+ log_and_print ("[PASSED] %s" % msg )
93
88
89
+ def failed (msg ):
90
+ failures .append (msg )
91
+ log_and_print ("[**FAILED**] %s" % msg )
94
92
95
93
def get_url (url ):
96
94
return urllib2 .urlopen (url ).read ()
97
95
96
+ # If the path exists, prompt the user to delete it
97
+ # If the resource is not deleted, abort
98
+ def ensure_path_not_present (path ):
99
+ full_path = os .path .expanduser (path )
100
+ if os .path .exists (full_path ):
101
+ print "Found %s locally." % full_path
102
+ response = raw_input ("This can interfere with testing published artifacts. OK to delete? (y/N) " )
103
+ if response == "y" :
104
+ shutil .rmtree (full_path )
105
+ else :
106
+ print "Abort."
107
+ sys .exit (- 1 )
108
+
109
+ log_and_print ("|-------- Starting Spark audit tests for release %s --------|" % RELEASE_VERSION )
110
+ log_and_print ("Log output can be found in %s" % LOG_FILE_NAME )
98
111
99
112
original_dir = os .getcwd ()
100
113
@@ -114,44 +127,45 @@ def get_url(url):
114
127
cache_ivy_spark = "~/.ivy2/cache/org.apache.spark"
115
128
local_maven_kafka = "~/.m2/repository/org/apache/kafka"
116
129
local_maven_kafka = "~/.m2/repository/org/apache/spark"
117
-
118
-
119
- def ensure_path_not_present (x ):
120
- if os .path .exists (os .path .expanduser (x )):
121
- print "Please remove %s, it can interfere with testing published artifacts." % x
122
- sys .exit (- 1 )
123
-
124
130
map (ensure_path_not_present , [local_ivy_spark , cache_ivy_spark , local_maven_kafka ])
125
131
126
132
# SBT build tests
133
+ log_and_print ("==== Building SBT modules ====" )
127
134
os .chdir ("blank_sbt_build" )
128
135
os .environ ["SPARK_VERSION" ] = RELEASE_VERSION
129
136
os .environ ["SCALA_VERSION" ] = SCALA_VERSION
130
137
os .environ ["SPARK_RELEASE_REPOSITORY" ] = RELEASE_REPOSITORY
131
138
os .environ ["SPARK_AUDIT_MASTER" ] = "local"
132
139
for module in modules :
140
+ log ("==== Building module %s in SBT ====" % module )
133
141
os .environ ["SPARK_MODULE" ] = module
134
- ret = run_cmd ("sbt clean update" , exit_on_failure = False )
135
- test (ret == 0 , "sbt build against '%s' module" % module )
142
+ ret = run_cmd ("%s clean update" % SBT_CMD , exit_on_failure = False )
143
+ test (ret == 0 , "SBT build against '%s' module" % module )
136
144
os .chdir (original_dir )
137
145
138
146
# SBT application tests
147
+ log_and_print ("==== Building SBT applications ====" )
139
148
for app in ["sbt_app_core" , "sbt_app_graphx" , "sbt_app_streaming" , "sbt_app_sql" , "sbt_app_hive" , "sbt_app_kinesis" ]:
149
+ log ("==== Building application %s in SBT ====" % app )
140
150
os .chdir (app )
141
- ret = run_cmd ("sbt clean run" , exit_on_failure = False )
142
- test (ret == 0 , "sbt application (%s)" % app )
151
+ ret = run_cmd ("%s clean run" % SBT_CMD , exit_on_failure = False )
152
+ test (ret == 0 , "SBT application (%s)" % app )
143
153
os .chdir (original_dir )
144
154
145
155
# Maven build tests
146
156
os .chdir ("blank_maven_build" )
157
+ log_and_print ("==== Building Maven modules ====" )
147
158
for module in modules :
159
+ log ("==== Building module %s in maven ====" % module )
148
160
cmd = ('%s --update-snapshots -Dspark.release.repository="%s" -Dspark.version="%s" '
149
161
'-Dspark.module="%s" clean compile' %
150
162
(MAVEN_CMD , RELEASE_REPOSITORY , RELEASE_VERSION , module ))
151
163
ret = run_cmd (cmd , exit_on_failure = False )
152
164
test (ret == 0 , "maven build against '%s' module" % module )
153
165
os .chdir (original_dir )
154
166
167
+ # Maven application tests
168
+ log_and_print ("==== Building Maven applications ====" )
155
169
os .chdir ("maven_app_core" )
156
170
mvn_exec_cmd = ('%s --update-snapshots -Dspark.release.repository="%s" -Dspark.version="%s" '
157
171
'-Dscala.binary.version="%s" clean compile '
@@ -172,15 +186,14 @@ def ensure_path_not_present(x):
172
186
artifact_regex = r = re .compile ("<a href=\" (.*.tgz)\" >" )
173
187
artifacts = r .findall (index_page )
174
188
189
+ # Verify artifact integrity
175
190
for artifact in artifacts :
176
- print "==== Verifying download integrity for artifact: %s ====" % artifact
191
+ log_and_print ( "==== Verifying download integrity for artifact: %s ====" % artifact )
177
192
178
193
artifact_url = "%s/%s" % (RELEASE_URL , artifact )
179
- run_cmd ("wget %s" % artifact_url )
180
-
181
194
key_file = "%s.asc" % artifact
195
+ run_cmd ("wget %s" % artifact_url )
182
196
run_cmd ("wget %s/%s" % (RELEASE_URL , key_file ))
183
-
184
197
run_cmd ("wget %s%s" % (artifact_url , ".sha" ))
185
198
186
199
# Verify signature
@@ -208,31 +221,17 @@ def ensure_path_not_present(x):
208
221
209
222
os .chdir (WORK_DIR )
210
223
211
- for artifact in artifacts :
212
- print "==== Verifying build and tests for artifact: %s ====" % artifact
213
- os .chdir (os .path .join (WORK_DIR , dir_name ))
214
-
215
- os .environ ["MAVEN_OPTS" ] = "-Xmx3g -XX:MaxPermSize=1g -XX:ReservedCodeCacheSize=1g"
216
- # Verify build
217
- print "==> Running build"
218
- run_cmd ("sbt assembly" )
219
- passed ("sbt build successful" )
220
- run_cmd ("%s package -DskipTests" % MAVEN_CMD )
221
- passed ("Maven build successful" )
222
-
223
- # Verify tests
224
- print "==> Performing unit tests"
225
- run_cmd ("%s test" % MAVEN_CMD )
226
- passed ("Tests successful" )
227
- os .chdir (WORK_DIR )
228
-
229
- clean_work_files ()
230
-
224
+ # Report result
225
+ log_and_print ("\n " )
231
226
if len (failures ) == 0 :
232
- print " ALL TESTS PASSED"
227
+ log_and_print ( "*** ALL TESTS PASSED ***" )
233
228
else :
234
- print " SOME TESTS DID NOT PASS"
229
+ log_and_print ( "XXXXX SOME TESTS DID NOT PASS XXXXX" )
235
230
for f in failures :
236
- print f
237
-
231
+ log_and_print (" %s" % f )
238
232
os .chdir (original_dir )
233
+
234
+ # Clean up
235
+ clean_work_files ()
236
+
237
+ log_and_print ("|-------- Spark release audit complete --------|" )
0 commit comments