-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpmbuild, frontend: activate Red Hat subscription on demand
Fix #2132
- Loading branch information
Showing
3 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
""" | ||
Red Hat Subscription Management | ||
Activating Red Hat subscription may take a lot of time and historically, the | ||
subscription service used to be unreliable, so we should wait for the | ||
subscription only when necessary. | ||
""" | ||
|
||
import time | ||
import logging | ||
import subprocess | ||
|
||
|
||
log = logging.getLogger("__main__") | ||
|
||
|
||
def subscription_required(task): | ||
""" | ||
Is subscription required for this task? | ||
""" | ||
return "subscription" in task["tags"] | ||
|
||
|
||
def active_subscription(): | ||
""" | ||
Is subscription active on this system? | ||
""" | ||
cmd = ["subscription-manager", "status"] | ||
proc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
Check warning Code scanning / vcs-diff-lint active_subscription: 'subprocess.run' used without explicitly defining the value for 'check'. Warning
active_subscription: 'subprocess.run' used without explicitly defining the value for 'check'.
|
||
return proc.returncode == 0 | ||
|
||
|
||
def wait_for_subscription(timeout=86400): | ||
""" | ||
Wait until this system has an active subscription | ||
""" | ||
start = time.time() | ||
attempt = 1 | ||
while True: | ||
log.info("Checking Red Hat subscription (attempt #%s)", attempt) | ||
if active_subscription(): | ||
log.info("Red Hat subscription active") | ||
return | ||
if time.time() > start + timeout: | ||
raise RuntimeError("Waiting for Red Hat subscription timeouted!") | ||
time.sleep(30) | ||
attempt += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters