122 lines
3.8 KiB
Python
122 lines
3.8 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
本地鉴权自检(不启动 MCP)。
|
||
|
||
优先读取 mcp/.env(需 pip install python-dotenv)。
|
||
也可在 PowerShell 里用 $env:XXX=... 临时设置。
|
||
|
||
cd mmp-training-workflow/mcp
|
||
conda activate mmp-training
|
||
pip install -r requirements.txt
|
||
python scripts/debug_auth.py
|
||
"""
|
||
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
# 将 mcp 目录加入 path,便于 import mmp_training
|
||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||
|
||
from mmp_training.client import assert_jsm_ok, assert_mmp_ok, jsm, mmp
|
||
from mmp_training.config import (
|
||
CLUSTER_ID,
|
||
JSM_BASE_URL,
|
||
JSM_PASSWORD,
|
||
JSM_USERNAME,
|
||
MMP_BASE_URL,
|
||
MMP_BEARER_TOKEN,
|
||
MMP_PASSWORD,
|
||
MMP_USERNAME,
|
||
mmp_auth_headers,
|
||
)
|
||
from mmp_training.jsm_auth import clear_jsm_token_cache, get_jsm_authorization
|
||
from mmp_training.mmp_auth import clear_mmp_token_cache, get_mmp_authorization
|
||
|
||
|
||
def main() -> None:
|
||
print("=== MMP 训练 MCP 鉴权自检 (Python) ===\n")
|
||
print("MMP_BASE_URL:", MMP_BASE_URL)
|
||
print("JSM_BASE_URL:", JSM_BASE_URL)
|
||
print("MMP_CLUSTER_ID:", CLUSTER_ID)
|
||
print("MMP_USERNAME:", MMP_USERNAME or "未配置")
|
||
print("MMP_PASSWORD:", "已配置" if MMP_PASSWORD else "未配置")
|
||
print(
|
||
"MMP_BEARER_TOKEN:",
|
||
f"已配置 ({MMP_BEARER_TOKEN[:20]}...)" if MMP_BEARER_TOKEN else "未配置(将走登录接口)",
|
||
)
|
||
print("JSM_USERNAME:", JSM_USERNAME or "未配置")
|
||
print("JSM_PASSWORD:", "已配置" if JSM_PASSWORD else "未配置")
|
||
print()
|
||
|
||
exit_code = 0
|
||
|
||
try:
|
||
clear_jsm_token_cache()
|
||
auth = get_jsm_authorization()
|
||
print("[OK] JSM 登录成功")
|
||
print(" Authorization:", auth[:40] + "...\n")
|
||
except Exception as e:
|
||
print("[FAIL] JSM 登录:", e)
|
||
sys.exit(1)
|
||
|
||
try:
|
||
from mmp_training.resource_catalog import list_resource_types
|
||
|
||
rt = list_resource_types()
|
||
types = [t["type"] for t in rt.get("resource_types") or []]
|
||
print(f"[OK] JSM resource/range 成功,资源类型 {len(types)} 种: {', '.join(types[:8])}\n")
|
||
except Exception as e:
|
||
print("[FAIL] JSM resource/range:", e)
|
||
exit_code = 1
|
||
|
||
try:
|
||
data = assert_jsm_ok(
|
||
jsm.post(
|
||
"/jsm/v2/resource/query",
|
||
{
|
||
"queryResource": {
|
||
"cpu": {"min": 0, "max": 0},
|
||
"memory": {"min": 0, "max": 0},
|
||
"gpu": {"min": 0, "max": 0},
|
||
"storage": {"min": 0, "max": 0},
|
||
"type": "GPU",
|
||
},
|
||
"resourceType": "Train",
|
||
"clusterIDs": [CLUSTER_ID],
|
||
},
|
||
)
|
||
)
|
||
n = len(data.get("resource") or [])
|
||
print(f"[OK] JSM resource/query 成功,资源规格 {n} 条\n")
|
||
except Exception as e:
|
||
print("[FAIL] JSM resource/query:", e)
|
||
exit_code = 1
|
||
|
||
try:
|
||
clear_mmp_token_cache()
|
||
auth = get_mmp_authorization()
|
||
print("[OK] MMP 登录成功")
|
||
print(" Authorization:", auth[:40] + "...\n")
|
||
mmp_auth_headers()
|
||
except Exception as e:
|
||
print("[FAIL] MMP 登录:", e)
|
||
sys.exit(1)
|
||
|
||
try:
|
||
data = assert_mmp_ok(mmp.get("/api/mmp/codeConfig", {"page": 0, "size": 3, "is_public": "false"}))
|
||
content = data.get("content") if isinstance(data, dict) else data
|
||
items = content if isinstance(content, list) else []
|
||
print(f"[OK] MMP codeConfig 成功,示例 {len(items)} 条")
|
||
for c in items[:3]:
|
||
print(f" - id={c.get('id')} {c.get('code_repo_name')}")
|
||
print("\n鉴权自检完成。")
|
||
except Exception as e:
|
||
print("[FAIL] MMP codeConfig:", e)
|
||
exit_code = 1
|
||
|
||
sys.exit(exit_code)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|