Add per-Connection ssl_verify / ssl_ca_bundle plus global defaults so CDH 5 / on-prem clusters with self-signed certs or custom CA bundles can be queried without patching code. - Connection gets ssl_verify (bool|None) and ssl_ca_bundle (str|None) - Settings gets ssl_verify_default and ssl_ca_bundle_default - New YarnClientConfig dataclass carries the resolved verify= value - _request passes verify= through to httpx.request - All public yarn_client functions now take YarnClientConfig instead of a bare yarn_rm_url string; tool call sites resolve the Connection - SaveConnectionRequest exposes the two new fields Tests cover per-connection CA bundle, per-connection verify=False, global default fallback, and connection-not-found error.
135 lines
3.9 KiB
Python
135 lines
3.9 KiB
Python
# coding=utf-8
|
|
from datetime import datetime
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
from spark_executor.core import connection_store
|
|
from spark_executor.core.job_store import JobStore
|
|
from spark_executor.models import Connection, Job
|
|
from spark_executor.tools import result
|
|
from spark_executor.tools import connections
|
|
|
|
|
|
def _fresh_stores():
|
|
store = connection_store.ConnectionStore()
|
|
connection_store.store = store
|
|
connections.store = store
|
|
result.conn_store = store
|
|
result.store = JobStore()
|
|
|
|
|
|
def _seed(job_id="abc", app_id="application_1"):
|
|
_fresh_stores()
|
|
result.conn_store.save(Connection(name="prod", master="yarn", yarn_rm_url="http://rm:8088"))
|
|
result.store.put(
|
|
Job(
|
|
job_id=job_id,
|
|
application_id=app_id,
|
|
script_path="/tmp/j.py",
|
|
queue="default",
|
|
submit_time=datetime(2026, 6, 24),
|
|
connection="prod",
|
|
yarn_rm_url="http://rm:8088",
|
|
)
|
|
)
|
|
|
|
|
|
def test_result_returns_parsed_fields():
|
|
_seed()
|
|
raw = {
|
|
"app": {
|
|
"id": "application_1",
|
|
"state": "FINISHED",
|
|
"finalStatus": "SUCCEEDED",
|
|
"diagnostics": "Application completed successfully",
|
|
"trackingUrl": "http://nm:8088/proxy/application_1",
|
|
"startedTime": 1700000000000,
|
|
"finishedTime": 1700000123000,
|
|
}
|
|
}
|
|
import json
|
|
|
|
with patch(
|
|
"spark_executor.tools.result.get_application_status",
|
|
return_value=("FINISHED", json.dumps(raw)),
|
|
) as m:
|
|
out = result.get_job_result("abc")
|
|
|
|
assert out.application_id == "application_1"
|
|
assert out.state == "FINISHED"
|
|
assert out.final_status == "SUCCEEDED"
|
|
assert out.diagnostics == "Application completed successfully"
|
|
assert out.tracking_url == "http://nm:8088/proxy/application_1"
|
|
assert out.started_time == 1700000000000
|
|
assert out.finished_time == 1700000123000
|
|
args = m.call_args.args
|
|
assert args[0] == "application_1"
|
|
assert args[1].yarn_rm_url == "http://rm:8088"
|
|
|
|
|
|
def test_result_handles_running_job():
|
|
_seed(job_id="running", app_id="application_2")
|
|
raw = {
|
|
"app": {
|
|
"id": "application_2",
|
|
"state": "RUNNING",
|
|
"finalStatus": "UNDEFINED",
|
|
"trackingUrl": "http://rm:8088/proxy/application_2",
|
|
"startedTime": 1700000000000,
|
|
}
|
|
}
|
|
import json
|
|
|
|
with patch(
|
|
"spark_executor.tools.result.get_application_status",
|
|
return_value=("RUNNING", json.dumps(raw)),
|
|
):
|
|
out = result.get_job_result("running")
|
|
|
|
assert out.state == "RUNNING"
|
|
assert out.final_status == "UNDEFINED"
|
|
assert out.finished_time is None
|
|
|
|
|
|
def test_result_handles_missing_optional_fields():
|
|
_seed(job_id="accepted", app_id="application_3")
|
|
raw = {"app": {"id": "application_3", "state": "ACCEPTED"}}
|
|
import json
|
|
|
|
with patch(
|
|
"spark_executor.tools.result.get_application_status",
|
|
return_value=("ACCEPTED", json.dumps(raw)),
|
|
):
|
|
out = result.get_job_result("accepted")
|
|
|
|
assert out.state == "ACCEPTED"
|
|
assert out.application_id == "application_3"
|
|
assert out.final_status is None
|
|
assert out.diagnostics is None
|
|
assert out.tracking_url is None
|
|
assert out.started_time is None
|
|
assert out.finished_time is None
|
|
|
|
|
|
def test_result_raises_keyerror_for_unknown_job():
|
|
_fresh_stores()
|
|
with pytest.raises(KeyError, match="Unknown job_id"):
|
|
result.get_job_result("missing")
|
|
|
|
|
|
def test_result_raises_when_connection_missing():
|
|
_fresh_stores()
|
|
result.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"):
|
|
result.get_job_result("abc")
|