Skip to content

Commit

Permalink
Merge pull request #16972 from bdunne/configure_proxy_info_for_yum_up…
Browse files Browse the repository at this point in the history
…dates

Configure yum proxy if given for updates
  • Loading branch information
carbonin authored Feb 8, 2018
2 parents 863255b + 5798d83 commit 58a6e56
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/models/miq_server/update_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def update_registration_status
def attempt_registration
return unless register
attach_products
configure_yum_proxy
# HACK: #enable_repos is not always successful immediately after #attach_products, retry to ensure they are enabled.
5.times { repos_enabled? ? break : enable_repos }
end
Expand Down Expand Up @@ -102,6 +103,16 @@ def attach_products
LinuxAdmin::SubscriptionManager.subscribe(assemble_registration_options)
end

def configure_yum_proxy
registration_options = assemble_registration_options
return unless registration_options[:proxy_address]
conf = IniFile.load("/etc/yum.conf")
conf["main"]["proxy"] = registration_options[:proxy_address]
conf["main"]["proxy_username"] = registration_options[:proxy_username] if registration_options[:proxy_username]
conf["main"]["proxy_password"] = registration_options[:proxy_password] if registration_options[:proxy_password]
conf.save
end

def repos_enabled?
enabled = LinuxAdmin::SubscriptionManager.enabled_repos
if MiqDatabase.first.update_repo_names.all? { |desired| enabled.include?(desired) }
Expand Down
35 changes: 35 additions & 0 deletions spec/models/miq_server/update_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,41 @@
end
end

context "#configure_yum_proxy" do
it "with no proxy server" do
expect(IniFile).not_to receive(:load)

@server.configure_yum_proxy
end

it "with proxy server but no credentials" do
database.update_attributes(:registration_http_proxy_server => "http://my_proxy:port")

Tempfile.open do |tempfile|
stub_inifile = IniFile.new(:filename => tempfile.path)
expect(IniFile).to receive(:load).and_return(stub_inifile)

@server.configure_yum_proxy

expect(File.read(tempfile)).to eq("[main]\nproxy = http://my_proxy:port\n\n")
end
end

it "with proxy server and credentials" do
database.update_authentication(:registration_http_proxy => {:userid => "user", :password => "pass"})
database.update_attributes(:registration_http_proxy_server => "http://my_proxy:port")

Tempfile.open do |tempfile|
stub_inifile = IniFile.new(:filename => tempfile.path)
expect(IniFile).to receive(:load).and_return(stub_inifile)

@server.configure_yum_proxy

expect(File.read(tempfile)).to eq("[main]\nproxy = http://my_proxy:port\nproxy_username = user\nproxy_password = pass\n\n")
end
end
end

context "#repo_enabled?" do
it "true" do
expect(reg_system).to receive(:enabled_repos).and_return(["abc", database.update_repo_names].flatten)
Expand Down

0 comments on commit 58a6e56

Please sign in to comment.