Skip to content

Update tests for deprecated CV/LCE param removal#21644

Open
jeremylenz wants to merge 2 commits into
SatelliteQE:masterfrom
jeremylenz:remove-deprecated-cv-lce-params
Open

Update tests for deprecated CV/LCE param removal#21644
jeremylenz wants to merge 2 commits into
SatelliteQE:masterfrom
jeremylenz:remove-deprecated-cv-lce-params

Conversation

@jeremylenz
Copy link
Copy Markdown
Contributor

@jeremylenz jeremylenz commented May 21, 2026

Problem Statement

Katello 4.21 removes the deprecated separate content_view_id and lifecycle_environment_id API parameters from activation keys, hosts, and hostgroups. These were replaced by content_view_environment_ids / content_view_environment_id in 6.19.

Solution

  • Add get_cvenv_id() helper to api_factory for looking up ContentViewEnvironment IDs from CV+LCE pairs
  • Update all activation key creations to use content_view_environment_ids=[cvenv_id] instead of content_view=cv, environment=lce
  • Update all host content_facet_attributes to use content_view_environment_ids instead of separate content_view_id/lifecycle_environment_id
  • Update all hostgroup creations to use content_view_environment_id=cvenv_id instead of separate content_view/lifecycle_environment

Read-side assertions (ak.content_view.id, ak.environment.read(), etc.) are preserved via nailgun backward-compat properties.

Related Issues

🤖 Generated with Claude Code

Summary by Sourcery

Migrate tests and helpers to use content view environment IDs instead of separate content view and lifecycle environment parameters.

New Features:

  • Add an API factory helper to look up ContentViewEnvironment IDs from content view and lifecycle environment pairs.

Enhancements:

  • Update activation key, host, and hostgroup helpers to set content_view_environment_ids consistently when registering or provisioning resources.

Tests:

  • Refresh API and UI tests, fixtures, and provisioning scenarios to create and update entities via content_view_environment_ids rather than deprecated content_view_id and lifecycle_environment_id fields.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 21, 2026

Reviewer's Guide

Refactors activation key, host, and hostgroup tests/fixtures to use combined content view environment identifiers (content_view_environment_id / content_view_environment_ids) instead of the deprecated separate content_view / environment and content_view_id / lifecycle_environment_id parameters, via a new api_factory.get_cvenv_id helper that resolves ContentViewEnvironment IDs.

Sequence diagram for resolving CV/LCE pair to ContentViewEnvironment ID

sequenceDiagram
    participant Fixture
    participant ApiFactory
    participant ContentViewEnvironmentAPI as ContentViewEnvironmentAPI
    participant ActivationKeyAPI as ActivationKeyAPI

    Fixture->>ApiFactory: get_cvenv_id(content_view, lifecycle_environment)
    ApiFactory->>ContentViewEnvironmentAPI: list_content_view_environments(params)
    ContentViewEnvironmentAPI-->>ApiFactory: result[results][0][id]
    ApiFactory-->>Fixture: cvenv_id
    Fixture->>ActivationKeyAPI: ActivationKey(content_view_environment_ids=[cvenv_id]).create()
    ActivationKeyAPI-->>Fixture: ActivationKey instance
Loading

File-Level Changes

Change Details Files
Introduce api_factory helper to resolve ContentViewEnvironment IDs from content view + lifecycle environment pairs.
  • Add get_cvenv_id(content_view, lifecycle_environment) method to api_factory that normalizes object-or-ID arguments, calls ContentViewEnvironment.list_content_view_environments, and returns the first matching ID
  • Use the helper throughout tests and fixtures wherever a ContentViewEnvironment ID is required, avoiding manual ID lookups or direct CV/LCE pairs
robottelo/host_helpers/api_factory.py
Switch activation key creation and update flows to use content_view_environment_ids instead of separate content_view/environment fields.
  • Update shared activation key setup logic in register_host_and_needed_setup to compute the desired CV/LCE pair, compare to the existing activation key association, and set content_view_environment_ids = [cvenv_id] when mismatched
  • Change numerous activation key fixtures to construct ActivationKey objects with content_view_environment_ids=[get_cvenv_id(cv,lce)] instead of content_view and environment arguments
  • Adjust tests that clear or reassign activation key content to update content_view_environment_ids (e.g. set to [] when removing CVE) instead of content_view_environments or individual CV/LCE fields
