From 0de601f65e11bdff78d473e46e1328ebb7b5586a Mon Sep 17 00:00:00 2001 From: Paul Van Eck Date: Wed, 28 Jan 2015 00:17:10 -0800 Subject: [PATCH] Remove upload as default behavior after testing The --offline argument was removed and an --upload argument was added. Adding this argument will have your test results be uploaded to the default Refstack API server or the server specified by --url. Story: https://storyboard.openstack.org/#!/story/2000136 Change-Id: I93302e1cacdd9d0f996ea5545fbe21e1fb6aaa23 --- README.rst | 10 ++--- refstack_client/refstack_client.py | 12 +++--- refstack_client/tests/unit/test_client.py | 51 ++++++++++++++--------- 3 files changed, 44 insertions(+), 29 deletions(-) diff --git a/README.rst b/README.rst index 1015f43..da49539 100644 --- a/README.rst +++ b/README.rst @@ -40,14 +40,14 @@ We've created an "easy button" for Ubuntu, Centos, RHEL and openSuSe. c. Adding -t option will only test a particular test case or a test group. This option can be used for quick verification of the target test cases (i.e. -t "tempest.api.identity.admin.test_roles"). - d. Adding --url option will upload the test results to the specified - Refstack API server instead of the default Refstack API server. - server instead of the default Refstack API server. - e. Adding --offline option will have your test results not be uploaded. + d. Adding --upload option will have your test results be uploaded to the + 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. **Upload:** - If you previously ran a test with refstack-client using the --offline + If you previously ran a test with refstack-client without the --upload option, you can upload your results to a Refstack API server by using the following command: diff --git a/refstack_client/refstack_client.py b/refstack_client/refstack_client.py index 28fe33f..1fb3cfb 100755 --- a/refstack_client/refstack_client.py +++ b/refstack_client/refstack_client.py @@ -230,9 +230,9 @@ class RefstackClient: self._save_json_results(content, json_path) self.logger.info('JSON results saved in: %s' % json_path) - # If the user did not specify the offline argument, then upload + # If the user specified the upload argument, then post # the results. - if not self.args.offline: + if self.args.upload: content = self._form_result_content(cpid, duration, results) self.post_results(self.args.url, content) else: @@ -307,10 +307,12 @@ def parse_cli_args(args=None): help='Specify a subset of test cases to run ' '(e.g. --test-cases tempest.api.compute).') - parser_test.add_argument('--offline', + parser_test.add_argument('-u', '--upload', action='store_true', - help='Do not upload test results after running ' - 'Tempest.') + required=False, + help='After running Tempest, upload the test ' + 'results to the default Refstack API server ' + 'or the server specified by --url.') parser_test.set_defaults(func="test") return parser.parse_args(args=args) diff --git a/refstack_client/tests/unit/test_client.py b/refstack_client/tests/unit/test_client.py index aef0367..702bf49 100755 --- a/refstack_client/tests/unit/test_client.py +++ b/refstack_client/tests/unit/test_client.py @@ -221,6 +221,30 @@ class TestRefstackClient(unittest.TestCase): expected = [{'name': 'tempest.passed.test'}] self.assertEqual(expected, results) + def test_post_results(self): + """ + Test the post_results method, ensuring a requests call is made. + """ + args = rc.parse_cli_args(self.mock_argv()) + client = rc.RefstackClient(args) + client.logger.info = MagicMock() + content = {'duration_seconds': 0, + 'cpid': 'test-id', + 'results': [{'name': 'tempest.passed.test'}]} + expected_response = json.dumps({'test_id': 42}) + + @httmock.urlmatch(netloc=r'(.*\.)?127.0.0.1$', path='/v1/results/') + def refstack_api_mock(url, request): + return expected_response + + with httmock.HTTMock(refstack_api_mock): + client.post_results("http://127.0.0.1", content) + + client.logger.info.assert_called_with( + 'http://127.0.0.1/v1/results/ Response: ' + '%s' % expected_response + ) + def test_run_tempest(self): """ Test that the test command will run the tempest script using the @@ -237,15 +261,8 @@ class TestRefstackClient(unittest.TestCase): client.get_passed_tests = MagicMock(return_value=[{'name': 'test'}]) client.logger.info = MagicMock() client._save_json_results = MagicMock() - - expected_content = json.dumps({'test_id': 42}) - - @httmock.urlmatch(netloc=r'(.*\.)?127.0.0.1$', path='/v1/results/') - def refstack_api_mock(url, request): - return expected_content - - with httmock.HTTMock(refstack_api_mock): - client.test() + client.post_results = MagicMock() + client.test() mock_popen.assert_called_with( ('%s/run_tempest.sh' % self.test_path, '-C', self.conf_file_name, @@ -253,17 +270,15 @@ class TestRefstackClient(unittest.TestCase): stderr=None ) - client.logger.info.assert_called_with( - 'http://127.0.0.1/v1/results/ Response: ' - '%s' % expected_content - ) + self.assertFalse(client.post_results.called) - def test_run_tempest_offline(self): + def test_run_tempest_upload(self): """ - Test that the test command will run the tempest script in offline mode. + Test that the test command will run the tempest script and call + post_results when the --upload argument is passed in. """ argv = self.mock_argv(verbose='-vv') - argv.append('--offline') + argv.append('--upload') args = rc.parse_cli_args(argv) client = rc.RefstackClient(args) client.tempest_dir = self.test_path @@ -282,9 +297,7 @@ class TestRefstackClient(unittest.TestCase): stderr=None ) - # The method post_results should not be called if --offline was - # specified. - self.assertFalse(client.post_results.called) + self.assertTrue(client.post_results.called) def test_run_tempest_no_conf_file(self): """