Fix to not run any test when the input test list is empty
When running refstack-client with the "--test-list" option, the entire API tests were run when the input test list file has no content. The correct behavior should be that no test would be run if the test-list is empty. Closes-Bug: #1677153 Change-Id: I0049f185e8c771419c0464a81d4f631ee5946ef2
This commit is contained in:
@@ -418,7 +418,13 @@ class RefstackClient:
|
|||||||
# get whitelist
|
# get whitelist
|
||||||
list_file = parser.create_whitelist(self.args.test_list)
|
list_file = parser.create_whitelist(self.args.test_list)
|
||||||
if list_file:
|
if list_file:
|
||||||
cmd += ('--whitelist_file', list_file)
|
if os.path.getsize(list_file) > 0:
|
||||||
|
cmd += ('--whitelist_file', list_file)
|
||||||
|
else:
|
||||||
|
self.logger.error("Test list is either empty or no valid "
|
||||||
|
"test cases for the tempest "
|
||||||
|
"environment were found.")
|
||||||
|
exit(1)
|
||||||
else:
|
else:
|
||||||
self.logger.error("Error normalizing passed in test list.")
|
self.logger.error("Error normalizing passed in test list.")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|||||||
@@ -660,6 +660,7 @@ class TestRefstackClient(unittest.TestCase):
|
|||||||
'refstack_client.refstack_client.subprocess.Popen',
|
'refstack_client.refstack_client.subprocess.Popen',
|
||||||
return_value=MagicMock(returncode=0))
|
return_value=MagicMock(returncode=0))
|
||||||
self.patch("os.path.isfile", return_value=True)
|
self.patch("os.path.isfile", return_value=True)
|
||||||
|
self.patch("os.path.getsize", return_value=4096)
|
||||||
self.mock_data()
|
self.mock_data()
|
||||||
client.get_passed_tests = MagicMock(return_value=[{'name': 'test'}])
|
client.get_passed_tests = MagicMock(return_value=[{'name': 'test'}])
|
||||||
client._save_json_results = MagicMock()
|
client._save_json_results = MagicMock()
|
||||||
@@ -884,3 +885,38 @@ class TestRefstackClient(unittest.TestCase):
|
|||||||
conf_file = os.path.basename(self.conf_file_name)
|
conf_file = os.path.basename(self.conf_file_name)
|
||||||
self.assertEqual(os.environ.get('TEMPEST_CONFIG_DIR'), conf_dir)
|
self.assertEqual(os.environ.get('TEMPEST_CONFIG_DIR'), conf_dir)
|
||||||
self.assertEqual(os.environ.get('TEMPEST_CONFIG'), conf_file)
|
self.assertEqual(os.environ.get('TEMPEST_CONFIG'), conf_file)
|
||||||
|
|
||||||
|
@mock.patch('refstack_client.list_parser.TestListParser.create_whitelist')
|
||||||
|
def test_run_tempest_with_empty_test_list(self, mock_whitelist):
|
||||||
|
"""Test that refstack-client can handle an empty test list file."""
|
||||||
|
argv = self.mock_argv(verbose='-vv')
|
||||||
|
argv.extend(['--test-list', 'foo.txt'])
|
||||||
|
args = rc.parse_cli_args(argv)
|
||||||
|
client = rc.RefstackClient(args)
|
||||||
|
self.mock_data()
|
||||||
|
self.patch(
|
||||||
|
'refstack_client.refstack_client.subprocess.Popen',
|
||||||
|
return_value=MagicMock(returncode=0))
|
||||||
|
client._get_keystone_config = MagicMock(return_value=self.v2_config)
|
||||||
|
client.tempest_dir = self.test_path
|
||||||
|
self.patch("os.path.isfile", return_value=True)
|
||||||
|
empty_file = tempfile.NamedTemporaryFile()
|
||||||
|
mock_whitelist.return_value = empty_file.name
|
||||||
|
self.assertRaises(SystemExit, client.test)
|
||||||
|
|
||||||
|
def test_run_tempest_with_non_exist_test_list_file(self):
|
||||||
|
"""Test that refstack-client runs with a nonexistent test list file."""
|
||||||
|
argv = self.mock_argv(verbose='-vv')
|
||||||
|
argv.extend(['--test-list', 'foo.txt'])
|
||||||
|
args = rc.parse_cli_args(argv)
|
||||||
|
client = rc.RefstackClient(args)
|
||||||
|
self.mock_data()
|
||||||
|
self.patch(
|
||||||
|
'refstack_client.list_parser.TestListParser._get_tempest_test_ids',
|
||||||
|
return_value={'foo': ''})
|
||||||
|
self.patch(
|
||||||
|
'refstack_client.refstack_client.subprocess.Popen',
|
||||||
|
return_value=MagicMock(returncode=0))
|
||||||
|
client._get_keystone_config = MagicMock(return_value=self.v2_config)
|
||||||
|
client.tempest_dir = self.test_path
|
||||||
|
self.assertRaises(IOError, client.test)
|
||||||
|
|||||||
Reference in New Issue
Block a user