Skip to content

Commit

Permalink
Add parameters for baseurl and gpgkey
Browse files Browse the repository at this point in the history
This can be used to test from staging repositories or a local mirror.

Co-Authored-By: Eric D. Helms <ericdhelms@gmail.com>
  • Loading branch information
2 people authored and evgeni committed Nov 17, 2023
1 parent 141d73a commit fa2bd4f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
13 changes: 10 additions & 3 deletions manifests/repo.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
}

Expand Down
28 changes: 15 additions & 13 deletions spec/classes/repo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit fa2bd4f

Please sign in to comment.