diff --git a/.fixtures.yml b/.fixtures.yml index 3a8278e..faa7b12 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -13,3 +13,4 @@ fixtures: puppet_version: '>= 6.0.0' stdlib: 'https://github.com/puppetlabs/puppetlabs-stdlib' systemd: 'https://github.com/voxpupuli/puppet-systemd' + yumrepo_core: 'https://github.com/puppetlabs/puppetlabs-yumrepo_core' diff --git a/manifests/repo.pp b/manifests/repo.pp index 51c8528..a22e7ab 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -2,17 +2,24 @@ # # @param version # The Pulpcore version to use +# @param baseurl +# An optional base URL to be used for yumrepo, instead of the default +# @param gpgkey +# An optional value for gpgkey to be used for yumrepo, instead of the default. +# If an empty string is passed, gpgcheck will be disabled. class pulpcore::repo ( Variant[Enum['nightly'], Pattern['^\d+\.\d+$']] $version = '3.28', + Optional[Stdlib::HTTPUrl] $baseurl = undef, + Optional[String[0]] $gpgkey = undef, ) { $dist_tag = "el${facts['os']['release']['major']}" yumrepo { 'pulpcore': name => "Pulpcore ${version}", - baseurl => "https://yum.theforeman.org/pulpcore/${version}/${dist_tag}/\$basearch", + baseurl => pick($baseurl, "https://yum.theforeman.org/pulpcore/${version}/${dist_tag}/\$basearch"), enabled => '1', - gpgcheck => '1', - gpgkey => "https://yum.theforeman.org/pulpcore/${version}/GPG-RPM-KEY-pulpcore", + gpgcheck => if $gpgkey == '' { '0' } else { '1' }, + gpgkey => pick($gpgkey, "https://yum.theforeman.org/pulpcore/${version}/GPG-RPM-KEY-pulpcore"), notify => Anchor['pulpcore::repo'], } diff --git a/spec/classes/repo_spec.rb b/spec/classes/repo_spec.rb index 0da9730..384e2e7 100644 --- a/spec/classes/repo_spec.rb +++ b/spec/classes/repo_spec.rb @@ -7,12 +7,13 @@ describe "with default values" do it { is_expected.to compile.with_all_deps } - it do - is_expected.to contain_anchor('pulpcore::repo') - is_expected.to contain_file('/etc/yum.repos.d/pulpcore.repo') - .with_content(%r{^baseurl=https://yum.theforeman.org/pulpcore/\d+\.\d+/el\d+/\$basearch$}) - .that_notifies('Anchor[pulpcore::repo]') - end + it { is_expected.to contain_anchor('pulpcore::repo') } + it { is_expected.to contain_yumrepo('pulpcore') + .with_baseurl(%r{https://yum.theforeman.org/pulpcore/\d+\.\d+/el\d+/\$basearch$}) + .with_gpgcheck(1) + .with_gpgkey(%r{https://yum.theforeman.org/pulpcore/\d+\.\d+/GPG-RPM-KEY-pulpcore}) + .that_notifies('Anchor[pulpcore::repo]') + } if os_facts[:os]['release']['major'] == '8' it 'configures the pulpcore module' do @@ -21,7 +22,7 @@ .with_ensure(/^el\d+/) .with_enable_only(true) .with_provider('dnfmodule') - .that_requires('File[/etc/yum.repos.d/pulpcore.repo]') + .that_requires('Yumrepo[pulpcore]') .that_notifies('Anchor[pulpcore::repo]') end else @@ -32,16 +33,17 @@ describe "with nightly version" do let :params do { - version: 'nightly' + version: 'nightly', + gpgkey: '', } end it { is_expected.to compile.with_all_deps } - it do - is_expected.to contain_file('/etc/yum.repos.d/pulpcore.repo') - .with_content(%r{^baseurl=https://yum.theforeman.org/pulpcore/nightly/el\d+/\$basearch$}) - .that_notifies('Anchor[pulpcore::repo]') - end + it { is_expected.to contain_yumrepo('pulpcore') + .with_baseurl(%r{https://yum.theforeman.org/pulpcore/nightly/el\d+/\$basearch$}) + .with_gpgcheck(0) + .that_notifies('Anchor[pulpcore::repo]') + } end end end