From 95b93713151d520d0d3a7ab715cd254d4bc75458 Mon Sep 17 00:00:00 2001 From: Jason Jerome Date: Tue, 3 Mar 2026 15:24:01 -0500 Subject: [PATCH] fix: skip package profile upload when disabled in config This patch checks the rhsm config to ensure the "report_package_profile" setting is not ignored during registration. Previously, this setting was ignored and the package profile was forced to upload. Resolves: RHEL-73923 AI Usage Disclosure: This commit contains test cases that were created with the assistance of AI tools. Signed-off-by: Jason Jerome --- .../cli_command/register.py | 8 ++-- test/test_registration.py | 39 +++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/subscription_manager/cli_command/register.py b/src/subscription_manager/cli_command/register.py index a96112cedc..09f7a29ee1 100644 --- a/src/subscription_manager/cli_command/register.py +++ b/src/subscription_manager/cli_command/register.py @@ -188,8 +188,7 @@ def _upload_profile(self, consumer: dict) -> None: # of DNF profile by rhsmcertd. We try to "outsource" this activity to rhsmcertd # server to not block registration process. # Note: rhsmcertd tries to upload profile using Python script and this script - # is always triggered with --force-upload CLI option. We ignore report_package_config - # configure option here due to BZ: 767265 + # is always triggered with --force-upload CLI option. log.debug("Sending SIGUSR1 signal to rhsmcertd process") try: os.kill(rhsmcertd_pid, signal.SIGUSR1) @@ -346,7 +345,10 @@ def _do_command(self): # FIXME: aside from the overhead, should this be cert_action_client.update? self.entcertlib.update() - self._upload_profile(consumer) + if conf["rhsm"].get_int("report_package_profile") == 1: + self._upload_profile(consumer) + else: + log.info("Skipping package profile upload due to report_package_profile config setting.") self._request_validity_check() diff --git a/test/test_registration.py b/test/test_registration.py index ef8ba30766..9720ef0275 100644 --- a/test/test_registration.py +++ b/test/test_registration.py @@ -18,6 +18,7 @@ from .stubs import StubUEP +from subscription_manager.cli_command import register from subscription_manager.cli_command.register import RegisterCommand from subscription_manager import injection as inj from subscription_manager import cache @@ -322,6 +323,44 @@ def env_list(*args, **kwargs): with self.assertRaises(SystemExit): rc._process_environments(mock_uep, "owner") + def test_registration_with_package_profile_disabled(self): + rhsm_conf_original_value = register.conf["rhsm"].get_int + + def get_package_profile_disabled(key): + return 0 if key == "report_package_profile" else rhsm_conf_original_value(key) + + with patch("rhsm.connection.UEPConnection", new_callable=StubUEP) as mock_uep: + self.stub_cp_provider.basic_auth_cp = mock_uep + cmd = RegisterCommand() + cmd._upload_profile = Mock() + + with patch.object(register.conf["rhsm"], "get_int", side_effect=get_package_profile_disabled): + with Capture() as cap: + cmd.main(["--force", "--username", "admin", "--password", "admin", "--org", "admin"]) + output = cap.out + self.assertTrue("The system has been registered with ID" in output) + self.assertTrue("The registered system name is:" in output) + cmd._upload_profile.assert_not_called() + + def test_registration_with_package_profile_enabled(self): + rhsm_conf_original_value = register.conf["rhsm"].get_int("report_package_profile") + + def get_package_profile_enabled(key): + return 1 if key == "report_package_profile" else rhsm_conf_original_value(key) + + with patch("rhsm.connection.UEPConnection", new_callable=StubUEP) as mock_uep: + self.stub_cp_provider.basic_auth_cp = mock_uep + cmd = RegisterCommand() + cmd._upload_profile = Mock() + + with patch.object(register.conf["rhsm"], "get_int", side_effect=get_package_profile_enabled): + with Capture() as cap: + cmd.main(["--force", "--username", "admin", "--password", "admin", "--org", "admin"]) + output = cap.out + self.assertTrue("The system has been registered with ID" in output) + self.assertTrue("The registered system name is:" in output) + cmd._upload_profile.assert_called_once() + def test_registration_with_failed_profile_upload(self): with patch("rhsm.connection.UEPConnection", new_callable=StubUEP) as mock_uep: profile_mgr = inj.require(inj.PROFILE_MANAGER)