compose
This commit is contained in:
parent
693364c151
commit
96b8739395
1327
create-compose-package-multiplatform.sh
Executable file
1327
create-compose-package-multiplatform.sh
Executable file
File diff suppressed because it is too large
Load Diff
0
create-compose-package-simple.sh
Executable file → Normal file
0
create-compose-package-simple.sh
Executable file → Normal file
0
create-compose-package.sh
Executable file → Normal file
0
create-compose-package.sh
Executable file → Normal file
0
create-offline-package.sh
Executable file → Normal file
0
create-offline-package.sh
Executable file → Normal file
11486
summary(10).json
11486
summary(10).json
File diff suppressed because it is too large
Load Diff
920631
summary(7).json
920631
summary(7).json
File diff suppressed because one or more lines are too long
920403
summary(8).json
920403
summary(8).json
File diff suppressed because one or more lines are too long
179
test-directory-fix.sh
Normal file
179
test-directory-fix.sh
Normal file
@ -0,0 +1,179 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 测试目录创建和复制逻辑
|
||||
|
||||
set -e
|
||||
|
||||
echo "=== 测试目录创建和复制逻辑 ==="
|
||||
|
||||
# 模拟变量
|
||||
SELECTED_SERVICE_ARCH="dual"
|
||||
TARGET_PLATFORM="linux/arm64"
|
||||
MULTI_PLATFORM=false
|
||||
|
||||
# 更新导出目录名称以包含平台信息
|
||||
if [[ "$MULTI_PLATFORM" == "true" ]]; then
|
||||
EXPORT_DIR="dms-compliance-${SELECTED_SERVICE_ARCH}-multiplatform-$(date +%Y%m%d-%H%M%S)"
|
||||
else
|
||||
platform_suffix=$(echo "$TARGET_PLATFORM" | sed 's/linux\///g' | sed 's/\//-/g')
|
||||
EXPORT_DIR="dms-compliance-${SELECTED_SERVICE_ARCH}-${platform_suffix}-$(date +%Y%m%d-%H%M%S)"
|
||||
fi
|
||||
ARCHIVE_NAME="$EXPORT_DIR.tar.gz"
|
||||
|
||||
echo "[信息] 最终输出目录: $EXPORT_DIR"
|
||||
|
||||
# 创建最终导出目录
|
||||
rm -rf "$EXPORT_DIR"
|
||||
mkdir -p "$EXPORT_DIR"
|
||||
|
||||
echo "[步骤 1/4] 复制项目文件..."
|
||||
|
||||
# 创建临时构建目录
|
||||
TEMP_BUILD_DIR=$(mktemp -d)
|
||||
trap "rm -rf $TEMP_BUILD_DIR" EXIT
|
||||
|
||||
# 复制核心目录(排除缓存和临时文件)
|
||||
echo "[信息] 复制核心目录..."
|
||||
mkdir -p "$TEMP_BUILD_DIR"/{ddms_compliance_suite,custom_stages,custom_testcases,templates,static,assets}
|
||||
|
||||
# 创建测试文件
|
||||
echo "# Test content" > "$TEMP_BUILD_DIR/requirements.txt"
|
||||
echo "# Test API server" > "$TEMP_BUILD_DIR/api_server.py"
|
||||
echo "# Test history viewer" > "$TEMP_BUILD_DIR/history_viewer.py"
|
||||
echo "# Test ddms suite" > "$TEMP_BUILD_DIR/ddms_compliance_suite/test.py"
|
||||
|
||||
echo "[步骤 2/4] 创建 Dockerfile..."
|
||||
cd "$TEMP_BUILD_DIR"
|
||||
|
||||
# 创建测试Dockerfile
|
||||
cat > "Dockerfile" << 'EOF'
|
||||
FROM python:3.11-alpine
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
EXPOSE 5050 5051
|
||||
CMD ["echo", "Test dockerfile"]
|
||||
EOF
|
||||
|
||||
# 创建supervisor配置
|
||||
cat > "supervisord.conf" << 'EOF'
|
||||
[supervisord]
|
||||
nodaemon=true
|
||||
|
||||
[program:api_server]
|
||||
command=python api_server.py
|
||||
|
||||
[program:history_viewer]
|
||||
command=python history_viewer.py
|
||||
EOF
|
||||
|
||||
cd ..
|
||||
|
||||
echo "[步骤 3/4] 复制构建文件..."
|
||||
# 确保目标目录存在
|
||||
mkdir -p "$EXPORT_DIR"
|
||||
cp -r "$TEMP_BUILD_DIR"/* "$EXPORT_DIR/"
|
||||
|
||||
echo "[步骤 4/4] 创建配置文件..."
|
||||
|
||||
# 创建Docker Compose文件
|
||||
cat > "$EXPORT_DIR/docker-compose.yml" << EOF
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
dms-compliance:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
platforms:
|
||||
- $TARGET_PLATFORM
|
||||
image: compliance-dms-multiplatform:latest
|
||||
container_name: dms-compliance-tool
|
||||
ports:
|
||||
- "5050:5050" # API服务器端口
|
||||
- "5051:5051" # 历史查看器端口
|
||||
environment:
|
||||
- PYTHONPATH=/app
|
||||
- TZ=Asia/Shanghai
|
||||
- FLASK_ENV=production
|
||||
- PYTHONUNBUFFERED=1
|
||||
volumes:
|
||||
- ./uploads:/app/uploads
|
||||
- ./logs:/app/logs
|
||||
- ./test_reports:/app/test_reports
|
||||
- ./config:/app/config:ro
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD", "curl", "-f", "http://localhost:5050/"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 40s
|
||||
networks:
|
||||
- dms-network
|
||||
|
||||
networks:
|
||||
dms-network:
|
||||
driver: bridge
|
||||
|
||||
volumes:
|
||||
uploads:
|
||||
logs:
|
||||
test_reports:
|
||||
config:
|
||||
EOF
|
||||
|
||||
# 创建启动脚本
|
||||
cat > "$EXPORT_DIR/start.sh" << 'EOF'
|
||||
#!/bin/bash
|
||||
echo "=== DMS合规性测试工具启动脚本 ==="
|
||||
echo "这是一个测试脚本"
|
||||
EOF
|
||||
|
||||
chmod +x "$EXPORT_DIR/start.sh"
|
||||
|
||||
# 创建README
|
||||
cat > "$EXPORT_DIR/README.md" << EOF
|
||||
# DMS合规性测试工具 - 测试部署包
|
||||
|
||||
## 系统信息
|
||||
|
||||
- **架构**: 双服务架构 - API服务器(5050) + 历史查看器(5051)
|
||||
- **端口**: 5050,5051
|
||||
- **目标平台**: ARM64 (aarch64) - Apple M1/M2, ARM 64位
|
||||
- **构建时间**: $(date '+%Y-%m-%d %H:%M:%S')
|
||||
|
||||
## 测试成功
|
||||
|
||||
目录创建和文件复制逻辑正常工作。
|
||||
EOF
|
||||
|
||||
# 验证文件结构
|
||||
echo ""
|
||||
echo "=== 验证文件结构 ==="
|
||||
echo "导出目录内容:"
|
||||
ls -la "$EXPORT_DIR"
|
||||
echo ""
|
||||
echo "核心文件检查:"
|
||||
for file in Dockerfile docker-compose.yml start.sh README.md requirements.txt api_server.py history_viewer.py supervisord.conf; do
|
||||
if [[ -f "$EXPORT_DIR/$file" ]]; then
|
||||
echo "✅ $file"
|
||||
else
|
||||
echo "❌ $file (缺失)"
|
||||
fi
|
||||
done
|
||||
|
||||
# 创建压缩包
|
||||
echo ""
|
||||
echo "[信息] 创建压缩包..."
|
||||
tar -czf "$ARCHIVE_NAME" "$EXPORT_DIR"
|
||||
|
||||
# 清理临时目录
|
||||
rm -rf "$EXPORT_DIR"
|
||||
|
||||
# 显示结果
|
||||
echo ""
|
||||
echo "=== 测试完成 ==="
|
||||
echo "[成功] 测试部署包已创建: $ARCHIVE_NAME"
|
||||
echo "[信息] 文件大小: $(du -h "$ARCHIVE_NAME" | cut -f1)"
|
||||
echo ""
|
||||
echo "目录创建和复制逻辑测试成功!"
|
||||
253
test-multiplatform-script.sh
Executable file
253
test-multiplatform-script.sh
Executable file
@ -0,0 +1,253 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 测试多平台脚本的基本功能(不构建Docker)
|
||||
|
||||
set -e
|
||||
|
||||
# 配置变量
|
||||
EXPORT_DIR="dms-compliance-multiplatform-test-$(date +%Y%m%d-%H%M%S)"
|
||||
IMAGE_NAME="compliance-dms-multiplatform"
|
||||
ARCHIVE_NAME="$EXPORT_DIR.tar.gz"
|
||||
|
||||
# 支持的平台列表 - 使用函数替代关联数组以兼容旧版bash
|
||||
get_platform() {
|
||||
case "$1" in
|
||||
1) echo "linux/amd64" ;;
|
||||
2) echo "linux/arm64" ;;
|
||||
3) echo "linux/arm/v7" ;;
|
||||
4) echo "linux/arm/v6" ;;
|
||||
5) echo "linux/386" ;;
|
||||
6) echo "linux/ppc64le" ;;
|
||||
7) echo "linux/s390x" ;;
|
||||
8) echo "linux/riscv64" ;;
|
||||
*) echo "" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
get_platform_name() {
|
||||
case "$1" in
|
||||
"linux/amd64") echo "AMD64 (x86_64) - Intel/AMD 64位" ;;
|
||||
"linux/arm64") echo "ARM64 (aarch64) - Apple M1/M2, ARM 64位" ;;
|
||||
"linux/arm/v7") echo "ARMv7 - 树莓派 3/4, ARM 32位" ;;
|
||||
"linux/arm/v6") echo "ARMv6 - 树莓派 1/Zero, ARM 32位" ;;
|
||||
"linux/386") echo "i386 - Intel/AMD 32位" ;;
|
||||
"linux/ppc64le") echo "PowerPC 64位小端" ;;
|
||||
"linux/s390x") echo "IBM System z" ;;
|
||||
"linux/riscv64") echo "RISC-V 64位" ;;
|
||||
*) echo "未知平台" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# 服务架构选择
|
||||
get_service_arch() {
|
||||
case "$1" in
|
||||
1) echo "dual" ;;
|
||||
2) echo "fastapi" ;;
|
||||
3) echo "flask" ;;
|
||||
*) echo "" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
get_service_arch_name() {
|
||||
case "$1" in
|
||||
"dual") echo "双服务架构 - API服务器(5050) + 历史查看器(5051)" ;;
|
||||
"fastapi") echo "FastAPI单服务 - 现代异步框架,自动生成API文档(5051)" ;;
|
||||
"flask") echo "Flask单服务 - 轻量级传统框架(5050)" ;;
|
||||
*) echo "未知架构" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
get_service_ports() {
|
||||
case "$1" in
|
||||
"dual") echo "5050,5051" ;;
|
||||
"fastapi") echo "5051" ;;
|
||||
"flask") echo "5050" ;;
|
||||
*) echo "5050" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
echo "=== DMS合规性测试工具 跨平台脚本测试 ==="
|
||||
echo ""
|
||||
|
||||
# 检测当前平台
|
||||
CURRENT_ARCH=$(uname -m)
|
||||
case "$CURRENT_ARCH" in
|
||||
x86_64|amd64) CURRENT_PLATFORM="linux/amd64" ;;
|
||||
aarch64|arm64) CURRENT_PLATFORM="linux/arm64" ;;
|
||||
armv7l) CURRENT_PLATFORM="linux/arm/v7" ;;
|
||||
armv6l) CURRENT_PLATFORM="linux/arm/v6" ;;
|
||||
i386|i686) CURRENT_PLATFORM="linux/386" ;;
|
||||
*) CURRENT_PLATFORM="linux/amd64" ;;
|
||||
esac
|
||||
|
||||
echo "[信息] 当前平台: $(get_platform_name "$CURRENT_PLATFORM")"
|
||||
echo ""
|
||||
|
||||
# 选择服务架构
|
||||
echo "请选择服务架构:"
|
||||
echo " 1) $(get_service_arch_name "dual")"
|
||||
echo " 2) $(get_service_arch_name "fastapi")"
|
||||
echo " 3) $(get_service_arch_name "flask")"
|
||||
echo ""
|
||||
read -p "请输入选择 (1-3) [默认: 1]: " service_choice
|
||||
service_choice=${service_choice:-1}
|
||||
|
||||
SELECTED_SERVICE_ARCH=$(get_service_arch "$service_choice")
|
||||
if [[ -z "$SELECTED_SERVICE_ARCH" ]]; then
|
||||
echo "[错误] 无效的服务架构选择"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SELECTED_PORTS=$(get_service_ports "$SELECTED_SERVICE_ARCH")
|
||||
|
||||
echo "[信息] 选择的架构: $(get_service_arch_name "$SELECTED_SERVICE_ARCH")"
|
||||
echo "[信息] 服务端口: $SELECTED_PORTS"
|
||||
echo ""
|
||||
|
||||
# 选择目标平台
|
||||
echo "请选择目标平台架构:"
|
||||
for key in 1 2 3 4 5 6 7 8; do
|
||||
platform=$(get_platform "$key")
|
||||
name=$(get_platform_name "$platform")
|
||||
if [[ "$platform" == "$CURRENT_PLATFORM" ]]; then
|
||||
echo " $key) $name [当前平台]"
|
||||
else
|
||||
echo " $key) $name"
|
||||
fi
|
||||
done
|
||||
echo " 9) 多平台构建 (同时构建多个平台)"
|
||||
echo " 0) 自动检测当前平台"
|
||||
echo ""
|
||||
read -p "请输入选择 (0-9) [默认: 0]: " platform_choice
|
||||
platform_choice=${platform_choice:-0}
|
||||
|
||||
if [[ "$platform_choice" == "0" ]]; then
|
||||
TARGET_PLATFORM="$CURRENT_PLATFORM"
|
||||
TARGET_PLATFORM_NAME="$(get_platform_name "$CURRENT_PLATFORM") [自动检测]"
|
||||
MULTI_PLATFORM=false
|
||||
elif [[ "$platform_choice" == "9" ]]; then
|
||||
TARGET_PLATFORM="linux/amd64,linux/arm64"
|
||||
TARGET_PLATFORM_NAME="常用平台 (AMD64 + ARM64)"
|
||||
MULTI_PLATFORM=true
|
||||
else
|
||||
TARGET_PLATFORM=$(get_platform "$platform_choice")
|
||||
if [[ -z "$TARGET_PLATFORM" ]]; then
|
||||
echo "[错误] 无效的平台选择"
|
||||
exit 1
|
||||
fi
|
||||
TARGET_PLATFORM_NAME=$(get_platform_name "$TARGET_PLATFORM")
|
||||
MULTI_PLATFORM=false
|
||||
fi
|
||||
|
||||
echo "[信息] 目标平台: $TARGET_PLATFORM_NAME"
|
||||
echo "[信息] 多平台构建: $MULTI_PLATFORM"
|
||||
echo ""
|
||||
|
||||
# 确认构建
|
||||
echo "构建配置确认:"
|
||||
echo " 架构: $(get_service_arch_name "$SELECTED_SERVICE_ARCH")"
|
||||
echo " 端口: $SELECTED_PORTS"
|
||||
echo " 平台: $TARGET_PLATFORM_NAME"
|
||||
echo ""
|
||||
read -p "确认开始测试? (y/N): " confirm
|
||||
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
|
||||
echo "[信息] 测试已取消"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# 更新导出目录名称以包含平台信息
|
||||
if [[ "$MULTI_PLATFORM" == "true" ]]; then
|
||||
EXPORT_DIR="dms-compliance-${SELECTED_SERVICE_ARCH}-multiplatform-$(date +%Y%m%d-%H%M%S)"
|
||||
else
|
||||
platform_suffix=$(echo "$TARGET_PLATFORM" | sed 's/linux\///g' | sed 's/\//-/g')
|
||||
EXPORT_DIR="dms-compliance-${SELECTED_SERVICE_ARCH}-${platform_suffix}-$(date +%Y%m%d-%H%M%S)"
|
||||
fi
|
||||
ARCHIVE_NAME="$EXPORT_DIR.tar.gz"
|
||||
|
||||
echo "[信息] 最终输出目录: $EXPORT_DIR"
|
||||
|
||||
# 创建最终导出目录
|
||||
rm -rf "$EXPORT_DIR"
|
||||
mkdir -p "$EXPORT_DIR"
|
||||
|
||||
echo ""
|
||||
echo "[步骤 1/3] 创建测试文件..."
|
||||
|
||||
# 创建临时构建目录
|
||||
TEMP_BUILD_DIR=$(mktemp -d)
|
||||
trap "rm -rf $TEMP_BUILD_DIR" EXIT
|
||||
|
||||
# 创建测试文件
|
||||
mkdir -p "$TEMP_BUILD_DIR"/{ddms_compliance_suite,custom_stages,templates,static}
|
||||
echo "# Test requirements" > "$TEMP_BUILD_DIR/requirements.txt"
|
||||
echo "# Test API server" > "$TEMP_BUILD_DIR/api_server.py"
|
||||
echo "# Test history viewer" > "$TEMP_BUILD_DIR/history_viewer.py"
|
||||
|
||||
echo "[步骤 2/3] 创建配置文件..."
|
||||
|
||||
# 创建测试Dockerfile
|
||||
if [[ "$SELECTED_SERVICE_ARCH" == "dual" ]]; then
|
||||
cat > "$TEMP_BUILD_DIR/Dockerfile" << 'EOF'
|
||||
FROM python:3.11-alpine
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
EXPOSE 5050 5051
|
||||
CMD ["echo", "Dual service architecture"]
|
||||
EOF
|
||||
|
||||
cat > "$TEMP_BUILD_DIR/supervisord.conf" << 'EOF'
|
||||
[supervisord]
|
||||
nodaemon=true
|
||||
|
||||
[program:api_server]
|
||||
command=python api_server.py
|
||||
|
||||
[program:history_viewer]
|
||||
command=python history_viewer.py
|
||||
EOF
|
||||
|
||||
else
|
||||
cat > "$TEMP_BUILD_DIR/Dockerfile" << 'EOF'
|
||||
FROM python:3.11-alpine
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
EXPOSE 5050
|
||||
CMD ["echo", "Single service architecture"]
|
||||
EOF
|
||||
fi
|
||||
|
||||
echo "[步骤 3/3] 复制文件到最终目录..."
|
||||
|
||||
# 复制构建文件到最终目录
|
||||
cp -r "$TEMP_BUILD_DIR"/* "$EXPORT_DIR/"
|
||||
|
||||
# 创建README
|
||||
cat > "$EXPORT_DIR/README.md" << EOF
|
||||
# DMS合规性测试工具 - 测试部署包
|
||||
|
||||
## 配置信息
|
||||
|
||||
- **架构**: $(get_service_arch_name "$SELECTED_SERVICE_ARCH")
|
||||
- **端口**: $SELECTED_PORTS
|
||||
- **目标平台**: $TARGET_PLATFORM_NAME
|
||||
- **构建时间**: $(date '+%Y-%m-%d %H:%M:%S')
|
||||
|
||||
## 测试成功
|
||||
|
||||
这是一个测试部署包,验证了脚本的基本功能。
|
||||
EOF
|
||||
|
||||
# 创建压缩包
|
||||
echo "[信息] 创建压缩包..."
|
||||
tar -czf "$ARCHIVE_NAME" "$EXPORT_DIR"
|
||||
|
||||
# 显示结果
|
||||
echo ""
|
||||
echo "=== 测试完成 ==="
|
||||
echo "[成功] 测试部署包已创建: $ARCHIVE_NAME"
|
||||
echo "[信息] 架构: $(get_service_arch_name "$SELECTED_SERVICE_ARCH")"
|
||||
echo "[信息] 端口: $SELECTED_PORTS"
|
||||
echo "[信息] 平台: $TARGET_PLATFORM_NAME"
|
||||
echo "[信息] 文件大小: $(du -h "$ARCHIVE_NAME" | cut -f1)"
|
||||
echo ""
|
||||
echo "测试成功!脚本功能正常。"
|
||||
241
test_orchestrator_fix.py
Normal file
241
test_orchestrator_fix.py
Normal file
@ -0,0 +1,241 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
测试orchestrator修复的脚本
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import logging
|
||||
|
||||
# 添加项目根目录到Python路径
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
def test_orchestrator_fix():
|
||||
"""测试orchestrator修复"""
|
||||
|
||||
# 设置日志
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
logger.info("开始测试orchestrator修复...")
|
||||
|
||||
try:
|
||||
# 导入必要的模块
|
||||
from ddms_compliance_suite.test_orchestrator import APITestOrchestrator
|
||||
from ddms_compliance_suite.input_parser.parser import ParsedDMSSpec, DMSEndpoint
|
||||
from custom_stages.dms_crud_scenario_stage import DmsCrudScenarioStage
|
||||
|
||||
# 创建一个简单的API规范
|
||||
simple_api_spec = {
|
||||
"dms_api_list": [
|
||||
{
|
||||
"method": "POST",
|
||||
"path": "/api/dms/well_kd_wellbore_ideas01/v1/dr_ach_survey_inc",
|
||||
"title": "Create dr_ach_survey_inc",
|
||||
"summary": "Create a new dr_ach_survey_inc record",
|
||||
"description": "Create a new dr_ach_survey_inc record",
|
||||
"operationId": "create_dr_ach_survey_inc",
|
||||
"tags": ["dr_ach_survey_inc"],
|
||||
"parameters": [],
|
||||
"requestBody": {
|
||||
"required": True,
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"version": {"type": "string", "example": "1.0.0"},
|
||||
"act": {"type": "integer", "example": -1},
|
||||
"data": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"dsid": {"type": "string", "title": "数据ID"},
|
||||
"wellId": {"type": "string", "title": "井标识符"},
|
||||
"wellboreId": {"type": "string", "title": "井筒唯一标识符"},
|
||||
"wellCommonName": {"type": "string", "title": "井名"},
|
||||
"dataRegion": {"type": "string", "title": "数据标识"},
|
||||
"description": {"type": "string", "title": "测斜描述"},
|
||||
"bsflag": {"type": "number", "title": "逻辑删除标识"}
|
||||
},
|
||||
"required": ["dsid", "dataRegion", "bsflag"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Success",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {"type": "integer"},
|
||||
"message": {"type": "string"},
|
||||
"data": {"type": "object"}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"_test_mode": "scenario_only",
|
||||
"_dms_model_pk_name": "dsid"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
# 创建DMSEndpoint
|
||||
endpoint = DMSEndpoint(
|
||||
method="POST",
|
||||
path="/api/dms/well_kd_wellbore_ideas01/v1/dr_ach_survey_inc",
|
||||
title="Create dr_ach_survey_inc",
|
||||
request_body=simple_api_spec["dms_api_list"][0]["requestBody"],
|
||||
responses=simple_api_spec["dms_api_list"][0]["responses"],
|
||||
parameters=[],
|
||||
test_mode="scenario_only",
|
||||
model_pk_name="dsid"
|
||||
)
|
||||
|
||||
# 创建ParsedDMSSpec
|
||||
parsed_spec = ParsedDMSSpec(endpoints=[endpoint], spec=simple_api_spec)
|
||||
|
||||
# 创建测试编排器
|
||||
orchestrator = APITestOrchestrator(
|
||||
base_url="https://www.dev.ideas.cnpc",
|
||||
enable_well_data=True
|
||||
)
|
||||
|
||||
logger.info(f"测试编排器创建成功")
|
||||
logger.info(f"orchestrator.well_data_manager: {getattr(orchestrator, 'well_data_manager', 'NOT_FOUND')}")
|
||||
logger.info(f"type(orchestrator.well_data_manager): {type(getattr(orchestrator, 'well_data_manager', None))}")
|
||||
|
||||
# 初始化井数据
|
||||
if orchestrator.well_data_manager:
|
||||
logger.info("开始初始化井数据...")
|
||||
well_data_success = orchestrator.initialize_well_data()
|
||||
if well_data_success:
|
||||
logger.info("井数据初始化成功")
|
||||
else:
|
||||
logger.warning("井数据初始化失败")
|
||||
else:
|
||||
logger.warning("井数据管理器不可用")
|
||||
|
||||
# 手动创建CRUD场景并传递orchestrator
|
||||
crud_stage = DmsCrudScenarioStage(
|
||||
api_group_metadata={"name": "test_group", "description": "测试分组"},
|
||||
apis_in_group=[endpoint],
|
||||
global_api_spec=parsed_spec,
|
||||
llm_service=orchestrator.llm_service,
|
||||
stage_llm_config=orchestrator.stage_llm_config,
|
||||
orchestrator=orchestrator # 🔑 关键:传递orchestrator
|
||||
)
|
||||
|
||||
logger.info(f"CRUD场景创建成功")
|
||||
logger.info(f"crud_stage.orchestrator: {crud_stage.orchestrator}")
|
||||
logger.info(f"hasattr(crud_stage, 'orchestrator'): {hasattr(crud_stage, 'orchestrator')}")
|
||||
|
||||
if hasattr(crud_stage, 'orchestrator'):
|
||||
logger.info(f"hasattr(crud_stage.orchestrator, 'well_data_manager'): {hasattr(crud_stage.orchestrator, 'well_data_manager')}")
|
||||
if hasattr(crud_stage.orchestrator, 'well_data_manager'):
|
||||
logger.info(f"crud_stage.orchestrator.well_data_manager: {crud_stage.orchestrator.well_data_manager}")
|
||||
logger.info(f"type(crud_stage.orchestrator.well_data_manager): {type(crud_stage.orchestrator.well_data_manager)}")
|
||||
logger.info(f"bool(crud_stage.orchestrator.well_data_manager): {bool(crud_stage.orchestrator.well_data_manager)}")
|
||||
|
||||
# 测试条件判断
|
||||
condition_result = (hasattr(crud_stage, 'orchestrator') and
|
||||
hasattr(crud_stage.orchestrator, 'well_data_manager') and
|
||||
crud_stage.orchestrator.well_data_manager)
|
||||
|
||||
logger.info(f"完整条件判断结果: {condition_result}")
|
||||
|
||||
if condition_result:
|
||||
logger.info("✅ 条件判断通过,井数据管理器可用")
|
||||
|
||||
# 测试井数据增强
|
||||
test_data = {
|
||||
'dsid': 'test-123',
|
||||
'wellId': 'WELL001',
|
||||
'wellboreId': 'WB001',
|
||||
'wellCommonName': '大庆1井',
|
||||
'dataRegion': '大庆油田',
|
||||
'description': '测试数据',
|
||||
'bsflag': 1
|
||||
}
|
||||
|
||||
logger.info(f"原始测试数据: {test_data}")
|
||||
enhanced_data = crud_stage.orchestrator.well_data_manager.enhance_data_with_well_values(test_data)
|
||||
logger.info(f"增强后数据: {enhanced_data}")
|
||||
|
||||
# 验证增强效果
|
||||
expected_changes = {
|
||||
'wellId': ['HB00019975', 'WELLHB100293168', 'WELLHB100295876', 'WELLHB100294095', 'WELLHB100293950'],
|
||||
'wellboreId': ['WEBHHB100083169', 'WEBHHB100085743', 'WEBHHB100083191', 'WEBHHB100082983', 'WEBHHB100083194'],
|
||||
'wellCommonName': ['郑4-106', '沁362', '新蔡39-169', '郑4-2', '郑4-3']
|
||||
}
|
||||
|
||||
all_correct = True
|
||||
for field, expected_values in expected_changes.items():
|
||||
actual_value = enhanced_data.get(field)
|
||||
if actual_value in expected_values:
|
||||
logger.info(f"✅ {field} 正确增强为真实值: {actual_value}")
|
||||
else:
|
||||
logger.error(f"❌ {field} 增强失败,期望值之一: {expected_values}, 实际: {actual_value}")
|
||||
all_correct = False
|
||||
|
||||
if all_correct:
|
||||
logger.info("🎉 井数据增强功能正常工作")
|
||||
return True
|
||||
else:
|
||||
logger.error("❌ 井数据增强功能有问题")
|
||||
return False
|
||||
|
||||
else:
|
||||
logger.warning("❌ 条件判断失败,井数据管理器不可用")
|
||||
|
||||
# 检查井数据管理器初始化
|
||||
logger.info("尝试手动初始化井数据管理器...")
|
||||
try:
|
||||
orchestrator._initialize_well_data_manager()
|
||||
logger.info(f"手动初始化后 - orchestrator.well_data_manager: {orchestrator.well_data_manager}")
|
||||
logger.info(f"手动初始化后 - type: {type(orchestrator.well_data_manager)}")
|
||||
logger.info(f"手动初始化后 - bool: {bool(orchestrator.well_data_manager)}")
|
||||
|
||||
# 重新测试条件判断
|
||||
condition_result_after_init = (hasattr(crud_stage, 'orchestrator') and
|
||||
hasattr(crud_stage.orchestrator, 'well_data_manager') and
|
||||
crud_stage.orchestrator.well_data_manager)
|
||||
|
||||
logger.info(f"初始化后的条件判断结果: {condition_result_after_init}")
|
||||
|
||||
if condition_result_after_init:
|
||||
logger.info("✅ 手动初始化后条件判断通过")
|
||||
return True
|
||||
else:
|
||||
logger.error("❌ 手动初始化后条件判断仍然失败")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"手动初始化井数据管理器失败: {e}")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"测试失败: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
success = test_orchestrator_fix()
|
||||
sys.exit(0 if success else 1)
|
||||
except Exception as e:
|
||||
print(f"❌ 测试失败: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
Loading…
x
Reference in New Issue
Block a user