1

I have written the below script to store the output of yardstick command into a variable(output) and display the value of variable.

The script is executing fine and the results are displayed in the console. After executing the script, I want to store the below details into a variable.But the below log details are not stored into output variable. Please help me to solve this issue?

Note: I am able to get the output of unix command into the output variable. Who, ls -ltr etc., Operating system: Ubuntu Programming language: Python Yardstick command to execute the opnfv test case. Code:

from time import sleep

import sys

import os

import subprocess

import pexpect

import time



script_exec_cmd="yardstick -d task start /home/test_cases/opnfv_yardstick_tc002.yaml"

output = subprocess.check_output(script_exec_cmd, shell=True)

sleep(100)

print '********************************'

print "output === >>" + output

print '****************************'

Information from console is mentioned below

2020-03-16 12:22:11,895 [DEBUG] yardstick.benchmark.runners.duration duration.py:124 queue.qsize() = 1

2020-03-16 12:22:11,895 [DEBUG] yardstick.benchmark.runners.duration duration.py:125 output_queue.qsize() = 0

2020-03-16 12:22:11,919 [DEBUG] yardstick.benchmark.runners.base base.py:282 result_queue size 1

2020-03-16 12:22:11,919 [INFO] yardstick.benchmark.core.task task.py:285 Runner ended

2020-03-16 12:22:11,920 [INFO] yardstick.benchmark.core.task task.py:129 Testcase: "opnfv_yardstick_tc002" SUCCESS!!!

2020-03-16 12:22:11,920 [INFO] yardstick.benchmark.contexts.heat heat.py:472 Undeploying context 'demo-b1a42587' START

2020-03-16 12:22:53,560 [INFO] yardstick.benchmark.contexts.heat heat.py:475 Undeploying context 'demo-b1a42587' DONE

2020-03-16 12:22:53,560 [INFO] yardstick.benchmark.core.task task.py:148 Task /home/ test_cases/opnfv_yardstick_tc002.yaml finished in 242 secs

2020-03-16 12:22:53,565 [INFO] yardstick.benchmark.core.task task.py:169 Report can be found in '/tmp/report.html'

2020-03-16 12:22:53,566 [INFO] yardstick.benchmark.core.task task.py:157 Total finished in 242 secs

2020-03-16 12:22:53,566 [INFO] yardstick.benchmark.core.task task.py:160 To generate report, execute command "yardstick report generate b1a42587-2285-4bb4-9805-e1e6bcebcc11 <YAML_NAME>"

2020-03-16 12:22:53,566 [INFO] yardstick.benchmark.core.task task.py:161 Task ALL DONE, exiting

2020-03-16 12:22:53,566 [INFO] yardstick.cmd.commands.task task.py:61 Task SUCCESS

2020-03-16 12:22:53,567 [DEBUG] yardstick.benchmark.runners.base base.py:147 Terminating all runners

********************************

output === >> Writing /home/yardstick/resources/files/yardstick_key-demo-b1a42587 ...



****************************
smci
  • 32,567
  • 20
  • 113
  • 146
Karthika
  • 109
  • 2
  • 3
  • 6
  • 2
    Did they get written to stderr rather than stdout? See the doc for the [subprocess functions](https://docs.python.org/3/library/subprocess.html) esp. about stderr output. You can first find out on the Unix command line what bits of output go to stderr vs stdout; using `cmd > STDOUT 2> STDERR` – smci Mar 16 '20 at 07:34
  • `script_exec_cmd` must be a list of string, not a string. `script_exec_cmd = ['yardstick', '-d', 'task...'] – smci Mar 16 '20 at 07:50
  • I think this answers your question? [How do you use subprocess.check\_output() in Python?](https://stackoverflow.com/questions/14078117/how-do-you-use-subprocess-check-output-in-python) – smci Mar 16 '20 at 07:50
  • Thanks a lot. It worked when I convert the subprocess into pexpect. I will also try the logic mentioned in the comment. – Karthika Mar 16 '20 at 16:50
  • Karthika: `subprocess` works fine, you just need to fix your syntax. See the many Q&A here on that. – smci Mar 17 '20 at 02:47

0 Answers0