Skip to content

Conversation

nacoool
Copy link
Contributor

@nacoool nacoool commented Oct 10, 2025

Problem Statement

There are no automated checks to verify Capsule Hammer functionality before and after an upgrade. Manual validation is time-consuming and prone to human error.

Solution

Added a new test class TestCapsuleHammer that validates Capsule Hammer in two phases:

  • Pre-upgrade: Confirms capsule configuration and baseline functionality before upgrade.

  • Post-upgrade: Runs dependent validation after upgrade to ensure functionality remains intact.

Related Issues

@nacoool nacoool requested a review from a team October 10, 2025 10:05
@nacoool nacoool requested a review from a team as a code owner October 10, 2025 10:05
@nacoool nacoool added QETestCoverage Issues and PRs relating to a Satellite bug CherryPick PR needs CherryPick to previous branches AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing 6.18.z Introduced in or relating directly to Satellite 6.18 labels Oct 10, 2025
Copy link

@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 there - I've reviewed your changes - here's some feedback:

  • Instead of hardcoding “satellite-capsule-6.19” in the post-upgrade check, parameterize the expected capsule version from settings or fixtures so it doesn’t break on version bumps.
  • Consider extracting repeated command execution and assertion logic (e.g. yum repo creation, package installation checks) into helper functions or fixtures to reduce duplication and improve readability.
  • Double-check the pytest.mark.post_upgrade(depend_on=…) usage to ensure it correctly references the pre-upgrade test (string or marker) so the dependency is actually enforced.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Instead of hardcoding “satellite-capsule-6.19” in the post-upgrade check, parameterize the expected capsule version from settings or fixtures so it doesn’t break on version bumps.
- Consider extracting repeated command execution and assertion logic (e.g. yum repo creation, package installation checks) into helper functions or fixtures to reduce duplication and improve readability.
- Double-check the pytest.mark.post_upgrade(depend_on=…) usage to ensure it correctly references the pre-upgrade test (string or marker) so the dependency is actually enforced.

## Individual Comments

### Comment 1
<location> `tests/upgrades/test_capsulecontent.py:296-297` </location>
<code_context>
+        assert result.status == 0
+        result = module_capsule_configured.execute('yum install rubygem-hammer_cli_katello -y')
+        assert result.status == 0
+        result = module_capsule_configured.execute('rpm -qa | grep -i "hammer"')
+        assert "hammer_cli_katello" in result.stdout
+        assert result.status == 0
+
</code_context>

<issue_to_address>
**suggestion (testing):** Suggestion to verify hammer CLI functionality, not just installation.

Consider adding a test that runs a basic hammer CLI command to ensure it works as expected after installation.

```suggestion
        result = module_capsule_configured.execute('yum install rubygem-hammer_cli_katello -y')
        assert result.status == 0
        # Verify hammer CLI is functional
        result = module_capsule_configured.execute('hammer --version')
        assert result.status == 0
        assert "Hammer CLI" in result.stdout or "hammer" in result.stdout.lower()
```
</issue_to_address>

### Comment 2
<location> `tests/upgrades/test_capsulecontent.py:317-318` </location>
<code_context>
+            1. The capsule should be upgraded.
+            2. The hammer should be installed on Capsule.
+        """
+        result = module_capsule_configured.execute('rpm -qa | grep -i "capsule"')
+        assert "satellite-capsule-6.19" in result.stdout
+        assert result.status == 0
+        result = module_capsule_configured.execute('rpm -qa | grep -i "hammer"')
</code_context>

<issue_to_address>
**question (testing):** Question about hardcoded version check for capsule upgrade.

If the expected version changes in future releases, this test may fail. Please consider parameterizing the version or using a more flexible check.
</issue_to_address>

### Comment 3
<location> `tests/upgrades/test_capsulecontent.py:302-303` </location>
<code_context>
+        assert "hammer_cli_katello" in result.stdout
+        assert result.status == 0
+
+    @pytest.mark.post_upgrade(depend_on=test_pre_upgrade_check_capsule_hammer)
+    def test_post_upgrade_check_capsule_hammer(self, module_capsule_configured):
+        """Post-upgrade scenario that verifies if the hammer is installed on Capsule
+        in the post-upgrade.
</code_context>

<issue_to_address>
**suggestion (testing):** Suggestion to add validation for repo sync after upgrade.

Please add a check to confirm the utils repository and its RPMs remain available and properly synced after the upgrade.

Suggested implementation:

```python
        result = module_capsule_configured.execute('yum install rubygem-hammer_cli_katello -y')
        assert result.status == 0
        result = module_capsule_configured.execute('rpm -qa | grep -i "hammer"')
        assert "hammer_cli_katello" in result.stdout
        assert result.status == 0

        # Validate utils repository and RPMs remain available and properly synced after upgrade
        result = module_capsule_configured.execute('yum repolist all')
        assert "Utils Repository" in result.stdout
        assert result.status == 0

        # Check for a known RPM from the utils repo (replace 'some-utils-rpm' with actual RPM name if needed)
        result = module_capsule_configured.execute('yum list available | grep -i "some-utils-rpm"')
        assert result.status == 0
        assert "some-utils-rpm" in result.stdout

        # Try installing the RPM to confirm availability
        result = module_capsule_configured.execute('yum install some-utils-rpm -y')
        assert result.status == 0

    @pytest.mark.post_upgrade(depend_on=test_pre_upgrade_check_capsule_hammer)
    def test_post_upgrade_check_capsule_hammer(self, module_capsule_configured):

```

