我想从运行测试命令时生成的输出文件中复制字符串

时间:2018-11-08 10:03:19

标签: python

当我运行特定的测试用例时,会创建一个文件夹-/ts/runtime/fvndd_dedicated.p.rhea-c4.181108.033014,每次都不同,并且该值将在输出文件中。现在,我想将此文件夹名称从输出文件复制到变量。我已经在屏幕截图中共享了文件格式。有人可以帮我吗?enter image description here

#!/usr/bin/python

import sys, os
import shlex, subprocess

sut = sys.argv[1]
pp = sys.argv[2]
sut_adapter = sys.argv[3]
pp_adapter = sys.argv[4]
switch_ip = sys.argv[5]
switch = sys.argv[6]
node_type = sys.argv[7]
hmc_name = sys.argv[8]
gsa_id = sys.argv[9]
gsa_pass = sys.argv[10]

f_name = sys.argv[1] + "_" + sys.argv[2] + ".p.config" 

args_str1="/Jenkins/config_gen.pl {} {} {} {} {} {} {} {}".format(sut, pp, sut_adapter, pp_adapter, switch_ip, switch, node_type, hmc_name)

def test_install():

        os.system("tar xvf FVSDD_Automation.tar")
        os.chdir("/FVSDD_Automation")

        arg_str = "AUTO_INSTALL.pl -i all {} {}".format(gsa_id, gsa_pass)
        arg = shlex.split(arg_str)
        pipe = subprocess.Popen(arg,bufsize=-1,stdin=subprocess.PIPE,stderr=subprocess.PIPE)
        pipe.communicate()
        print pipe.returncode

def test_run():

        args_str2="/framework/scripts/ts//ts /testrepo/lokesh/NDD/fvndd_dedicated.p -g /Jenkins/config/{} >output.txt".format(f_name)

        args2 = shlex.split(args_str2)
        pipe = subprocess.Popen(args2,bufsize=-1,stdin=subprocess.PIPE,stderr=subprocess.PIPE)
        print pipe.communicate()
        print pipe.returncode
        sys.stdin.close()
        sys.exit(os.EX_OK)

def main():

        args = "ls -d /framework"
        arg = shlex.split(args)
        p = subprocess.Popen(arg,bufsize=-1,stdin=subprocess.PIPE,stderr=subprocess.PIPE)
        p.communicate()
        output = p.returncode

        if output != 0:

                  test_install()

        else:

                  print (" The TS Framework installation is already done ")

        os.chdir("/Jenkins/config")
        if not os.path.exists(f_name):

                  args = shlex.split(args_str1)
                  pipe = subprocess.Popen(args,bufsize=-1,stdin=subprocess.PIPE,stderr=subprocess.PIPE)
                  print pipe.communicate()
                  print pipe.returncode 

        else:

                   print (" The configuration file %s already exists, proceeding to run the testcases "%f_name)
        test_run()

if __name__== "__main__":
        main()

0 个答案:

没有答案