]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
Read XML file from client
authorVallari Agrawal <val.agl002@gmail.com>
Sat, 8 Oct 2022 09:45:03 +0000 (15:15 +0530)
committerVallari Agrawal <val.agl002@gmail.com>
Mon, 10 Oct 2022 02:34:06 +0000 (08:04 +0530)
Signed-off-by: Vallari Agrawal <val.agl002@gmail.com>
teuthology/orchestra/run.py
teuthology/orchestra/test/test_run.py

index 085eea71515cff475bbc5c479beadc9eeb863013..03d49bae7a6f7f293be2dc1c840ee900a2cc2d3b 100644 (file)
@@ -3,7 +3,6 @@ Paramiko run support
 """
 
 import io
-from pathlib import Path
 
 from paramiko import ChannelFile
 
@@ -187,7 +186,7 @@ class RemoteProcess(object):
                 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 @@ class RemoteProcess(object):
             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))
 
index 14b4b98f0a96f37713be8c8ef52d6247967ce4df..3e41e39535c8b49571f4a05ed50ad8f37d8f723e 100644 (file)
@@ -1,4 +1,5 @@
 from io import BytesIO
+import os
 
 import paramiko
 import socket
@@ -264,9 +265,16 @@ class TestRun(object):
         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)
-        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' -------------------- >> "
+        unittest_xml = os.path.dirname(__file__) + "/xml_files/test_scan_nose.xml"
+        m_ssh = MagicMock()
+        with open(unittest_xml) as xmlfile:
+            m_ssh.exec_command.return_value = (
+                self.m_stdin_buf,
+                xmlfile,
+                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):
     def test_quote_simple(self):