From 669ea69aacdfeae507de606d33f414fff0723d11 Mon Sep 17 00:00:00 2001 From: cc <18856836718@163.com> Date: Sun, 17 Mar 2024 21:45:00 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3yum=20install=20=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../install_dependency/src/machine/machine.py | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/tools/install_dependency/src/machine/machine.py b/tools/install_dependency/src/machine/machine.py index 8868df9..b7eeba5 100644 --- a/tools/install_dependency/src/machine/machine.py +++ b/tools/install_dependency/src/machine/machine.py @@ -92,7 +92,8 @@ class Machine: sftp_client = self.sftp_client() try: self.install_component_handler(component_name, sftp_client, ssh_client) - except (FileNotFoundError, PermissionError, NotADirectoryError, OSError, IOError) as e: + except (FileNotFoundError, PermissionError, NotADirectoryError, OSError, IOError, + timeout_decorator.TimeoutError) as e: LOGGER.error(f"Remote machine {self.ip} occur Error: {str(e)}") finally: ssh_client.close() @@ -111,19 +112,8 @@ class Machine: return component_name_to_func_dict.get(component_name)(component_name, sftp_client, ssh_client) def lkptest_install_component_handle(self, component_name, sftp_client, ssh_client): - try: - stdin, stdout, stderr = ssh_client.exec_command(f"mkdir -p /tmp/{constant.DEPENDENCY_DIR}", timeout=10) - stdin, stdout, stderr = ssh_client.exec_command(f"yum install -y git wget rubygems", timeout=100) - except (paramiko.ssh_exception.SSHException, socket.timeout) as e: - LOGGER.error(f"yum install -y git wget rubygems failed plz run this command to install") - LOGGER.info(f"Remote machine {self.ip} install {component_name} failed.") - raise ConnectRemoteException() - exit_status = stdout.channel.recv_exit_status() - LOGGER.debug(f"Remote machine {self.ip} mkdir -p /tmp/{constant.DEPENDENCY_DIR} result: " - f"{'success' if not exit_status else 'failed'}") - if exit_status: - raise NotADirectoryError(f"Remote machine {self.ip} " - f"directory {os.path.join('/tmp/', constant.DEPENDENCY_DIR)} not exist.") + cmd = "yum install -y git wget rubygems" + self._remote_exec_command(cmd, component_name, ssh_client) # 上传 lkp-tests.tar.gz文件 LOGGER.info(f"Install component in remote machine {self.ip}: {component_name}") @@ -288,6 +278,21 @@ class Machine: # 清理tmp临时文件 self.clear_tmp_file_at_remote_machine(ssh_client, remote_file_list) + @timeout_decorator.timeout(100) + def _remote_exec_command(self, cmd, component_name, ssh_client): + try: + stdin, stdout, stderr = ssh_client.exec_command(cmd, timeout=80) + except (paramiko.ssh_exception.SSHException, socket.timeout) as e: + LOGGER.error(f"Remote machine {self.ip} exec '{cmd}' failed Please run this command.") + LOGGER.error(f"Remote machine {self.ip} install {component_name} failed.") + raise OSError(f"Remote machine {self.ip} exec '{cmd}' failed Please run this command.") + 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.") + raise OSError(f"Remote machine {self.ip} exec '{cmd}' failed Please run this command.") + def transport_shell_file_and_execute(self, ssh_client, sftp_client, sh_file_local_path, sh_file_remote_path, sh_cmd): if not os.path.exists(sh_file_local_path): -- Gitee