Add argument for renaming result file

A user can use the -r/--result-file-tag argument to change the name of the output
json file. The name will always include the subunit stream ID, for example if a user
input '--result-file-tag my-test' and the next-stream id was "2", the output filename
would be my-test-2.json.

Change-Id: Ie7302470fe1b63a21f61451ef62687634b6e0932
This commit is contained in:
Paul Van Eck 2015-02-03 11:26:54 -08:00 committed by Sergey Slipushenko
parent b4fe4b4dfa
commit 748d259296
3 changed files with 49 additions and 1 deletions

View File

@ -51,6 +51,9 @@ We've created an "easy button" for Ubuntu, Centos, RHEL and openSuSe.
default Refstack API server or the server specified by --url.
e. Adding --url option will allow you to change where test results should
be uploaded.
f. Adding -r option with a string will prefix the JSON result file with the
given string (e.g. '-r my-test' will yield a result file like
'my-test-0.json').
**Upload:**

View File

@ -226,6 +226,13 @@ class RefstackClient:
self.logger.info("Number of passed tests: %d" % len(results))
content = self._form_result_content(cpid, duration, results)
if self.args.result_tag:
file_name = os.path.basename(results_file)
directory = os.path.dirname(results_file)
file_name = '-'.join([self.args.result_tag, file_name])
results_file = os.path.join(directory, file_name)
json_path = results_file + ".json"
self._save_json_results(content, json_path)
self.logger.info('JSON results saved in: %s' % json_path)
@ -233,7 +240,6 @@ class RefstackClient:
# If the user specified the upload argument, then post
# the results.
if self.args.upload:
content = self._form_result_content(cpid, duration, results)
self.post_results(self.args.url, content)
else:
self.logger.error("Problem executing Tempest script. Exit code %d",
@ -299,6 +305,14 @@ def parse_cli_args(args=None):
help='Path of the Tempest configuration file to '
'use.')
parser_test.add_argument('-r', '--result-file-tag',
action='store',
required=False,
dest='result_tag',
type=str,
help='Specify a string to prefix the result '
'file with to easier distinguish them. ')
parser_test.add_argument('-t', '--test-cases',
action='store',
required=False,

View File

@ -316,6 +316,37 @@ class TestRefstackClient(unittest.TestCase):
client.tempest_dir = "/does/not/exist"
self.assertRaises(SystemExit, client.test)
def test_run_tempest_result_tag(self):
"""
Check that the result JSON file is renamed with the result file tag
when the --result-file-tag argument is passed in.
"""
argv = self.mock_argv(verbose='-vv')
argv.extend(['--result-file-tag', 'my-test'])
args = rc.parse_cli_args(argv)
client = rc.RefstackClient(args)
client.tempest_dir = self.test_path
mock_popen = self.patch(
'refstack_client.refstack_client.subprocess.Popen',
return_value=MagicMock(returncode=0))
self.patch("os.path.isfile", return_value=True)
self.mock_keystone()
client.get_passed_tests = MagicMock(return_value=['test'])
client._save_json_results = MagicMock()
client.test()
mock_popen.assert_called_with(
('%s/run_tempest.sh' % self.test_path, '-C', self.conf_file_name,
'-V', '-t', '--', 'tempest.api.compute'),
stderr=None
)
directory = os.path.dirname(os.path.realpath(__file__))
# Since '1' is in the next-stream file, we expect the JSON output file
# to be 'my-test-1.json'.
expected_file = directory + "/.testrepository/my-test-1.json"
client._save_json_results.assert_called_with(mock.ANY, expected_file)
def test_failed_run(self):
"""
Test when the Tempest script returns a non-zero exit code.