# 故障单 API 测试 本指南以通用的 [API 测试](https://docs.equinix.com/zh-Hans/equinix-api/testing.md) 原则为基础,为 Equinix 故障单 API 提供具体的测试方法和示例。 ## 故障单 API 概述[​](#故障单-api-概述 "直接链接至故障单 API 概述") 故障单 API 允许客户以编程方式与 Equinix 支持团队进行交互,为各种类别的服务影响问题创建支持工单: * 交叉连接问题 * 网络连接问题 * 电力相关事件 * 环境问题 * 硬件故障 * 安全事件 * 托管服务支持 ## 故障单问题类型[​](#故障单问题类型 "直接链接至故障单问题类型") 故障单 API 支持多种问题类别,每种类别都有特定的问题代码: | Problem Category | Description | Example Codes | | ---------------- | ----------------------------------- | -------------------------- | | Cross Connect | Physical cable connection issues | cc01, cc02, cc03 | | Network | Network connectivity problems | net01, net02 | | Environment | HVAC, cooling, environmental issues | env01, env02, env03, env04 | | Hardware | Equipment and hardware failures | hdw01 | | Power | Power-related incidents | pwr01, pwr02 | | Security | Security access and badge issues | sec01, sec02 | | Managed Services | Managed service support requests | ms01-ms13 | | SmartView | SmartView monitoring issues | sv01-sv05 | ## 故障单测试工作流程[​](#故障单测试工作流程 "直接链接至故障单测试工作流程") 在测试故障单 API 之前,请确保您已具备以下条件: * 具有故障单权限的 Equinix 开发人员帐户 * 有效的 API 凭证(客户端 ID 和客户端密钥) * 获取合适的IBX地点和笼子 * 了解[API身份验证](https://docs.equinix.com/zh-Hans/equinix-api/api-authentication.md) 创建故障单 ``` import requests import json from datetime import datetime, timedelta # Setup authentication auth_url = "https://api.equinix.com/oauth2/v1/token" auth_payload = { "grant_type": "client_credentials", "client_id": "YOUR_CLIENT_ID", "client_secret": "YOUR_CLIENT_SECRET" } auth_response = requests.post(auth_url, data=auth_payload) token = auth_response.json()["access_token"] # Test creating a trouble ticket order base_url = "https://api.equinix.com" headers = { "Authorization": f"Bearer {token}", "Content-Type": "application/json" } # Example: Create a network connectivity trouble ticket request_payload = { "customerReferenceNumber": "TT-TEST-001", "ibxLocation": { "ibx": "CH1", "cages": [ { "cage": "CH1:05:000750", "accountNumber": "12345", "cabinets": [ "CH1:05:000750:01" ] } ] }, "serviceDetails": { "incidentDateTime": (datetime.utcnow() - timedelta(hours=1)).isoformat() + "Z", "problemCode": "net01", # Network connectivity issue "additionalDetails": "TEST: Network connectivity issue - API testing" }, "contacts": [ { "contactType": "ORDERING", "userName": "test_ordering_user" }, { "contactType": "NOTIFICATION", "userName": "test_notification_user" }, { "contactType": "TECHNICAL", "userName": "test_technical_user", "workPhone": "555-0123", "workPhonePrefToCall": "ANYTIME" } ] } create_response = requests.post( f"{base_url}/v1/orders/troubleticket", headers=headers, data=json.dumps(request_payload) ) # Verify response assert create_response.status_code == 201, f"Failed to create trouble ticket: {create_response.text}" order_number = create_response.json()["OrderNumber"] print(f"Successfully created trouble ticket order: {order_number}") ``` **测试地点和问题类型验证** ``` # Test retrieving available locations locations_response = requests.get( f"{base_url}/v1/orders/troubleticket/locations", headers=headers ) assert locations_response.status_code == 200, f"Failed to retrieve locations: {locations_response.text}" locations = locations_response.json()["locations"] print(f"Available locations: {len(locations)}") # Test retrieving problem types types_response = requests.get( f"{base_url}/v1/orders/troubleticket/types", headers=headers ) assert types_response.status_code == 200, f"Failed to retrieve problem types: {types_response.text}" problem_types = types_response.json()["troubleTicketTypes"] print(f"Available problem types: {len(problem_types)}") ``` ## 测试错误场景[​](#测试错误场景 "直接链接至测试错误场景") 务必对 API 实现中的错误处理进行测试: ``` import requests import json from datetime import datetime, timedelta # Setup authentication auth_url = "https://api.equinix.com/oauth2/v1/token" auth_payload = { "grant_type": "client_credentials", "client_id": "YOUR_CLIENT_ID", "client_secret": "YOUR_CLIENT_SECRET" } auth_response = requests.post(auth_url, data=auth_payload) token = auth_response.json()["access_token"] # Prepare request base_url = "https://api.equinix.com" headers = { "Authorization": f"Bearer {token}", "Content-Type": "application/json" } # Test with invalid problem code invalid_payload = { "customerReferenceNumber": "TT-ERROR-TEST-001", "ibxLocation": { "ibx": "CH1", "cages": [{"cage": "CH1:05:000750", "accountNumber": "12345"}] }, "serviceDetails": { "incidentDateTime": (datetime.utcnow() - timedelta(hours=1)).isoformat() + "Z", "problemCode": "INVALID_CODE", # Invalid problem code "additionalDetails": "TEST: Invalid problem code test" }, "contacts": [ {"contactType": "ORDERING", "userName": "test_user"}, {"contactType": "NOTIFICATION", "userName": "test_user"} ] } error_response = requests.post( f"{base_url}/v1/orders/troubleticket", headers=headers, data=json.dumps(invalid_payload) ) # Verify error response assert error_response.status_code == 400, f"Expected error but got: {error_response.status_code}" error_data = error_response.json() assert "errors" in error_data, "Error response format not as expected" print("Successfully validated error handling for invalid problem code") print(json.dumps(error_data, indent=2)) ``` ## 故障单 API 测试最佳实践[​](#故障单-api-测试最佳实践 "直接链接至故障单 API 测试最佳实践") 重要提示: Equinix 故障单 API 是一个生产系统,会创建真实的支持工单。请务必遵循以下测试最佳实践,以确保不会产生意外的运维工作。 1. **设置专用测试账号**:如果可以,请申请一个单独的测试账号。 2. **请使用清晰标记的测试请求**:始终在描述前加上“测试:”前缀,以便支持人员识别测试请求。 3. **请使用有效的事件发生时间**:确保事件日期/时间格式正确,且不包含未来时间。 4. **验证位置访问权限**:在创建工单之前,请使用位置端点验证 IBX 位置是否可访问。 5. **使用有效的错误代码进行测试**:始终使用类型端点验证错误代码。 6. **请提供完整的联系信息**:确保提供所有必要的联系方式(订购、通知)。 7. **清理测试资源**:与技术支持人员合作,在创建后立即关闭所有测试工单。 8. **测试错误处理**:验证错误处理和响应代码是否正确 ## 自动化考量[​](#自动化考量 "直接链接至自动化考量") 在围绕故障单 API 构建自动化流程时: * 实现适当的错误处理和API故障重试机制 * 构建必填字段和数据格式的验证 * 包括所有工单创建活动的审计日志记录 * 确保准确记录并格式化事件发生时间。 * 提交前请验证位置和问题代码信息。 * 考虑实施生产工单创建审批工作流程 * 请提供完整的联系信息,以便更快解决问题。 ## 其他资源[​](#其他资源 "直接链接至其他资源") * [Trouble Ticket API OpenAPI Specification](https://docs.equinix.com/zh-Hans/api-catalog/troubleticketv1.md) * [General API Testing Guidelines](https://docs.equinix.com/zh-Hans/equinix-api/testing.md) * [API Authentication Guide](https://docs.equinix.com/zh-Hans/equinix-api/api-authentication.md)