Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a custom_junit callback plugin #132

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open

Conversation

mgirgisf
Copy link
Contributor

@mgirgisf mgirgisf commented Jul 22, 2024

This custom_junit plugin extends the existing junit plugin and produces an XML report with classes and names that polarian expects.

Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://review.rdoproject.org/zuul/buildset/e8c007fe0bc8493baff88e377f733728

✔️ openstack-k8s-operators-content-provider SUCCESS in 40m 47s
functional-tests-on-osp18 FAILURE in 25m 00s

@mgirgisf
Copy link
Contributor Author

recheck

Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://review.rdoproject.org/zuul/buildset/c8c7ff17afe04310af8bb8e233af99a1

✔️ openstack-k8s-operators-content-provider SUCCESS in 1h 21m 47s
functional-tests-on-osp18 FAILURE in 1h 05m 20s

- name: Add failure to test result
delegate_to: localhost
lineinfile:
path: "{{ logs_dir }}/test_run_result.xml"
Copy link
Collaborator

@elfiesmelfie elfiesmelfie Jul 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elfiesmelfie elfiesmelfie marked this pull request as ready for review July 23, 2024 15:14
@elfiesmelfie elfiesmelfie marked this pull request as draft July 23, 2024 15:14
Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://review.rdoproject.org/zuul/buildset/46d9b206bd794ec2b8a5752e4e7080f4

✔️ openstack-k8s-operators-content-provider SUCCESS in 1h 30m 52s
functional-tests-on-osp18 FAILURE in 1h 16m 14s

Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://softwarefactory-project.io/zuul/t/rdoproject.org/buildset/49968e7a68554e05a78f3a2266edf975

✔️ openstack-k8s-operators-content-provider SUCCESS in 1h 35m 47s
functional-tests-on-osp18 FAILURE in 1h 06m 47s

Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://softwarefactory-project.io/zuul/t/rdoproject.org/buildset/3c4a444c4e1d40a0b1dcbd3cd550bb96

✔️ openstack-k8s-operators-content-provider SUCCESS in 1h 51m 13s
functional-tests-on-osp18 FAILURE in 1h 06m 22s

Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://softwarefactory-project.io/zuul/t/rdoproject.org/buildset/80c5859d0993422db465a39200fc2aeb

✔️ feature-verification-tests-noop SUCCESS in 5s
✔️ openstack-k8s-operators-content-provider SUCCESS in 1h 39m 12s
functional-tests-on-osp18 FAILURE in 1h 23m 50s

Comment on lines 62 to 74
line: |
'<testcase classname="openstack-observability" name="configure-hest-template-automatically-scaling_instances" time="1"/>'
'<failure> configure Heat template failed <failure/>'</testcase>'
insertbefore: "</testsuite>"

- name: increment number of failures
set_fact:
number_of_failures: "{{ number_of_failures | int + 1 }}"

- name: increment number of tests
set_fact:
number_of_tests: "{{ number_of_tests | int + 1 }}"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these be done in v2_playbook_on_stats?

@@ -1,92 +1,274 @@
# (c) 2016 Matt Clay <[email protected]>
# (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy/pasting the existing junitXML plugin is not the way to go.

Either try to contribute upstream to it, or inherit from the existing class here to make changes.

There MIGHT be an issue with using a GPL-licensed library to provide the base class, since this project is not GPL licensed, nor do we plan to adopt GPL v3 as the license.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yet another alternative would be to record the results and then render the XML at the end using a jinja2 template, so that there's no back-tracking through the document. However, this would use more memory.

Comment on lines 50 to 55
- name: Add pass to test results
delegate_to: localhost
lineinfile:
path: "{{ logs_dir }}/test_run_result.xml"
line: '<testcase classname="openstack-observability" name="configure-hest-template-automatically-scaling-instances" time="1"/>'
insertbefore: "</testsuite>"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only test result file I can see.

I need to look for the one generated by the junit plugin

host = result._host.get_name()
task_name = result._task.get_name()
self.log_task_result(host, 'passed', task_name)
self._output_dir = os.getcwd()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a sensible default. I don't know where this ends up, maybe on the executer, but it's not in a location that gets uploaded

self._fail_on_ignore = os.getenv('JUNIT_FAIL_ON_IGNORE', 'False').lower()
self._include_setup_tasks_in_report = os.getenv('JUNIT_INCLUDE_SETUP_TASKS_IN_REPORT', 'False').lower()
self._hide_task_arguments = os.getenv('JUNIT_HIDE_TASK_ARGUMENTS', 'True').lower()
self._test_case_prefix = os.getenv('JUNIT_TEST_CASE_PREFIX', 'RHOSO')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this needs further work. Using prefix only doesn't work if the same task has multiple test IDs in it.

Copy link
Collaborator

@elfiesmelfie elfiesmelfie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran this locally, using the test playbook for the custom logger

I left ci/ansible.cfg as-is, and used the following command to test cd ci && ansible-playbook -v github/test_logger.yml

The output was this:

cat *.xml
<?xml version="1.0" ?>
<testsuites disabled="0" errors="0" failures="0" tests="1" time="0.012203693389892578125">
	<testsuite disabled="0" errors="0" failures="0" name="test_logger" skipped="0" tests="1" time="0.012203693389892578125">
		<testcase classname="/home/emma/repos/github/infrawatch/feature-verification-tests/ci/github/test_logger.yml:6" name="[localhost] Run tests to make sure the custom_logger plugin is running as expected: RHOSO-01 show some message" time="0.012203693389892578">
			<system-out>{
    &quot;changed&quot;: false,
    &quot;msg&quot;: &quot;You can start the task name with the test ID.&quot;
}</system-out>
		</testcase>
	</testsuite>
