Skip to content

Commit

Permalink
fix: 非直连场景下 Agent 安装密码查询错误 (closed TencentBlueKing#1966)
Browse files Browse the repository at this point in the history
# Reviewed, transaction id: 5929
  • Loading branch information
ping15 authored and ZhuoZhuoCrayon committed Apr 16, 2024
1 parent e1612fb commit 013a530
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ def _execute(self, data, parent_data, common_data: AgentCommonData):
)

no_need_query_inst_ids = []
direct_connection_only_inst_ids = []

# 这里暂不支持多
cloud_ip_map = {}
oa_ticket = ""
Expand All @@ -160,13 +162,16 @@ def _execute(self, data, parent_data, common_data: AgentCommonData):

if host.identity.auth_type != constants.AuthType.TJJ_PASSWORD:
no_need_query_inst_ids.append(sub_inst.id)
elif host.bk_cloud_id != constants.DEFAULT_CLOUD:
direct_connection_only_inst_ids.append(sub_inst.id)
else:
cloud_ip_map[f"{host.bk_cloud_id}-{host.inner_ip}"] = {"host": host, "sub_inst_id": sub_inst.id}
# 兼容 extra 为 None 的情况
if host.identity.extra_data:
oa_ticket = host.identity.extra_data.get("oa_ticket")

self.log_info(sub_inst_ids=no_need_query_inst_ids, log_content=_("当前主机验证类型无需查询密码"))
self.move_insts_to_failed(sub_inst_ids=direct_connection_only_inst_ids, log_content=_("密码查询逻辑仅支持直连"))
need_query_inst_ids = [item["sub_inst_id"] for item in cloud_ip_map.values()]
if not need_query_inst_ids:
return True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import random

import mock
from django.db.models import F
from django.utils.translation import ugettext as _

from apps.backend.components.collections.agent_new import query_password
from apps.backend.components.collections.agent_new.components import (
Expand Down Expand Up @@ -154,3 +156,20 @@ def assert_in_teardown(self):
).count(),
len(self.obj_factory.bk_host_ids),
)


class QueryPasswordNotInDefaultCloudIDTestCase(QueryPasswordFailedTestCase):
def _do_case_assert(self, service, method, assertion, no, name, args=None, kwargs=None):
models.Host.objects.all().update(bk_cloud_id=F("bk_cloud_id") + 1)
super()._do_case_assert(service, method, assertion, no, name, args, kwargs)
failed_subscription_instance_id_reason_map = service.failed_subscription_instance_id_reason_map
self.assertEqual(len(failed_subscription_instance_id_reason_map), self.obj_factory.init_host_num)
self.assertEqual(list(failed_subscription_instance_id_reason_map.values()), [_("密码查询逻辑仅支持直连")] * 255)


class QueryPasswordInDefaultCloudIDTestCase(QueryPasswordFailedTestCase):
def _do_case_assert(self, service, method, assertion, no, name, args=None, kwargs=None):
super()._do_case_assert(service, method, assertion, no, name, args, kwargs)
failed_subscription_instance_id_reason_map = service.failed_subscription_instance_id_reason_map
self.assertEqual(len(failed_subscription_instance_id_reason_map), self.obj_factory.init_host_num)
self.assertNotEquals(list(failed_subscription_instance_id_reason_map.values()), [_("密码查询逻辑仅支持直连")] * 255)

0 comments on commit 013a530

Please sign in to comment.