Skip to content

Commit

Permalink
Read XML file from client
Browse files Browse the repository at this point in the history
Signed-off-by: Vallari Agrawal <[email protected]>
  • Loading branch information
VallariAg committed Oct 9, 2022
1 parent 89a69f0 commit 4583c3d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
16 changes: 8 additions & 8 deletions teuthology/orchestra/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""

import io
from pathlib import Path

from paramiko import ChannelFile

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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.")
Expand All @@ -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()
Expand All @@ -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))

Expand Down
11 changes: 9 additions & 2 deletions teuthology/orchestra/test/test_run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from io import BytesIO
import os

import paramiko
import socket
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 4583c3d

Please sign in to comment.