forked from fedora-copr/copr
-
Notifications
You must be signed in to change notification settings - Fork 0
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 fedora-copr#2132
- Loading branch information
Showing
4 changed files
with
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,8 @@ | |
# cute | ||
# multiline | ||
# snippet | ||
# | ||
# Chroots that require active Red Hat subscription | ||
# rhsm: | ||
# - rhel-* | ||
# - epel-* |
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,57 @@ | ||
""" | ||
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 os | ||
import time | ||
import logging | ||
from fnmatch import fnmatch | ||
|
||
|
||
log = logging.getLogger("__main__") | ||
|
||
|
||
def subscription_required(task, config): | ||
""" | ||
Is subscription required for this task? | ||
""" | ||
for pattern in config.rhsm: | ||
if fnmatch(task["chroot"], pattern): | ||
return True | ||
return False | ||
|
||
|
||
def active_subscription(): | ||
""" | ||
Is subscription active on this system? | ||
""" | ||
# This is not a 100% reliable check that the subscription is active. The | ||
# ideal check would be running `subscription-manager status` and checking | ||
# its exit code but that requires root privileges. This check will break | ||
# in the following corner cases: | ||
# - The system is registered and then halted for a long time and then | ||
# booted again after the entitlement is no longer valid | ||
# - The system is unregistered from the server (but not from the client | ||
# itself), making all the client files stale | ||
return os.path.exists("/etc/pki/consumer/cert.pem") | ||
|
||
|
||
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