Skip to content

Commit

Permalink
recovery the code that was modified to remove the zip command in PR o…
Browse files Browse the repository at this point in the history
  • Loading branch information
Teingi committed Nov 19, 2024
1 parent 01e76f9 commit a3ec412
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 40 deletions.
15 changes: 8 additions & 7 deletions handler/gather/gather_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from handler.base_shell_handler import BaseShellHandler
from common.obdiag_exception import OBDIAGFormatException
from common.constant import const
from common.command import get_file_size, download_file, is_empty_dir, rm_rf_file, get_logfile_name_list, mkdir, delete_empty_file, tar_gz_dir
from common.command import get_file_size, download_file, is_empty_dir, rm_rf_file, get_logfile_name_list, mkdir, delete_empty_file, zip_encrypt_dir, zip_dir
from common.command import SshClient
from common.tool import TimeUtils
from common.tool import Util
Expand Down Expand Up @@ -368,17 +368,18 @@ def __handle_zip_file(self, ssh_client, resp, gather_dir_name, pack_dir_this_com
self.stdio.print('[ip: {0}] gather observer log start'.format(ssh_client.get_name()))
if self.zip_encrypt:
zip_password = Util.gen_password(16)
tar_gz_dir(ssh_client, self.gather_ob_log_temporary_dir, gather_dir_name, self.stdio)
self.stdio.print('[{0}] gather observer log end'.format(ssh_client.get_name()))
gather_package_dir = "{0}.tar.gz".format(gather_dir_full_path)
self.zip_password = zip_password
zip_encrypt_dir(ssh_client, zip_password, self.gather_ob_log_temporary_dir, gather_dir_name, self.stdio)
else:
zip_dir(ssh_client, self.gather_ob_log_temporary_dir, gather_dir_name, self.stdio)
self.stdio.print('[{0}] zip observer log end'.format(ssh_client.get_name()))
gather_package_dir = "{0}.zip".format(gather_dir_full_path)
gather_log_file_size = get_file_size(ssh_client, gather_package_dir, self.stdio)
self.stdio.print(FileUtil.show_file_size_tabulate(ssh_client, gather_log_file_size))
local_store_path = ""
if int(gather_log_file_size) < self.file_size_limit:
local_store_tar_gz_file = pack_dir_this_command + "/{0}.tar.gz".format(gather_dir_name)
download_file(ssh_client, gather_package_dir, local_store_tar_gz_file, self.stdio)
local_store_path = pack_dir_this_command + "/{0}.zip".format(gather_dir_name)
FileUtil.tar_gz_to_zip(pack_dir_this_command, local_store_tar_gz_file, local_store_path, zip_password, self.stdio)
download_file(ssh_client, gather_package_dir, local_store_path, self.stdio)
resp["error"] = ""
resp["zip_password"] = zip_password
else:
Expand Down
14 changes: 7 additions & 7 deletions handler/gather/gather_obproxy_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from common.obdiag_exception import OBDIAGFormatException
from common.command import SshClient
from common.constant import const
from common.command import get_file_size, download_file, is_empty_dir, get_logfile_name_list, mkdir, delete_empty_file, rm_rf_file, tar_gz_dir
from common.command import get_file_size, download_file, is_empty_dir, get_logfile_name_list, mkdir, delete_empty_file, rm_rf_file, zip_encrypt_dir, zip_dir
from common.tool import Util
from common.tool import DirectoryUtil
from common.tool import FileUtil
Expand Down Expand Up @@ -306,16 +306,16 @@ def __handle_zip_file(self, ssh_client, resp, gather_dir_name, pack_dir_this_com
gather_dir_full_path = "{0}/{1}".format(self.gather_log_temporary_dir, gather_dir_name)
if self.zip_encrypt:
zip_password = Util.gen_password(16)
tar_gz_dir(ssh_client, self.gather_log_temporary_dir, gather_dir_name, self.stdio)
gather_package_dir = "{0}.tar.gz".format(gather_dir_full_path)
zip_encrypt_dir(ssh_client, zip_password, self.gather_log_temporary_dir, gather_dir_name, self.stdio)
else:
zip_dir(ssh_client, self.gather_log_temporary_dir, gather_dir_name, self.stdio)
gather_package_dir = "{0}.zip".format(gather_dir_full_path)
gather_log_file_size = get_file_size(ssh_client, gather_package_dir, self.stdio)
self.stdio.print(FileUtil.show_file_size_tabulate(ssh_client, gather_log_file_size))
local_path = ""
if int(gather_log_file_size) < self.file_size_limit:
local_store_tar_gz_file = pack_dir_this_command + "/{0}.tar.gz".format(gather_dir_name)
download_file(ssh_client, gather_package_dir, local_store_tar_gz_file, self.stdio)
local_path = pack_dir_this_command + "/{0}.zip".format(gather_dir_name)
FileUtil.tar_gz_to_zip(pack_dir_this_command, local_store_tar_gz_file, local_path, zip_password, self.stdio)
local_store_path = pack_dir_this_command + "/{0}.zip".format(gather_dir_name)
local_path = download_file(ssh_client, gather_package_dir, local_store_path, self.stdio)
resp["error"] = ""
resp["zip_password"] = zip_password
else:
Expand Down
18 changes: 8 additions & 10 deletions handler/gather/gather_obstack2.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

import tabulate

from common.command import download_file, is_empty_dir, is_support_arch, get_observer_version, get_observer_pid, mkdir, tar_gz_dir, get_file_size, delete_file_force, is_empty_file, upload_file
from common.command import download_file, is_empty_dir, is_support_arch, get_observer_version, get_observer_pid, mkdir, zip_dir, get_file_size, delete_file_force, is_empty_file, upload_file
from common.constant import const
from common.command import LocalClient, SshClient
from handler.base_shell_handler import BaseShellHandler
Expand Down Expand Up @@ -167,17 +167,15 @@ def __handle_from_node(self, local_stored_path, node):
if is_empty_dir(ssh_client, "/tmp/{0}".format(remote_dir_name), self.stdio):
resp["error"] = "gather failed, folder is empty"
return resp
tar_gz_dir(ssh_client, "/tmp", remote_dir_name, self.stdio)
remote_tar_file_path = "{0}.tar.gz".format(remote_dir_full_path)
zip_dir(ssh_client, "/tmp", remote_dir_name, self.stdio)
remote_zip_file_path = "{0}.zip".format(remote_dir_full_path)

file_size = get_file_size(ssh_client, remote_zip_file_path, self.stdio)
remote_file_full_path = "{0}.zip".format(remote_dir_full_path)

file_size = get_file_size(ssh_client, remote_tar_file_path, self.stdio)
remote_file_full_path = "{0}.tar.gz".format(remote_dir_full_path)
if int(file_size) < self.file_size_limit:
local_tar_file_path = "{0}/{1}.tar.gz".format(local_stored_path, remote_dir_name)
self.stdio.verbose("local tar file path {0}...".format(local_tar_file_path))
download_file(ssh_client, remote_file_full_path, local_tar_file_path, self.stdio)
local_zip_file_path = local_stored_path + "/{0}.zip".format(remote_dir_name)
FileUtil.tar_gz_to_zip(local_stored_path, local_tar_file_path, local_zip_file_path, None, self.stdio)
local_file_path = "{0}/{1}.zip".format(local_stored_path, remote_dir_name)
download_file(ssh_client, remote_file_full_path, local_file_path, self.stdio)
resp["error"] = ""
else:
resp["error"] = "File too large"
Expand Down
13 changes: 5 additions & 8 deletions handler/gather/gather_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import tabulate

from common.command import get_observer_pid, mkdir, tar_gz_dir, get_file_size, download_file, delete_file_force
from common.command import get_observer_pid, mkdir, zip_dir, get_file_size, download_file, delete_file_force
from common.command import SshClient
from common.constant import const
from handler.base_shell_handler import BaseShellHandler
Expand Down Expand Up @@ -151,15 +151,12 @@ def __handle_from_node(self, node, local_stored_path):
self.__gather_perf_flame(ssh_client, remote_dir_full_path, pid_observer)
self.__gather_top(ssh_client, remote_dir_full_path, pid_observer)

tar_gz_dir(ssh_client, "/tmp", remote_dir_name, self.stdio)
remote_file_full_path = "{0}.tar.gz".format(remote_dir_full_path)
zip_dir(ssh_client, "/tmp", remote_dir_name, self.stdio)
remote_file_full_path = "{0}.zip".format(remote_dir_full_path)
file_size = get_file_size(ssh_client, remote_file_full_path, self.stdio)
if int(file_size) < self.file_size_limit:
local_tar_file_path = "{0}/{1}.tar.gz".format(local_stored_path, remote_dir_name)
self.stdio.verbose("local tar file path {0}...".format(local_tar_file_path))
download_file(ssh_client, remote_file_full_path, local_tar_file_path, self.stdio)
local_zip_file_path = local_stored_path + "/{0}.zip".format(remote_dir_name)
FileUtil.tar_gz_to_zip(local_stored_path, local_tar_file_path, local_zip_file_path, None, self.stdio)
local_file_path = "{0}/{1}.zip".format(local_stored_path, remote_dir_name)
download_file(ssh_client, remote_file_full_path, local_file_path, self.stdio)
resp["error"] = ""
else:
resp["error"] = "File too large"
Expand Down
14 changes: 6 additions & 8 deletions handler/gather/gather_sysstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import tabulate
from common.constant import const
from common.command import LocalClient, SshClient
from common.command import get_file_size, download_file, mkdir, tar_gz_dir
from common.command import get_file_size, download_file, mkdir, zip_dir
from handler.base_shell_handler import BaseShellHandler
from common.tool import Util
from common.tool import DirectoryUtil
Expand Down Expand Up @@ -147,15 +147,13 @@ def __handle_from_node(self, node, local_stored_path):
self.__gather_io_info(ssh_client, remote_dir_full_path)
self.__gather_traffic_info(ssh_client, remote_dir_full_path)
self.__gather_tcp_udp_info(ssh_client, remote_dir_full_path)
tar_gz_dir(ssh_client, "/tmp", remote_dir_name, self.stdio)
remote_file_full_path = "{0}.tar.gz".format(remote_dir_full_path)
zip_dir(ssh_client, "/tmp", remote_dir_name, self.stdio)
remote_file_full_path = "{0}.zip".format(remote_dir_full_path)
file_size = get_file_size(ssh_client, remote_file_full_path, self.stdio)
if int(file_size) < self.file_size_limit:
local_tar_file_path = "{0}/{1}.tar.gz".format(local_stored_path, remote_dir_name)
self.stdio.verbose("local tar file path {0}...".format(local_tar_file_path))
download_file(ssh_client, remote_file_full_path, local_tar_file_path, self.stdio)
local_zip_file_path = local_stored_path + "/{0}.zip".format(remote_dir_name)
FileUtil.tar_gz_to_zip(local_stored_path, local_tar_file_path, local_zip_file_path, None, self.stdio)
local_file_path = "{0}/{1}.zip".format(local_stored_path, remote_dir_name)
self.stdio.verbose("local file path {0}...".format(local_file_path))
download_file(ssh_client, remote_file_full_path, local_file_path, self.stdio)
resp["error"] = ""
else:
resp["error"] = "File too large"
Expand Down

0 comments on commit a3ec412

Please sign in to comment.