From c8eb27cc5f9eddd142082ed07e11efd0996da871 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Tue, 1 Oct 2024 14:49:21 +0200 Subject: [PATCH 1/2] chore: move autoreg waiting code in own function Move the code that performs the waiting/delay during automatic registration in its own function; this way it can be reused also in other places. This is only a code recfatoring, there is no behaviour changes. (cherry picked from commit 85544b28764a9ed4edf5824ca1de5f16b875391b) --- .../scripts/rhsmcertd_worker.py | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/subscription_manager/scripts/rhsmcertd_worker.py b/src/subscription_manager/scripts/rhsmcertd_worker.py index 236b095a4..05af1130e 100644 --- a/src/subscription_manager/scripts/rhsmcertd_worker.py +++ b/src/subscription_manager/scripts/rhsmcertd_worker.py @@ -160,6 +160,25 @@ def _collect_cloud_info(cloud_list: List[str]) -> dict: return result +def _auto_register_wait() -> None: + """Delay during the automatic registration. + + Wait for an amount of time during automatic registration, looking at the + configured splay and autoregistration interval. + """ + cfg = config.get_config_parser() + if cfg.get("rhsmcertd", "splay") == "0": + log.debug("Trying to obtain the identity immediately, splay is disabled.") + else: + registration_interval = int(cfg.get("rhsmcertd", "auto_registration_interval")) + splay_interval: int = random.randint(60, registration_interval * 60) + log.debug( + f"Waiting a period of {splay_interval} seconds " + f"(about {splay_interval // 60} minutes) before attempting to obtain the identity." + ) + time.sleep(splay_interval) + + def _auto_register(cp_provider: "CPProvider") -> ExitStatus: """Try to perform automatic registration. @@ -245,17 +264,7 @@ def _auto_register_anonymous(uep: "UEPConnection", token: Dict[str, str]) -> Non manager.install_temporary_certificates(uuid=token["anonymousConsumerUuid"], jwt=token["token"]) # Step 2: Wait - cfg = config.get_config_parser() - if cfg.get("rhsmcertd", "splay") == "0": - log.debug("Trying to obtain the identity immediately, splay is disabled.") - else: - registration_interval = int(cfg.get("rhsmcertd", "auto_registration_interval")) - splay_interval: int = random.randint(60, registration_interval * 60) - log.debug( - f"Waiting a period of {splay_interval} seconds " - f"(about {splay_interval // 60} minutes) before attempting to obtain the identity." - ) - time.sleep(splay_interval) + _auto_register_wait() # Step 3: Obtain the identity certificate log.debug("Obtaining system identity") From aee5b01684ecbbe56782075bb131596b06773676 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Tue, 1 Oct 2024 15:12:18 +0200 Subject: [PATCH 2/2] fix: perform autoreg waiting when performing standard autoreg The initial delay when performing the standard autoregistration used to be done directly in rhsmcertd (the C daemon). When the anonymous autoregistration was implemented, since it has to start immediately, that delay in rhsmcertd was dropped in favour of doing it "inline" during the autoregistration. The waiting was added only during the anonymous autoregistration flow and not during the standard autoregistration. Hence, add the autoregistration wait/delay before performing the standard autoregistration, restoring the previous behaviour. (cherry picked from commit 0d27a5919dbe8e2406c9b81f93cfb5a94eae9379) --- src/subscription_manager/scripts/rhsmcertd_worker.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/subscription_manager/scripts/rhsmcertd_worker.py b/src/subscription_manager/scripts/rhsmcertd_worker.py index 05af1130e..8f377db06 100644 --- a/src/subscription_manager/scripts/rhsmcertd_worker.py +++ b/src/subscription_manager/scripts/rhsmcertd_worker.py @@ -239,6 +239,8 @@ def _auto_register_standard(uep: "UEPConnection", token: Dict[str, str]) -> None """ log.debug("Registering the system through standard automatic registration.") + _auto_register_wait() + service = RegisterService(cp=uep) service.register(org=None, jwt_token=token)