-
Notifications
You must be signed in to change notification settings - Fork 30
Modify rhn and subscription manager to inherit from new registration system class #33
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
Merged
Fryguy
merged 6 commits into
ManageIQ:master
from
bdunne:modify_rhn_and_subscription_manager_to_inherit_from_registration_system
Aug 14, 2013
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fe3b39d
Create LinuxAdmin::RegistrationSystem
bdunne d3c4ed6
Modify Inheritence
bdunne aa3db54
Fix tests related to registration_system commands
bdunne 7288583
Change Rhn class methods to instance methods
bdunne f645e06
Change SubscriptionManager class methods to instance methods
bdunne 1d9d4cd
Move subclasses into a folder
bdunne 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 hidden or 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 hidden or 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,45 @@ | ||
class LinuxAdmin | ||
class RegistrationSystem < LinuxAdmin | ||
def self.registration_type(reload = false) | ||
return @registration_type if @registration_type && !reload | ||
@registration_type = registration_type_uncached | ||
end | ||
|
||
def self.method_missing(meth, *args, &block) | ||
if white_list_methods.include?(meth) | ||
r = self.registration_type.new | ||
raise NotImplementedError, "#{meth} not implemented for #{self.name}" unless r.respond_to?(meth) | ||
r.send(meth, *args, &block) | ||
else | ||
super | ||
end | ||
end | ||
|
||
def registered? | ||
false | ||
end | ||
|
||
private | ||
|
||
def self.registration_type_uncached | ||
if SubscriptionManager.new.registered? | ||
SubscriptionManager | ||
elsif Rhn.new.registered? | ||
Rhn | ||
else | ||
self | ||
end | ||
end | ||
private_class_method :registration_type_uncached | ||
|
||
def self.white_list_methods | ||
@white_list_methods ||= begin | ||
all_methods = RegistrationSystem.instance_methods(false) + Rhn.instance_methods(false) + SubscriptionManager.instance_methods(false) | ||
all_methods.uniq | ||
end | ||
end | ||
private_class_method :white_list_methods | ||
end | ||
end | ||
|
||
Dir.glob(File.join(File.dirname(__FILE__), "registration_system", "*.rb")).each { |f| require f } |
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,42 +1,4 @@ | ||
require 'spec_helper' | ||
|
||
describe LinuxAdmin do | ||
context ".registered?" do | ||
it "when registered Subscription Manager" do | ||
stub_registered_to_system(:sm) | ||
expect(described_class.registered?).to be_true | ||
end | ||
|
||
it "when registered RHN" do | ||
stub_registered_to_system(:rhn) | ||
expect(described_class.registered?).to be_true | ||
end | ||
|
||
it "when unregistered" do | ||
stub_registered_to_system(nil) | ||
expect(described_class.registered?).to be_false | ||
end | ||
end | ||
|
||
context ".registration_type" do | ||
it "when registered Subscription Manager" do | ||
stub_registered_to_system(:sm) | ||
expect(described_class.registration_type).to eq(LinuxAdmin::SubscriptionManager) | ||
end | ||
|
||
it "when registered RHN" do | ||
stub_registered_to_system(:rhn) | ||
expect(described_class.registration_type).to eq(LinuxAdmin::Rhn) | ||
end | ||
|
||
it "when unregistered" do | ||
stub_registered_to_system(nil) | ||
expect(described_class.registration_type).to be_nil | ||
end | ||
end | ||
|
||
def stub_registered_to_system(system) | ||
described_class::SubscriptionManager.stub(:registered? => (system == :sm)) | ||
described_class::Rhn.stub(:registered? => (system == :rhn)) | ||
end | ||
end |
This file contains hidden or 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,60 @@ | ||
require 'spec_helper' | ||
|
||
describe LinuxAdmin::RegistrationSystem do | ||
context ".registration_type" do | ||
it "when registered Subscription Manager" do | ||
stub_registered_to_system(:sm) | ||
expect(described_class.registration_type).to eq(LinuxAdmin::SubscriptionManager) | ||
end | ||
|
||
it "when registered RHN" do | ||
stub_registered_to_system(:rhn) | ||
expect(described_class.registration_type).to eq(LinuxAdmin::Rhn) | ||
end | ||
|
||
it "when unregistered" do | ||
stub_registered_to_system(nil) | ||
expect(described_class.registration_type).to eq(described_class) | ||
end | ||
|
||
it "should memoize results" do | ||
described_class.should_receive(:registration_type_uncached).once.and_call_original | ||
described_class.registration_type | ||
described_class.registration_type | ||
end | ||
|
||
it "with reload should refresh results" do | ||
described_class.should_receive(:registration_type_uncached).twice.and_call_original | ||
described_class.registration_type | ||
described_class.registration_type(true) | ||
end | ||
end | ||
|
||
it "#registered? when unregistered" do | ||
stub_registered_to_system(nil) | ||
expect(described_class.registered?).to be_false | ||
end | ||
|
||
context ".method_missing" do | ||
before do | ||
stub_registered_to_system(:rhn) | ||
end | ||
|
||
it "exists on the subclass" do | ||
expect(LinuxAdmin::RegistrationSystem.registered?).to be_true | ||
end | ||
|
||
it "does not exist on the subclass" do | ||
expect { LinuxAdmin::RegistrationSystem.organizations }.to raise_error(NotImplementedError) | ||
end | ||
|
||
it "is an unknown method" do | ||
expect { LinuxAdmin::RegistrationSystem.method_does_not_exist }.to be_true | ||
end | ||
end | ||
|
||
def stub_registered_to_system(system) | ||
LinuxAdmin::SubscriptionManager.any_instance.stub(:registered? => (system == :sm)) | ||
LinuxAdmin::Rhn.any_instance.stub(:registered? => data_file_path("rhn/systemid")) if system == :rhn | ||
end | ||
end |
This file contains hidden or 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
Oops, something went wrong.
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.
Can be shortened to: