Skip to content

Commit

Permalink
style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
squito committed Jan 2, 2019
1 parent 9cc545b commit c6e0811
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion python/pyspark/accumulators.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def authenticate_and_accum_updates():
raise Exception(
"The value of the provided token to the AccumulatorServer is not correct.")

if auth_token:
if auth_token is not None:
# first we keep polling till we've received the authentication token
poll(authenticate_and_accum_updates)
# now we've authenticated if needed, don't need to check for the token anymore
Expand Down
2 changes: 1 addition & 1 deletion python/pyspark/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def __init__(self, master=None, appName=None, sparkHome=None, pyFiles=None,
"You are passing in an insecure Py4j gateway. This "
"presents a security risk, and will be completely forbidden in Spark 3.0")
else:
raise Exception(
raise ValueError(
"You are trying to pass an insecure Py4j gateway to Spark. This"
" presents a security risk. If you are sure you understand and accept this"
" risk, you can set the environment variable"
Expand Down
4 changes: 2 additions & 2 deletions python/pyspark/java_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def _launch_gateway(conf=None, insecure=False):
:param insecure: True to create an insecure gateway; only for testing
:return: a JVM gateway
"""
if insecure and not os.environ.get("SPARK_TESTING", "0") == "1":
raise Exception("creating insecure gateways is only for testing")
if insecure and os.environ.get("SPARK_TESTING", "0") != "1":
raise ValueError("creating insecure gateways is only for testing")
if "PYSPARK_GATEWAY_PORT" in os.environ:
gateway_port = int(os.environ["PYSPARK_GATEWAY_PORT"])
gateway_secret = os.environ["PYSPARK_GATEWAY_SECRET"]
Expand Down
17 changes: 11 additions & 6 deletions python/pyspark/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2386,11 +2386,17 @@ def test_forbid_insecure_gateway(self):
# By default, we fail immediately if you try to create a SparkContext
# with an insecure gateway
gateway = _launch_gateway(insecure=True)
with self.assertRaises(Exception) as context:
SparkContext(gateway=gateway)
self.assertIn("insecure Py4j gateway", str(context.exception))
self.assertIn("PYSPARK_ALLOW_INSECURE_GATEWAY", str(context.exception))
self.assertIn("removed in Spark 3.0", str(context.exception))
log4j = gateway.jvm.org.apache.log4j
old_level = log4j.LogManager.getRootLogger().getLevel()
try:
log4j.LogManager.getRootLogger().setLevel(log4j.Level.FATAL)
with self.assertRaises(Exception) as context:
SparkContext(gateway=gateway)
self.assertIn("insecure Py4j gateway", str(context.exception))
self.assertIn("PYSPARK_ALLOW_INSECURE_GATEWAY", str(context.exception))
self.assertIn("removed in Spark 3.0", str(context.exception))
finally:
log4j.LogManager.getRootLogger().setLevel(old_level)

def test_allow_insecure_gateway_with_conf(self):
with SparkContext._lock:
Expand All @@ -2400,7 +2406,6 @@ def test_allow_insecure_gateway_with_conf(self):
try:
os.environ["PYSPARK_ALLOW_INSECURE_GATEWAY"] = "1"
with SparkContext(gateway=gateway) as sc:
print("sc created, about to create accum")
a = sc.accumulator(1)
rdd = sc.parallelize([1, 2, 3])
rdd.foreach(lambda x: a.add(x))
Expand Down

0 comments on commit c6e0811

Please sign in to comment.