Skip to content

Commit

Permalink
fix: 修复Windows下解压插件进程占用问题 (closed #2486)
Browse files Browse the repository at this point in the history
  • Loading branch information
Huayeaaa committed Nov 8, 2024
1 parent f14f01b commit 0813184
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
5 changes: 5 additions & 0 deletions apps/backend/components/collections/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
10 changes: 9 additions & 1 deletion script_tools/plugin_scripts/update_binary.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit 0813184

Please sign in to comment.