Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete useless code #616

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions common/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,6 @@ def delete_file_in_folder(ssh_client, file_path, stdio=None):
ssh_client.exec_cmd(cmd)


def is_empty_dir(ssh_client, dir, stdio=None):
"""
determine whether it is an empty folder
:return: true or false
"""
cmd = "ls -A {gather_path}|wc -w".format(gather_path=dir)
file_num = ssh_client.exec_cmd(cmd)
if int(file_num) == 0:
return True
else:
return False


def get_file_start_time(ssh_client, file_name, dir, stdio=None):
"""
get log file start time
Expand Down Expand Up @@ -367,15 +354,6 @@ def delete_file_force(ssh_client, file_name, stdio=None):
ssh_client.exec_cmd(cmd)


def delete_empty_file(ssh_client, file_path, stdio=None):
"""
delete empty file
:return:
"""
cmd = "find {file_path} -name '*' -type f -size 0c | xargs -n 1 rm -f".format(file_path=file_path)
ssh_client.exec_cmd(cmd)


def delete_file(ssh_client, file_path, stdio=None):
"""
delete file
Expand Down
52 changes: 1 addition & 51 deletions common/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,17 @@
import os
import tempfile
import warnings
import sys

import paramiko
import time
import docker
from glob import glob
from paramiko import AuthenticationException, SFTPClient
from paramiko.client import SSHClient, AutoAddPolicy
from paramiko.ssh_exception import NoValidConnectionsError, SSHException
from multiprocessing.queues import Empty
from multiprocessing import Queue
from multiprocessing.pool import ThreadPool
from common.tool import COMMAND_ENV, DirectoryUtil, FileUtil, Timeout
from common.obdiag_exception import OBDIAGSSHConnException
from common.obdiag_exception import OBDIAGShellCmdException
from common.tool import StringUtils
from common.tool import TimeUtils
from stdio import SafeStdio
from err import EC_SSH_CONNECT
from subprocess32 import Popen, PIPE
from subprocess import Popen, PIPE

warnings.filterwarnings("ignore")

Expand Down Expand Up @@ -761,44 +752,3 @@ def _filter_dir_in_file_path(files, directories):
directories.remove(dir_name)
skip_directories.append(dir_name)
dir_name = os.path.dirname(dir_name)

def file_downloader(self, local_dir, remote_dir, stdio=None):
try:
client = SshClient(config=self.config, stdio=None)
client._open_sftp(stdio=stdio)
client._remote_transporter = self.remote_transporter
while True:
remote_path = self.task_queue.get(block=False)
local_path = os.path.join(local_dir, os.path.relpath(remote_path, remote_dir))
if client.get_file(local_path, remote_path, stdio=stdio):
self.result_queue.put(remote_path)
else:
stdio.error('Fail to get %s' % remote_path)
except Empty:
return
except:
stdio.exception("")
stdio.exception('Failed to get %s' % remote_dir)

def file_uploader(self, local_dir, remote_dir, stdio=None):
try:
client = SshClient(config=self.config, stdio=None)
client._remote_transporter = self.remote_transporter
while True:
local_path, is_dir = self.task_queue.get(block=False)
remote_path = os.path.join(remote_dir, os.path.relpath(local_path, local_dir))
if is_dir:
stat = oct(os.stat(local_path).st_mode)[-3:]
cmd = '[ -d "{remote_path}" ] || (mkdir -p {remote_path}; chmod {stat} {remote_path})'.format(remote_path=remote_path, stat=stat)
if client.execute_command(cmd):
self.result_queue.put(remote_path)
else:
if client.put_file(local_path, remote_path, stdio=stdio):
self.result_queue.put(remote_path)
else:
stdio.error('Fail to get %s' % remote_path)
except Empty:
return
except:
stdio.exception("")
stdio.verbose('Failed to get %s' % remote_dir)
2 changes: 1 addition & 1 deletion common/ssh_client/local_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""

from common.ssh_client.base import SsherClient
import subprocess32 as subprocess
import subprocess
import shutil


