From 2821b5affae2a6d537eab797aebd55413c39db48 Mon Sep 17 00:00:00 2001 From: cc <18856836718@163.com> Date: Sun, 31 Mar 2024 12:51:16 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9DevKitWeb=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E5=99=A8=EF=BC=8C=E9=BB=98=E8=AE=A4=E5=AE=89=E8=A3=85?= =?UTF-8?q?24.0.RC1=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devkit_installer/devkit_installer.py | 6 +++--- .../devkit_installer/devkit_machine.py | 20 +++++++++---------- .../installer_command_line.py | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/component/DevKitWeb/devkit_installer/devkit_installer.py b/component/DevKitWeb/devkit_installer/devkit_installer.py index 06036dd..71d3963 100644 --- a/component/DevKitWeb/devkit_installer/devkit_installer.py +++ b/component/DevKitWeb/devkit_installer/devkit_installer.py @@ -30,7 +30,7 @@ class DevKitInstaller: ) if not decompress_result: LOGGER.error("Decompress package failed.") - exit(1) + sys.exit(1) LOGGER.info("Decompress package success.") def install_java_perf(self): @@ -42,14 +42,14 @@ class DevKitInstaller: rpc_port=50051) if not install_result: LOGGER.error(f"Install DevKit failed.") - exit(1) + sys.exit(1) LOGGER.info(f"Install DevKit success.") def set_up_password(self): # 初始化管理员密码 result_dict = self.user_manage.first_login(username=self.admin_username, password=self.admin_password) if not result_dict: - exit(1) + sys.exit(1) LOGGER.info("DevKitInstaller executive success.") diff --git a/component/DevKitWeb/devkit_installer/devkit_machine.py b/component/DevKitWeb/devkit_installer/devkit_machine.py index c8000de..58b7cb6 100644 --- a/component/DevKitWeb/devkit_installer/devkit_machine.py +++ b/component/DevKitWeb/devkit_installer/devkit_machine.py @@ -110,7 +110,7 @@ class DevKitMachine: else: plugin_param = f"--plugin={plugin}" - cmd = (f"cd {self.install_dir} && yes | head -1 | sudo bash {self.install_file} {plugin_param} -d={install_path} " + cmd = (f"cd {self.install_dir} && sudo bash {self.install_file} {plugin_param} -d={install_path} " f"--ip={server_ip} --map_ip={server_ip} -p={server_port} --http_port={http_port} " f"--rpc_ip={server_ip} --rpc_port={rpc_port} --normal-install=1") LOGGER.info(f"cmd: {cmd}") @@ -123,39 +123,37 @@ class DevKitMachine: if not ssh_client: return False channel = DevKitMachine.channel_create(ssh_client) - result = self.channel_send_cmd(chan=channel, cmd=cmd, special_end=special_end, + result = self.channel_send_cmd(channel=channel, cmd=cmd, special_end=special_end, error_special_end=[environment_check], timeout=300) if not result or environment_check in result: # 授权工具处理环境检查失败项 - result = self.channel_send_cmd(chan=channel, cmd="y\n", special_end=special_end, timeout=240) + result = self.channel_send_cmd(channel=channel, cmd="y\n", special_end=special_end, timeout=240) if special_end in result: ssh_client.close() return True ssh_client.close() return False - def channel_send_cmd(self, chan, cmd, special_end="", error_special_end=None, timeout=60): + def channel_send_cmd(self, channel, cmd, special_end="", error_special_end=None, timeout=60): if error_special_end is None: error_special_end = [] try: - chan.settimeout(timeout) + channel.settimeout(timeout) if not cmd.endswith('\n'): cmd = cmd + '\n' - chan.send(cmd) + channel.send(cmd) while True: - time.sleep(5) - buff = chan.recv(65535) + buff = channel.recv(65535) buff_decode = buff.decode("utf8", errors='ignore') + LOGGER.debug(buff_decode) if special_end in buff_decode: break for error_end in error_special_end: if error_end in buff_decode: break - result = buff.decode("utf8", errors="ignore") - LOGGER.info("result: {}".format(result.split('\n')[-2])) - return result + return buff_decode except Exception as e: LOGGER.info(f"Exec '{cmd}' error occurs: {str(e)}") return "" diff --git a/component/DevKitWeb/devkit_installer/installer_command_line.py b/component/DevKitWeb/devkit_installer/installer_command_line.py index 0c73f93..9ea38bc 100644 --- a/component/DevKitWeb/devkit_installer/installer_command_line.py +++ b/component/DevKitWeb/devkit_installer/installer_command_line.py @@ -1,6 +1,6 @@ import argparse -PACKAGE_NAME = "DevKit-All-23.0.T30-Linux-Kunpeng.tar.gz" +PACKAGE_NAME = "DevKit-All-24.0.RC1-Linux-Kunpeng.tar.gz" class CommandLine: -- Gitee From 5617c8dfed6726016801df961f99ecb4b5951ed2 Mon Sep 17 00:00:00 2001 From: cc <18856836718@163.com> Date: Sun, 31 Mar 2024 16:22:03 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=80=82=E9=85=8D=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E7=9A=84devkitweb=20=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devkit_installer/devkit_machine.py | 36 ++++++++++--------- .../install_dependency/src/machine/machine.py | 14 ++++---- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/component/DevKitWeb/devkit_installer/devkit_machine.py b/component/DevKitWeb/devkit_installer/devkit_machine.py index 58b7cb6..fb477a0 100644 --- a/component/DevKitWeb/devkit_installer/devkit_machine.py +++ b/component/DevKitWeb/devkit_installer/devkit_machine.py @@ -118,25 +118,29 @@ class DevKitMachine: special_end = f"https://{server_ip}:{server_port}" environment_check = ("Do you want to " "authorize the tool to handle the items failed in the installation environment check") + continue_statement = "Do you want to continue?" + use_statement = "do you want to use it?" + error_special_end = "you want to" ssh_client = self.ssh_client() if not ssh_client: return False channel = DevKitMachine.channel_create(ssh_client) result = self.channel_send_cmd(channel=channel, cmd=cmd, special_end=special_end, - error_special_end=[environment_check], timeout=300) - if not result or environment_check in result: - # 授权工具处理环境检查失败项 - result = self.channel_send_cmd(channel=channel, cmd="y\n", special_end=special_end, timeout=240) - if special_end in result: + error_special_end=error_special_end, timeout=300) + + while result.find(error_special_end) != -1: + # 授权工具安装继续运行 + result = self.channel_send_cmd(channel=channel, cmd="y\n", special_end=special_end, + error_special_end=error_special_end, timeout=300) + if result.find(special_end) != -1: ssh_client.close() return True ssh_client.close() return False - def channel_send_cmd(self, channel, cmd, special_end="", error_special_end=None, timeout=60): - if error_special_end is None: - error_special_end = [] + def channel_send_cmd(self, channel, cmd, special_end, error_special_end, timeout=60): + buff_decode = "" try: channel.settimeout(timeout) if not cmd.endswith('\n'): @@ -145,16 +149,14 @@ class DevKitMachine: while True: buff = channel.recv(65535) - buff_decode = buff.decode("utf8", errors='ignore') - LOGGER.debug(buff_decode) - if special_end in buff_decode: + buff_decode = str(buff.decode("utf8", errors='ignore')) + LOGGER.debug(buff_decode.replace("\n", "")) + if buff_decode.find(special_end) != -1: + break + if buff_decode.find(error_special_end) != -1: break - for error_end in error_special_end: - if error_end in buff_decode: - break + LOGGER.debug(f"process_result: {buff_decode}") - return buff_decode except Exception as e: LOGGER.info(f"Exec '{cmd}' error occurs: {str(e)}") - return "" - + return buff_decode diff --git a/tools/install_dependency/src/machine/machine.py b/tools/install_dependency/src/machine/machine.py index 7162a10..ad3ae0f 100644 --- a/tools/install_dependency/src/machine/machine.py +++ b/tools/install_dependency/src/machine/machine.py @@ -1,6 +1,7 @@ import logging import os import socket +import subprocess import typing import paramiko @@ -160,14 +161,11 @@ class Machine: remote_file_list.append(remote_file) sftp_client.put(localpath=f"{local_file}", remotepath=f"{remote_file}") - stdin, stdout, stderr = ssh_client.exec_command( - f"{os.path.join(base_path('component'), component_name, 'devkit_installer')} " - f"-i {self.ip} -u {self.user} -p {self.pkey}") - exit_status = stdout.channel.recv_exit_status() - if exit_status == 0: - LOGGER.debug(f"Remote machine {self.ip} exec 'devkit_installer' success.") - else: - LOGGER.error(f"Remote machine {self.ip} exec 'devkit_installer' failed.") + cmd = f"{os.path.join(base_path('component'), component_name, 'devkit_installer')} " \ + f"-i {self.ip} -u {self.user} -p {self.pkey} -paname {local_file.split('/')[-1]}" + LOGGER.debug(f"Executing command: {cmd}") + subprocess.run(cmd.split(' '), + capture_output=False, shell=False, stderr=subprocess.STDOUT) # 清理tmp临时文件 self.clear_tmp_file_at_remote_machine(ssh_client, remote_file_list) -- Gitee