Skip to content
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
11 changes: 8 additions & 3 deletions lib/linux_admin/registration_system/rhn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,24 @@ def register(options)
end

def subscribe(options)
raise ArgumentError, "pools, username and password are required" if options[:pools].blank? || options[:username].blank? || options[:password].blank?
raise ArgumentError, "channels, username and password are required" if options[:channels].blank? || options[:username].blank? || options[:password].blank?
cmd = "rhn-channel -a"

pools = options[:pools].collect {|pool| ["--channel=", pool]}
channels = options[:channels].collect {|channel| ["--channel=", channel]}

params = {}
params["--user="] = options[:username]
params["--password="] = options[:password]
params = params.to_a + pools
params = params.to_a + channels

run!(cmd, :params => params)
end

def subscribed_products
cmd = "rhn-channel -l"
run!(cmd).output.split("\n").compact
end
Copy link
Member

Choose a reason for hiding this comment

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

Does this return the same thing as SubscriptionManager#subscribed_products ? I would think both methods should return the same thing for consistency.

Copy link
Member

Choose a reason for hiding this comment

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

More specifically, I noticed in the specs, that one returns an array of string, and the other an array of ids...I'm assuming that's considered the "same thing", but does the caller know to present those differently. I guess my overall question is what is the use case?

Copy link
Member Author

Choose a reason for hiding this comment

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

They both return an array. The two sources don't provide any common values. This is the closest that it can get.


private

def systemid_file
Expand Down
20 changes: 17 additions & 3 deletions lib/linux_admin/registration_system/subscription_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,25 @@ def register(options)

def subscribe(options)
cmd = "subscription-manager attach"
pools = options[:pools].collect {|pool| ["--pool", pool]}
params = proxy_params(options).to_a + pools
params = proxy_params(options)

if options[:pools].blank?
params.merge!({"--auto" => nil})
else
pools = options[:pools].collect {|pool| ["--pool", pool]}
params = params.to_a + pools
end

run!(cmd, :params => params)
end

def subscribed_products
cmd = "subscription-manager list --installed"
output = run!(cmd).output

parse_output(output).select {|p| p[:status].downcase == "subscribed"}.collect {|p| p[:product_id]}
end

def available_subscriptions
cmd = "subscription-manager list --all --available"
output = run!(cmd).output
Expand Down Expand Up @@ -80,7 +93,8 @@ def parse_content(content)
end

def format_values(content_group)
content_group[:ends] = Date.strptime(content_group[:ends], "%m/%d/%Y") if content_group[:ends]
content_group[:ends] = Date.strptime(content_group[:ends], "%m/%d/%Y") if content_group[:ends]
content_group[:starts] = Date.strptime(content_group[:starts], "%m/%d/%Y") if content_group[:starts]
content_group
end

Expand Down
2 changes: 2 additions & 0 deletions spec/data/rhn/output_rhn-channel_list
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rhel-x86_64-server-6
rhel-x86_64-server-6-cf-me-2
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
+-------------------------------------------+
Installed Product Status
+-------------------------------------------+
Product Name: Red Hat Enterprise Linux Server
Product ID: 69
Version: 6.3
Arch: x86_64
Status: Not Subscribed
Starts: 09/27/2012
Ends: 09/26/2013

Product Name: Red Hat CloudForms
Product ID: 167
Version: 2.1
Arch: x86_64
Status: Subscribed
Starts: 01/03/2013
Ends: 01/03/2014

19 changes: 19 additions & 0 deletions spec/data/subscription_manager/output_list_installed_subscribed
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
+-------------------------------------------+
Installed Product Status
+-------------------------------------------+
Product Name: Red Hat Enterprise Linux Server
Product ID: 69
Version: 6.3
Arch: x86_64
Status: Subscribed
Starts: 09/27/2012
Ends: 09/26/2013

Product Name: Red Hat CloudForms
Product ID: 167
Version: 2.1
Arch: x86_64
Status: Subscribed
Starts: 01/03/2013
Ends: 01/03/2014

9 changes: 7 additions & 2 deletions spec/rhn_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,18 @@
expect { described_class.new.subscribe({}) }.to raise_error(ArgumentError)
end

it "with pools" do
it "with channels" do
described_class.any_instance.should_receive(:run!).once.with("rhn-channel -a", {:params=>[["--user=", "SomeUser"], ["--password=", "SomePass"], ["--channel=", 123], ["--channel=", 456]]})
described_class.new.subscribe({
:username => "SomeUser",
:password => "SomePass",
:pools => [123, 456]
:channels => [123, 456]
})
end
end

it "#subscribed_products" do
described_class.any_instance.should_receive(:run!).once.with("rhn-channel -l").and_return(double(:output => sample_output("rhn/output_rhn-channel_list")))
expect(described_class.new.subscribed_products).to eq(["rhel-x86_64-server-6", "rhel-x86_64-server-6-cf-me-2"])
end
end
29 changes: 24 additions & 5 deletions spec/subscription_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
end

it "with username and password" do
run_options = ["subscription-manager register", {:params=>{"--username="=>"SomeUser", "--password="=>"SomePass", "--org="=>"IT", "--proxy="=>"1.2.3.4", "--proxyuser="=>"ProxyUser", "--proxypassword="=>"ProxyPass", "--serverurl="=>"192.168.1.1"}}]
run_options = ["subscription-manager register", {:params=>{"--username="=>"SomeUser@SomeDomain.org", "--password="=>"SomePass", "--org="=>"IT", "--proxy="=>"1.2.3.4", "--proxyuser="=>"ProxyUser", "--proxypassword="=>"ProxyPass", "--serverurl="=>"192.168.1.1"}}]
described_class.any_instance.should_receive(:run!).once.with(*run_options)
described_class.new.register(
:username => "SomeUser",
:username => "SomeUser@SomeDomain.org",
:password => "SomePass",
:org => "IT",
:proxy_address => "1.2.3.4",
Expand All @@ -38,9 +38,28 @@
end
end

it "#subscribe" do
described_class.any_instance.should_receive(:run!).once.with("subscription-manager attach", {:params=>[["--pool", 123], ["--pool", 456]]})
described_class.new.subscribe({:pools => [123, 456]})
context "#subscribe" do
it "with pools" do
described_class.any_instance.should_receive(:run!).once.with("subscription-manager attach", {:params=>[["--pool", 123], ["--pool", 456]]})
described_class.new.subscribe({:pools => [123, 456]})
end

it "without pools" do
described_class.any_instance.should_receive(:run!).once.with("subscription-manager attach --auto", {:params=>{}})
described_class.new.subscribe({})
end
end

context "#subscribed_products" do
it "subscribed" do
described_class.any_instance.should_receive(:run!).once.with("subscription-manager list --installed").and_return(double(:output => sample_output("subscription_manager/output_list_installed_subscribed")))
expect(described_class.new.subscribed_products).to eq(["69", "167"])
end

it "not subscribed" do
described_class.any_instance.should_receive(:run!).once.with("subscription-manager list --installed").and_return(double(:output => sample_output("subscription_manager/output_list_installed_not_subscribed")))
expect(described_class.new.subscribed_products).to eq(["167"])
end
end

it "#available_subscriptions" do
Expand Down