- Replace "some-utils-rpm" with the actual RPM name from the utils repository that should be validated.
- If the repository name in `yum repolist all` output differs, adjust "Utils Repository" accordingly.
- If you have a helper for repo sync status, consider using it for more robust validation.
</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 302 to 303
@pytest.mark.post_upgrade(depend_on=test_pre_upgrade_check_capsule_hammer)
def test_post_upgrade_check_capsule_hammer(self, module_capsule_configured):
Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Suggestion to add validation for repo sync after upgrade.

Please add a check to confirm the utils repository and its RPMs remain available and properly synced after the upgrade.

Suggested implementation:

        result = module_capsule_configured.execute('yum install rubygem-hammer_cli_katello -y')
        assert result.status == 0
        result = module_capsule_configured.execute('rpm -qa | grep -i "hammer"')
        assert "hammer_cli_katello" in result.stdout
        assert result.status == 0

        # Validate utils repository and RPMs remain available and properly synced after upgrade
        result = module_capsule_configured.execute('yum repolist all')
        assert "Utils Repository" in result.stdout
        assert result.status == 0

        # Check for a known RPM from the utils repo (replace 'some-utils-rpm' with actual RPM name if needed)
        result = module_capsule_configured.execute('yum list available | grep -i "some-utils-rpm"')
        assert result.status == 0
        assert "some-utils-rpm" in result.stdout

        # Try installing the RPM to confirm availability
        result = module_capsule_configured.execute('yum install some-utils-rpm -y')
        assert result.status == 0

    @pytest.mark.post_upgrade(depend_on=test_pre_upgrade_check_capsule_hammer)
    def test_post_upgrade_check_capsule_hammer(self, module_capsule_configured):
  • Replace "some-utils-rpm" with the actual RPM name from the utils repository that should be validated.
  • If the repository name in yum repolist all output differs, adjust "Utils Repository" accordingly.
  • If you have a helper for repo sync status, consider using it for more robust validation.

Copy link
Contributor

@vsedmik vsedmik left a comment

Choose a reason for hiding this comment

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

I'm afraid this test needs to go into tests/new_upgrades and be updated accordingly.

The legacy tests/upgrades are not to be run in CI.

@nacoool
Copy link
Contributor Author

nacoool commented Oct 10, 2025

trigger: test-robottelo
pytest: tests/upgrades/test_capsulecontent.py -k TestCapsuleHammer
env:
ROBOTTELO_server__deploy_arguments__deploy_sat_version: '6.18'

@nacoool nacoool force-pushed the CapsuleHammerUpgrade branch from 81745f8 to e2f6967 Compare October 10, 2025 10:44
@nacoool
Copy link
Contributor Author

nacoool commented Oct 10, 2025

I'm afraid this test needs to go into tests/new_upgrades and be updated accordingly.

The legacy tests/upgrades are not to be run in CI.

I have added to new_upgrades now.

@nacoool
Copy link
Contributor Author

nacoool commented Oct 10, 2025

trigger: test-robottelo
pytest: tests/upgrades/test_capsulecontent.py -k "TestCapsuleHammer"
env:
ROBOTTELO_server__deploy_arguments__deploy_sat_version: '6.18'

@nacoool
Copy link
Contributor Author

nacoool commented Oct 10, 2025

trigger: test-robottelo
pytest: tests/new_upgrades/test_capsulecontent.py::TestCapsuleHammer
env:
ROBOTTELO_server__deploy_arguments__deploy_sat_version: '6.18'

@nacoool
Copy link
Contributor Author

nacoool commented Oct 10, 2025

trigger: test-robottelo
pytest: tests/new_upgrades/test_capsulecontent.py::TestCapsuleHammer
env:
    ROBOTTELO_server__deploy_workflows__product: 'deploy-satellite-upgrade'
    ROBOTTELO_server__deploy_arguments__deploy_rhel_version: '9'
    ROBOTTELO_server__deploy_arguments__deploy_sat_version: '6.18'
    ROBOTTELO_server__deploy_arguments__deploy_snap_version: 'ystream'
    BROKER_AnsibleTower__inventory: 'osp-rhos01-satellite-upgrade'

@Satellite-QE
Copy link
Collaborator

PRT Result

Build Number: 13118
Build Status: UNSTABLE
PRT Comment: pytest tests/new_upgrades/test_capsulecontent.py::TestCapsuleHammer --external-logging
Test Result : ======================== 4 warnings, 2 errors in 38.32s ========================

