2014-02-09 02:13:34 -05:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
|
|
#
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright ownership.
|
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
# (the "License"); you may not use this file except in compliance with
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Audits binary and maven artifacts for a Spark release.
|
|
|
|
# Requires GPG and Maven.
|
|
|
|
# usage:
|
|
|
|
# python audit_release.py
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
import urllib2
|
|
|
|
|
2014-11-12 19:30:58 -05:00
|
|
|
# Note: The following variables must be set before use!
|
|
|
|
RELEASE_URL = "http://people.apache.org/~andrewor14/spark-1.1.1-rc1/"
|
|
|
|
RELEASE_KEY = "XXXXXXXX" # Your 8-digit hex
|
|
|
|
RELEASE_REPOSITORY = "https://repository.apache.org/content/repositories/orgapachespark-1033"
|
|
|
|
RELEASE_VERSION = "1.1.1"
|
2016-02-09 14:56:25 -05:00
|
|
|
SCALA_VERSION = "2.11.7"
|
|
|
|
SCALA_BINARY_VERSION = "2.11"
|
2014-02-09 02:13:34 -05:00
|
|
|
|
2014-11-12 19:30:58 -05:00
|
|
|
# Do not set these
|
2014-02-09 02:13:34 -05:00
|
|
|
LOG_FILE_NAME = "spark_audit_%s" % time.strftime("%h_%m_%Y_%I_%M_%S")
|
|
|
|
LOG_FILE = open(LOG_FILE_NAME, 'w')
|
2014-05-27 00:40:52 -04:00
|
|
|
WORK_DIR = "/tmp/audit_%s" % int(time.time())
|
2014-02-09 02:13:34 -05:00
|
|
|
MAVEN_CMD = "mvn"
|
|
|
|
GPG_CMD = "gpg"
|
2014-11-12 19:30:58 -05:00
|
|
|
SBT_CMD = "sbt -Dsbt.log.noformat=true"
|
2014-02-09 02:13:34 -05:00
|
|
|
|
2014-11-12 19:30:58 -05:00
|
|
|
# Track failures to print them at the end
|
2014-02-09 02:13:34 -05:00
|
|
|
failures = []
|
|
|
|
|
2014-11-12 19:30:58 -05:00
|
|
|
# Log a message. Use sparingly because this flushes every write.
|
|
|
|
def log(msg):
|
|
|
|
LOG_FILE.write(msg + "\n")
|
|
|
|
LOG_FILE.flush()
|
2014-05-27 00:40:52 -04:00
|
|
|
|
2014-11-12 19:30:58 -05:00
|
|
|
def log_and_print(msg):
|
|
|
|
print msg
|
|
|
|
log(msg)
|
|
|
|
|
|
|
|
# Prompt the user to delete the scratch directory used
|
2014-02-09 02:13:34 -05:00
|
|
|
def clean_work_files():
|
2014-11-12 19:30:58 -05:00
|
|
|
response = raw_input("OK to delete scratch directory '%s'? (y/N) " % WORK_DIR)
|
2014-05-27 00:40:52 -04:00
|
|
|
if response == "y":
|
|
|
|
shutil.rmtree(WORK_DIR)
|
2014-02-09 02:13:34 -05:00
|
|
|
|
2014-11-12 19:30:58 -05:00
|
|
|
# Run the given command and log its output to the log file
|
2014-02-09 02:13:34 -05:00
|
|
|
def run_cmd(cmd, exit_on_failure=True):
|
2014-11-12 19:30:58 -05:00
|
|
|
log("Running command: %s" % cmd)
|
2014-05-27 00:40:52 -04:00
|
|
|
ret = subprocess.call(cmd, shell=True, stdout=LOG_FILE, stderr=LOG_FILE)
|
|
|
|
if ret != 0 and exit_on_failure:
|
2014-11-12 19:30:58 -05:00
|
|
|
log_and_print("Command failed: %s" % cmd)
|
2014-05-27 00:40:52 -04:00
|
|
|
clean_work_files()
|
|
|
|
sys.exit(-1)
|
|
|
|
return ret
|
|
|
|
|
2014-02-09 02:13:34 -05:00
|
|
|
def run_cmd_with_output(cmd):
|
2014-11-12 19:30:58 -05:00
|
|
|
log_and_print("Running command: %s" % cmd)
|
2014-05-27 00:40:52 -04:00
|
|
|
return subprocess.check_output(cmd, shell=True, stderr=LOG_FILE)
|
|
|
|
|
2014-11-12 19:30:58 -05:00
|
|
|
# Test if the given condition is successful
|
|
|
|
# If so, print the pass message; otherwise print the failure message
|
|
|
|
def test(cond, msg):
|
|
|
|
return passed(msg) if cond else failed(msg)
|
2014-02-09 02:13:34 -05:00
|
|
|
|
2014-11-12 19:30:58 -05:00
|
|
|
def passed(msg):
|
|
|
|
log_and_print("[PASSED] %s" % msg)
|
2014-05-27 00:40:52 -04:00
|
|
|
|
2014-11-12 19:30:58 -05:00
|
|
|
def failed(msg):
|
|
|
|
failures.append(msg)
|
|
|
|
log_and_print("[**FAILED**] %s" % msg)
|
2014-02-09 02:13:34 -05:00
|
|
|
|
|
|
|
def get_url(url):
|
2014-05-27 00:40:52 -04:00
|
|
|
return urllib2.urlopen(url).read()
|
|
|
|
|
2014-11-12 19:30:58 -05:00
|
|
|
# If the path exists, prompt the user to delete it
|
|
|
|
# If the resource is not deleted, abort
|
|
|
|
def ensure_path_not_present(path):
|
|
|
|
full_path = os.path.expanduser(path)
|
|
|
|
if os.path.exists(full_path):
|
|
|
|
print "Found %s locally." % full_path
|
|
|
|
response = raw_input("This can interfere with testing published artifacts. OK to delete? (y/N) ")
|
|
|
|
if response == "y":
|
|
|
|
shutil.rmtree(full_path)
|
|
|
|
else:
|
|
|
|
print "Abort."
|
|
|
|
sys.exit(-1)
|
|
|
|
|
|
|
|
log_and_print("|-------- Starting Spark audit tests for release %s --------|" % RELEASE_VERSION)
|
|
|
|
log_and_print("Log output can be found in %s" % LOG_FILE_NAME)
|
2014-02-09 02:13:34 -05:00
|
|
|
|
|
|
|
original_dir = os.getcwd()
|
|
|
|
|
2014-05-27 00:40:52 -04:00
|
|
|
# For each of these modules, we'll test an 'empty' application in sbt and
|
2014-02-09 02:13:34 -05:00
|
|
|
# maven that links against them. This will catch issues with messed up
|
|
|
|
# dependencies within those projects.
|
2014-05-22 23:48:55 -04:00
|
|
|
modules = [
|
2015-12-20 01:40:35 -05:00
|
|
|
"spark-core", "spark-mllib", "spark-streaming", "spark-repl",
|
2016-03-25 20:37:16 -04:00
|
|
|
"spark-graphx", "spark-streaming-flume", "spark-streaming-kafka",
|
2014-08-02 16:35:35 -04:00
|
|
|
"spark-catalyst", "spark-sql", "spark-hive", "spark-streaming-kinesis-asl"
|
2014-05-22 23:48:55 -04:00
|
|
|
]
|
2014-02-09 02:13:34 -05:00
|
|
|
modules = map(lambda m: "%s_%s" % (m, SCALA_BINARY_VERSION), modules)
|
|
|
|
|
|
|
|
# Check for directories that might interfere with tests
|
|
|
|
local_ivy_spark = "~/.ivy2/local/org.apache.spark"
|
|
|
|
cache_ivy_spark = "~/.ivy2/cache/org.apache.spark"
|
|
|
|
local_maven_kafka = "~/.m2/repository/org/apache/kafka"
|
|
|
|
local_maven_kafka = "~/.m2/repository/org/apache/spark"
|
|
|
|
map(ensure_path_not_present, [local_ivy_spark, cache_ivy_spark, local_maven_kafka])
|
|
|
|
|
2014-05-27 00:40:52 -04:00
|
|
|
# SBT build tests
|
2014-11-12 19:30:58 -05:00
|
|
|
log_and_print("==== Building SBT modules ====")
|
2014-02-09 02:13:34 -05:00
|
|
|
os.chdir("blank_sbt_build")
|
|
|
|
os.environ["SPARK_VERSION"] = RELEASE_VERSION
|
|
|
|
os.environ["SCALA_VERSION"] = SCALA_VERSION
|
|
|
|
os.environ["SPARK_RELEASE_REPOSITORY"] = RELEASE_REPOSITORY
|
2014-04-21 13:26:33 -04:00
|
|
|
os.environ["SPARK_AUDIT_MASTER"] = "local"
|
2014-02-09 02:13:34 -05:00
|
|
|
for module in modules:
|
2014-11-12 19:30:58 -05:00
|
|
|
log("==== Building module %s in SBT ====" % module)
|
2014-05-27 00:40:52 -04:00
|
|
|
os.environ["SPARK_MODULE"] = module
|
2014-11-12 19:30:58 -05:00
|
|
|
ret = run_cmd("%s clean update" % SBT_CMD, exit_on_failure=False)
|
|
|
|
test(ret == 0, "SBT build against '%s' module" % module)
|
2014-02-09 02:13:34 -05:00
|
|
|
os.chdir(original_dir)
|
|
|
|
|
|
|
|
# SBT application tests
|
2014-11-12 19:30:58 -05:00
|
|
|
log_and_print("==== Building SBT applications ====")
|
2014-08-02 16:35:35 -04:00
|
|
|
for app in ["sbt_app_core", "sbt_app_graphx", "sbt_app_streaming", "sbt_app_sql", "sbt_app_hive", "sbt_app_kinesis"]:
|
2014-11-12 19:30:58 -05:00
|
|
|
log("==== Building application %s in SBT ====" % app)
|
2014-05-27 00:40:52 -04:00
|
|
|
os.chdir(app)
|
2014-11-12 19:30:58 -05:00
|
|
|
ret = run_cmd("%s clean run" % SBT_CMD, exit_on_failure=False)
|
|
|
|
test(ret == 0, "SBT application (%s)" % app)
|
2014-05-27 00:40:52 -04:00
|
|
|
os.chdir(original_dir)
|
2014-02-09 02:13:34 -05:00
|
|
|
|
|
|
|
# Maven build tests
|
|
|
|
os.chdir("blank_maven_build")
|
2014-11-12 19:30:58 -05:00
|
|
|
log_and_print("==== Building Maven modules ====")
|
2014-02-09 02:13:34 -05:00
|
|
|
for module in modules:
|
2014-11-12 19:30:58 -05:00
|
|
|
log("==== Building module %s in maven ====" % module)
|
2014-05-27 00:40:52 -04:00
|
|
|
cmd = ('%s --update-snapshots -Dspark.release.repository="%s" -Dspark.version="%s" '
|
|
|
|
'-Dspark.module="%s" clean compile' %
|
|
|
|
(MAVEN_CMD, RELEASE_REPOSITORY, RELEASE_VERSION, module))
|
|
|
|
ret = run_cmd(cmd, exit_on_failure=False)
|
|
|
|
test(ret == 0, "maven build against '%s' module" % module)
|
2014-02-09 02:13:34 -05:00
|
|
|
os.chdir(original_dir)
|
|
|
|
|
2014-11-12 19:30:58 -05:00
|
|
|
# Maven application tests
|
|
|
|
log_and_print("==== Building Maven applications ====")
|
2014-02-09 02:13:34 -05:00
|
|
|
os.chdir("maven_app_core")
|
|
|
|
mvn_exec_cmd = ('%s --update-snapshots -Dspark.release.repository="%s" -Dspark.version="%s" '
|
|
|
|
'-Dscala.binary.version="%s" clean compile '
|
2014-05-27 00:40:52 -04:00
|
|
|
'exec:java -Dexec.mainClass="SimpleApp"' %
|
|
|
|
(MAVEN_CMD, RELEASE_REPOSITORY, RELEASE_VERSION, SCALA_BINARY_VERSION))
|
2014-02-09 02:13:34 -05:00
|
|
|
ret = run_cmd(mvn_exec_cmd, exit_on_failure=False)
|
|
|
|
test(ret == 0, "maven application (core)")
|
|
|
|
os.chdir(original_dir)
|
|
|
|
|
|
|
|
# Binary artifact tests
|
|
|
|
if os.path.exists(WORK_DIR):
|
2014-05-27 00:40:52 -04:00
|
|
|
print "Working directory '%s' already exists" % WORK_DIR
|
|
|
|
sys.exit(-1)
|
2014-02-09 02:13:34 -05:00
|
|
|
os.mkdir(WORK_DIR)
|
|
|
|
os.chdir(WORK_DIR)
|
|
|
|
|
|
|
|
index_page = get_url(RELEASE_URL)
|
|
|
|
artifact_regex = r = re.compile("<a href=\"(.*.tgz)\">")
|
|
|
|
artifacts = r.findall(index_page)
|
|
|
|
|
2014-11-12 19:30:58 -05:00
|
|
|
# Verify artifact integrity
|
2014-02-09 02:13:34 -05:00
|
|
|
for artifact in artifacts:
|
2014-11-12 19:30:58 -05:00
|
|
|
log_and_print("==== Verifying download integrity for artifact: %s ====" % artifact)
|
2014-05-27 00:40:52 -04:00
|
|
|
|
|
|
|
artifact_url = "%s/%s" % (RELEASE_URL, artifact)
|
|
|
|
key_file = "%s.asc" % artifact
|
2014-11-12 19:30:58 -05:00
|
|
|
run_cmd("wget %s" % artifact_url)
|
2014-05-27 00:40:52 -04:00
|
|
|
run_cmd("wget %s/%s" % (RELEASE_URL, key_file))
|
|
|
|
run_cmd("wget %s%s" % (artifact_url, ".sha"))
|
|
|
|
|
|
|
|
# Verify signature
|
|
|
|
run_cmd("%s --keyserver pgp.mit.edu --recv-key %s" % (GPG_CMD, RELEASE_KEY))
|
|
|
|
run_cmd("%s %s" % (GPG_CMD, key_file))
|
|
|
|
passed("Artifact signature verified.")
|
|
|
|
|
|
|
|
# Verify md5
|
|
|
|
my_md5 = run_cmd_with_output("%s --print-md MD5 %s" % (GPG_CMD, artifact)).strip()
|
|
|
|
release_md5 = get_url("%s.md5" % artifact_url).strip()
|
|
|
|
test(my_md5 == release_md5, "Artifact MD5 verified.")
|
|
|
|
|
|
|
|
# Verify sha
|
|
|
|
my_sha = run_cmd_with_output("%s --print-md SHA512 %s" % (GPG_CMD, artifact)).strip()
|
|
|
|
release_sha = get_url("%s.sha" % artifact_url).strip()
|
|
|
|
test(my_sha == release_sha, "Artifact SHA verified.")
|
|
|
|
|
|
|
|
# Verify Apache required files
|
|
|
|
dir_name = artifact.replace(".tgz", "")
|
|
|
|
run_cmd("tar xvzf %s" % artifact)
|
|
|
|
base_files = os.listdir(dir_name)
|
|
|
|
test("CHANGES.txt" in base_files, "Tarball contains CHANGES.txt file")
|
|
|
|
test("NOTICE" in base_files, "Tarball contains NOTICE file")
|
|
|
|
test("LICENSE" in base_files, "Tarball contains LICENSE file")
|
|
|
|
|
|
|
|
os.chdir(WORK_DIR)
|
|
|
|
|
2014-11-12 19:30:58 -05:00
|
|
|
# Report result
|
|
|
|
log_and_print("\n")
|
2014-02-09 02:13:34 -05:00
|
|
|
if len(failures) == 0:
|
2014-11-12 19:30:58 -05:00
|
|
|
log_and_print("*** ALL TESTS PASSED ***")
|
2014-02-09 02:13:34 -05:00
|
|
|
else:
|
2014-11-12 19:30:58 -05:00
|
|
|
log_and_print("XXXXX SOME TESTS DID NOT PASS XXXXX")
|
2014-05-27 00:40:52 -04:00
|
|
|
for f in failures:
|
2014-11-12 19:30:58 -05:00
|
|
|
log_and_print(" %s" % f)
|
2014-02-09 02:13:34 -05:00
|
|
|
os.chdir(original_dir)
|
2014-11-12 19:30:58 -05:00
|
|
|
|
|
|
|
# Clean up
|
|
|
|
clean_work_files()
|
|
|
|
|
|
|
|
log_and_print("|-------- Spark release audit complete --------|")
|