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:
Catherine Diep 2017-04-06 16:51:30 -07:00
parent dab1b18435
commit f7a9226899
2 changed files with 43 additions and 1 deletions

View File

@ -418,7 +418,13 @@ class RefstackClient:
# get whitelist
list_file = parser.create_whitelist(self.args.test_list)
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:
self.logger.error("Error normalizing passed in test list.")
exit(1)

View File

@ -660,6 +660,7 @@ class TestRefstackClient(unittest.TestCase):
'refstack_client.refstack_client.subprocess.Popen',
return_value=MagicMock(returncode=0))
self.patch("os.path.isfile", return_value=True)
self.patch("os.path.getsize", return_value=4096)
self.mock_data()
client.get_passed_tests = MagicMock(return_value=[{'name': 'test'}])
client._save_json_results = MagicMock()
@ -884,3 +885,38 @@ class TestRefstackClient(unittest.TestCase):
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'), 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)