linux 写目录错误代码2,python - IO错误:[错误2]没有这样的文件或目录 - 在Linux中,使用绝对路径 - SO中文参考 - www.soinside.com...

我苦苦寻找这种解决方案。我使用的文件系统绝对存在的绝对路径。当完全相同的路径与同一个脚本使用

if host.file(logPath).exists:

print("Exists: " + logPath)

我得到

Exists: /var/opt/jws/jws3.0/v7/testinfra_node1/logs/catalina.out

但是,试图在:

with open(logPath, "rt") as log:

我正进入(状态:

> with open(logPath, "rt") as log:

E IOError: [Errno 2] No such file or directory: '/var/opt/jws/jws3.0/v7/testinfra_node1/logs/catalina.out'

这里是整个代码(这是测试JWT安装testinfra脚本):

import pytest

import testinfra

import time

import os

@pytest.mark.parametrize("jws_version", [("3.0")])

def test_server_recycle(host, jws_version):

instances = host.check_output("cat /var/opt/jws/jws" + jws_version + "/init/init_instances | grep -oP '(\/.*?\/)((?:[^\/]|\\\\/)+?)(?:(?

last = ""

for last in iter(instances.splitlines()):

pass

last = last.strip().encode('ascii','ignore')

print(last)

instanceName = ""

for instanceName in iter(last.split("/")):

pass

print(instanceName)

binPath = last + "/bin/"

logDir = last + "/logs/"

logPath = os.path.join(logDir, "catalina.out")

print(logPath)

runningAt0 = isInstanceRunning(host, instanceName)

if host.file(logPath).exists:

print("Exists: " + logPath)

if (runningAt0):

with host.sudo():

host.run(os.path.join(binPath, "shutdown.sh"))

with open(logPath, "rt") as log:

result = waitForEntry(log, "INFO org.apache.catalina.core.StandardService- Stopping service Catalina","ERROR")

assert not result.eq("ERROR")

assert not isInstanceRunning(host, instanceName)

host.run(os.path.join(binPath, "/bin/startup.sh"))

with open(logPath, "rt") as log:

result = waitForEntry(log, "INFO org.apache.catalina.startup.Catalina- Server startup in","ERROR")

assert not result.eq("ERROR")

assert isInstanceRunning(host, instanceName)

else:

with host.sudo():

host.run(os.path.join(binPath, "startup.sh"))

with open(logPath, "rt") as log:

result = waitForEntry(log, "INFO org.apache.catalina.core.StandardService- Stopping service Catalina","ERROR")

assert not result.eq("ERROR")

assert isInstanceRunning(host, instanceName)

host.run(os.path.join(binPath, "shutdown.sh"))

with open(logPath, "rt") as log:

result = waitForEntry(log, "INFO org.apache.catalina.startup.Catalina- Server startup in","ERROR")

assert not result.eq("ERROR")

assert not isInstanceRunning(host, instanceName)

def isInstanceRunning(host, instanceName):

processes = host.check_output("ps auwwx | grep catalina.startup.Bootstrap")

if "-Dtomcat.inst.name=" + instanceName in processes:

return True

else:

return False

def waitForEntry(file, entry1, entry2):

while 1:

file.seek(0,2)

line = file.readline()

if entry1 in line:

return entry1

else:

if entry2 in line:

return entry2

else:

time.sleep(0.1)

代替

host.file(logPath).exists

我一直也在尝试

print(host.check_output("cat " + logPath))

它很好地打印文件内容。

任何想法如何处理呢?提前谢谢了!

编辑:这是我如何执行该脚本:

po.test -in主机= Userov @ NOSTA tomchat_test_retsikle.po --sudu

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值