Skip to content

Commit

Permalink
Don't use epoch/release for yum package version on Chef < 14 (#856)
Browse files Browse the repository at this point in the history
* Don't use epoch/release for yum package version on Chef < 14

* Fix style and specs
  • Loading branch information
Slavek Kabrda authored Aug 10, 2022
1 parent e77a6c3 commit e3616d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
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

0 comments on commit e3616d0

Please sign in to comment.