Skip to content

Commit

Permalink
chore: move autoreg waiting code in own function
Browse files Browse the repository at this point in the history
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 85544b2)
  • Loading branch information
ptoscano committed Oct 2, 2024
1 parent 19f6b74 commit 8bbc063
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions src/subscription_manager/scripts/rhsmcertd_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,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.
Expand Down Expand Up @@ -268,17 +287,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")
Expand Down

0 comments on commit 8bbc063

Please sign in to comment.