测试
验收测试
登录后可跨设备保存划线和私人笔记登录
验收测试从最终用户的角度验证完整的 Ozone 系统。它们在一个与真实部署非常相似的容器化环境中部署并测试 Ozone。
范围与目的
验收测试是 Ozone 测试策略中的最终验证层:
- 单元测试:独立测试各个类
- 集成测试:使用内存集群测试组件间的交互
- 验收测试:测试以容器方式部署的整个系统
验收测试非常适合用于:
- 端到端工作流
- API 合规性(尤其是 S3)
- 安全配置
- 各种条件下的系统行为
- 外部接口与集成
测试框架
Ozone 使用 Robot Framework 进行验收测试。Robot Framework 是一个通用的测试自动化框架,采用关键字驱动的测试方式。
在安装 Robot Framework 之后,你可以在任何环境中运行验收测试。
主要特性
- 人类可读的测试语法
- 丰富的测试库
- 按功能组织测试用例
- 详细的测试报告
- 能够创建自定义关键字
目录结构
验收测试位于 hadoop-ozone/dist/src/main/smoketest/ 目录中。
smoketest/
├── basic/ # Basic functionality tests
├── s3/ # S3 gateway tests
├── security/ # Security and authentication tests
├── recon/ # Recon service tests
├── ozone-lib/ # Shared libraries and utilities
├── commonlib.robot # Common test keywords
└── compose/ # Docker Compose test environment
├── ozone/ # Ozone-specific test configurations
├── security/ # Secure test configurations
└── ha/ # HA test configurations测试结构
Robot Framework 测试编写在 test_name.robot 文件中,并采用结构化的格式:
*** Settings ***
Documentation Test Ozone volume operations
Library OperatingSystems
Resource ../ozone-lib/shell.robot
*** Variables ***
${volume} vol1
*** Test Cases ***
Create Volume
Execute ozone sh volume create /${volume}
Execute ozone sh volume list
Should contain ${OUTPUT} ${volume}
Delete Volume
Execute ozone sh volume delete /${volume}
Execute ozone sh volume list
Should not contain ${OUTPUT} ${volume}使用 Docker Compose 在本地运行测试
# Go to the compose directory
cd hadoop-ozone/dist/src/main/compose/
# Run all tests
./test-all.sh
# Run single test
docker-compose up -d
# wait....
./test-single.sh scm basic/basic.robot专用测试环境
Ozone 提供了多个预配置的测试环境:
标准环境
具有最简服务的基础 Ozone 集群。
安全环境(Kerberos)
启用了 Kerberos 安全机制的 Ozone 集群。
高可用(HA)环境
包含多个 OM 和 SCM 的 Ozone 集群,用于高可用测试。
S3
运行 S3 相关测试需要以下设置:
- 创建一个存储桶
- 配置本地的
aws cli - 在执行 robot 测试时设置存储桶/端点 URL
robot -v bucket:ozonetest -v OZONE_TEST:false -v OZONE_S3_SET_CREDENTIALS:false -v ENDPOINT_URL:https://s3.us-east-2.amazonaws.com smoketest/s3测试报告
运行测试后,Robot Framework 会生成详细的 HTML 报告:
report.html:所有测试用例的汇总报告log.html:测试执行的详细日志output.xml:XML 格式的输出,可交由其他工具处理
这些报告通常位于 robot-results/ 目录中。
最佳实践
- 使用现有关键字:充分利用
commonlib.robot及其他库中已有的关键字 - 创建可重用的关键字:为复杂操作定义新的关键字
- 清晰的测试描述:每个测试用例都应有明确的目的
- 独立的测试:测试之间不应相互依赖
- 恰当的清理操作:始终在 teardown 部分清理资源
- 有意义的断言:使用恰当的断言来验证正确的条件
评论
登录后参与评论
正在加载评论…
KnowForge