From f4165b07d21cae256a48cdc6a168d994bb49d575 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Tue, 14 Dec 2021 17:32:49 -0800 Subject: Backport of DNF idempotency fixes to YUM This should fix most outstanding issues with the yum_package provide and give roughtly the same syntax options as with DNF (although DNF supports more syntax than YUM does because the library support is inherently better) Signed-off-by: Lamont Granquist --- lib/chef/provider/package/yum.rb | 51 +- lib/chef/provider/package/yum/python_helper.rb | 68 +- spec/functional/resource/yum_package_spec.rb | 830 +++++++++++++++++++++---- 3 files changed, 799 insertions(+), 150 deletions(-) diff --git a/lib/chef/provider/package/yum.rb b/lib/chef/provider/package/yum.rb index 121083ea46..07ed56aaf1 100644 --- a/lib/chef/provider/package/yum.rb +++ b/lib/chef/provider/package/yum.rb @@ -36,6 +36,7 @@ class Chef allow_nils use_multipackage_api use_package_name_for_source + use_magic_version provides :package, platform_family: "fedora_derived" @@ -64,6 +65,16 @@ class Chef current_resource end + def load_after_resource + # force the installed version array to repopulate + @current_version = [] + @after_resource = Chef::Resource::YumPackage.new(new_resource.name) + after_resource.package_name(new_resource.package_name) + after_resource.version(get_current_versions) + + after_resource + end + def define_resource_requirements requirements.assert(:install, :upgrade, :remove, :purge) do |a| a.assertion { !new_resource.source || ::File.exist?(new_resource.source) } @@ -80,9 +91,15 @@ class Chef end end + def magic_version_array + package_name_array.each_with_index.map do |pkg, i| + magical_version(i).version_with_arch + end + end + def get_current_versions package_name_array.each_with_index.map do |pkg, i| - installed_version(i).version_with_arch + current_version(i).version_with_arch end end @@ -127,7 +144,7 @@ class Chef alias upgrade_package install_package def remove_package(names, versions) - resolved_names = names.each_with_index.map { |name, i| installed_version(i).to_s unless name.nil? } + resolved_names = names.each_with_index.map { |name, i| magical_version(i).to_s unless name.nil? } yum(options, "-y", "remove", resolved_names) flushcache end @@ -157,10 +174,10 @@ class Chef def resolved_package_lock_names(names) names.each_with_index.map do |name, i| unless name.nil? - if installed_version(i).version.nil? + if magical_version(i).version.nil? available_version(i).name else - installed_version(i).name + magical_version(i).name end end end @@ -226,15 +243,25 @@ class Chef @available_version[index] end + def magical_version(index) + @magical_version ||= [] + @magical_version[index] ||= if new_resource.source + python_helper.package_query(:whatinstalled, available_version(index).name, version: safe_version_array[index], arch: safe_arch_array[index], options: options) + else + python_helper.package_query(:whatinstalled, package_name_array[index], version: safe_version_array[index], arch: safe_arch_array[index], options: options) + end + @magical_version[index] + end + # @return Array - def installed_version(index) - @installed_version ||= [] - @installed_version[index] ||= if new_resource.source - python_helper.package_query(:whatinstalled, available_version(index).name, arch: safe_arch_array[index], options: options) - else - python_helper.package_query(:whatinstalled, package_name_array[index], arch: safe_arch_array[index], options: options) - end - @installed_version[index] + def current_version(index) + @current_version ||= [] + @current_version[index] ||= if new_resource.source + python_helper.package_query(:whatinstalled, available_version(index).name, arch: safe_arch_array[index], options: options) + else + python_helper.package_query(:whatinstalled, package_name_array[index], arch: safe_arch_array[index], options: options) + end + @current_version[index] end def flushcache diff --git a/lib/chef/provider/package/yum/python_helper.rb b/lib/chef/provider/package/yum/python_helper.rb index db929ea88b..adf950ee88 100644 --- a/lib/chef/provider/package/yum/python_helper.rb +++ b/lib/chef/provider/package/yum/python_helper.rb @@ -115,17 +115,71 @@ class Chef end end + def is_arch?(arch) + # cspell:disable-next + arches = %w{alpha alphaev4 alphaev45 alphaev5 alphaev56 alphaev6 alphaev67 alphaev68 alphaev7 alphapca56 amd64 armv5tejl armv5tel armv6l armv7l athlon geode i386 i486 i586 i686 ia32e ia64 noarch ppc ppc64 ppc64iseries ppc64pseries s390 s390x sh3 sh4 sh4a sparc sparc64 sparc64v sparcv8 sparcv9 sparcv9v x86_64} + arches.include?(arch) + end + + # We have a provides line with an epoch in it and yum cannot parse that, so we + # need to deconstruct the args. This doesn't support splats which is why we + # only do it for this particularly narrow use case. + # + # name-epoch:version + # name-epoch:version.arch + # name-epoch:version-release + # name-epoch:version-release.arch + # + def deconstruct_args(provides) + raise "provides must have an epoch in the version to deconstruct" unless provides =~ /^(\S+)-(\d+):(\S+)/ + + name = $1 + epoch = $2 + other = $3 + ret = { "provides" => name, "epoch" => epoch } + maybe_arch = other.rpartition(".").last + arch = if is_arch?(maybe_arch) + other.delete_suffix!(".#{maybe_arch}") + maybe_arch + end + ret.merge!({ "arch" => arch }) if arch + (version, _, release) = other.rpartition("-") + if version.empty? + ret.merge!({ "version" => release }) # yeah, rpartition is just weird + else + ret.merge!({ "version" => version, "release" => release }) + end + end + + def combine_args(provides, version, arch) + provides = provides.dup + maybe_arch = provides.rpartition(".").last + if is_arch?(maybe_arch) + arch = maybe_arch + provides.delete_suffix!(".#{arch}") + end + provides = "#{provides}-#{version}" if version + provides = "#{provides}.#{arch}" if arch + # yum (on rhel7) can't handle an epoch in provides, but + # deconstructing the args can't handle dealing with globs + if provides =~ /-\d+:/ && provides !~ /[\*\?]/ + deconstruct_args(provides) + else + { "provides" => provides } + end + end + # @return Array # NB: "options" here is the yum_package options hash and is deliberately not **opts def package_query(action, provides, version: nil, arch: nil, options: {}) - parameters = { "provides" => provides, "version" => version, "arch" => arch } + parameters = combine_args(provides, version, arch) repo_opts = options_params(options || {}) parameters.merge!(repo_opts) # XXX: for now we close the rpmdb before and after every query with an enablerepo/disablerepo to clean the helpers internal state close_rpmdb unless repo_opts.empty? query_output = query(action, parameters) version = parse_response(query_output.lines.last) - Chef::Log.trace "parsed #{version} from python helper" + puts "parsed #{version} from python helper" close_rpmdb unless repo_opts.empty? version end @@ -159,11 +213,11 @@ class Chef def query(action, parameters) with_helper do json = build_query(action, parameters) - Chef::Log.trace "sending '#{json}' to python helper" + puts "sending '#{json}' to python helper" outpipe.puts json outpipe.flush output = inpipe.readline.chomp - Chef::Log.trace "got '#{output}' from python helper" + puts "got '#{output}' from python helper" output end end @@ -175,9 +229,9 @@ class Chef end # Special handling for certain action / param combos - if %i{whatinstalled whatavailable}.include?(action) - add_version(hash, parameters["version"]) unless parameters["version"].nil? - end + # if %i{whatinstalled whatavailable}.include?(action) + # add_version(hash, parameters["version"]) unless parameters["version"].nil? + # end FFI_Yajl::Encoder.encode(hash) end diff --git a/spec/functional/resource/yum_package_spec.rb b/spec/functional/resource/yum_package_spec.rb index d401651f70..1d6c5c8019 100644 --- a/spec/functional/resource/yum_package_spec.rb +++ b/spec/functional/resource/yum_package_spec.rb @@ -81,36 +81,40 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do context "vanilla use case" do it "installs if the package is not installed" do flush_cache - yum_package("chef_rpm") do + yum_package "chef_rpm" do options default_options + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") end it "does not install if the package is installed" do preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") - yum_package("chef_rpm") do + yum_package "chef_rpm" do options default_options + action :install end.should_not_be_updated - expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") end it "does not install twice" do flush_cache - yum_package("chef_rpm") do + yum_package "chef_rpm" do options default_options + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") - yum_package("chef_rpm") do + yum_package "chef_rpm" do options default_options + action :install end.should_not_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") end it "does not install if the prior version package is installed" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") - yum_package("chef_rpm") do + yum_package "chef_rpm" do options default_options + action :install end.should_not_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") end @@ -118,8 +122,9 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do it "does not install if the i686 package is installed", :intel_64bit do skip "FIXME: do nothing, or install the #{pkg_arch} version?" preinstall("chef_rpm-1.10-1.i686.rpm") - yum_package("chef_rpm") do + yum_package "chef_rpm" do options default_options + action :install end.should_not_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.i686$") end @@ -127,77 +132,234 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do it "does not install if the prior version i686 package is installed", :intel_64bit do skip "FIXME: do nothing, or install the #{pkg_arch} version?" preinstall("chef_rpm-1.2-1.i686.rpm") - yum_package("chef_rpm") do + yum_package "chef_rpm" do options default_options + action :install end.should_not_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.i686$") end end + context "expanded idempotency checks with version variants" do + # 0:1.10, 0:1.10-1, 0:1*-1 don't work on yum/el6 + %w{1.10 1* 1.10-1 1*-1 1.10-* 1*-* 0:1* *:1.10-* *:1*-*}.each do |vstring| + it "installs the rpm when #{vstring} is in the package_name" do + flush_cache + yum_package "chef_rpm-#{vstring}" do + options default_options + action :install + end.should_be_updated + end + + it "is idempotent when #{vstring} is in the package_name" do + preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") + yum_package "chef_rpm-#{vstring}" do + options default_options + action :install + end.should_not_be_updated + end + + it "installs the rpm when #{vstring} is in the version property" do + flush_cache + yum_package "chef_rpm" do + options default_options + version vstring + action :install + end.should_be_updated + end + + it "is idempotent when #{vstring} is in the version property" do + preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") + yum_package "chef_rpm" do + options default_options + version vstring + action :install + end.should_not_be_updated + end + + it "upgrades the rpm when #{vstring} is in the package_name" do + flush_cache + yum_package "chef_rpm-#{vstring}" do + options default_options + action :upgrade + end.should_be_updated + end + + it "is idempotent when #{vstring} is in the package_name" do + preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") + yum_package "chef_rpm-#{vstring}" do + options default_options + action :upgrade + end.should_not_be_updated + end + + it "upgrades the rpm when #{vstring} is in the version property" do + flush_cache + yum_package "chef_rpm" do + options default_options + version vstring + action :upgrade + end.should_be_updated + end + + it "is idempotent when #{vstring} is in the version property" do + preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") + yum_package "chef_rpm" do + options default_options + version vstring + action :upgrade + end.should_not_be_updated + end + end + + # 0:1.2 0:1.2-1 0:1*-1 don't work on yum/el6 + %w{1.2 1* 1.2-1 1*-1 1.2-* 1*-* 0:1* *:1.2-* *:1*-*}.each do |vstring| + it "is idempotent when #{vstring} is in the version property and there is a candidate version" do + preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") + yum_package "chef_rpm" do + options default_options + version vstring + action :install + end.should_not_be_updated + expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + end + end + + # 0:1.2, 0:1.2-1, 0:1*-1 don't work on yum/el6 + %w{1.2 1.2-1 1.2-* *:1.2-*}.each do |vstring| + it "is idempotent when #{vstring} is in the version property on upgrade and it doesn't match the candidate version" do + preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") + yum_package "chef_rpm" do + options default_options + version vstring + action :upgrade + end.should_not_be_updated + expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + end + end + + # 0:1.2, 0:1.2-1, 0:1*-1 don't work on yum/el6 + %w{1* 1*-1 1*-* 0:1* *:1*-*}.each do |vstring| + it "upgrades when #{vstring} is in the version property on upgrade and it matches the candidate version" do + preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") + yum_package "chef_rpm" do + options default_options + version vstring + action :upgrade + end.should_be_updated + expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm" do + options default_options + version vstring + action :upgrade + end.should_not_be_updated + end + end + end + context "with versions or globs in the name" do it "works with a version" do flush_cache - yum_package("chef_rpm-1.10") do + yum_package "chef_rpm-1.10" do options default_options + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm-1.10" do + options default_options + action :install + end.should_not_be_updated end it "works with an older version" do flush_cache - yum_package("chef_rpm-1.2") do + yum_package "chef_rpm-1.2" do options default_options + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + yum_package "chef_rpm-1.2" do + options default_options + action :install + end.should_not_be_updated end it "works with an evra" do flush_cache - yum_package("chef_rpm-0:1.2-1.#{pkg_arch}") do + yum_package "chef_rpm-0:1.2-1.#{pkg_arch}" do options default_options + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + yum_package "chef_rpm-0:1.2-1.#{pkg_arch}" do + options default_options + action :install + end.should_not_be_updated end it "works with version and release" do flush_cache - yum_package("chef_rpm-1.2-1") do + yum_package "chef_rpm-1.2-1" do options default_options + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + yum_package "chef_rpm-1.2-1" do + options default_options + action :install + end.should_not_be_updated end it "works with a version glob" do flush_cache - yum_package("chef_rpm-1*") do + yum_package "chef_rpm-1*" do options default_options + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm-1*" do + options default_options + action :install + end.should_not_be_updated end it "works with a name glob + version glob" do flush_cache - yum_package("chef_rp*-1*") do + yum_package "chef_rp*-1*" do options default_options + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rp*-1*" do + options default_options + action :install + end.should_not_be_updated end it "upgrades when the installed version does not match the version string" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") - yum_package("chef_rpm-1.10") do + yum_package "chef_rpm-1.10" do options default_options + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}") + yum_package "chef_rpm-1.10" do + options default_options + action :install + end.should_not_be_updated end it "downgrades when the installed version is higher than the package_name version" do preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") - yum_package("chef_rpm-1.2") do - allow_downgrade true + yum_package "chef_rpm-1.2" do options default_options + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + yum_package "chef_rpm-1.2" do + options default_options + action :install + end.should_not_be_updated end end @@ -205,221 +367,349 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do context "with version property" do it "matches the full version" do flush_cache - yum_package("chef_rpm") do + yum_package "chef_rpm" do options default_options - version("1.10") + version "1.10" + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm" do + options default_options + version "1.10" + action :install + end.should_not_be_updated end it "matches with a glob" do - # we are unlikely to ever fix this. if you've found this comment you should use e.g. "tcpdump-4*" in - # the name field rather than trying to use a name of "tcpdump" and a version of "4*". - pending "this does not work, is not easily supported by the underlying yum libraries, but does work in the new dnf_package provider" flush_cache - yum_package("chef_rpm") do + yum_package "chef_rpm" do options default_options - version("1*") + version "1*" + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm" do + options default_options + version "1*" + action :install + end.should_not_be_updated end it "matches the vr" do flush_cache - yum_package("chef_rpm") do + yum_package "chef_rpm" do options default_options - version("1.10-1") + version "1.10-1" + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm" do + options default_options + version "1.10-1" + action :install + end.should_not_be_updated end it "matches the evr" do flush_cache - yum_package("chef_rpm") do + yum_package "chef_rpm" do options default_options - version("0:1.10-1") + version "0:1.10-1" + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm" do + options default_options + version "0:1.10-1" + action :install + end.should_not_be_updated end it "matches with a vr glob" do - pending "doesn't work on command line either" flush_cache - yum_package("chef_rpm") do + yum_package "chef_rpm" do options default_options - version("1.10-1*") + version "1.10-1*" + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm" do + options default_options + version "1.10-1*" + action :install + end.should_not_be_updated end it "matches with an evr glob" do - pending "doesn't work on command line either" flush_cache - yum_package("chef_rpm") do + yum_package "chef_rpm" do options default_options - version("0:1.10-1*") + version "0:1.10-1*" + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm" do + options default_options + version "0:1.10-1*" + action :install + end.should_not_be_updated end end context "downgrades" do - it "downgrades the package when allow_downgrade" do + it "downgrades the package when allow_downgrade is true" do flush_cache preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") - yum_package("chef_rpm") do + yum_package "chef_rpm" do options default_options - allow_downgrade true - version("1.2-1") + version "1.2-1" + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + yum_package "chef_rpm" do + options default_options + version "1.2-1" + action :install + end.should_not_be_updated + end + + it "does not downgrade the package when allow_downgrade is false" do + flush_cache + preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") + yum_package "chef_rpm" do + options default_options + allow_downgrade false + version "1.2-1" + action :install + end.should_not_be_updated + expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") end end context "with arches", :intel_64bit do it "installs with 64-bit arch in the name" do flush_cache - yum_package("chef_rpm.#{pkg_arch}") do + yum_package "chef_rpm.#{pkg_arch}" do options default_options + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm.#{pkg_arch}" do + options default_options + action :install + end.should_not_be_updated end it "installs with 32-bit arch in the name" do flush_cache - yum_package("chef_rpm.i686") do + yum_package "chef_rpm.i686" do options default_options + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.i686$") + yum_package "chef_rpm.i686" do + options default_options + action :install + end.should_not_be_updated end it "installs with 64-bit arch in the property" do flush_cache - yum_package("chef_rpm") do + yum_package "chef_rpm" do options default_options - arch((pkg_arch).to_s) + arch pkg_arch + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm" do + options default_options + arch pkg_arch + action :install + end.should_not_be_updated end it "installs with 32-bit arch in the property" do flush_cache - yum_package("chef_rpm") do + yum_package "chef_rpm" do options default_options - arch("i686") + arch "i686" + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.i686$") + yum_package "chef_rpm" do + options default_options + arch "i686" + action :install + end.should_not_be_updated + end + + it "installs when the 32-bit arch is in the name and the version is in the property" do + flush_cache + yum_package "chef_rpm.i686" do + options default_options + version "1.10-1" + action :install + end.should_be_updated + expect_matching_installed_version("^chef_rpm-1.10-1.i686$") + yum_package "chef_rpm.i686" do + options default_options + version "1.10-1" + action :install + end.should_not_be_updated + end + + it "installs when the 64-bit arch is in the name and the version is in the property" do + flush_cache + yum_package "chef_rpm.#{pkg_arch}" do + options default_options + version "1.10-1" + action :install + end.should_be_updated + expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm.#{pkg_arch}" do + options default_options + version "1.10-1" + action :install + end.should_not_be_updated end end context "with constraints" do it "with nothing installed, it installs the latest version" do flush_cache - yum_package("chef_rpm >= 1.2") do + yum_package "chef_rpm >= 1.2" do options default_options + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm >= 1.2" do + options default_options + action :install + end.should_not_be_updated end it "when it is met, it does nothing" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") - yum_package("chef_rpm >= 1.2") do + yum_package "chef_rpm >= 1.2" do options default_options + action :install end.should_not_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") end it "when it is met, it does nothing" do preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") - yum_package("chef_rpm >= 1.2") do + yum_package "chef_rpm >= 1.2" do options default_options + action :install end.should_not_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") end - it "with nothing intalled, it installs the latest version" do + it "with nothing installed, it installs the latest version" do flush_cache - yum_package("chef_rpm > 1.2") do + yum_package "chef_rpm > 1.2" do options default_options + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm > 1.2" do + options default_options + action :install + end.should_not_be_updated end it "when it is not met by an installed rpm, it upgrades" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") - yum_package("chef_rpm > 1.2") do + yum_package "chef_rpm > 1.2" do options default_options + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm > 1.2" do + options default_options + action :install + end.should_not_be_updated end it "with an equality constraint, when it is not met by an installed rpm, it upgrades" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") - yum_package("chef_rpm = 1.10") do + yum_package "chef_rpm = 1.10" do options default_options + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm = 1.10" do + options default_options + action :install + end.should_not_be_updated end it "with an equality constraint, when it is met by an installed rpm, it does nothing" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") - yum_package("chef_rpm = 1.2") do + yum_package "chef_rpm = 1.2" do options default_options + action :install end.should_not_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") end it "when it is met by an installed rpm, it does nothing" do preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") - yum_package("chef_rpm > 1.2") do + yum_package "chef_rpm > 1.2" do options default_options + action :install end.should_not_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") end - it "when there is no solution to the constraint" do + it "when there is no solution to the contraint" do flush_cache expect { - yum_package("chef_rpm > 2.0") do - options default_options - end + yum_package "chef_rpm > 2.0" }.to raise_error(Chef::Exceptions::Package, /No candidate version available/) end - it "when there is no solution to the constraint but an rpm is preinstalled" do + it "when there is no solution to the contraint but an rpm is preinstalled" do preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") expect { - yum_package("chef_rpm > 2.0") do - options default_options - end + yum_package "chef_rpm > 2.0" }.to raise_error(Chef::Exceptions::Package, /No candidate version available/) end it "with a less than constraint, when nothing is installed, it installs" do flush_cache - yum_package("chef_rpm < 1.10") do - allow_downgrade true + yum_package "chef_rpm < 1.10" do options default_options + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + yum_package "chef_rpm < 1.10" do + options default_options + action :install + end.should_not_be_updated end it "with a less than constraint, when the install version matches, it does nothing" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") - yum_package("chef_rpm < 1.10") do - allow_downgrade true + yum_package "chef_rpm < 1.10" do options default_options + action :install end.should_not_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") end it "with a less than constraint, when the install version fails, it should downgrade" do preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") - yum_package("chef_rpm < 1.10") do - allow_downgrade true + yum_package "chef_rpm < 1.10" do options default_options + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + yum_package "chef_rpm < 1.10" do + options default_options + action :install + end.should_not_be_updated end end @@ -427,95 +717,110 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do it "raises an exception when the package does not exist" do flush_cache expect { - yum_package("#{CHEF_SPEC_ASSETS}/yumrepo/this-file-better-not-exist.rpm") do - options default_options - end + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/this-file-better-not-exist.rpm" }.to raise_error(Chef::Exceptions::Package, /No candidate version available/) end it "does not raise a hard exception in why-run mode when the package does not exist" do Chef::Config[:why_run] = true flush_cache - yum_package("#{CHEF_SPEC_ASSETS}/yumrepo/this-file-better-not-exist.rpm") do + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/this-file-better-not-exist.rpm" do options default_options + action :install end end it "installs the package when using the source argument" do flush_cache yum_package "something" do - package_name "somethingelse" source("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm") + options default_options + package_name "somethingelse" + name "something" + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + yum_package "something" do + source("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm") + options default_options + package_name "somethingelse" + name "something" + action :install + end.should_not_be_updated end it "installs the package when the name is a path to a file" do flush_cache - yum_package("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm") do + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm" do options default_options + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm" do + options default_options + action :install + end.should_not_be_updated end - it "downgrade on a local file is ignored when allow_downgrade is false" do + it "downgrade on a local file with allow_downgrade true works" do preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") - yum_package("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm") do - allow_downgrade false + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm" do + options default_options version "1.2-1" + action :install + end.should_be_updated + expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm" do options default_options + version "1.2-1" + action :install end.should_not_be_updated - expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") end - it "downgrade on a local file with allow_downgrade true works" do + it "downgrade on a local file with allow_downgrade false does not downgrade" do preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") - yum_package("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm") do - version "1.2-1" - allow_downgrade true + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm" do options default_options - end.should_be_updated - expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + allow_downgrade false + version "1.2-1" + action :install + end.should_not_be_updated + expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") end it "does not downgrade the package with :install" do preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") - yum_package("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm") do + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm" do options default_options + action :install end.should_not_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") end it "does not upgrade the package with :install" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") - yum_package("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.10-1.#{pkg_arch}.rpm") do + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.10-1.#{pkg_arch}.rpm" do options default_options + action :install end.should_not_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") end it "is idempotent when the package is already installed" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") - yum_package("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm") do + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm" do options default_options + action :install end.should_not_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") end it "is idempotent when the package is already installed and there is a version string" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") - yum_package("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm") do - version "1.2-1" - options default_options - end.should_not_be_updated - expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") - end - - it "is idempotent when the package is already installed and there is a version string with arch" do - preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") - yum_package("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm") do - version "1.2-1.#{pkg_arch}" + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm" do options default_options + version "1.2-1" + action :install end.should_not_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") end @@ -527,6 +832,7 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") yum_package "chef_rpm" do options "--nogpgcheck" + action :install end.should_not_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") end @@ -534,28 +840,39 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do it "works with a local source" do FileUtils.rm_f "/etc/yum.repos.d/chef-yum-localtesting.repo" flush_cache - yum_package("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm") do + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm" do options "--nogpgcheck" + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm" do + options "--nogpgcheck" + action :install + end.should_not_be_updated end end context "multipackage with arches", :intel_64bit do it "installs two rpms" do flush_cache - yum_package([ "chef_rpm.#{pkg_arch}", "chef_rpm.i686" ] ) do + yum_package [ "chef_rpm.#{pkg_arch}", "chef_rpm.i686" ] do options default_options + action :install end.should_be_updated expect_matching_installed_version(/^chef_rpm-1.10-1.#{pkg_arch}$/) expect_matching_installed_version(/^chef_rpm-1.10-1.i686$/) + yum_package [ "chef_rpm.#{pkg_arch}", "chef_rpm.i686" ] do + options default_options + action :install + end.should_not_be_updated end it "does nothing if both are installed" do preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm", "chef_rpm-1.10-1.i686.rpm") flush_cache - yum_package([ "chef_rpm.#{pkg_arch}", "chef_rpm.i686" ] ) do + yum_package [ "chef_rpm.#{pkg_arch}", "chef_rpm.i686" ] do options default_options + action :install end.should_not_be_updated end @@ -563,18 +880,28 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") yum_package [ "chef_rpm.#{pkg_arch}", "chef_rpm.i686" ] do options default_options + action :install end.should_be_updated expect_matching_installed_version(/^chef_rpm-1.10-1.#{pkg_arch}$/) expect_matching_installed_version(/^chef_rpm-1.10-1.i686$/) + yum_package [ "chef_rpm.#{pkg_arch}", "chef_rpm.i686" ] do + options default_options + action :install + end.should_not_be_updated end it "installs the first rpm if the second is installed" do preinstall("chef_rpm-1.10-1.i686.rpm") yum_package [ "chef_rpm.#{pkg_arch}", "chef_rpm.i686" ] do options default_options + action :install end.should_be_updated expect_matching_installed_version(/^chef_rpm-1.10-1.#{pkg_arch}$/) expect_matching_installed_version(/^chef_rpm-1.10-1.i686$/) + yum_package [ "chef_rpm.#{pkg_arch}", "chef_rpm.i686" ] do + options default_options + action :install + end.should_not_be_updated end # unlikely to work consistently correct, okay to deprecate the arch-array in favor of the arch in the name @@ -583,9 +910,15 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do yum_package %w{chef_rpm chef_rpm} do options default_options arch [pkg_arch, "i686"] + action :install end.should_be_updated expect_matching_installed_version(/^chef_rpm-1.10-1.#{pkg_arch}$/) expect_matching_installed_version(/^chef_rpm-1.10-1.i686$/) + yum_package %w{chef_rpm chef_rpm} do + options default_options + arch [pkg_arch, "i686"] + action :install + end.should_not_be_updated end # unlikely to work consistently correct, okay to deprecate the arch-array in favor of the arch in the name @@ -594,9 +927,14 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do yum_package %w{chef_rpm chef_rpm} do options default_options arch [pkg_arch, "i686"] + action :install end.should_be_updated expect_matching_installed_version(/^chef_rpm-1.10-1.#{pkg_arch}$/) expect_matching_installed_version(/^chef_rpm-1.10-1.i686$/) + yum_package %w{chef_rpm chef_rpm} do + options default_options + action :install + end.should_not_be_updated end # unlikely to work consistently correct, okay to deprecate the arch-array in favor of the arch in the name @@ -605,9 +943,14 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do yum_package %w{chef_rpm chef_rpm} do options default_options arch [pkg_arch, "i686"] + action :install end.should_be_updated expect_matching_installed_version(/^chef_rpm-1.10-1.#{pkg_arch}$/) expect_matching_installed_version(/^chef_rpm-1.10-1.i686$/) + yum_package %w{chef_rpm chef_rpm} do + options default_options + action :install + end.should_not_be_updated end # unlikely to work consistently correct, okay to deprecate the arch-array in favor of the arch in the name @@ -616,6 +959,7 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do yum_package %w{chef_rpm chef_rpm} do options default_options arch [pkg_arch, "i686"] + action :install end.should_not_be_updated end end @@ -626,6 +970,7 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do expect { yum_package "chef_rpm" do options "--nogpgcheck --disablerepo=chef-yum-localtesting" + action :install end }.to raise_error(Chef::Exceptions::Package, /No candidate version available/) end @@ -633,9 +978,14 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do it "should work with disablerepo first" do flush_cache yum_package "chef_rpm" do - options "--nogpgcheck --disablerepo=* --enablerepo=chef-yum-localtesting" + options ["--nogpgcheck", "--disablerepo=*", "--enablerepo=chef-yum-localtesting"] + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm" do + options ["--nogpgcheck", "--disablerepo=*", "--enablerepo=chef-yum-localtesting"] + action :install + end.should_not_be_updated end it "should work to enable a disabled repo" do @@ -644,13 +994,19 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do expect { yum_package "chef_rpm" do options "--nogpgcheck" + action :install end }.to raise_error(Chef::Exceptions::Package, /No candidate version available/) flush_cache yum_package "chef_rpm" do options "--nogpgcheck --enablerepo=chef-yum-localtesting" + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm" do + options "--nogpgcheck --enablerepo=chef-yum-localtesting" + action :install + end.should_not_be_updated end it "when an idempotent install action is run, does not leave repos disabled" do @@ -667,58 +1023,107 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") # now we're still using the same cache in the yum_helper.py cache and we test to see if the # repo that we temporarily disabled is enabled on this pass. - yum_package("chef_rpm-1.10-1.#{pkg_arch}") do + yum_package "chef_rpm-1.10-1.#{pkg_arch}" do options "--nogpgcheck" + action :install end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm-1.10-1.#{pkg_arch}" do + options "--nogpgcheck" + action :install + end.should_not_be_updated end end end describe ":upgrade" do + context "downgrades" do + it "just work with DNF" do + preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") + yum_package "chef_rpm" do + options default_options + version "1.2" + action :install + end.should_be_updated + expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}") + yum_package "chef_rpm" do + options default_options + version "1.2" + action :install + end.should_not_be_updated + end + end context "with source arguments" do it "installs the package when using the source argument" do flush_cache yum_package "something" do + options default_options package_name "somethingelse" source("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm") action :upgrade end.should_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + yum_package "something" do + options default_options + package_name "somethingelse" + source("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm") + action :upgrade + end.should_not_be_updated end it "installs the package when the name is a path to a file" do flush_cache - yum_package("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm") do + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm" do options default_options action :upgrade end.should_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm" do + options default_options + action :upgrade + end.should_not_be_updated end it "downgrades the package when allow_downgrade is true" do preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") - yum_package("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm") do - allow_downgrade true + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm" do options default_options action :upgrade end.should_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm" do + options default_options + action :upgrade + end.should_not_be_updated + end + + it "does not downgrade the package when allow_downgrade is false" do + preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm" do + options default_options + allow_downgrade false + action :upgrade + end.should_not_be_updated + expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") end it "upgrades the package" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") - yum_package("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.10-1.#{pkg_arch}.rpm") do + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.10-1.#{pkg_arch}.rpm" do options default_options action :upgrade end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.10-1.#{pkg_arch}.rpm" do + options default_options + action :upgrade + end.should_not_be_updated end it "is idempotent when the package is already installed" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") - yum_package("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm") do + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm" do options default_options action :upgrade end.should_not_be_updated @@ -730,7 +1135,7 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do it "works when a package is installed" do FileUtils.rm_f "/etc/yum.repos.d/chef-yum-localtesting.repo" preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") - yum_package("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm") do + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm" do options "--nogpgcheck" action :upgrade end.should_not_be_updated @@ -740,74 +1145,186 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do it "works with a local source" do FileUtils.rm_f "/etc/yum.repos.d/chef-yum-localtesting.repo" flush_cache - yum_package("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm") do + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm" do options "--nogpgcheck" action :upgrade end.should_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + yum_package "#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm" do + options "--nogpgcheck" + action :upgrade + end.should_not_be_updated end end context "version pinning" do - it "with an equality pin in the name it upgrades a prior package" do + it "with a full version pin it installs a later package" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") - yum_package("chef_rpm-1.10") do + yum_package "chef_rpm" do options default_options + version "1.10-1" action :upgrade end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm" do + options default_options + version "1.10-1" + action :upgrade + end.should_not_be_updated end - it "with a prco equality pin in the name it upgrades a prior package" do + it "with a full version pin in the name it downgrades the package" do + preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") + yum_package "chef_rpm" do + options default_options + version "1.2-1" + action :upgrade + end.should_be_updated + expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + yum_package "chef_rpm" do + options default_options + version "1.2-1" + action :upgrade + end.should_not_be_updated + end + + it "with a partial (no release) version pin it installs a later package" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") - yum_package("chef_rpm == 1.10") do + yum_package "chef_rpm" do options default_options + version "1.10" action :upgrade end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm" do + options default_options + version "1.10" + action :upgrade + end.should_not_be_updated end - it "with an equality pin in the name it downgrades a later package" do + it "with a partial (no release) version pin in the name it downgrades the package" do preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") - yum_package("chef_rpm-1.2") do - allow_downgrade true + yum_package "chef_rpm" do options default_options + version("1.2") action :upgrade end.should_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + yum_package "chef_rpm" do + options default_options + version("1.2") + action :upgrade + end.should_not_be_updated + end + + it "with a full version pin it installs a later package" do + preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") + yum_package "chef_rpm-1.10-1" do + options default_options + action :upgrade + end.should_be_updated + expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm-1.10-1" do + options default_options + action :upgrade + end.should_not_be_updated + end + + it "with a full version pin in the name it downgrades the package" do + preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") + yum_package "chef_rpm-1.2-1" do + options default_options + action :upgrade + end.should_be_updated + expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + yum_package "chef_rpm-1.2-1" do + options default_options + action :upgrade + end.should_not_be_updated + end + + it "with a partial (no release) version pin it installs a later package" do + preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") + yum_package "chef_rpm-1.10" do + options default_options + action :upgrade + end.should_be_updated + expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm-1.10" do + options default_options + action :upgrade + end.should_not_be_updated + end + + it "with a partial (no release) version pin in the name it downgrades the package" do + preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") + yum_package "chef_rpm-1.2" do + options default_options + action :upgrade + end.should_be_updated + expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + yum_package "chef_rpm-1.2" do + options default_options + action :upgrade + end.should_not_be_updated + end + + it "with a prco equality pin in the name it upgrades a prior package" do + preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") + yum_package "chef_rpm = 1.10" do + options default_options + action :upgrade + end.should_be_updated + expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm = 1.10" do + options default_options + action :upgrade + end.should_not_be_updated end it "with a prco equality pin in the name it downgrades a later package" do preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") - yum_package("chef_rpm == 1.2") do - allow_downgrade true + yum_package "chef_rpm = 1.2" do options default_options action :upgrade end.should_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + yum_package "chef_rpm = 1.2" do + options default_options + action :upgrade + end.should_not_be_updated end it "with a > pin in the name and no rpm installed it installs" do flush_cache - yum_package("chef_rpm > 1.2") do + yum_package "chef_rpm > 1.2" do options default_options action :upgrade end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm > 1.2" do + options default_options + action :upgrade + end.should_not_be_updated end it "with a < pin in the name and no rpm installed it installs" do flush_cache - yum_package("chef_rpm < 1.10") do + yum_package "chef_rpm < 1.10" do options default_options action :upgrade end.should_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + yum_package "chef_rpm < 1.10" do + options default_options + action :upgrade + end.should_not_be_updated end it "with a > pin in the name and matching rpm installed it does nothing" do preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") - yum_package("chef_rpm > 1.2") do + yum_package "chef_rpm > 1.2" do options default_options action :upgrade end.should_not_be_updated @@ -816,7 +1333,7 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do it "with a < pin in the name and no rpm installed it installs" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") - yum_package("chef_rpm < 1.10") do + yum_package "chef_rpm < 1.10" do options default_options action :upgrade end.should_not_be_updated @@ -825,21 +1342,28 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do it "with a > pin in the name and non-matching rpm installed it upgrades" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") - yum_package("chef_rpm > 1.2") do + yum_package "chef_rpm > 1.2" do options default_options action :upgrade end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm > 1.2" do + options default_options + action :upgrade + end.should_not_be_updated end it "with a < pin in the name and non-matching rpm installed it downgrades" do preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") - yum_package("chef_rpm < 1.10") do - allow_downgrade true + yum_package "chef_rpm < 1.10" do options default_options action :upgrade end.should_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") + yum_package "chef_rpm < 1.10" do + options default_options + action :upgrade + end.should_not_be_updated end end end @@ -885,6 +1409,10 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do action :remove end.should_be_updated expect_matching_installed_version("^package chef_rpm is not installed$") + yum_package "chef_rpm" do + options default_options + action :remove + end.should_not_be_updated end it "removes the package if the i686 package is installed", :intel_64bit do @@ -895,6 +1423,10 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do action :remove end.should_be_updated expect_matching_installed_version("^package chef_rpm is not installed$") + yum_package "chef_rpm" do + options default_options + action :remove + end.should_not_be_updated end it "removes the package if the prior version i686 package is installed", :intel_64bit do @@ -905,6 +1437,10 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do action :remove end.should_be_updated expect_matching_installed_version("^package chef_rpm is not installed$") + yum_package "chef_rpm" do + options default_options + action :remove + end.should_not_be_updated end end @@ -925,6 +1461,10 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do action :remove end.should_be_updated expect_matching_installed_version("^package chef_rpm is not installed$") + yum_package "chef_rpm.#{pkg_arch}" do + options default_options + action :remove + end.should_not_be_updated end it "removes the package if the prior version package is installed" do @@ -934,6 +1474,10 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do action :remove end.should_be_updated expect_matching_installed_version("^package chef_rpm is not installed$") + yum_package "chef_rpm.#{pkg_arch}" do + options default_options + action :remove + end.should_not_be_updated end it "does nothing if the i686 package is installed" do @@ -963,6 +1507,10 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do action :remove end.should_be_updated expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") + yum_package "chef_rpm.i686" do + options default_options + action :remove + end.should_not_be_updated end end @@ -975,6 +1523,10 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do action :remove end.should_be_updated expect_matching_installed_version("^package chef_rpm is not installed$") + yum_package "chef_rpm" do + options "--nogpgcheck" + action :remove + end.should_not_be_updated end end end @@ -990,17 +1542,21 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do it "locks an rpm" do flush_cache - yum_package("chef_rpm") do + yum_package "chef_rpm" do options default_options action :lock end.should_be_updated expect(shell_out("yum versionlock list").stdout.chomp).to match("^0:chef_rpm-") + yum_package "chef_rpm" do + options default_options + action :lock + end.should_not_be_updated end it "does not lock if its already locked" do flush_cache shell_out!("yum versionlock add chef_rpm") - yum_package("chef_rpm") do + yum_package "chef_rpm" do options default_options action :lock end.should_not_be_updated @@ -1010,16 +1566,20 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do it "unlocks an rpm" do flush_cache shell_out!("yum versionlock add chef_rpm") - yum_package("chef_rpm") do + yum_package "chef_rpm" do options default_options action :unlock end.should_be_updated expect(shell_out("yum versionlock list").stdout.chomp).not_to match("^0:chef_rpm-") + yum_package "chef_rpm" do + options default_options + action :unlock + end.should_not_be_updated end it "does not unlock an already locked rpm" do flush_cache - yum_package("chef_rpm") do + yum_package "chef_rpm" do options default_options action :unlock end.should_not_be_updated @@ -1028,21 +1588,29 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do it "check that we can lock based on provides" do flush_cache - yum_package("chef_rpm_provides") do + yum_package "chef_rpm_provides" do options default_options action :lock end.should_be_updated expect(shell_out("yum versionlock list").stdout.chomp).to match("^0:chef_rpm-") + yum_package "chef_rpm_provides" do + options default_options + action :lock + end.should_not_be_updated end it "check that we can unlock based on provides" do flush_cache shell_out!("yum versionlock add chef_rpm") - yum_package("chef_rpm_provides") do + yum_package "chef_rpm_provides" do options default_options action :unlock end.should_be_updated expect(shell_out("yum versionlock list").stdout.chomp).not_to match("^0:chef_rpm-") + yum_package "chef_rpm_provides" do + options default_options + action :unlock + end.should_not_be_updated end end end -- cgit v1.2.1 From 824fdb9288c01036316b8e1c10b4893a90f9a899 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Tue, 14 Dec 2021 17:35:39 -0800 Subject: remove puts Signed-off-by: Lamont Granquist --- lib/chef/provider/package/yum/python_helper.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/chef/provider/package/yum/python_helper.rb b/lib/chef/provider/package/yum/python_helper.rb index adf950ee88..7e702f06c7 100644 --- a/lib/chef/provider/package/yum/python_helper.rb +++ b/lib/chef/provider/package/yum/python_helper.rb @@ -179,7 +179,7 @@ class Chef close_rpmdb unless repo_opts.empty? query_output = query(action, parameters) version = parse_response(query_output.lines.last) - puts "parsed #{version} from python helper" + Chef::Log.trace "parsed #{version} from python helper" close_rpmdb unless repo_opts.empty? version end @@ -213,11 +213,11 @@ class Chef def query(action, parameters) with_helper do json = build_query(action, parameters) - puts "sending '#{json}' to python helper" - outpipe.puts json + Chef::Log.trace "sending '#{json}' to python helper" + outpipe.Chef::Log.trace json outpipe.flush output = inpipe.readline.chomp - puts "got '#{output}' from python helper" + Chef::Log.trace "got '#{output}' from python helper" output end end -- cgit v1.2.1 From 80004ad9e2594ad80593d6bddc29de89fef53460 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Tue, 14 Dec 2021 17:47:12 -0800 Subject: errant copypasta fix Signed-off-by: Lamont Granquist --- lib/chef/provider/package/yum/python_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/chef/provider/package/yum/python_helper.rb b/lib/chef/provider/package/yum/python_helper.rb index 7e702f06c7..e595b79278 100644 --- a/lib/chef/provider/package/yum/python_helper.rb +++ b/lib/chef/provider/package/yum/python_helper.rb @@ -214,7 +214,7 @@ class Chef with_helper do json = build_query(action, parameters) Chef::Log.trace "sending '#{json}' to python helper" - outpipe.Chef::Log.trace json + outpipe.puts json outpipe.flush output = inpipe.readline.chomp Chef::Log.trace "got '#{output}' from python helper" -- cgit v1.2.1 From 1635491e8e2561c5eba12e68d929ee366cd8491c Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Wed, 15 Dec 2021 13:12:05 -0800 Subject: comments Signed-off-by: Lamont Granquist --- lib/chef/provider/package/yum/python_helper.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/chef/provider/package/yum/python_helper.rb b/lib/chef/provider/package/yum/python_helper.rb index e595b79278..df46c77c03 100644 --- a/lib/chef/provider/package/yum/python_helper.rb +++ b/lib/chef/provider/package/yum/python_helper.rb @@ -130,6 +130,7 @@ class Chef # name-epoch:version-release # name-epoch:version-release.arch # + # @api private def deconstruct_args(provides) raise "provides must have an epoch in the version to deconstruct" unless provides =~ /^(\S+)-(\d+):(\S+)/ @@ -151,6 +152,31 @@ class Chef end end + # In the default case for the yum provider we now do terrible things with ruby + # to concatenate all the properties together to form a single string to feed to + # the python which favors using returnPackages/searchProvides over the + # searchNevra API. That means that these two different ways of constructing the + # resource are now perfectly identical: + # + # yum_package "zabbix-agent-4.0.15-1.fc31.x86_64" + # + # yum_package "zabbix-agent" do + # version "4.0.15-1.fc31" + # arch "x86_64" + # end + # + # This function handles turning the second form into the first form. + # + # In the case where the epoch is given in the version and we do not have any glob + # patterns that is handled by going the other way and calling deconstruct_args due + # to the yum libraries not supporting that calling pattern other than by searchNevra. + # + # NOTE: This is an ugly hack and should NOT be considered an endorsement of this approach + # towards any kind of features or bugfixes in the DNF provider. I'm doing this + # because YUM is sunsetting at this point and its very difficult to fight with the + # libraries on the python side of things. + # + # @api private def combine_args(provides, version, arch) provides = provides.dup maybe_arch = provides.rpartition(".").last -- cgit v1.2.1 From 6a8fcdd25572fb3b17323af727a9528019d1f7d3 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Wed, 15 Dec 2021 14:23:21 -0800 Subject: cspell nagging Signed-off-by: Lamont Granquist --- cspell.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cspell.json b/cspell.json index 6f40be96c2..ab4ba89343 100644 --- a/cspell.json +++ b/cspell.json @@ -1256,6 +1256,7 @@ "subresources", "subsession", "SUBSTED", + "sunsetting", "SUPPRESSMSGBOXES", "svcadm", "svccfg", @@ -1470,6 +1471,7 @@ "XFORM", "XMLHTTP", "yieldparam", + "zabbix", "zanetti", "Zapp", "zeproc", -- cgit v1.2.1 From e7c01b838980ceb14a555550169fa0a90363cb08 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Wed, 15 Dec 2021 14:28:49 -0800 Subject: retesting the support matrix Signed-off-by: Lamont Granquist --- spec/functional/resource/yum_package_spec.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/spec/functional/resource/yum_package_spec.rb b/spec/functional/resource/yum_package_spec.rb index 1d6c5c8019..1eac11e599 100644 --- a/spec/functional/resource/yum_package_spec.rb +++ b/spec/functional/resource/yum_package_spec.rb @@ -142,7 +142,8 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do context "expanded idempotency checks with version variants" do # 0:1.10, 0:1.10-1, 0:1*-1 don't work on yum/el6 - %w{1.10 1* 1.10-1 1*-1 1.10-* 1*-* 0:1* *:1.10-* *:1*-*}.each do |vstring| + # %w{1.10 1* 1.10-1 1*-1 1.10-* 1*-* 0:1* *:1.10-* *:1*-*}.each do |vstring| + %w{1.10 1* 1.10-1 1*-1 1.10-* 1*-* 0:1* *:1.10-* *:1*-* 0:1.10 0:1.10-1 0:1*-1}.each do |vstring| it "installs the rpm when #{vstring} is in the package_name" do flush_cache yum_package "chef_rpm-#{vstring}" do @@ -213,7 +214,8 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do end # 0:1.2 0:1.2-1 0:1*-1 don't work on yum/el6 - %w{1.2 1* 1.2-1 1*-1 1.2-* 1*-* 0:1* *:1.2-* *:1*-*}.each do |vstring| + # %w{1.2 1* 1.2-1 1*-1 1.2-* 1*-* 0:1* *:1.2-* *:1*-*}.each do |vstring| + %w{1.2 1* 1.2-1 1*-1 1.2-* 1*-* 0:1* *:1.2-* *:1*-* 0:1.2 0:1.2-1 0:1*-1}.each do |vstring| it "is idempotent when #{vstring} is in the version property and there is a candidate version" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") yum_package "chef_rpm" do @@ -226,7 +228,8 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do end # 0:1.2, 0:1.2-1, 0:1*-1 don't work on yum/el6 - %w{1.2 1.2-1 1.2-* *:1.2-*}.each do |vstring| + # %w{1.2 1.2-1 1.2-* *:1.2-*}.each do |vstring| + %w{1.2 1.2-1 1.2-* *:1.2-* 0:1.2 0:1.2-1 0:1*-1}.each do |vstring| it "is idempotent when #{vstring} is in the version property on upgrade and it doesn't match the candidate version" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") yum_package "chef_rpm" do @@ -239,7 +242,8 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do end # 0:1.2, 0:1.2-1, 0:1*-1 don't work on yum/el6 - %w{1* 1*-1 1*-* 0:1* *:1*-*}.each do |vstring| + # %w{1* 1*-1 1*-* 0:1* *:1*-*}.each do |vstring| + %w{1* 1*-1 1*-* 0:1* *:1*-* 0:1.2 0:1.2-1 0:1*-1}.each do |vstring| it "upgrades when #{vstring} is in the version property on upgrade and it matches the candidate version" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") yum_package "chef_rpm" do -- cgit v1.2.1 From 398d42dd9fc8319c9a5d6f8c4b67e308c38330db Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Wed, 15 Dec 2021 14:34:24 -0800 Subject: remove vestigial add_version hack Signed-off-by: Lamont Granquist --- lib/chef/provider/package/yum/python_helper.rb | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/lib/chef/provider/package/yum/python_helper.rb b/lib/chef/provider/package/yum/python_helper.rb index df46c77c03..6ca5cf5183 100644 --- a/lib/chef/provider/package/yum/python_helper.rb +++ b/lib/chef/provider/package/yum/python_helper.rb @@ -217,25 +217,6 @@ class Chef private - # i couldn't figure out how to decompose an evr on the python side, it seems reasonably - # painless to do it in ruby (generally massaging nevras in the ruby side is HIGHLY - # discouraged -- this is an "every rule has an exception" exception -- any additional - # functionality should probably trigger moving this regexp logic into python) - def add_version(hash, version) - epoch = nil - if version =~ /(\S+):(\S+)/ - epoch = $1 - version = $2 - end - if version =~ /(\S+)-(\S+)/ - version = $1 - release = $2 - end - hash["epoch"] = epoch unless epoch.nil? - hash["release"] = release unless release.nil? - hash["version"] = version - end - def query(action, parameters) with_helper do json = build_query(action, parameters) @@ -254,11 +235,6 @@ class Chef hash[param_name] = param_value unless param_value.nil? end - # Special handling for certain action / param combos - # if %i{whatinstalled whatavailable}.include?(action) - # add_version(hash, parameters["version"]) unless parameters["version"].nil? - # end - FFI_Yajl::Encoder.encode(hash) end -- cgit v1.2.1 From fe97522c6dc5e66e851cd15436b0cae3ba0b3309 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Wed, 15 Dec 2021 14:36:19 -0800 Subject: weird typo Signed-off-by: Lamont Granquist --- spec/functional/resource/yum_package_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/functional/resource/yum_package_spec.rb b/spec/functional/resource/yum_package_spec.rb index 1eac11e599..ca0e2cbd95 100644 --- a/spec/functional/resource/yum_package_spec.rb +++ b/spec/functional/resource/yum_package_spec.rb @@ -667,14 +667,14 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do expect_matching_installed_version("^chef_rpm-1.10-1.#{pkg_arch}$") end - it "when there is no solution to the contraint" do + it "when there is no solution to the constraint" do flush_cache expect { yum_package "chef_rpm > 2.0" }.to raise_error(Chef::Exceptions::Package, /No candidate version available/) end - it "when there is no solution to the contraint but an rpm is preinstalled" do + it "when there is no solution to the constraint but an rpm is preinstalled" do preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") expect { yum_package "chef_rpm > 2.0" -- cgit v1.2.1 From 926ae65a444de4bbc9a6f4baebbb32b7105b6602 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Wed, 15 Dec 2021 15:18:23 -0800 Subject: tweak some strings Signed-off-by: Lamont Granquist --- spec/functional/resource/dnf_package_spec.rb | 2 +- spec/functional/resource/yum_package_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/functional/resource/dnf_package_spec.rb b/spec/functional/resource/dnf_package_spec.rb index 860eb2f999..655ae41a85 100644 --- a/spec/functional/resource/dnf_package_spec.rb +++ b/spec/functional/resource/dnf_package_spec.rb @@ -1036,7 +1036,7 @@ describe Chef::Resource::DnfPackage, :requires_root, external: exclude_test do describe ":upgrade" do context "downgrades" do - it "just work with DNF" do + it "just works by default" do preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") dnf_package "chef_rpm" do options default_options diff --git a/spec/functional/resource/yum_package_spec.rb b/spec/functional/resource/yum_package_spec.rb index ca0e2cbd95..0f54575cfe 100644 --- a/spec/functional/resource/yum_package_spec.rb +++ b/spec/functional/resource/yum_package_spec.rb @@ -1042,7 +1042,7 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do describe ":upgrade" do context "downgrades" do - it "just work with DNF" do + it "just works by default" do preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm") yum_package "chef_rpm" do options default_options -- cgit v1.2.1 From 1adbd71c9e8093fab703f8d3896cf470a15d4221 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Wed, 15 Dec 2021 15:24:13 -0800 Subject: fix the "support matrix" Signed-off-by: Lamont Granquist --- spec/functional/resource/yum_package_spec.rb | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/spec/functional/resource/yum_package_spec.rb b/spec/functional/resource/yum_package_spec.rb index 0f54575cfe..2135d23341 100644 --- a/spec/functional/resource/yum_package_spec.rb +++ b/spec/functional/resource/yum_package_spec.rb @@ -141,9 +141,8 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do end context "expanded idempotency checks with version variants" do - # 0:1.10, 0:1.10-1, 0:1*-1 don't work on yum/el6 - # %w{1.10 1* 1.10-1 1*-1 1.10-* 1*-* 0:1* *:1.10-* *:1*-*}.each do |vstring| - %w{1.10 1* 1.10-1 1*-1 1.10-* 1*-* 0:1* *:1.10-* *:1*-* 0:1.10 0:1.10-1 0:1*-1}.each do |vstring| + # 0:1*-1 doesn't work on yum/el6 + %w{1.10 1* 1.10-1 1*-1 1.10-* 1*-* 0:1* *:1.10-* *:1*-* 0:1.10 0:1.10-1}.each do |vstring| it "installs the rpm when #{vstring} is in the package_name" do flush_cache yum_package "chef_rpm-#{vstring}" do @@ -213,9 +212,8 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do end end - # 0:1.2 0:1.2-1 0:1*-1 don't work on yum/el6 - # %w{1.2 1* 1.2-1 1*-1 1.2-* 1*-* 0:1* *:1.2-* *:1*-*}.each do |vstring| - %w{1.2 1* 1.2-1 1*-1 1.2-* 1*-* 0:1* *:1.2-* *:1*-* 0:1.2 0:1.2-1 0:1*-1}.each do |vstring| + # 0:1*-1 doesn't work on yum/el6 + %w{1.2 1* 1.2-1 1*-1 1.2-* 1*-* 0:1* *:1.2-* *:1*-* 0:1.2 0:1.2-1}.each do |vstring| it "is idempotent when #{vstring} is in the version property and there is a candidate version" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") yum_package "chef_rpm" do @@ -227,9 +225,8 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do end end - # 0:1.2, 0:1.2-1, 0:1*-1 don't work on yum/el6 - # %w{1.2 1.2-1 1.2-* *:1.2-*}.each do |vstring| - %w{1.2 1.2-1 1.2-* *:1.2-* 0:1.2 0:1.2-1 0:1*-1}.each do |vstring| + # 0:1.2 0:1*-1 doesn't work on yum/el6 + %w{1.2 1.2-1 1.2-* *:1.2-* 0:1.2-1}.each do |vstring| it "is idempotent when #{vstring} is in the version property on upgrade and it doesn't match the candidate version" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") yum_package "chef_rpm" do @@ -241,9 +238,8 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do end end - # 0:1.2, 0:1.2-1, 0:1*-1 don't work on yum/el6 - # %w{1* 1*-1 1*-* 0:1* *:1*-*}.each do |vstring| - %w{1* 1*-1 1*-* 0:1* *:1*-* 0:1.2 0:1.2-1 0:1*-1}.each do |vstring| + # 0:1.2 0:1*-1 doesn't work on yum/el6 + %w{1* 1*-1 1*-* 0:1* *:1*-* 0:1.2-1}.each do |vstring| it "upgrades when #{vstring} is in the version property on upgrade and it matches the candidate version" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") yum_package "chef_rpm" do -- cgit v1.2.1 From 8519f0a9fdce4a5546a74c994471c2d9067a8ae4 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Wed, 15 Dec 2021 18:38:59 -0800 Subject: roll back one more unsupported use case Signed-off-by: Lamont Granquist --- spec/functional/resource/yum_package_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/functional/resource/yum_package_spec.rb b/spec/functional/resource/yum_package_spec.rb index 2135d23341..9b127def8e 100644 --- a/spec/functional/resource/yum_package_spec.rb +++ b/spec/functional/resource/yum_package_spec.rb @@ -238,8 +238,8 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do end end - # 0:1.2 0:1*-1 doesn't work on yum/el6 - %w{1* 1*-1 1*-* 0:1* *:1*-* 0:1.2-1}.each do |vstring| + # 0:1.2-1 0:1.2 0:1*-1 doesn't work on yum/el6 + %w{1* 1*-1 1*-* 0:1* *:1*-*}.each do |vstring| it "upgrades when #{vstring} is in the version property on upgrade and it matches the candidate version" do preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") yum_package "chef_rpm" do -- cgit v1.2.1