tmt icon indicating copy to clipboard operation
tmt copied to clipboard

polarion upload test run results via pylero, possible to use token

Open jscotka opened this issue 1 month ago • 1 comments

Add Polarion Reporter Token Upload with ReportPortal Integration

🎯 Overview

This PR adds token-based authentication support to the Polarion reporter and implements seamless integration with ReportPortal, enabling automated cross-linking between the two systems.

✨ Key Features

1. Token-Based API Upload (--token-upload)

  • Direct Polarion API integration using pylero's TestRun API
  • Supports both token and password authentication
  • Enables rich metadata fields not available via XUnit importer
  • Minimal code changes: new functionality in separate _upload_via_api() method
  • Original XUnit importer logic preserved and unchanged

2. ReportPortal Integration

  • Automatic cross-linking: Polarion test runs include ReportPortal launch URL
  • ReportPortal launch URL stored in Polarion's rplaunchurl custom field
  • Launch metadata (URL and name) saved to files for cross-reporter communication
  • Seamless workflow: run both reporters in sequence for complete traceability

3. Enhanced Test Run Metadata

Smart Title Generation:

[polarion ID] - [distro] - [plan name]
Example: 20251113-1031 - Fedora-43 - /examples/polarion-run-report/plan

Rich HTML Descriptions including:

  • Plan summary and description
  • Environment variables from TMT plan
  • Detailed provision information (method, image, memory, disk, addresses, distro, kernel, etc.)
  • ReportPortal launch link with sync information

4. Generic Provision Data Display

  • Works across all provision methods: testcloud, virtual, beaker, artemis, local, connect
  • Automatically displays all available metadata without special handling
  • Extracts distro from provision facts or image name patterns
  • Supports multiple provision backends without code changes

5. Auto-Create Test Cases (--auto-create-testcases)

  • Automatically creates missing test cases in Polarion
  • No manual setup required before first run
  • Logs creation activity for visibility
  • Gracefully handles cases that cannot be auto-created

6. XML Sanitization

  • Removes invalid XML characters (null bytes, control chars)
  • Prevents SAXParseException errors
  • Applies to title, description, test notes, and logs
  • Ensures compatibility even with binary test output

7. Architecture Normalization

  • Consistent handling of architecture values (e.g., x86_64x8664)
  • Centralized normalize_arch() helper function
  • Applied across all upload methods

Test Execution

tmt run -vv plan --name examples/polarion-run-report/plan

Test Results

All tests passing

  • ReportPortal: Launch created with UUID and URL captured
  • Polarion: Test run created with ID 20251113-1031
  • Cross-linking: RP URL successfully set in Polarion's rplaunchurl field
  • Provision data: Distro and metadata correctly extracted
  • Cleanup: All resources properly cleaned up

Verified Scenarios

  • ✅ Token-based Polarion upload
  • ✅ ReportPortal launch URL linking
  • ✅ Title generation with distro detection
  • ✅ Rich descriptions with provision details
  • ✅ Generic provision data across multiple backends
  • ✅ XML sanitization for special characters
  • ✅ Auto-create test cases functionality
  • ✅ Architecture normalization

Custom Fields Required

  • rplaunchurl - Rich text field for ReportPortal launch URL
  • plannedin - Enum field for release/cycle
  • assignee - Enum field for user assignment
  • arch - Enum field for architecture

⚙️ Backward Compatibility

  • 100% backward compatible
  • Original XUnit importer upload method unchanged
  • New features opt-in via --token-upload flag
  • All existing options and workflows continue to work
  • Default behavior unchanged

🚀 Benefits

  1. Token Authentication: Secure API access without exposing passwords
  2. Cross-System Traceability: Direct links between ReportPortal and Polarion
  3. Rich Metadata: Detailed test run information with provision details
  4. Flexible Provisioning: Works with any provision backend
  5. Reduced Manual Work: Auto-create test cases, automatic linking
  6. Better Error Handling: XML sanitization prevents upload failures
  7. Production Ready: Tested and documented with real examples

jscotka avatar Nov 05 '25 20:11 jscotka

@LecrisUT many thaks for feedback, I've done massive change of this source code, to be less invasive for current code, so that tried to separate new functionality and do not mix it together with old upload way.

jscotka avatar Nov 13 '25 10:11 jscotka

@jscotka our PO @lachmanfrantisek will reach out to you to talk about this change.

thrix avatar Nov 26 '25 10:11 thrix