Skip to content

Commit 1c63dd9

Browse files
feat(test): 补充Redis、Kafka、Es、Hdfs的单测 #10361
1 parent a9378be commit 1c63dd9

File tree

11 files changed

+1650
-1
lines changed

11 files changed

+1650
-1
lines changed

dbm-ui/backend/tests/db_services/infras/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def test_list_cities(bk_user):
2626
view = LogicalCityViewSet.as_view({"get": "list_cities"})
2727
response = view(request)
2828
data = response.data
29-
assert len(data) == 2
29+
assert len(data) == 3
3030

3131

3232
def test_list_host_specs(bk_user):
Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
4+
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
5+
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at https://opensource.org/licenses/MIT
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
specific language governing permissions and limitations under the License.
10+
"""
11+
12+
13+
from backend.db_meta.enums.cluster_type import ClusterType
14+
from backend.tests.mock_data import constant
15+
16+
BK_USERNAME = "admin"
17+
BK_BIZ_ID = constant.BK_BIZ_ID
18+
CLUSTER_ID = 91
19+
20+
21+
# es 部署集群
22+
ES_APPLY_DATA = {
23+
"bk_biz_id": BK_BIZ_ID,
24+
"details": {
25+
"bk_cloud_id": 0,
26+
"city_code": "default",
27+
"cluster_alias": "",
28+
"cluster_name": "testes",
29+
"db_app_abbr": "1",
30+
"db_version": "7.2.0",
31+
"disaster_tolerance_level": "MAX_EACH_ZONE_EQUAL",
32+
"http_port": 9200,
33+
"ip_source": "resource_pool",
34+
"resource_spec": {
35+
"master": {
36+
"count": 3,
37+
"spec_id": 391,
38+
"cpu": {"max": 256, "min": 1},
39+
"mem": {"max": 256, "min": 1},
40+
"qps": {},
41+
"spec_name": "1核_1G_10G",
42+
"storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data", "_X_ROW_KEY": "row_72"}],
43+
"affinity": "MAX_EACH_ZONE_EQUAL",
44+
"location_spec": {"city": "default"},
45+
},
46+
"hot": {
47+
"count": 1,
48+
"spec_id": 393,
49+
"cpu": {"max": 256, "min": 1},
50+
"instance_num": 1,
51+
"mem": {"max": 256, "min": 1},
52+
"qps": {},
53+
"spec_name": "1核_1G_10G",
54+
"storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data", "_X_ROW_KEY": "row_117"}],
55+
"affinity": "MAX_EACH_ZONE_EQUAL",
56+
"location_spec": {"city": "default"},
57+
},
58+
},
59+
"city_name": "无限制",
60+
},
61+
"remark": "",
62+
"ticket_type": "ES_APPLY",
63+
}
64+
65+
# es 集群扩容
66+
ES_SCALE_UP_DATA = {
67+
"bk_biz_id": BK_BIZ_ID,
68+
"details": {
69+
"cluster_id": CLUSTER_ID,
70+
"ext_info": {
71+
"client": {"expansion_disk": 0, "total_disk": 0, "total_hosts": 0},
72+
"cold": {"expansion_disk": 10, "total_disk": None, "total_hosts": 1},
73+
"hot": {"expansion_disk": 0, "total_disk": None, "total_hosts": 1},
74+
},
75+
"ip_source": "resource_pool",
76+
"resource_spec": {"cold": {"count": 1, "instance_num": 1, "spec_id": 393}},
77+
},
78+
"ticket_type": "ES_SCALE_UP",
79+
}
80+
81+
# es 集群缩容
82+
ES_SHRINK_DATA = {
83+
"bk_biz_id": BK_BIZ_ID,
84+
"details": {
85+
"cluster_id": CLUSTER_ID,
86+
"ext_info": {
87+
"client": {"shrink_disk": 0, "total_disk": 0, "total_hosts": 0},
88+
"cold": {"shrink_disk": 0, "total_disk": 0, "total_hosts": 1},
89+
"hot": {"shrink_disk": 0, "total_disk": 0, "total_hosts": 1},
90+
},
91+
"ip_source": "resource_pool",
92+
"old_nodes": {"client": [], "cold": [{"bk_cloud_id": 0, "bk_host_id": 56, "ip": "1.1.1.2"}], "hot": []},
93+
},
94+
"ticket_type": "ES_SHRINK",
95+
}
96+
97+
# es 集群禁用
98+
ES_DISABLE_DATA = {"bk_biz_id": BK_BIZ_ID, "details": {"cluster_id": CLUSTER_ID}, "ticket_type": "ES_DISABLE"}
99+
100+
ES_MACHINE_DATA = [
101+
{
102+
"creator": BK_USERNAME,
103+
"create_at": "2023-03-13 11:14:48.433116",
104+
"updater": "",
105+
"update_at": "2023-03-13 11:14:48.433116",
106+
"ip": "1.1.3.4",
107+
"bk_biz_id": BK_BIZ_ID,
108+
"db_module_id": 0,
109+
"access_layer": "storage",
110+
"machine_type": "es_datanode",
111+
"cluster_type": ClusterType.Es,
112+
"bk_host_id": 55,
113+
"bk_os_name": "linux centos",
114+
"bk_idc_area": "",
115+
"bk_idc_area_id": 0,
116+
"bk_sub_zone": "",
117+
"bk_sub_zone_id": 0,
118+
"bk_rack": "",
119+
"bk_rack_id": 0,
120+
"bk_svr_device_cls_name": "",
121+
"bk_idc_name": "",
122+
"bk_idc_id": 0,
123+
"bk_cloud_id": 0,
124+
"net_device_id": "",
125+
"bk_city_id": 0,
126+
"spec_config": '{"id": 393, "cpu": {"max": 256, "min": 1}, "mem": {"max": 256, "min": 1}, "qps": {}, '
127+
'"name": "1核_1G_10G", "count": 1, "device_class": [], '
128+
'"storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data"}]}',
129+
"spec_id": 393,
130+
"bk_agent_id": "",
131+
},
132+
{
133+
"creator": BK_USERNAME,
134+
"create_at": "2024-03-13 11:14:48.433116",
135+
"updater": "",
136+
"update_at": "2024-03-13 11:14:48.433116",
137+
"ip": "1.1.1.2",
138+
"bk_biz_id": BK_BIZ_ID,
139+
"db_module_id": 0,
140+
"access_layer": "storage",
141+
"machine_type": "es_datanode",
142+
"cluster_type": ClusterType.Es,
143+
"bk_host_id": 56,
144+
"bk_os_name": "linux centos",
145+
"bk_idc_area": "",
146+
"bk_idc_area_id": 0,
147+
"bk_sub_zone": "",
148+
"bk_sub_zone_id": 0,
149+
"bk_rack": "",
150+
"bk_rack_id": 0,
151+
"bk_svr_device_cls_name": "",
152+
"bk_idc_name": "",
153+
"bk_idc_id": 0,
154+
"bk_cloud_id": 0,
155+
"net_device_id": "",
156+
"bk_city_id": 0,
157+
"spec_config": '{"id": 393, "cpu": {"max": 256, "min": 1}, "mem": {"max": 256, "min": 1}, "qps": {}, '
158+
'"name": "1核_1G_10G", "count": 1, "device_class": [], '
159+
'"storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data"}]}',
160+
"spec_id": 393,
161+
"bk_agent_id": "",
162+
},
163+
]
164+
165+
ES_CLUSTER_DATA = {
166+
"id": CLUSTER_ID,
167+
"creator": BK_USERNAME,
168+
"updater": BK_USERNAME,
169+
"name": "randpass",
170+
"alias": "randpass",
171+
"bk_biz_id": BK_BIZ_ID,
172+
"cluster_type": ClusterType.Es,
173+
"db_module_id": 0,
174+
"immute_domain": "es.randpass.dba.db",
175+
"major_version": "7.10.2",
176+
"phase": "online",
177+
"status": "normal",
178+
"bk_cloud_id": 0,
179+
"region": "",
180+
"time_zone": "+08:00",
181+
"disaster_tolerance_level": "NONE",
182+
}
183+
184+
ES_SPEC_DATA = [
185+
{
186+
"creator": BK_USERNAME,
187+
"create_at": "2024-03-13 11:14:48.433116",
188+
"updater": "",
189+
"update_at": "2024-03-13 11:14:48.433116",
190+
"spec_id": 391,
191+
"spec_name": "1核_1G_10G",
192+
"spec_cluster_type": "es",
193+
"spec_machine_type": "es_master",
194+
"cpu": {"max": 256, "min": 1},
195+
"mem": {"max": 256, "min": 1},
196+
"device_class": [],
197+
"storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data"}],
198+
"desc": "12",
199+
"enable": True,
200+
"instance_num": 0,
201+
"qps": {},
202+
},
203+
{
204+
"creator": BK_USERNAME,
205+
"create_at": "2024-03-15 11:14:48.433116",
206+
"updater": "",
207+
"update_at": "2024-03-15 11:14:48.433116",
208+
"spec_id": 393,
209+
"spec_name": "1核_1G_10G",
210+
"spec_cluster_type": "es",
211+
"spec_machine_type": "es_datanode",
212+
"cpu": {"max": 256, "min": 1},
213+
"mem": {"max": 256, "min": 1},
214+
"device_class": [],
215+
"storage_spec": [{"size": 10, "type": "ALL", "mount_point": "/data"}],
216+
"desc": "es_datanode",
217+
"enable": True,
218+
"instance_num": 0,
219+
"qps": {},
220+
},
221+
]
222+
223+
ES_STORAGE_INSTANCE = [
224+
{
225+
"id": 4,
226+
"creator": BK_USERNAME,
227+
"create_at": "2024-03-13 11:14:48.433116",
228+
"updater": "",
229+
"update_at": "2024-03-13 11:14:48.433116",
230+
"version": "",
231+
"port": 9200,
232+
"machine_id": 55,
233+
"db_module_id": 0,
234+
"bk_biz_id": BK_BIZ_ID,
235+
"access_layer": "storage",
236+
"machine_type": "es_datanode",
237+
"instance_role": "es_datanode_hot",
238+
"instance_inner_role": "orphan",
239+
"cluster_type": "es",
240+
"status": "running",
241+
"phase": "online",
242+
"name": "dn-1.1.2.2_1",
243+
"time_zone": "+08:00",
244+
"bk_instance_id": 0,
245+
"is_stand_by": "1",
246+
},
247+
{
248+
"id": 5,
249+
"creator": BK_USERNAME,
250+
"create_at": "2024-03-13 11:14:48.433116",
251+
"updater": "",
252+
"update_at": "2024-03-13 11:14:48.433116",
253+
"version": "",
254+
"port": 9200,
255+
"machine_id": 56,
256+
"db_module_id": 0,
257+
"bk_biz_id": BK_BIZ_ID,
258+
"access_layer": "storage",
259+
"machine_type": "es_datanode",
260+
"instance_role": "es_datanode_cold",
261+
"instance_inner_role": "orphan",
262+
"cluster_type": "es",
263+
"status": "running",
264+
"phase": "online",
265+
"name": "cold-1.1.3.3_1",
266+
"time_zone": "+08:00",
267+
"bk_instance_id": 5883,
268+
"is_stand_by": "1",
269+
},
270+
]

0 commit comments

Comments
 (0)