@Satellite-QE Satellite-QE added the PRT-Failed Indicates that latest PRT run is failed for the PR label Oct 10, 2025
@nacoool nacoool force-pushed the CapsuleHammerUpgrade branch from e2f6967 to 7117b11 Compare October 15, 2025 08:37
@nacoool
Copy link
Contributor Author

nacoool commented Oct 15, 2025

I'm afraid this test needs to go into tests/new_upgrades and be updated accordingly.

The legacy tests/upgrades are not to be run in CI.

I have added it to tests/foreman/maintain/test_upgrade.py with respect to component mentioned in the bug.

@nacoool nacoool force-pushed the CapsuleHammerUpgrade branch from 7117b11 to ed96980 Compare October 15, 2025 08:47
Copy link
Contributor

@vsedmik vsedmik left a comment

Choose a reason for hiding this comment

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

Proposed a couple of nit-picks, otherwise looks good.

Comment on lines +242 to +245
repo_config = f"[utils]\nname=Utils Repository\nbaseurl={settings.repos.satutils_repo}\nenabled=1\ngpgcheck=0\n"
result = module_capsule_configured.execute(
f'cat > /etc/yum.repos.d/utils.repo << EOF\n{repo_config}\nEOF'
)
Copy link
Contributor

Choose a reason for hiding this comment

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

You can use the create_custom_repos helper here and lower.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created Custom Repo using create_custom_repos

repo='capsule',
product='capsule',
release='stream',
os_release=9,
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we could use os_version (os_release=module_capsule_configured.os_version.major) so the test becomes future-proof when SAT and CAPS are based on RHEL10+.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

replaced with os_release=module_capsule_configured.os_version.major

assert "Upgrade finished." in result.stdout
result = module_capsule_configured.execute('rpm -qa | grep -i "capsule"')
assert result.status == 0
assert "satellite-capsule-6.19" in result.stdout
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar here, we should omit version hard-coding. We could use settings.server.version.release or just check it matches the original (pre-upgrade) version, since we are using the stream repos.

"""


@pytest.mark.upgrade
Copy link
Contributor

Choose a reason for hiding this comment

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

This decorator qualifies the test to being additionally run in the "upgade-all-tiers" pipeline (aka on a setup upgraded from n-1 version), apart from being run in the standard CI.

Is it something you intentionally want, or you just wanted to declare this test is related to upgrade? Then I would remove the decorator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to declare this test is related to capsule upgrade. Should i use any other decorator?

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope, I would just note it in the docstring and/or test name (you have that done already).

And please remove the @pytest.mark.upgrade decorator. Based on this decorator the upgrade all-tiers tests are collected, see the stream Upgrade > sat-stream-rhel9-ystream-upgrade-all-tiers job output in Jenkins how they are collected: py.test <some_options> tests/foreman -m upgrade

And I believe it was not intended in this case.

4. The capsule should be upgraded
5. The hammer should be installed on Capsule
:Verifies: SAT-37909
Copy link
Contributor

Choose a reason for hiding this comment

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

This linked issue feels incorrect, can you double-check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, My bad :-) ; adding correct number.

Comment on lines +304 to +306
result = module_capsule_configured.execute('rpm -qa | grep -i "hammer"')
assert "hammer_cli_katello" in result.stdout
assert result.status == 0
Copy link
Member

Choose a reason for hiding this comment

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

Do you want to validate something else here after hammer is installed like hammer ping?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Scope is to upgrade with a package like Hammer, Not to test the functionality of hammer in this scenario. So it is not required.

Comment on lines +256 to +259
capsule = dogfood_repository(
ohsnap=settings.ohsnap,
repo='capsule',
product='capsule',
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure why this is needed for hammer install? but if you really need it I'd suggest downloading a repofile from ohsnapUtils here on capsule instead of manually creating repofile

Copy link
Member

Choose a reason for hiding this comment

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

Also, when you checkout module_capsule_configured fixture, the provided capsule instance should have capsule repofile present on it already, so this could be redundant step here to add same repos

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No this code do not install hammer. but for capsule upgraded repos.

Comment on lines +304 to +305
result = module_capsule_configured.execute('rpm -qa | grep -i "hammer"')
assert "hammer_cli_katello" in result.stdout
Copy link
Member

Choose a reason for hiding this comment

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

Use either single quote or double quotes for your tests for better readability and consistency. Single quotes are preferred

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

assert "Successfully updated satellite-maintain" in result.stdout
result = module_capsule_configured.cli.Upgrade.run(
options={
'whitelist': 'repositories-validate, non-rh-packages, repositories-setup, pulpcore-rpm-datarepair',
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
'whitelist': 'repositories-validate, non-rh-packages, repositories-setup, pulpcore-rpm-datarepair',
'whitelist': 'repositories-validate, repositories-setup,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pulpcore-rpm-datarepair is required as mentioned in SAT-39207.

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

Labels

6.18.z Introduced in or relating directly to Satellite 6.18 AutoMerge_Cherry_Picked The cherrypicked PRs of master PR would be automerged if all checks passing CherryPick PR needs CherryPick to previous branches PRT-Failed Indicates that latest PRT run is failed for the PR QETestCoverage Issues and PRs relating to a Satellite bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants