From dc8e472a37729e40fa4865ad67e5ff6b85914399 Mon Sep 17 00:00:00 2001 From: ygcyao Date: Tue, 26 Mar 2024 18:32:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(backend):=20mango=E6=95=B4=E6=9C=BA?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=B5=8B=E8=AF=95=E5=86=B2=E7=AA=81=20#3711?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/mock_data/ticket/mongodb_flow.py | 72 +++++++++++++++++++ .../backend/tests/ticket/test_mangodb_flow.py | 41 +++++++++++ 2 files changed, 113 insertions(+) diff --git a/dbm-ui/backend/tests/mock_data/ticket/mongodb_flow.py b/dbm-ui/backend/tests/mock_data/ticket/mongodb_flow.py index 875041270d..182398189d 100644 --- a/dbm-ui/backend/tests/mock_data/ticket/mongodb_flow.py +++ b/dbm-ui/backend/tests/mock_data/ticket/mongodb_flow.py @@ -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, diff --git a/dbm-ui/backend/tests/ticket/test_mangodb_flow.py b/dbm-ui/backend/tests/ticket/test_mangodb_flow.py index 99e6c8d094..9874f15f49 100644 --- a/dbm-ui/backend/tests/ticket/test_mangodb_flow.py +++ b/dbm-ui/backend/tests/ticket/test_mangodb_flow.py @@ -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, ) @@ -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