v1.1.47: fix scenario UUID extraction — _find_uid + _uid_from_location fallback
This commit is contained in:
+1
-1
@@ -18,7 +18,7 @@ from routes.api_test import bp as api_test_bp
|
|||||||
from routes.api_scenario import bp as api_scenario_bp
|
from routes.api_scenario import bp as api_scenario_bp
|
||||||
|
|
||||||
# Версия — меняется при КАЖДОМ изменении кода. Показывается в топбаре UI.
|
# Версия — меняется при КАЖДОМ изменении кода. Показывается в топбаре UI.
|
||||||
VERSION = "1.1.46"
|
VERSION = "1.1.47"
|
||||||
|
|
||||||
app = Flask(__name__, template_folder="templates", static_folder="static")
|
app = Flask(__name__, template_folder="templates", static_folder="static")
|
||||||
app.config["NUBES_API_ENDPOINT"] = os.getenv("NUBES_API_ENDPOINT", "https://lk-api-gateway-test.ngcloud.ru/api/v1/svc")
|
app.config["NUBES_API_ENDPOINT"] = os.getenv("NUBES_API_ENDPOINT", "https://lk-api-gateway-test.ngcloud.ru/api/v1/svc")
|
||||||
|
|||||||
@@ -27,13 +27,31 @@ import uuid
|
|||||||
|
|
||||||
from runner import load_config
|
from runner import load_config
|
||||||
from operations.get_services import get_service_detail
|
from operations.get_services import get_service_detail
|
||||||
from operations.get_instances import get_instances
|
|
||||||
from db.pool import get_conn, put_conn
|
from db.pool import get_conn, put_conn
|
||||||
from db.save_run import save_run
|
from db.save_run import save_run
|
||||||
|
|
||||||
AUTOTEST_PREFIX = "autotest-scenario-"
|
AUTOTEST_PREFIX = "autotest-scenario-"
|
||||||
|
|
||||||
|
|
||||||
|
def _find_uid(resp):
|
||||||
|
"""Extract UUID from nested response (e.g. {instanceOperation: {instanceOperationUid: ...}})."""
|
||||||
|
if isinstance(resp, dict):
|
||||||
|
for v in resp.values():
|
||||||
|
if isinstance(v, dict):
|
||||||
|
uid = v.get("instanceOperationUid") or v.get("instanceUid")
|
||||||
|
if uid:
|
||||||
|
return uid
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def _uid_from_location(loc):
|
||||||
|
"""Extract UUID from Location header."""
|
||||||
|
if not loc:
|
||||||
|
return None
|
||||||
|
parts = str(loc).rstrip("/").split("/")
|
||||||
|
return parts[-1] if parts[-1] else None
|
||||||
|
|
||||||
|
|
||||||
def load_scenarios():
|
def load_scenarios():
|
||||||
"""Загрузить словарь сценариев из config.yaml."""
|
"""Загрузить словарь сценариев из config.yaml."""
|
||||||
cfg = load_config() or {}
|
cfg = load_config() or {}
|
||||||
@@ -162,9 +180,9 @@ def run_scenario(client, scenario_name, client_id, stand, user_email, app_versio
|
|||||||
descr = f"scenario {scenario_name} step {step_num}"
|
descr = f"scenario {scenario_name} step {step_num}"
|
||||||
payload = {"serviceId": svc_id, "displayName": display_name, "descr": descr}
|
payload = {"serviceId": svc_id, "displayName": display_name, "descr": descr}
|
||||||
resp = client.post("/instances", payload)
|
resp = client.post("/instances", payload)
|
||||||
instance_uid = resp.get("instanceUid")
|
instance_uid = resp.get("instanceUid") or _find_uid(resp) or _uid_from_location(resp.get("_location", ""))
|
||||||
if not instance_uid:
|
if not instance_uid:
|
||||||
raise RuntimeError("CREATE: no instanceUid in response")
|
raise RuntimeError(f"CREATE: no instanceUid in response: {json.dumps(resp)[:200]}")
|
||||||
instance_map[svc_name] = instance_uid
|
instance_map[svc_name] = instance_uid
|
||||||
else:
|
else:
|
||||||
instance_uid = instance_map.get(svc_name)
|
instance_uid = instance_map.get(svc_name)
|
||||||
@@ -176,12 +194,11 @@ def run_scenario(client, scenario_name, client_id, stand, user_email, app_versio
|
|||||||
op_resp = client.post("/instanceOperations", op_payload)
|
op_resp = client.post("/instanceOperations", op_payload)
|
||||||
op_uid = op_resp.get("instanceOperationUid") or op_resp.get("instanceOperation", {}).get("instanceOperationUid")
|
op_uid = op_resp.get("instanceOperationUid") or op_resp.get("instanceOperation", {}).get("instanceOperationUid")
|
||||||
if not op_uid:
|
if not op_uid:
|
||||||
op_uid = next((v for k, v in op_resp.items() if "Uid" in k or "uid" in k), None)
|
op_uid = _find_uid(op_resp)
|
||||||
if not op_uid and "_location" in op_resp:
|
|
||||||
loc = op_resp["_location"]
|
|
||||||
op_uid = loc.rsplit("/", 1)[-1] if "/" in loc else loc
|
|
||||||
if not op_uid:
|
if not op_uid:
|
||||||
raise RuntimeError("No opUid in response")
|
op_uid = _uid_from_location(op_resp.get("_location", ""))
|
||||||
|
if not op_uid:
|
||||||
|
raise RuntimeError(f"No opUid in response: {json.dumps(op_resp)[:200]}")
|
||||||
|
|
||||||
# Отправить параметры и запустить
|
# Отправить параметры и запустить
|
||||||
from routes.api_test import _send_params_terraform
|
from routes.api_test import _send_params_terraform
|
||||||
|
|||||||
Reference in New Issue
Block a user