Skip to content

Commit

Permalink
feature: Agent升级功能支持 2.x -> 2.x 的升级 (close TencentBlueKing#1311)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangzhw8 committed Dec 6, 2022
1 parent 343aeeb commit 627c199
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
3 changes: 3 additions & 0 deletions apps/backend/components/collections/agent_new/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ def get_agent_upgrade_pkg_name(cls, host: models.Host) -> str:
:return:
"""
package_type = ("client", "proxy")[host.node_type == constants.NodeType.PROXY]
if host.bk_agent_id:
# 保证升级到 stable 稳定的版本
return f"gse_{package_type}-stable.tgz"
if host.os_version:
major_version_number = None
if host.os_type == constants.OsType.AIX:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,19 @@ class PushUpgradeFileService(AgentTransferFileService):
def get_file_target_path(self, data, common_data: AgentCommonData, host: models.Host) -> str:
return common_data.host_id__ap_map[host.bk_host_id].get_agent_config(host.os_type)["temp_path"]

def get_file_list(self, data, common_data: AgentCommonData, host: models.Host) -> List[str]:

def get_upgrade_package_source_path(self, common_data: AgentCommonData, host: models.Host):
"""
获取升级包源路径
"""
# 1.x 升级到 1.x,使用老到路径,升级包直接放在 download 目录下
download_path = common_data.host_id__ap_map[host.bk_host_id].nginx_path or settings.DOWNLOAD_PATH
if host.bk_agent_id:
# 2.x 升级到 2.x,根据操作系统、CPU 架构等组合路径
download_path = os.path.join(download_path, "agent", host.os_type.lower(), host.cpu_arch.lower())
return download_path

def get_file_list(self, data, common_data: AgentCommonData, host: models.Host) -> List[str]:
download_path = self.get_upgrade_package_source_path(common_data, host)
agent_upgrade_package_name = self.get_agent_upgrade_pkg_name(host=host)

file_names: List[str] = [agent_upgrade_package_name]
Expand Down
4 changes: 3 additions & 1 deletion apps/backend/subscription/steps/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ def _generate_activities(self, agent_manager: AgentManager):

class UpgradeAgent(ReinstallAgent):
"""
升级Agent
升级Agent,仅适用于 1.x 升级到 1.x 或 2.x 升级到 2.x ,不支持 1.x 升级到 2.x 的场景
1.x 升级到 2.x 到场景,使用 InstallAgent2 覆盖安装
TODO 2.x 升级到 2.x 的场景暂时沿用替换二进制后 reload 的方案,待 GSE 提供自升级方案后再调整
"""

ACTION_NAME = backend_const.ActionNameType.UPGRADE_AGENT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from abc import ABC

from django.conf import settings
from django.utils.crypto import get_random_string

from apps.backend.components.collections.agent_new import components
from apps.node_man import constants, models
Expand Down Expand Up @@ -39,6 +40,29 @@ def tearDown(self) -> None:
super().tearDown()


class PushUpgradePackageV2TestCase(base.JobBaseTestCase):
@classmethod
def get_default_case_name(cls) -> str:
return "下发 Linux 升级包 2.0 成功"

@classmethod
def setUpTestData(cls):
super().setUpTestData()
models.Host.objects.filter(bk_host_id__in=cls.obj_factory.bk_host_ids).update(bk_agent_id=get_random_string())

def component_cls(self):
return components.PushUpgradePackageComponent

def tearDown(self) -> None:
record = self.job_api_mock_client.call_recorder.record
fast_transfer_file_query_params = record[JobApi.fast_transfer_file][0].args[0]
self.assertEqual(
fast_transfer_file_query_params["file_source_list"][0]["file_list"],
[os.path.join(settings.DOWNLOAD_PATH, "agent/linux/x86_64/gse_client-stable.tgz")],
)
super().tearDown()


class PushAixUpgradePackageSuccessTestCase(base.JobBaseTestCase):
@classmethod
def get_default_case_name(cls) -> str:
Expand Down

0 comments on commit 627c199

Please sign in to comment.