diff options
author | Lamont Granquist <454857+lamont-granquist@users.noreply.github.com> | 2021-12-16 17:10:18 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-16 17:10:18 -0800 |
commit | 29fe9511a9cd173c31bb9b38f6b193df350d4682 (patch) | |
tree | f0cc31e79687aa43bdaa949b80ccc982c46804f1 | |
parent | b360464582e11b4b71b11505fe933e38a8de26df (diff) | |
parent | 8519f0a9fdce4a5546a74c994471c2d9067a8ae4 (diff) | |
download | chef-29fe9511a9cd173c31bb9b38f6b193df350d4682.tar.gz |
Merge pull request #10823 from chef/lcg/yum-versionfix
-rw-r--r-- | cspell.json | 2 | ||||
-rw-r--r-- | lib/chef/provider/package/yum.rb | 51 | ||||
-rw-r--r-- | lib/chef/provider/package/yum/python_helper.rb | 106 | ||||
-rw-r--r-- | spec/functional/resource/dnf_package_spec.rb | 2 | ||||
-rw-r--r-- | spec/functional/resource/yum_package_spec.rb | 826 |
5 files changed, 820 insertions, 167 deletions
diff --git a/cspell.json b/cspell.json index 838d70c661..baafe6cbeb 100644 --- a/cspell.json +++ b/cspell.json @@ -1257,6 +1257,7 @@ "subresources", "subsession", "SUBSTED", + "sunsetting", "SUPPRESSMSGBOXES", "svcadm", "svccfg", @@ -1471,6 +1472,7 @@ "XFORM", "XMLHTTP", "yieldparam", + "zabbix", "zanetti", "Zapp", "zeproc", 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<Version> - 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..6ca5cf5183 100644 --- a/lib/chef/provider/package/yum/python_helper.rb +++ b/lib/chef/provider/package/yum/python_helper.rb @@ -115,10 +115,90 @@ 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 + # + # @api private + 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 + + # 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 + 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<Version> # 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 @@ -137,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) @@ -174,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 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 d401651f70..9b127def8e 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*-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 + 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*-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 + 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*-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 + 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-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 + 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,174 +367,298 @@ 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 @@ -380,46 +666,50 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do it "when there is no solution to the constraint" 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 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 works by default" 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 |