Skip to content

Commit

Permalink
节点管理-免评审: 节点管理「管控区域」「agent版本」筛选能力优化 (closed TencentBlueKing#1752)
Browse files Browse the repository at this point in the history
  • Loading branch information
Huayeaaa committed Jan 17, 2024
1 parent 7c1f74a commit db8f672
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions apps/node_man/handlers/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def fetch_host_process_unique_col(
select_sql = "SELECT distinct "
select_conditions = []
for col in col_list:
if col in ["version", "status"]:
if col in ["version", "status", "is_latest"]:
select_conditions.append(f"{models.ProcessStatus._meta.db_table}.{col} AS `{col}`")
else:
select_conditions.append(f"{models.Host._meta.db_table}.{col} AS `{col}`")
Expand Down Expand Up @@ -486,7 +486,7 @@ def fetch_plugin_version_condition(self, params):
return [{"name": name, "id": name} for name in settings.HEAD_PLUGINS]

plugin_versions = []
col_list = ["version"]
col_list = ["version", "is_latest"]
plugin_names = tools.PluginV2Tools.fetch_head_plugins()
for name in plugin_names:
col_data = self.fetch_host_process_unique_col(
Expand All @@ -498,8 +498,8 @@ def fetch_plugin_version_condition(self, params):
)

for sublist in col_data:
# 过滤掉版本号为""的插件
if not sublist[0] == "":
# 过滤掉版本号为""且is_latest=0的插件
if not sublist[0] == "" and sublist[1] == 1:
plugin_versions.append({"name": name, "version": sublist[0]})

agent_versions = (
Expand Down
5 changes: 3 additions & 2 deletions apps/node_man/tests/test_handlers/test_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def test_fetch_plugin_condition(self):
@patch("apps.node_man.handlers.cmdb.CmdbHandler.cmdb_or_cache_biz", cmdb_or_cache_biz)
@patch("apps.node_man.handlers.cmdb.client_v2", MockClient)
def test_fetch_plugin_version_condition(self):
host_to_create, _, _ = create_host(10)
host_to_create, _, _ = create_host(100)
process_to_create = []
for host in host_to_create:
process_to_create.append(
Expand All @@ -290,13 +290,14 @@ def test_fetch_plugin_version_condition(self):
version=f"{random.randint(1, 10)}",
name=settings.HEAD_PLUGINS[random.randint(0, len(settings.HEAD_PLUGINS) - 1)],
status="RUNNING",
is_latest=random.randint(0, 1),
)
)
ProcessStatus.objects.bulk_create(process_to_create)
# 验证不传业务ID的情况;即返回用户所有权限的业务ID
result = MetaHandler().fetch_plugin_version_condition(params={"bk_biz_ids": []})
self.assertEqual(len(result), 11)
self.assertEqual(len(result[0]["children"]), 10)
self.assertEqual(len(result[0]["children"]), 100)
# 验证传入部分业务ID的情况
result = MetaHandler().fetch_plugin_version_condition(params={"bk_biz_ids": [27, 30]})
self.assertLessEqual(len(result), 11)
Expand Down

0 comments on commit db8f672

Please sign in to comment.