Skip to content

Migrate 10 tests to use module_import_sat instead of target_sat#21687

Open
vsedmik wants to merge 1 commit into
SatelliteQE:masterfrom
vsedmik:iss-separate-imports
Open

Migrate 10 tests to use module_import_sat instead of target_sat#21687
vsedmik wants to merge 1 commit into
SatelliteQE:masterfrom
vsedmik:iss-separate-imports

Conversation

@vsedmik
Copy link
Copy Markdown
Contributor

@vsedmik vsedmik commented May 28, 2026

Problem Statement

Currently we the the vast majority of the ISS export+import tests runs against the same Satellite instance for both - export and import (just into another organization), which does not quite follow the user case and may miss some important issues.

Solution

After merge of #21600 we should be ready to migrate the tests to use a separate Satellite instance for imports. In this PR I'm migrating 10 of them where it makes sense the most. Others may follow.

PRT test Cases example

trigger: test-robottelo
pytest: tests/foreman/cli/test_satellitesync.py -k 'test_postive_export_import_cv_with_mixed_content_syncable or test_postive_export_import_repo_with_GPG or test_positive_export_import_incremental_yum_repo or test_positive_export_import_consume_incremental_yum_repo or test_positive_export_import_default_org_view or test_postive_export_import_podman_repo or test_postive_export_import_ansible_collection_repo or test_positive_export_import_redhat_cv or test_positive_export_import_filtered_cvv or test_postive_export_import_large_cv'
env:
    ROBOTTELO_iss__separate_import_sat: true
trigger: test-robottelo
pytest: tests/foreman/cli/test_satellitesync.py -k 'test_postive_export_import_cv_with_mixed_content_syncable or test_postive_export_import_repo_with_GPG or test_positive_export_import_incremental_yum_repo or test_positive_export_import_consume_incremental_yum_repo or test_positive_export_import_default_org_view or test_postive_export_import_podman_repo or test_postive_export_import_ansible_collection_repo or test_positive_export_import_redhat_cv or test_positive_export_import_filtered_cvv or test_postive_export_import_large_cv'
env:
    ROBOTTELO_iss__separate_import_sat: false

Summary by Sourcery

Migrate several content export/import CLI tests to use a dedicated import Satellite instance instead of the primary target Satellite.

Tests:

  • Update ten ISS export/import scenarios to perform imports against module_import_sat and import-specific organizations/fixtures.
  • Adjust content view and repository setup in tests to use bulk repository-ids arguments and align with new cleanup fixtures.
  • Extend test coverage of import-side behavior by validating imported entities (packages, files, products, repositories, credentials) on the separate Satellite instance.

@vsedmik vsedmik self-assigned this May 28, 2026
@vsedmik vsedmik added No-CherryPick PR doesnt need CherryPick to previous branches Stream Introduced in or relating directly to Satellite Stream/Master labels May 28, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 28, 2026

Reviewer's Guide

This PR migrates ten ISS export/import tests to use a dedicated import Satellite instance (module_import_sat via module_import_sat/function_import_org_at_isat* fixtures) instead of the primary target_sat, while also simplifying content view creation, standardizing cleanup, and making assertions/queries ID-based where possible.

File-Level Changes

Change Details Files
Introduce fixtures and plumbing to create/import organizations with manifests on the separate import Satellite instance and route imports to it.
  • Add function_import_org_at_isat_with_manifest fixture to create an org on the import Satellite and upload a fresh manifest using Manifester and module_import_sat.upload_manifest.
  • Extend affected tests to depend on module_import_sat and new function_import_org_at_isat* fixtures instead of function_import_org/function_import_org_with_manifest.
  • Change export-to-import handoff to use target_sat.move_pulp_archive(..., target=module_import_sat) so exported archives are moved onto the import Satellite before running import commands.
tests/foreman/cli/test_satellitesync.py
Update export/import tests to execute all import operations and validations against module_import_sat rather than target_sat.
  • Replace target_sat.cli.ContentImport.*, Settings.set, execute, and related calls with their module_import_sat equivalents in the default org view, filtered CV, Red Hat CV, mixed-content syncable CV, Ansible collection, GPG repo, large CV, incremental YUM repo, incremental YUM consume, and podman repo tests.
  • Ensure all post-import verification (content views, repositories, packages, files, products, content credentials, activation keys, import history, and API ContentViewVersion reads) are performed against module_import_sat and the corresponding import org IDs.
  • Adjust host registration in the incremental consume test so the content host registers against the import Satellite and organization while still exporting from the original target_sat instance.
tests/foreman/cli/test_satellitesync.py
Simplify content view creation and lookups by passing repository IDs at creation time and querying by ID where possible.
  • Create content views with a repository-ids list in a single make_content_view call instead of creating an empty CV then calling ContentView.add_repository for each repo.
  • Stop generating random CV names where not needed and rely on the CV object returned by make_content_view, using ContentView.info({'id': cv['id']}) or cv['name'] for later lookups.
  • Tighten equality assertions (e.g., all(exporting_cv[key] == importing_cv[key] for key in ['label','name'])) and reuse CV names from the exporting side when verifying imported views.
