-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(MODULES-11113) Allow present and latest as package version #565
(MODULES-11113) Allow present and latest as package version #565
Conversation
puppet_agent is a classthat may have no external impact to Forge modules. puppet_agent::install is a classthat may have no external impact to Forge modules. This module is declared in 3 of 576 indexed public
|
Thanks for your contribution @relearnshuffle!
After digging a bit into this, I found that we can search the catalog for the version we just upgraded to (in case
Since the version format is specific to yum-based packages, we have to normalize it so it looks like what
So the def needs_upgrade?
current_version = Facter.value('aio_agent_version')
desired_version = @resource.name
return false if desired_version == 'present'
if desired_version == 'latest'
latest_version = @resource.catalog.resource('package', 'puppet-agent').parameters[:ensure].latest
desired_version = latest_version.match(/^(?:[0-9]:)?(?<aio_version>\d+\.\d+\.\d+(?:\.\d+))?/)[:aio_version]
end
Puppet::Util::Package.versioncmp(desired_version, current_version) != 0
end I assume Let me know if this works for you! |
@relearnshuffle I created the following JIRA ticket to track this issue: https://tickets.puppetlabs.com/browse/MODULES-11113 To get the PR commit check to pass, please prefix |
I took it upon myself to work on this PR, since I believe this is an useful improvement. This was also a good opportunity to add some test coverage, and bump rspec-puppet-facts which lowers CI duration with about ~5 minutes per run (due to the memoization of Setting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 👍
Manually tested these changes on Ubuntu 20.04 and everything seems to be working as expected. Manifests used:
class {'::puppet_agent':
package_version => latest,
collection => 'puppet6'
}
and
class {'::puppet_agent':
package_version => latest,
apt_source => "http://nightlies.puppet.com/apt",
collection => 'puppet6-nightly'
}
Output example:
➜ puppet apply manifest.pp
Notice: Compiled catalog for example.puppetlabs.net in environment production in 0.45 seconds
Notice: /Stage[main]/Puppet_agent::Osfamily::Debian/Apt::Source[pc_repo]/Apt::Setting[list-pc_repo]/File[/etc/apt/sources.list.d/pc_repo.list]/content: content changed '{md5}88e1295cfdbda94bebe58c92215d90b7' to '{md5}935d4fe674b74276a929259e113d3e65'
Notice: /Stage[main]/Apt::Update/Exec[apt_update]: Triggered 'refresh' from 1 event
Notice: /Stage[main]/Puppet_agent::Osfamily::Debian/Exec[pc_repo_force]/returns: forcing apt update for pc_repo puppet6-nightly
Notice: /Stage[main]/Puppet_agent::Osfamily::Debian/Exec[pc_repo_force]: Triggered 'refresh' from 2 events
Notice: /Stage[main]/Puppet_agent::Install/Package[puppet-agent]/ensure: ensure changed '6.23.0-1bionic' to '6.24.0.28.g6b5947a6a-1bionic'
Notice: Stopping run after puppet-agent upgrade. Run puppet agent -t or apply your manifest again to finish the transaction.
Notice: Applied catalog in 12.81 seconds
➜ puppet apply manifest.pp
Notice: Compiled catalog for example.puppetlabs.net in environment production in 0.59 seconds
Notice: Applied catalog in 0.99 seconds
Treat latest and present as valid package versions. Add tests for the puppet_agent_end_run provider and switch to rspec style mocks.
Newer versions of rspec-puppet-facts memoize the values of `on_supported_os` which we call multiple times in our spec tests. This makes loading the facts about 5 times faster. Unpin rspec-puppet as it had multiple releases since we pinned it to 2.7.9.
This pull requests intends to implement the package versions
present
andlatest
as valid package versions. According to #333, this was the case prior to commit c2206a7. The issue with #333 is that it is an outdated pull request that does not apply to the current state ofmain
. This, along with the fact that the author of #333 did not agree to the CLA in over 2 years now, is why I am raising this as a separate pull request.Since there is no issues section in this project, I would also like to use this pull request as a discussion for this feature. The issue with the implementation as it is proposed in this pull request is that every puppet run will end with:
when the version is set to
present
orlatest
. This is because theneeds_upgrade?
function in thepuppet_agent_end_run
type uses thePuppet::Util::Package.versioncmp
function to compare the literal stringpresent
andlatest
with the actual version of the Puppet agent installed, e.g.6.22.1
, which will never be equal.I am not sure of a suitable fix for this and was hoping someone else could help.
I stumbled upon this issue when I realized the
pc_repo.repo
file was no longer being managed by this module after removing settingpuppet_agent::package_version
toauto
which in itself led to an issue where the Puppet agent would also be downgraded (despite the server being the same version as the client) anytime the Puppet agent upgraded through the package manager. This is withpuppet_agent::collection
set topuppet6
for both the main server and the agent, thepuppetserver
version being6.15.3
and thepuppet-agent
version, prior to a catalogue pull, being6.22.1
on both the main server and the agent.