Skip to content

Commit

Permalink
fix(backend): mango整机替换测试冲突 #3711
Browse files Browse the repository at this point in the history
  • Loading branch information
ygcyao authored and zhangzhw8 committed Mar 27, 2024
1 parent 7d2a97b commit dc8e472
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
72 changes: 72 additions & 0 deletions dbm-ui/backend/tests/mock_data/ticket/mongodb_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,78 @@
]
}

# mango 整机替换请求单据
MANGODB_CUTOFF_TICKET_DATA = {
"bk_biz_id": BK_BIZ_ID,
"ticket_type": "MONGODB_CUTOFF",
"details": {
"ip_source": "resource_pool",
"infos": [
{
"cluster_id": CLUSTER_ID,
"mongos": [{"ip": "1.1.1.3", "spec_id": 3, "bk_cloud_id": 0}],
"mongodb": [{"ip": "1.1.1.4", "spec_id": 3, "bk_cloud_id": 0}],
"mongo_config": [{"ip": "1.1.1.5", "spec_id": 3, "bk_cloud_id": 0}],
}
],
},
}

# mango 整机替换资源申请数据
MANGODB_SOURCE_APPLICATION_DATA = {
"0_mongodb_1.1.1.4": [
{
"bk_biz_id": BK_BIZ_ID,
"ip": "2.2.2.1",
"bk_cloud_id": 0,
"bk_host_id": 3,
"bk_cpu": 2,
"bk_disk": 147,
"bk_mem": 3663,
"storage_device": {"/data": {"size": 50, "disk_id": "disk-01", "disk_type": "HDD", "file_type": "ext4"}},
"city": "",
"sub_zone": "",
"sub_zone_id": "",
"rack_id": "",
"device_class": "",
}
],
"0_mongos_1.1.1.3": [
{
"bk_biz_id": BK_BIZ_ID,
"ip": "2.2.2.3",
"bk_cloud_id": 0,
"bk_host_id": 3,
"bk_cpu": 2,
"bk_disk": 147,
"bk_mem": 3663,
"storage_device": {"/data": {"size": 50, "disk_id": "disk-01", "disk_type": "HDD", "file_type": "ext4"}},
"city": "",
"sub_zone": "",
"sub_zone_id": "",
"rack_id": "",
"device_class": "",
}
],
"0_mongo_config_1.1.1.5": [
{
"bk_biz_id": BK_BIZ_ID,
"ip": "2.2.2.5",
"bk_cloud_id": 0,
"bk_host_id": 3,
"bk_cpu": 2,
"bk_disk": 147,
"bk_mem": 3663,
"storage_device": {"/data": {"size": 50, "disk_id": "disk-01", "disk_type": "HDD", "file_type": "ext4"}},
"city": "",
"sub_zone": "",
"sub_zone_id": "",
"rack_id": "",
"device_class": "",
}
],
}

# 初始化mongodb集群
MANGODB_CLUSTER_DATA = {
"id": CLUSTER_ID,
Expand Down
41 changes: 41 additions & 0 deletions dbm-ui/backend/tests/ticket/test_mangodb_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
APPCACHE_DATA,
MANGODB_ADD_MANGOS_TICKET_DATA,
MANGODB_CLUSTER_DATA,
MANGODB_CUTOFF_TICKET_DATA,
MANGODB_DESTROY_TICKET_DATA,
MANGODB_MACHINE_DATA,
MANGODB_PROXYINSTANCE_DATA,
MANGODB_REDUCE_MANGOS_DATA,
MANGODB_SOURCE_APPLICATION_DATA,
MANGODB_SPEC_DATA,
MANGOS_ADD_SOURCE_DATA,
)
Expand Down Expand Up @@ -190,3 +192,42 @@ def test_mangodb_destroy_flow(
client.post(f"/apis/tickets/{current_flow.ticket_id}/callback/")
current_flow = Flow.objects.exclude(flow_obj_id="").last()
assert current_flow.flow_type == FlowType.INNER_FLOW

@patch.object(TicketViewSet, "permission_classes")
@patch.object(InnerFlow, "_run")
@patch.object(InnerFlow, "status", new_callable=PropertyMock)
@patch.object(PauseFlow, "status", new_callable=PropertyMock)
@patch.object(TicketViewSet, "get_permissions", lambda x: [])
@patch("backend.ticket.flow_manager.itsm.ItsmApi", ItsmApiMock())
@patch("backend.db_services.cmdb.biz.CCApi", CCApiMock())
@patch("backend.components.cmsi.handler.CmsiHandler.send_msg", lambda msg: "有一条MANGO 整机替换待办需要您处理")
@patch(
"backend.ticket.flow_manager.resource.ResourceApplyFlow.apply_resource",
lambda resource_request_id, node_infos: (1, MANGODB_SOURCE_APPLICATION_DATA),
)
@patch("backend.db_services.cmdb.biz.Permission", PermissionMock)
def test_mango_outoff_flow(
self, mock_pause_status, mocked_status, mocked__run, mocked_permission_classes, query_fixture, db
):
# MANGODB 整机替换: start --> itsm --> PAUSE --> RESOURC --> INNER_FLOW --> end
mocked_status.return_value = TicketStatus.SUCCEEDED
mock_pause_status.return_value = TicketFlowStatus.SKIPPED
mocked__run.return_value = ROOT_ID
mocked_permission_classes.return_value = [AllowAny]

client.login(username="admin")

# itsm流程
mangos_add_data = copy.deepcopy(MANGODB_CUTOFF_TICKET_DATA)
client.post("/apis/tickets/", data=mangos_add_data)
current_flow = Flow.objects.filter(flow_obj_id=SN).first()
assert current_flow is not None

# PAUSE流程
client.post(f"/apis/tickets/{current_flow.ticket_id}/callback/")
current_flow = Flow.objects.exclude(flow_obj_id="").last()
assert current_flow.flow_type == FlowType.PAUSE
# RESOURCE_APPLY -> INNER_FLOW
client.post(f"/apis/tickets/{current_flow.ticket_id}/callback/")
current_flow = Flow.objects.exclude(flow_obj_id="").last()
assert current_flow.flow_type == FlowType.INNER_FLOW

0 comments on commit dc8e472

Please sign in to comment.