-
Notifications
You must be signed in to change notification settings - Fork 66
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
(maint) Centralize puppet_collection_for logic #100
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 |
---|---|---|
|
@@ -76,8 +76,7 @@ def remove_puppet_paths_on(hosts) | |
# | ||
# @param [String] agent_version version string or 'latest' | ||
# @deprecated This method returns 'PC1' as the latest puppet collection; | ||
# this is incorrect. Use {#puppet_collection_for_puppet_agent_version} or | ||
# {#puppet_collection_for_puppet_version} instead. | ||
# this is incorrect. Use {#puppet_collection_for} instead. | ||
def get_puppet_collection(agent_version = 'latest') | ||
collection = "PC1" | ||
if agent_version != 'latest' | ||
|
@@ -90,41 +89,40 @@ def get_puppet_collection(agent_version = 'latest') | |
collection | ||
end | ||
|
||
# Determine the puppet collection that matches a given version of the puppet-agent | ||
# package (you can find this version in the `aio_agent_version` fact). | ||
# Determine the puppet collection that matches a given package version. The package | ||
# must be one of | ||
# * :puppet_agent (you can get this version from the `aio_agent_version_fact`) | ||
# * :puppet | ||
# | ||
# @param agent_version [String] a semver version number of the puppet-agent package, or the string 'latest' | ||
# | ||
# @param package [Symbol] the package name. must be one of :puppet_agent, :puppet | ||
# @param version [String] a version number or the string 'latest' | ||
# @returns [String|nil] the name of the corresponding puppet collection, if any | ||
def puppet_collection_for_puppet_agent_version(agent_version) | ||
agent_version = agent_version.to_s | ||
return 'puppet' if agent_version.strip == 'latest' | ||
|
||
x, y, z = agent_version.to_s.split('.').map(&:to_i) | ||
return nil if x.nil? || y.nil? || z.nil? | ||
def puppet_collection_for(package, version) | ||
valid_packages = [ | ||
:puppet_agent, | ||
:puppet | ||
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. Shouldn't we have a longer list of valid packages here? Puppetserver, puppetdb, puppetdb-termini are all versioned on the same scheme as puppet and puppet_agent, so there is a case to be made that we might need to find the release stream for those packages. 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. I was thinking this could be something that'd be extended on a per-need case? So if a puppetserver person finds out that they need to calculate the collection from their package version, then they can extend this method with that code (and they'd figure out they need the collection from the raised exception). If you think it is a good idea to do as much as we can in the current implementation, however, I'm happy to update it. I'm not sure what the collection should be for legacy server/puppetdb versions (like Server 2.x, since agent 1.x uses it). Maybe we don't need to worry about those. 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. I suppose it depends on where this method is used? But generally since this repo is so ad hoc, I'm fine waiting to add those other packages until we need them. As long as that's a conscious decision |
||
] | ||
|
||
return 'pc1' if x == 1 | ||
|
||
# A y version >= 99 indicates a pre-release version of the next x release | ||
x += 1 if y >= 99 | ||
"puppet#{x}" if x > 4 | ||
end | ||
unless valid_packages.include?(package) | ||
raise "package must be one of #{valid_packages.join(', ')}" | ||
end | ||
|
||
# Determine the puppet collection that matches a given version of the puppet gem. | ||
# | ||
# @param version [String] a semver version number of the puppet gem, or the string 'latest' | ||
# @returns [String|nil] the name of the corresponding puppet collection, if any | ||
def puppet_collection_for_puppet_version(puppet_version) | ||
puppet_version = puppet_version.to_s | ||
return 'puppet' if puppet_version.strip == 'latest' | ||
case package | ||
when :puppet_agent, :puppet | ||
version = version.to_s | ||
return 'puppet' if version.strip == 'latest' | ||
|
||
x, y, z = puppet_version.to_s.split('.').map(&:to_i) | ||
return nil if x.nil? || y.nil? || z.nil? | ||
x, y, z = version.to_s.split('.').map(&:to_i) | ||
return nil if x.nil? || y.nil? || z.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. Is there a way we can reduce the redundancies here? The only real difference between 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. Yeah, I can go ahead and do that. 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. Updated the PR with a new commit. |
||
|
||
return 'pc1' if x == 4 | ||
pc1_x = package == :puppet ? 4 : 1 | ||
return 'pc1' if x == pc1_x | ||
|
||
# A y version >= 99 indicates a pre-release version of the next x release | ||
x += 1 if y >= 99 | ||
"puppet#{x}" if x > 4 | ||
# A y version >= 99 indicates a pre-release version of the next x release | ||
x += 1 if y >= 99 | ||
"puppet#{x}" if x > 4 | ||
end | ||
end | ||
|
||
# Report the version of puppet-agent installed on `host` | ||
|
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.
Chose this instead of
puppet_collection_for(agent_version: <version>)
because a single entry hash parameter doesn't really make sense.