waveclaw / puppet-subscription_manager

Handle Client Registration to RedHat Satellite 6 or Katello
https://rhn.redhat.com
Other
6 stars 34 forks source link

Rhsm_register should fail when underlying command fails #87

Open jameslikeslinux opened 4 years ago

jameslikeslinux commented 4 years ago

My organization has been using this module for several years. Thank you for it.

We have observed that when host registration fails, the rhsm_register resource returns successfully. This can cause problems for other resources that depend on our rhsm_register resource, and it is confusing trying to identify where the problem is when reading Puppet reports.

For example, if we provide a fake activation key, on the command line we get:

> subscription-manager register --org="dit" --activationkey="fake"
HTTP error (404 - Not Found): Couldn't find activation key 'fake'
> echo $?
70

And providing the same fake activation key to the rhsm_resource, we get:

Notice: /Stage[first]/Satellite_client::Config/Rhsm_register[satellite-server-name]/ensure: created (corrective)

When turning on the --debug option, we see the detailed error message, but the resource is still considered to have returned successfully:

Notice: /Stage[first]/Satellite_client::Config/Rhsm_register[satellite-server-name]/ensure: created (corrective)
Debug: This server will be registered
Debug: Executing: '/usr/sbin/subscription-manager register --activationkey foo --org dit'
Debug: Registration returned: Execution of '/usr/sbin/subscription-manager register --activationkey foo --org dit' returned 70: HTTP error (404 - Not Found): Couldn't find activation key 'foo'

I believe this is because the subscription-manager command failure is caught and not re-raised at https://github.com/waveclaw/puppet-subscription_manager/blob/master/lib/puppet/provider/rhsm_register/subscription_manager.rb#L55. Is there a reason for this? I'm happy to submit a patch if this is something that should be corrected.

Thanks.

waveclaw commented 4 years ago

The command returns unusual return values so a blanket catch was used.

On some of the older branches there are some attempts to process these return codes but they never resulted in workable solutions in the field.

If you have a working implemtnation of handling the return data from subscription-manager, please do submit a patch. I would be very interested in testing it.