Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the not-satellite: prefix for server hostname #5828

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pyanaconda/modules/subscription/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
10 changes: 9 additions & 1 deletion pyanaconda/modules/subscription/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
Loading