Expand Down
12 changes: 1 addition & 11 deletions common/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
"""

from __future__ import absolute_import, division, print_function
import multiprocessing as mp

import os
import io
import bz2
import random
Expand All @@ -27,26 +24,19 @@
import gzip
import fcntl
import signal
import shutil
import re
import json
import hashlib
import datetime
import uuid

import tabulate
import tarfile
import socket
import requests
import decimal
import time
import json
import time
import traceback
import datetime
import string
import oyaml as yaml
import ast
import lzma
import pymysql as mysql
import shutil
Expand All @@ -66,7 +56,7 @@
encoding_open = open


__all__ = ("Timeout", "DynamicLoading", "ConfigUtil", "DirectoryUtil", "FileUtil", "YamlLoader", "OrderedDict", "COMMAND_ENV", "TimeUtils", "NetUtils", "StringUtils", "YamlUtils", "Util")
__all__ = ("Timeout", "DynamicLoading", "ConfigUtil", "DirectoryUtil", "FileUtil", "YamlLoader", "COMMAND_ENV", "TimeUtils", "NetUtils", "StringUtils", "YamlUtils", "Util")

_WINDOWS = os.name == 'nt'

Expand Down
1 change: 0 additions & 1 deletion common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import os
import re
import uuid
import traceback

__all__ = ("Moment", "Time", "Capacity", "CapacityWithB", "CapacityMB", "StringList", "Dict", "List", "StringOrKvList", "Double", "Boolean", "Integer", "String", "Path", "SafeString", "PathList", "SafeStringList", "DBUrl", "WebUrl", "OBUser")

Expand Down
5 changes: 2 additions & 3 deletions core.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
from common.tool import TimeUtils, Util
from common.command import get_observer_version_by_sql
from common.ob_connector import OBConnector
from collections import OrderedDict


class ObdiagHome(object):
Expand Down Expand Up @@ -173,7 +172,7 @@ def update_obcluster_nodes(self, config):
if not all(ob_cluster.values()) or not all(ob_cluster['tenant_sys'].values()):
raise ValueError("Missing required configuration values in ob_cluster or tenant_sys")

if (obcluster := config_data.get('obcluster')) and (servers := obcluster.get('servers')) and servers.get('nodes'):
if config_data.get('obcluster') and config_data.get('obcluster').get('servers') and config_data.get('obcluster').get('servers').get('nodes'):
return

ob_version = get_observer_version_by_sql(self.context, ob_cluster)
Expand Down Expand Up @@ -548,7 +547,7 @@ def update(self, opts):
self.stdio.print("update start ...")
self.set_offline_context('update', 'update')
handler = UpdateHandler(self.context)
return handler.execute()
return handler.handle()

def config(self, opt):
config = self.config_manager
Expand Down
1 change: 0 additions & 1 deletion handler/analyzer/analyze_index_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"""


import sys
from prettytable import PrettyTable
from common.tool import StringUtils, Util
from common.ob_connector import OBConnector
Expand Down
3 changes: 1 addition & 2 deletions handler/analyzer/analyze_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"""
import datetime
import os
import re
import csv
from tabulate import tabulate
from common.command import get_observer_version_by_sql
Expand All @@ -27,7 +26,7 @@
from common.command import SshClient
from common.ob_log_level import OBLogLevel
from common.command import download_file, get_logfile_name_list, mkdir, delete_file
from common.tool import DirectoryUtil, TimeUtils, Util, StringUtils
from common.tool import StringUtils
from common.tool import Util
from common.tool import DirectoryUtil
from common.tool import FileUtil
Expand Down
2 changes: 0 additions & 2 deletions handler/analyzer/analyze_sql_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@
import time
import sqlparse
from tabulate import tabulate
from colorama import Fore, Style
from common.constant import const
from common.tool import StringUtils, Util
from common.tool import TimeUtils
from common.tool import FileUtil
from common.ob_connector import OBConnector
from handler.analyzer.sql.rule_manager import SQLReviewRuleManager
from handler.meta.sql_meta import GlobalSqlMeta
from handler.meta.html_meta import GlobalHtmlMeta


Expand Down
4 changes: 2 additions & 2 deletions handler/checker/check_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ def handle(self):

cases_map[package_data] = {
"name": package_data,
"command": "obdiag check --{0}={1}".format(package_target, package_data),
"command": "obdiag check run --{0}={1}".format(package_target, package_data),
"info_en": package_file_data[package_data].get("info_en") or "",
"info_cn": package_file_data[package_data].get("info_cn") or "",
}
result_map[target]["commands"].append(
{
"name": package_data,
"command": "obdiag check --{0}={1}".format(package_target, package_data),
"command": "obdiag check run --{0}={1}".format(package_target, package_data),
"info_en": package_file_data[package_data].get("info_en") or "",
"info_cn": package_file_data[package_data].get("info_cn") or "",
}
Expand Down
1 change: 0 additions & 1 deletion handler/checker/check_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"""
import threading

from common.ob_connector import OBConnector
from handler.checker.check_exception import StepResultFailException, StepExecuteFailException, StepResultFalseException, TaskException
from handler.checker.step.stepbase import StepBase
from common.tool import StringUtils
Expand Down
2 changes: 1 addition & 1 deletion handler/checker/result/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@file: result.py
@desc:
"""
from handler.checker.check_exception import ResultFalseException, ResultFailException, VerifyFailException
from handler.checker.check_exception import ResultFalseException, ResultFailException
from handler.checker.result.verify import VerifyResult
import re

Expand Down
2 changes: 1 addition & 1 deletion handler/checker/result/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""
import decimal
import re
import subprocess32 as subprocess
import subprocess
from handler.checker.check_exception import VerifyFalseException, VerifyFailException
from handler.meta.check_meta import GlobalCheckMeta
from common.tool import StringUtils
Expand Down
3 changes: 0 additions & 3 deletions handler/checker/step/sleep.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
import time

from handler.checker.check_exception import StepExecuteFailException
from common.ob_connector import OBConnector
from common.tool import StringUtils
from common.tool import Util


class StepSleepHandler:
Expand Down
1 change: 0 additions & 1 deletion handler/checker/step/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"""

