Files
tracer-cloud--opensre/tests/shared/infrastructure_sdk/config.py
T
wehub-resource-sync 4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:10:45 +08:00

96 lines
2.4 KiB
Python

"""Stack output management - save/load outputs."""
import json
from pathlib import Path
from typing import Any
# Output files are stored in this directory
OUTPUTS_DIR = Path(__file__).parent / "outputs"
def _ensure_outputs_dir() -> None:
"""Ensure the outputs directory exists."""
OUTPUTS_DIR.mkdir(parents=True, exist_ok=True)
def _get_output_path(stack_name: str) -> Path:
"""Get the path to an output file."""
return OUTPUTS_DIR / f"{stack_name}.json"
def save_outputs(stack_name: str, outputs: dict[str, Any]) -> None:
"""Save stack outputs to local JSON file for tests to read.
Args:
stack_name: Name of the stack.
outputs: Dictionary of outputs to save.
"""
_ensure_outputs_dir()
output_path = _get_output_path(stack_name)
with open(output_path, "w") as f:
json.dump(outputs, f, indent=2, default=str)
def load_outputs(stack_name: str) -> dict[str, Any]:
"""Load stack outputs from JSON file.
Args:
stack_name: Name of the stack.
Returns:
Dictionary of outputs.
Raises:
FileNotFoundError: If outputs file doesn't exist.
"""
output_path = _get_output_path(stack_name)
if not output_path.exists():
raise FileNotFoundError(
f"No outputs found for stack '{stack_name}'. Deploy the stack first."
)
with open(output_path) as f:
result: dict[str, Any] = json.load(f)
return result
def get_output(stack_name: str, key: str) -> str:
"""Get single output value.
Args:
stack_name: Name of the stack.
key: Output key to retrieve.
Returns:
The output value as a string.
Raises:
KeyError: If the key doesn't exist.
"""
outputs = load_outputs(stack_name)
if key not in outputs:
raise KeyError(
f"Output '{key}' not found in stack '{stack_name}'. Available: {list(outputs.keys())}"
)
return str(outputs[key])
def delete_outputs(stack_name: str) -> None:
"""Delete stack outputs file.
Args:
stack_name: Name of the stack.
"""
output_path = _get_output_path(stack_name)
if output_path.exists():
output_path.unlink()
def list_stacks() -> list[str]:
"""List all stacks that have saved outputs.
Returns:
List of stack names.
"""
_ensure_outputs_dir()
return [p.stem for p in OUTPUTS_DIR.glob("*.json")]