本文整理汇总了Python中SSH_utils.execute_remote_cmd方法的典型用法代码示例。如果您正苦于以下问题:Python SSH_utils.execute_remote_cmd方法的具体用法?Python SSH_utils.execute_remote_cmd怎么用?Python SSH_utils.execute_remote_cmd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SSH_utils
的用法示例。
在下文中一共展示了SSH_utils.execute_remote_cmd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_for_expired_proxies
# 需要导入模块: import SSH_utils [as 别名]
# 或者: from SSH_utils import execute_remote_cmd [as 别名]
def check_for_expired_proxies(utils,ssh,wms_location_var):
proxies=SSH_utils.execute_remote_cmd(utils,ssh,"find %s/proxycache/ -name \*.pem"%(wms_location_var)).split("\n")
for proxy in proxies:
if proxy.strip()!='':
expiry_date=SSH_utils.execute_remote_cmd(utils,ssh,"openssl x509 -in %s -noout -enddate"%(proxy.strip())).split("=")[1].strip("\n")
ddate_str=time.strptime(expiry_date,"%b %d %H:%M:%S %Y %Z")[0:8]
dt = datetime.datetime(ddate_str[0],ddate_str[1],ddate_str[2],ddate_str[3],ddate_str[4],ddate_str[5],ddate_str[6])
now_dt = datetime.datetime.utcnow()
diff=now_dt-dt
minutes, seconds = divmod(diff.seconds, 60)
hours, minutes = divmod(minutes, 60)
if diff.days>=0:
#Maybe it is necessary to check and minutes
if hours>=6:
utils.log_info("ERROR: Find expired proxy for more than 6 hours. Proxy is %s"%(proxy))
raise GeneralError("Check for expired proxies for more than 6 hours","Find expired proxy for more than 6 hours. Proxy is %s"%(proxy))
示例2: test6
# 需要导入模块: import SSH_utils [as 别名]
# 或者: from SSH_utils import execute_remote_cmd [as 别名]
def test6(utils,title):
utils.show_progress(title)
utils.info(title)
fails=0
try:
if utils.OSB_DEST_HOSTNAME=='' or utils.OSB_DEST_USERNAME=='' or utils.OSB_DEST_PASSWORD=='' :
utils.warn("Please set the required variables for OSB node in test's configuration file")
utils.show_progress("Please set the required variables for OSB node in test's configuration file")
return 1
ssh=SSH_utils.open_ssh(utils.OSB_DEST_HOSTNAME,utils.OSB_DEST_USERNAME,utils.OSB_DEST_PASSWORD)
SSH_utils.execute_remote_cmd(ssh,"mkdir -p -m 0777 /tmp/%s/osbbase"%(utils.ID))
target_info,target_ces=utils.get_target_ces()
if len(target_info)==0:
target_info.append("Default Test - Submit to CREAM CE")
target_ces.append("/cream-")
for target in target_ces:
utils.show_progress("%s - %s"%(title,target_info[target_ces.index(target)]))
utils.info("%s - %s"%(title,target_info[target_ces.index(target)]))
utils.run_command_continue_on_error("rm -rf %s/*"%(utils.get_job_output_dir()))
if osbbasetdesturi_test(utils,target,ssh)==1:
fails=fails+1
SSH_utils.close_ssh(ssh)
except (RunCommandError,GeneralError,TimeOutError) , e :
utils.log_error("%s"%(utils.get_current_test()))
utils.log_error("Command: %s"%(e.expression))
utils.log_error("Message: %s"%(e.message))
utils.log_traceback("%s"%(utils.get_current_test()))
utils.log_traceback(traceback.format_exc())
fails=fails+1
示例3: check_for_empty_directories
# 需要导入模块: import SSH_utils [as 别名]
# 或者: from SSH_utils import execute_remote_cmd [as 别名]
def check_for_empty_directories(utils,ssh,wms_location_var):
dirs = SSH_utils.execute_remote_cmd(utils,ssh,"ls /%s/proxycache"%(wms_location_var)).split(" ")
for dir in dirs:
dir=dir.strip(" \n\t")
if dir.find("cache")==-1:
utils.log_info("Check directory: %s"%(dir))
subdirs=SSH_utils.execute_remote_cmd(utils,ssh,"find /%s/proxycache/%s -name userproxy.pem | wc -l"%(wms_location_var,dir))
total_subdirs=SSH_utils.execute_remote_cmd(utils,ssh,"ls -l /%s/proxycache/%s | grep glite | wc -l"%(wms_location_var,dir))
if total_subdirs == subdirs :
utils.log_info("Check OK, there are no empty directories in %s"%(dir))
else:
utils.log_info("ERROR: Test Failed. There are empty directories in %s"%(dir))
raise GeneralError("Check for emptry directories","Test Failed. There are empty directories in %s"%(dir))
示例4: test7_target
# 需要导入模块: import SSH_utils [as 别名]
# 或者: from SSH_utils import execute_remote_cmd [as 别名]
def test7_target(utils,ssh,wms_location_var):
proxies=SSH_utils.execute_remote_cmd(utils,ssh,"find %s/SandboxDir/ -name user.proxy"%(wms_location_var)).split("\n")
has_expired=0
for proxy in proxies:
if proxy.strip()!='':
expiry_date=SSH_utils.execute_remote_cmd(utils,ssh,"openssl x509 -in %s -noout -enddate"%(proxy.strip())).split("=")[1].strip("\n")
ddate_str=time.strptime(expiry_date,"%b %d %H:%M:%S %Y %Z")[0:8]
dt = datetime.datetime(ddate_str[0],ddate_str[1],ddate_str[2],ddate_str[3],ddate_str[4],ddate_str[5],ddate_str[6])
now_dt = datetime.datetime.utcnow()
diff=now_dt-dt
minutes, seconds = divmod(diff.seconds, 60)
hours, minutes = divmod(minutes, 60)
if diff.days>=0:
if minutes>0 or hours>0:
target_proxy=proxy
has_expired=1
break
if has_expired==0:
utils.log_info("Skip test: Unable to find any expired proxy in %s/SandboxDir"%(wms_location_var))
raise GeneralError("","Skip test: Unable to find any expired proxy in %s/SandboxDir"%(wms_location_var))
target_dir=target_proxy.split("/https")[0]
return target_dir
示例5: set_ISBBase
# 需要导入模块: import SSH_utils [as 别名]
# 或者: from SSH_utils import execute_remote_cmd [as 别名]
def set_ISBBase(utils,filename):
utils.log_info("Define a jdl with ISBBaseURI attribute")
FILE=open(filename,"w")
FILE.write("Executable = \"test.sh\";\n")
FILE.write("StdOutput = \"std.out\";\n")
FILE.write("StdError = \"std.err\";\n")
FILE.write("FuzzyRank = true;\n")
FILE.write("InputSandboxBaseURI = \"gsiftp://%s:2811/tmp/%s/isb\";\n"%(utils.ISB_DEST_HOSTNAME,utils.ID))
FILE.write("InputSandbox = {\"test.sh\",\"test1.txt\"};\n")
FILE.write("OutputSandbox = {\"std.out\", \"std.err\"};\n")
FILE.write("DataAccessProtocol = \"gsiftp\";\n")
FILE.write("RetryCount = 1;\n")
FILE.write("ShallowRetryCount = 2;\n")
FILE.close()
utils.log_info("The saved jdl is:\n%s"%(commands.getoutput("cat %s"%(filename))),'DEBUG')
utils.log_info("Create executable script (test.sh) and test1.txt file at remote host: %s"%(utils.ISB_DEST_HOSTNAME))
ssh=SSH_utils.open_ssh(utils.ISB_DEST_HOSTNAME,utils.ISB_DEST_USERNAME,utils.ISB_DEST_PASSWORD,utils)
SSH_utils.execute_remote_cmd(utils,ssh,"rm -f /tmp/%s/isb/*"%(utils.ID))
SSH_utils.execute_remote_cmd(utils,ssh,"echo \"#!/bin/sh\" > /tmp/%s/isb/test.sh"%(utils.ID))
SSH_utils.execute_remote_cmd(utils,ssh,"echo $GLITE_WMS_JOBID >> /tmp/%s/isb/test.sh"%(utils.ID))
SSH_utils.execute_remote_cmd(utils,ssh,"echo \"ls -la\" >> /tmp/%s/isb/test.sh"%(utils.ID))
SSH_utils.execute_remote_cmd(utils,ssh,"touch /tmp/%s/isb/test1.txt"%(utils.ID))
SSH_utils.close_ssh(ssh,utils)
示例6: get_nodes_dir
# 需要导入模块: import SSH_utils [as 别名]
# 或者: from SSH_utils import execute_remote_cmd [as 别名]
def get_nodes_dir(utils,ssh,jobid):
output=utils.run_command("glite-wms-job-status -c %s %s"%(utils.get_config_file(),jobid)).split("\n")
nodes_dir=[]
for line in output :
if line.find("https://")!=-1 and line.find(jobid)==-1:
id=line.split("Status info for the Job : ")[1]
ndprefix=id.split(":9000/")[1][0:2]
nodes_dir.append(SSH_utils.execute_remote_cmd(utils,ssh,"ls /var/SandboxDir/%s"%(ndprefix)))
return nodes_dir
示例7: set_drain
# 需要导入模块: import SSH_utils [as 别名]
# 或者: from SSH_utils import execute_remote_cmd [as 别名]
def set_drain(utils,ssh):
utils.log_info("Set WMS in draining mode")
SSH_utils.execute_remote_cmd(utils,ssh,"touch /var/.drain")
示例8: restore_configuration
# 需要导入模块: import SSH_utils [as 别名]
# 或者: from SSH_utils import execute_remote_cmd [as 别名]
def restore_configuration(utils,ssh):
SSH_utils.execute_remote_cmd(utils,ssh, "cp -f /etc/glite-wms/glite_wms.conf.bak /etc/glite-wms/glite_wms.conf")
SSH_utils.execute_remote_cmd(utils,ssh,"/etc/init.d/glite-wms-wm restart")
示例9: test7
# 需要导入模块: import SSH_utils [as 别名]
# 或者: from SSH_utils import execute_remote_cmd [as 别名]
def test7(utils, ssh, title):
utils.show_progress(title)
utils.info(title)
try:
wms_location_var = SSH_utils.execute_remote_cmd(ssh, "echo $WMS_LOCATION_VAR")[:-1]
utils.info("Check inside $WMS_LOCATION_VAR/SandboxDir for jobs with expired proxy")
proxies = SSH_utils.execute_remote_cmd(ssh, "find %s/SandboxDir/ -name user.proxy" % (wms_location_var)).split(
"\n"
)
has_expired = 0
for proxy in proxies:
if proxy.strip() != "":
expiry_date = (
SSH_utils.execute_remote_cmd(ssh, "openssl x509 -in %s -noout -enddate" % (proxy.strip()))
.split("=")[1]
.strip("\n")
)
ddate_str = time.strptime(expiry_date, "%b %d %H:%M:%S %Y %Z")[0:8]
dt = datetime.datetime(
ddate_str[0], ddate_str[1], ddate_str[2], ddate_str[3], ddate_str[4], ddate_str[5], ddate_str[6]
)
now_dt = datetime.datetime.utcnow()
diff = now_dt - dt
minutes, seconds = divmod(diff.seconds, 60)
hours, minutes = divmod(minutes, 60)
if diff.days >= 0:
if minutes > 0 or hours > 0:
target_proxy = proxy
has_expired = 1
break
if has_expired == 0:
utils.error("Skip test: Unable to find any expired proxy in %s/SandboxDir" % (wms_location_var))
raise GeneralError(
title, "Skip test: Unable to find any expired proxy in %s/SandboxDir" % (wms_location_var)
)
target_dir = target_proxy.split("/https")[0]
utils.info("Purge a job with expired proxy")
# WARNING EXECUTE COMMAND AS root INSTEAD OF glite USER
utils.info("Execute '/usr/sbin/glite-wms-purgeStorage.sh -p %s -s' on remote host" % (target_dir))
output = SSH_utils.execute_remote_cmd(ssh, "/usr/sbin/glite-wms-purgeStorage.sh -p %s -s" % (target_dir))
utils.info("Get job id ")
JOBID = output.split(": ")[2]
utils.info("Check job's status")
utils.job_status(JOBID)
if utils.get_job_status().find("Cleared") != -1:
utils.info("Job's final status after purge is Cleared")
utils.info("Check job's status reason")
status = utils.get_job_status_reason(JOBID)
if status.find("timed out, resource purge forced") != -1:
utils.info("Status reason is 'timed out, resource purge forced' as expected")
else:
utils.error("Status reason is %s while the expected is 'timed out, resource purge forced'" % (status))
raise GeneralError(
"Check job's status reason",
"Status reason is %s while the expected is 'timed out, resource purge forced'" % (status),
)
else:
utils.error("Job's final status after purge is not Cleared , instead we get %s" % (utils.get_job_status()))
raise GeneralError(
"Check job final status after purge",
"Job's final status after purge is not Cleared , instead we get %s" % (utils.get_job_status()),
)
utils.info("Check the user Clear event")
output = utils.run_command_continue_on_error(
"glite-wms-job-logging-info --event Clear -v 2 %s" % (JOBID)
).split("\n")
#.........这里部分代码省略.........
示例10: test5
# 需要导入模块: import SSH_utils [as 别名]
# 或者: from SSH_utils import execute_remote_cmd [as 别名]
def test5(utils, ssh, title):
utils.show_progress(title)
utils.info(title)
try:
Job_utils.prepare_normal_job(utils, utils.get_jdl_file())
utils.info("Submit a job to a CREAM CE")
JOBID = Job_utils.submit_only_normal_job(utils)[1]
prefix = JOBID.split("https://%s:9000/" % (utils.get_WMS()))[1][0:2]
utils.info("Wait until job finishes")
utils.wait_until_job_finishes(JOBID)
utils.job_status(JOBID)
if utils.get_job_status().find("Done") != -1:
utils.info("Purge a done job")
# WARNING EXECUTE COMMAND AS root INSTEAD OF glite USER
utils.info(
"Execute '/usr/sbin/glite-wms-purgeStorage.sh -p /var/SandboxDir/%s -s' on remote host" % (prefix)
)
output = SSH_utils.execute_remote_cmd(
ssh, "/usr/sbin/glite-wms-purgeStorage.sh -p /var/SandboxDir/%s -s" % (prefix)
)
utils.info("Check glite-wms-purgeStorage.sh output")
if output.find("%s: removed DONE job" % (JOBID)) != -1:
utils.info("glite-wms-purgeStorage.sh successfully remove the DONE job %s" % (JOBID))
else:
utils.error("glite-wms-purgeStorage.sh didn't remove successfully the DONE job %s" % (JOBID))
raise GeneralError(
"Check glite-wms-purgeStorage.sh",
"glite-wms-purgeStorage.sh didn't remove successfully the DONE job %s" % (JOBID),
)
utils.info("Check again job's status")
utils.job_status(JOBID)
if utils.get_job_status().find("Cleared") != -1:
utils.info("Job's final status after purge is Cleared")
utils.info("Check job's status reason")
status = utils.get_job_status_reason(JOBID)
if status.find("timed out, resource purge forced") != -1:
utils.info("Status reason is 'timed out, resource purge forced' as expected")
else:
utils.error(
"Status reason is %s while the expected is 'timed out, resource purge forced'" % (status)
)
raise GeneralError(
"Check job's status reason",
"Status reason is %s while the expected is 'timed out, resource purge forced'" % (status),
)
else:
utils.error(
"Job's final status after purge is not Cleared , instead we get %s" % (utils.get_job_status())
)
raise GeneralError(
"Check job final status after purge",
"Job's final status after purge is not Cleared , instead we get %s" % (utils.get_job_status()),
)
else:
utils.error("Job finishes with status: %s while expected 'Done'" % (utils.get_job_status()))
raise GeneralError(
"Check job final status",
"Job finishes with status: %s while expected 'Done'" % (utils.get_job_status()),
)
utils.info("TEST OK")
except (RunCommandError, GeneralError, TimeOutError), e:
utils.log_error("%s" % (utils.get_current_test()))
utils.log_error("Command: %s" % (e.expression))
utils.log_error("Message: %s" % (e.message))
utils.log_traceback("%s" % (utils.get_current_test()))
utils.log_traceback(traceback.format_exc())
return 1
示例11: test3
# 需要导入模块: import SSH_utils [as 别名]
# 或者: from SSH_utils import execute_remote_cmd [as 别名]
def test3(utils, ssh, title):
utils.show_progress(title)
utils.info(title)
try:
wms_location_var = SSH_utils.execute_remote_cmd(ssh, "echo $WMS_LOCATION_VAR")[:-1]
utils.info("Check inside $WMS_LOCATION_VAR/proxycache for expired proxies for more than 6 hours")
proxies = SSH_utils.execute_remote_cmd(ssh, "find %s/proxycache/ -name \*.pem" % (wms_location_var)).split("\n")
for proxy in proxies:
if proxy.strip() != "":
expiry_date = (
SSH_utils.execute_remote_cmd(ssh, "openssl x509 -in %s -noout -enddate" % (proxy.strip()))
.split("=")[1]
.strip("\n")
)
ddate_str = time.strptime(expiry_date, "%b %d %H:%M:%S %Y %Z")[0:8]
dt = datetime.datetime(
ddate_str[0], ddate_str[1], ddate_str[2], ddate_str[3], ddate_str[4], ddate_str[5], ddate_str[6]
)
now_dt = datetime.datetime.utcnow()
diff = now_dt - dt
minutes, seconds = divmod(diff.seconds, 60)
hours, minutes = divmod(minutes, 60)
if diff.days >= 0:
# Maybe it is necessary to check and minutes
if hours >= 6:
utils.error("Find expired proxy for more than 6 hours. Proxy is %s" % (proxy))
raise GeneralError(
"Check for expired proxies for more than 6 hours",
"Find expired proxy for more than 6 hours. Proxy is %s" % (proxy),
)
utils.info("Check if there are empty directories")
dirs = SSH_utils.execute_remote_cmd(ssh, "ls /%s/proxycache" % (wms_location_var)).split(" ")
for dir in dirs:
dir = dir.strip(" \n\t")
if dir.find("cache") == -1:
utils.info("Check directory: %s" % (dir))
subdirs = SSH_utils.execute_remote_cmd(
ssh, "find /var/proxycache/%s -name userproxy.pem | wc -l" % (dir)
)
total_subdirs = SSH_utils.execute_remote_cmd(
ssh, "ls -l /var/proxycache/%s | grep glite | wc -l" % (dir)
)
if total_subdirs == subdirs:
utils.info("Check OK, there are no empty directories in %s" % (dir))
else:
utils.error("Test Failed. There are empty directories in %s" % (dir))
raise GeneralError(
"Check for emptry directories", "Test Failed. There are empty directories in %s" % (dir)
)
utils.info("TEST OK")
except (RunCommandError, GeneralError, TimeOutError), e:
utils.log_error("%s" % (utils.get_current_test()))
utils.log_error("Command: %s" % (e.expression))
utils.log_error("Message: %s" % (e.message))
utils.log_traceback("%s" % (utils.get_current_test()))
utils.log_traceback(traceback.format_exc())
return 1
示例12: restore_configuration_file
# 需要导入模块: import SSH_utils [as 别名]
# 或者: from SSH_utils import execute_remote_cmd [as 别名]
def restore_configuration_file(utils,ssh):
utils.log_info("Restore initial version of glite-wms.conf file")
SSH_utils.execute_remote_cmd(utils,ssh, "cp -f /etc/glite-wms/glite_wms.conf.bak /etc/glite-wms/glite_wms.conf")
SSH_utils.execute_remote_cmd(utils,ssh,"/etc/init.d/glite-wms-wmproxy restart")
示例13: get_location_var
# 需要导入模块: import SSH_utils [as 别名]
# 或者: from SSH_utils import execute_remote_cmd [as 别名]
def get_location_var(utils,ssh):
return SSH_utils.execute_remote_cmd(utils,ssh,"echo $WMS_LOCATION_VAR")[:-1]
示例14: test2
# 需要导入模块: import SSH_utils [as 别名]
# 或者: from SSH_utils import execute_remote_cmd [as 别名]
def test2(utils,ssh,title):
utils.show_progress(title)
utils.info(title)
try:
limit_values="--load1 22 --load5 0.01 --load15 18 --memusage 99 --diskusage 95 --fdnum 1000 --jdnum 150000 --ftpconn 300"
job_submit="\"${WMS_LOCATION_SBIN}/glite_wms_wmproxy_load_monitor --oper jobSubmit %s\""%(limit_values)
job_register="\"${WMS_LOCATION_SBIN}/glite_wms_wmproxy_load_monitor --oper jobRegister %s\""%(limit_values)
utils.info("Set jobSubmit = %s; and jobRegister = %s; to glite_wms.conf at WMS"%(job_submit,job_register))
SSH_utils.change_remote_file(utils,ssh,"/etc/glite-wms/glite_wms.conf", ['jobSubmit','jobRegister'],['*','*'],[job_submit,job_register])
utils.info("Restart workload manager proxy glite-wms-wmproxy")
SSH_utils.execute_remote_cmd(ssh,"/etc/init.d/glite-wms-wmproxy restart")
utils.set_isb_jdl(utils.get_jdl_file())
utils.info("Submit a job , submission should be failed")
OUTPUT=utils.run_command_continue_on_error("glite-wms-job-submit %s --config %s %s"%(utils.get_delegation_options(),utils.get_config_file(),utils.get_jdl_file()),1).split("\n")
utils.info("Check failed message")
find=0
for line in OUTPUT:
if line.find("System load is too high")!=-1:
utils.info("Check OK, the detected failure reason is: 'System load is too high'")
find=1
break
if find==0:
utils.error("Faulure reason is not 'System load is too high' as expected.")
raise GeneralError("Check faulure reason","Failure reason is not 'System load is too high' as expected")
utils.info("Check if the detected threshold is for parameter --load5, 'Load Average(5 min)'")
find=0
for line in OUTPUT:
if line.find("Threshold for Load Average(5 min):")!=-1:
utils.info("Check OK, detected threshold is for parameter --load5 'Load Average5 min)' as expected")
find=1
break
if find==0:
utils.error("Detected threshold is not for parameter load5 ('Load Average(5 min)') as expected")
raise GeneralError("Check the parameter of the limiter mechanism","Detected threshold is not for parameter load5 ('Load Average(5 min)') as expected ")
for line in OUTPUT:
if line.find("Method")!=-1:
utils.info("Get Method: %s"%(line))
break
utils.info("Test OK")
utils.info("Restore initial version of glite-wms.conf file")
SSH_utils.execute_remote_cmd(ssh, "cp -f /etc/glite-wms/glite_wms.conf.bak /etc/glite-wms/glite_wms.conf")
SSH_utils.execute_remote_cmd(ssh,"/etc/init.d/glite-wms-wmproxy restart")
except (RunCommandError,GeneralError,TimeOutError) , e :
utils.log_error("%s"%(utils.get_current_test()))
utils.log_error("Command: %s"%(e.expression))
utils.log_error("Message: %s"%(e.message))
utils.log_traceback("%s"%(utils.get_current_test()))
utils.log_traceback(traceback.format_exc())
utils.info("Restore initial version of glite-wms.conf file")
SSH_utils.execute_remote_cmd(ssh, "cp -f /etc/glite-wms/glite_wms.conf.bak /etc/glite-wms/glite_wms.conf")
SSH_utils.execute_remote_cmd(ssh,"/etc/init.d/glite-wms-wmproxy restart")
return 1
示例15: unset_drain
# 需要导入模块: import SSH_utils [as 别名]
# 或者: from SSH_utils import execute_remote_cmd [as 别名]
def unset_drain(utils,ssh):
utils.log_info("Unset WMS from draining mode")
SSH_utils.execute_remote_cmd(utils,ssh,"rm -f /var/.drain")