-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,7 @@ class TestSparkSubmitHook: | |
"args should keep embedded spaces", | ||
"baz", | ||
], | ||
"use_krb5ccache": True, | ||
} | ||
|
||
@staticmethod | ||
|
@@ -141,7 +142,10 @@ def setup_method(self): | |
) | ||
) | ||
|
||
def test_build_spark_submit_command(self): | ||
@patch( | ||
"airflow.providers.apache.spark.hooks.spark_submit.os.getenv", return_value="/tmp/airflow_krb5_ccache" | ||
) | ||
def test_build_spark_submit_command(self, mock_get_env): | ||
# Given | ||
hook = SparkSubmitHook(**self._config) | ||
|
||
|
@@ -183,6 +187,8 @@ def test_build_spark_submit_command(self): | |
"privileged_user.keytab", | ||
"--principal", | ||
"user/[email protected]", | ||
"--conf", | ||
"spark.kerberos.renewal.credentials=ccache", | ||
"--proxy-user", | ||
"sample_user", | ||
"--name", | ||
|
@@ -200,6 +206,25 @@ def test_build_spark_submit_command(self): | |
"baz", | ||
] | ||
assert expected_build_cmd == cmd | ||
mock_get_env.assert_called_with("KRB5CCNAME") | ||
|
||
@patch("airflow.configuration.conf.get_mandatory_value") | ||
def test_resolve_spark_submit_env_vars_use_krb5ccache_missing_principal(self, mock_get_madantory_value): | ||
mock_principle = "airflow" | ||
mock_get_madantory_value.return_value = mock_principle | ||
hook = SparkSubmitHook(conn_id="spark_yarn_cluster", principal=None, use_krb5ccache=True) | ||
mock_get_madantory_value.assert_called_with("kerberos", "principal") | ||
assert hook._principal == mock_principle | ||
|
||
def test_resolve_spark_submit_env_vars_use_krb5ccache_missing_KRB5CCNAME_env(self): | ||
hook = SparkSubmitHook( | ||
conn_id="spark_yarn_cluster", principal="user/[email protected]", use_krb5ccache=True | ||
) | ||
with pytest.raises( | ||
AirflowException, | ||
match="KRB5CCNAME environment variable required to use ticket ccache is missing.", | ||
): | ||
hook._build_spark_submit_command(self._spark_job_file) | ||
|
||
def test_build_track_driver_status_command(self): | ||
# note this function is only relevant for spark setup matching below condition | ||
|