diff --git a/README.rst b/README.rst index 44b7203..ab18c51 100644 --- a/README.rst +++ b/README.rst @@ -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:** diff --git a/refstack_client/refstack_client.py b/refstack_client/refstack_client.py index e1069cc..11caa3c 100755 --- a/refstack_client/refstack_client.py +++ b/refstack_client/refstack_client.py @@ -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, diff --git a/refstack_client/tests/unit/test_client.py b/refstack_client/tests/unit/test_client.py index 702bf49..4f655cd 100755 --- a/refstack_client/tests/unit/test_client.py +++ b/refstack_client/tests/unit/test_client.py @@ -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.