robottelo/host_helpers/api_factory.py
pytest_fixtures/component/activationkey.py
pytest_fixtures/component/rh_cloud.py
tests/foreman/api/test_contentview.py
tests/foreman/api/test_docker.py
tests/foreman/api/test_subscription.py
pytest_fixtures/component/provision_capsule_pxe.py
pytest_fixtures/component/provision_pxe.py
tests/foreman/api/test_activationkey.py
pytest_fixtures/component/contentview.py
pytest_fixtures/component/leapp_client.py
tests/foreman/ui/test_activationkey.py
tests/new_upgrades/test_capsulecontent.py
pytest_fixtures/component/repository.py
pytest_fixtures/core/contenthosts.py
Update host creation/update paths to set content_facet_attributes using content_view_environment_ids rather than content_view_id/lifecycle_environment_id.
  • Replace content_facet_attributes dictionaries that previously used content_view_id and lifecycle_environment_id with content_view_environment_ids=[get_cvenv_id(cv,lce)] in host-related API tests
  • Ensure all provisioning, subscription, ENC, and UI tests that create hosts now supply the combined CVE reference but continue to assert on read-side content_view/environment via nailgun’s backward-compatible properties
tests/foreman/api/test_host.py
tests/foreman/api/test_provisioningtemplate.py
tests/foreman/api/test_contentview.py
tests/foreman/api/test_hostgroup.py
tests/foreman/api/test_provisioning.py
tests/foreman/api/test_provisioning_puppet.py
tests/foreman/api/test_subscription.py
tests/foreman/destructive/test_infoblox.py
tests/foreman/endtoend/test_api_endtoend.py
tests/foreman/ui/test_host.py
tests/foreman/ui/test_hostcollection.py
tests/foreman/ui/test_errata.py
tests/foreman/ui/test_oscappolicy.py
tests/new_upgrades/test_capsulecontent.py
Refactor hostgroup-related fixtures and tests to use single content_view_environment_id instead of separate content_view and lifecycle_environment fields.
  • Update HostGroup creations in tests and provisioning fixtures to pass content_view_environment_id=get_cvenv_id(cv,lce) and drop explicit lifecycle_environment arguments
  • Adjust HostGroup update flows to reassign content_view_environment_id when changing CV/LCE, and update the list of fields passed to update() accordingly
tests/foreman/api/test_host.py
tests/foreman/api/test_hostgroup.py
pytest_fixtures/component/provision_capsule_pxe.py
pytest_fixtures/component/provision_pxe.py
pytest_fixtures/component/provision_ocpv.py
pytest_fixtures/component/provision_vmware.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

@jeremylenz jeremylenz added the No-CherryPick PR doesnt need CherryPick to previous branches label May 21, 2026
@jeremylenz
Copy link
Copy Markdown
Contributor Author

trigger: test-robottelo
pytest: tests/foreman/api/test_activationkey.py tests/foreman/api/test_host.py tests/foreman/api/test_hostgroup.py tests/foreman/api/test_docker.py tests/foreman/api/test_contentview.py
nailgun: 1419
Katello:
    katello: 11753

@jeremylenz
Copy link
Copy Markdown
Contributor Author

trigger: test-robottelo
pytest: tests/foreman/api/test_activationkey.py tests/foreman/api/test_host.py tests/foreman/api/test_hostgroup.py
nailgun: 1419
Katello:
    katello: 11753

@jeremylenz
Copy link
Copy Markdown
Contributor Author

trigger: test-robottelo
pytest: "tests/foreman/api/test_activationkey.py tests/foreman/api/test_host.py tests/foreman/api/test_hostgroup.py"
nailgun: 1419
Katello:
    katello: 11753

@tpapaioa
Copy link
Copy Markdown
Contributor

