Skip to content

Commit

Permalink
feature: 重启/重载/升级 Agent 后增加功能检测步骤 (closed TencentBlueKing#1338)
Browse files Browse the repository at this point in the history
  • Loading branch information
CohleRustW authored and ZhuoZhuoCrayon committed Dec 22, 2022
1 parent d21c3c3 commit ae320dc
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 0 deletions.
10 changes: 10 additions & 0 deletions apps/backend/agent/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,13 @@ def push_agent_pkg_to_proxy(cls):
name=components.PushAgentPkgToProxyComponent.name,
)
return act

@classmethod
def check_agent_ability(cls):
"""检测 Agent 功能"""
act = AgentServiceActivity(
component_code=components.CheckAgentAbilityComponent.code,
name=components.CheckAgentAbilityComponent.name,
)
act.component.inputs.polling_time = Var(type=Var.PLAIN, value=10)
return act
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*-
"""
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-节点管理(BlueKing-BK-NODEMAN) available.
Copyright (C) 2017-2022 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at https://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""

from apps.node_man import constants, models
from apps.utils.files import PathHandler

from .base import AgentCommonData, AgentExecuteScriptService


class CheckAgentAbilityService(AgentExecuteScriptService):
@property
def script_name(self):
return "check_agent_ability"

def get_script_content(self, data, common_data: AgentCommonData, host: models.Host) -> str:
"""
获取脚本内容
:param data:
:param common_data:
:param host: 主机对象
:return: 脚本内容
"""
path_handler: PathHandler = PathHandler(host.os_type)
ctl_exe_name: str = ("gse_agent", "gse_agent.exe")[host.os_type == constants.OsType.WINDOWS]
general_node_type: str = self.get_general_node_type(host.node_type)
setup_path: str = common_data.host_id__ap_map[host.bk_host_id].get_agent_config(host.os_type)["setup_path"]
agent_path: str = path_handler.join(setup_path, general_node_type, "bin", ctl_exe_name)

return f"{agent_path} --version"
7 changes: 7 additions & 0 deletions apps/backend/components/collections/agent_new/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from . import base
from .add_or_update_hosts import AddOrUpdateHostsService
from .bind_host_agent import BindHostAgentService
from .check_agent_ability import CheckAgentAbilityService
from .check_agent_status import CheckAgentStatusService
from .check_policy_gse_to_proxy import CheckPolicyGseToProxyService
from .choose_access_point import ChooseAccessPointService
Expand Down Expand Up @@ -200,3 +201,9 @@ class PushAgentPkgToProxyComponent(Component):
name = _("下发 Agent 安装包到 Proxy")
code = "push_agent_pkg_to_proxy"
bound_service = PushAgentPkgToProxyService


class CheckAgentAbilityComponent(Component):
name = _("检查Agent功能")
code = "check_agent_ability"
bound_service = CheckAgentAbilityService
1 change: 1 addition & 0 deletions apps/backend/components/collections/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ def inputs_format(self):
return super().inputs_format() + [
Service.InputItem(name="script_content", key="script_content", type="str", required=False),
Service.InputItem(name="script_param", key="script_param", type="str", required=False),
Service.InputItem(name="polling_time", key="polling_time", type="int", required=False),
]

@property
Expand Down
5 changes: 5 additions & 0 deletions apps/backend/subscription/steps/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ def _generate_activities(self, agent_manager: AgentManager):
agent_manager.run_upgrade_command(),
agent_manager.wait(10),
agent_manager.get_agent_status(expect_status=constants.ProcStateType.RUNNING),
agent_manager.check_agent_ability(),
]
return activities, None

Expand All @@ -316,6 +317,7 @@ def _generate_activities(self, agent_manager: AgentManager):
agent_manager.restart(skip_polling_result=True),
agent_manager.wait(5),
agent_manager.get_agent_status(expect_status=constants.ProcStateType.RUNNING),
agent_manager.check_agent_ability(),
]

return activities, None
Expand All @@ -334,6 +336,7 @@ def _generate_activities(self, agent_manager: AgentManager):
agent_manager.restart(skip_polling_result=True),
agent_manager.wait(5),
agent_manager.get_agent_status(expect_status=constants.ProcStateType.RUNNING, name=_("查询Proxy状态")),
agent_manager.check_agent_ability(),
]
return activities, None

Expand Down Expand Up @@ -412,6 +415,7 @@ def _generate_activities(self, agent_manager: AgentManager):
agent_manager.run_upgrade_command(),
agent_manager.wait(30),
agent_manager.get_agent_status(expect_status=constants.ProcStateType.RUNNING),
agent_manager.check_agent_ability(),
]

# 推送文件到proxy
Expand Down Expand Up @@ -488,6 +492,7 @@ def _generate_activities(self, agent_manager: AgentManager):
agent_manager.reload_agent(skip_polling_result=True),
agent_manager.wait(5),
agent_manager.get_agent_status(expect_status=constants.ProcStateType.RUNNING),
agent_manager.check_agent_ability(),
]
return activities, None

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
"""
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-节点管理(BlueKing-BK-NODEMAN) available.
Copyright (C) 2017-2022 THL A29 Limited, a Tencent company. All rights reserved.
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at https://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
"""

import base64

from apps.backend.components.collections.agent_new import components
from common.api import JobApi

from . import base
from .test_restart import RestartTestCase


class CheckAgentAbilityTestCase(RestartTestCase):
@classmethod
def get_default_case_name(cls) -> str:
return "测试Agent功能成功"

def component_cls(self):
return components.CheckAgentAbilityComponent

def tearDown(self) -> None:
record = self.job_api_mock_client.call_recorder.record
fast_execute_script_query_params = record[JobApi.fast_execute_script][0].args[0]
self.assertEqual(
"c:\\gse\\agent\\bin\\gse_agent.exe --version",
base64.b64decode(fast_execute_script_query_params["script_content"]).decode(),
)


#
class PollingResultFailedTestCase(base.JobFailedBaseTestCase, CheckAgentAbilityTestCase):
@classmethod
def get_default_case_name(cls) -> str:
return "测试失败 Agent 功能失败"
3 changes: 3 additions & 0 deletions dev_log/2.2.32/xcwang_202212152014.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
feature:
- "重启/重载/升级 Agent 后增加功能检测步骤 (closed #1338)"

0 comments on commit ae320dc

Please sign in to comment.