From 8a9bbebabe887a518c71206e4609e4487cf2624e Mon Sep 17 00:00:00 2001 From: Jiri Hnidek Date: Mon, 9 Dec 2024 11:43:20 +0100 Subject: [PATCH] feat: Enable register with environment names * Allow to register with environment names, not only environment IDs. it is possible to use username & password and activation keys & organization * Modified few unit tests --- src/rhsm/connection.py | 8 +++++++- src/rhsmlib/services/register.py | 3 +++ test/rhsmlib/services/test_register.py | 4 ++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/rhsm/connection.py b/src/rhsm/connection.py index 163b8ef055..bc7f06f584 100644 --- a/src/rhsm/connection.py +++ b/src/rhsm/connection.py @@ -1536,6 +1536,7 @@ def registerConsumer( facts: Optional[dict] = None, owner: str = None, environments: str = None, + environment_names: str = None, keys: str = None, installed_products: list = None, uuid: str = None, @@ -1576,7 +1577,12 @@ def registerConsumer( params["usage"] = usage if service_level is not None: params["serviceLevel"] = service_level - if environments is not None and self.has_capability(MULTI_ENV): + if environment_names is not None and self.has_capability(MULTI_ENV): + env_name_list = [] + for env_name in environment_names.split(","): + env_name_list.append({"name": env_name}) + params["environments"] = env_name_list + elif environments is not None and self.has_capability(MULTI_ENV): env_list = [] for environment in environments.split(","): env_list.append({"id": environment}) diff --git a/src/rhsmlib/services/register.py b/src/rhsmlib/services/register.py index f3fe421d61..a5115e8782 100644 --- a/src/rhsmlib/services/register.py +++ b/src/rhsmlib/services/register.py @@ -46,6 +46,7 @@ def register( org: Optional[str], activation_keys: list = None, environments: list = None, + environment_names: list = None, force: bool = False, name: str = None, consumerid: str = None, @@ -95,6 +96,7 @@ def register( options = { "activation_keys": activation_keys, "environments": environments, + "environment_names": environment_names, "force": force, "name": name, "consumerid": consumerid, @@ -123,6 +125,7 @@ def register( facts=facts_dict, owner=org, environments=environments, + environment_names=environment_names, keys=options.get("activation_keys"), installed_products=self.installed_mgr.format_for_server(), content_tags=self.installed_mgr.tags, diff --git a/test/rhsmlib/services/test_register.py b/test/rhsmlib/services/test_register.py index 223eed10fc..69d9ca5748 100644 --- a/test/rhsmlib/services/test_register.py +++ b/test/rhsmlib/services/test_register.py @@ -229,6 +229,7 @@ def test_register_normally(self, mock_persist_consumer, mock_write_cache): facts={}, owner="org", environments="environment", + environment_names=None, keys=None, installed_products=[], jwt_token=None, @@ -348,6 +349,7 @@ def _no_owner_cb(username): facts={}, owner="snowwhite", environments="environment", + environment_names=None, keys=None, installed_products=[], jwt_token=None, @@ -388,6 +390,7 @@ def test_register_with_activation_keys(self, mock_persist_consumer, mock_write_c facts={}, owner="org", environments=None, + environment_names=None, keys=[1], installed_products=[], jwt_token=None, @@ -473,6 +476,7 @@ def test_reads_syspurpose(self, mock_persist_consumer, mock_write_cache): addons=["addon1"], content_tags=[], environments=None, + environment_names=None, facts={}, installed_products=[], jwt_token=None,