Created
July 15, 2015 20:06
-
-
Save ajroetker/e76dd6f7ff2c7ead9bae to your computer and use it in GitHub Desktop.
WHAT DO IT DO?!!?!?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<<<<<<< HEAD | |
def get_package_version(host, version = nil) | |
version = PuppetDBExtensions.config[:package_build_version].to_s | |
# version can look like: | |
# 3.0.0 | |
# 3.0.0.SNAPSHOT.2015.07.08T0945 | |
# Rewrite version if its a SNAPSHOT in rc form | |
if version.include?("SNAPSHOT") | |
version = version.sub(/^(.*)\.(SNAPSHOT\..*)$/, "\\1-0.1\\2") | |
else | |
version = version + "-1" | |
end | |
## These 'platform' values come from the acceptance config files, so | |
## we're relying entirely on naming conventions here. Would be nicer | |
## to do this using lsb_release or something, but... | |
if host['platform'].include?('el-5') | |
"#{version}.el5" | |
elsif host['platform'].include?('el-6') | |
"#{version}.el6" | |
elsif host['platform'].include?('el-7') | |
"#{version}.el7" | |
elsif host['platform'].include?('fedora') | |
version_tag = host['platform'].match(/^fedora-(\d+)/)[1] | |
"#{version}.fc#{version_tag}" | |
elsif host['platform'].include?('ubuntu') or host['platform'].include?('debian') | |
"#{version}puppetlabs1" | |
else | |
raise ArgumentError, "Unsupported platform: '#{platform}'" | |
end | |
end | |
======= | |
def platform_is_rpm_based(platform) | |
platform.include?('el-') or platform.include?('fedora') | |
end | |
def platform_is_deb_based(platform) | |
platform.include?('ubuntu') or platform.include?('debian') | |
end | |
def expected_version_for_platform(platform) | |
if platform_is_rpm_based(platform) | |
PuppetDBExtensions.config[:expected_rpm_version] | |
elsif platform_is_deb_based(platform) | |
PuppetDBExtensions.config[:expected_deb_version] | |
else | |
raise ArgumentError, "Unsupported platform: '#{platform}'" | |
end | |
end | |
def ensure_suffix(s, suffix) | |
if s.end_with?(suffix) | |
s | |
else | |
s + suffix | |
end | |
end | |
def format_package_version_for_platform(platform, version) | |
## These 'platform' values come from the acceptance config files, so | |
## we're relying entirely on naming conventions here. Would be nicer | |
## to do this using lsb_release or something, but... | |
if platform.include?('el-5') | |
ensure_suffix(version, ".el5") | |
elsif platform.include?('el-6') | |
ensure_suffix(version, ".el6") | |
elsif platform.include?('el-7') | |
ensure_suffix(version, ".el7") | |
elsif platform.include?('fedora') | |
version_tag = platform.match(/^fedora-(\d+)/)[1] | |
ensure_suffix(version, ".fc#{version_tag}") | |
elsif platform.include?('ubuntu') or platform.include?('debian') | |
ensure_suffix(version, "-1puppetlabs1") | |
else | |
raise ArgumentError, "Unsupported platform: '#{platform}'" | |
end | |
end | |
def get_package_version(host, version = nil) | |
# Handle a few different kinds of input: | |
# - version = nil -> use PUPPETDB_EXPECTED_RPM_VERSION or PUPPETDB_EXPECTED_DEB_VERSION, | |
# depending on the distro. Add distro-specific formatting if it's not already there. | |
# - version = "x.y.z" -> Add distro-specific formatting to the given version. | |
# - anything else: assume it's already been formatted correctly, just return it. | |
platform = host['platform'] | |
if version.nil? | |
expected_version = expected_version_for_platform(platform) | |
format_package_version_for_platform(platform, expected_version) | |
elsif version =~ /\d+\.\d+\.\d+/ | |
format_package_version_for_platform(platform, version) | |
else | |
version | |
end | |
end | |
>>>>>>> 2.3.x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment