Skip to content

Commit

Permalink
fix: 修复proxy主机转移模块后变成pagent问题 (closed #2474)
Browse files Browse the repository at this point in the history
  • Loading branch information
Huayeaaa committed Oct 28, 2024
1 parent 7f47072 commit efbe7a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion apps/node_man/periodic_tasks/sync_cmdb_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,13 @@ def sync_cmdb_host(bk_biz_id=None, task_id=None):
# 节点管理需要删除的host_id
need_delete_host_ids = set(node_man_host_ids) - set(cc_bk_host_ids)
if need_delete_host_ids:
models.Host.objects.filter(bk_host_id__in=need_delete_host_ids).delete()
proxy_host_ids: typing.Set[int] = set(
models.Host.objects.filter(
bk_host_id__in=need_delete_host_ids, node_type=constants.NodeType.PROXY
).values_list("bk_host_id", flat=True)
)
need_delete_agent_host_ids = need_delete_host_ids - proxy_host_ids
models.Host.objects.filter(bk_host_id__in=need_delete_agent_host_ids).delete()
models.IdentityData.objects.filter(bk_host_id__in=need_delete_host_ids).delete()
if not LPUSH_AND_EXPIRE_FUNC:
models.ProcessStatus.objects.filter(bk_host_id__in=need_delete_host_ids).delete()
Expand Down Expand Up @@ -566,6 +572,7 @@ def query_cmdb_and_handle_need_delete_host_ids(host_ids: typing.List[int], task_
)
)
final_delete_host_ids = set(host_ids) - set(bk_host_ids_in_cmdb)
models.Host.objects.filter(bk_host_id__in=final_delete_host_ids).delete()
models.ProcessStatus.objects.filter(bk_host_id__in=final_delete_host_ids).delete()
logger.info(
"[clear_final_delete_host_ids] task_id -> %s, final_delete_host_ids -> %s, num -> %s"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def test_sync_cmdb_host(self):
)
self.assertEqual(itf_results.sort(key=lambda t: t[0]), list(db_result).sort(key=lambda t: t[0]))

# 验证主机信息是否删除成功
self.assertEqual(Host.objects.filter(bk_host_id=-1).count(), 0)
# 验证主机信息是否删除成功/proxy主机信息先保留
self.assertEqual(Host.objects.filter(bk_host_id=-1).count(), 1)


class TestClearNeedDeleteHostIds(CustomBaseTestCase):
Expand Down

0 comments on commit efbe7a5

Please sign in to comment.