tests/foreman/cli/test_satellitesync.py
Standardize cleanup and environment configuration across the migrated tests.
  • Replace legacy export_import_cleanup_function/export_import_cleanup_module fixtures with the unified complete_export_import_cleanup fixture in all updated tests.
  • Ensure subscription-connection/disconnected mode is configured on the import Satellite (module_import_sat.cli.Settings.set(...)) rather than the export Satellite for tests that require it.
  • Use the import Satellite to run path/file presence checks (execute('ls ...') and ContentImport.list) so verification happens in the correct environment.
tests/foreman/cli/test_satellitesync.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@vsedmik
Copy link
Copy Markdown
Contributor Author

vsedmik commented May 28, 2026

trigger: test-robottelo
pytest: tests/foreman/cli/test_satellitesync.py -k 'test_postive_export_import_cv_with_mixed_content_syncable or test_postive_export_import_repo_with_GPG or test_positive_export_import_incremental_yum_repo or test_positive_export_import_consume_incremental_yum_repo or test_positive_export_import_default_org_view or test_postive_export_import_podman_repo or test_postive_export_import_ansible_collection_repo or test_positive_export_import_redhat_cv or test_positive_export_import_filtered_cvv or test_postive_export_import_large_cv'
env:
    ROBOTTELO_iss__separate_import_sat: true

@Satellite-QE
Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 15641
Build Status: SUCCESS
PRT Comment: pytest tests/foreman/cli/test_satellitesync.py -k test_postive_export_import_cv_with_mixed_content_syncable or test_postive_export_import_repo_with_GPG or test_positive_export_import_incremental_yum_repo or test_positive_export_import_consume_incremental_yum_repo or test_positive_export_import_default_org_view or test_postive_export_import_podman_repo or test_postive_export_import_ansible_collection_repo or test_positive_export_import_redhat_cv or test_positive_export_import_filtered_cvv or test_postive_export_import_large_cv --external-logging
Test Result : ======== 12 passed, 28 deselected, 148 warnings in 10813.54s (3:00:13) =========

@Satellite-QE Satellite-QE added the PRT-Passed Indicates that latest PRT run is passed for the PR label May 28, 2026
@vsedmik
Copy link
Copy Markdown
Contributor Author

vsedmik commented May 28, 2026

trigger: test-robottelo
pytest: tests/foreman/cli/test_satellitesync.py -k 'test_postive_export_import_cv_with_mixed_content_syncable or test_postive_export_import_repo_with_GPG or test_positive_export_import_incremental_yum_repo or test_positive_export_import_consume_incremental_yum_repo or test_positive_export_import_default_org_view or test_postive_export_import_podman_repo or test_postive_export_import_ansible_collection_repo or test_positive_export_import_redhat_cv or test_positive_export_import_filtered_cvv or test_postive_export_import_large_cv'
env:
    ROBOTTELO_iss__separate_import_sat: false

@Satellite-QE
Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 15648
Build Status: SUCCESS
PRT Comment: pytest tests/foreman/cli/test_satellitesync.py -k test_postive_export_import_cv_with_mixed_content_syncable or test_postive_export_import_repo_with_GPG or test_positive_export_import_incremental_yum_repo or test_positive_export_import_consume_incremental_yum_repo or test_positive_export_import_default_org_view or test_postive_export_import_podman_repo or test_postive_export_import_ansible_collection_repo or test_positive_export_import_redhat_cv or test_positive_export_import_filtered_cvv or test_postive_export_import_large_cv --external-logging
Test Result : ========= 12 passed, 28 deselected, 115 warnings in 8434.25s (2:20:34) =========

@vsedmik vsedmik marked this pull request as ready for review May 28, 2026 19:39
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • Several tests now directly set subscription_connection_enabled to 'No' on module_import_sat without any teardown, which risks leaking state across tests; consider introducing a fixture (e.g. import_satellite_disconnected) that manages this setting and restores the previous value.
  • In tests like the Ansible collection and podman repo scenarios, the code relies on Product.list(...)[0] or Repository.list(...)[0], which can be fragile if multiple items exist; it would be more robust to fetch the product/repository by name and product name instead of assuming the first element is the one just created.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Several tests now directly set `subscription_connection_enabled` to `'No'` on `module_import_sat` without any teardown, which risks leaking state across tests; consider introducing a fixture (e.g. `import_satellite_disconnected`) that manages this setting and restores the previous value.
- In tests like the Ansible collection and podman repo scenarios, the code relies on `Product.list(...)[0]` or `Repository.list(...)[0]`, which can be fragile if multiple items exist; it would be more robust to fetch the product/repository by name and product name instead of assuming the first element is the one just created.

## Individual Comments