</testsuites>

It looks like unexpected values are being used in unexpected places, and the TestCase class probably needs to be updated.
There's also only one testcase recorded because there's only one task with the ID at the start of the name.

self._task_class = os.getenv('JUNIT_TASK_CLASS', 'False').lower()
self._task_relative_path = os.getenv('JUNIT_TASK_RELATIVE_PATH', '')
self._fail_on_change = os.getenv('JUNIT_FAIL_ON_CHANGE', 'False').lower()
self._fail_on_ignore = os.getenv('JUNIT_FAIL_ON_IGNORE', 'False').lower()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be true, because we use "ignore_errors: true" in our playbooks

Copy link
Collaborator

@elfiesmelfie elfiesmelfie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can extend the existing xml plugin, and redefine only what we need.
It should be possible to create a new class, with the existing XML plugin as a base and then redefines the methods we need to update.

Copy link

Merge Failed.

This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset.
Warning:
Error merging github.com/infrawatch/feature-verification-tests for 132,3e3e2b8e43c5cb72b5c0cb9f0f46b8f7d69a57cf

@@ -0,0 +1,49 @@
from ansible.plugins.callback import CallbackModule as OriginalCallbackModule
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ansible.plugins.callback.junit.CallbackModule as the superclass

from ansible.module_utils._text import to_bytes, to_text
from ansible.utils._junit_xml import TestCase, TestError, TestFailure, TestSuite, TestSuites

class CustomCallbackModule(OriginalCallbackModule):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CallbackModule is a required classname for ansible to run the module.

Copy link

Merge Failed.

This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset.
Warning:
Error merging github.com/infrawatch/feature-verification-tests for 132,e7b5b1eb56694d4cdda3d4ce42b9a3bd0aa93c45

Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://softwarefactory-project.io/zuul/t/rdoproject.org/buildset/0c7dd74db81a43028204e648edaadcb0

✔️ feature-verification-tests-noop SUCCESS in 4s
✔️ openstack-k8s-operators-content-provider SUCCESS in 1h 18m 46s
functional-tests-on-osp18 FAILURE in 1h 04m 17s

Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://softwarefactory-project.io/zuul/t/rdoproject.org/buildset/15f121dab19441cda6f4bcc84d365aa5

✔️ feature-verification-tests-noop SUCCESS in 5s
✔️ openstack-k8s-operators-content-provider SUCCESS in 2h 08m 51s
functional-tests-on-osp18 FAILURE in 1h 03m 44s

Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://softwarefactory-project.io/zuul/t/rdoproject.org/buildset/abdfd613a7144e99a17b7380cb3eb14b

✔️ feature-verification-tests-noop SUCCESS in 4s
✔️ openstack-k8s-operators-content-provider SUCCESS in 1h 22m 11s
functional-tests-on-osp18 FAILURE in 1h 00m 55s

Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://softwarefactory-project.io/zuul/t/rdoproject.org/buildset/47ac0c5c769f457f8f3111222c249bef

✔️ feature-verification-tests-noop SUCCESS in 4s
openstack-k8s-operators-content-provider FAILURE in 13m 11s
⚠️ functional-tests-on-osp18 SKIPPED Skipped due to failed job openstack-k8s-operators-content-provider

@elfiesmelfie
Copy link
Collaborator

recheck

Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://softwarefactory-project.io/zuul/t/rdoproject.org/buildset/97af9659e8c7442f933f22d5df65f300

✔️ feature-verification-tests-noop SUCCESS in 4s
✔️ openstack-k8s-operators-content-provider SUCCESS in 1h 31m 57s
functional-tests-on-osp18 FAILURE in 1h 16m 34s

Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://softwarefactory-project.io/zuul/t/rdoproject.org/buildset/d9453489e33749a5ab3a54abc929a062

✔️ feature-verification-tests-noop SUCCESS in 4s
✔️ openstack-k8s-operators-content-provider SUCCESS in 1h 30m 53s
functional-tests-on-osp18 FAILURE in 1h 16m 28s

elfiesmelfie and others added 26 commits October 1, 2024 15:02
The original test ID that custom_logger uses is still in the name,
Custom logger will record test results as long as the expected
test ids are in the name somewhere.
Use copy with remote src instead of shell/cp, so that the files can be copied from compute nodes into the controller logs dir
Add a new play to make sure the output dir is created on the controller before copying the files.
Rename the files using the hostname of the src
Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://softwarefactory-project.io/zuul/t/rdoproject.org/buildset/9f2fafd5337146e0b77da991fd146755

✔️ feature-verification-tests-noop SUCCESS in 5s
✔️ openstack-k8s-operators-content-provider SUCCESS in 2h 20m 22s
functional-tests-on-osp18 FAILURE in 1h 37m 40s
✔️ functional-logging-tests-osp18 SUCCESS in 1h 04m 20s

Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://softwarefactory-project.io/zuul/t/rdoproject.org/buildset/78ad75d4b36c420a960550cdda1e0c09

✔️ feature-verification-tests-noop SUCCESS in 4s
✔️ openstack-k8s-operators-content-provider SUCCESS in 1h 45m 49s
functional-tests-on-osp18 FAILURE in 1h 32m 53s
✔️ functional-logging-tests-osp18 SUCCESS in 1h 00m 28s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants