diff --git a/teuthology/orchestra/run.py b/teuthology/orchestra/run.py index 085eea7151..03d49bae7a 100644 --- a/teuthology/orchestra/run.py +++ b/teuthology/orchestra/run.py @@ -3,7 +3,6 @@ """ import io -from pathlib import Path from paramiko import ChannelFile @@ -187,7 +186,7 @@ def _raise_for_status(self): if self.unittest_xml: error_msg = None try: - error_msg = find_unittest_error(self.unittest_xml) + error_msg = find_unittest_error(self.unittest_xml, self.client) except Exception as exc: self.logger.error('Unable to scan logs, exception occurred: {exc}'.format(exc=repr(exc))) if error_msg: @@ -238,7 +237,7 @@ def __repr__(self): name=self.hostname, ) -def find_unittest_error(xmlfile_path): +def find_unittest_error(xmlfile_path, client): """ Load the unit test output XML file and parse for failures and errors. @@ -247,9 +246,9 @@ def find_unittest_error(xmlfile_path): if not xmlfile_path: return "No XML file was passed to process!" try: - xml_path = Path(xmlfile_path) - if xml_path.is_file(): - tree = etree.parse(xmlfile_path) + (_, stdout, _) = client.exec_command(f'cat {xmlfile_path}', timeout=200) + if stdout: + tree = etree.parse(stdout) failed_testcases = tree.xpath('.//failure/.. | .//error/..') if len(failed_testcases) == 0: log.debug("No failures or errors found in unit test's output xml file.") @@ -262,7 +261,7 @@ def find_unittest_error(xmlfile_path): testcase1_casename = testcase1.get("name", "test-name") testcase1_suitename = testcase1.get("classname", "suite-name") testcase1_msg = f'Test `{testcase1_casename}` of `{testcase1_suitename}` did not pass.' - + for child in testcase1: if child.tag in ['failure', 'error']: fault_kind = child.tag.upper() @@ -272,7 +271,8 @@ def find_unittest_error(xmlfile_path): break return (error_message + testcase1_msg).replace("\n", " ") - return f'XML output not found at `{xmlfile_path}`!' + else: + return f'XML output not found at `{str(xmlfile_path)}`!' except Exception as exc: raise Exception("Somthing went wrong while searching for error in XML file: " + repr(exc)) diff --git a/teuthology/orchestra/test/test_run.py b/teuthology/orchestra/test/test_run.py index 14b4b98f0a..177bc8b45f 100644 --- a/teuthology/orchestra/test/test_run.py +++ b/teuthology/orchestra/test/test_run.py @@ -1,4 +1,5 @@ from io import BytesIO +import os import paramiko import socket @@ -264,8 +265,14 @@ def test_copy_and_close(self): run.copy_and_close(b'', MagicMock()) def test_find_unittest_error(self): - unittest_xml = "xml_files/test_scan_nose.xml" - error_msg = run.find_unittest_error(unittest_xml) + unittest_xml = os.path.dirname(__file__) + "/xml_files/test_scan_nose.xml" + m_ssh = MagicMock() + m_ssh.exec_command.return_value = ( + self.m_stdin_buf, + open(unittest_xml), + self.m_stderr_buf, + ) + error_msg = run.find_unittest_error(unittest_xml, m_ssh) assert error_msg == "Total 1 testcase/s did not pass. FAILURE: Test `test_set_bucket_tagging` of `s3tests_boto3.functional.test_s3` because 'NoSuchTagSetError' != 'NoSuchTagSet' -------------------- >> " class TestQuote(object):