### Comment 1
<location path="tests/foreman/cli/test_satellitesync.py" line_range="1016-1017" />
<code_context>
-        target_sat.cli.Settings.set({'name': 'subscription_connection_enabled', 'value': "No"})
-        target_sat.cli.ContentImport.library(
-            {'organization-id': function_import_org_with_manifest.id, 'path': import_path}
+        module_import_sat.cli.Settings.set(
+            {'name': 'subscription_connection_enabled', 'value': 'No'}
         )
-        importing_cvv = target_sat.cli.ContentView.info(
</code_context>
<issue_to_address>
**suggestion (testing):** Avoid leaking `subscription_connection_enabled` setting changes across tests

These tests (e.g. `test_positive_export_import_default_org_view`, `test_positive_export_import_filtered_cvv`, `test_positive_export_import_redhat_cv`) disable `subscription_connection_enabled` on the shared `module_import_sat` but never restore it, so later tests can see the modified state and become order-dependent. Please encapsulate this in a helper (fixture/context manager) that saves and restores the original value (e.g. via `finally` or `monkeypatch`) so each test leaves `module_import_sat` in a clean state.

Suggested implementation:

```python
        # Import and verify content of library
        with subscription_connection_disabled(module_import_sat):
            module_import_sat.cli.ContentImport.library(
                {
                    'organization-id': function_import_org_at_isat_with_manifest.id,
                    'path': import_path,
                }
            )

```

To fully implement the suggestion across the file:

1. **Add a context manager helper** near the top of `tests/foreman/cli/test_satellitesync.py` (e.g. next to other test utilities):

```python
from contextlib import contextmanager

@contextmanager
def subscription_connection_disabled(satellite):
    # Read and save the original value; adjust to actual Settings API if different
    original = satellite.cli.Settings.info({'name': 'subscription_connection_enabled'})['value']
    try:
        satellite.cli.Settings.set({'name': 'subscription_connection_enabled', 'value': 'No'})
        yield
    finally:
        satellite.cli.Settings.set({'name': 'subscription_connection_enabled', 'value': original})
```

   If `Settings.info` is not the correct API, replace it with whatever call returns the current value of `subscription_connection_enabled`.

2. **Update all other tests** in this file that currently do:

```python
module_import_sat.cli.Settings.set(
    {'name': 'subscription_connection_enabled', 'value': 'No'}
)
module_import_sat.cli.ContentImport.library(...)
```

   to use the context manager instead:

```python
with subscription_connection_disabled(module_import_sat):
    module_import_sat.cli.ContentImport.library(...)
```

   This includes at least the tests mentioned in your comment:
   - `test_positive_export_import_default_org_view`
   - `test_positive_export_import_filtered_cvv`
   - `test_positive_export_import_redhat_cv`

These changes ensure `subscription_connection_enabled` is always restored to its original value, avoiding leakage across tests and order-dependence.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +1016 to +1017
module_import_sat.cli.Settings.set(
{'name': 'subscription_connection_enabled', 'value': 'No'}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion (testing): Avoid leaking subscription_connection_enabled setting changes across tests

These tests (e.g. test_positive_export_import_default_org_view, test_positive_export_import_filtered_cvv, test_positive_export_import_redhat_cv) disable subscription_connection_enabled on the shared module_import_sat but never restore it, so later tests can see the modified state and become order-dependent. Please encapsulate this in a helper (fixture/context manager) that saves and restores the original value (e.g. via finally or monkeypatch) so each test leaves module_import_sat in a clean state.

Suggested implementation:

        # Import and verify content of library
        with subscription_connection_disabled(module_import_sat):
            module_import_sat.cli.ContentImport.library(
                {
                    'organization-id': function_import_org_at_isat_with_manifest.id,
                    'path': import_path,
                }
            )

To fully implement the suggestion across the file:

  1. Add a context manager helper near the top of tests/foreman/cli/test_satellitesync.py (e.g. next to other test utilities):
from contextlib import contextmanager

@contextmanager
def subscription_connection_disabled(satellite):
    # Read and save the original value; adjust to actual Settings API if different
    original = satellite.cli.Settings.info({'name': 'subscription_connection_enabled'})['value']
    try:
        satellite.cli.Settings.set({'name': 'subscription_connection_enabled', 'value': 'No'})
        yield
    finally:
        satellite.cli.Settings.set({'name': 'subscription_connection_enabled', 'value': original})

If Settings.info is not the correct API, replace it with whatever call returns the current value of subscription_connection_enabled.

  1. Update all other tests in this file that currently do:
module_import_sat.cli.Settings.set(
    {'name': 'subscription_connection_enabled', 'value': 'No'}
)
module_import_sat.cli.ContentImport.library(...)

to use the context manager instead:

with subscription_connection_disabled(module_import_sat):
    module_import_sat.cli.ContentImport.library(...)

This includes at least the tests mentioned in your comment:

  • test_positive_export_import_default_org_view
  • test_positive_export_import_filtered_cvv
  • test_positive_export_import_redhat_cv

These changes ensure subscription_connection_enabled is always restored to its original value, avoiding leakage across tests and order-dependence.

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

Labels

No-CherryPick PR doesnt need CherryPick to previous branches PRT-Passed Indicates that latest PRT run is passed for the PR Stream Introduced in or relating directly to Satellite Stream/Master

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants