From f1f70ac5cd50e588e7fd94103a77f973b812f685 Mon Sep 17 00:00:00 2001 From: liuheng Date: Mon, 28 Oct 2024 09:49:49 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=A4=9A=E4=B8=AA=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E5=88=9B=E5=BB=BA=E4=BA=92=E4=BF=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/base_utils/os/file_util.py | 3 ++- script/gs_sshexkey | 18 +++++++++--------- script/gspylib/common/Constants.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/script/base_utils/os/file_util.py b/script/base_utils/os/file_util.py index 2f2ef51..8a6d1de 100644 --- a/script/base_utils/os/file_util.py +++ b/script/base_utils/os/file_util.py @@ -30,6 +30,7 @@ from subprocess import PIPE from base_utils.common.constantsbase import ConstantsBase from gspylib.common.ErrorCode import ErrorCode +from gspylib.common.Constants import Constants from base_utils.os.cmd_util import CmdUtil from base_utils.os.env_util import EnvUtil from base_utils.os.user_util import UserUtil @@ -964,7 +965,7 @@ class FileUtil(object): get hosts file """ host_file = "" - tmp_hosts_file = "/tmp/gs_sshexkey_hosts" + tmp_hosts_file = Constants.TMP_SSH_FILE if os.path.exists(tmp_hosts_file): host_file = tmp_hosts_file if host_file and os.path.exists(host_file) and os.path.isfile(host_file): diff --git a/script/gs_sshexkey b/script/gs_sshexkey index 8f6b94b..9f6cd32 100644 --- a/script/gs_sshexkey +++ b/script/gs_sshexkey @@ -43,6 +43,7 @@ from gspylib.common.ErrorCode import ErrorCode from gspylib.threads.parallelTool import parallelTool from gspylib.common.Common import DefaultValue, ClusterCommand from gspylib.common.ParameterParsecheck import Parameter +from gspylib.common.Constants import Constants from base_utils.os.env_util import EnvUtil from base_utils.os.file_util import FileUtil from base_utils.os.grep_util import GrepUtil @@ -172,6 +173,7 @@ class GaussCreateTrust(): self.secret_word = "" self.correct_passwd_map = {} self.host_name_list = [] + self.hosts_file = Constants.TMP_SSH_FILE def usage(self): """ @@ -1161,14 +1163,13 @@ General options: """ contents = copy.deepcopy(result) # write hosts file - hosts_file = "/tmp/gs_sshexkey_hosts" - if os.path.exists(hosts_file): - FileUtil.removeFile(hosts_file) - FileUtil.createFile(hosts_file) + if os.path.exists(self.hosts_file): + FileUtil.removeFile(self.hosts_file) + FileUtil.createFile(self.hosts_file) - HostsUtil.write_hosts_file(hosts_file, contents) - FileUtil.changeMode(DefaultValue.FILE_MODE, hosts_file, cmd_type="shell") - FileUtil.changeOwner(self.user, hosts_file, cmd_type="shell") + HostsUtil.write_hosts_file(self.hosts_file, contents) + FileUtil.changeMode(DefaultValue.FILE_MODE, self.hosts_file, cmd_type="shell") + FileUtil.changeOwner(self.user, self.hosts_file, cmd_type="shell") def delete_tmp_file(self): """ @@ -1176,8 +1177,7 @@ General options: input : NA output: NA """ - hosts_file = "/tmp/gs_sshexkey_hosts" - FileUtil.removeFile(hosts_file) + FileUtil.removeFile(self.hosts_file) def write_hostname_to_list(self, ip_hostname): """ diff --git a/script/gspylib/common/Constants.py b/script/gspylib/common/Constants.py index 9ac2a11..3527952 100644 --- a/script/gspylib/common/Constants.py +++ b/script/gspylib/common/Constants.py @@ -1,12 +1,40 @@ +#!/usr/bin/env python3 +# -*- coding:utf-8 -*- +############################################################################# +# Copyright (c) 2024 Huawei Technologies Co.,Ltd. +# +# openGauss is licensed under Mulan PSL v2. +# You can use this software according to the terms +# and conditions of the Mulan PSL v2. +# You may obtain a copy of Mulan PSL v2 at: +# +# http://license.coscl.org.cn/MulanPSL2 +# +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OF ANY KIND, +# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, +# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. +# See the Mulan PSL v2 for more details. +# ---------------------------------------------------------------------------- +# Description : Constants.py is a constant tool +############################################################################# +import os +import sys + +local_dir_path = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(local_dir_path + "/../../") from base_utils.common.constantsbase import ConstantsBase class Constants(ConstantsBase): """common constants""" + def __init__(self): pass __slots__ = () + _pid = os.getpid() SSH_PROTECT_PATH = "~/gaussdb_tmp/ssh_protect" TMP_HOSTS_FILE = "/tmp/tmp_hosts_%d" + TMP_SSH_FILE = "/tmp/tmp_ssh_%d" % _pid