feat: add confirm_submit_job (two-step submit flow)
This commit is contained in:
@@ -77,3 +77,56 @@ def test_prepare_snapshots_connection_at_prepare_time(monkeypatch):
|
||||
p2 = submit.pending_store.get(p.pending_id)
|
||||
assert p2.master == "yarn"
|
||||
assert p2.deploy_mode == "cluster"
|
||||
|
||||
|
||||
# --- confirm_submit_job ---
|
||||
|
||||
def test_confirm_invokes_spark_submit_and_marks_submitted(monkeypatch):
|
||||
submit.prepare_submit_job(connection="prod", script_path="/tmp/j.py")
|
||||
pid = _last_pending_id()
|
||||
fake_proc = type("P", (), {
|
||||
"returncode": 0,
|
||||
"stderr": "tracking URL: http://rm:8088/proxy/application_17400000001/\n",
|
||||
})()
|
||||
with patch("spark_executor.tools.submit.run_spark_submit", return_value=fake_proc) as m:
|
||||
result = submit.confirm_submit_job(pending_id=pid)
|
||||
cmd = m.call_args.args[0]
|
||||
assert "yarn" in cmd
|
||||
assert "cluster" in cmd
|
||||
assert cmd[-1] == "/tmp/j.py"
|
||||
assert result.application_id == "application_17400000001"
|
||||
# pending updated
|
||||
p = submit.pending_store.get(pid)
|
||||
assert p.status == "SUBMITTED"
|
||||
assert p.application_id == "application_17400000001"
|
||||
assert p.job_id is not None
|
||||
|
||||
|
||||
def test_confirm_raises_for_unknown_pending_id():
|
||||
with pytest.raises(KeyError, match="missing"):
|
||||
submit.confirm_submit_job(pending_id="missing")
|
||||
|
||||
|
||||
def test_confirm_refuses_non_pending_status(monkeypatch):
|
||||
submit.prepare_submit_job(connection="prod", script_path="/tmp/j.py")
|
||||
pid = _last_pending_id()
|
||||
# Mark it CANCELLED first
|
||||
p = submit.pending_store.get(pid)
|
||||
p.status = "CANCELLED"
|
||||
submit.pending_store.save(p)
|
||||
with pytest.raises(ValueError, match="CANCELLED"):
|
||||
submit.confirm_submit_job(pending_id=pid)
|
||||
|
||||
|
||||
def test_confirm_marks_failed_on_spark_submit_error(monkeypatch):
|
||||
from spark_executor.core.spark_submit import SparkSubmitError
|
||||
submit.prepare_submit_job(connection="prod", script_path="/tmp/j.py")
|
||||
pid = _last_pending_id()
|
||||
def _raise(_cmd):
|
||||
raise SparkSubmitError("boom")
|
||||
monkeypatch.setattr(submit, "run_spark_submit", _raise)
|
||||
with pytest.raises(SparkSubmitError):
|
||||
submit.confirm_submit_job(pending_id=pid)
|
||||
p = submit.pending_store.get(pid)
|
||||
assert p.status == "FAILED"
|
||||
assert "boom" in (p.error or "")
|
||||
|
||||
Reference in New Issue
Block a user