Skip to content

Deprecate content_view and lifecycle_environment parameters#1977

Open
jeremylenz wants to merge 3 commits into
theforeman:developfrom
jeremylenz:deprecate-cv-lce-params
Open

Deprecate content_view and lifecycle_environment parameters#1977
jeremylenz wants to merge 3 commits into
theforeman:developfrom
jeremylenz:deprecate-cv-lce-params

Conversation

@jeremylenz
Copy link
Copy Markdown
Contributor

Deprecates the content_view and lifecycle_environment parameters in the activation_key, host, and hostgroup modules.

On newer Katello versions (where the old API parameters are removed), the modules internally convert these deprecated parameters to the new content_view_environment_id(s) API parameters. Multi-CV entities are protected from accidental overwrite. Old Katello versions continue to work unchanged.

Files changed:

  • plugins/module_utils/foreman_helper.py — helper method, HostMixin conversion logic, workaround safety fix
  • plugins/modules/activation_key.py — AK-specific conversion logic + deprecation docs
  • plugins/doc_fragments/foreman.py — deprecation notices in HOST_OPTIONS
  • changelogs/fragments/deprecate-cv-lce-params.yml — changelog entry

Related Katello PR: Katello/katello#11753

Deprecate content_view and lifecycle_environment parameters in activation_key, host, and hostgroup modules. On newer Katello versions, modules convert these deprecated params to content_view_environment_id(s). Multi-CV entities are protected from accidental overwrite. Old Katello versions continue to work unchanged.
@jeremylenz
Copy link
Copy Markdown
Contributor Author

jeremylenz commented May 19, 2026

Manual test results

All 7 tests pass against both:

  • New Katello (sat-38100-remove-deprecated-cv-lce-params branch) — conversion fires, deprecation warnings emitted
  • Old Katello (master branch) — conversion skips, old params flow through natively, no warnings
Test New Katello Old Katello
1 - AK create with deprecated params PASS (warns) PASS (no warn)
2 - AK idempotency with deprecated params PASS PASS
3 - AK create with content_view_environments PASS PASS
4 - AK content_view_environments idempotency PASS PASS
5 - Multi-CV AK protection PASS (fails with error) PASS (no-op, old API ignores)
6 - Hostgroup create with deprecated params PASS (warns) PASS (no warn)
7 - Hostgroup idempotency with deprecated params PASS PASS

Test vars (test_cv_lce_vars.yml)

foreman_server_url: "https://your-foreman.example.com"
foreman_username: "admin"
foreman_password: "changeme"
foreman_validate_certs: false
test_organization: "Default Organization"
test_lifecycle_environment: "Library"
test_content_view: "Default Organization View"
# The default CVE label is just the LCE label (e.g. "Library"),
# not "Library/Default_Organization_View". Non-default CVEs use "lce_label/cv_label".
test_cve_label: "Library"
test_lifecycle_environment_2: "dev"
test_content_view_2: "cv1"

Test playbook (test_deprecate_cv_lce.yml)

Run with: ansible-playbook test_deprecate_cv_lce.yml -e @test_cv_lce_vars.yml

Prerequisites:

  • Katello server (works with both old and new API)
  • allow_multiple_content_views setting enabled (for test 5)
  • A second content view promoted to a second lifecycle environment (for test 5)
