mirror of
https://github.com/NVIDIA/OpenShell.git
synced 2026-11-01 07:53:42 +08:00
feat(api)!: unify sandbox references
Signed-off-by: Drew Newberry <anewberry@nvidia.com>
This commit is contained in:
@@ -43,7 +43,12 @@ from openshell.sandbox import (
|
||||
|
||||
|
||||
def _request_workspace(request: Any) -> str | None:
|
||||
scope = request.workspace_scope
|
||||
sandbox_ref = getattr(request, "sandbox_ref", None)
|
||||
scope = (
|
||||
sandbox_ref.workspace_scope
|
||||
if sandbox_ref is not None and sandbox_ref.HasField("workspace_scope")
|
||||
else request.workspace_scope
|
||||
)
|
||||
if scope.WhichOneof("selection") == "workspace":
|
||||
return cast("str", scope.workspace)
|
||||
return None
|
||||
@@ -53,6 +58,12 @@ def _request_selects_all_workspaces(request: Any) -> bool:
|
||||
return request.workspace_scope.WhichOneof("selection") == "all_workspaces"
|
||||
|
||||
|
||||
def _request_sandbox_name(request: Any) -> str:
|
||||
sandbox_ref = request.sandbox_ref
|
||||
assert sandbox_ref.WhichOneof("identifier") == "name"
|
||||
return cast("str", sandbox_ref.name)
|
||||
|
||||
|
||||
def _client_credentials_fixture() -> dict[str, Any]:
|
||||
return json.loads(
|
||||
(
|
||||
@@ -1993,7 +2004,7 @@ class _FakeSandboxStub:
|
||||
return SimpleNamespace(
|
||||
sandbox=_make_sandbox_proto(
|
||||
"sandbox-1",
|
||||
request.name,
|
||||
_request_sandbox_name(request),
|
||||
workspace=_request_workspace(request) or "default",
|
||||
)
|
||||
)
|
||||
@@ -2017,7 +2028,7 @@ class _FakeSandboxStub:
|
||||
return SimpleNamespace(
|
||||
sandbox=_make_sandbox_proto(
|
||||
"sandbox-1",
|
||||
request.name,
|
||||
_request_sandbox_name(request),
|
||||
phase=openshell_pb2.SANDBOX_PHASE_STOPPED,
|
||||
workspace=_request_workspace(request) or "default",
|
||||
)
|
||||
@@ -2033,7 +2044,7 @@ class _FakeSandboxStub:
|
||||
return SimpleNamespace(
|
||||
sandbox=_make_sandbox_proto(
|
||||
"sandbox-1",
|
||||
request.name,
|
||||
_request_sandbox_name(request),
|
||||
phase=openshell_pb2.SANDBOX_PHASE_STARTING,
|
||||
workspace=_request_workspace(request) or "default",
|
||||
)
|
||||
@@ -2429,13 +2440,13 @@ def test_stop_and_start_forward_workspace_and_return_phase() -> None:
|
||||
|
||||
stopped = client.stop("job-1", workspace="team-a")
|
||||
assert stub.stop_request is not None
|
||||
assert stub.stop_request.name == "job-1"
|
||||
assert _request_sandbox_name(stub.stop_request) == "job-1"
|
||||
assert _request_workspace(stub.stop_request) == "team-a"
|
||||
assert stopped.phase == openshell_pb2.SANDBOX_PHASE_STOPPED
|
||||
|
||||
starting = client.start("job-1", workspace="team-a")
|
||||
assert stub.start_request is not None
|
||||
assert stub.start_request.name == "job-1"
|
||||
assert _request_sandbox_name(stub.start_request) == "job-1"
|
||||
assert _request_workspace(stub.start_request) == "team-a"
|
||||
assert starting.phase == openshell_pb2.SANDBOX_PHASE_STARTING
|
||||
|
||||
@@ -2460,7 +2471,7 @@ def test_wait_ready_handles_terminal_main_process_results(
|
||||
return SimpleNamespace(
|
||||
sandbox=_make_sandbox_proto(
|
||||
"sandbox-1",
|
||||
request.name,
|
||||
_request_sandbox_name(request),
|
||||
phase=phase,
|
||||
workspace=_request_workspace(request) or "default",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user