From 08131840bf6f745463f7c791acbd0a0012192864 Mon Sep 17 00:00:00 2001 From: dcd <1151627903@qq.com> Date: Fri, 8 Nov 2024 16:52:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DWindows=E4=B8=8B?= =?UTF-8?q?=E8=A7=A3=E5=8E=8B=E6=8F=92=E4=BB=B6=E8=BF=9B=E7=A8=8B=E5=8D=A0?= =?UTF-8?q?=E7=94=A8=E9=97=AE=E9=A2=98=20(closed=20#2486)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/backend/components/collections/plugin.py | 5 +++ .../plugin/test_install_package.py | 31 +++++++++++++++++++ script_tools/plugin_scripts/update_binary.bat | 10 +++++- 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/apps/backend/components/collections/plugin.py b/apps/backend/components/collections/plugin.py index d87312bd2..0167e4f96 100644 --- a/apps/backend/components/collections/plugin.py +++ b/apps/backend/components/collections/plugin.py @@ -723,6 +723,11 @@ def generate_script_params_by_process_status( if category == constants.CategoryType.external and group_id: # 设置插件实例目录 script_param += " -i %s" % group_id + host = self.get_host_by_process_status(process_status, common_data) + if host.os_type == constants.OsType.WINDOWS: + # 设置Windows临时解压目录 + temp_sub_unpack_dir: str = "{}\\{}".format(agent_config["temp_path"], group_id) + script_param += " -u %s" % temp_sub_unpack_dir return script_param diff --git a/apps/backend/tests/components/collections/plugin/test_install_package.py b/apps/backend/tests/components/collections/plugin/test_install_package.py index 9e923acd3..94e011b19 100644 --- a/apps/backend/tests/components/collections/plugin/test_install_package.py +++ b/apps/backend/tests/components/collections/plugin/test_install_package.py @@ -8,12 +8,15 @@ 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 copy import deepcopy from unittest.mock import patch from django.test import TestCase +from apps.backend.api.job import process_parms from apps.backend.components.collections.plugin import InstallPackageComponent from apps.backend.tests.components.collections.plugin import utils +from apps.node_man import constants, models from pipeline.component_framework.test import ( ComponentTestCase, ComponentTestMixin, @@ -83,3 +86,31 @@ def cases(self): execute_call_assertion=None, ) ] + + +class TestInstallPackageUnpackTempDir(InstallPackageTest): + def setUp(self): + super().setUp() + models.Host.objects.all().update(os_type=constants.OsType.WINDOWS) + windows_package_info = deepcopy(utils.PKG_INFO) + windows_package_info["os"] = "windows" + models.Packages.objects.create(**windows_package_info) + + config = {"details": [windows_package_info]} + models.SubscriptionStep.objects.filter(id=self.ids["subscription_step_id"]).update(config=config) + + def test_component(self): + with patch( + "apps.backend.tests.components.collections.plugin.utils.JobMockClient.fast_execute_script" + ) as fast_execute_script: + fast_execute_script.return_value = { + "job_instance_name": "API Quick execution script1521100521303", + "job_instance_id": utils.JOB_INSTANCE_ID, + } + super().test_component() + group_id = models.ProcessStatus.objects.filter(bk_host_id=self.ids["bk_host_id"]).first().group_id + process_params = process_parms( + f"-t official -p c:\\gse -n gseagent -f basereport-10.8.50.tgz -m OVERRIDE " + f"-z C:\\tmp -u C:\\tmp\\{group_id}" + ) + self.assertEqual(fast_execute_script.call_args[0][0]["script_param"], process_params) diff --git a/script_tools/plugin_scripts/update_binary.bat b/script_tools/plugin_scripts/update_binary.bat index 83c326e6e..71984010e 100644 --- a/script_tools/plugin_scripts/update_binary.bat +++ b/script_tools/plugin_scripts/update_binary.bat @@ -35,6 +35,10 @@ IF NOT "%1"=="" ( SET GROUP_DIR=%2 SHIFT ) + IF "%1"=="-u" ( + SET TEMP_SUB_UNPACK_DIR=%2 + SHIFT + ) SHIFT GOTO :loop ) @@ -119,7 +123,11 @@ rem 解压配置到目标路径 :unzip_config echo "coming into %SWWIN_GSE_HOME%" cd %SWWIN_GSE_HOME% -%s7zPath%\7z.exe x -aoa %SWWIN_TMP%\%SWWIN_PACKAGE% -o%SWWIN_GSE_HOME% +echo "copy package into temp_sub_unpack_dir: %TEMP_SUB_UNPACK_DIR%" +xcopy %SWWIN_TMP%\%SWWIN_PACKAGE% %TEMP_SUB_UNPACK_DIR%\ /I /Y +%s7zPath%\7z.exe x -aoa %TEMP_SUB_UNPACK_DIR%\%SWWIN_PACKAGE% -o%SWWIN_GSE_HOME% +echo "unpack package into %SWWIN_GSE_HOME% from dir %TEMP_SUB_UNPACK_DIR%" +rd /S /Q %TEMP_SUB_UNPACK_DIR% if exist %SWWIN_PACKAGE:~0,-4%.tar ( set TAR_FILE_NAME=%SWWIN_PACKAGE:~0,-4%.tar ) else if exist %SWWIN_PACKAGE:~0,-4%.tgz (