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

Deprecate LinuxAdmin::Rhn #198

Merged
merged 1 commit into from
Dec 6, 2017
Merged

Conversation

bdunne
Copy link
Member

@bdunne bdunne commented Dec 6, 2017

RHN is no longer active, we no longer need this class.

Example (the raise is because I don't have subscription-manager installed):

$ irb -Ilib
irb(main):001:0> require 'linux_admin'
=> true
irb(main):002:0> LinuxAdmin::RegistrationSystem.registered?
[DEPRECATION] 'LinuxAdmin::Rhn' is deprecated.  Please use 'LinuxAdmin::SubscriptionManager' instead.
AwesomeSpawn::NoSuchFileError: No such file or directory - subscription-manager
	from /home/bdunne/.gem/ruby/2.3.3/gems/awesome_spawn-1.4.1/lib/awesome_spawn.rb:81:in `rescue in run'
	from /home/bdunne/.gem/ruby/2.3.3/gems/awesome_spawn-1.4.1/lib/awesome_spawn.rb:71:in `run'
	from /home/bdunne/projects/rubygems/linux_admin/lib/linux_admin/common.rb:19:in `run'
	from /home/bdunne/projects/rubygems/linux_admin/lib/linux_admin/registration_system/subscription_manager.rb:21:in `registered?'
	from /home/bdunne/projects/rubygems/linux_admin/lib/linux_admin/registration_system.rb:29:in `registration_type_uncached'
	from /home/bdunne/projects/rubygems/linux_admin/lib/linux_admin/registration_system.rb:7:in `registration_type'
	from /home/bdunne/projects/rubygems/linux_admin/lib/linux_admin/registration_system.rb:12:in `method_missing'
	from (irb):2
	from /home/bdunne/.rubies/ruby-2.3.3/bin/irb:11:in `<main>'
irb(main):003:0> LinuxAdmin::Rhn.new
[DEPRECATION] 'LinuxAdmin::Rhn' is deprecated.  Please use 'LinuxAdmin::SubscriptionManager' instead.
=> #<LinuxAdmin::Rhn:0x00000002412fb0>

RHN is no longer active, we no longer need this class
@miq-bot
Copy link
Member

miq-bot commented Dec 6, 2017

Checked commit bdunne@1d7c4f7 with ruby 2.3.3, rubocop 0.47.1, haml-lint 0.20.0, and yamllint 1.10.0
1 file checked, 0 offenses detected
Everything looks fine. 🏆

@carbonin carbonin self-assigned this Dec 6, 2017
@carbonin carbonin merged commit a8a5c5c into ManageIQ:master Dec 6, 2017
@bdunne bdunne deleted the deprecate_rhn branch December 6, 2017 22:43
NickLaMuro added a commit to NickLaMuro/manageiq that referenced this pull request Mar 13, 2018
So there is a whole mess of WTF going on here, but I will try and
explain as best as possible:

To start off, the deprecation warning from `linux_admin` was added here:

ManageIQ/linux_admin#198

There was little to go off of for a "why", except that it was, in fact,
deprecated.  So there is that.

Our codebase as well wasn't using `LinuxAdmin::Rhn` anywhere, and was
only referenced in the specs.  So just change `LinuxAdmin::Rhn` to
`LinuxAdmin::SubscriptionManager` right?

WRONG!

So that causes two issues:

First, the `LinuxAdmin::SubscriptionManager` doesn't fail with the same
error as `LinuxAdmin::Rhn` did in this test.  So as a quick solution, I
just made it so that `RegistrationSystem.verify_credentials` now rescues
the `AwesomeSpawn::NoSuchFileError` that gets thrown when it calls it's
`run!` method.

But even with that fix, and changing the stub, there is still a
deprecation warning?  What gives.

Well, that is the second, and much more obnoxious part with the whole
ordeal.  Thanks to some "totally obvious and not confusing"
metaprogramming happening in the base class of SubscriptionManager, the
class method version of `.verify_credentials` is actually called via the
`LinuxAdmin::RegistrationSystem.method_missing`, which will eventually
call on `LinuxAdmin::Rhn.new.registered?` prior to calling that on
`LinuxAdmin::SubscriptionManager.new.registered?`

What truly heinous about this is not that we are deprecating `Rhn`, but
that we are doing so, and providing no way to have the user avoid the
deprecation warning in `Rhn.new`, and still favor the old code in inner
workings of these public APIs.  Which doesn't seem to make much sense
since it is deprecated... but who am I to judge...

Anyway, for now, the quick fix done here is to sub out the `.new` method
for `LinuxAdmin::Rhn` with a double, and have that return `false` for
`#registered?`.  Really, this should be a change to `LinuxAdmin` to make
`SubscriptionManager` the default.  With that said, added a "future
proof" version check as well in that spec that will make the test break
when this klugy-ness is no longer needed.
NickLaMuro added a commit to NickLaMuro/manageiq that referenced this pull request Mar 13, 2018
So there is a whole mess of WTF going on here, but I will try and
explain as best as possible:

To start off, the deprecation warning from `linux_admin` was added here:

ManageIQ/linux_admin#198

There was little to go off of for a "why", except that it was, in fact,
deprecated.  So there is that.

Our codebase as well wasn't using `LinuxAdmin::Rhn` anywhere, and was
only referenced in the specs.  So just change `LinuxAdmin::Rhn` to
`LinuxAdmin::SubscriptionManager` right?

WRONG!

So that causes two issues:

First, the `LinuxAdmin::SubscriptionManager` doesn't fail with the same
error as `LinuxAdmin::Rhn` did in this test.  So as a quick solution, I
just made it so that `RegistrationSystem.verify_credentials` now rescues
the `AwesomeSpawn::NoSuchFileError` that gets thrown when it calls it's
`run!` method.

But even with that fix, and changing the stub, there is still a
deprecation warning?  What gives.

Well, that is the second, and much more obnoxious part with the whole
ordeal.  Thanks to some "totally obvious and not confusing"
metaprogramming happening in the base class of SubscriptionManager, the
class method version of `.verify_credentials` is actually called via the
`LinuxAdmin::RegistrationSystem.method_missing`, which will eventually
call on `LinuxAdmin::Rhn.new.registered?` prior to calling that on
`LinuxAdmin::SubscriptionManager.new.registered?`

What truly heinous about this is not that we are deprecating `Rhn`, but
that we are doing so, and providing no way to have the user avoid the
deprecation warning in `Rhn.new`, and still favor the old code in inner
workings of these public APIs.  Which doesn't seem to make much sense
since it is deprecated... but who am I to judge...

Anyway, for now, the quick fix done here is to stub out the `.new`
method for `LinuxAdmin::Rhn` with a double, and have that return `false`
for `#registered?`.  Really, this should be a change to `LinuxAdmin` to
make `SubscriptionManager` the default.  With that said, added a "future
proof" version check as well in that spec that will make the test break
when this klugy-ness is no longer needed.
NickLaMuro added a commit to NickLaMuro/linux_admin that referenced this pull request Mar 13, 2018
Now the `LinuxAdmin::Rhn` has been deprecated:

    ManageIQ#198
    1ifd7c4f788ce34200ff09ef56176397306904f85b

This means that every instantiation of `LinuxAdmin::Rhn` will then add a
deprecation warning to STDOUT.

Previously, this would also be triggered even if you used the public
class methods on `LinuxAdmin::SubscriptionManager` (the deprecation's
suggested replacement), because under the hood it determine which to
(`Rhn` or `SubscriptionManager`) by initializing each and calling their
`registered?` methods.

Furthermore, these means if `Rhn` is registered on the system in
addition to the preferred `SubscriptionManager`, it the
`LinuxAdmin::SubscriptionManager.validate_credentials` class method
would actually end up calling `LinuxAdmin::Rhn.validate_credentials`
instead because of the preference.

* * *

While this favoring should probably be refine to first look at the class
the `method_missing` method is being called against, this fix simply
favors `SubscriptionManager` over `Rhn` when deciding which class to
use.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants