Skip to content

Commit

Permalink
fix: 修复返回数据格式错误 #7550
Browse files Browse the repository at this point in the history
  • Loading branch information
guohelu committed Oct 29, 2024
1 parent 387fd50 commit c1fb8e0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
40 changes: 36 additions & 4 deletions gcloud/tests/utils/cmdb/test_business_host_topo.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ def setUp(self):
},
],
},
]
],
"count": 2,
},
}
self.get_business_host_topo_expect_return = [
Expand Down Expand Up @@ -142,6 +143,37 @@ def setUp(self):
],
},
]
self.get_filter_business_host_topo_expect_return = (
[
{
"host": {
"bk_cloud_id": 0,
"bk_host_id": 1,
"bk_host_innerip": "127.0.0.1",
"bk_mac": "",
"bk_os_type": None,
},
"set": [{"bk_set_id": 11, "bk_set_name": "set1"}],
"module": [{"bk_module_id": 56, "bk_module_name": "m1"}],
},
{
"host": {
"bk_cloud_id": 0,
"bk_host_id": 3,
"bk_host_innerip": "127.0.0.3",
"bk_mac": "",
"bk_os_type": None,
},
"set": [{"bk_set_id": 10, "bk_set_name": "空闲机池"}, {"bk_set_id": 11, "bk_set_name": "set1"}],
"module": [
{"bk_module_id": 54, "bk_module_name": "空闲机"},
{"bk_module_id": 55, "bk_module_name": "空闲机1"},
{"bk_module_id": 56, "bk_module_name": "m1"},
],
},
],
2,
)

def tearDown(self):
self.get_client_by_user_patcher.stop()
Expand Down Expand Up @@ -202,7 +234,7 @@ def test__get_contains_with_ip_list(self):
ip_str=self.ip_str,
)

self.assertEqual(hosts_topo, self.get_business_host_topo_expect_return)
self.assertEqual(hosts_topo, self.get_filter_business_host_topo_expect_return)
self.mock_client.cc.list_biz_hosts_topo.assert_called_once_with(
{
"bk_biz_id": self.bk_biz_id,
Expand All @@ -228,7 +260,7 @@ def test__get_many_contains_with_ip_list(self):
ip_str=self.ip_strs,
)

self.assertEqual(hosts_topo, self.get_business_host_topo_expect_return)
self.assertEqual(hosts_topo, self.get_filter_business_host_topo_expect_return)
self.mock_client.cc.list_biz_hosts_topo.assert_called_once_with(
{
"bk_biz_id": self.bk_biz_id,
Expand All @@ -251,7 +283,7 @@ def test__get_with_page_list(self):
self.username, self.bk_biz_id, self.supplier_account, self.host_fields, start=0, limit=10
)

self.assertEqual(hosts_topo, self.get_business_host_topo_expect_return)
self.assertEqual(hosts_topo, self.get_filter_business_host_topo_expect_return)
self.mock_client.cc.list_biz_hosts_topo.assert_called_once_with(
{
"bk_biz_id": self.bk_biz_id,
Expand Down
2 changes: 1 addition & 1 deletion gcloud/utils/cmdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def get_filter_business_host_topo(username, bk_biz_id, supplier_account, host_fi

host_info_list.append(host_info)

return host_info_list
return host_info_list, data["data"]["count"]


def get_business_host(username, bk_biz_id, supplier_account, host_fields, ip_list=None, bk_cloud_id=None):
Expand Down
9 changes: 6 additions & 3 deletions pipeline_plugins/cmdb_ip_picker/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ def cmdb_search_host(request, bk_biz_id, bk_supplier_account="", bk_supplier_id=
message = handle_api_error(_("配置平台(CMDB)"), "cc.search_cloud_area", {}, cloud_area_result)
result = {"result": False, "code": ERROR_CODES.API_GSE_ERROR, "message": message}
return JsonResponse(result)

count = None
if start and limit:
raw_host_info_list = cmdb.get_filter_business_host_topo(
raw_host_info_list, count = cmdb.get_filter_business_host_topo(
request.user.username, bk_biz_id, bk_supplier_account, fields, int(start), int(limit), ip_str
)
else:
Expand Down Expand Up @@ -219,7 +219,10 @@ def cmdb_search_host(request, bk_biz_id, bk_supplier_account="", bk_supplier_id=
host_lock_status = host_lock_status_data.get(host_detail["bk_host_id"])
if host_lock_status is not None:
host_detail["bk_host_lock_status"] = host_lock_status
result = {"result": True, "code": NO_ERROR, "data": data}
if count:
result = {"result": True, "code": NO_ERROR, "data": {"data": data, "count": count}}
else:
result = {"result": True, "code": NO_ERROR, "data": data}
return JsonResponse(result)


Expand Down

0 comments on commit c1fb8e0

Please sign in to comment.