From 53381c640688c444b5fe9b1db7e75a474da0f1f8 Mon Sep 17 00:00:00 2001 From: cc <18856836718@163.com> Date: Tue, 19 Mar 2024 22:05:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9C=AC=E6=9C=BA=E5=8D=B8?= =?UTF-8?q?=E8=BD=BD=E9=95=9C=E5=83=8F=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/OpenEulerMirrorISO/install.sh | 1 + component/OpenEulerMirrorISO/uninstall.sh | 3 +- .../src/machine/local_machine.py | 32 +++++++++++++------ .../install_dependency/src/machine/machine.py | 4 +-- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/component/OpenEulerMirrorISO/install.sh b/component/OpenEulerMirrorISO/install.sh index 4d9189c..85912fa 100644 --- a/component/OpenEulerMirrorISO/install.sh +++ b/component/OpenEulerMirrorISO/install.sh @@ -24,6 +24,7 @@ enabled=1 gpgcheck=0 EOF yum clean all + echo "yum makecache: " yum makecache } diff --git a/component/OpenEulerMirrorISO/uninstall.sh b/component/OpenEulerMirrorISO/uninstall.sh index 43233d1..b2e4c39 100644 --- a/component/OpenEulerMirrorISO/uninstall.sh +++ b/component/OpenEulerMirrorISO/uninstall.sh @@ -6,12 +6,11 @@ function resume_original_mirror() { rm -rf /etc/yum.repos.d/yum.repos.backup yum clean all + echo "yum makecache: " yum makecache } function main() { - iso_file_path=$1 - rm -rf "${iso_file_path}" umount /devkitmirror rm -rf /devkitmirror diff --git a/tools/install_dependency/src/machine/local_machine.py b/tools/install_dependency/src/machine/local_machine.py index 8bb1ccf..f61ef15 100644 --- a/tools/install_dependency/src/machine/local_machine.py +++ b/tools/install_dependency/src/machine/local_machine.py @@ -7,7 +7,8 @@ from command_line import CommandLine from exception.connect_exception import NotMatchedMachineTypeException from download import component_collection_map from lkp_collect_map import lkp_collection_map -from utils import base_path +from utils import (base_path, MKDIR_TMP_DEVKITDEPENDENCIES_CMD, YUM_INSTALL_LKP_DEPENDENCIES_CMD, + CHECK_MIRROR_INSTALL_STATUS, PROMPT_MAP) LOGGER = logging.getLogger("install_dependency") SHELL_FILE_LIST = ["install.sh", "check_install_result.sh"] @@ -39,13 +40,13 @@ class LocalMachine: "BiShengJDK8": self.default_install_component_handle, "LkpTests": self.lkptest_install_component_handle, "OpenEulerMirrorISO": self.deploy_iso_handle, - "UnOpenEulerMirrorISO": self.undeploy_iso_handle(), + "UnOpenEulerMirrorISO": self.undeploy_iso_handle, } return component_name_to_func_dict.get(component_name)(component_name) def lkptest_install_component_handle(self, component_name): - self._local_exec_command(f"mkdir -p /tmp/{constant.DEPENDENCY_DIR}") - self._local_exec_command(f"yum install -y git wget rubygems") + self._local_exec_command(MKDIR_TMP_DEVKITDEPENDENCIES_CMD) + self._local_exec_command(YUM_INSTALL_LKP_DEPENDENCIES_CMD) # 复制 tar.gz 文件 LOGGER.info(f"Install component in local machine {self.ip}: {component_name}") @@ -145,7 +146,7 @@ class LocalMachine: LOGGER.info(f"Remote machine {self.ip} deploy {component_name} failed.") def default_install_component_handle(self, component_name): - self._local_exec_command(f"mkdir -p /tmp/{constant.DEPENDENCY_DIR}") + self._local_exec_command(MKDIR_TMP_DEVKITDEPENDENCIES_CMD) # 上传 组件压缩包和校验文件 LOGGER.info(f"Install component in local machine {self.ip}: {component_name}") @@ -185,10 +186,10 @@ class LocalMachine: result = subprocess.run(cmd.split(' '), capture_output=False, shell=False, stderr=subprocess.STDOUT) if result.returncode == 0: - LOGGER.debug(f"Local machine {self.ip} exec '{cmd}' result: success") + LOGGER.debug(f"Local machine {self.ip} exec '{cmd}' success.") else: - LOGGER.error(f"Local machine {self.ip} exec '{cmd}' result: failed") - raise OSError(f"Local machine {self.ip} exec '{cmd}' failed.") + LOGGER.error(f"Local machine {self.ip} exec '{cmd}' failed.") + raise OSError(PROMPT_MAP.get(cmd, f"Local machine {self.ip} exec '{cmd}' failed.")) def transport_shell_file_and_execute(self, sh_file_local_path, sh_file_remote_path, sh_cmd): if not os.path.exists(sh_file_local_path): @@ -218,7 +219,20 @@ class LocalMachine: def undeploy_iso_handle(self, component_name): # 需要检查本地镜像是否安装成功 - self._local_exec_command("test -d /etc/yum.repos.d/yum.repos.backup") + self._local_exec_command(CHECK_MIRROR_INSTALL_STATUS) component_name = component_name.replace("Un", "") + LOGGER.info(f"Umount component in local machine {self.ip}: {component_name}") + # 执行 卸载脚本 + for shell_file in ["uninstall.sh"]: + sh_file_local_path = os.path.join(base_path("component"), component_name, shell_file) + sh_cmd = f"bash {sh_file_local_path}" + if not os.path.exists(sh_file_local_path): + LOGGER.error(f"{sh_file_local_path} not exists.") + raise FileNotFoundError(f"local file {sh_file_local_path} not exists.") + + result = subprocess.run(f"{sh_cmd}".split(' '), + capture_output=True, shell=False) + output = result.stdout.decode().strip() + LOGGER.info(f"Local machine {self.ip} exec '{sh_cmd}' output: {output}") diff --git a/tools/install_dependency/src/machine/machine.py b/tools/install_dependency/src/machine/machine.py index ebc14d4..f8b8f7d 100644 --- a/tools/install_dependency/src/machine/machine.py +++ b/tools/install_dependency/src/machine/machine.py @@ -315,7 +315,6 @@ class Machine: self._remote_exec_command(CHECK_MIRROR_INSTALL_STATUS, ssh_client) component_name = component_name.replace("Un", "") - LOGGER.info(f"Umount component in remote machine {self.ip}: {component_name}") local_path = os.path.abspath(CommandLine.iso_path) remote_path = os.path.join("/home", local_path.split('/')[-1]) @@ -325,7 +324,7 @@ class Machine: for shell_file in ["uninstall.sh"]: sh_file_local_path = os.path.join(base_path("component"), component_name, shell_file) sh_file_remote_path = os.path.join("/tmp/", component_name + shell_file) - sh_cmd = f"bash {sh_file_remote_path} {remote_path}" + sh_cmd = f"bash {sh_file_remote_path}" execute_output = ( self.transport_shell_file_and_execute( ssh_client, sftp_client, @@ -334,5 +333,6 @@ class Machine: sh_cmd=sh_cmd )) remote_file_list.append(sh_file_remote_path) + remote_file_list.append(remote_path) # 清理tmp临时文件 self.clear_tmp_file_at_remote_machine(ssh_client, remote_file_list) -- Gitee