diff --git a/lib/puppet/type/yumrepo.rb b/lib/puppet/type/yumrepo.rb index 5668697..4359f67 100644 --- a/lib/puppet/type/yumrepo.rb +++ b/lib/puppet/type/yumrepo.rb @@ -304,19 +304,25 @@ newproperty(:proxy) do desc "URL of a proxy server that Yum should use when accessing this repository. - This attribute can also be set to `'_none_'`, which will make Yum bypass any - global proxy settings when accessing this repository. + This attribute can also be set to '_none_' (or '' for EL >= 8 only), + which will make Yum bypass any global proxy settings when accessing this repository. #{ABSENT_DOC}" newvalues(%r{.*}, :absent) validate do |value| next if value.to_s =~ %r{^(absent|_none_)$} - parsed = URI.parse(value) + next if value.to_s.empty? && Facter.value(:operatingsystemmajrelease).to_i >= 8 + parsed = URI.parse(value) unless VALID_SCHEMES.include?(parsed.scheme) raise _('Must be a valid URL') end end + + munge do |value| + return '' if Facter.value(:operatingsystemmajrelease).to_i >= 8 && value.to_s == '_none_' + value.to_s + end end newproperty(:proxy_username) do diff --git a/spec/unit/type/yumrepo_spec.rb b/spec/unit/type/yumrepo_spec.rb index 1afdea3..81dbbdb 100644 --- a/spec/unit/type/yumrepo_spec.rb +++ b/spec/unit/type/yumrepo_spec.rb @@ -312,13 +312,37 @@ describe 'proxy' do it_behaves_like 'a yumrepo parameter that can be absent', :proxy + it_behaves_like 'a yumrepo parameter that accepts a single URL', :proxy + it 'accepts _none_' do described_class.new( name: 'puppetlabs', proxy: '_none_', ) end - it_behaves_like 'a yumrepo parameter that accepts a single URL', :proxy + + it 'accepts an empty string' do + described_class.new( + name: 'puppetlabs', + proxy: '', + ) + end + + it 'munges \'_none_\' to empty string for EL >= 8' do + Facter.stubs(:value).with(:operatingsystemmajrelease).returns('8') + instance = described_class.new(name: 'puppetlabs', proxy: '_none_') + expect(instance[:proxy]).to eq '' + end + + it 'does not munges \'_none_\' to empty string for EL < 8' do + Facter.stubs(:value).with(:operatingsystemmajrelease).returns('7') + instance = described_class.new(name: 'puppetlabs', proxy: '_none_') + expect(instance[:proxy]).to eq '_none_' + end + + it 'does not raise any errors' do + expect { described_class.new(name: 'puppetlabs', proxy: '') }.not_to raise_error + end end describe 'proxy_username' do