trigger: test-robottelo
pytest: tests/foreman/api/test_activationkey.py tests/foreman/api/test_host.py tests/foreman/api/test_hostgroup.py
nailgun: 1419
Katello:
  katello: 11753

@Satellite-QE
Copy link
Copy Markdown
Collaborator

PRT Result

Build Number: 15559
Build Status: SUCCESS
PRT Comment: pytest tests/foreman/api/test_activationkey.py tests/foreman/api/test_host.py tests/foreman/api/test_hostgroup.py --external-logging
Test Result : ======== 169 passed, 8 deselected, 1670 warnings in 3640.22s (1:00:40) =========

@Satellite-QE Satellite-QE added the PRT-Passed Indicates that latest PRT run is passed for the PR label May 21, 2026
@jeremylenz jeremylenz marked this pull request as ready for review May 27, 2026 13:49
@jeremylenz jeremylenz requested review from a team as code owners May 27, 2026 13:49
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:

  • The new get_cvenv_id helper assumes that list_content_view_environments always returns at least one result and blindly accesses result['results'][0]['id']; consider adding a sanity check (and a clearer failure message) for the case where no matching content view environment is found to make test failures easier to diagnose.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `get_cvenv_id` helper assumes that `list_content_view_environments` always returns at least one result and blindly accesses `result['results'][0]['id']`; consider adding a sanity check (and a clearer failure message) for the case where no matching content view environment is found to make test failures easier to diagnose.

## Individual Comments

### Comment 1
<location path="tests/foreman/api/test_docker.py" line_range="516-520" />
<code_context>
     cvv = cv.read().version[0].read()
     cvv.promote(data={'environment_ids': lce.id, 'force': False})
+    cvenv_id = module_target_sat.api_factory.get_cvenv_id(cv, lce)
     ak = module_target_sat.api.ActivationKey(
-        content_view=cv, max_hosts=100, organization=org, environment=lce
+        content_view_environment_ids=[cvenv_id], max_hosts=100, organization=org
</code_context>
<issue_to_address>
**suggestion (testing):** Also assert environment is cleared when `content_view_environment_ids` is emptied

Since these removal tests now only check that `content_view` becomes `None` after `content_view_environment_ids = []`, please also assert that `ak.environment` is `None` after the update. This better validates the backward‑compat behavior on the nailgun side when the CVE mapping is removed.
</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 516 to 520
ak = module_target_sat.api.ActivationKey(
content_view=content_view, environment=module_lce, organization=module_org
content_view_environment_ids=[cvenv_id], organization=module_org
).create()
assert ak.content_view.id == content_view.id
assert ak.content_view.read().repository[0].id == repo.id
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): Also assert environment is cleared when content_view_environment_ids is emptied

Since these removal tests now only check that content_view becomes None after content_view_environment_ids = [], please also assert that ak.environment is None after the update. This better validates the backward‑compat behavior on the nailgun side when the CVE mapping is removed.

@LadislavVasina1 LadislavVasina1 requested a review from Copilot May 27, 2026 13:52
@LadislavVasina1 LadislavVasina1 self-requested a review May 27, 2026 13:53
@LadislavVasina1 LadislavVasina1 added the Stream Introduced in or relating directly to Satellite Stream/Master label May 27, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates Robottelo tests/fixtures/helpers to use Katello’s Content View Environment (CVE) identifiers (content_view_environment_ids / content_view_environment_id) instead of the deprecated separate CV/LCE parameters that are removed in Katello 4.21.

Changes:

  • Added APIFactory.get_cvenv_id() helper to resolve a CVE id from a Content View + Lifecycle Environment pair.
  • Updated Activation Key creation/update paths to set content_view_environment_ids instead of content_view + environment.
  • Updated Host/HostGroup-related test data to use CVE ids (content_view_environment_ids / content_view_environment_id) in content facet attributes and hostgroup creation.

