Merge "Support a "mirror" method of apt-get"

This commit is contained in:
Jenkins 2017-04-28 20:34:32 +00:00 committed by Gerrit Code Review
commit 9995f60d10
2 changed files with 11 additions and 9 deletions

View File

@ -4,7 +4,13 @@ require 'net/http'
require 'open-uri' require 'open-uri'
require 'uri' require 'uri'
Puppet::Parser::Functions::newfunction(:url_available, :doc => <<-EOS module URI
# Define 'mirror:' scheme
class MIRROR < HTTP; end
@@schemes['MIRROR'] = MIRROR
end
Puppet::Parser::Functions::newfunction(:url_available, :arity => -2, :doc => <<-EOS
The url_available function attempts to make a http request to a url and throws The url_available function attempts to make a http request to a url and throws
a puppet error if the URL is unavailable. The url_available function can take a puppet error if the URL is unavailable. The url_available function can take
up to two paramters. The first paramter is the URL which is required and can be up to two paramters. The first paramter is the URL which is required and can be
@ -39,8 +45,7 @@ url_available({ 'uri' => 'http://www.google.com',
EOS EOS
) do |argv| ) do |argv|
url = argv[0] url, http_proxy = argv
http_proxy = argv[1]
threads_count = 16 threads_count = 16
Thread.abort_on_exception=true Thread.abort_on_exception=true
@ -54,12 +59,8 @@ EOS
# check the type of url being passed, if hash look for the uri key # check the type of url being passed, if hash look for the uri key
if url.instance_of? Hash if url.instance_of? Hash
if url.has_key?('uri') uri = url.fetch 'uri', nil
uri = url['uri'] http_proxy = url.fetch 'proxy', nil
end
if url.has_key?('proxy')
http_proxy = url['proxy']
end
elsif url.instance_of? String elsif url.instance_of? String
uri = url uri = url
else else

View File

@ -7,6 +7,7 @@ describe 'url_available' do
http://archive.ubuntu.com/ubuntu/ http://archive.ubuntu.com/ubuntu/
http://mirror.fuel-infra.org/mos/ubuntu/ http://mirror.fuel-infra.org/mos/ubuntu/
http://apt.postgresql.org/pub/repos/apt/ http://apt.postgresql.org/pub/repos/apt/
http://mirrors.ubuntu.com/mirrors.txt
) )
end end