diff --git a/tools/install_dependency/src/handler/install_package.py b/tools/install_dependency/src/handler/install_package.py index d3e42e39b237a82fbed7890121789f2742ddd736..e0629a08b3807fcedde096433ac261932bd1cc37 100644 --- a/tools/install_dependency/src/handler/install_package.py +++ b/tools/install_dependency/src/handler/install_package.py @@ -32,7 +32,7 @@ class InstallPackage(Handler): for role in ({constant.EXECUTOR, constant.DEVKIT} & set(data.keys())): machine_dict = data[role + constant.MACHINE] - LOGGER.debug(f"{role} machine list: {list(machine_dict.keys())}") + LOGGER.debug(f"{role} machine list to deploy iso: {list(machine_dict.keys())}") for machine_ip in machine_dict: if machine_ip in ip_set: continue @@ -64,7 +64,7 @@ class InstallPackage(Handler): if machine_ip in ip_set: continue ip_set.add(machine_ip) - LOGGER.debug(f"ip_set: {ip_set}") + LOGGER.debug(f"ip_set to install package: {ip_set}") machine = machine_dict.get(machine_ip) process = multiprocessing.Process( target=process_work, @@ -86,18 +86,28 @@ class InstallPackage(Handler): @staticmethod def undeploy_iso_handle(data): ip_set = set() + jobs = [] for role in ({constant.EXECUTOR, constant.DEVKIT} & set(data.keys())): machine_dict = data[role + constant.MACHINE] - + LOGGER.debug(f"{role} machine list to un-deploy iso: {list(machine_dict.keys())}") for machine_ip in machine_dict: if machine_ip in ip_set: continue ip_set.add(machine_ip) LOGGER.debug(f"ip_set to un-deploy iso: {ip_set}") machine = machine_dict.get(machine_ip) - machine.undeploy_iso_work() - LOGGER.debug(f"Resume original mirror in machine: {machine_ip} ") + process = multiprocessing.Process( + target=process_work, + args=(machine, + "UnOpenEulerMirrorISO", + ), + ) + jobs.append(process) + process.start() + + for job in jobs: + job.join() def process_work(machine, *components: str): diff --git a/tools/install_dependency/src/machine/builder_machine.py b/tools/install_dependency/src/machine/builder_machine.py index 3320be3152c9ca891f7f388b446cb339a9d5d68c..2f6559063bb5c4dd36f0840ea2c214fcbfee199e 100644 --- a/tools/install_dependency/src/machine/builder_machine.py +++ b/tools/install_dependency/src/machine/builder_machine.py @@ -15,5 +15,6 @@ class BuilderMachine(Machine): "BiShengJDK8": self.default_install_component_handle, "LkpTests": self.do_nothing, "OpenEulerMirrorISO": self.do_nothing, + "UnOpenEulerMirrorISO": self.do_nothing, } return component_name_to_func_dict.get(component_name)(component_name, sftp_client, ssh_client) \ No newline at end of file diff --git a/tools/install_dependency/src/machine/devkit_machine.py b/tools/install_dependency/src/machine/devkit_machine.py index 4c3201e981e72e404b7169b9abe03e2343480aa4..aac52f93073e175b9d73995f2b6e97bcf48ccef3 100644 --- a/tools/install_dependency/src/machine/devkit_machine.py +++ b/tools/install_dependency/src/machine/devkit_machine.py @@ -15,5 +15,6 @@ class DevkitMachine(Machine): "BiShengJDK8": self.default_install_component_handle, "LkpTests": self.do_nothing, "OpenEulerMirrorISO": self.deploy_iso_handle, + "UnOpenEulerMirrorISO": self.undeploy_iso_handle, } return component_name_to_func_dict.get(component_name)(component_name, sftp_client, ssh_client) diff --git a/tools/install_dependency/src/machine/executor_machine.py b/tools/install_dependency/src/machine/executor_machine.py index b3f9cbdd007bdd67ba0e1dae2797aee7d45f97f9..52f7ad965f88f2e4d16a069e5e3af8235b9bc485 100644 --- a/tools/install_dependency/src/machine/executor_machine.py +++ b/tools/install_dependency/src/machine/executor_machine.py @@ -15,5 +15,6 @@ class ExecutorMachine(Machine): "BiShengJDK8": self.default_install_component_handle, "LkpTests": self.lkptest_install_component_handle, "OpenEulerMirrorISO": self.deploy_iso_handle, + "UnOpenEulerMirrorISO": self.undeploy_iso_handle, } return component_name_to_func_dict.get(component_name)(component_name, sftp_client, ssh_client) diff --git a/tools/install_dependency/src/machine/local_machine.py b/tools/install_dependency/src/machine/local_machine.py index ec7408d25ff66660749692e43ba520a55b9a1080..8bb1ccf3a1a1078009d6cac4f5ab212f97fe1737 100644 --- a/tools/install_dependency/src/machine/local_machine.py +++ b/tools/install_dependency/src/machine/local_machine.py @@ -39,6 +39,7 @@ class LocalMachine: "BiShengJDK8": self.default_install_component_handle, "LkpTests": self.lkptest_install_component_handle, "OpenEulerMirrorISO": self.deploy_iso_handle, + "UnOpenEulerMirrorISO": self.undeploy_iso_handle(), } return component_name_to_func_dict.get(component_name)(component_name) @@ -215,5 +216,9 @@ class LocalMachine: def do_nothing(self, component_name, sftp_client, ssh_client): return - def undeploy_iso_work(self): - return + def undeploy_iso_handle(self, component_name): + # 需要检查本地镜像是否安装成功 + self._local_exec_command("test -d /etc/yum.repos.d/yum.repos.backup") + + component_name = component_name.replace("Un", "") + diff --git a/tools/install_dependency/src/machine/machine.py b/tools/install_dependency/src/machine/machine.py index 0a3cb64c89fd4e2f92fffb637e0b1828f3147136..ebc14d4f0962d8c79e84444f794ca9b54cec3ecf 100644 --- a/tools/install_dependency/src/machine/machine.py +++ b/tools/install_dependency/src/machine/machine.py @@ -13,7 +13,8 @@ from exception.connect_exception import CreatePkeyFailedException, ConnectRemote from download import component_collection_map from lkp_collect_map import lkp_collection_map from utils import (base_path, MKDIR_TMP_DEVKITDEPENDENCIES_CMD, YUM_INSTALL_LKP_DEPENDENCIES_CMD, - CHECK_HOME_SPACE_SUFFICIENT_FOR_MIRROR, CHECK_TMP_SPACE_SUFFICIENT_FOR_PACKAGE, PROMPT_MAP) + CHECK_HOME_SPACE_SUFFICIENT_FOR_MIRROR, CHECK_TMP_SPACE_SUFFICIENT_FOR_PACKAGE, + CHECK_MIRROR_INSTALL_STATUS, PROMPT_MAP) LOGGER = logging.getLogger("install_dependency") SHELL_FILE_LIST = ["install.sh", "check_install_result.sh"] @@ -110,6 +111,7 @@ class Machine: "BiShengJDK8": self.default_install_component_handle, "LkpTests": self.lkptest_install_component_handle, "OpenEulerMirrorISO": self.deploy_iso_handle, + "UnOpenEulerMirrorISO": self.undeploy_iso_handle, } return component_name_to_func_dict.get(component_name)(component_name, sftp_client, ssh_client) @@ -275,13 +277,13 @@ class Machine: try: stdin, stdout, stderr = ssh_client.exec_command(cmd, timeout=90) except (paramiko.ssh_exception.SSHException, socket.timeout) as e: - LOGGER.error(f"Remote machine {self.ip} exec '{cmd}' failed Please run this command in remote machine.") + LOGGER.error(f"Remote machine {self.ip} exec '{cmd}' failed Please run this command in this machine.") raise OSError(PROMPT_MAP.get(cmd, f"Remote machine {self.ip} exec '{cmd}' failed.")) exit_status = stdout.channel.recv_exit_status() - LOGGER.debug(f"Remote machine {self.ip} exec '{cmd}' result: " - f"{'success' if not exit_status else 'failed'}") - if exit_status: - LOGGER.error(f"Remote machine {self.ip} exec '{cmd}' failed Please run this command in remote machine.") + if exit_status == 0: + LOGGER.debug(f"Remote machine {self.ip} exec '{cmd}' success.") + else: + LOGGER.error(f"Remote machine {self.ip} exec '{cmd}' failed. Please run this command in this machine.") raise OSError(PROMPT_MAP.get(cmd, f"Remote machine {self.ip} exec '{cmd}' failed.")) def transport_shell_file_and_execute(self, ssh_client, sftp_client, sh_file_local_path, sh_file_remote_path, @@ -308,5 +310,29 @@ class Machine: def do_nothing(self, component_name, sftp_client, ssh_client): return - def undeploy_iso_work(self): - return + def undeploy_iso_handle(self, component_name, sftp_client, ssh_client): + # 需要检查本地镜像是否安装成功 + 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]) + + # 上传并执行 卸载脚本 + remote_file_list = [] + 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}" + execute_output = ( + self.transport_shell_file_and_execute( + ssh_client, sftp_client, + sh_file_local_path=sh_file_local_path, + sh_file_remote_path=sh_file_remote_path, + sh_cmd=sh_cmd + )) + remote_file_list.append(sh_file_remote_path) + # 清理tmp临时文件 + self.clear_tmp_file_at_remote_machine(ssh_client, remote_file_list) diff --git a/tools/install_dependency/src/machine/scanner_machine.py b/tools/install_dependency/src/machine/scanner_machine.py index 8a993b8d64511ac26f5b3a144ba23ebb0e02fce5..92903e87a16e0dceebedea5d3c27143593e7eec8 100644 --- a/tools/install_dependency/src/machine/scanner_machine.py +++ b/tools/install_dependency/src/machine/scanner_machine.py @@ -15,5 +15,6 @@ class ScannerMachine(Machine): "BiShengJDK8": self.default_install_component_handle, "LkpTests": self.do_nothing, "OpenEulerMirrorISO": self.do_nothing, + "UnOpenEulerMirrorISO": self.do_nothing, } return component_name_to_func_dict.get(component_name)(component_name, sftp_client, ssh_client) \ No newline at end of file diff --git a/tools/install_dependency/src/utils.py b/tools/install_dependency/src/utils.py index 5e631fa9a444c4c609bb68c42926c55dc8d9fd88..848aa9eec7bff2ecf5c740d36808303ff7406558 100644 --- a/tools/install_dependency/src/utils.py +++ b/tools/install_dependency/src/utils.py @@ -5,12 +5,14 @@ MKDIR_TMP_DEVKITDEPENDENCIES_CMD = "mkdir -p /tmp/devkitdependencies" YUM_INSTALL_LKP_DEPENDENCIES_CMD = "yum install -y git wget rubygems" CHECK_HOME_SPACE_SUFFICIENT_FOR_MIRROR = "[[ $(df -m /home | awk 'NR==2' | awk '{print $4}') -gt 17*1024 ]]" CHECK_TMP_SPACE_SUFFICIENT_FOR_PACKAGE = "[[ $(df -m /tmp | awk 'NR==2' | awk '{print $4}') -gt 1024 ]]" +CHECK_MIRROR_INSTALL_STATUS = "test -d /etc/yum.repos.d/yum.repos.backup" PROMPT_MAP = { MKDIR_TMP_DEVKITDEPENDENCIES_CMD: "Directory /tmp/devkitdependencies not exists.", YUM_INSTALL_LKP_DEPENDENCIES_CMD: "Yum install dependencies failed.", CHECK_HOME_SPACE_SUFFICIENT_FOR_MIRROR: "Machine /home space not sufficient for mirror.", CHECK_TMP_SPACE_SUFFICIENT_FOR_PACKAGE: "Machine /tmp space not sufficient for package.", + CHECK_MIRROR_INSTALL_STATUS: "Mirror mount status not correct." }