teemtee / tmt

Test Management Tool
MIT License
76 stars 112 forks source link

reportportal report phase fails when logs contain null characted #2854

Open The-Mule opened 1 month ago

The-Mule commented 1 month ago

We noticed that when test results contains a null character ('\0') then reportportal report phase fails as follows:

tmt -c arch=x86_64 -c distro=RHEL-9.4.0-20240406.57 -c fips=1 -c report=1 run -e RP_TOKEN=0afb4e41-89d2-4a23-95d3-6a4130eca837 --id /tmp/work-gnutlsd0liux94 plan --name '^/plans/modules/gnutls$' report --force -vvv

/plans/modules/gnutls
    report
        how: reportportal
        order: 50
        launch: FIPS 140 Integration Testing - Tier 2: Modules
            uuid: 34d0cf3c-7824-4b3e-9b8c-10bd62f2db75
        test: /gnutls/Security/CVE-2009-2730-incorrect-verification-of-SSL-cert
            uuid: 33c24a2b-01b1-49d4-9e45-54f0831acfd1

plan failed

The exception was caused by 1 earlier exceptions

Cause number 1:

    Received non-ok status code from ReportPortal: {"errorCode":5000,"message":"Unclassified error [org.hibernate.exception.DataException: could not execute statement]"}

See http://artifacts.osci.redhat.com/testing-farm/aa52f015-8f84-45b8-9419-cb3be3919e85/ for more details about the run. There is a null characted in TESTOUT.log in the test report (propagated from test PURPOSE file).

When this null character is removed from PURPOSE file and test is re-executed, it can be reported fine.

Please notice that having a special character in the TESTOUT.log is completely okay - this particular test is almost 16 years old and was executed (and reported elsewhere) hundreds of times. We need to fix either plugin or RP to handle this situation correctly (without errors).

kkaarreell commented 1 month ago

In my script I am removing "invalid" characters with

d = re.sub(u'[^\u0020-\uD7FF\u0009\u000A\u000D\uE000-\uFFFD\U00010000-\U0010FFFF]+', '', data)

although other alternatives like replacing them with the respective unicode number might be also reasonable.

The-Mule commented 1 month ago

I actually thing the only invalid character is \00 (null byte). There are a ton of non-printable characters in the logs from what I can see but the only one that breaks log/entry post request is null byte. What I did on my machine to fix it temporarily was:

                    for index, log_path in enumerate(result.log):
                        try:                        
                            log = str(self.step.plan.execute.read(log_path)).replace('\00', '\\00')
                            #                                               ^^^^^^^^^^^^^^^^^^^^^^^
                        except tmt.utils.FileError:
                            continue

                        level = "INFO" if log_path == result.log[0] else "TRACE"
                        status = self.TMT_TO_RP_RESULT_STATUS[result.result]

And it works for me.

kkaarreell commented 1 month ago

I think that I have hit this issue also for a different control character. Also, CDATA included in test output might be a problem.

The-Mule commented 1 month ago

Maybe we can have just link to TF instead of logs (the way we had it in TCMS)...? But I assume RP TA is expected to work on logs and that is why we have it there. Also, TF results would have to be slightly improved to be able to navigate there (through anchors or something similar). But you know - for real debugging one have to look there anyway. Debugging based solely on TESTOUT.log is very limited.

kkaarreell commented 1 month ago

Right, AA needs a failure log. But I find complete log handy too, in most cases there isnt more verbose log available anyway.