diff --git a/dbm-ui/backend/tests/mock_data/components/drs.py b/dbm-ui/backend/tests/mock_data/components/drs.py index 40b9300539..e2a758b722 100644 --- a/dbm-ui/backend/tests/mock_data/components/drs.py +++ b/dbm-ui/backend/tests/mock_data/components/drs.py @@ -15,6 +15,32 @@ class DRSApiMock(object): Drs 相关接口的mock """ + @classmethod + def rpc(cls, *args, **kwargs): + source_data = [ + { + "address": "5.5.5.5:20001", + "cmd_results": [ + {"cmd": "", "table_data": [{"Database": "source_test_db1"}], "rows_affected": 0, "error_msg": ""} + ], + "error_msg": "", + }, + { + "address": "5.5.5.4:20001", + "cmd_results": [ + {"cmd": "", "table_data": [{"Database": "test_db1"}], "rows_affected": 0, "error_msg": ""} + ], + "error_msg": "", + }, + ] + response_data = [] + + for address in args[0]["addresses"]: + for data in source_data: + if address == data.get("address"): + response_data.append(data) + return response_data + @classmethod def sqlserver_rpc(cls, *args, **kwargs): response_data = [ diff --git a/dbm-ui/backend/tests/mock_data/ticket/es_flow.py b/dbm-ui/backend/tests/mock_data/ticket/es_flow.py new file mode 100644 index 0000000000..2bb3006bf9 --- /dev/null +++ b/dbm-ui/backend/tests/mock_data/ticket/es_flow.py @@ -0,0 +1,270 @@ +# -*- coding: utf-8 -*- +""" +TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. +Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. +Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. +You may obtain a copy of the License at https://opensource.org/licenses/MIT +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. +""" + + +from backend.db_meta.enums.cluster_type import ClusterType +from backend.tests.mock_data import constant + +BK_USERNAME = "admin" +BK_BIZ_ID = constant.BK_BIZ_ID +CLUSTER_ID = 91 + + +# es 部署集群 +ES_APPLY_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "bk_cloud_id": 0, + "city_code": "default", + "cluster_alias": "", + "cluster_name": "testes", + "db_app_abbr": "1", + "db_version": "7.2.0", + "disaster_tolerance_level": "MAX_EACH_ZONE_EQUAL", + "http_port": 9200, + "ip_source": "resource_pool", + "resource_spec": { + "master": { + "count": 3, + "spec_id": 391, + "cpu": {"max": 256, "min": 1}, + "mem": {"max": 256, "min": 1}, + "qps": {}, + "spec_name": "1核_1G_10G", + "storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data", "_X_ROW_KEY": "row_72"}], + "affinity": "MAX_EACH_ZONE_EQUAL", + "location_spec": {"city": "default"}, + }, + "hot": { + "count": 1, + "spec_id": 393, + "cpu": {"max": 256, "min": 1}, + "instance_num": 1, + "mem": {"max": 256, "min": 1}, + "qps": {}, + "spec_name": "1核_1G_10G", + "storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data", "_X_ROW_KEY": "row_117"}], + "affinity": "MAX_EACH_ZONE_EQUAL", + "location_spec": {"city": "default"}, + }, + }, + "city_name": "无限制", + }, + "remark": "", + "ticket_type": "ES_APPLY", +} + +# es 集群扩容 +ES_SCALE_UP_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "cluster_id": CLUSTER_ID, + "ext_info": { + "client": {"expansion_disk": 0, "total_disk": 0, "total_hosts": 0}, + "cold": {"expansion_disk": 10, "total_disk": None, "total_hosts": 1}, + "hot": {"expansion_disk": 0, "total_disk": None, "total_hosts": 1}, + }, + "ip_source": "resource_pool", + "resource_spec": {"cold": {"count": 1, "instance_num": 1, "spec_id": 393}}, + }, + "ticket_type": "ES_SCALE_UP", +} + +# es 集群缩容 +ES_SHRINK_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "cluster_id": CLUSTER_ID, + "ext_info": { + "client": {"shrink_disk": 0, "total_disk": 0, "total_hosts": 0}, + "cold": {"shrink_disk": 0, "total_disk": 0, "total_hosts": 1}, + "hot": {"shrink_disk": 0, "total_disk": 0, "total_hosts": 1}, + }, + "ip_source": "resource_pool", + "old_nodes": {"client": [], "cold": [{"bk_cloud_id": 0, "bk_host_id": 56, "ip": "1.1.1.2"}], "hot": []}, + }, + "ticket_type": "ES_SHRINK", +} + +# es 集群禁用 +ES_DISABLE_DATA = {"bk_biz_id": BK_BIZ_ID, "details": {"cluster_id": CLUSTER_ID}, "ticket_type": "ES_DISABLE"} + +ES_MACHINE_DATA = [ + { + "creator": BK_USERNAME, + "create_at": "2023-03-13 11:14:48.433116", + "updater": "", + "update_at": "2023-03-13 11:14:48.433116", + "ip": "1.1.3.4", + "bk_biz_id": BK_BIZ_ID, + "db_module_id": 0, + "access_layer": "storage", + "machine_type": "es_datanode", + "cluster_type": ClusterType.Es, + "bk_host_id": 55, + "bk_os_name": "linux centos", + "bk_idc_area": "", + "bk_idc_area_id": 0, + "bk_sub_zone": "", + "bk_sub_zone_id": 0, + "bk_rack": "", + "bk_rack_id": 0, + "bk_svr_device_cls_name": "", + "bk_idc_name": "", + "bk_idc_id": 0, + "bk_cloud_id": 0, + "net_device_id": "", + "bk_city_id": 0, + "spec_config": '{"id": 393, "cpu": {"max": 256, "min": 1}, "mem": {"max": 256, "min": 1}, "qps": {}, ' + '"name": "1核_1G_10G", "count": 1, "device_class": [], ' + '"storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data"}]}', + "spec_id": 393, + "bk_agent_id": "", + }, + { + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", + "ip": "1.1.1.2", + "bk_biz_id": BK_BIZ_ID, + "db_module_id": 0, + "access_layer": "storage", + "machine_type": "es_datanode", + "cluster_type": ClusterType.Es, + "bk_host_id": 56, + "bk_os_name": "linux centos", + "bk_idc_area": "", + "bk_idc_area_id": 0, + "bk_sub_zone": "", + "bk_sub_zone_id": 0, + "bk_rack": "", + "bk_rack_id": 0, + "bk_svr_device_cls_name": "", + "bk_idc_name": "", + "bk_idc_id": 0, + "bk_cloud_id": 0, + "net_device_id": "", + "bk_city_id": 0, + "spec_config": '{"id": 393, "cpu": {"max": 256, "min": 1}, "mem": {"max": 256, "min": 1}, "qps": {}, ' + '"name": "1核_1G_10G", "count": 1, "device_class": [], ' + '"storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data"}]}', + "spec_id": 393, + "bk_agent_id": "", + }, +] + +ES_CLUSTER_DATA = { + "id": CLUSTER_ID, + "creator": BK_USERNAME, + "updater": BK_USERNAME, + "name": "randpass", + "alias": "randpass", + "bk_biz_id": BK_BIZ_ID, + "cluster_type": ClusterType.Es, + "db_module_id": 0, + "immute_domain": "es.randpass.dba.db", + "major_version": "7.10.2", + "phase": "online", + "status": "normal", + "bk_cloud_id": 0, + "region": "", + "time_zone": "+08:00", + "disaster_tolerance_level": "NONE", +} + +ES_SPEC_DATA = [ + { + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", + "spec_id": 391, + "spec_name": "1核_1G_10G", + "spec_cluster_type": "es", + "spec_machine_type": "es_master", + "cpu": {"max": 256, "min": 1}, + "mem": {"max": 256, "min": 1}, + "device_class": [], + "storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data"}], + "desc": "12", + "enable": True, + "instance_num": 0, + "qps": {}, + }, + { + "creator": BK_USERNAME, + "create_at": "2024-03-15 11:14:48.433116", + "updater": "", + "update_at": "2024-03-15 11:14:48.433116", + "spec_id": 393, + "spec_name": "1核_1G_10G", + "spec_cluster_type": "es", + "spec_machine_type": "es_datanode", + "cpu": {"max": 256, "min": 1}, + "mem": {"max": 256, "min": 1}, + "device_class": [], + "storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data"}], + "desc": "es_datanode", + "enable": True, + "instance_num": 0, + "qps": {}, + }, +] + +ES_STORAGE_INSTANCE = [ + { + "id": 4, + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", + "version": "", + "port": 9200, + "machine_id": 55, + "db_module_id": 0, + "bk_biz_id": BK_BIZ_ID, + "access_layer": "storage", + "machine_type": "es_datanode", + "instance_role": "es_datanode_hot", + "instance_inner_role": "orphan", + "cluster_type": "es", + "status": "running", + "phase": "online", + "name": "dn-1.1.2.2_1", + "time_zone": "+08:00", + "bk_instance_id": 0, + "is_stand_by": "1", + }, + { + "id": 5, + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", + "version": "", + "port": 9200, + "machine_id": 56, + "db_module_id": 0, + "bk_biz_id": BK_BIZ_ID, + "access_layer": "storage", + "machine_type": "es_datanode", + "instance_role": "es_datanode_cold", + "instance_inner_role": "orphan", + "cluster_type": "es", + "status": "running", + "phase": "online", + "name": "cold-1.1.3.3_1", + "time_zone": "+08:00", + "bk_instance_id": 5883, + "is_stand_by": "1", + }, +] diff --git a/dbm-ui/backend/tests/mock_data/ticket/hdfs_flow.py b/dbm-ui/backend/tests/mock_data/ticket/hdfs_flow.py new file mode 100644 index 0000000000..6c27ea0c9b --- /dev/null +++ b/dbm-ui/backend/tests/mock_data/ticket/hdfs_flow.py @@ -0,0 +1,142 @@ +# -*- coding: utf-8 -*- +""" +TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. +Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. +Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. +You may obtain a copy of the License at https://opensource.org/licenses/MIT +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. +""" + + +from backend.db_meta.enums.cluster_type import ClusterType +from backend.tests.mock_data import constant + +BK_USERNAME = "admin" +BK_BIZ_ID = constant.BK_BIZ_ID +CLUSTER_ID = 92 + + +HDFS_APPLY_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "bk_cloud_id": 0, + "city_code": "default", + "cluster_alias": "", + "cluster_name": "testhdfs", + "db_app_abbr": "1", + "db_version": "2.6.0-cdh5.4.11-tendataV0.2", + "disaster_tolerance_level": "MAX_EACH_ZONE_EQUAL", + "http_port": 50070, + "ip_source": "resource_pool", + "resource_spec": { + "datanode": { + "count": 2, + "spec_id": 394, + "cpu": {"max": 256, "min": 1}, + "mem": {"max": 256, "min": 1}, + "qps": {}, + "spec_name": "1核_1G_10G", + "storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data", "_X_ROW_KEY": "row_93"}], + "affinity": "MAX_EACH_ZONE_EQUAL", + "location_spec": {"city": "default"}, + }, + "namenode": { + "count": 2, + "spec_id": 395, + "cpu": {"max": 256, "min": 1}, + "mem": {"max": 256, "min": 1}, + "qps": {}, + "spec_name": "1核_1G_10G", + "storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data", "_X_ROW_KEY": "row_53"}], + "affinity": "MAX_EACH_ZONE_EQUAL", + "location_spec": {"city": "default"}, + }, + "zookeeper": { + "count": 3, + "spec_id": 395, + "cpu": {"max": 256, "min": 1}, + "mem": {"max": 256, "min": 1}, + "qps": {}, + "spec_name": "1核_1G_10G", + "storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data", "_X_ROW_KEY": "row_69"}], + "affinity": "MAX_EACH_ZONE_EQUAL", + "location_spec": {"city": "default"}, + }, + }, + "rpc_port": 9000, + "city_name": "无限制", + }, + "remark": "", + "ticket_type": "HDFS_APPLY", +} + +HDFS_SCALE_UP_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "cluster_id": CLUSTER_ID, + "ext_info": {"datanode": {"expansion_disk": 10, "total_disk": None, "total_hosts": 2}}, + "ip_source": "resource_pool", + "resource_spec": {"datanode": {"count": 1, "spec_id": 394}}, + }, + "ticket_type": "HDFS_SCALE_UP", +} + +HDFS_SPEC_DATA = [ + { + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", + "spec_id": 394, + "spec_name": "1核_1G_10G", + "spec_cluster_type": "hdfs", + "spec_machine_type": "hdfs_datanode", + "cpu": {"max": 256, "min": 1}, + "mem": {"max": 256, "min": 1}, + "device_class": [], + "storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data"}], + "desc": "12", + "enable": True, + "instance_num": 0, + "qps": {}, + }, + { + "creator": BK_USERNAME, + "create_at": "2024-03-15 11:14:48.433116", + "updater": "", + "update_at": "2024-03-15 11:14:48.433116", + "spec_id": 395, + "spec_name": "1核_1G_10G", + "spec_cluster_type": "hdfs", + "spec_machine_type": "hdfs_master", + "cpu": {"max": 256, "min": 1}, + "mem": {"max": 256, "min": 1}, + "device_class": [], + "storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data"}], + "desc": "212112", + "enable": True, + "instance_num": 0, + "qps": {}, + }, +] + +HDFS_CLUSTER_DATA = { + "id": CLUSTER_ID, + "creator": BK_USERNAME, + "updater": BK_USERNAME, + "name": "randpass", + "alias": "randpass", + "bk_biz_id": BK_BIZ_ID, + "cluster_type": ClusterType.Hdfs, + "db_module_id": 0, + "immute_domain": "hdfs.randpass.dba.db", + "major_version": "2.6.0-cdh5.4.11-tendataV0.2", + "phase": "online", + "status": "normal", + "bk_cloud_id": 0, + "region": "", + "time_zone": "+08:00", + "disaster_tolerance_level": "NONE", +} diff --git a/dbm-ui/backend/tests/mock_data/ticket/kafka_flow.py b/dbm-ui/backend/tests/mock_data/ticket/kafka_flow.py new file mode 100644 index 0000000000..e1647524c3 --- /dev/null +++ b/dbm-ui/backend/tests/mock_data/ticket/kafka_flow.py @@ -0,0 +1,140 @@ +# -*- coding: utf-8 -*- +""" +TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. +Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. +Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. +You may obtain a copy of the License at https://opensource.org/licenses/MIT +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. +""" + + +from backend.db_meta.enums.cluster_type import ClusterType +from backend.tests.mock_data import constant + +BK_USERNAME = "admin" +BK_BIZ_ID = constant.BK_BIZ_ID +CLUSTER_ID = 29 + +# kafka 集群部署 +KAFKA_APPLY_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "bk_cloud_id": 0, + "city_code": "default", + "cluster_alias": "", + "cluster_name": "testkafka", + "db_app_abbr": "1", + "db_version": "2.4.0", + "disaster_tolerance_level": "MAX_EACH_ZONE_EQUAL", + "ip_source": "resource_pool", + "no_security": 0, + "partition_num": 1, + "port": 9092, + "replication_num": 2, + "resource_spec": { + "broker": { + "count": 2, + "spec_id": 240, + "cpu": {"max": 256, "min": 1}, + "mem": {"max": 256, "min": 1}, + "qps": {}, + "spec_name": "1核_1G_10G", + "storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data", "_X_ROW_KEY": "row_387"}], + "affinity": "MAX_EACH_ZONE_EQUAL", + "location_spec": {"city": "default"}, + }, + "zookeeper": { + "count": 3, + "spec_id": 189, + "cpu": {"max": 2, "min": 2}, + "mem": {"max": 4, "min": 4}, + "qps": {}, + "spec_name": "2核_4G_100G", + "storage_spec": [{"size": 100, "type": "SSD", "mount_point": "/data", "_X_ROW_KEY": "row_371"}], + "affinity": "MAX_EACH_ZONE_EQUAL", + "location_spec": {"city": "default"}, + }, + }, + "retention_bytes": -1, + "retention_hours": 4, + "city_name": "无限制", + }, + "remark": "", + "ticket_type": "KAFKA_APPLY", +} + +# kafka 扩容 +KAFKA_SCALE_UP_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "cluster_id": CLUSTER_ID, + "ext_info": {"broker": {"expansion_disk": 10, "total_disk": None, "total_hosts": 1}}, + "ip_source": "resource_pool", + "resource_spec": {"broker": {"count": 1, "spec_id": 240}}, + }, + "ticket_type": "KAFKA_SCALE_UP", +} + +# kafka 禁用 +KAFKA_DISABLE_DATA = {"bk_biz_id": BK_BIZ_ID, "details": {"cluster_id": CLUSTER_ID}, "ticket_type": "KAFKA_DISABLE"} + +# 初始化redis集群 +KAFKA_CLUSTER_DATA = { + "id": CLUSTER_ID, + "creator": BK_USERNAME, + "updater": BK_USERNAME, + "name": "testredis", + "alias": "", + "bk_biz_id": BK_BIZ_ID, + "cluster_type": ClusterType.Kafka, + "db_module_id": 0, + "immute_domain": "kafka.testredis.dba.db", + "major_version": "2.4.0", + "phase": "online", + "status": "normal", + "bk_cloud_id": 0, + "region": "", + "time_zone": "+08:00", + "disaster_tolerance_level": "NONE", +} + +KAFKA_SPEC_DATA = [ + { + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", + "spec_id": 189, + "spec_name": "2核_4G_100G", + "spec_cluster_type": "kafka", + "spec_machine_type": "zookeeper", + "cpu": {"max": 2, "min": 2}, + "mem": {"max": 4, "min": 4}, + "device_class": [], + "storage_spec": [{"size": 100, "type": "SSD", "mount_point": "/data"}], + "desc": "zookeeper规格", + "enable": True, + "instance_num": 0, + "qps": {}, + }, + { + "creator": BK_USERNAME, + "create_at": "2024-03-15 11:14:48.433116", + "updater": "", + "update_at": "2024-03-15 11:14:48.433116", + "spec_id": 240, + "spec_name": "1核_1G_10G", + "spec_cluster_type": "kafka", + "spec_machine_type": "broker", + "cpu": {"max": 256, "min": 1}, + "mem": {"max": 256, "min": 1}, + "device_class": [], + "storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data"}], + "desc": "", + "enable": True, + "instance_num": 0, + "qps": {}, + }, +] diff --git a/dbm-ui/backend/tests/mock_data/ticket/mysql_flow.py b/dbm-ui/backend/tests/mock_data/ticket/mysql_flow.py index 6792455712..4b5b61c524 100644 --- a/dbm-ui/backend/tests/mock_data/ticket/mysql_flow.py +++ b/dbm-ui/backend/tests/mock_data/ticket/mysql_flow.py @@ -11,15 +11,99 @@ import uuid from backend.configuration.constants import DBType +from backend.db_meta.enums.cluster_type import ClusterType +from backend.db_meta.enums.machine_type import MachineType from backend.db_services.dbbase.constants import IpSource from backend.flow.models import StateType from backend.tests.mock_data import constant from backend.tests.mock_data.ticket.ticket_flow import BK_BIZ_ID, ROOT_ID from backend.ticket.constants import TicketType +BK_USERNAME = "admin" +CLUSTER_ID = 125 SQL_IMPORT_NODE_ID = "a651615616516dwqd156dq6616516qd" SQL_IMPORT_VERSION_ID = "d516156156qwd161651665161656" + +MYSQL_ADD_SLAVE_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "backup_source": "remote", + "infos": [ + { + "cluster_ids": [CLUSTER_ID], + "resource_spec": { + "new_slave": { + "hosts": [{"bk_biz_id": BK_BIZ_ID, "bk_cloud_id": 0, "bk_host_id": 1, "ip": "1.1.2.2"}], + "spec_id": 0, + } + }, + } + ], + "ip_source": "resource_pool", + }, + "remark": "", + "ticket_type": "MYSQL_ADD_SLAVE", +} + +MYSQL_CHECKSUM_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "data_repair": {"is_repair": True, "mode": "manual"}, + "remark": "", + "runtime_hour": 48, + "timing": "2099-05-21T00:00:00+08:00", + "infos": [ + { + "cluster_id": CLUSTER_ID, + "master": { + "bk_biz_id": BK_BIZ_ID, + "bk_cloud_id": 0, + "bk_host_id": 599, + "ip": "1.1.3.3", + "port": 20000, + }, + "slaves": [ + {"bk_biz_id": BK_BIZ_ID, "bk_cloud_id": 0, "bk_host_id": 604, "ip": "1.1.3.5", "port": 20000} + ], + "db_patterns": ["source_test_db1"], + "ignore_dbs": [], + "table_patterns": ["*"], + "ignore_tables": [], + } + ], + }, + "remark": "", + "ticket_type": "MYSQL_CHECKSUM", +} + +MYSQL_HA_FULL_BACKUP_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "backup_type": "logical", + "file_tag": "DBFILE1M", + "infos": [{"cluster_id": CLUSTER_ID, "backup_local": "master"}], + }, + "remark": "", + "ticket_type": "MYSQL_HA_FULL_BACKUP", +} + +MYSQL_DATA_MIGRATE_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "infos": [ + { + "db_list": ["source_test_db1"], + "source_cluster": CLUSTER_ID, + "target_clusters": [99], + "data_schema_grant": "data,schema", + } + ] + }, + "remark": "", + "ticket_type": "MYSQL_DATA_MIGRATE", +} + MYSQL_AUTHORIZE_TICKET_DATA = { "bk_biz_id": constant.BK_BIZ_ID, "details": { @@ -198,3 +282,267 @@ "dump_schema": True, }, } + +MYSQL_CLUSTER_DATA = [ + { + "id": CLUSTER_ID, + "creator": BK_USERNAME, + "updater": BK_USERNAME, + "name": "fre4", + "alias": "", + "bk_biz_id": BK_BIZ_ID, + "cluster_type": ClusterType.TenDBHA, + "db_module_id": 2, + "immute_domain": "tendbha57db.fre4.dba.db", + "major_version": "MySQL-5.7", + "phase": "online", + "status": "normal", + "bk_cloud_id": 0, + "region": "default", + "time_zone": "+08:00", + "disaster_tolerance_level": "NONE", + }, + { + "id": 99, + "creator": BK_USERNAME, + "updater": BK_USERNAME, + "name": "9527", + "alias": "", + "bk_biz_id": BK_BIZ_ID, + "cluster_type": ClusterType.TenDBSingle, + "db_module_id": 1, + "immute_domain": "test1db.9527.1.db", + "major_version": "MySQL-5.7", + "phase": "online", + "status": "normal", + "bk_cloud_id": 0, + "region": "default", + "time_zone": "+08:00", + "disaster_tolerance_level": "NONE", + }, +] + +MYSQL_STORAGE_INSTANCE = [ + { + "id": 935, + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", + "version": "5.7.20", + "port": 20001, + "machine_id": 552, + "db_module_id": 2, + "bk_biz_id": BK_BIZ_ID, + "access_layer": "storage", + "machine_type": "backend", + "instance_role": "backend_master", + "instance_inner_role": "master", + "cluster_type": "tendbha", + "status": "running", + "phase": "online", + "name": "", + "time_zone": "+08:00", + "bk_instance_id": 7878, + "is_stand_by": "1", + }, + { + "id": 936, + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", + "version": "5.7.20", + "port": 20001, + "machine_id": 556, + "db_module_id": 0, + "bk_biz_id": BK_BIZ_ID, + "access_layer": "storage", + "machine_type": "backend", + "instance_role": "backend_slave", + "instance_inner_role": "slave", + "cluster_type": "tendbha", + "status": "running", + "phase": "online", + "name": "", + "time_zone": "+08:00", + "bk_instance_id": 7879, + "is_stand_by": "1", + }, + { + "id": 966, + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", + "version": "5.7.20", + "port": 20001, + "machine_id": 182, + "db_module_id": 0, + "bk_biz_id": BK_BIZ_ID, + "access_layer": "storage", + "machine_type": "single", + "instance_role": "orphan", + "instance_inner_role": "orphan", + "cluster_type": "tendbsingle", + "status": "running", + "phase": "online", + "name": "", + "time_zone": "+08:00", + "bk_instance_id": 6272, + "is_stand_by": "1", + }, +] + +MYSQL_MACHINE_DATA = [ + { + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", + "ip": "5.5.5.5", + "bk_biz_id": BK_BIZ_ID, + "db_module_id": 0, + "access_layer": "storage", + "machine_type": MachineType.BACKEND.value, + "cluster_type": ClusterType.TenDBHA, + "bk_host_id": 552, + "bk_os_name": "linux centos", + "bk_idc_area": "", + "bk_idc_area_id": 0, + "bk_sub_zone": "", + "bk_sub_zone_id": 0, + "bk_rack": "", + "bk_rack_id": 0, + "bk_svr_device_cls_name": "", + "bk_idc_name": "", + "bk_idc_id": 0, + "bk_cloud_id": 0, + "net_device_id": "", + "bk_city_id": 0, + "spec_config": '{"id": 3, "cpu": {"max": 256, "min": 1}, "mem": {"max": 256, "min": 1}, ' + '"qps": {"max": 0, "min": 0}, "name": "1核_1G_10G", "count": 1, "device_class": [],' + ' "storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data"}]}', + "spec_id": 445, + "bk_agent_id": "", + }, + { + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", + "ip": "5.5.5.3", + "bk_biz_id": BK_BIZ_ID, + "db_module_id": 0, + "access_layer": "storage", + "machine_type": MachineType.BACKEND.value, + "cluster_type": ClusterType.TenDBHA, + "bk_host_id": 556, + "bk_os_name": "linux centos", + "bk_idc_area": "", + "bk_idc_area_id": 0, + "bk_sub_zone": "", + "bk_sub_zone_id": 0, + "bk_rack": "", + "bk_rack_id": 0, + "bk_svr_device_cls_name": "", + "bk_idc_name": "", + "bk_idc_id": 0, + "bk_cloud_id": 0, + "net_device_id": "", + "bk_city_id": 0, + "spec_config": '{"id": 3, "cpu": {"max": 256, "min": 1}, "mem": {"max": 256, "min": 1}, ' + '"qps": {"max": 0, "min": 0}, "name": "1核_1G_10G", "count": 1, "device_class": [],' + ' "storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data"}]}', + "spec_id": 444, + "bk_agent_id": "", + }, + { + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", + "ip": "5.5.5.4", + "bk_biz_id": BK_BIZ_ID, + "db_module_id": 0, + "access_layer": "storage", + "machine_type": MachineType.SINGLE.value, + "cluster_type": ClusterType.TenDBSingle, + "bk_host_id": 182, + "bk_os_name": "linux centos", + "bk_idc_area": "", + "bk_idc_area_id": 0, + "bk_sub_zone": "", + "bk_sub_zone_id": 0, + "bk_rack": "", + "bk_rack_id": 0, + "bk_svr_device_cls_name": "", + "bk_idc_name": "", + "bk_idc_id": 0, + "bk_cloud_id": 0, + "net_device_id": "", + "bk_city_id": 0, + "spec_config": '{"id": 3, "cpu": {"max": 256, "min": 1}, "mem": {"max": 256, "min": 1}, ' + '"qps": {"max": 0, "min": 0}, "name": "1核_1G_10G", "count": 1, "device_class": [],' + ' "storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data"}]}', + "spec_id": 336, + "bk_agent_id": "", + }, +] + +MYSQL_SPEC_DATA = [ + { + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", + "spec_id": 444, + "spec_name": "无限制", + "spec_cluster_type": "mysql", + "spec_machine_type": "backend", + "cpu": {"max": 256, "min": 1}, + "mem": {"max": 256, "min": 1}, + "device_class": [], + "storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data"}], + "desc": "111", + "enable": True, + "instance_num": 0, + "qps": {}, + }, + { + "creator": BK_USERNAME, + "create_at": "2024-03-15 11:14:48.433116", + "updater": "", + "update_at": "2024-03-15 11:14:48.433116", + "spec_id": 445, + "spec_name": "2c_4g_50g", + "spec_cluster_type": "mysql", + "spec_machine_type": "backend", + "cpu": {"max": 2, "min": 2}, + "mem": {"max": 4, "min": 3}, + "device_class": ["S5.MEDIUM4", "SA2.MEDIUM4", "S5t.MEDIUM4"], + "storage_spec": [{"size": 50, "type": "ALL", "mount_point": "/data"}], + "desc": "", + "enable": True, + "instance_num": 0, + "qps": {}, + }, + { + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", + "spec_id": 336, + "spec_name": "无限制", + "spec_cluster_type": "mysql", + "spec_machine_type": "backend", + "cpu": {"max": 256, "min": 1}, + "mem": {"max": 256, "min": 1}, + "device_class": [], + "storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data"}], + "desc": "111", + "enable": True, + "instance_num": 0, + "qps": {}, + }, +] diff --git a/dbm-ui/backend/tests/mock_data/ticket/redis_flow.py b/dbm-ui/backend/tests/mock_data/ticket/redis_flow.py new file mode 100644 index 0000000000..61d26c6091 --- /dev/null +++ b/dbm-ui/backend/tests/mock_data/ticket/redis_flow.py @@ -0,0 +1,665 @@ +# -*- coding: utf-8 -*- +""" +TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. +Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. +Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. +You may obtain a copy of the License at https://opensource.org/licenses/MIT +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. +""" + + +from backend.db_meta.enums.cluster_type import ClusterType +from backend.db_meta.enums.machine_type import MachineType +from backend.tests.mock_data import constant + +CLUSTER_ID = 130 +BK_USERNAME = "admin" +BK_BIZ_ID = constant.BK_BIZ_ID + + +# redis 集群部署 +REDIS_CLUSTER_APPLY_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "bk_cloud_id": 0, + "cap_key": "", + "city_code": "default", + "cluster_alias": "", + "cluster_name": "redis-test", + "cluster_type": "PredixyRedisCluster", + "db_app_abbr": "1", + "db_version": "Redis-5", + "disaster_tolerance_level": "CROSS_RACK", + "ip_source": "resource_pool", + "proxy_port": 55556, + "proxy_pwd": "UIVCVSo;xxe-m;oyK#KK7L;a%3wW#b=j", + "resource_spec": { + "backend_group": { + "affinity": "CROSS_RACK", + "count": 3, + "location_spec": {"city": "default"}, + "spec_id": 333, + "spec_info": {"cluster_capacity": 3, "cluster_shard_num": 3, "machine_pair": 3, "spec_name": "无限制"}, + }, + "proxy": { + "count": 2, + "spec_id": 338, + "cpu": {"max": 2, "min": 2}, + "mem": {"max": 4, "min": 3}, + "qps": {}, + "spec_name": "2c_4g_50g", + "storage_spec": [{"size": 50, "type": "ALL", "mount_point": "/data", "_X_ROW_KEY": "row_107"}], + "affinity": "CROSS_RACK", + "location_spec": {"city": "default"}, + "spec_cluster_type": "PredixyRedisCluster", + "spec_machine_type": "TwemproxyRedisInstance", + }, + }, + "sub_zone_ids": [], + "city_name": "无限制", + "cluster_shard_num": 3, + }, + "remark": "", + "ticket_type": "REDIS_CLUSTER_APPLY", +} + +# redis 主从节点部署 +REDIS_INS_APPLY_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "bk_cloud_id": 0, + "city_code": "default", + "cluster_type": "RedisInstance", + "db_app_abbr": "1", + "db_version": "Redis-5", + "disaster_tolerance_level": "CROSS_RACK", + "infos": [{"cluster_name": "testttredis", "databases": 2}], + "ip_source": "resource_pool", + "port": 30000, + "redis_pwd": "vMF@is8s#RBl4EnF5jTaHALjWKWBqAhr", + "resource_spec": { + "backend_group": { + "count": 1, + "spec_id": 335, + "cpu": {"max": 2, "min": 2}, + "mem": {"max": 4, "min": 3}, + "qps": {}, + "spec_name": "2c_4g_50gb", + "storage_spec": [{"size": 50, "type": "ALL", "mount_point": "/data"}], + "affinity": "CROSS_RACK", + "location_spec": {"city": "default"}, + } + }, + "sub_zone_ids": [], + "append_apply": False, + }, + "remark": "", + "ticket_type": "REDIS_INS_APPLY", +} + +# redis 数据复制 + +REDIS_CLUSTER_DATA_COPY_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "data_check_repair_setting": { + "execution_frequency": "once_after_replication", + "type": "data_check_and_repair", + }, + "dts_copy_type": "one_app_diff_cluster", + "infos": [{"dst_cluster": CLUSTER_ID, "key_black_regex": "", "key_white_regex": "*", "src_cluster": 131}], + "sync_disconnect_setting": {"reminder_frequency": "once_daily", "type": "keep_sync_with_reminder"}, + "write_mode": "delete_and_write_to_redis", + }, + "remark": "", + "ticket_type": "REDIS_CLUSTER_DATA_COPY", + "ignore_duplication": True, +} + +# redis 销毁构造实例 +REDIS_STRUCTURE_TASK_DELETE_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "infos": [ + { + "bk_cloud_id": 0, + "cluster_id": CLUSTER_ID, + "display_info": {"temp_cluster_proxy": "2.2.3.3:50000"}, + "related_rollback_bill_id": 2551, + } + ] + }, + "ticket_type": "REDIS_DATA_STRUCTURE_TASK_DELETE", + "ignore_duplication": True, +} + +# redis 重建从库单据 +REDIS_REBUILD_SLAVE_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "infos": [ + { + "bk_cloud_id": 0, + "cluster_ids": [CLUSTER_ID], + "pairs": [ + { + "redis_master": {"bk_cloud_id": 0, "bk_host_id": 493, "ip": "5.5.5.3"}, + "redis_slave": {"count": 1, "old_slave_ip": "5.5.5.5", "spec_id": 333}, + } + ], + } + ], + "ip_source": "resource_pool", + }, + "remark": "", + "ticket_type": "REDIS_CLUSTER_ADD_SLAVE", +} + +# redis 整机替换 +REDIS_CLUSTER_CUTOFF_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "infos": [ + { + "bk_cloud_id": 0, + "cluster_ids": [CLUSTER_ID], + "proxy": [], + "redis_master": [{"bk_host_id": 493, "ip": "5.5.5.3", "spec_id": 333}], + "redis_slave": [], + } + ], + "ip_source": "resource_pool", + }, + "remark": "", + "ticket_type": "REDIS_CLUSTER_CUTOFF", +} + +# redis 主从替换 +REDIS_MASTER_SLAVE_SWITCH_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "force": True, + "infos": [ + { + "cluster_ids": [CLUSTER_ID], + "online_switch_type": "user_confirm", + "pairs": [{"redis_master": "5.5.5.3", "redis_slave": "5.5.5.5"}], + } + ], + }, + "remark": "", + "ticket_type": "REDIS_MASTER_SLAVE_SWITCH", +} + +# redis 迁移 +REDIS_MIGRATE_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "infos": [ + { + "cluster_id": CLUSTER_ID, + "display_info": {"db_version": ["redis-6.2.14"], "instance": "5.5.5.5:30000"}, + "old_nodes": { + "master": [ + { + "bk_biz_id": BK_BIZ_ID, + "bk_cloud_id": 0, + "bk_host_id": 493, + "ip": "5.5.5.3", + "port": 30000, + } + ], + "slave": [ + { + "bk_biz_id": BK_BIZ_ID, + "bk_cloud_id": 0, + "bk_host_id": 495, + "ip": "5.5.5.5", + "port": 30000, + } + ], + }, + "resource_spec": {"backend_group": {"count": 1, "spec_id": 333}}, + } + ] + }, + "remark": "", + "ticket_type": "REDIS_CLUSTER_INS_MIGRATE", +} + +# redis 版本升级 +REDIS_VERSION_UPDATE_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "infos": [ + { + "node_type": "Backend", + "cluster_ids": [CLUSTER_ID], + "target_version": "redis-6.2.14", + "current_versions": ["redis-4.0.11-t-v1"], + } + ] + }, + "remark": "", + "ticket_type": "REDIS_VERSION_UPDATE_ONLINE", +} + +# redis 构造实例数据回写 +REDIS_CLUSTER_ROLLBACK_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "dts_copy_type": "copy_from_rollback_instance", + "infos": [ + { + "dst_cluster": CLUSTER_ID, + "key_black_regex": "", + "key_white_regex": "*", + "recovery_time_point": "2024-05-19T00:00:00+08:00", + "src_cluster": "2.2.3.3:50000", + } + ], + "write_mode": "delete_and_write_to_redis", + }, + "remark": "", + "ticket_type": "REDIS_CLUSTER_ROLLBACK_DATA_COPY", +} + +# redis 集群数据构造 +REDIS_DATA_STRUCTURE_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "infos": [ + { + "bk_cloud_id": 0, + "cluster_id": 130, + "master_instances": [ + "5.5.5.3:30000", + "5.5.5.3:30001", + "5.5.5.3:30002", + "5.5.5.3:30003", + ], + "recovery_time_point": "2025-05-25T04:00:00+08:00", + "resource_spec": {"redis": {"count": 1, "spec_id": 333}}, + } + ], + "ip_source": "resource_pool", + }, + "remark": "", + "ticket_type": "REDIS_DATA_STRUCTURE", +} + +# redis 集群扩容 +REDIS_PROXY_SCALE_UP_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "infos": [ + { + "bk_cloud_id": 0, + "cluster_id": CLUSTER_ID, + "resource_spec": {"proxy": {"count": 1, "spec_id": 338}}, + "target_proxy_count": 3, + } + ], + "ip_source": "resource_pool", + }, + "remark": "", + "ticket_type": "REDIS_PROXY_SCALE_UP", + "ignore_duplication": True, +} + +# redis 集群分片变更 +REDIS_CLUSTER_SHARD_NUM_UPDATE_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "data_check_repair_setting": { + "execution_frequency": "once_after_replication", + "type": "data_check_and_repair", + }, + "infos": [ + { + "capacity": 128.5, + "cluster_shard_num": 2, + "current_shard_num": 4, + "current_spec_id": 333, + "db_version": "Redis-5", + "future_capacity": 1, + "online_switch_type": "user_confirm", + "resource_spec": { + "backend_group": {"affinity": "CROS_SUBZONE", "count": 1, "spec_id": 333}, + "proxy": {"affinity": "CROS_SUBZONE", "count": 2, "spec_id": 338}, + }, + "src_cluster": CLUSTER_ID, + } + ], + "ip_source": "resource_pool", + }, + "remark": "", + "ticket_type": "REDIS_CLUSTER_SHARD_NUM_UPDATE", + "ignore_duplication": True, +} + +# redis 集群类型变更 +REDIS_CLUSTER_TYPE_UPDATE_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "data_check_repair_setting": { + "execution_frequency": "once_after_replication", + "type": "data_check_and_repair", + }, + "infos": [ + { + "capacity": 128.5, + "cluster_shard_num": 16, + "current_cluster_type": "TwemproxyRedisInstance", + "current_shard_num": 4, + "current_spec_id": 333, + "db_version": "Redis-5", + "future_capacity": 3, + "online_switch_type": "user_confirm", + "resource_spec": { + "backend_group": {"affinity": "CROS_SUBZONE", "count": 1, "spec_id": 335}, + "proxy": {"affinity": "CROS_SUBZONE", "count": 2, "spec_id": 338}, + }, + "src_cluster": CLUSTER_ID, + "target_cluster_type": "PredixyRedisCluster", + } + ], + "ip_source": "resource_pool", + }, + "remark": "", + "ticket_type": "REDIS_CLUSTER_TYPE_UPDATE", + "ignore_duplication": True, +} + +# redis 接入clb +REDIS_PLUGIN_CREATE_CLB = { + "bk_biz_id": BK_BIZ_ID, + "details": {"cluster_id": CLUSTER_ID}, + "ticket_type": "REDIS_PLUGIN_CREATE_CLB", +} + +# redis 集群机器信息 +REDIS_MACHINE_DATA = [ + { + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", + "ip": "5.5.5.5", + "bk_biz_id": BK_BIZ_ID, + "db_module_id": 0, + "access_layer": "dns", + "machine_type": MachineType.TENDISCACHE.value, + "cluster_type": ClusterType.TendisTwemproxyRedisInstance, + "bk_host_id": 495, + "bk_os_name": "linux centos", + "bk_idc_area": "", + "bk_idc_area_id": 0, + "bk_sub_zone": "", + "bk_sub_zone_id": 0, + "bk_rack": "", + "bk_rack_id": 0, + "bk_svr_device_cls_name": "", + "bk_idc_name": "", + "bk_idc_id": 0, + "bk_cloud_id": 0, + "net_device_id": "", + "bk_city_id": 0, + "spec_config": '{"id": 3, "cpu": {"max": 256, "min": 1}, "mem": {"max": 256, "min": 1}, ' + '"qps": {"max": 0, "min": 0}, "name": "1核_1G_10G", "count": 1, "device_class": [],' + ' "storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data"}]}', + "spec_id": 3, + "bk_agent_id": "", + }, + { + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", + "ip": "5.5.5.3", + "bk_biz_id": BK_BIZ_ID, + "db_module_id": 0, + "access_layer": "dns", + "machine_type": MachineType.TENDISCACHE.value, + "cluster_type": ClusterType.TendisTwemproxyRedisInstance, + "bk_host_id": 493, + "bk_os_name": "linux centos", + "bk_idc_area": "", + "bk_idc_area_id": 0, + "bk_sub_zone": "", + "bk_sub_zone_id": 0, + "bk_rack": "", + "bk_rack_id": 0, + "bk_svr_device_cls_name": "", + "bk_idc_name": "", + "bk_idc_id": 0, + "bk_cloud_id": 0, + "net_device_id": "", + "bk_city_id": 0, + "spec_config": '{"id": 3, "cpu": {"max": 256, "min": 1}, "mem": {"max": 256, "min": 1}, ' + '"qps": {"max": 0, "min": 0}, "name": "1核_1G_10G", "count": 1, "device_class": [],' + ' "storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data"}]}', + "spec_id": 3, + "bk_agent_id": "", + }, +] + +# 初始化redis集群 +REDIS_CLUSTER_DATA = [ + { + "id": CLUSTER_ID, + "creator": BK_USERNAME, + "updater": BK_USERNAME, + "name": "kiotest-iam-1", + "alias": "kiotest-iam-1", + "bk_biz_id": BK_BIZ_ID, + "cluster_type": ClusterType.TendisTwemproxyRedisInstance, + "db_module_id": 0, + "immute_domain": "cache.kiotest-iam-1.dba.db", + "major_version": "Redis-5", + "phase": "online", + "status": "normal", + "bk_cloud_id": 0, + "region": "default", + "time_zone": "+08:00", + "disaster_tolerance_level": "NONE", + }, + { + "id": 131, + "creator": BK_USERNAME, + "updater": BK_USERNAME, + "name": "kiotest-iam-2", + "alias": "kiotest-iam-2", + "bk_biz_id": BK_BIZ_ID, + "cluster_type": ClusterType.TendisTwemproxyRedisInstance, + "db_module_id": 0, + "immute_domain": "cache.kiotest-iam-2.dba.db", + "major_version": "Redis-5", + "phase": "online", + "status": "normal", + "bk_cloud_id": 0, + "region": "default", + "time_zone": "+08:00", + "disaster_tolerance_level": "CROS_SUBZONE", + }, +] + +# 初始化机器实际的城市信息 +REDIS_BKCITY_DATA = { + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", + "bk_idc_city_id": 0, + "bk_idc_city_name": "default", + "logical_city_id": 1, +} + +# 初始化逻辑上的城市信息 +REDIS_LOGICALCITY_DATA = { + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", + "NAME": "default", +} + +REDIS_STORAGE_INSTANCE_TUPLE = { + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", +} + +REDIS_STORAGE_INSTANCE = [ + { + "id": 1, + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", + "version": "", + "port": 30000, + "machine_id": 495, + "db_module_id": 0, + "bk_biz_id": BK_BIZ_ID, + "access_layer": "storage", + "machine_type": "tendiscache", + "instance_role": "redis_slave", + "instance_inner_role": "slave", + "cluster_type": "TwemproxyRedisInstance", + "status": "unavailable", + "phase": "online", + "name": "", + "time_zone": "+08:00", + "bk_instance_id": 7979, + "is_stand_by": "1", + }, + { + "id": 2, + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", + "version": "", + "port": 30000, + "machine_id": 493, + "db_module_id": 0, + "bk_biz_id": BK_BIZ_ID, + "access_layer": "storage", + "machine_type": "tendiscache", + "instance_role": "redis_master", + "instance_inner_role": "master", + "cluster_type": "TwemproxyRedisInstance", + "status": "running", + "phase": "online", + "name": "", + "time_zone": "+08:00", + "bk_instance_id": 7975, + "is_stand_by": "1", + }, +] + +REDIS_SPEC_DATA = [ + { + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", + "spec_id": 333, + "spec_name": "无限制", + "spec_cluster_type": "redis", + "spec_machine_type": "TwemproxyRedisInstance", + "cpu": {"max": 256, "min": 1}, + "mem": {"max": 256, "min": 1}, + "device_class": [], + "storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data"}], + "desc": "111", + "enable": True, + "instance_num": 0, + "qps": {}, + }, + { + "creator": BK_USERNAME, + "create_at": "2024-03-15 11:14:48.433116", + "updater": "", + "update_at": "2024-03-15 11:14:48.433116", + "spec_id": 335, + "spec_name": "2c_4g_50g", + "spec_cluster_type": "redis", + "spec_machine_type": "TwemproxyRedisInstance", + "cpu": {"max": 2, "min": 2}, + "mem": {"max": 4, "min": 3}, + "device_class": ["S5.MEDIUM4", "SA2.MEDIUM4", "S5t.MEDIUM4"], + "storage_spec": [{"size": 50, "type": "ALL", "mount_point": "/data"}], + "desc": "", + "enable": True, + "instance_num": 0, + "qps": {}, + }, + { + "creator": BK_USERNAME, + "create_at": "2024-03-15 11:14:48.433116", + "updater": "", + "update_at": "2024-03-15 11:14:48.433116", + "spec_id": 338, + "spec_name": "2c_4g_50g", + "spec_cluster_type": "redis", + "spec_machine_type": "proxy", + "cpu": {"max": 2, "min": 2}, + "mem": {"max": 4, "min": 3}, + "device_class": ["S5.MEDIUM4", "SA2.MEDIUM4", "S5t.MEDIUM4"], + "storage_spec": [{"size": 50, "type": "ALL", "mount_point": "/data"}], + "desc": "基础机型", + "enable": True, + "instance_num": 0, + "qps": {}, + }, +] + +REDIS_TENDIS_ROLLBACK_TASK_DATA = { + "creator": BK_USERNAME, + "create_at": "2024-03-13 11:14:48.433116", + "updater": "", + "update_at": "2024-03-13 11:14:48.433116", + "related_rollback_bill_id": 2551, + "bk_biz_id": BK_BIZ_ID, + "app": "", + "bk_cloud_id": 0, + "prod_cluster_type": ClusterType.TendisTwemproxyRedisInstance, + "prod_cluster": "cache.kiotest-iam-1.dba.db", + "prod_instance_range": ["5.5.5.5:30000", "5.5.5.5:30001", "5.5.5.5:30002", "5.5.5.5:30003"], + "temp_cluster_type": ClusterType.TendisTwemproxyRedisInstance, + "temp_proxy_password": "xxxxxxx", + "temp_instance_range": [ + "2.2.3.3:30000", + "2.2.3.3:30001", + "2.2.3.3:30002", + "2.2.3.3:30003", + ], + "temp_cluster_proxy": "2.2.3.3:50000", + "prod_temp_instance_pairs": [ + ["5.5.5.5:30000", "2.2.3.3:30000"], + ["5.5.5.5:30001", "2.2.3.3:30001"], + ["5.5.5.5:30002", "2.2.3.3:30002"], + ["5.5.5.5:30003", "2.2.3.3:30003"], + ], + "status": 2, + "specification": { + "id": 333, + "cpu": {"max": 256, "min": 1}, + "mem": {"max": 256, "min": 1}, + "qps": {}, + "name": "无限制", + "count": 1, + "device_class": [], + "storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data"}], + }, + "host_count": 1, + "recovery_time_point": "2024-05-19T00:00:00+08:00", + "prod_cluster_id": CLUSTER_ID, + "destroyed_status": 0, + "temp_redis_password": "xxxxxxxxxx", +} diff --git a/dbm-ui/backend/tests/mock_data/ticket/tendbcluster.py b/dbm-ui/backend/tests/mock_data/ticket/tendbcluster.py new file mode 100644 index 0000000000..ebfb27a47f --- /dev/null +++ b/dbm-ui/backend/tests/mock_data/ticket/tendbcluster.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +""" +TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. +Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. +Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. +You may obtain a copy of the License at https://opensource.org/licenses/MIT +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. +""" + + +from backend.db_meta.enums.cluster_type import ClusterType +from backend.tests.mock_data import constant + +BK_USERNAME = "admin" +BK_BIZ_ID = constant.BK_BIZ_ID +CLUSTER_ID = 177 + + +TENDBCLUSTER_FULL_BACKUP_DATA = { + "bk_biz_id": BK_BIZ_ID, + "details": { + "backup_type": "logical", + "file_tag": "DBFILE1M", + "infos": [{"cluster_id": CLUSTER_ID, "backup_local": "master"}], + }, + "remark": "", + "ticket_type": "TENDBCLUSTER_FULL_BACKUP", +} + +TENDBCLUSTER_CLUSTER_DATA = { + "id": CLUSTER_ID, + "creator": BK_USERNAME, + "updater": BK_USERNAME, + "name": "dev-ygctest-tendbcluster", + "alias": "", + "bk_biz_id": BK_BIZ_ID, + "cluster_type": ClusterType.TenDBCluster, + "db_module_id": 42, + "immute_domain": "spider.dev-ygctest-tendbcluster.dba.db", + "major_version": "MySQL-5.7", + "phase": "online", + "status": "normal", + "bk_cloud_id": 0, + "region": "", + "time_zone": "+08:00", + "disaster_tolerance_level": "NONE", +} diff --git a/dbm-ui/backend/tests/ticket/es/test_es_flow.py b/dbm-ui/backend/tests/ticket/es/test_es_flow.py new file mode 100644 index 0000000000..092eea7517 --- /dev/null +++ b/dbm-ui/backend/tests/ticket/es/test_es_flow.py @@ -0,0 +1,77 @@ +# -*- coding: utf-8 -*- +""" +TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. +Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. +Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. +You may obtain a copy of the License at https://opensource.org/licenses/MIT +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. +""" +import logging + +import pytest + +from backend.configuration.constants import DBType +from backend.db_meta.enums import ClusterType +from backend.db_meta.models import Cluster, Machine, Spec, StorageInstance +from backend.tests.mock_data.ticket.es_flow import ( + ES_APPLY_DATA, + ES_CLUSTER_DATA, + ES_DISABLE_DATA, + ES_MACHINE_DATA, + ES_SCALE_UP_DATA, + ES_SHRINK_DATA, + ES_SPEC_DATA, + ES_STORAGE_INSTANCE, +) +from backend.tests.ticket.server_base import BaseTicketTest + +logger = logging.getLogger("test") +pytestmark = pytest.mark.django_db + + +@pytest.fixture(scope="class", autouse=True) +def setup_es_database(django_db_setup, django_db_blocker): + with django_db_blocker.unblock(): + # 初始化集群数据 + cluster = Cluster.objects.create(**ES_CLUSTER_DATA) + Machine.objects.bulk_create([Machine(**data) for data in ES_MACHINE_DATA]) + Spec.objects.bulk_create([Spec(**data) for data in ES_SPEC_DATA]) + storage_instances = StorageInstance.objects.bulk_create( + [StorageInstance(**data) for data in ES_STORAGE_INSTANCE] + ) + storage_instances[0].cluster.add(cluster) + storage_instances[1].cluster.add(cluster) + yield + es_cluster_types = ClusterType.db_type_to_cluster_types(DBType.Es) + Cluster.objects.filter(cluster_type__in=es_cluster_types).delete() + StorageInstance.objects.filter(cluster_type__in=es_cluster_types).delete() + Machine.objects.filter(cluster_type__in=es_cluster_types).delete() + Spec.objects.filter(spec_cluster_type=DBType.Es).delete() + + +class TestEsFlow(BaseTicketTest): + """ + es测试类 + """ + + @classmethod + def apply_patches(cls): + super().apply_patches() + + def test_es_apply_flow(self): + # es集群部署 + self.flow_test(ES_APPLY_DATA) + + def test_es_scale_up_flow(self): + # es集群扩容 + self.flow_test(ES_SCALE_UP_DATA) + + def test_es_shrink_flow(self): + # es集群缩容 + self.flow_test(ES_SHRINK_DATA) + + def test_es_disable(self): + # es禁用 + self.flow_test(ES_DISABLE_DATA) diff --git a/dbm-ui/backend/tests/ticket/hdfs/test_hdfs_flow.py b/dbm-ui/backend/tests/ticket/hdfs/test_hdfs_flow.py new file mode 100644 index 0000000000..bd8feb7fa5 --- /dev/null +++ b/dbm-ui/backend/tests/ticket/hdfs/test_hdfs_flow.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +""" +TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. +Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. +Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. +You may obtain a copy of the License at https://opensource.org/licenses/MIT +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. +""" +import logging + +import pytest + +from backend.configuration.constants import DBType +from backend.db_meta.enums import ClusterType +from backend.db_meta.models import Cluster, Spec +from backend.tests.mock_data.ticket.hdfs_flow import ( + HDFS_APPLY_DATA, + HDFS_CLUSTER_DATA, + HDFS_SCALE_UP_DATA, + HDFS_SPEC_DATA, +) +from backend.tests.ticket.server_base import BaseTicketTest + +logger = logging.getLogger("test") +pytestmark = pytest.mark.django_db + + +@pytest.fixture(scope="class", autouse=True) +def setup_hdfs_database(django_db_setup, django_db_blocker): + with django_db_blocker.unblock(): + # 初始化集群数据 + Cluster.objects.create(**HDFS_CLUSTER_DATA) + Spec.objects.bulk_create([Spec(**data) for data in HDFS_SPEC_DATA]) + yield + hdfs_cluster_types = ClusterType.db_type_to_cluster_types(DBType.Hdfs) + Cluster.objects.filter(cluster_type__in=hdfs_cluster_types).delete() + Spec.objects.filter(spec_cluster_type=DBType.Hdfs).delete() + + +class TestHdfsFlow(BaseTicketTest): + """ + hdfs测试类 + """ + + @classmethod + def apply_patches(cls): + super().apply_patches() + + def test_hdfs_apply_flow(self): + # hdfs集群部署 + self.flow_test(HDFS_APPLY_DATA) + + def test_hdfs_scale_up_flow(self): + # hdfs扩容 + self.flow_test(HDFS_SCALE_UP_DATA) diff --git a/dbm-ui/backend/tests/ticket/kafka/test_kafka_flow.py b/dbm-ui/backend/tests/ticket/kafka/test_kafka_flow.py new file mode 100644 index 0000000000..ee446f6df3 --- /dev/null +++ b/dbm-ui/backend/tests/ticket/kafka/test_kafka_flow.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +""" +TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. +Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. +Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. +You may obtain a copy of the License at https://opensource.org/licenses/MIT +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. +""" +import logging + +import pytest + +from backend.configuration.constants import DBType +from backend.db_meta.enums import ClusterType +from backend.db_meta.models import Cluster, Spec +from backend.tests.mock_data.ticket.kafka_flow import ( + KAFKA_APPLY_DATA, + KAFKA_CLUSTER_DATA, + KAFKA_DISABLE_DATA, + KAFKA_SCALE_UP_DATA, + KAFKA_SPEC_DATA, +) +from backend.tests.ticket.server_base import BaseTicketTest + +logger = logging.getLogger("test") +pytestmark = pytest.mark.django_db + + +@pytest.fixture(scope="class", autouse=True) +def setup_kafka_database(django_db_setup, django_db_blocker): + with django_db_blocker.unblock(): + # 初始化集群数据 + Cluster.objects.create(**KAFKA_CLUSTER_DATA) + Spec.objects.bulk_create([Spec(**data) for data in KAFKA_SPEC_DATA]) + yield + kafka_cluster_types = ClusterType.db_type_to_cluster_types(DBType.Kafka) + Cluster.objects.filter(cluster_type__in=kafka_cluster_types).delete() + Spec.objects.filter(spec_cluster_type=DBType.Kafka).delete() + + +class TestKafkaFlow(BaseTicketTest): + """ + kafka测试类 + """ + + @classmethod + def apply_patches(cls): + super().apply_patches() + + def test_kafka_apply_flow(self): + # kafka集群部署 + self.flow_test(KAFKA_APPLY_DATA) + + def test_kafka_scale_up_flow(self): + # kafka扩容 + self.flow_test(KAFKA_SCALE_UP_DATA) + + def test_kafka_disable(self): + # kafka禁用 + self.flow_test(KAFKA_DISABLE_DATA) diff --git a/dbm-ui/backend/tests/ticket/mysql/test_mysql_flow.py b/dbm-ui/backend/tests/ticket/mysql/test_mysql_flow.py index 26bc0358f8..ef7cccdeaf 100644 --- a/dbm-ui/backend/tests/ticket/mysql/test_mysql_flow.py +++ b/dbm-ui/backend/tests/ticket/mysql/test_mysql_flow.py @@ -18,19 +18,29 @@ from django.conf import settings from django.core.cache import cache +from backend.configuration.constants import DBType from backend.db_meta.enums import ClusterType -from backend.db_meta.models import Cluster +from backend.db_meta.models import Cluster, Machine, Spec, StorageInstance from backend.flow.models import FlowNode, FlowTree from backend.tests.mock_data.components.cc import CCApiMock from backend.tests.mock_data.components.dbconfig import DBConfigApiMock +from backend.tests.mock_data.components.drs import DRSApiMock from backend.tests.mock_data.components.mysql_priv_manager import DBPrivManagerApiMock from backend.tests.mock_data.components.sql_import import SQLSimulationApiMock from backend.tests.mock_data.flow.engine.bamboo.engine import BambooEngineMock from backend.tests.mock_data.ticket.mysql_flow import ( + MYSQL_ADD_SLAVE_DATA, MYSQL_AUTHORIZE_TICKET_DATA, + MYSQL_CHECKSUM_DATA, + MYSQL_CLUSTER_DATA, + MYSQL_DATA_MIGRATE_DATA, MYSQL_DUMP_DATA, + MYSQL_HA_FULL_BACKUP_DATA, MYSQL_ITSM_AUTHORIZE_TICKET_DATA, + MYSQL_MACHINE_DATA, MYSQL_SINGLE_APPLY_TICKET_DATA, + MYSQL_SPEC_DATA, + MYSQL_STORAGE_INSTANCE, MYSQL_TENDBHA_TICKET_DATA, SQL_IMPORT_FLOW_NODE_DATA, SQL_IMPORT_TICKET_DATA, @@ -47,9 +57,23 @@ @pytest.fixture(scope="class", autouse=True) def setup_mysql_database(django_db_setup, django_db_blocker): with django_db_blocker.unblock(): + clusters = Cluster.objects.bulk_create([Cluster(**data) for data in MYSQL_CLUSTER_DATA]) + Machine.objects.bulk_create([Machine(**data) for data in MYSQL_MACHINE_DATA]) + storage_instances = StorageInstance.objects.bulk_create( + [StorageInstance(**data) for data in MYSQL_STORAGE_INSTANCE] + ) + storage_instances[0].cluster.add(clusters[0]) + storage_instances[1].cluster.add(clusters[0]) + storage_instances[2].cluster.add(clusters[1]) + Spec.objects.bulk_create([Spec(**data) for data in MYSQL_SPEC_DATA]) FlowTree.objects.create(**FLOW_TREE_DATA) FlowNode.objects.create(**SQL_IMPORT_FLOW_NODE_DATA) yield + mysql_cluster_types = ClusterType.db_type_to_cluster_types(DBType.MySQL) + Cluster.objects.filter(cluster_type__in=mysql_cluster_types).delete() + StorageInstance.objects.filter(cluster_type__in=mysql_cluster_types).delete() + Machine.objects.filter(cluster_type__in=mysql_cluster_types).delete() + Spec.objects.filter(spec_cluster_type=DBType.Redis).delete() FlowTree.objects.all().delete() FlowNode.objects.all().delete() @@ -74,6 +98,9 @@ def apply_patches(cls): "backend.ticket.builders.mysql.mysql_import_sqlfile.BambooEngine", BambooEngineMock ) mock_cc_api_patch = patch("backend.db_meta.models.app.CCApi", CCApiMock()) + mock_drs_api_patch = patch( + "backend.db_services.mysql.remote_service.handlers.DRSApi", new_callable=lambda: DRSApiMock() + ) cls.patches.extend( [ mock_list_account_rules_patch, @@ -81,6 +108,7 @@ def apply_patches(cls): mock_simulation_api_patch, mock_bamboo_api_patch, mock_cc_api_patch, + mock_drs_api_patch, ] ) super().apply_patches() @@ -93,6 +121,18 @@ def test_mysql_authorize_ticket_flow(self): self.flow_test(authorize_data) cache.delete(authorize_uid) + def test_mysql_add_slave_flow(self): + self.flow_test(MYSQL_ADD_SLAVE_DATA) + + def test_mysql_checksum_flow(self): + self.flow_test(MYSQL_CHECKSUM_DATA) + + def test_mysql_full_backup_flow(self): + self.flow_test(MYSQL_HA_FULL_BACKUP_DATA) + + def test_mysql_data_migrate_flow(self): + self.flow_test(MYSQL_DATA_MIGRATE_DATA) + def test_mysql_single_apply_flow(self): self.flow_test(MYSQL_SINGLE_APPLY_TICKET_DATA) diff --git a/dbm-ui/backend/tests/ticket/redis/test_redis_flow.py b/dbm-ui/backend/tests/ticket/redis/test_redis_flow.py new file mode 100644 index 0000000000..0c01c2a112 --- /dev/null +++ b/dbm-ui/backend/tests/ticket/redis/test_redis_flow.py @@ -0,0 +1,141 @@ +# -*- coding: utf-8 -*- +""" +TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. +Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. +Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. +You may obtain a copy of the License at https://opensource.org/licenses/MIT +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. +""" +import logging + +import pytest + +from backend.configuration.constants import DBType +from backend.db_meta.enums import ClusterType +from backend.db_meta.models import Cluster, Machine, Spec, StorageInstance, StorageInstanceTuple +from backend.db_services.redis.rollback.models import TbTendisRollbackTasks +from backend.tests.mock_data.ticket.redis_flow import ( + REDIS_CLUSTER_APPLY_DATA, + REDIS_CLUSTER_CUTOFF_DATA, + REDIS_CLUSTER_DATA, + REDIS_CLUSTER_DATA_COPY_DATA, + REDIS_CLUSTER_ROLLBACK_DATA, + REDIS_CLUSTER_SHARD_NUM_UPDATE_DATA, + REDIS_CLUSTER_TYPE_UPDATE_DATA, + REDIS_DATA_STRUCTURE_DATA, + REDIS_INS_APPLY_DATA, + REDIS_MACHINE_DATA, + REDIS_MASTER_SLAVE_SWITCH_DATA, + REDIS_MIGRATE_DATA, + REDIS_PLUGIN_CREATE_CLB, + REDIS_PROXY_SCALE_UP_DATA, + REDIS_REBUILD_SLAVE_DATA, + REDIS_SPEC_DATA, + REDIS_STORAGE_INSTANCE, + REDIS_STORAGE_INSTANCE_TUPLE, + REDIS_STRUCTURE_TASK_DELETE_DATA, + REDIS_TENDIS_ROLLBACK_TASK_DATA, + REDIS_VERSION_UPDATE_DATA, +) +from backend.tests.ticket.server_base import BaseTicketTest + +logger = logging.getLogger("test") +pytestmark = pytest.mark.django_db + + +@pytest.fixture(scope="class", autouse=True) +def setup_redis_database(django_db_setup, django_db_blocker): + with django_db_blocker.unblock(): + # 初始化集群数据 + clusters = Cluster.objects.bulk_create([Cluster(**data) for data in REDIS_CLUSTER_DATA]) + Machine.objects.bulk_create([Machine(**data) for data in REDIS_MACHINE_DATA]) + storage_instances = StorageInstance.objects.bulk_create( + [StorageInstance(**data) for data in REDIS_STORAGE_INSTANCE] + ) + storage_instances[0].cluster.add(clusters[0]) + storage_instances[1].cluster.add(clusters[0]) + REDIS_STORAGE_INSTANCE_TUPLE["receiver"] = storage_instances[0] + REDIS_STORAGE_INSTANCE_TUPLE["ejector"] = storage_instances[1] + StorageInstanceTuple.objects.create(**REDIS_STORAGE_INSTANCE_TUPLE) + Spec.objects.bulk_create([Spec(**data) for data in REDIS_SPEC_DATA]) + TbTendisRollbackTasks.objects.create(**REDIS_TENDIS_ROLLBACK_TASK_DATA) + yield + redis_cluster_types = ClusterType.db_type_to_cluster_types(DBType.Redis) + Cluster.objects.filter(cluster_type__in=redis_cluster_types).delete() + StorageInstance.objects.filter(cluster_type__in=redis_cluster_types).delete() + Machine.objects.filter(cluster_type__in=redis_cluster_types).delete() + StorageInstanceTuple.objects.all().delete() + Spec.objects.filter(spec_cluster_type=DBType.Redis).delete() + TbTendisRollbackTasks.objects.filter(temp_cluster_type__in=redis_cluster_types).delete() + + +class TestRedisFlow(BaseTicketTest): + """ + redis测试类 + """ + + @classmethod + def apply_patches(cls): + super().apply_patches() + + def test_redis_master_apply_test(self): + # redis构建集群 + self.flow_test(REDIS_CLUSTER_APPLY_DATA) + + def test_redis_ins_apply_test(self): + # redis构建主从集群 + self.flow_test(REDIS_INS_APPLY_DATA) + + def test_redis_data_copy_test(self): + # redis数据复制 + self.flow_test(REDIS_CLUSTER_DATA_COPY_DATA) + + def test_redis_task_delete_test(self): + # redis销毁构造实例 + self.flow_test(REDIS_STRUCTURE_TASK_DELETE_DATA) + + def test_redis_rebuild_slave_flow(self): + # redis从库重建 + self.flow_test(REDIS_REBUILD_SLAVE_DATA) + + def test_redis_cut_off_flow(self): + # redis整机替换 + self.flow_test(REDIS_CLUSTER_CUTOFF_DATA) + + def test_redis_master_slave_switch_flow(self): + # redis主从切换 + self.flow_test(REDIS_MASTER_SLAVE_SWITCH_DATA) + + def test_redis_migrate_flow(self): + # redis迁移 + self.flow_test(REDIS_MIGRATE_DATA) + + def test_redis_version_update(self): + # redis版本升级 + self.flow_test(REDIS_VERSION_UPDATE_DATA) + + def test_redis_cluster_rollback_flow(self): + # redis构造实例恢复 + self.flow_test(REDIS_CLUSTER_ROLLBACK_DATA) + + def test_redis_structure_flow(self): + # redis集群数据构造 + self.flow_test(REDIS_DATA_STRUCTURE_DATA) + + def test_redis_proxy_scale_up_flow(self): + # redis集群扩容 + self.flow_test(REDIS_PROXY_SCALE_UP_DATA) + + def test_redis_shard_num_update_flow(self): + # redis集群分片变更 + self.flow_test(REDIS_CLUSTER_SHARD_NUM_UPDATE_DATA) + + def test_redis_cluster_type_update(self): + # redis集群类型变更 + self.flow_test(REDIS_CLUSTER_TYPE_UPDATE_DATA) + + def test_redis_create_clb(self): + # redis集群接入clb + self.flow_test(REDIS_PLUGIN_CREATE_CLB) diff --git a/dbm-ui/backend/tests/ticket/tendbcluster/test_tendbcluster_flow.py b/dbm-ui/backend/tests/ticket/tendbcluster/test_tendbcluster_flow.py new file mode 100644 index 0000000000..3fcfdd11d9 --- /dev/null +++ b/dbm-ui/backend/tests/ticket/tendbcluster/test_tendbcluster_flow.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +""" +TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available. +Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved. +Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. +You may obtain a copy of the License at https://opensource.org/licenses/MIT +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. +""" +import logging + +import pytest + +from backend.configuration.constants import DBType +from backend.db_meta.enums import ClusterType +from backend.db_meta.models import Cluster +from backend.tests.mock_data.ticket.tendbcluster import TENDBCLUSTER_CLUSTER_DATA, TENDBCLUSTER_FULL_BACKUP_DATA +from backend.tests.ticket.server_base import BaseTicketTest + +logger = logging.getLogger("test") +pytestmark = pytest.mark.django_db + + +@pytest.fixture(scope="class", autouse=True) +def setup_tendbcluster_database(django_db_setup, django_db_blocker): + with django_db_blocker.unblock(): + # 初始化集群数据 + Cluster.objects.create(**TENDBCLUSTER_CLUSTER_DATA) + yield + tendbcluster_cluster_types = ClusterType.db_type_to_cluster_types(DBType.TenDBCluster) + Cluster.objects.filter(cluster_type__in=tendbcluster_cluster_types).delete() + + +class TestTenDBClusterFlow(BaseTicketTest): + """ + tendbcluster测试类 + """ + + @classmethod + def apply_patches(cls): + super().apply_patches() + + def test_tendbcluster_full_backup_flow(self): + # tendbcluster全库备份 + self.flow_test(TENDBCLUSTER_FULL_BACKUP_DATA)