Skip to content
This repository has been archived by the owner on Jan 19, 2019. It is now read-only.

rhsm_register runs even though a system is already registered #23

Open
er0 opened this issue Apr 13, 2017 · 1 comment
Open

rhsm_register runs even though a system is already registered #23

er0 opened this issue Apr 13, 2017 · 1 comment

Comments

@er0
Copy link

er0 commented Apr 13, 2017

If the the test 'subscription-manager status' fails even though a system is registered, rhsm_register then tries to register again and the registration fails with:

Expected process to exit with [0], but received '64'
---- Begin output of subscription-manager register --activationkey=redacted --org=redacted ----
STDOUT:
STDERR: This system is already registered. Use --force to override

I believe this is due to this block of code in libraries/helpers.rb:

def registered_with_rhsm?
  cmd = Mixlib::ShellOut.new('subscription-manager status')
  cmd.run_command
  !cmd.stdout.match(/Overall Status: Unknown/)
end

maybe change registered_with_rhsm? to true on exit status 0, or:
cmd.stdout.match(/Overall Status: Current/)

@jayhendren
Copy link

We ran into this too. We worked around this with the following monkey-patch, which we placed into the libraries folder of our wrapper cookbook:

module CubRhsmCookbook
  # this is a top-level module documentation comment to please rubocop.
  module RhsmHelpers
    def registered_with_rhsm?
      # err on the side of assuming the system is already registered
      #
      # we only need systems to register themselves on the first converge
      # in the typical case; otherwise avoid errors by assuming a system is
      # registered if it looks even slightly like it is registered
      #
      # product_status.json is a cache of a call to the RHSM API.
      # subscription-manager creates this file upon a successful registration
      # and deletes it when a system is unregistered cleanly.
      File.exist?('/var/lib/rhsm/cache/product_status.json') || super
    end
  end
end

RhsmCookbook::RhsmRegister.include CubRhsmCookbook::RhsmHelpers

Strictly speaking, this is not an issue with the redhat-subscription-manager-cookbook, but with RHSM and subscription-manager, which fail to return consistent values when a system is already registered.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants