Skip to content
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

add option to ignore registration failures #261

Merged
merged 1 commit into from
Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,20 @@ When registering a client, it is sometimes desirable to add a comment, denoting
--comment 'Crash Testing Server'
~~~

### Ignoring Registration Failures

When registering a client, it is sometimes desired to ignore registration failures reported via `subscription-manager` or `rhn-migrate-classic-to-rhsm`. The `--ignore-registration-failures` option allows `bootstrap.py` to continue running even when these commands return a non-zero error code. **NOTE**: it is the responsibility of the end-user to ensure, when using this option, that registration has completed successfully.

~~~
./bootstrap.py -l admin \
-s foreman.example.com \
-o "Red Hat" \
-L RDU \
-g "RHEL7/Crash" \
-a ak-Reg_To_Crash \
--ignore-registration-failures
~~~

# Help / Available options:

~~~
Expand Down Expand Up @@ -614,6 +628,10 @@ Options:
manager registration. Defaults to 900
-c COMMENT, --comment=COMMENT
Add a host comment
--ignore-registration-failures
Continue running even if registration via
subscription-manager/rhn-migrate-classic-to-rhsm
returns a non-zero return code.
~~~

# Additional Notes
Expand Down
15 changes: 12 additions & 3 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,12 @@ def migrate_systems(org_name, activationkey):
else:
options.rhsmargs += " --keep"
exec_failok("/usr/sbin/subscription-manager config --server.server_timeout=%s" % options.timeout)
exec_failexit("/usr/sbin/rhn-migrate-classic-to-rhsm --org %s --activation-key '%s' %s" % (org_label, activationkey, options.rhsmargs))
exec_failexit("subscription-manager config --rhsm.baseurl=https://%s/pulp/repos" % options.foreman_fqdn)
if options.ignore_registration_failures:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reading these branches, I wonder how often we will forget to update params in one of them.

how about we mangle exec_failok and exec_failexit into one function exec(command, failok=False) and make the other two sensible aliases to it? then we can just pass ignore_r_f as the failok param.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack, but I'd rather handle a refactoring of the exec* functions as a different PR. (because I am bound to mess it up :) )

exec_failok("/usr/sbin/rhn-migrate-classic-to-rhsm --org %s --activation-key '%s' %s" % (org_label, activationkey, options.rhsmargs))
exec_failok("subscription-manager config --rhsm.baseurl=https://%s/pulp/repos" % options.foreman_fqdn)
else:
exec_failexit("/usr/sbin/rhn-migrate-classic-to-rhsm --org %s --activation-key '%s' %s" % (org_label, activationkey, options.rhsmargs))
exec_failexit("subscription-manager config --rhsm.baseurl=https://%s/pulp/repos" % options.foreman_fqdn)
if options.release:
exec_failexit("subscription-manager release --set %s" % options.release)
enable_rhsmcertd()
Expand Down Expand Up @@ -377,7 +381,10 @@ def register_systems(org_name, activationkey):
if options.release:
options.smargs += " --release %s" % options.release
exec_failok("/usr/sbin/subscription-manager config --server.server_timeout=%s" % options.timeout)
exec_failexit("/usr/sbin/subscription-manager register --org '%s' --name '%s' --activationkey '%s' %s" % (org_label, FQDN, activationkey, options.smargs))
if options.ignore_registration_failures:
exec_failok("/usr/sbin/subscription-manager register --org '%s' --name '%s' --activationkey '%s' %s" % (org_label, FQDN, activationkey, options.smargs))
else:
exec_failexit("/usr/sbin/subscription-manager register --org '%s' --name '%s' --activationkey '%s' %s" % (org_label, FQDN, activationkey, options.smargs))
enable_rhsmcertd()


Expand Down Expand Up @@ -1063,6 +1070,7 @@ def exec_service(service, command, failonerror=True):
parser.add_option("--new-capsule", dest="new_capsule", action="store_true", help="Switch the server to a new capsule for content and Puppet. Pass --server with the Capsule FQDN as well.")
parser.add_option("-t", "--timeout", dest="timeout", type="int", help="Timeout (in seconds) for API calls and subscription-manager registration. Defaults to %default", metavar="timeout", default=900)
parser.add_option("-c", "--comment", dest="comment", help="Add a host comment")
parser.add_option("--ignore-registration-failures", dest="ignore_registration_failures", action="store_true", help="Continue running even if registration via subscription-manager/rhn-migrate-classic-to-rhsm returns a non-zero return code.")
(options, args) = parser.parse_args()

if options.no_foreman:
Expand Down Expand Up @@ -1179,6 +1187,7 @@ def exec_service(service, command, failonerror=True):
print "PUPPET SERVER - %s" % options.puppet_server
print "PUPPET CA SERVER - %s" % options.puppet_ca_server
print "PUPPET CA PORT - %s" % options.puppet_ca_port
print "IGNORE REGISTRATION FAILURES - %s" % options.ignore_registration_failures

# > Exit if the user isn't root.
# Done here to allow an unprivileged user to run the script to see
Expand Down