diff --git a/libraries/recipe_helpers.rb b/libraries/recipe_helpers.rb index 767e995f..4f2afcd5 100644 --- a/libraries/recipe_helpers.rb +++ b/libraries/recipe_helpers.rb @@ -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) @@ -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 @@ -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 diff --git a/spec/dd-agent_spec.rb b/spec/dd-agent_spec.rb index 08a7471e..cc5bde17 100644 --- a/spec/dd-agent_spec.rb +++ b/spec/dd-agent_spec.rb @@ -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