-
Notifications
You must be signed in to change notification settings - Fork 193
fix: Do not hard code package name in puppet_agent_end_run.rb #761
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,8 +32,13 @@ def needs_upgrade? | |
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(%r{^(?:[0-9]:)?(\d+\.\d+(\.\d+)?(?:\.\d+))?}).captures.first | ||
# Package name might be different to puppet-agent, hence we need to look it up. | ||
package_name = @resource.catalog.resource('class', 'puppet_agent')[:package_name] | ||
|
||
# Latest version might be undefined, e.G. if we're about to install a different named | ||
# package than the currently running one. In that case, we'll leave desired_version empty. | ||
latest_version = @resource.catalog.resource('package', package_name).parameters[:ensure].latest | ||
desired_version = latest_version.match(%r{^(?:[0-9]:)?(\d+\.\d+(\.\d+)?(?:\.\d+))?}).captures.first unless latest_version.nil? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If
Maybe use empty string instead? desired_version = if latest_version.nil?
""
else
latest_version.match(%r{^(?:[0-9]:)?(\d+\.\d+(\.\d+)?(?:\.\d+))?}).captures.first
end There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If latest_version is nil then desired_version will still be 'latest' - But I think it makes sense to be more explicit here. |
||
end | ||
|
||
Puppet::Util::Package.versioncmp(desired_version, current_version) != 0 | ||
|
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.
If
package_name
can be nil (not sure that's possible?), then it'd be good to set a default: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.
I don't think it can (realistically) be nil - but having a sane default still seems like a good idea.