Add per-Connection authentication so CDH 5 / Kerberos / HTTP Basic clusters can be queried. - auth_type: none / simple / basic / kerberos - auth_user / auth_password for HTTP Basic - auth_principal / auth_keytab stored for audit/display; actual SPNEGO handled by httpx-kerberos using the system Kerberos credential cache - YarnClientConfig.auth_for_httpx() returns the right httpx.Auth object - _request passes auth= through to httpx.request alongside verify= New dependency: httpx-kerberos. Tests cover none/simple (no auth object), Basic auth header, Kerberos auth object, missing basic user, invalid auth_type, and tool-layer config propagation.
106 lines
3.1 KiB
Python
106 lines
3.1 KiB
Python
# coding=utf-8
|
|
from datetime import datetime
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
from spark_executor.core.job_store import JobStore
|
|
from spark_executor.core import connection_store
|
|
from spark_executor.models import Connection, Job
|
|
from spark_executor.tools import connections, status
|
|
from spark_executor.core.yarn_client import YarnClientConfig
|
|
|
|
|
|
def _fresh_stores():
|
|
"""Reset job store and connection store singletons for a single test."""
|
|
store = connection_store.ConnectionStore()
|
|
connection_store.store = store
|
|
connections.store = store
|
|
status.conn_store = store
|
|
status.store = JobStore()
|
|
|
|
|
|
def test_get_job_status_returns_state():
|
|
_fresh_stores()
|
|
status.conn_store.save(Connection(name="prod", master="yarn", yarn_rm_url="http://rm:8088"))
|
|
status.store.put(
|
|
Job(
|
|
job_id="abc",
|
|
application_id="application_1",
|
|
script_path="/tmp/j.py",
|
|
queue="default",
|
|
submit_time=datetime(2026, 6, 24),
|
|
connection="prod",
|
|
yarn_rm_url="http://rm:8088",
|
|
)
|
|
)
|
|
with patch(
|
|
"spark_executor.tools.status.get_application_status",
|
|
return_value=("RUNNING", "State : RUNNING\n"),
|
|
) as m:
|
|
out = status.get_job_status("abc")
|
|
assert out.application_id == "application_1"
|
|
assert out.state == "RUNNING"
|
|
assert "RUNNING" in out.raw
|
|
# resolved YarnClientConfig is forwarded to the REST client
|
|
args = m.call_args.args
|
|
assert args[0] == "application_1"
|
|
assert args[1].yarn_rm_url == "http://rm:8088"
|
|
|
|
|
|
def test_get_job_status_raises_for_unknown_job():
|
|
_fresh_stores()
|
|
with pytest.raises(KeyError):
|
|
status.get_job_status("missing")
|
|
|
|
|
|
def test_get_job_status_raises_when_connection_missing():
|
|
_fresh_stores()
|
|
status.store.put(
|
|
Job(
|
|
job_id="abc",
|
|
application_id="application_1",
|
|
script_path="/tmp/j.py",
|
|
queue="default",
|
|
submit_time=datetime(2026, 6, 24),
|
|
connection="missing",
|
|
)
|
|
)
|
|
with pytest.raises(KeyError, match="Connection not found"):
|
|
status.get_job_status("abc")
|
|
|
|
|
|
def test_get_job_status_passes_auth_config():
|
|
_fresh_stores()
|
|
status.conn_store.save(
|
|
Connection(
|
|
name="secure",
|
|
master="yarn",
|
|
yarn_rm_url="http://rm:8088",
|
|
auth_type="basic",
|
|
auth_user="hdfs",
|
|
auth_password="secret",
|
|
)
|
|
)
|
|
status.store.put(
|
|
Job(
|
|
job_id="abc",
|
|
application_id="application_1",
|
|
script_path="/tmp/j.py",
|
|
queue="default",
|
|
submit_time=datetime(2026, 6, 24),
|
|
connection="secure",
|
|
yarn_rm_url="http://rm:8088",
|
|
)
|
|
)
|
|
with patch(
|
|
"spark_executor.tools.status.get_application_status",
|
|
return_value=("RUNNING", "State : RUNNING\n"),
|
|
) as m:
|
|
status.get_job_status("abc")
|
|
args = m.call_args.args
|
|
assert args[0] == "application_1"
|
|
assert isinstance(args[1], YarnClientConfig)
|
|
assert args[1].auth_type == "basic"
|
|
assert args[1].auth_user == "hdfs"
|