summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2018-07-27 14:10:12 +0200
committerCédric Ollivier <cedric.ollivier@orange.com>2018-07-27 16:05:57 +0200
commit355c8b40907b0178774ddc6d3defcd5ec4236c0c (patch)
tree5658e1cae59f944d41c33227e03244e97b7a2f65
parent2ffe21e6510a2e52fb0caa457be5556592a8fe12 (diff)
Stop redirecting output to json files
Rally may print additional data to console which results in an invalid json files. The json files are generated via rally instead of dumping stdout. It's mandatory to backport the next bugfix [1] in stable/fraser. [1] https://gerrit.opnfv.org/gerrit/#/c/60265/ Change-Id: Ifbd90e685a7b52c70b3110a46e3c7991eddc05f4 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com> (cherry picked from commit 18c96abe8b6a3d6e919ff7ba64952454830357b3)
-rw-r--r--functest/opnfv_tests/openstack/rally/rally.py25
-rw-r--r--functest/tests/unit/openstack/rally/test_rally.py1
2 files changed, 11 insertions, 15 deletions
diff --git a/functest/opnfv_tests/openstack/rally/rally.py b/functest/opnfv_tests/openstack/rally/rally.py
index 7d91720a3..446e596c0 100644
--- a/functest/opnfv_tests/openstack/rally/rally.py
+++ b/functest/opnfv_tests/openstack/rally/rally.py
@@ -297,23 +297,17 @@ class RallyBase(singlevm.VmReady1):
# put detailed result to log
cmd = (["rally", "task", "detailed", "--uuid", task_id])
LOGGER.debug('running command: %s', cmd)
- proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
- json_detailed = self.get_cmd_output(proc)
- LOGGER.info('%s', json_detailed)
+ output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
+ LOGGER.info("%s\n%s", " ".join(cmd), output)
# save report as JSON
- cmd = (["rally", "task", "report", "--json", "--uuid", task_id])
- LOGGER.debug('running command: %s', cmd)
- with open(os.devnull, 'w') as devnull:
- proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
- stderr=devnull)
- json_results = self.get_cmd_output(proc)
report_json_name = 'opnfv-{}.json'.format(test_name)
report_json_dir = os.path.join(self.RESULTS_DIR, report_json_name)
- with open(report_json_dir, 'w') as r_file:
- LOGGER.debug('saving json file')
- r_file.write(json_results)
+ cmd = (["rally", "task", "report", "--json", "--uuid", task_id,
+ "--out", report_json_dir])
+ LOGGER.debug('running command: %s', cmd)
+ output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
+ LOGGER.info("%s\n%s", " ".join(cmd), output)
# save report as HTML
report_html_name = 'opnfv-{}.html'.format(test_name)
@@ -321,9 +315,10 @@ class RallyBase(singlevm.VmReady1):
cmd = (["rally", "task", "report", "--html", "--uuid", task_id,
"--out", report_html_dir])
LOGGER.debug('running command: %s', cmd)
- with open(os.devnull, 'w') as devnull:
- subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=devnull)
+ output = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
+ LOGGER.info("%s\n%s", " ".join(cmd), output)
+ json_results = open(report_json_dir).read()
self._append_summary(json_results, test_name)
# parse JSON operation result
diff --git a/functest/tests/unit/openstack/rally/test_rally.py b/functest/tests/unit/openstack/rally/test_rally.py
index e7805c72f..6a9581af0 100644
--- a/functest/tests/unit/openstack/rally/test_rally.py
+++ b/functest/tests/unit/openstack/rally/test_rally.py
@@ -267,6 +267,7 @@ class OSRallyTesting(unittest.TestCase):
'get_cmd_output', return_value='')
@mock.patch('functest.opnfv_tests.openstack.rally.rally.os.path.exists',
return_value=True)
+ @mock.patch('subprocess.check_output')
@mock.patch('functest.opnfv_tests.openstack.rally.rally.subprocess.Popen')
@mock.patch('functest.opnfv_tests.openstack.rally.rally.os.makedirs')
@mock.patch('functest.opnfv_tests.openstack.rally.rally.LOGGER.info')