-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Activate Red Hat subscription on demand #3426
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,94 @@ | ||
#! /usr/bin/python3 | ||
|
||
""" | ||
Final checks that the builder machine is ready to be used | ||
|
||
Everything printed to STDOUT will be redirected to the copr-backend logs, | ||
STDERR will be ignored. | ||
""" | ||
|
||
import os | ||
import sys | ||
import time | ||
from fnmatch import fnmatch | ||
from copr_rpmbuild.config import Config | ||
|
||
|
||
def check_mock_config(chroot): | ||
""" | ||
Does the mock config for this chroot exist? | ||
""" | ||
if chroot == "srpm-builds": | ||
return | ||
|
||
config = "/etc/mock/{}.cfg".format(chroot) | ||
if os.path.isfile(config): | ||
praiskup marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return | ||
|
||
print("Chroot config {} not found".format(config)) | ||
sys.exit(1) | ||
|
||
|
||
def subscription_required(chroot): | ||
""" | ||
Is subscription required for this task? | ||
""" | ||
config = Config() | ||
config.load_config() | ||
|
||
for pattern in config.rhsm: | ||
if fnmatch(chroot, pattern): | ||
return True | ||
return False | ||
|
||
|
||
def active_subscription(): | ||
""" | ||
Is subscription active on this system? | ||
""" | ||
# There are standard-ish ways for checking whether the subscription is | ||
# active. No silver bullet, all of them have trade-offs. | ||
# - Checking the existence of `/etc/pki/consumer/cert.pem` file | ||
# - Checking the existence of `/etc/pki/entitlement/*.pem` files | ||
# - Exit code from `subscription-manager status` | ||
# - Exit code from `subscription-manager identity` | ||
# We don't want to rely on any of them. We use a custom daemon for | ||
# registering the system on the background. Once it is done, | ||
# it creates a file. | ||
return os.path.exists("/run/copr-builder/rhsm-subscribed") | ||
|
||
|
||
def wait_for_subscription(timeout=600): | ||
""" | ||
Wait until this system has an active subscription | ||
|
||
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. | ||
""" | ||
start = time.time() | ||
attempt = 1 | ||
while True: | ||
print("Checking Red Hat subscription (attempt #{0})".format(attempt)) | ||
if active_subscription(): | ||
print("Red Hat subscription active") | ||
return | ||
if time.time() > start + timeout: | ||
print("Waiting for Red Hat subscription timeouted!") | ||
sys.exit(1) | ||
time.sleep(30) | ||
attempt += 1 | ||
|
||
|
||
def main(): | ||
""" | ||
The entrypoint for this script | ||
""" | ||
chroot = sys.argv[1] | ||
check_mock_config(chroot) | ||
if subscription_required(chroot): | ||
wait_for_subscription() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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 |
---|---|---|
|
@@ -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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a nit: separate method would be nice