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
This commit is contained in:
Paul Van Eck
2015-01-28 00:17:10 -08:00
parent 445e643855
commit 0de601f65e
3 changed files with 44 additions and 29 deletions

View File

@@ -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. 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 This option can be used for quick verification of the target test cases
(i.e. -t "tempest.api.identity.admin.test_roles"). (i.e. -t "tempest.api.identity.admin.test_roles").
d. Adding --url option will upload the test results to the specified d. Adding --upload option will have your test results be uploaded to the
Refstack API server instead of the default Refstack API server. default Refstack API server or the server specified by --url.
server instead of the default Refstack API server. e. Adding --url option will allow you to change where test results should
e. Adding --offline option will have your test results not be uploaded. be uploaded.
**Upload:** **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 option, you can upload your results to a Refstack API server by using the
following command: following command:

View File

@@ -230,9 +230,9 @@ class RefstackClient:
self._save_json_results(content, json_path) self._save_json_results(content, json_path)
self.logger.info('JSON results saved in: %s' % 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. # the results.
if not self.args.offline: if self.args.upload:
content = self._form_result_content(cpid, duration, results) content = self._form_result_content(cpid, duration, results)
self.post_results(self.args.url, content) self.post_results(self.args.url, content)
else: else:
@@ -307,10 +307,12 @@ def parse_cli_args(args=None):
help='Specify a subset of test cases to run ' help='Specify a subset of test cases to run '
'(e.g. --test-cases tempest.api.compute).') '(e.g. --test-cases tempest.api.compute).')
parser_test.add_argument('--offline', parser_test.add_argument('-u', '--upload',
action='store_true', action='store_true',
help='Do not upload test results after running ' required=False,
'Tempest.') 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") parser_test.set_defaults(func="test")
return parser.parse_args(args=args) return parser.parse_args(args=args)

View File

@@ -221,6 +221,30 @@ class TestRefstackClient(unittest.TestCase):
expected = [{'name': 'tempest.passed.test'}] expected = [{'name': 'tempest.passed.test'}]
self.assertEqual(expected, results) 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): def test_run_tempest(self):
""" """
Test that the test command will run the tempest script using the Test that the test command will run the tempest script using the
@@ -237,14 +261,7 @@ class TestRefstackClient(unittest.TestCase):
client.get_passed_tests = MagicMock(return_value=[{'name': 'test'}]) client.get_passed_tests = MagicMock(return_value=[{'name': 'test'}])
client.logger.info = MagicMock() client.logger.info = MagicMock()
client._save_json_results = MagicMock() client._save_json_results = MagicMock()
client.post_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.test()
mock_popen.assert_called_with( mock_popen.assert_called_with(
@@ -253,17 +270,15 @@ class TestRefstackClient(unittest.TestCase):
stderr=None stderr=None
) )
client.logger.info.assert_called_with( self.assertFalse(client.post_results.called)
'http://127.0.0.1/v1/results/ Response: '
'%s' % expected_content
)
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 = self.mock_argv(verbose='-vv')
argv.append('--offline') argv.append('--upload')
args = rc.parse_cli_args(argv) args = rc.parse_cli_args(argv)
client = rc.RefstackClient(args) client = rc.RefstackClient(args)
client.tempest_dir = self.test_path client.tempest_dir = self.test_path
@@ -282,9 +297,7 @@ class TestRefstackClient(unittest.TestCase):
stderr=None stderr=None
) )
# The method post_results should not be called if --offline was self.assertTrue(client.post_results.called)
# specified.
self.assertFalse(client.post_results.called)
def test_run_tempest_no_conf_file(self): def test_run_tempest_no_conf_file(self):
""" """