---
- name: "Test deprecated CV/LCE param handling"
  hosts: localhost
  collections:
    - theforeman.foreman
  gather_facts: false
  vars:
    foreman_conn: &foreman_conn
      server_url: "{{ foreman_server_url }}"
      username: "{{ foreman_username }}"
      password: "{{ foreman_password }}"
      validate_certs: "{{ foreman_validate_certs }}"
  tasks:

    # =========================================================================
    # CLEANUP (before tests, so playbook is re-runnable)
    # =========================================================================

    - name: "Setup - Remove leftover test resources"
      block:
        - activation_key:
            <<: *foreman_conn
            organization: "{{ test_organization }}"
            name: "{{ item }}"
            state: absent
          loop:
            - "test-deprecated-cv-lce"
            - "test-new-cve-param"
            - "test-multi-cv-ak"
          ignore_errors: true
        - hostgroup:
            <<: *foreman_conn
            name: "test-deprecated-cv-lce-hg"
            state: absent
          ignore_errors: true

    # =========================================================================
    # ACTIVATION KEY TESTS
    # =========================================================================

    - name: "Test 1 - AK create with deprecated params (should warn + succeed)"
      activation_key:
        <<: *foreman_conn
        organization: "{{ test_organization }}"
        name: "test-deprecated-cv-lce"
        lifecycle_environment: "{{ test_lifecycle_environment }}"
        content_view: "{{ test_content_view }}"
        state: present
      register: ak_create
    - debug:
        msg: "Test 1: changed={{ ak_create.changed }}, warnings={{ ak_create.warnings | default([]) }}"
    - assert:
        that: ak_create.changed
        fail_msg: "Test 1 FAILED - AK should have been created"

    - name: "Test 2 - AK idempotency with deprecated params (should not change)"
      activation_key:
        <<: *foreman_conn
        organization: "{{ test_organization }}"
        name: "test-deprecated-cv-lce"
        lifecycle_environment: "{{ test_lifecycle_environment }}"
        content_view: "{{ test_content_view }}"
        state: present
      register: ak_idempotent
    - debug:
        msg: "Test 2: changed={{ ak_idempotent.changed }}"
    - assert:
        that: not ak_idempotent.changed
        fail_msg: "Test 2 FAILED - AK should be idempotent (no change)"

    - name: "Test 3 - AK create with content_view_environments param (no deprecation warning)"
      activation_key:
        <<: *foreman_conn
        organization: "{{ test_organization }}"
        name: "test-new-cve-param"
        content_view_environments:
          - "{{ test_cve_label }}"
        state: present
      register: ak_cve
    - debug:
        msg: "Test 3: changed={{ ak_cve.changed }}, warnings={{ ak_cve.warnings | default([]) }}"
    - assert:
        that: ak_cve.changed
        fail_msg: "Test 3 FAILED - AK with content_view_environments should have been created"

    - name: "Test 4 - AK with content_view_environments idempotency"
      activation_key:
        <<: *foreman_conn
        organization: "{{ test_organization }}"
        name: "test-new-cve-param"
        content_view_environments:
          - "{{ test_cve_label }}"
        state: present
      register: ak_cve_idempotent
    - debug:
        msg: "Test 4: changed={{ ak_cve_idempotent.changed }}"
    - assert:
        that: not ak_cve_idempotent.changed
        fail_msg: "Test 4 FAILED - AK with content_view_environments should be idempotent"

    - name: "Test 5 - AK multi-CV protection (should FAIL if multi-CV)"
      when: test_content_view_2 is defined and test_lifecycle_environment_2 is defined
      block:
        - name: "Test 5a - Set up multi-CV activation key"
          activation_key:
            <<: *foreman_conn
            organization: "{{ test_organization }}"
            name: "test-multi-cv-ak"
            content_view_environments:
              - "{{ test_cve_label }}"
              - "{{ test_lifecycle_environment_2 }}/{{ test_content_view_2 }}"
            state: present

        - name: "Test 5b - Try deprecated params on multi-CV AK"
          activation_key:
            <<: *foreman_conn
            organization: "{{ test_organization }}"
            name: "test-multi-cv-ak"
            lifecycle_environment: "{{ test_lifecycle_environment }}"
            content_view: "{{ test_content_view }}"
            state: present
          register: ak_multi_cv
          ignore_errors: true
        - debug:
            msg: >-
              Test 5: failed={{ ak_multi_cv.failed }},
              changed={{ ak_multi_cv.changed | default('N/A') }},
              msg={{ ak_multi_cv.msg | default('') }}
        # New API: should fail with multi-CV protection error
        # Old API: should succeed but not change (old API silently ignores single params on multi-CV AKs)
        - assert:
            that: ak_multi_cv.failed or not ak_multi_cv.changed
            fail_msg: "Test 5 FAILED - Should either fail (new API) or be a no-op (old API), not change the AK"

    # =========================================================================
    # HOSTGROUP TESTS
    # =========================================================================

    - name: "Test 6 - Hostgroup create with deprecated params (should warn + succeed)"
      hostgroup:
        <<: *foreman_conn
        organization: "{{ test_organization }}"
        name: "test-deprecated-cv-lce-hg"
        lifecycle_environment: "{{ test_lifecycle_environment }}"
        content_view: "{{ test_content_view }}"
        state: present
      register: hg_create
    - debug:
        msg: "Test 6: changed={{ hg_create.changed }}, warnings={{ hg_create.warnings | default([]) }}"
    - assert:
        that: hg_create.changed
        fail_msg: "Test 6 FAILED - Hostgroup should have been created"

    - name: "Test 7 - Hostgroup idempotency with deprecated params"
      hostgroup:
        <<: *foreman_conn
        organization: "{{ test_organization }}"
        name: "test-deprecated-cv-lce-hg"
        lifecycle_environment: "{{ test_lifecycle_environment }}"
        content_view: "{{ test_content_view }}"
        state: present
      register: hg_idempotent
    - debug:
        msg: "Test 7: changed={{ hg_idempotent.changed }}"
    - assert:
        that: not hg_idempotent.changed
        fail_msg: "Test 7 FAILED - Hostgroup should be idempotent (no change)"

    # =========================================================================
    # CLEANUP (after tests)
    # =========================================================================

    - name: "Cleanup - Remove test activation keys"
      activation_key:
        <<: *foreman_conn
        organization: "{{ test_organization }}"
        name: "{{ item }}"
        state: absent
      loop:
        - "test-deprecated-cv-lce"
        - "test-new-cve-param"
        - "test-multi-cv-ak"
      ignore_errors: true

    - name: "Cleanup - Remove test hostgroup"
      hostgroup:
        <<: *foreman_conn
        name: "test-deprecated-cv-lce-hg"
        state: absent
      ignore_errors: true

Rename `_` to `_filtered` in validate_payload tuple unpacking
to satisfy pylint's disallowed-name check.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jeremylenz
Copy link
Copy Markdown
Contributor Author

Pushed. The CI failures break down as:

  - Sanity tests (all versions): Fixed — was pylint complaining about _ as a variable name in our tuple unpacking. Renamed to _filtered.
  - Build tests (devel, 2.21, 3.13, 3.14): Pre-existing callback fixture mismatches from newer ansible-core versions. Unrelated to our changes — these would fail on any PR right now.

Check whether the old content_view_id param is absent (removed)
rather than whether content_view_environment_id is present,
since older Katello versions have both params simultaneously.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@jeremylenz
Copy link
Copy Markdown
Contributor Author

Fixed an issue with the test playbook; it should now run on both Katello master and PR branch.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant