diff --git a/common/command.py b/common/command.py index 8d838198..4bd18249 100644 --- a/common/command.py +++ b/common/command.py @@ -189,7 +189,7 @@ def zip_dir(ssh_client, father_dir, zip_dir, stdio=None): Compress files through zip :return: """ - cmd = "zip {father_dir}/{zip_dir}.zip -rm {father_dir}/{zip_dir}".format(father_dir=father_dir, zip_dir=zip_dir) + cmd = "cd {father_dir} && zip {zip_dir}.zip -rm {zip_dir}".format(father_dir=father_dir, zip_dir=zip_dir) ssh_client.exec_cmd(cmd) @@ -198,7 +198,7 @@ def zip_encrypt_dir(ssh_client, zip_password, father_dir, zip_dir, stdio=None): Compress files by encryption :return: """ - cmd = "zip --password {zip_password} {father_dir}/{zip_dir}.zip -rm {father_dir}/{zip_dir}".format(zip_password=zip_password, father_dir=father_dir, zip_dir=zip_dir) + cmd = "cd {father_dir} && zip --password {zip_password} {zip_dir}.zip -rm {zip_dir}".format(zip_password=zip_password, father_dir=father_dir, zip_dir=zip_dir) ssh_client.exec_cmd(cmd) diff --git a/common/ssh_client/remote_client.py b/common/ssh_client/remote_client.py index d61c0821..3cb08197 100644 --- a/common/ssh_client/remote_client.py +++ b/common/ssh_client/remote_client.py @@ -87,6 +87,7 @@ def exec_cmd(self, cmd): if len(stderr.read().decode('utf-8').strip()) > 0: raise Exception(stderr.read().decode('utf-8')) cmd = "sudo {0}".format(cmd) + cmd = cmd.replace("&&", "&& sudo ") self.stdio.verbose('Execute Shell command on server {0}:{1}'.format(self.host_ip, cmd)) stdin, stdout, stderr = self._ssh_fd.exec_command(cmd) err_text = stderr.read() diff --git a/handler/rca/rca_handler.py b/handler/rca/rca_handler.py index 1fe3a14e..35be6529 100644 --- a/handler/rca/rca_handler.py +++ b/handler/rca/rca_handler.py @@ -175,13 +175,15 @@ def execute(self): self.rca_scene.execute() except RCANotNeedExecuteException as e: self.stdio.warn("rca_scene.execute not need execute: {0}".format(e)) - return ObdiagResult(ObdiagResult.SERVER_ERROR_CODE, data="rca_scene.execute not need execute: {0}") + return ObdiagResult(ObdiagResult.SERVER_ERROR_CODE, data={"result": "rca_scene.execute not need execute"}) except Exception as e: - raise Exception("rca_scene.execute err: {0}".format(e)) + self.stdio.error("rca_scene.execute err: {0}".format(e)) + return ObdiagResult(ObdiagResult.SERVER_ERROR_CODE, error_data="rca_scene.execute err: {0}".format(e)) try: self.rca_scene.export_result() except Exception as e: - raise Exception("rca_scene.export_result err: {0}".format(e)) + self.stdio.error("rca_scene.export_result err: {0}".format(e)) + return ObdiagResult(ObdiagResult.SERVER_ERROR_CODE, error_data="rca_scene.export_result err: {0}".format(e)) self.stdio.print("rca finished. For more details, the result on '" + Fore.YELLOW + self.get_result_path() + Style.RESET_ALL + "' \nYou can get the suggest by '" + Fore.YELLOW + "cat " + self.get_result_path() + "/record" + Style.RESET_ALL + "'") return ObdiagResult(ObdiagResult.SUCCESS_CODE, data={"store_dir": self.get_result_path(), "record": self.rca_scene.Result.records_data()})