from handler.checker.check_exception import StepExecuteFailException
from common.ob_connector import OBConnector
from common.tool import StringUtils
from common.tool import Util

Expand Down
1 change: 0 additions & 1 deletion handler/checker/step/stepbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from handler.checker.result.result import CheckResult
from handler.checker.step.ssh import SshHandler
from handler.checker.step.sql import StepSQLHandler
import docker
from common.ssh_client.ssh import SshClient


Expand Down
5 changes: 1 addition & 4 deletions handler/display/display_scenes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,15 @@
@desc:
"""

import os
import re
from result_type import ObdiagResult
from stdio import SafeStdio
import datetime
from handler.display.scenes.base import SceneBase
from common.obdiag_exception import OBDIAGFormatException
from handler.display.scenes.list import DisplayScenesListHandler
from common.tool import DirectoryUtil
from common.tool import StringUtils
from common.scene import get_version_by_type
from colorama import Fore, Style
from common.tool import Util
from common.tool import TimeUtils
from common.ob_connector import OBConnector
Expand Down Expand Up @@ -129,7 +126,7 @@ def __execute_code_task_one(self, task_name):
try:
self.stdio.verbose("execute tasks is {0}".format(task_name))
scene = {"name": task_name}
task = SceneBase(context=self.context, scene=scene, env=self.env, mode='code', task_type=task_name)
task = SceneBase(context=self.context, scene=scene, env=self.env, mode='code', task_type=task_name, db_connector=self.db_connector)
self.stdio.verbose("{0} execute!".format(task_name))
task.execute()
self.stdio.verbose("execute tasks end : {0}".format(task_name))
Expand Down
7 changes: 5 additions & 2 deletions handler/display/scenes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
from stdio import SafeStdio
from common.scene import filter_by_version
from handler.display.step.base import Base
from common.tool import StringUtils


class SceneBase(SafeStdio):
def __init__(self, context, scene, db_connector, report_dir=None, scene_variable_dict={}, env={}, mode="yaml", task_type="observer"):
def __init__(self, context, scene, db_connector, report_dir=None, scene_variable_dict=None, env=None, mode="yaml", task_type="observer"):
if env is None:
env = {}
if scene_variable_dict is None:
scene_variable_dict = {}
self.context = context
self.stdio = context.stdio
self.scene_variable_dict = scene_variable_dict
Expand Down
5 changes: 3 additions & 2 deletions handler/display/step/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
"""
from common.ssh_client.ssh import SshClient
from stdio import SafeStdio
from handler.display.step.ssh import SshHandler
from handler.display.step.sql import StepSQLHandler


class Base(SafeStdio):
def __init__(self, context, step, node, cluster, task_variable_dict=None, env={}, node_number=1, db_connector=None):
def __init__(self, context, step, node, cluster, task_variable_dict=None, env=None, node_number=1, db_connector=None):
if env is None:
env = {}
self.context = context
self.stdio = context.stdio
if task_variable_dict is None:
Expand Down
3 changes: 0 additions & 3 deletions handler/display/step/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
@file: sql.py
@desc:
"""
import os
from stdio import SafeStdio
from common.ob_connector import OBConnector
from tabulate import tabulate
from common.tool import StringUtils
from prettytable import PrettyTable

Expand Down
2 changes: 1 addition & 1 deletion handler/gather/gather_obadmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import tabulate
from common.obdiag_exception import OBDIAGFormatException
from common.constant import const
from common.command import LocalClient, SshClient, is_empty_dir
from common.command import SshClient, is_empty_dir
from handler.base_shell_handler import BaseShellHandler
from common.command import download_file, rm_rf_file, get_file_size, get_observer_version, tar_gz_dir
from common.tool import TimeUtils
Expand Down
2 changes: 1 addition & 1 deletion handler/gather/gather_obproxy_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def __handle_from_node(self, node, pack_dir_this_command):
return resp
for log_name in log_list:
self.__pharse_log(ssh_client=ssh_client, log_name=log_name, home_path=remote_home_path, gather_path=gather_dir_full_path)
delete_empty_file(ssh_client, gather_dir_full_path, self.stdio)
delete_empty_file(ssh_client, gather_dir_full_path)

is_empty = is_empty_dir(ssh_client, gather_dir_full_path, self.stdio)
if is_empty:
Expand Down
Loading
Loading