Reviewed changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/new_upgrades/test_capsulecontent.py Switch AK creation to CVE ids for upgrade coverage.
tests/foreman/ui/test_oscappolicy.py Use CVE ids when creating a host with content facet attributes.
tests/foreman/ui/test_hostcollection.py Use CVE ids for hosts used in host collection tests.
tests/foreman/ui/test_host.py Replace host content facet CV/LCE ids with CVE ids in UI flows.
tests/foreman/ui/test_errata.py Update host content facet updates to use CVE ids.
tests/foreman/ui/test_activationkey.py Create AKs using content_view_environment_ids.
tests/foreman/endtoend/test_api_endtoend.py Use CVE ids for content hosts in end-to-end scenario.
tests/foreman/destructive/test_infoblox.py Provisioning host content facet uses CVE ids.
tests/foreman/api/test_subscription.py Update AK fixtures and host content facet updates to CVE ids.
tests/foreman/api/test_provisioningtemplate.py Provisioning template tests create hosts with CVE ids.
tests/foreman/api/test_provisioning.py PXE provisioning test sets CVE ids for host content facet.
tests/foreman/api/test_provisioning_puppet.py Puppet provisioning test sets CVE ids for host content facet.
tests/foreman/api/test_hostgroup.py Hostgroup/host content facet updated; hostgroup uses content_view_environment_id.
tests/foreman/api/test_host.py Host creation/update flows use content_view_environment_ids.
tests/foreman/api/test_docker.py AK create/update uses content_view_environment_ids and clearing uses empty list.
tests/foreman/api/test_contentview.py Host subscription and AK rolling-CV paths use CVE ids; updates clear via ids.
tests/foreman/api/test_activationkey.py AK tests create/search using content_view_environment_ids.
robottelo/host_helpers/api_factory.py Add get_cvenv_id() and update registration helper to set CVE ids on AK.
pytest_fixtures/core/contenthosts.py Content host registration fixture creates AK via CVE ids.
pytest_fixtures/component/rh_cloud.py RH cloud activation key fixtures use CVE ids.
pytest_fixtures/component/repository.py Repository fixture creates AK via CVE ids.
pytest_fixtures/component/provision_vmware.py VMware hostgroup fixture uses content_view_environment_id.
pytest_fixtures/component/provision_pxe.py PXE provisioning fixtures use CVE ids for AK/hostgroup.
pytest_fixtures/component/provision_ocpv.py OCPV hostgroup fixture uses content_view_environment_id.
pytest_fixtures/component/provision_capsule_pxe.py Capsule PXE fixtures use CVE ids for hostgroup/AK.
pytest_fixtures/component/leapp_client.py Leapp AK fixture uses CVE ids.
pytest_fixtures/component/contentview.py CV/LCE activation key fixture uses CVE ids.
pytest_fixtures/component/activationkey.py Activation key fixtures consistently use content_view_environment_ids.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

result = self._satellite.api.ContentViewEnvironment().list_content_view_environments(
params={'content_view_id': cv_id, 'lifecycle_environment_id': lce_id}
)
return result['results'][0]['id']
Comment on lines 665 to 675
hosts = []
for _ in range(2):
hosts.append(
module_target_sat.api.Host(
organization=module_org_with_parameter,
location=smart_proxy_location,
content_facet_attributes={
'content_view_id': cv.id,
'lifecycle_environment_id': lce.id,
'content_view_environment_ids': [
module_target_sat.api_factory.get_cvenv_id(cv, lce)
],
},
Update all API tests, fixtures, and helpers to use
content_view_environment_ids (activation keys, hosts) and
content_view_environment_id (hostgroups) instead of the removed
separate content_view_id and lifecycle_environment_id params.

Add get_cvenv_id() helper to api_factory for looking up
ContentViewEnvironment IDs from CV+LCE pairs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jeremylenz jeremylenz force-pushed the remove-deprecated-cv-lce-params branch from 6e86d38 to b2ffb02 Compare May 27, 2026 14:10
@Satellite-QE Satellite-QE removed the PRT-Passed Indicates that latest PRT run is passed for the PR label May 27, 2026
@jeremylenz
Copy link
Copy Markdown
Contributor Author

pre-commit.ci autofix

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.

5 participants