Skip to content
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

Don't use epoch/release for yum package version on Chef < 14 #856

Merged
merged 2 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions libraries/recipe_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class << self
datadog-iot-agent
].freeze

def chef_version_ge?(version)
Gem::Requirement.new(">= #{version}").satisfied_by?(Gem::Version.new(Chef::VERSION))
end

def agent_version(node)
dd_agent_version = node['datadog']['agent_version']
if dd_agent_version.respond_to?(:each_pair)
Expand All @@ -18,7 +22,10 @@ def agent_version(node)
dd_agent_version = dd_agent_version[platform_family]
end
if !dd_agent_version.nil? && dd_agent_version.match(/^[0-9]+\.[0-9]+\.[0-9]+((?:~|-)[^0-9\s-]+[^-\s]*)?$/)
if %w[debian amazon fedora rhel suse].include?(node['platform_family'])
# For RHEL-based distros, we can only add epoch and release when running Chef >= 14, as Chef < 14
# has different yum logic that doesn't know how to work with epoch and/or release
if %w[debian suse].include?(node['platform_family']) ||
(%w[amazon fedora rhel].include?(node['platform_family']) && chef_version_ge?(14))
dd_agent_version = '1:' + dd_agent_version + '-1'
end
end
Expand Down Expand Up @@ -187,7 +194,7 @@ def chef_version_can_uninstall?
# because they cannot correctly fetch the registry keys of 64 bits
# applications for uninstallation so we are only using the downgrade
# feature on chef >= to 14
Gem::Requirement.new('>= 14').satisfied_by?(Gem::Version.new(Chef::VERSION))
Chef::Datadog.chef_version_ge? 14
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion spec/dd-agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,11 @@ def set_env_var(name, value)
end.converge described_recipe
end
it 'installs the full version' do
expect(chef_run).to install_dnf_package('datadog-agent').with_version('1:6.16.0-1')
if Chef::Datadog.chef_version_ge? 14
expect(chef_run).to install_dnf_package('datadog-agent').with_version('1:6.16.0-1')
else
expect(chef_run).to install_dnf_package('datadog-agent').with_version('6.16.0')
end
end
end
end
Expand Down