目录
XOA是什么
XOA(Xena Open-Source Automation)是一个开源的测试自动化框架,追求“高效、易用、灵活”的跨操作系统的开发框架。能与Xena现有解决方案无缝配合,借助XOA可调用Xena(Z系列打流仪、E系列损伤仪)完成自动化测试任务。同时它提供了操作接口可将其他仪表/设备做并栈集成测试验证,统一整理输出测试报告。
XOA包含:
XOA CLI、XOA Python API、XOA Python TestSuite、XOA Converter
XOA CLI
XOA CLI 提供了一套简洁直观的基于文本语言的独立命令,用以控制和集成 Xena测试仪硬件,实现各种测试任务的自动化。
任何客户端平台/编程语言(如 Python、Tcl、Bash)都可与 XOA CLI 配合使用。
CLI 可在远程登录终端上使用,直接向 Xena 测试仪发送命令。
ValkyrieManager通过测试端口配置文件(.xpc ),可在 XOA CLI 环境之间无缝转换。
XOA Python API
XOA Python API与XOA CLI和XenaManager无缝集成
- 面向对象的高级抽象: XOA Python API采用面向对象的方法,提供了更高层次的抽象,加快了自动化脚本的开发。
- 集成开发环境自动完成,内置手册: XOA Python API 包含 IDE 自动完成以及类、函数和 API 内置手册等功能,可显著提高开发效率。
- 命令分组和响应自动匹配:该功能允许命令分组和响应自动匹配,从而优化了测试执行效率。
- 服务器到客户端推送通知订阅: XOA Python API 支持服务器到客户端的推送通知订阅,降低了用户代码的复杂性。
- 支持 Python 3.8 及更高版本: XOA Python API 兼容 Python 3.8 及更高版本,确保与现代 Python 环境兼容。
import asyncio from contextlib import suppress from xoa_driver import testers from xoa_driver import modules from xoa_driver import ports from xoa_driver import utils from xoa_driver import enums from xoa_driver import exceptions from ipaddress import IPv4Address, IPv6Address from binascii import hexlify from xoa_driver.misc import Hex #--------------------------- # Global parameters #--------------------------- CHASSIS_IP = "10.165.16.70" # Chassis IP address or hostname USERNAME = "XOA" # Username MODULE_INDEX = 4 # Module index TX_PORT_INDEX = 0 # TX Port index FRAME_SIZE_BYTES = 4178 # Frame size on wire including the FCS. FRAME_COUNT = 20 # The number of frames including the first, the middle, and the last. REPETITION = 1 # The number of repetitions of the frame sequence, set to 0 if you want the port to repeat over and over TRAFFIC_RATE_FPS = 100 # Traffic rate in frames per second TRAFFIC_RATE_PERCENT = int(4/10 * 1000000) SHOULD_BURST = False # Whether the middle frames should be bursty BURST_SIZE_FRAMES = 9 # Burst size in frames for the middle frames INTER_BURST_GAP_BYTES = 3000 # The inter-burst gap in bytes INTRA_BURST_GAP_BYTES = 1000 # The inter-frame gap within a burst, aka. intra-burst gap, in bytes #--------------------------- # Header content for streams #--------------------------- class Ethernet: def __init__(self): self.dst_mac = "0000.0000.0000" self.src_mac = "0000.0000.0000" self.ethertype = "86DD" def __str__(self): _dst_mac = self.dst_mac.replace(".", "") _src_mac = self.src_mac.replace(".", "") _ethertype = self.ethertype return f"{_dst_mac}{_src_mac}{_ethertype}".upper() class IPV4: def __init__(self): self.version = 4 self.header_length = 5 self.dscp = 0 self.ecn = 0 self.total_length = 42 self.identification = "0000" self.flags = 0 self.offset = 0 self.ttl = 255 self.proto = 255 self.checksum &