diff --git a/pyanaconda/modules/subscription/constants.py b/pyanaconda/modules/subscription/constants.py index 8ccd146118f..01a6cb8f4b6 100644 --- a/pyanaconda/modules/subscription/constants.py +++ b/pyanaconda/modules/subscription/constants.py @@ -20,3 +20,5 @@ # name of the RHSM systemd unit RHSM_SERVICE_NAME = "rhsm.service" +# server hostname prefix marking the URL as not Satellite +SERVER_HOSTNAME_NOT_SATELLITE_PREFIX = "not-satellite:" diff --git a/pyanaconda/modules/subscription/runtime.py b/pyanaconda/modules/subscription/runtime.py index 7a517091e51..a996bec7048 100644 --- a/pyanaconda/modules/subscription/runtime.py +++ b/pyanaconda/modules/subscription/runtime.py @@ -33,6 +33,7 @@ from pyanaconda.modules.common.structures.subscription import AttachedSubscription, \ SystemPurposeData from pyanaconda.modules.subscription import system_purpose +from pyanaconda.modules.subscription.constants import SERVER_HOSTNAME_NOT_SATELLITE_PREFIX from pyanaconda.anaconda_loggers import get_module_logger import gi @@ -176,8 +177,15 @@ def run(self): # - all values need to be string variants # - proxy password is stored in SecretData instance and we need to retrieve # its value + # - server host name might have a prefix indicating the given URL is not + # a Satellite URL, drop that prefix before setting the value to RHSM + + # drop the not-satellite prefix, if any + server_hostname = self._request.server_hostname.removeprefix( + SERVER_HOSTNAME_NOT_SATELLITE_PREFIX + ) property_key_map = { - self.CONFIG_KEY_SERVER_HOSTNAME: self._request.server_hostname, + self.CONFIG_KEY_SERVER_HOSTNAME: server_hostname, self.CONFIG_KEY_SERVER_PROXY_HOSTNAME: self._request.server_proxy_hostname, self.CONFIG_KEY_SERVER_PROXY_PORT: str(self._request.server_proxy_port), self.CONFIG_KEY_SERVER_PROXY_USER: self._request.server_proxy_user, diff --git a/tests/unit_tests/pyanaconda_tests/modules/subscription/test_subscription_tasks.py b/tests/unit_tests/pyanaconda_tests/modules/subscription/test_subscription_tasks.py index 3ad7f1f4c6a..b66dc0e93b7 100644 --- a/tests/unit_tests/pyanaconda_tests/modules/subscription/test_subscription_tasks.py +++ b/tests/unit_tests/pyanaconda_tests/modules/subscription/test_subscription_tasks.py @@ -287,6 +287,50 @@ def test_set_rhsm_config_tast_restore_default_value(self): mock_config_proxy.SetAll.assert_called_once_with(expected_dict, "") + def test_set_rhsm_config_task_not_satellite(self): + """Test the SetRHSMConfigurationTask task - not-satellite prefix handling.""" + # if the subscription request has the no-satellite prefix, it should be stripped + # before the server hostname value is sent to RHSM + mock_config_proxy = Mock() + # RHSM config default values + default_config = { + SetRHSMConfigurationTask.CONFIG_KEY_SERVER_HOSTNAME: "server.example.com", + SetRHSMConfigurationTask.CONFIG_KEY_SERVER_PROXY_HOSTNAME: "proxy.example.com", + SetRHSMConfigurationTask.CONFIG_KEY_SERVER_PROXY_PORT: "1000", + SetRHSMConfigurationTask.CONFIG_KEY_SERVER_PROXY_USER: "foo_user", + SetRHSMConfigurationTask.CONFIG_KEY_SERVER_PROXY_PASSWORD: "foo_password", + SetRHSMConfigurationTask.CONFIG_KEY_RHSM_BASEURL: "cdn.example.com", + "key_anaconda_does_not_use_1": "foo1", + "key_anaconda_does_not_use_2": "foo2" + } + # a representative subscription request + request = SubscriptionRequest() + request.type = SUBSCRIPTION_REQUEST_TYPE_ORG_KEY + request.organization = "123456789" + request.account_username = "foo_user" + request.server_hostname = "not-satellite:candlepin.foo.com" + request.rhsm_baseurl = "cdn.foo.com" + request.server_proxy_hostname = "proxy.foo.com" + request.server_proxy_port = 9001 + request.server_proxy_user = "foo_proxy_user" + request.account_password.set_secret("foo_password") + request.activation_keys.set_secret(["key1", "key2", "key3"]) + request.server_proxy_password.set_secret("foo_proxy_password") + # create a task + task = SetRHSMConfigurationTask(rhsm_config_proxy=mock_config_proxy, + rhsm_config_defaults=default_config, + subscription_request=request) + task.run() + # check that we tried to set the expected config keys via the RHSM config DBus API + expected_dict = {"server.hostname": get_variant(Str, "candlepin.foo.com"), + "server.proxy_hostname": get_variant(Str, "proxy.foo.com"), + "server.proxy_port": get_variant(Str, "9001"), + "server.proxy_user": get_variant(Str, "foo_proxy_user"), + "server.proxy_password": get_variant(Str, "foo_proxy_password"), + "rhsm.baseurl": get_variant(Str, "cdn.foo.com")} + + mock_config_proxy.SetAll.assert_called_once_with(expected_dict, "") + class RestoreRHSMDefaultsTaskTestCase(unittest.TestCase): """Test the RestoreRHSMDefaultsTask task."""