CheckBlockdev添加解析函数以及针对scpFIle函数添加本地模式生成临时文件

This commit is contained in:
zhang_xubo
2022-03-11 10:27:50 +08:00
parent e148212355
commit d2d608c215
2 changed files with 46 additions and 2 deletions

View File

@ -704,6 +704,8 @@ class SshTool():
""" """
scpCmd = "source /etc/profile" scpCmd = "source /etc/profile"
outputCollect = "" outputCollect = ""
localMode = False
resultMap = {}
if hostList is None: if hostList is None:
hostList = [] hostList = []
try: try:
@ -735,6 +737,7 @@ class SshTool():
hostList = self.hostNames hostList = self.hostNames
if len(hostList) == 1 and hostList[0] == socket.gethostname() and \ if len(hostList) == 1 and hostList[0] == socket.gethostname() and \
srcFile != targetDir: srcFile != targetDir:
localMode = True
scpCmd = "cp -r %s %s" % (srcFile, targetDir) scpCmd = "cp -r %s %s" % (srcFile, targetDir)
else: else:
scpCmd += " && %s -r -v -t %s -p %s -H %s -o %s -e %s %s %s" \ scpCmd += " && %s -r -v -t %s -p %s -H %s -o %s -e %s %s %s" \
@ -763,7 +766,36 @@ class SshTool():
+ " Error:\n%s" % output) + " Error:\n%s" % output)
# ip and host name should match here # ip and host name should match here
resultMap, outputCollect = self.parseSshResult(hostList) if localMode:
dir_permission = 0o700
if status == 0:
resultMap[hostList[0]] = DefaultValue.SUCCESS
outputCollect = "[%s] %s:\n%s" % ("SUCCESS", hostList[0],
SensitiveMask.mask_pwd(output))
if not os.path.exists(self.__outputPath):
os.makedirs(self.__outputPath, mode=dir_permission)
file_path = os.path.join(self.__outputPath, hostList[0])
FileUtil.createFileInSafeMode(file_path)
with open(file_path, "w") as fp:
fp.write(SensitiveMask.mask_pwd(output))
fp.flush()
fp.close()
else:
resultMap[hostList[0]] = DefaultValue.FAILURE
outputCollect = "[%s] %s:\n%s" % ("FAILURE", hostList[0],
SensitiveMask.mask_pwd(output))
if not os.path.exists(self.__errorPath):
os.makedirs(self.__errorPath, mode=dir_permission)
file_path = os.path.join(self.__errorPath, hostList[0])
FileUtil.createFileInSafeMode(file_path)
with open(file_path, "w") as fp:
fp.write(SensitiveMask.mask_pwd(output))
fp.flush()
fp.close()
else:
resultMap, outputCollect = self.parseSshResult(hostList)
except Exception as e: except Exception as e:
self.clenSshResultFiles() self.clenSshResultFiles()
raise Exception(str(e)) raise Exception(str(e))

View File

@ -26,7 +26,7 @@ from gspylib.common.ErrorCode import ErrorCode
from os_platform.common import BIT_VERSION, EULEROS, SUPPORT_EULEROS_VERSION_LIST, \ from os_platform.common import BIT_VERSION, EULEROS, SUPPORT_EULEROS_VERSION_LIST, \
SUPPORT_RHEL_SERIES_PLATFORM_LIST, \ SUPPORT_RHEL_SERIES_PLATFORM_LIST, \
SUPPORT_RHEL_SERIES_VERSION_LIST, OPENEULER, CENTOS, \ SUPPORT_RHEL_SERIES_VERSION_LIST, OPENEULER, CENTOS, \
SUPPORT_RHEL7X_VERSION_LIST, DEBIAN SUPPORT_RHEL7X_VERSION_LIST, DEBIAN, BLANK_SPACE
from os_platform.linux_distro import LinuxDistro from os_platform.linux_distro import LinuxDistro
from os_platform.linux_platform import LinuxPlatform from os_platform.linux_platform import LinuxPlatform
@ -141,6 +141,18 @@ class RHELPlatform(LinuxPlatform):
% ("systemd-journald", "SuSE")) % ("systemd-journald", "SuSE"))
except Exception as e: except Exception as e:
raise Exception(str(e)) raise Exception(str(e))
def getBlockdevCmd(self, device, value="", isSet=False):
"""
function: get block dev cmd
input : device, value, isSet
output : str
"""
if isSet and value != "":
return self.findCmdInPath('blockdev') + " --setra " + value + \
BLANK_SPACE + device
else:
return self.findCmdInPath('blockdev') + " --getra " + device
def getCurrentPlatForm(self): def getCurrentPlatForm(self):
""" """