summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2018-03-16 09:55:33 -0700
committerGitHub <noreply@github.com>2018-03-16 09:55:33 -0700
commitb73d398049d25b38b6d1cc36d5fdc108d2912d80 (patch)
treeb0f5db55ce9f306aceb2069060f848da9473e95d
parentfb61966bbc7a2d8920d772ff7f3f3fc8543b107d (diff)
parentf6a4bf2fa6b47344acfc65b4f71d7952287a3840 (diff)
downloadchef-b73d398049d25b38b6d1cc36d5fdc108d2912d80.tar.gz
Merge pull request #6540 from chef/jcowie_yum_refactor
Yum refactor
-rw-r--r--lib/chef/provider/package.rb17
-rw-r--r--lib/chef/provider/package/yum.rb561
-rw-r--r--lib/chef/provider/package/yum/python_helper.rb221
-rw-r--r--lib/chef/provider/package/yum/rpm_utils.rb11
-rw-r--r--lib/chef/provider/package/yum/simplejson/LICENSE.txt79
-rw-r--r--lib/chef/provider/package/yum/simplejson/__init__.py318
-rw-r--r--lib/chef/provider/package/yum/simplejson/__init__.pycbin0 -> 12059 bytes
-rw-r--r--lib/chef/provider/package/yum/simplejson/decoder.py354
-rw-r--r--lib/chef/provider/package/yum/simplejson/decoder.pycbin0 -> 11088 bytes
-rw-r--r--lib/chef/provider/package/yum/simplejson/encoder.py440
-rw-r--r--lib/chef/provider/package/yum/simplejson/encoder.pycbin0 -> 13588 bytes
-rw-r--r--lib/chef/provider/package/yum/simplejson/scanner.py65
-rw-r--r--lib/chef/provider/package/yum/simplejson/scanner.pycbin0 -> 2405 bytes
-rw-r--r--lib/chef/provider/package/yum/simplejson/tool.py37
-rw-r--r--lib/chef/provider/package/yum/version.rb56
-rw-r--r--lib/chef/provider/package/yum/yum-dump.py307
-rw-r--r--lib/chef/provider/package/yum/yum_cache.rb349
-rw-r--r--lib/chef/provider/package/yum/yum_helper.py198
-rw-r--r--lib/chef/resource/yum_package.rb2
-rw-r--r--spec/functional/assets/yumrepo/chef_rpm-1.10-1.aarch64.rpmbin0 -> 2096 bytes
-rw-r--r--spec/functional/assets/yumrepo/chef_rpm-1.10-1.fc24.i686.rpmbin6530 -> 0 bytes
-rw-r--r--spec/functional/assets/yumrepo/chef_rpm-1.10-1.fc24.src.rpmbin6331 -> 0 bytes
-rw-r--r--spec/functional/assets/yumrepo/chef_rpm-1.10-1.fc24.x86_64.rpmbin6498 -> 0 bytes
-rw-r--r--spec/functional/assets/yumrepo/chef_rpm-1.10-1.i686.rpmbin0 -> 2148 bytes
-rw-r--r--spec/functional/assets/yumrepo/chef_rpm-1.10-1.ppc64.rpmbin0 -> 2118 bytes
-rw-r--r--spec/functional/assets/yumrepo/chef_rpm-1.10-1.ppc64le.rpmbin0 -> 2098 bytes
-rw-r--r--spec/functional/assets/yumrepo/chef_rpm-1.10-1.s390x.rpmbin0 -> 2102 bytes
-rw-r--r--spec/functional/assets/yumrepo/chef_rpm-1.10-1.src.rpmbin0 -> 2132 bytes
-rw-r--r--spec/functional/assets/yumrepo/chef_rpm-1.10-1.x86_64.rpmbin0 -> 2110 bytes
-rw-r--r--spec/functional/assets/yumrepo/chef_rpm-1.2-1.aarch64.rpmbin0 -> 2096 bytes
-rw-r--r--spec/functional/assets/yumrepo/chef_rpm-1.2-1.fc24.i686.rpmbin6526 -> 0 bytes
-rw-r--r--spec/functional/assets/yumrepo/chef_rpm-1.2-1.fc24.src.rpmbin6331 -> 0 bytes
-rw-r--r--spec/functional/assets/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpmbin6494 -> 0 bytes
-rw-r--r--spec/functional/assets/yumrepo/chef_rpm-1.2-1.i686.rpmbin0 -> 2149 bytes
-rw-r--r--spec/functional/assets/yumrepo/chef_rpm-1.2-1.ppc64.rpmbin0 -> 2119 bytes
-rw-r--r--spec/functional/assets/yumrepo/chef_rpm-1.2-1.ppc64le.rpmbin0 -> 2098 bytes
-rw-r--r--spec/functional/assets/yumrepo/chef_rpm-1.2-1.s390x.rpmbin0 -> 2102 bytes
-rw-r--r--spec/functional/assets/yumrepo/chef_rpm-1.2-1.src.rpmbin0 -> 2133 bytes
-rw-r--r--spec/functional/assets/yumrepo/chef_rpm-1.2-1.x86_64.rpmbin0 -> 2113 bytes
-rw-r--r--spec/functional/assets/yumrepo/repodata/313329137b55fd333b2dc66394a6661a2befa6cc535d8460d92a4a78a9c581f0-primary.sqlite.bz2bin2460 -> 0 bytes
-rw-r--r--spec/functional/assets/yumrepo/repodata/31ac4db5d5ac593728fcc26aef82b7b93c4cc4dbec843786b1845b939b658553-other.xml.gzbin413 -> 0 bytes
-rw-r--r--spec/functional/assets/yumrepo/repodata/4632d67cb92636e7575d911c24f0e04d3505a944e97c483abe0c3e73a7c62d33-filelists.sqlite.bz2bin0 -> 1322 bytes
-rw-r--r--spec/functional/assets/yumrepo/repodata/4ac40fa3c6728c1401318e2e20a997436624e83dcf7a5f952b851ef422637773-filelists.sqlite.bz2bin1131 -> 0 bytes
-rw-r--r--spec/functional/assets/yumrepo/repodata/66391e53f0510b98b3f0b79f40ba1048026d9a1ef20905d9c40ba6f5411f3243-primary.xml.gzbin859 -> 0 bytes
-rw-r--r--spec/functional/assets/yumrepo/repodata/74599b793e54d877323837d2d81a1c3c594c44e4335f9528234bb490f7b9b439-other.xml.gzbin0 -> 502 bytes
-rw-r--r--spec/functional/assets/yumrepo/repodata/8b34697595fcc87928e12d24644dda9462c3857bd932861e28bc77ae1f31be16-filelists.xml.gzbin419 -> 0 bytes
-rw-r--r--spec/functional/assets/yumrepo/repodata/a845d418f919d2115ab95a56b2c76f6825ad0d0bede49181a55c04f58995d057-primary.sqlite.bz2bin0 -> 2569 bytes
-rw-r--r--spec/functional/assets/yumrepo/repodata/af9b7cf9ef23bd7b43068d74a460f3b5d06753d638e58e4a0c9edc35bfb9cdc4-other.sqlite.bz2bin0 -> 1115 bytes
-rw-r--r--spec/functional/assets/yumrepo/repodata/b97cca3fe14bcf06c52be4449b6108f7731239ff221111dcce8aada5467f60dc-other.sqlite.bz2bin967 -> 0 bytes
-rw-r--r--spec/functional/assets/yumrepo/repodata/bdb4f5f1492a3b9532f22c43110a81500dd744f23da0aec5c33b2a41317c737d-filelists.xml.gzbin0 -> 529 bytes
-rw-r--r--spec/functional/assets/yumrepo/repodata/c10d1d34ce99e02f12ec96ef68360543ab1bb7c3cb81a4a2bf78df7d8597e9df-primary.xml.gzbin0 -> 966 bytes
-rw-r--r--spec/functional/assets/yumrepo/repodata/filelists.xml.gzbin0 -> 773 bytes
-rw-r--r--spec/functional/assets/yumrepo/repodata/other.xml.gzbin0 -> 742 bytes
-rw-r--r--spec/functional/assets/yumrepo/repodata/primary.xml.gzbin0 -> 1459 bytes
-rw-r--r--spec/functional/assets/yumrepo/repodata/repomd.xml72
-rw-r--r--spec/functional/resource/dnf_package_spec.rb230
-rw-r--r--spec/functional/resource/yum_package_spec.rb949
-rw-r--r--spec/spec_helper.rb10
-rw-r--r--spec/support/platform_helpers.rb20
-rw-r--r--spec/unit/provider/package/yum/python_helper_spec.rb29
-rw-r--r--spec/unit/provider/package/yum/yum_cache_spec.rb90
-rw-r--r--spec/unit/provider/package/yum_spec.rb2294
-rw-r--r--spec/unit/provider_resolver_spec.rb8
63 files changed, 3223 insertions, 3494 deletions
diff --git a/lib/chef/provider/package.rb b/lib/chef/provider/package.rb
index 9bfe94d5d0..0011efbcf4 100644
--- a/lib/chef/provider/package.rb
+++ b/lib/chef/provider/package.rb
@@ -1,6 +1,6 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2017, Chef Software Inc.
+# Copyright:: Copyright 2008-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -220,7 +220,12 @@ class Chef
end
def action_lock
- unless package_locked(new_resource.package_name, new_resource.version)
+ packages_locked = if respond_to?(:packages_all_locked?, true)
+ packages_all_locked?(Array(new_resource.package_name), Array(new_resource.version))
+ else
+ package_locked(new_resource.package_name, new_resource.version)
+ end
+ unless packages_locked
description = new_resource.version ? "version #{new_resource.version} of " : ""
converge_by("lock #{description}package #{current_resource.package_name}") do
multipackage_api_adapter(current_resource.package_name, new_resource.version) do |name, version|
@@ -234,7 +239,12 @@ class Chef
end
def action_unlock
- if package_locked(new_resource.package_name, new_resource.version)
+ packages_unlocked = if respond_to?(:packages_all_unlocked?, true)
+ packages_all_unlocked?(Array(new_resource.package_name), Array(new_resource.version))
+ else
+ !package_locked(new_resource.package_name, new_resource.version)
+ end
+ unless packages_unlocked
description = new_resource.version ? "version #{new_resource.version} of " : ""
converge_by("unlock #{description}package #{current_resource.package_name}") do
multipackage_api_adapter(current_resource.package_name, new_resource.version) do |name, version|
@@ -247,6 +257,7 @@ class Chef
end
end
+ # for multipackage just implement packages_all_[un]locked? properly and omit implementing this API
def package_locked(name, version)
raise Chef::Exceptions::UnsupportedAction, "#{self} has no way to detect if package is locked"
end
diff --git a/lib/chef/provider/package/yum.rb b/lib/chef/provider/package/yum.rb
index 4151b88242..805a74d013 100644
--- a/lib/chef/provider/package/yum.rb
+++ b/lib/chef/provider/package/yum.rb
@@ -1,6 +1,5 @@
-
-# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2017, Chef Software Inc.
+#
+# Copyright:: Copyright 2016-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,483 +15,264 @@
# limitations under the License.
#
-require "chef/config"
require "chef/provider/package"
require "chef/resource/yum_package"
+require "chef/mixin/which"
+require "chef/mixin/shell_out"
require "chef/mixin/get_source_from_package"
-require "chef/provider/package/yum/rpm_utils"
+require "chef/provider/package/yum/python_helper"
+require "chef/provider/package/yum/version"
+# the stubs in the YumCache class are still an external API
require "chef/provider/package/yum/yum_cache"
class Chef
class Provider
class Package
class Yum < Chef::Provider::Package
+ extend Chef::Mixin::Which
+ extend Chef::Mixin::ShellOut
include Chef::Mixin::GetSourceFromPackage
- provides :package, platform_family: %w{rhel fedora amazon}
- provides :yum_package, os: "linux"
-
- # Multipackage API
allow_nils
use_multipackage_api
use_package_name_for_source
- # Overload the Package provider to keep track of the YumCache
- def initialize(new_resource, run_context)
- super
+ provides :package, platform_family: %w{fedora amazon rhel}
+
+ provides :yum_package
- @yum = YumCache.instance
- @yum.yum_binary = yum_binary
+ #
+ # Most of the magic in this class happens in the python helper script. The ruby side of this
+ # provider knows only enough to translate Chef-style new_resource name+package+version into
+ # a request to the python side. The python side is then responsible for knowing everything
+ # about RPMs and what is installed and what is available. The ruby side of this class should
+ # remain a lightweight translation layer to translate Chef requests into RPC requests to
+ # python. This class knows nothing about how to compare RPM versions, and does not maintain
+ # any cached state of installed/available versions and should be kept that way.
+ #
+ def python_helper
+ @python_helper ||= PythonHelper.instance
end
- # @see Chef::Provider::Package#check_resource_semantics!
- def check_resource_semantics!
- super
+ def load_current_resource
+ flushcache if new_resource.flush_cache[:before]
- if !new_resource.version.nil? && package_name_array.length != new_version_array.length
- raise Chef::Exceptions::InvalidResourceSpecification, "Please provide a version for each package. Use `nil` for default version."
- end
+ @current_resource = Chef::Resource::YumPackage.new(new_resource.name)
+ current_resource.package_name(new_resource.package_name)
+ current_resource.version(get_current_versions)
- if !new_resource.arch.nil? && package_name_array.length != safe_arch_array.length
- raise Chef::Exceptions::InvalidResourceSpecification, "Please provide an architecture for each package. Use `nil` for default architecture."
- end
+ current_resource
end
- # @see Chef::Provider#define_resource_requirements
def define_resource_requirements
- super
-
- # Ensure that the source file (if specified) is present on the file system
requirements.assert(:install, :upgrade, :remove, :purge) do |a|
a.assertion { !new_resource.source || ::File.exist?(new_resource.source) }
a.failure_message Chef::Exceptions::Package, "Package #{new_resource.package_name} not found: #{new_resource.source}"
a.whyrun "assuming #{new_resource.source} would have previously been created"
end
- end
-
- # @see Chef::Provider#load_current_resource
- def load_current_resource
- @yum.reload if flush_cache[:before]
- manage_extra_repo_control
-
- if new_resource.source
- query_source_file
- else
- # At this point package_name could be:
- #
- # 1) a package name, eg: "foo"
- # 2) a package name.arch, eg: "foo.i386"
- # 3) or a dependency, eg: "foo >= 1.1"
- #
- # In the third case, we want to convert those dependency strings into
- # packages that we can actually install
- convert_dependency_strings_into_packages
-
- # Fill out the rest of the details by querying the Yum Cache
- query_yum_cache
- end
- @current_resource = Chef::Resource::YumPackage.new(new_resource.name)
- current_resource.package_name(new_resource.package_name)
- current_resource.version(@installed_version)
- current_resource
+ super
end
- # @see Chef::Provider::Package#package_locked
- def package_locked(name, version)
- locked = shell_out_with_timeout!("yum versionlock")
- locked_packages = locked.stdout.each_line.map do |line|
- line.sub(/-[^-]*-[^-]*$/, "").split(":").last.strip
+ def candidate_version
+ package_name_array.each_with_index.map do |pkg, i|
+ available_version(i).version_with_arch
end
- name.all? { |n| locked_packages.include? n }
end
- #
- # Package Action Classes
- #
-
- # @see Chef::Provider::Package#install_package
- def install_package(name, version)
- if new_resource.source
- yum_command("-d0 -e0 -y#{expand_options(new_resource.options)} localinstall #{new_resource.source}")
- else
- install_remote_package(name, version)
+ def get_current_versions
+ package_name_array.each_with_index.map do |pkg, i|
+ installed_version(i).version_with_arch
end
-
- flush_cache[:after] ? @yum.reload : @yum.reload_installed
end
- # @see Chef::Provider::Package#upgrade_package
- def upgrade_package(name, version)
- install_package(name, version)
- end
+ def install_package(names, versions)
+ method = nil
+ methods = []
+ names.each_with_index do |n, i|
+ next if n.nil?
- # @see Chef::Provider::Package#remove_package
- def remove_package(name, version)
- remove_str = full_package_name(name, version).join(" ")
- yum_command("-d0 -e0 -y#{expand_options(new_resource.options)} remove #{remove_str}")
+ av = available_version(i)
- flush_cache[:after] ? @yum.reload : @yum.reload_installed
- end
+ name = av.name # resolve the name via the available/candidate version
- # @see Chef::Provider::Package#purge_package
- def purge_package(name, version)
- remove_package(name, version)
- end
+ iv = python_helper.package_query(:whatinstalled, name)
- # @see Chef::Provider::Package#lock_package
- def lock_package(name, version)
- lock_str = full_package_name(name, as_array(name).map { nil }).join(" ")
- yum_command("-d0 -e0 -y#{expand_options(new_resource.options)} versionlock add #{lock_str}")
- end
+ method = "install"
- # @see Chef::Provider::Package#unlock_package
- def unlock_package(name, version)
- unlock_str = full_package_name(name, as_array(name).map { nil }).join(" ")
- yum_command("-d0 -e0 -y#{expand_options(new_resource.options)} versionlock delete #{unlock_str}")
- end
-
- private
-
- #
- # System Level Yum Operations
- #
-
- def yum_binary
- @yum_binary ||=
- begin
- yum_binary = new_resource.yum_binary if new_resource.is_a?(Chef::Resource::YumPackage)
- yum_binary ||= ::File.exist?("/usr/bin/yum-deprecated") ? "yum-deprecated" : "yum"
+ # If this is a package like the kernel that can be installed multiple times, we'll skip over this logic
+ if new_resource.allow_downgrade && version_gt?(iv.version_with_arch, av.version_with_arch) && !python_helper.install_only_packages(name)
+ # We allow downgrading only in the evenit of single-package
+ # rules where the user explicitly allowed it
+ method = "downgrade"
end
- end
- def version_compare(v1, v2)
- RPMVersion.parse(v1) <=> RPMVersion.parse(v2)
- end
+ methods << method
+ end
- # Enable or disable YumCache extra_repo_control
- def manage_extra_repo_control
- if new_resource.options
- repo_control = []
- new_resource.options.each do |opt|
- repo_control << opt if opt =~ /--(enable|disable)repo=.+/
- end
+ # We could split this up into two commands if we wanted to, but
+ # for now, just don't support this.
+ if methods.uniq.length > 1
+ raise Chef::Exceptions::Package, "Multipackage rule has a mix of upgrade and downgrade packages. Cannot proceed."
+ end
- if !repo_control.empty?
- @yum.enable_extra_repo_control(repo_control.join(" "))
- else
- @yum.disable_extra_repo_control
- end
+ if new_resource.source
+ yum(options, "-y #{method}", new_resource.source)
else
- @yum.disable_extra_repo_control
+ resolved_names = names.each_with_index.map { |name, i| available_version(i).to_s unless name.nil? }
+ yum(options, "-y #{method}", resolved_names)
end
+ flushcache
end
- # Query the Yum cache for information about potential packages
- def query_yum_cache
- installed_versions = []
- candidate_versions = []
-
- package_name_array.each_with_index do |n, idx|
- pkg_name, eval_pkg_arch = parse_arch(n)
+ # yum upgrade does not work on uninstalled packaged, while install will upgrade
+ alias upgrade_package install_package
- # Defer to the arch property for the desired package architecture
- pkg_arch = safe_arch_array[idx] || eval_pkg_arch
- set_package_name(idx, pkg_name)
- set_package_arch(idx, pkg_arch)
+ def remove_package(names, versions)
+ resolved_names = names.each_with_index.map { |name, i| installed_version(i).to_s unless name.nil? }
+ yum(options, "-y remove", resolved_names)
+ flushcache
+ end
- Chef::Log.debug("#{new_resource} checking yum info for #{yum_syntax(n, nil, pkg_arch)}")
- installed_versions << iv = @yum.installed_version(pkg_name, pkg_arch)
- candidate_versions << cv = @yum.candidate_version(pkg_name, pkg_arch)
+ alias purge_package remove_package
- Chef::Log.debug("Found Yum package: #{pkg_name} installed version: #{iv || '(none)'} candidate version: #{cv || '(none)'}")
- end
+ action :flush_cache do
+ flushcache
+ end
- @installed_version = installed_versions.length > 1 ? installed_versions : installed_versions[0]
- @candidate_version = candidate_versions.length > 1 ? candidate_versions : candidate_versions[0]
+ # NB: the yum_package provider manages individual single packages, please do not submit issues or PRs to try to add wildcard
+ # support to lock / unlock. The best solution is to write an execute resource which does a not_if `yum versionlock | grep '^pattern`` kind of approach
+ def lock_package(names, versions)
+ yum("-d0 -e0 -y", options, "versionlock add", resolved_package_lock_names(names))
end
- # Query the provided source file for the package name and version
- def query_source_file
- Chef::Log.debug("#{new_resource} checking rpm status")
- shell_out_with_timeout!("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE} %{ARCH}\n' #{new_resource.source}", timeout: Chef::Config[:yum_timeout]).stdout.each_line do |line|
- case line
- when /^(\S+)\s(\S+)\s(\S+)$/
- n = $1
- v = $2
- a = $3
-
- unless new_resource.package_name == n
- Chef::Log.debug("#{new_resource} updating package_name from #{new_resource.package_name} to #{n} (per #{new_resource.source})")
- new_resource.package_name(n)
- end
+ # NB: the yum_package provider manages individual single packages, please do not submit issues or PRs to try to add wildcard
+ # support to lock / unlock. The best solution is to write an execute resource which does a only_if `yum versionlock | grep '^pattern`` kind of approach
+ def unlock_package(names, versions)
+ # yum versionlock delete on rhel6 needs the glob nonsense in the following command
+ yum("-d0 -e0 -y", options, "versionlock delete", resolved_package_lock_names(names).map { |n| "'*:#{n}-*'" })
+ end
- unless new_resource.version == v
- Chef::Log.debug("#{new_resource} updating version from #{new_resource.version} to #{v} (per #{new_resource.source})")
- new_resource.version(v)
- end
+ private
- unless new_resource.arch == a
- Chef::Log.debug("#{new_resource} updating architecture from #{new_resource.arch} to #{a} (per #{new_resource.source})")
- new_resource.arch(a)
+ # this will resolve things like `/usr/bin/perl` or virtual packages like `mysql` -- it will not work (well? at all?) with globs that match multiple packages
+ def resolved_package_lock_names(names)
+ names.each_with_index.map do |name, i|
+ if !name.nil?
+ if installed_version(i).version.nil?
+ available_version(i).name
+ else
+ installed_version(i).name
end
end
end
-
- @installed_version = @yum.installed_version(new_resource.package_name, new_resource.arch)
- @candidate_version = new_resource.version
end
- def yum_command(command)
- command = "#{yum_binary} #{command}"
- Chef::Log.debug("#{new_resource}: yum command: \"#{command}\"")
- status = shell_out_with_timeout(command, timeout: Chef::Config[:yum_timeout])
-
- # This is fun: rpm can encounter errors in the %post/%postun scripts which aren't
- # considered fatal - meaning the rpm is still successfully installed. These issue
- # cause yum to emit a non fatal warning but still exit(1). As there's currently no
- # way to suppress this behavior and an exit(1) will break a Chef run we make an
- # effort to trap these and re-run the same install command - it will either fail a
- # second time or succeed.
- #
- # A cleaner solution would have to be done in python and better hook into
- # yum/rpm to handle exceptions as we see fit.
- if status.exitstatus == 1
- status.stdout.each_line do |l|
- # rpm-4.4.2.3 lib/psm.c line 2182
- next unless l =~ /^error: %(post|postun)\(.*\) scriptlet failed, exit status \d+$/
- Chef::Log.warn("#{new_resource} caught non-fatal scriptlet issue: \"#{l}\". Can't trust yum exit status " \
- "so running install again to verify.")
- status = shell_out_with_timeout(command, timeout: Chef::Config[:yum_timeout])
- break
+ def locked_packages
+ @locked_packages ||=
+ begin
+ locked = shell_out_with_timeout!("yum versionlock list")
+ locked.stdout.each_line.map do |line|
+ line.sub(/-[^-]*-[^-]*$/, "").split(":").last.strip
+ end
end
- end
-
- if status.exitstatus > 0
- command_output = "STDOUT: #{status.stdout}\nSTDERR: #{status.stderr}"
- raise Chef::Exceptions::Exec, "#{command} returned #{status.exitstatus}:\n#{command_output}"
- end
end
- def install_remote_package(name, version)
- # Work around yum not exiting with an error if a package doesn't exist for CHEF-2062.
- all_avail = as_array(name).zip(as_array(version), safe_arch_array).any? do |n, v, a|
- @yum.version_available?(n, v, a)
- end
-
- method = log_method = nil
- methods = []
- if all_avail
- # More Yum fun:
- #
- # yum install of an old name+version will exit(1)
- # yum install of an old name+version+arch will exit(0) for some reason
- #
- # Some packages can be installed multiple times like the kernel
- as_array(name).zip(current_version_array, as_array(version), safe_arch_array).each do |n, cv, v, a|
- next if n.nil?
-
- method = "install"
- log_method = "installing"
-
- unless @yum.allow_multi_install.include?(n)
- if RPMVersion.parse(cv) > RPMVersion.parse(v)
- # We allow downgrading only in the evenit of single-package
- # rules where the user explicitly allowed it
- if allow_downgrade
- method = "downgrade"
- log_method = "downgrading"
- else
- # we bail like yum when the package is older
- raise Chef::Exceptions::Package, "Installed package #{yum_syntax(n, cv, a)} is newer " \
- "than candidate package #{yum_syntax(n, v, a)}"
- end
- end
- end
- # methods don't count for packages we won't be touching
- next if RPMVersion.parse(cv) == RPMVersion.parse(v)
- methods << method
- end
+ def packages_all_locked?(names, versions)
+ resolved_package_lock_names(names).all? { |n| locked_packages.include? n }
+ end
- # We could split this up into two commands if we wanted to, but
- # for now, just don't support this.
- if methods.uniq.length > 1
- raise Chef::Exceptions::Package, "Multipackage rule #{name} has a mix of upgrade and downgrade packages. Cannot proceed."
- end
+ def packages_all_unlocked?(names, versions)
+ !resolved_package_lock_names(names).any? { |n| locked_packages.include? n }
+ end
- repos = []
- pkg_string_bits = []
- as_array(name).zip(current_version_array, as_array(version), safe_arch_array).each do |n, cv, v, a|
- next if n.nil?
- next if v == cv
- s = yum_syntax(n, v, a)
- repo = @yum.package_repository(n, v, a)
- repos << "#{s} from #{repo} repository"
- pkg_string_bits << s
- end
- pkg_string = pkg_string_bits.join(" ")
- Chef::Log.info("#{new_resource} #{log_method} #{repos.join(' ')}")
- yum_command("-d0 -e0 -y#{expand_options(new_resource.options)} #{method} #{pkg_string}")
- else
- raise Chef::Exceptions::Package, "Version #{version} of #{name} not found. Did you specify both version " \
- "and release? (version-release, e.g. 1.84-10.fc6)"
- end
+ def version_gt?(v1, v2)
+ return false if v1.nil? || v2.nil?
+ python_helper.compare_versions(v1, v2) == 1
end
- # Allow for foo.x86_64 style package_name like yum uses in it's output
- def parse_arch(package_name)
- if package_name =~ /^(.*)\.(.*)$/
- new_package_name = $1
- new_arch = $2
- # foo.i386 and foo.beta1 are both valid package names or expressions of an arch.
- # Ensure we don't have an existing package matching package_name, then ensure we at
- # least have a match for the new_package+new_arch before we overwrite. If neither
- # then fall through to standard package handling.
- old_installed = @yum.installed_version(package_name)
- old_candidate = @yum.candidate_version(package_name)
- new_installed = @yum.installed_version(new_package_name, new_arch)
- new_candidate = @yum.candidate_version(new_package_name, new_arch)
- if (old_installed.nil? && old_candidate.nil?) && (new_installed || new_candidate)
- Chef::Log.debug("Parsed out arch #{new_arch}, new package name is #{new_package_name}")
- return new_package_name, new_arch
- end
- end
- [package_name, nil]
+ def version_equals?(v1, v2)
+ return false if v1.nil? || v2.nil?
+ python_helper.compare_versions(v1, v2) == 0
end
- #
- # Dependency String Handling
- #
+ def version_compare(v1, v2)
+ return false if v1.nil? || v2.nil?
+ python_helper.compare_versions(v1, v2)
+ end
- # Iterate through the list of package_names given to us by the user and
- # see if any of them are in the depenency format ("foo >= 1.1"). Modify
- # the list of packages and versions to incorporate those values.
- def convert_dependency_strings_into_packages
- package_name_array.each_with_index do |n, index|
- next if @yum.package_available?(n)
- # If they aren't in the installed packages they could be a dependency.
- dep = parse_dependency(n, new_version_array[index])
- if dep
- if new_resource.package_name.is_a?(Array)
- new_resource.package_name(package_name_array - [n] + [dep.first])
- new_resource.version(new_version_array - [new_version_array[index]] + [dep.last]) if dep.last
- else
- new_resource.package_name(dep.first)
- new_resource.version(dep.last) if dep.last
- end
- end
- end
+ # Generate the yum syntax for the package
+ def yum_syntax(name, version, arch)
+ s = name
+ s += "-#{version}" if version
+ s += ".#{arch}" if arch
+ s
end
- # If we don't have the package we could have been passed a 'whatprovides' feature
- #
- # eg: yum install "perl(Config)"
- # yum install "mtr = 2:0.71-3.1"
- # yum install "mtr > 2:0.71"
- #
- # We support resolving these out of the Provides data imported from yum-dump.py and
- # matching them up with an actual package so the standard resource handling can apply.
- #
- # There is currently no support for filename matching.
- #
- # Note: This was largely left alone during the multipackage refactor
- def parse_dependency(name, version)
- # Transform the package_name into a requirement
-
- # If we are passed a version or a version constraint we have to assume it's a requirement first. If it can't be
- # parsed only yum_require.name will be set and new_resource.version will be left intact
- require_string = if version
- "#{name} #{version}"
- else
- # Transform the package_name into a requirement, might contain a version, could just be
- # a match for virtual provides
- name
- end
- yum_require = RPMRequire.parse(require_string)
- # and gather all the packages that have a Provides feature satisfying the requirement.
- # It could be multiple be we can only manage one
- packages = @yum.packages_from_require(yum_require)
-
- if packages.empty?
- # Don't bother if we are just ensuring a package is removed - we don't need Provides data
- actions = Array(new_resource.action)
- unless actions.size == 1 && (actions[0] == :remove || actions[0] == :purge)
- Chef::Log.debug("#{new_resource} couldn't match #{new_resource.package_name} in " \
- "installed Provides, loading available Provides - this may take a moment")
- @yum.reload_provides
- packages = @yum.packages_from_require(yum_require)
+ def resolve_source_to_version_obj
+ shell_out_with_timeout!("rpm -qp --queryformat '%{NAME} %{EPOCH} %{VERSION} %{RELEASE} %{ARCH}\n' #{new_resource.source}").stdout.each_line do |line|
+ # this is another case of committing the sin of doing some lightweight mangling of RPM versions in ruby -- but the output of the rpm command
+ # does not match what the yum library accepts.
+ case line
+ when /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/
+ return Version.new($1, "#{$2 == '(none)' ? '0' : $2}:#{$3}-#{$4}", $5)
end
end
+ end
- unless packages.empty?
- new_package_name = packages.first.name
- new_package_version = packages.first.version.to_s
- debug_msg = "#{name}: Unable to match package '#{name}' but matched #{packages.size} "
- debug_msg << (packages.size == 1 ? "package" : "packages")
- debug_msg << ", selected '#{new_package_name}' version '#{new_package_version}'"
- Chef::Log.debug(debug_msg)
-
- # Ensure it's not the same package under a different architecture
- unique_names = []
- packages.each do |pkg|
- unique_names << "#{pkg.name}-#{pkg.version.evr}"
- end
- unique_names.uniq!
+ # @returns Array<Version>
+ def available_version(index)
+ @available_version ||= []
- if unique_names.size > 1
- Chef::Log.warn("#{new_resource} matched multiple Provides for #{new_resource.package_name} " \
- "but we can only use the first match: #{new_package_name}. Please use a more " \
- "specific version.")
- end
+ @available_version[index] ||= if new_resource.source
+ resolve_source_to_version_obj
+ else
+ python_helper.package_query(:whatavailable, package_name_array[index], version: safe_version_array[index], arch: safe_arch_array[index], options: options)
+ end
- if yum_require.version.to_s.nil?
- new_package_version = nil
- end
-
- [new_package_name, new_package_version]
- end
+ @available_version[index]
end
- #
- # Misc Helpers
- #
+ # @returns Array<Version>
+ def installed_version(index)
+ @installed_version ||= []
+ @installed_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])
+ else
+ python_helper.package_query(:whatinstalled, package_name_array[index], version: safe_version_array[index], arch: safe_arch_array[index])
+ end
+ @installed_version[index]
+ end
- # Given an list of names and versions, generate the full yum syntax package name
- def full_package_name(name, version)
- as_array(name).zip(as_array(version), safe_arch_array).map do |n, v, a|
- yum_syntax(n, v, a)
- end
+ # cache flushing is accomplished by simply restarting the python helper. this produces a roughly
+ # 15% hit to the runtime of installing/removing/upgrading packages. correctly using multipackage
+ # array installs (and the multipackage cookbook) can produce 600% improvements in runtime.
+ def flushcache
+ python_helper.restart
end
- # Generate the yum syntax for the package
- def yum_syntax(name, version, arch)
- s = name
- s += "-#{version}" if version
- s += ".#{arch}" if arch
- s
+ def yum_binary
+ @yum_binary ||=
+ begin
+ yum_binary = new_resource.yum_binary if new_resource.is_a?(Chef::Resource::YumPackage)
+ yum_binary ||= ::File.exist?("/usr/bin/yum-deprecated") ? "yum-deprecated" : "yum"
+ end
end
- # Set the package name correctly based on whether it is a String or Array
- def set_package_name(idx, name)
- if new_resource.package_name.is_a?(String)
- new_resource.package_name(name)
- else
- new_resource.package_name[idx] = name
- end
+ def yum(*args)
+ shell_out_with_timeout!(a_to_s(yum_binary, *args))
end
- # Set the architecture correcly based on whether it is a String or Array
- def set_package_arch(idx, arch)
- if new_resource.package_name.is_a?(String)
- new_resource.arch(arch) unless arch.nil?
+ def safe_version_array
+ if new_resource.version.is_a?(Array)
+ new_resource.version
+ elsif new_resource.version.nil?
+ package_name_array.map { nil }
else
- new_resource.arch ||= []
- new_resource.arch[idx] = arch
+ [ new_resource.version ]
end
end
- # A cousin of package_name_array, return a list of the architectures
- # defined in the resource.
def safe_arch_array
if new_resource.arch.is_a?(Array)
new_resource.arch
@@ -503,13 +283,6 @@ class Chef
end
end
- def flush_cache
- if new_resource.respond_to?("flush_cache")
- new_resource.flush_cache
- else
- { before: false, after: false }
- end
- end
end
end
end
diff --git a/lib/chef/provider/package/yum/python_helper.rb b/lib/chef/provider/package/yum/python_helper.rb
new file mode 100644
index 0000000000..8fac97577b
--- /dev/null
+++ b/lib/chef/provider/package/yum/python_helper.rb
@@ -0,0 +1,221 @@
+#
+# Copyright:: Copyright 2016-2018, Chef Software Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require "chef/mixin/which"
+require "chef/mixin/shell_out"
+require "chef/provider/package/yum/version"
+require "singleton"
+require "timeout"
+
+class Chef
+ class Provider
+ class Package
+ class Yum < Chef::Provider::Package
+ class PythonHelper
+ include Singleton
+ include Chef::Mixin::Which
+ include Chef::Mixin::ShellOut
+
+ attr_accessor :stdin
+ attr_accessor :stdout
+ attr_accessor :stderr
+ attr_accessor :inpipe
+ attr_accessor :outpipe
+ attr_accessor :wait_thr
+
+ YUM_HELPER = ::File.expand_path(::File.join(::File.dirname(__FILE__), "yum_helper.py")).freeze
+
+ def yum_command
+ @yum_command ||= which("python", "python2", "python2.7") do |f|
+ shell_out("#{f} -c 'import yum'").exitstatus == 0
+ end + " #{YUM_HELPER}"
+ end
+
+ def start
+ ENV["PYTHONUNBUFFERED"] = "1"
+ @inpipe, inpipe_write = IO.pipe
+ outpipe_read, @outpipe = IO.pipe
+ @stdin, @stdout, @stderr, @wait_thr = Open3.popen3("#{yum_command} #{outpipe_read.fileno} #{inpipe_write.fileno}", outpipe_read.fileno => outpipe_read, inpipe_write.fileno => inpipe_write, close_others: false)
+ outpipe_read.close
+ inpipe_write.close
+ end
+
+ def reap
+ unless wait_thr.nil?
+ Process.kill("INT", wait_thr.pid) rescue nil
+ begin
+ Timeout.timeout(3) do
+ wait_thr.value # this calls waitpid()
+ end
+ rescue Timeout::Error
+ Process.kill("KILL", wait_thr.pid) rescue nil
+ end
+ stdin.close unless stdin.nil?
+ stdout.close unless stdout.nil?
+ stderr.close unless stderr.nil?
+ inpipe.close unless inpipe.nil?
+ outpipe.close unless outpipe.nil?
+ end
+ end
+
+ def check
+ start if stdin.nil?
+ end
+
+ def compare_versions(version1, version2)
+ query("versioncompare", { "versions" => [version1, version2] }).to_i
+ end
+
+ def install_only_packages(name)
+ query_output = query("installonlypkgs", { "package" => name })
+ if query_output == "False"
+ return false
+ elsif query_output == "True"
+ return true
+ end
+ end
+
+ def options_params(options)
+ options.each_with_object({}) do |opt, h|
+ if opt =~ /--enablerepo=(.+)/
+ $1.split(",").each do |repo|
+ h["enablerepos"] ||= []
+ h["enablerepos"].push(repo)
+ end
+ end
+ if opt =~ /--disablerepo=(.+)/
+ $1.split(",").each do |repo|
+ h["disablerepos"] ||= []
+ h["disablerepos"].push(repo)
+ end
+ end
+ end
+ end
+
+ # @returns 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 }
+ repo_opts = options_params(options || {})
+ parameters.merge!(repo_opts)
+ query_output = query(action, parameters)
+ version = parse_response(query_output.lines.last)
+ Chef::Log.debug "parsed #{version} from python helper"
+ # XXX: for now we restart after every query with an enablerepo/disablerepo to clean the helpers internal state
+ restart unless repo_opts.empty?
+ version
+ end
+
+ def restart
+ reap
+ start
+ end
+
+ 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)
+ Chef::Log.debug "sending '#{json}' to python helper"
+ outpipe.syswrite json + "\n"
+ output = inpipe.sysread(4096).chomp
+ Chef::Log.debug "got '#{output}' from python helper"
+ return output
+ end
+ end
+
+ def build_query(action, parameters)
+ hash = { "action" => action }
+ parameters.each do |param_name, param_value|
+ hash[param_name] = param_value unless param_value.nil?
+ end
+
+ # Special handling for certain action / param combos
+ if [:whatinstalled, :whatavailable].include?(action)
+ add_version(hash, parameters["version"]) unless parameters["version"].nil?
+ end
+
+ FFI_Yajl::Encoder.encode(hash)
+ end
+
+ def parse_response(output)
+ array = output.split.map { |x| x == "nil" ? nil : x }
+ array.each_slice(3).map { |x| Version.new(*x) }.first
+ end
+
+ def drain_fds
+ output = ""
+ fds, = IO.select([stderr, stdout, inpipe], nil, nil, 0)
+ unless fds.nil?
+ fds.each do |fd|
+ output += fd.sysread(4096) rescue ""
+ end
+ end
+ output
+ rescue => e
+ output
+ end
+
+ def with_helper
+ max_retries ||= 5
+ ret = nil
+ Timeout.timeout(600) do
+ check
+ ret = yield
+ end
+ output = drain_fds
+ unless output.empty?
+ Chef::Log.debug "discarding output on stderr/stdout from python helper: #{output}"
+ end
+ ret
+ rescue EOFError, Errno::EPIPE, Timeout::Error, Errno::ESRCH => e
+ output = drain_fds
+ if ( max_retries -= 1 ) > 0
+ unless output.empty?
+ Chef::Log.debug "discarding output on stderr/stdout from python helper: #{output}"
+ end
+ restart
+ retry
+ else
+ raise e if output.empty?
+ raise "yum-helper.py had stderr/stdout output:\n\n#{output}"
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/chef/provider/package/yum/rpm_utils.rb b/lib/chef/provider/package/yum/rpm_utils.rb
index 0709118184..eefc0b95b2 100644
--- a/lib/chef/provider/package/yum/rpm_utils.rb
+++ b/lib/chef/provider/package/yum/rpm_utils.rb
@@ -1,6 +1,6 @@
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software, Inc.
+# Copyright:: Copyright 2008-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,6 +18,15 @@
require "chef/provider/package"
+#
+# BUGGY AND DEPRECATED: This ruby code is known to not match the python implementation for version comparisons.
+# The APIs here should probably be converted to talk to the PythonHelper or just abandonded completely.
+#
+# e.g. this should just use Chef::Provider::Package::Yum::PythonHelper.instance.compare_versions(x,y)
+#
+# The python_helper could be extended to support additional APIs in here to remove the ruby code entirely.
+#
+
class Chef
class Provider
class Package
diff --git a/lib/chef/provider/package/yum/simplejson/LICENSE.txt b/lib/chef/provider/package/yum/simplejson/LICENSE.txt
new file mode 100644
index 0000000000..e05f49c3fd
--- /dev/null
+++ b/lib/chef/provider/package/yum/simplejson/LICENSE.txt
@@ -0,0 +1,79 @@
+simplejson is dual-licensed software. It is available under the terms
+of the MIT license, or the Academic Free License version 2.1. The full
+text of each license agreement is included below. This code is also
+licensed to the Python Software Foundation (PSF) under a Contributor
+Agreement.
+
+MIT License
+===========
+
+Copyright (c) 2006 Bob Ippolito
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+Academic Free License v. 2.1
+============================
+
+Copyright (c) 2006 Bob Ippolito. All rights reserved.
+
+This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following notice immediately following the copyright notice for the Original Work:
+
+Licensed under the Academic Free License version 2.1
+
+1) Grant of Copyright License. Licensor hereby grants You a world-wide, royalty-free, non-exclusive, perpetual, sublicenseable license to do the following:
+
+a) to reproduce the Original Work in copies;
+
+b) to prepare derivative works ("Derivative Works") based upon the Original Work;
+
+c) to distribute copies of the Original Work and Derivative Works to the public;
+
+d) to perform the Original Work publicly; and
+
+e) to display the Original Work publicly.
+
+2) Grant of Patent License. Licensor hereby grants You a world-wide, royalty-free, non-exclusive, perpetual, sublicenseable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, to make, use, sell and offer for sale the Original Work and Derivative Works.
+
+3) Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor hereby agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work, and by publishing the address of that information repository in a notice immediately following the copyright notice that applies to the Original Work.
+
+4) Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior written permission of the Licensor. Nothing in this License shall be deemed to grant any rights to trademarks, copyrights, patents, trade secrets or any other intellectual property of Licensor except as expressly stated herein. No patent license is granted to make, use, sell or offer to sell embodiments of any patent claims other than the licensed claims defined in Section 2. No right is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under different terms from this License any Original Work that Licensor otherwise would have a right to license.
+
+5) This section intentionally omitted.
+
+6) Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work.
+
+7) Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately proceeding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to Original Work is granted hereunder except under this disclaimer.
+
+8) Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to any person for any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to liability for death or personal injury resulting from Licensor's negligence to the extent applicable law prohibits such limitation. Some jurisdictions do not allow the exclusion or limitation of incidental or consequential damages, so this exclusion and limitation may not apply to You.
+
+9) Acceptance and Termination. If You distribute copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. Nothing else but this License (or another written agreement between Licensor and You) grants You permission to create Derivative Works based upon the Original Work or to exercise any of the rights granted in Section 1 herein, and any attempt to do so except under the terms of this License (or another written agreement between Licensor and You) is expressly prohibited by U.S. copyright law, the equivalent laws of other countries, and by international treaty. Therefore, by exercising any of the rights granted to You in Section 1 herein, You indicate Your acceptance of this License and all of its terms and conditions.
+
+10) Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware.
+
+11) Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of the U.S. Copyright Act, 17 U.S.C. § 101 et seq., the equivalent laws of other countries, and international treaty. This section shall survive the termination of this License.
+
+12) Attorneys Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License.
+
+13) Miscellaneous. This License represents the complete agreement concerning the subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable.
+
+14) Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
+
+15) Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You.
+
+This license is Copyright (C) 2003-2004 Lawrence E. Rosen. All rights reserved. Permission is hereby granted to copy and distribute this license without modification. This license may not be modified without the express written permission of its copyright owner.
diff --git a/lib/chef/provider/package/yum/simplejson/__init__.py b/lib/chef/provider/package/yum/simplejson/__init__.py
new file mode 100644
index 0000000000..d5b4d39913
--- /dev/null
+++ b/lib/chef/provider/package/yum/simplejson/__init__.py
@@ -0,0 +1,318 @@
+r"""JSON (JavaScript Object Notation) <http://json.org> is a subset of
+JavaScript syntax (ECMA-262 3rd edition) used as a lightweight data
+interchange format.
+
+:mod:`simplejson` exposes an API familiar to users of the standard library
+:mod:`marshal` and :mod:`pickle` modules. It is the externally maintained
+version of the :mod:`json` library contained in Python 2.6, but maintains
+compatibility with Python 2.4 and Python 2.5 and (currently) has
+significant performance advantages, even without using the optional C
+extension for speedups.
+
+Encoding basic Python object hierarchies::
+
+ >>> import simplejson as json
+ >>> json.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])
+ '["foo", {"bar": ["baz", null, 1.0, 2]}]'
+ >>> print json.dumps("\"foo\bar")
+ "\"foo\bar"
+ >>> print json.dumps(u'\u1234')
+ "\u1234"
+ >>> print json.dumps('\\')
+ "\\"
+ >>> print json.dumps({"c": 0, "b": 0, "a": 0}, sort_keys=True)
+ {"a": 0, "b": 0, "c": 0}
+ >>> from StringIO import StringIO
+ >>> io = StringIO()
+ >>> json.dump(['streaming API'], io)
+ >>> io.getvalue()
+ '["streaming API"]'
+
+Compact encoding::
+
+ >>> import simplejson as json
+ >>> json.dumps([1,2,3,{'4': 5, '6': 7}], separators=(',',':'))
+ '[1,2,3,{"4":5,"6":7}]'
+
+Pretty printing::
+
+ >>> import simplejson as json
+ >>> s = json.dumps({'4': 5, '6': 7}, sort_keys=True, indent=4)
+ >>> print '\n'.join([l.rstrip() for l in s.splitlines()])
+ {
+ "4": 5,
+ "6": 7
+ }
+
+Decoding JSON::
+
+ >>> import simplejson as json
+ >>> obj = [u'foo', {u'bar': [u'baz', None, 1.0, 2]}]
+ >>> json.loads('["foo", {"bar":["baz", null, 1.0, 2]}]') == obj
+ True
+ >>> json.loads('"\\"foo\\bar"') == u'"foo\x08ar'
+ True
+ >>> from StringIO import StringIO
+ >>> io = StringIO('["streaming API"]')
+ >>> json.load(io)[0] == 'streaming API'
+ True
+
+Specializing JSON object decoding::
+
+ >>> import simplejson as json
+ >>> def as_complex(dct):
+ ... if '__complex__' in dct:
+ ... return complex(dct['real'], dct['imag'])
+ ... return dct
+ ...
+ >>> json.loads('{"__complex__": true, "real": 1, "imag": 2}',
+ ... object_hook=as_complex)
+ (1+2j)
+ >>> import decimal
+ >>> json.loads('1.1', parse_float=decimal.Decimal) == decimal.Decimal('1.1')
+ True
+
+Specializing JSON object encoding::
+
+ >>> import simplejson as json
+ >>> def encode_complex(obj):
+ ... if isinstance(obj, complex):
+ ... return [obj.real, obj.imag]
+ ... raise TypeError(repr(o) + " is not JSON serializable")
+ ...
+ >>> json.dumps(2 + 1j, default=encode_complex)
+ '[2.0, 1.0]'
+ >>> json.JSONEncoder(default=encode_complex).encode(2 + 1j)
+ '[2.0, 1.0]'
+ >>> ''.join(json.JSONEncoder(default=encode_complex).iterencode(2 + 1j))
+ '[2.0, 1.0]'
+
+
+Using simplejson.tool from the shell to validate and pretty-print::
+
+ $ echo '{"json":"obj"}' | python -m simplejson.tool
+ {
+ "json": "obj"
+ }
+ $ echo '{ 1.2:3.4}' | python -m simplejson.tool
+ Expecting property name: line 1 column 2 (char 2)
+"""
+__version__ = '2.0.9'
+__all__ = [
+ 'dump', 'dumps', 'load', 'loads',
+ 'JSONDecoder', 'JSONEncoder',
+]
+
+__author__ = 'Bob Ippolito <bob@redivi.com>'
+
+from decoder import JSONDecoder
+from encoder import JSONEncoder
+
+_default_encoder = JSONEncoder(
+ skipkeys=False,
+ ensure_ascii=True,
+ check_circular=True,
+ allow_nan=True,
+ indent=None,
+ separators=None,
+ encoding='utf-8',
+ default=None,
+)
+
+def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
+ allow_nan=True, cls=None, indent=None, separators=None,
+ encoding='utf-8', default=None, **kw):
+ """Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
+ ``.write()``-supporting file-like object).
+
+ If ``skipkeys`` is true then ``dict`` keys that are not basic types
+ (``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
+ will be skipped instead of raising a ``TypeError``.
+
+ If ``ensure_ascii`` is false, then the some chunks written to ``fp``
+ may be ``unicode`` instances, subject to normal Python ``str`` to
+ ``unicode`` coercion rules. Unless ``fp.write()`` explicitly
+ understands ``unicode`` (as in ``codecs.getwriter()``) this is likely
+ to cause an error.
+
+ If ``check_circular`` is false, then the circular reference check
+ for container types will be skipped and a circular reference will
+ result in an ``OverflowError`` (or worse).
+
+ If ``allow_nan`` is false, then it will be a ``ValueError`` to
+ serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``)
+ in strict compliance of the JSON specification, instead of using the
+ JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
+
+ If ``indent`` is a non-negative integer, then JSON array elements and object
+ members will be pretty-printed with that indent level. An indent level
+ of 0 will only insert newlines. ``None`` is the most compact representation.
+
+ If ``separators`` is an ``(item_separator, dict_separator)`` tuple
+ then it will be used instead of the default ``(', ', ': ')`` separators.
+ ``(',', ':')`` is the most compact JSON representation.
+
+ ``encoding`` is the character encoding for str instances, default is UTF-8.
+
+ ``default(obj)`` is a function that should return a serializable version
+ of obj or raise TypeError. The default simply raises TypeError.
+
+ To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
+ ``.default()`` method to serialize additional types), specify it with
+ the ``cls`` kwarg.
+
+ """
+ # cached encoder
+ if (not skipkeys and ensure_ascii and
+ check_circular and allow_nan and
+ cls is None and indent is None and separators is None and
+ encoding == 'utf-8' and default is None and not kw):
+ iterable = _default_encoder.iterencode(obj)
+ else:
+ if cls is None:
+ cls = JSONEncoder
+ iterable = cls(skipkeys=skipkeys, ensure_ascii=ensure_ascii,
+ check_circular=check_circular, allow_nan=allow_nan, indent=indent,
+ separators=separators, encoding=encoding,
+ default=default, **kw).iterencode(obj)
+ # could accelerate with writelines in some versions of Python, at
+ # a debuggability cost
+ for chunk in iterable:
+ fp.write(chunk)
+
+
+def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
+ allow_nan=True, cls=None, indent=None, separators=None,
+ encoding='utf-8', default=None, **kw):
+ """Serialize ``obj`` to a JSON formatted ``str``.
+
+ If ``skipkeys`` is false then ``dict`` keys that are not basic types
+ (``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
+ will be skipped instead of raising a ``TypeError``.
+
+ If ``ensure_ascii`` is false, then the return value will be a
+ ``unicode`` instance subject to normal Python ``str`` to ``unicode``
+ coercion rules instead of being escaped to an ASCII ``str``.
+
+ If ``check_circular`` is false, then the circular reference check
+ for container types will be skipped and a circular reference will
+ result in an ``OverflowError`` (or worse).
+
+ If ``allow_nan`` is false, then it will be a ``ValueError`` to
+ serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``) in
+ strict compliance of the JSON specification, instead of using the
+ JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
+
+ If ``indent`` is a non-negative integer, then JSON array elements and
+ object members will be pretty-printed with that indent level. An indent
+ level of 0 will only insert newlines. ``None`` is the most compact
+ representation.
+
+ If ``separators`` is an ``(item_separator, dict_separator)`` tuple
+ then it will be used instead of the default ``(', ', ': ')`` separators.
+ ``(',', ':')`` is the most compact JSON representation.
+
+ ``encoding`` is the character encoding for str instances, default is UTF-8.
+
+ ``default(obj)`` is a function that should return a serializable version
+ of obj or raise TypeError. The default simply raises TypeError.
+
+ To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
+ ``.default()`` method to serialize additional types), specify it with
+ the ``cls`` kwarg.
+
+ """
+ # cached encoder
+ if (not skipkeys and ensure_ascii and
+ check_circular and allow_nan and
+ cls is None and indent is None and separators is None and
+ encoding == 'utf-8' and default is None and not kw):
+ return _default_encoder.encode(obj)
+ if cls is None:
+ cls = JSONEncoder
+ return cls(
+ skipkeys=skipkeys, ensure_ascii=ensure_ascii,
+ check_circular=check_circular, allow_nan=allow_nan, indent=indent,
+ separators=separators, encoding=encoding, default=default,
+ **kw).encode(obj)
+
+
+_default_decoder = JSONDecoder(encoding=None, object_hook=None)
+
+
+def load(fp, encoding=None, cls=None, object_hook=None, parse_float=None,
+ parse_int=None, parse_constant=None, **kw):
+ """Deserialize ``fp`` (a ``.read()``-supporting file-like object containing
+ a JSON document) to a Python object.
+
+ If the contents of ``fp`` is encoded with an ASCII based encoding other
+ than utf-8 (e.g. latin-1), then an appropriate ``encoding`` name must
+ be specified. Encodings that are not ASCII based (such as UCS-2) are
+ not allowed, and should be wrapped with
+ ``codecs.getreader(fp)(encoding)``, or simply decoded to a ``unicode``
+ object and passed to ``loads()``
+
+ ``object_hook`` is an optional function that will be called with the
+ result of any object literal decode (a ``dict``). The return value of
+ ``object_hook`` will be used instead of the ``dict``. This feature
+ can be used to implement custom decoders (e.g. JSON-RPC class hinting).
+
+ To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
+ kwarg.
+
+ """
+ return loads(fp.read(),
+ encoding=encoding, cls=cls, object_hook=object_hook,
+ parse_float=parse_float, parse_int=parse_int,
+ parse_constant=parse_constant, **kw)
+
+
+def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None,
+ parse_int=None, parse_constant=None, **kw):
+ """Deserialize ``s`` (a ``str`` or ``unicode`` instance containing a JSON
+ document) to a Python object.
+
+ If ``s`` is a ``str`` instance and is encoded with an ASCII based encoding
+ other than utf-8 (e.g. latin-1) then an appropriate ``encoding`` name
+ must be specified. Encodings that are not ASCII based (such as UCS-2)
+ are not allowed and should be decoded to ``unicode`` first.
+
+ ``object_hook`` is an optional function that will be called with the
+ result of any object literal decode (a ``dict``). The return value of
+ ``object_hook`` will be used instead of the ``dict``. This feature
+ can be used to implement custom decoders (e.g. JSON-RPC class hinting).
+
+ ``parse_float``, if specified, will be called with the string
+ of every JSON float to be decoded. By default this is equivalent to
+ float(num_str). This can be used to use another datatype or parser
+ for JSON floats (e.g. decimal.Decimal).
+
+ ``parse_int``, if specified, will be called with the string
+ of every JSON int to be decoded. By default this is equivalent to
+ int(num_str). This can be used to use another datatype or parser
+ for JSON integers (e.g. float).
+
+ ``parse_constant``, if specified, will be called with one of the
+ following strings: -Infinity, Infinity, NaN, null, true, false.
+ This can be used to raise an exception if invalid JSON numbers
+ are encountered.
+
+ To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
+ kwarg.
+
+ """
+ if (cls is None and encoding is None and object_hook is None and
+ parse_int is None and parse_float is None and
+ parse_constant is None and not kw):
+ return _default_decoder.decode(s)
+ if cls is None:
+ cls = JSONDecoder
+ if object_hook is not None:
+ kw['object_hook'] = object_hook
+ if parse_float is not None:
+ kw['parse_float'] = parse_float
+ if parse_int is not None:
+ kw['parse_int'] = parse_int
+ if parse_constant is not None:
+ kw['parse_constant'] = parse_constant
+ return cls(encoding=encoding, **kw).decode(s)
diff --git a/lib/chef/provider/package/yum/simplejson/__init__.pyc b/lib/chef/provider/package/yum/simplejson/__init__.pyc
new file mode 100644
index 0000000000..10679d3b04
--- /dev/null
+++ b/lib/chef/provider/package/yum/simplejson/__init__.pyc
Binary files differ
diff --git a/lib/chef/provider/package/yum/simplejson/decoder.py b/lib/chef/provider/package/yum/simplejson/decoder.py
new file mode 100644
index 0000000000..d921ce0b97
--- /dev/null
+++ b/lib/chef/provider/package/yum/simplejson/decoder.py
@@ -0,0 +1,354 @@
+"""Implementation of JSONDecoder
+"""
+import re
+import sys
+import struct
+
+from simplejson.scanner import make_scanner
+try:
+ from simplejson._speedups import scanstring as c_scanstring
+except ImportError:
+ c_scanstring = None
+
+__all__ = ['JSONDecoder']
+
+FLAGS = re.VERBOSE | re.MULTILINE | re.DOTALL
+
+def _floatconstants():
+ _BYTES = '7FF80000000000007FF0000000000000'.decode('hex')
+ if sys.byteorder != 'big':
+ _BYTES = _BYTES[:8][::-1] + _BYTES[8:][::-1]
+ nan, inf = struct.unpack('dd', _BYTES)
+ return nan, inf, -inf
+
+NaN, PosInf, NegInf = _floatconstants()
+
+
+def linecol(doc, pos):
+ lineno = doc.count('\n', 0, pos) + 1
+ if lineno == 1:
+ colno = pos
+ else:
+ colno = pos - doc.rindex('\n', 0, pos)
+ return lineno, colno
+
+
+def errmsg(msg, doc, pos, end=None):
+ # Note that this function is called from _speedups
+ lineno, colno = linecol(doc, pos)
+ if end is None:
+ #fmt = '{0}: line {1} column {2} (char {3})'
+ #return fmt.format(msg, lineno, colno, pos)
+ fmt = '%s: line %d column %d (char %d)'
+ return fmt % (msg, lineno, colno, pos)
+ endlineno, endcolno = linecol(doc, end)
+ #fmt = '{0}: line {1} column {2} - line {3} column {4} (char {5} - {6})'
+ #return fmt.format(msg, lineno, colno, endlineno, endcolno, pos, end)
+ fmt = '%s: line %d column %d - line %d column %d (char %d - %d)'
+ return fmt % (msg, lineno, colno, endlineno, endcolno, pos, end)
+
+
+_CONSTANTS = {
+ '-Infinity': NegInf,
+ 'Infinity': PosInf,
+ 'NaN': NaN,
+}
+
+STRINGCHUNK = re.compile(r'(.*?)(["\\\x00-\x1f])', FLAGS)
+BACKSLASH = {
+ '"': u'"', '\\': u'\\', '/': u'/',
+ 'b': u'\b', 'f': u'\f', 'n': u'\n', 'r': u'\r', 't': u'\t',
+}
+
+DEFAULT_ENCODING = "utf-8"
+
+def py_scanstring(s, end, encoding=None, strict=True, _b=BACKSLASH, _m=STRINGCHUNK.match):
+ """Scan the string s for a JSON string. End is the index of the
+ character in s after the quote that started the JSON string.
+ Unescapes all valid JSON string escape sequences and raises ValueError
+ on attempt to decode an invalid string. If strict is False then literal
+ control characters are allowed in the string.
+
+ Returns a tuple of the decoded string and the index of the character in s
+ after the end quote."""
+ if encoding is None:
+ encoding = DEFAULT_ENCODING
+ chunks = []
+ _append = chunks.append
+ begin = end - 1
+ while 1:
+ chunk = _m(s, end)
+ if chunk is None:
+ raise ValueError(
+ errmsg("Unterminated string starting at", s, begin))
+ end = chunk.end()
+ content, terminator = chunk.groups()
+ # Content is contains zero or more unescaped string characters
+ if content:
+ if not isinstance(content, unicode):
+ content = unicode(content, encoding)
+ _append(content)
+ # Terminator is the end of string, a literal control character,
+ # or a backslash denoting that an escape sequence follows
+ if terminator == '"':
+ break
+ elif terminator != '\\':
+ if strict:
+ msg = "Invalid control character %r at" % (terminator,)
+ #msg = "Invalid control character {0!r} at".format(terminator)
+ raise ValueError(errmsg(msg, s, end))
+ else:
+ _append(terminator)
+ continue
+ try:
+ esc = s[end]
+ except IndexError:
+ raise ValueError(
+ errmsg("Unterminated string starting at", s, begin))
+ # If not a unicode escape sequence, must be in the lookup table
+ if esc != 'u':
+ try:
+ char = _b[esc]
+ except KeyError:
+ msg = "Invalid \\escape: " + repr(esc)
+ raise ValueError(errmsg(msg, s, end))
+ end += 1
+ else:
+ # Unicode escape sequence
+ esc = s[end + 1:end + 5]
+ next_end = end + 5
+ if len(esc) != 4:
+ msg = "Invalid \\uXXXX escape"
+ raise ValueError(errmsg(msg, s, end))
+ uni = int(esc, 16)
+ # Check for surrogate pair on UCS-4 systems
+ if 0xd800 <= uni <= 0xdbff and sys.maxunicode > 65535:
+ msg = "Invalid \\uXXXX\\uXXXX surrogate pair"
+ if not s[end + 5:end + 7] == '\\u':
+ raise ValueError(errmsg(msg, s, end))
+ esc2 = s[end + 7:end + 11]
+ if len(esc2) != 4:
+ raise ValueError(errmsg(msg, s, end))
+ uni2 = int(esc2, 16)
+ uni = 0x10000 + (((uni - 0xd800) << 10) | (uni2 - 0xdc00))
+ next_end += 6
+ char = unichr(uni)
+ end = next_end
+ # Append the unescaped character
+ _append(char)
+ return u''.join(chunks), end
+
+
+# Use speedup if available
+scanstring = c_scanstring or py_scanstring
+
+WHITESPACE = re.compile(r'[ \t\n\r]*', FLAGS)
+WHITESPACE_STR = ' \t\n\r'
+
+def JSONObject((s, end), encoding, strict, scan_once, object_hook, _w=WHITESPACE.match, _ws=WHITESPACE_STR):
+ pairs = {}
+ # Use a slice to prevent IndexError from being raised, the following
+ # check will raise a more specific ValueError if the string is empty
+ nextchar = s[end:end + 1]
+ # Normally we expect nextchar == '"'
+ if nextchar != '"':
+ if nextchar in _ws:
+ end = _w(s, end).end()
+ nextchar = s[end:end + 1]
+ # Trivial empty object
+ if nextchar == '}':
+ return pairs, end + 1
+ elif nextchar != '"':
+ raise ValueError(errmsg("Expecting property name", s, end))
+ end += 1
+ while True:
+ key, end = scanstring(s, end, encoding, strict)
+
+ # To skip some function call overhead we optimize the fast paths where
+ # the JSON key separator is ": " or just ":".
+ if s[end:end + 1] != ':':
+ end = _w(s, end).end()
+ if s[end:end + 1] != ':':
+ raise ValueError(errmsg("Expecting : delimiter", s, end))
+
+ end += 1
+
+ try:
+ if s[end] in _ws:
+ end += 1
+ if s[end] in _ws:
+ end = _w(s, end + 1).end()
+ except IndexError:
+ pass
+
+ try:
+ value, end = scan_once(s, end)
+ except StopIteration:
+ raise ValueError(errmsg("Expecting object", s, end))
+ pairs[key] = value
+
+ try:
+ nextchar = s[end]
+ if nextchar in _ws:
+ end = _w(s, end + 1).end()
+ nextchar = s[end]
+ except IndexError:
+ nextchar = ''
+ end += 1
+
+ if nextchar == '}':
+ break
+ elif nextchar != ',':
+ raise ValueError(errmsg("Expecting , delimiter", s, end - 1))
+
+ try:
+ nextchar = s[end]
+ if nextchar in _ws:
+ end += 1
+ nextchar = s[end]
+ if nextchar in _ws:
+ end = _w(s, end + 1).end()
+ nextchar = s[end]
+ except IndexError:
+ nextchar = ''
+
+ end += 1
+ if nextchar != '"':
+ raise ValueError(errmsg("Expecting property name", s, end - 1))
+
+ if object_hook is not None:
+ pairs = object_hook(pairs)
+ return pairs, end
+
+def JSONArray((s, end), scan_once, _w=WHITESPACE.match, _ws=WHITESPACE_STR):
+ values = []
+ nextchar = s[end:end + 1]
+ if nextchar in _ws:
+ end = _w(s, end + 1).end()
+ nextchar = s[end:end + 1]
+ # Look-ahead for trivial empty array
+ if nextchar == ']':
+ return values, end + 1
+ _append = values.append
+ while True:
+ try:
+ value, end = scan_once(s, end)
+ except StopIteration:
+ raise ValueError(errmsg("Expecting object", s, end))
+ _append(value)
+ nextchar = s[end:end + 1]
+ if nextchar in _ws:
+ end = _w(s, end + 1).end()
+ nextchar = s[end:end + 1]
+ end += 1
+ if nextchar == ']':
+ break
+ elif nextchar != ',':
+ raise ValueError(errmsg("Expecting , delimiter", s, end))
+
+ try:
+ if s[end] in _ws:
+ end += 1
+ if s[end] in _ws:
+ end = _w(s, end + 1).end()
+ except IndexError:
+ pass
+
+ return values, end
+
+class JSONDecoder(object):
+ """Simple JSON <http://json.org> decoder
+
+ Performs the following translations in decoding by default:
+
+ +---------------+-------------------+
+ | JSON | Python |
+ +===============+===================+
+ | object | dict |
+ +---------------+-------------------+
+ | array | list |
+ +---------------+-------------------+
+ | string | unicode |
+ +---------------+-------------------+
+ | number (int) | int, long |
+ +---------------+-------------------+
+ | number (real) | float |
+ +---------------+-------------------+
+ | true | True |
+ +---------------+-------------------+
+ | false | False |
+ +---------------+-------------------+
+ | null | None |
+ +---------------+-------------------+
+
+ It also understands ``NaN``, ``Infinity``, and ``-Infinity`` as
+ their corresponding ``float`` values, which is outside the JSON spec.
+
+ """
+
+ def __init__(self, encoding=None, object_hook=None, parse_float=None,
+ parse_int=None, parse_constant=None, strict=True):
+ """``encoding`` determines the encoding used to interpret any ``str``
+ objects decoded by this instance (utf-8 by default). It has no
+ effect when decoding ``unicode`` objects.
+
+ Note that currently only encodings that are a superset of ASCII work,
+ strings of other encodings should be passed in as ``unicode``.
+
+ ``object_hook``, if specified, will be called with the result
+ of every JSON object decoded and its return value will be used in
+ place of the given ``dict``. This can be used to provide custom
+ deserializations (e.g. to support JSON-RPC class hinting).
+
+ ``parse_float``, if specified, will be called with the string
+ of every JSON float to be decoded. By default this is equivalent to
+ float(num_str). This can be used to use another datatype or parser
+ for JSON floats (e.g. decimal.Decimal).
+
+ ``parse_int``, if specified, will be called with the string
+ of every JSON int to be decoded. By default this is equivalent to
+ int(num_str). This can be used to use another datatype or parser
+ for JSON integers (e.g. float).
+
+ ``parse_constant``, if specified, will be called with one of the
+ following strings: -Infinity, Infinity, NaN.
+ This can be used to raise an exception if invalid JSON numbers
+ are encountered.
+
+ """
+ self.encoding = encoding
+ self.object_hook = object_hook
+ self.parse_float = parse_float or float
+ self.parse_int = parse_int or int
+ self.parse_constant = parse_constant or _CONSTANTS.__getitem__
+ self.strict = strict
+ self.parse_object = JSONObject
+ self.parse_array = JSONArray
+ self.parse_string = scanstring
+ self.scan_once = make_scanner(self)
+
+ def decode(self, s, _w=WHITESPACE.match):
+ """Return the Python representation of ``s`` (a ``str`` or ``unicode``
+ instance containing a JSON document)
+
+ """
+ obj, end = self.raw_decode(s, idx=_w(s, 0).end())
+ end = _w(s, end).end()
+ if end != len(s):
+ raise ValueError(errmsg("Extra data", s, end, len(s)))
+ return obj
+
+ def raw_decode(self, s, idx=0):
+ """Decode a JSON document from ``s`` (a ``str`` or ``unicode`` beginning
+ with a JSON document) and return a 2-tuple of the Python
+ representation and the index in ``s`` where the document ended.
+
+ This can be used to decode a JSON document from a string that may
+ have extraneous data at the end.
+
+ """
+ try:
+ obj, end = self.scan_once(s, idx)
+ except StopIteration:
+ raise ValueError("No JSON object could be decoded")
+ return obj, end
diff --git a/lib/chef/provider/package/yum/simplejson/decoder.pyc b/lib/chef/provider/package/yum/simplejson/decoder.pyc
new file mode 100644
index 0000000000..d402901870
--- /dev/null
+++ b/lib/chef/provider/package/yum/simplejson/decoder.pyc
Binary files differ
diff --git a/lib/chef/provider/package/yum/simplejson/encoder.py b/lib/chef/provider/package/yum/simplejson/encoder.py
new file mode 100644
index 0000000000..cf58290366
--- /dev/null
+++ b/lib/chef/provider/package/yum/simplejson/encoder.py
@@ -0,0 +1,440 @@
+"""Implementation of JSONEncoder
+"""
+import re
+
+try:
+ from simplejson._speedups import encode_basestring_ascii as c_encode_basestring_ascii
+except ImportError:
+ c_encode_basestring_ascii = None
+try:
+ from simplejson._speedups import make_encoder as c_make_encoder
+except ImportError:
+ c_make_encoder = None
+
+ESCAPE = re.compile(r'[\x00-\x1f\\"\b\f\n\r\t]')
+ESCAPE_ASCII = re.compile(r'([\\"]|[^\ -~])')
+HAS_UTF8 = re.compile(r'[\x80-\xff]')
+ESCAPE_DCT = {
+ '\\': '\\\\',
+ '"': '\\"',
+ '\b': '\\b',
+ '\f': '\\f',
+ '\n': '\\n',
+ '\r': '\\r',
+ '\t': '\\t',
+}
+for i in range(0x20):
+ #ESCAPE_DCT.setdefault(chr(i), '\\u{0:04x}'.format(i))
+ ESCAPE_DCT.setdefault(chr(i), '\\u%04x' % (i,))
+
+# Assume this produces an infinity on all machines (probably not guaranteed)
+INFINITY = float('1e66666')
+FLOAT_REPR = repr
+
+def encode_basestring(s):
+ """Return a JSON representation of a Python string
+
+ """
+ def replace(match):
+ return ESCAPE_DCT[match.group(0)]
+ return '"' + ESCAPE.sub(replace, s) + '"'
+
+
+def py_encode_basestring_ascii(s):
+ """Return an ASCII-only JSON representation of a Python string
+
+ """
+ if isinstance(s, str) and HAS_UTF8.search(s) is not None:
+ s = s.decode('utf-8')
+ def replace(match):
+ s = match.group(0)
+ try:
+ return ESCAPE_DCT[s]
+ except KeyError:
+ n = ord(s)
+ if n < 0x10000:
+ #return '\\u{0:04x}'.format(n)
+ return '\\u%04x' % (n,)
+ else:
+ # surrogate pair
+ n -= 0x10000
+ s1 = 0xd800 | ((n >> 10) & 0x3ff)
+ s2 = 0xdc00 | (n & 0x3ff)
+ #return '\\u{0:04x}\\u{1:04x}'.format(s1, s2)
+ return '\\u%04x\\u%04x' % (s1, s2)
+ return '"' + str(ESCAPE_ASCII.sub(replace, s)) + '"'
+
+
+encode_basestring_ascii = c_encode_basestring_ascii or py_encode_basestring_ascii
+
+class JSONEncoder(object):
+ """Extensible JSON <http://json.org> encoder for Python data structures.
+
+ Supports the following objects and types by default:
+
+ +-------------------+---------------+
+ | Python | JSON |
+ +===================+===============+
+ | dict | object |
+ +-------------------+---------------+
+ | list, tuple | array |
+ +-------------------+---------------+
+ | str, unicode | string |
+ +-------------------+---------------+
+ | int, long, float | number |
+ +-------------------+---------------+
+ | True | true |
+ +-------------------+---------------+
+ | False | false |
+ +-------------------+---------------+
+ | None | null |
+ +-------------------+---------------+
+
+ To extend this to recognize other objects, subclass and implement a
+ ``.default()`` method with another method that returns a serializable
+ object for ``o`` if possible, otherwise it should call the superclass
+ implementation (to raise ``TypeError``).
+
+ """
+ item_separator = ', '
+ key_separator = ': '
+ def __init__(self, skipkeys=False, ensure_ascii=True,
+ check_circular=True, allow_nan=True, sort_keys=False,
+ indent=None, separators=None, encoding='utf-8', default=None):
+ """Constructor for JSONEncoder, with sensible defaults.
+
+ If skipkeys is false, then it is a TypeError to attempt
+ encoding of keys that are not str, int, long, float or None. If
+ skipkeys is True, such items are simply skipped.
+
+ If ensure_ascii is true, the output is guaranteed to be str
+ objects with all incoming unicode characters escaped. If
+ ensure_ascii is false, the output will be unicode object.
+
+ If check_circular is true, then lists, dicts, and custom encoded
+ objects will be checked for circular references during encoding to
+ prevent an infinite recursion (which would cause an OverflowError).
+ Otherwise, no such check takes place.
+
+ If allow_nan is true, then NaN, Infinity, and -Infinity will be
+ encoded as such. This behavior is not JSON specification compliant,
+ but is consistent with most JavaScript based encoders and decoders.
+ Otherwise, it will be a ValueError to encode such floats.
+
+ If sort_keys is true, then the output of dictionaries will be
+ sorted by key; this is useful for regression tests to ensure
+ that JSON serializations can be compared on a day-to-day basis.
+
+ If indent is a non-negative integer, then JSON array
+ elements and object members will be pretty-printed with that
+ indent level. An indent level of 0 will only insert newlines.
+ None is the most compact representation.
+
+ If specified, separators should be a (item_separator, key_separator)
+ tuple. The default is (', ', ': '). To get the most compact JSON
+ representation you should specify (',', ':') to eliminate whitespace.
+
+ If specified, default is a function that gets called for objects
+ that can't otherwise be serialized. It should return a JSON encodable
+ version of the object or raise a ``TypeError``.
+
+ If encoding is not None, then all input strings will be
+ transformed into unicode using that encoding prior to JSON-encoding.
+ The default is UTF-8.
+
+ """
+
+ self.skipkeys = skipkeys
+ self.ensure_ascii = ensure_ascii
+ self.check_circular = check_circular
+ self.allow_nan = allow_nan
+ self.sort_keys = sort_keys
+ self.indent = indent
+ if separators is not None:
+ self.item_separator, self.key_separator = separators
+ if default is not None:
+ self.default = default
+ self.encoding = encoding
+
+ def default(self, o):
+ """Implement this method in a subclass such that it returns
+ a serializable object for ``o``, or calls the base implementation
+ (to raise a ``TypeError``).
+
+ For example, to support arbitrary iterators, you could
+ implement default like this::
+
+ def default(self, o):
+ try:
+ iterable = iter(o)
+ except TypeError:
+ pass
+ else:
+ return list(iterable)
+ return JSONEncoder.default(self, o)
+
+ """
+ raise TypeError(repr(o) + " is not JSON serializable")
+
+ def encode(self, o):
+ """Return a JSON string representation of a Python data structure.
+
+ >>> JSONEncoder().encode({"foo": ["bar", "baz"]})
+ '{"foo": ["bar", "baz"]}'
+
+ """
+ # This is for extremely simple cases and benchmarks.
+ if isinstance(o, basestring):
+ if isinstance(o, str):
+ _encoding = self.encoding
+ if (_encoding is not None
+ and not (_encoding == 'utf-8')):
+ o = o.decode(_encoding)
+ if self.ensure_ascii:
+ return encode_basestring_ascii(o)
+ else:
+ return encode_basestring(o)
+ # This doesn't pass the iterator directly to ''.join() because the
+ # exceptions aren't as detailed. The list call should be roughly
+ # equivalent to the PySequence_Fast that ''.join() would do.
+ chunks = self.iterencode(o, _one_shot=True)
+ if not isinstance(chunks, (list, tuple)):
+ chunks = list(chunks)
+ return ''.join(chunks)
+
+ def iterencode(self, o, _one_shot=False):
+ """Encode the given object and yield each string
+ representation as available.
+
+ For example::
+
+ for chunk in JSONEncoder().iterencode(bigobject):
+ mysocket.write(chunk)
+
+ """
+ if self.check_circular:
+ markers = {}
+ else:
+ markers = None
+ if self.ensure_ascii:
+ _encoder = encode_basestring_ascii
+ else:
+ _encoder = encode_basestring
+ if self.encoding != 'utf-8':
+ def _encoder(o, _orig_encoder=_encoder, _encoding=self.encoding):
+ if isinstance(o, str):
+ o = o.decode(_encoding)
+ return _orig_encoder(o)
+
+ def floatstr(o, allow_nan=self.allow_nan, _repr=FLOAT_REPR, _inf=INFINITY, _neginf=-INFINITY):
+ # Check for specials. Note that this type of test is processor- and/or
+ # platform-specific, so do tests which don't depend on the internals.
+
+ if o != o:
+ text = 'NaN'
+ elif o == _inf:
+ text = 'Infinity'
+ elif o == _neginf:
+ text = '-Infinity'
+ else:
+ return _repr(o)
+
+ if not allow_nan:
+ raise ValueError(
+ "Out of range float values are not JSON compliant: " +
+ repr(o))
+
+ return text
+
+
+ if _one_shot and c_make_encoder is not None and not self.indent and not self.sort_keys:
+ _iterencode = c_make_encoder(
+ markers, self.default, _encoder, self.indent,
+ self.key_separator, self.item_separator, self.sort_keys,
+ self.skipkeys, self.allow_nan)
+ else:
+ _iterencode = _make_iterencode(
+ markers, self.default, _encoder, self.indent, floatstr,
+ self.key_separator, self.item_separator, self.sort_keys,
+ self.skipkeys, _one_shot)
+ return _iterencode(o, 0)
+
+def _make_iterencode(markers, _default, _encoder, _indent, _floatstr, _key_separator, _item_separator, _sort_keys, _skipkeys, _one_shot,
+ ## HACK: hand-optimized bytecode; turn globals into locals
+ False=False,
+ True=True,
+ ValueError=ValueError,
+ basestring=basestring,
+ dict=dict,
+ float=float,
+ id=id,
+ int=int,
+ isinstance=isinstance,
+ list=list,
+ long=long,
+ str=str,
+ tuple=tuple,
+ ):
+
+ def _iterencode_list(lst, _current_indent_level):
+ if not lst:
+ yield '[]'
+ return
+ if markers is not None:
+ markerid = id(lst)
+ if markerid in markers:
+ raise ValueError("Circular reference detected")
+ markers[markerid] = lst
+ buf = '['
+ if _indent is not None:
+ _current_indent_level += 1
+ newline_indent = '\n' + (' ' * (_indent * _current_indent_level))
+ separator = _item_separator + newline_indent
+ buf += newline_indent
+ else:
+ newline_indent = None
+ separator = _item_separator
+ first = True
+ for value in lst:
+ if first:
+ first = False
+ else:
+ buf = separator
+ if isinstance(value, basestring):
+ yield buf + _encoder(value)
+ elif value is None:
+ yield buf + 'null'
+ elif value is True:
+ yield buf + 'true'
+ elif value is False:
+ yield buf + 'false'
+ elif isinstance(value, (int, long)):
+ yield buf + str(value)
+ elif isinstance(value, float):
+ yield buf + _floatstr(value)
+ else:
+ yield buf
+ if isinstance(value, (list, tuple)):
+ chunks = _iterencode_list(value, _current_indent_level)
+ elif isinstance(value, dict):
+ chunks = _iterencode_dict(value, _current_indent_level)
+ else:
+ chunks = _iterencode(value, _current_indent_level)
+ for chunk in chunks:
+ yield chunk
+ if newline_indent is not None:
+ _current_indent_level -= 1
+ yield '\n' + (' ' * (_indent * _current_indent_level))
+ yield ']'
+ if markers is not None:
+ del markers[markerid]
+
+ def _iterencode_dict(dct, _current_indent_level):
+ if not dct:
+ yield '{}'
+ return
+ if markers is not None:
+ markerid = id(dct)
+ if markerid in markers:
+ raise ValueError("Circular reference detected")
+ markers[markerid] = dct
+ yield '{'
+ if _indent is not None:
+ _current_indent_level += 1
+ newline_indent = '\n' + (' ' * (_indent * _current_indent_level))
+ item_separator = _item_separator + newline_indent
+ yield newline_indent
+ else:
+ newline_indent = None
+ item_separator = _item_separator
+ first = True
+ if _sort_keys:
+ items = dct.items()
+ items.sort(key=lambda kv: kv[0])
+ else:
+ items = dct.iteritems()
+ for key, value in items:
+ if isinstance(key, basestring):
+ pass
+ # JavaScript is weakly typed for these, so it makes sense to
+ # also allow them. Many encoders seem to do something like this.
+ elif isinstance(key, float):
+ key = _floatstr(key)
+ elif key is True:
+ key = 'true'
+ elif key is False:
+ key = 'false'
+ elif key is None:
+ key = 'null'
+ elif isinstance(key, (int, long)):
+ key = str(key)
+ elif _skipkeys:
+ continue
+ else:
+ raise TypeError("key " + repr(key) + " is not a string")
+ if first:
+ first = False
+ else:
+ yield item_separator
+ yield _encoder(key)
+ yield _key_separator
+ if isinstance(value, basestring):
+ yield _encoder(value)
+ elif value is None:
+ yield 'null'
+ elif value is True:
+ yield 'true'
+ elif value is False:
+ yield 'false'
+ elif isinstance(value, (int, long)):
+ yield str(value)
+ elif isinstance(value, float):
+ yield _floatstr(value)
+ else:
+ if isinstance(value, (list, tuple)):
+ chunks = _iterencode_list(value, _current_indent_level)
+ elif isinstance(value, dict):
+ chunks = _iterencode_dict(value, _current_indent_level)
+ else:
+ chunks = _iterencode(value, _current_indent_level)
+ for chunk in chunks:
+ yield chunk
+ if newline_indent is not None:
+ _current_indent_level -= 1
+ yield '\n' + (' ' * (_indent * _current_indent_level))
+ yield '}'
+ if markers is not None:
+ del markers[markerid]
+
+ def _iterencode(o, _current_indent_level):
+ if isinstance(o, basestring):
+ yield _encoder(o)
+ elif o is None:
+ yield 'null'
+ elif o is True:
+ yield 'true'
+ elif o is False:
+ yield 'false'
+ elif isinstance(o, (int, long)):
+ yield str(o)
+ elif isinstance(o, float):
+ yield _floatstr(o)
+ elif isinstance(o, (list, tuple)):
+ for chunk in _iterencode_list(o, _current_indent_level):
+ yield chunk
+ elif isinstance(o, dict):
+ for chunk in _iterencode_dict(o, _current_indent_level):
+ yield chunk
+ else:
+ if markers is not None:
+ markerid = id(o)
+ if markerid in markers:
+ raise ValueError("Circular reference detected")
+ markers[markerid] = o
+ o = _default(o)
+ for chunk in _iterencode(o, _current_indent_level):
+ yield chunk
+ if markers is not None:
+ del markers[markerid]
+
+ return _iterencode
diff --git a/lib/chef/provider/package/yum/simplejson/encoder.pyc b/lib/chef/provider/package/yum/simplejson/encoder.pyc
new file mode 100644
index 0000000000..207bce5cfb
--- /dev/null
+++ b/lib/chef/provider/package/yum/simplejson/encoder.pyc
Binary files differ
diff --git a/lib/chef/provider/package/yum/simplejson/scanner.py b/lib/chef/provider/package/yum/simplejson/scanner.py
new file mode 100644
index 0000000000..adbc6ec979
--- /dev/null
+++ b/lib/chef/provider/package/yum/simplejson/scanner.py
@@ -0,0 +1,65 @@
+"""JSON token scanner
+"""
+import re
+try:
+ from simplejson._speedups import make_scanner as c_make_scanner
+except ImportError:
+ c_make_scanner = None
+
+__all__ = ['make_scanner']
+
+NUMBER_RE = re.compile(
+ r'(-?(?:0|[1-9]\d*))(\.\d+)?([eE][-+]?\d+)?',
+ (re.VERBOSE | re.MULTILINE | re.DOTALL))
+
+def py_make_scanner(context):
+ parse_object = context.parse_object
+ parse_array = context.parse_array
+ parse_string = context.parse_string
+ match_number = NUMBER_RE.match
+ encoding = context.encoding
+ strict = context.strict
+ parse_float = context.parse_float
+ parse_int = context.parse_int
+ parse_constant = context.parse_constant
+ object_hook = context.object_hook
+
+ def _scan_once(string, idx):
+ try:
+ nextchar = string[idx]
+ except IndexError:
+ raise StopIteration
+
+ if nextchar == '"':
+ return parse_string(string, idx + 1, encoding, strict)
+ elif nextchar == '{':
+ return parse_object((string, idx + 1), encoding, strict, _scan_once, object_hook)
+ elif nextchar == '[':
+ return parse_array((string, idx + 1), _scan_once)
+ elif nextchar == 'n' and string[idx:idx + 4] == 'null':
+ return None, idx + 4
+ elif nextchar == 't' and string[idx:idx + 4] == 'true':
+ return True, idx + 4
+ elif nextchar == 'f' and string[idx:idx + 5] == 'false':
+ return False, idx + 5
+
+ m = match_number(string, idx)
+ if m is not None:
+ integer, frac, exp = m.groups()
+ if frac or exp:
+ res = parse_float(integer + (frac or '') + (exp or ''))
+ else:
+ res = parse_int(integer)
+ return res, m.end()
+ elif nextchar == 'N' and string[idx:idx + 3] == 'NaN':
+ return parse_constant('NaN'), idx + 3
+ elif nextchar == 'I' and string[idx:idx + 8] == 'Infinity':
+ return parse_constant('Infinity'), idx + 8
+ elif nextchar == '-' and string[idx:idx + 9] == '-Infinity':
+ return parse_constant('-Infinity'), idx + 9
+ else:
+ raise StopIteration
+
+ return _scan_once
+
+make_scanner = c_make_scanner or py_make_scanner
diff --git a/lib/chef/provider/package/yum/simplejson/scanner.pyc b/lib/chef/provider/package/yum/simplejson/scanner.pyc
new file mode 100644
index 0000000000..12df070e44
--- /dev/null
+++ b/lib/chef/provider/package/yum/simplejson/scanner.pyc
Binary files differ
diff --git a/lib/chef/provider/package/yum/simplejson/tool.py b/lib/chef/provider/package/yum/simplejson/tool.py
new file mode 100644
index 0000000000..90443317b2
--- /dev/null
+++ b/lib/chef/provider/package/yum/simplejson/tool.py
@@ -0,0 +1,37 @@
+r"""Command-line tool to validate and pretty-print JSON
+
+Usage::
+
+ $ echo '{"json":"obj"}' | python -m simplejson.tool
+ {
+ "json": "obj"
+ }
+ $ echo '{ 1.2:3.4}' | python -m simplejson.tool
+ Expecting property name: line 1 column 2 (char 2)
+
+"""
+import sys
+import simplejson
+
+def main():
+ if len(sys.argv) == 1:
+ infile = sys.stdin
+ outfile = sys.stdout
+ elif len(sys.argv) == 2:
+ infile = open(sys.argv[1], 'rb')
+ outfile = sys.stdout
+ elif len(sys.argv) == 3:
+ infile = open(sys.argv[1], 'rb')
+ outfile = open(sys.argv[2], 'wb')
+ else:
+ raise SystemExit(sys.argv[0] + " [infile [outfile]]")
+ try:
+ obj = simplejson.load(infile)
+ except ValueError, e:
+ raise SystemExit(e)
+ simplejson.dump(obj, outfile, sort_keys=True, indent=4)
+ outfile.write('\n')
+
+
+if __name__ == '__main__':
+ main()
diff --git a/lib/chef/provider/package/yum/version.rb b/lib/chef/provider/package/yum/version.rb
new file mode 100644
index 0000000000..b19f52fe09
--- /dev/null
+++ b/lib/chef/provider/package/yum/version.rb
@@ -0,0 +1,56 @@
+#
+# Copyright:: Copyright 2016-2018, Chef Software Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+class Chef
+ class Provider
+ class Package
+ class Yum < Chef::Provider::Package
+
+ # helper class to assist in passing around name/version/arch triples
+ class Version
+ attr_accessor :name
+ attr_accessor :version
+ attr_accessor :arch
+
+ def initialize(name, version, arch)
+ @name = name
+ @version = version
+ @arch = arch
+ end
+
+ def to_s
+ "#{name}-#{version}.#{arch}" unless version.nil?
+ end
+
+ def version_with_arch
+ "#{version}.#{arch}" unless version.nil?
+ end
+
+ def matches_name_and_arch?(other)
+ other.version == version && other.arch == arch
+ end
+
+ def ==(other)
+ name == other.name && version == other.version && arch == other.arch
+ end
+
+ alias eql? ==
+ end
+ end
+ end
+ end
+end
diff --git a/lib/chef/provider/package/yum/yum-dump.py b/lib/chef/provider/package/yum/yum-dump.py
deleted file mode 100644
index 6183460195..0000000000
--- a/lib/chef/provider/package/yum/yum-dump.py
+++ /dev/null
@@ -1,307 +0,0 @@
-#
-# Author:: Matthew Kent (<mkent@magoazul.com>)
-# Copyright:: Copyright 2009-2016, Matthew Kent
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-# yum-dump.py
-# Inspired by yumhelper.py by David Lutterkort
-#
-# Produce a list of installed, available and re-installable packages using yum
-# and dump the results to stdout.
-#
-# yum-dump invokes yum similarly to the command line interface which makes it
-# subject to most of the configuration parameters in yum.conf. yum-dump will
-# also load yum plugins in the same manor as yum - these can affect the output.
-#
-# Can be run as non root, but that won't update the cache.
-#
-# Intended to support yum 2.x and 3.x
-
-import os
-import sys
-import time
-import yum
-import re
-import errno
-
-from yum import Errors
-from optparse import OptionParser
-from distutils import version
-
-YUM_PID_FILE='/var/run/yum.pid'
-
-YUM_VER = version.StrictVersion(yum.__version__)
-YUM_MAJOR = YUM_VER.version[0]
-
-if YUM_MAJOR > 3 or YUM_MAJOR < 2:
- print >> sys.stderr, "yum-dump Error: Can't match supported yum version" \
- " (%s)" % yum.__version__
- sys.exit(1)
-
-# Required for Provides output
-if YUM_MAJOR == 2:
- import rpm
- import rpmUtils.miscutils
-
-def setup(yb, options):
- # Only want our output
- #
- if YUM_MAJOR == 3:
- try:
- if YUM_VER >= version.StrictVersion("3.2.22"):
- yb.preconf.errorlevel=0
- yb.preconf.debuglevel=0
-
- # initialize the config
- yb.conf
- else:
- yb.doConfigSetup(errorlevel=0, debuglevel=0)
- except yum.Errors.ConfigError, e:
- # suppresses an ignored exception at exit
- yb.preconf = None
- print >> sys.stderr, "yum-dump Config Error: %s" % e
- return 1
- except ValueError, e:
- yb.preconf = None
- print >> sys.stderr, "yum-dump Options Error: %s" % e
- return 1
- elif YUM_MAJOR == 2:
- yb.doConfigSetup()
-
- def __log(a,b): pass
-
- yb.log = __log
- yb.errorlog = __log
-
- # Give Chef every possible package version, it can decide what to do with them
- if YUM_MAJOR == 3:
- yb.conf.showdupesfromrepos = True
- elif YUM_MAJOR == 2:
- yb.conf.setConfigOption('showdupesfromrepos', True)
-
- # Optionally run only on cached repositories, but non root must use the cache
- if os.geteuid() != 0:
- if YUM_MAJOR == 3:
- yb.conf.cache = True
- elif YUM_MAJOR == 2:
- yb.conf.setConfigOption('cache', True)
- else:
- if YUM_MAJOR == 3:
- yb.conf.cache = options.cache
- elif YUM_MAJOR == 2:
- yb.conf.setConfigOption('cache', options.cache)
-
- # Handle repo toggle via id or glob exactly like yum
- for opt, repos in options.repo_control:
- for repo in repos:
- if opt == '--enablerepo':
- yb.repos.enableRepo(repo)
- elif opt == '--disablerepo':
- yb.repos.disableRepo(repo)
-
- return 0
-
-def dump_packages(yb, list, output_provides):
- packages = {}
-
- if YUM_MAJOR == 2:
- yb.doTsSetup()
- yb.doRepoSetup()
- yb.doSackSetup()
-
- db = yb.doPackageLists(list)
-
- for pkg in db.installed:
- pkg.type = 'i'
- packages[str(pkg)] = pkg
-
- if YUM_VER >= version.StrictVersion("3.2.21"):
- for pkg in db.available:
- pkg.type = 'a'
- packages[str(pkg)] = pkg
-
- # These are both installed and available
- for pkg in db.reinstall_available:
- pkg.type = 'r'
- packages[str(pkg)] = pkg
- else:
- # Old style method - no reinstall list
- for pkg in yb.pkgSack.returnPackages():
-
- if str(pkg) in packages:
- if packages[str(pkg)].type == "i":
- packages[str(pkg)].type = 'r'
- continue
-
- pkg.type = 'a'
- packages[str(pkg)] = pkg
-
- unique_packages = packages.values()
-
- unique_packages.sort(lambda x, y: cmp(x.name, y.name))
-
- for pkg in unique_packages:
- if output_provides == "all" or \
- (output_provides == "installed" and (pkg.type == "i" or pkg.type == "r")):
-
- # yum 2 doesn't have provides_print, implement it ourselves using methods
- # based on requires gathering in packages.py
- if YUM_MAJOR == 2:
- provlist = []
-
- # Installed and available are gathered in different ways
- if pkg.type == 'i' or pkg.type == 'r':
- names = pkg.hdr[rpm.RPMTAG_PROVIDENAME]
- flags = pkg.hdr[rpm.RPMTAG_PROVIDEFLAGS]
- ver = pkg.hdr[rpm.RPMTAG_PROVIDEVERSION]
- if names is not None:
- tmplst = zip(names, flags, ver)
-
- for (n, f, v) in tmplst:
- prov = rpmUtils.miscutils.formatRequire(n, v, f)
- provlist.append(prov)
- # This is slow :(
- elif pkg.type == 'a':
- for prcoTuple in pkg.returnPrco('provides'):
- prcostr = pkg.prcoPrintable(prcoTuple)
- provlist.append(prcostr)
-
- provides = provlist
- else:
- provides = pkg.provides_print
- else:
- provides = "[]"
-
- print '%s %s %s %s %s %s %s %s' % (
- pkg.name,
- pkg.epoch,
- pkg.version,
- pkg.release,
- pkg.arch,
- provides,
- pkg.type,
- pkg.repoid )
-
- return 0
-
-def yum_dump(options):
- lock_obtained = False
-
- yb = yum.YumBase()
-
- status = setup(yb, options)
- if status != 0:
- return status
-
- if options.output_options:
- print "[option installonlypkgs] %s" % " ".join(yb.conf.installonlypkgs)
-
- # Non root can't handle locking on rhel/centos 4
- if os.geteuid() != 0:
- return dump_packages(yb, options.package_list, options.output_provides)
-
- # Wrap the collection and output of packages in yum's global lock to prevent
- # any inconsistencies.
- try:
- # Spin up to --yum-lock-timeout option
- countdown = options.yum_lock_timeout
- while True:
- try:
- yb.doLock(YUM_PID_FILE)
- lock_obtained = True
- except Errors.LockError, e:
- time.sleep(1)
- countdown -= 1
- if countdown == 0:
- print >> sys.stderr, "yum-dump Locking Error! Couldn't obtain an " \
- "exclusive yum lock in %d seconds. Giving up." % options.yum_lock_timeout
- return 200
- else:
- break
-
- return dump_packages(yb, options.package_list, options.output_provides)
-
- # Ensure we clear the lock and cleanup any resources
- finally:
- try:
- yb.closeRpmDB()
- if lock_obtained == True:
- yb.doUnlock(YUM_PID_FILE)
- except Errors.LockError, e:
- print >> sys.stderr, "yum-dump Unlock Error: %s" % e
- return 200
-
-# Preserve order of enable/disable repo args like yum does
-def gather_repo_opts(option, opt, value, parser):
- if getattr(parser.values, option.dest, None) is None:
- setattr(parser.values, option.dest, [])
- getattr(parser.values, option.dest).append((opt, value.split(',')))
-
-def main():
- usage = "Usage: %prog [options]\n" + \
- "Output a list of installed, available and re-installable packages via yum"
- parser = OptionParser(usage=usage)
- parser.add_option("-C", "--cache",
- action="store_true", dest="cache", default=False,
- help="run entirely from cache, don't update cache")
- parser.add_option("-o", "--options",
- action="store_true", dest="output_options", default=False,
- help="output select yum options useful to Chef")
- parser.add_option("-p", "--installed-provides",
- action="store_const", const="installed", dest="output_provides", default="none",
- help="output Provides for installed packages, big/wide output")
- parser.add_option("-P", "--all-provides",
- action="store_const", const="all", dest="output_provides", default="none",
- help="output Provides for all package, slow, big/wide output")
- parser.add_option("-i", "--installed",
- action="store_const", const="installed", dest="package_list", default="all",
- help="output only installed packages")
- parser.add_option("-a", "--available",
- action="store_const", const="available", dest="package_list", default="all",
- help="output only available and re-installable packages")
- parser.add_option("--enablerepo",
- action="callback", callback=gather_repo_opts, type="string", dest="repo_control", default=[],
- help="enable disabled repositories by id or glob")
- parser.add_option("--disablerepo",
- action="callback", callback=gather_repo_opts, type="string", dest="repo_control", default=[],
- help="disable repositories by id or glob")
- parser.add_option("--yum-lock-timeout",
- action="store", type="int", dest="yum_lock_timeout", default=30,
- help="Time in seconds to wait for yum process lock")
-
- (options, args) = parser.parse_args()
-
- try:
- return yum_dump(options)
-
- except yum.Errors.RepoError, e:
- print >> sys.stderr, "yum-dump Repository Error: %s" % e
- return 1
-
- except yum.Errors.YumBaseError, e:
- print >> sys.stderr, "yum-dump General Error: %s" % e
- return 1
-
-try:
- status = main()
-# Suppress a nasty broken pipe error when output is piped to utilities like 'head'
-except IOError, e:
- if e.errno == errno.EPIPE:
- sys.exit(1)
- else:
- raise
-
-sys.exit(status)
diff --git a/lib/chef/provider/package/yum/yum_cache.rb b/lib/chef/provider/package/yum/yum_cache.rb
index 9fd95af138..fa0930109f 100644
--- a/lib/chef/provider/package/yum/yum_cache.rb
+++ b/lib/chef/provider/package/yum/yum_cache.rb
@@ -1,6 +1,6 @@
# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software, Inc.
+# Copyright:: Copyright 2008-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,357 +16,74 @@
# limitations under the License.
#
-require "chef/config"
+require "chef/provider/package/yum/python_helper"
require "chef/provider/package"
-require "chef/mixin/which"
-require "chef/mixin/shell_out"
require "singleton"
-require "chef/provider/package/yum/rpm_utils"
+
+#
+# These are largely historical APIs, the YumCache object no longer exists and this is a
+# fascade over the python helper class. It should be considered deprecated-lite and
+# no new APIs should be added and should be added to the python_helper instead.
+#
class Chef
class Provider
class Package
class Yum < Chef::Provider::Package
- # Cache for our installed and available packages, pulled in from yum-dump.py
class YumCache
- include Chef::Mixin::Which
- include Chef::Mixin::ShellOut
include Singleton
- attr_accessor :yum_binary
-
- def initialize
- @rpmdb = RPMDb.new
-
- # Next time @rpmdb is accessed:
- # :all - Trigger a run of "yum-dump.py --options --installed-provides", updates
- # yum's cache and parses options from /etc/yum.conf. Pulls in Provides
- # dependency data for installed packages only - this data is slow to
- # gather.
- # :provides - Same as :all but pulls in Provides data for available packages as well.
- # Used as a last resort when we can't find a Provides match.
- # :installed - Trigger a run of "yum-dump.py --installed", only reads the local rpm
- # db. Used between client runs for a quick refresh.
- # :none - Do nothing, a call to one of the reload methods is required.
- @next_refresh = :all
-
- @allow_multi_install = []
-
- @extra_repo_control = nil
-
- # these are for subsequent runs if we are on an interval
- Chef::Client.when_run_starts do
- YumCache.instance.reload
- end
- end
-
- attr_reader :extra_repo_control
-
- # Cache management
- #
-
- def yum_dump_path
- ::File.join(::File.dirname(__FILE__), "yum-dump.py")
- end
-
def refresh
- case @next_refresh
- when :none
- return nil
- when :installed
- reset_installed
- # fast
- opts = " --installed"
- when :all
- reset
- # medium
- opts = " --options --installed-provides"
- when :provides
- reset
- # slow!
- opts = " --options --all-provides"
- else
- raise ArgumentError, "Unexpected value in next_refresh: #{@next_refresh}"
- end
-
- if @extra_repo_control
- opts << " #{@extra_repo_control}"
- end
-
- opts << " --yum-lock-timeout #{Chef::Config[:yum_lock_timeout]}"
-
- one_line = false
- error = nil
-
- status = nil
-
- begin
- status = shell_out!("#{python_bin} #{yum_dump_path}#{opts}", timeout: Chef::Config[:yum_timeout])
- status.stdout.each_line do |line|
- one_line = true
-
- line.chomp!
- if line =~ /\[option (.*)\] (.*)/
- if $1 == "installonlypkgs"
- @allow_multi_install = $2.split
- else
- raise Chef::Exceptions::Package, "Strange, unknown option line '#{line}' from yum-dump.py"
- end
- next
- end
-
- if line =~ /^(\S+) ([0-9]+) (\S+) (\S+) (\S+) \[(.*)\] ([i,a,r]) (\S+)$/
- name = $1
- epoch = $2
- version = $3
- release = $4
- arch = $5
- provides = parse_provides($6)
- type = $7
- repoid = $8
- else
- Chef::Log.warn("Problem parsing line '#{line}' from yum-dump.py! " \
- "Please check your yum configuration.")
- next
- end
-
- case type
- when "i"
- # if yum-dump was called with --installed this may not be true, but it's okay
- # since we don't touch the @available Set in reload_installed
- available = false
- installed = true
- when "a"
- available = true
- installed = false
- when "r"
- available = true
- installed = true
- end
-
- pkg = RPMDbPackage.new(name, epoch, version, release, arch, provides, installed, available, repoid)
- @rpmdb << pkg
- end
-
- error = status.stderr
- rescue Mixlib::ShellOut::CommandTimeout => e
- Chef::Log.error("#{yum_dump_path} exceeded timeout #{Chef::Config[:yum_timeout]}")
- raise(e)
- end
-
- if status.exitstatus != 0
- raise Chef::Exceptions::Package, "Yum failed - #{status.inspect} - returns: #{error}"
- else
- unless one_line
- Chef::Log.warn("Odd, no output from yum-dump.py. Please check " \
- "your yum configuration.")
- end
- end
-
- # A reload method must be called before the cache is altered
- @next_refresh = :none
- end
-
- def python_bin
- yum_executable = which(yum_binary)
- if yum_executable && shabang?(yum_executable)
- shabang_or_fallback(extract_interpreter(yum_executable))
- else
- Chef::Log.warn("Yum executable not found or doesn't start with #!. Using default python.")
- "/usr/bin/python"
- end
- rescue StandardError => e
- Chef::Log.warn("An error occurred attempting to determine correct python executable. Using default.")
- Chef::Log.debug(e)
- "/usr/bin/python"
- end
-
- def extract_interpreter(file)
- ::File.open(file, "r", &:readline)[2..-1].strip
- end
-
- # dnf based systems have a yum shim that has /bin/bash as the interpreter. Don't use this.
- def shabang_or_fallback(interpreter)
- if interpreter == "/bin/bash"
- Chef::Log.warn("Yum executable interpreter is /bin/bash. Falling back to default python.")
- "/usr/bin/python"
- else
- interpreter
- end
- end
-
- def shabang?(file)
- ::File.open(file, "r") do |f|
- f.read(2) == "#!"
- end
- rescue Errno::ENOENT
- false
+ python_helper.restart
end
def reload
- @next_refresh = :all
+ python_helper.restart
end
def reload_installed
- @next_refresh = :installed
+ python_helper.restart
end
def reload_provides
- @next_refresh = :provides
+ python_helper.restart
end
def reset
- @rpmdb.clear
+ python_helper.restart
end
def reset_installed
- @rpmdb.clear_installed
+ python_helper.restart
end
- # Querying the cache
- #
-
- # Check for package by name or name+arch
- def package_available?(package_name)
- refresh
-
- if @rpmdb.lookup(package_name)
- return true
- else
- if package_name =~ /^(.*)\.(.*)$/
- pkg_name = $1
- pkg_arch = $2
-
- if matches = @rpmdb.lookup(pkg_name)
- matches.each do |m|
- return true if m.arch == pkg_arch
- end
- end
- end
- end
-
- false
+ def available_version(name, arch = nil)
+ p = python_helper.package_query(:whatavailable, name, arch: arch)
+ "#{p.version}.#{p.arch}" unless p.version.nil?
end
- # Returns a array of packages satisfying an RPMDependency
- def packages_from_require(rpmdep)
- refresh
- @rpmdb.whatprovides(rpmdep)
+ def installed_version(name, arch = nil)
+ p = python_helper.package_query(:whatinstalled, name, arch: arch)
+ "#{p.version}.#{p.arch}" unless p.version.nil?
end
- # Check if a package-version.arch is available to install
- def version_available?(package_name, desired_version, arch = nil)
- version(package_name, arch, true, false) do |v|
- return true if desired_version == v
- end
-
- false
- end
-
- # Return the source repository for a package-version.arch
- def package_repository(package_name, desired_version, arch = nil)
- package(package_name, arch, true, false) do |pkg|
- return pkg.repoid if desired_version == pkg.version.to_s
- end
-
- nil
+ def package_available?(name, arch = nil)
+ p = python_helper.package_query(:whatavailable, name, arch: arch)
+ !p.version.nil?
end
- # Return the latest available version for a package.arch
- def available_version(package_name, arch = nil)
- version(package_name, arch, true, false)
+ # NOTE that it is the responsibility of the python_helper to get these APIs correct and
+ # we do not do any validation here that the e.g. version or arch matches the requested value
+ # (because the bigger issue there is a buggy+broken python_helper -- so don't try to fix those
+ # kinds of bugs here)
+ def version_available?(name, version, arch = nil)
+ p = python_helper.package_query(:whatavailable, name, version: version, arch: arch)
+ !p.version.nil?
end
- alias candidate_version available_version
-
- # Return the currently installed version for a package.arch
- def installed_version(package_name, arch = nil)
- version(package_name, arch, false, true)
- end
-
- # Return an array of packages allowed to be installed multiple times, such as the kernel
- def allow_multi_install
- refresh
- @allow_multi_install
- end
-
- def enable_extra_repo_control(arg)
- # Don't touch cache if it's the same repos as the last load
- unless @extra_repo_control == arg
- @extra_repo_control = arg
- reload
- end
- end
-
- def disable_extra_repo_control
- # Only force reload when set
- if @extra_repo_control
- @extra_repo_control = nil
- reload
- end
- end
-
- private
-
- def version(package_name, arch = nil, is_available = false, is_installed = false)
- package(package_name, arch, is_available, is_installed) do |pkg|
- if block_given?
- yield pkg.version.to_s
- else
- # first match is latest version
- return pkg.version.to_s
- end
- end
-
- if block_given?
- return self
- else
- return nil
- end
- end
-
- def package(package_name, arch = nil, is_available = false, is_installed = false)
- refresh
- packages = @rpmdb[package_name]
- if packages
- packages.each do |pkg|
- if is_available
- next unless @rpmdb.available?(pkg)
- end
- if is_installed
- next unless @rpmdb.installed?(pkg)
- end
- if arch
- next unless pkg.arch == arch
- end
-
- if block_given?
- yield pkg
- else
- # first match is latest version
- return pkg
- end
- end
- end
-
- if block_given?
- return self
- else
- return nil
- end
- end
-
- # Parse provides from yum-dump.py output
- def parse_provides(string)
- ret = []
- # ['atk = 1.12.2-1.fc6', 'libatk-1.0.so.0']
- string.split(", ").each do |seg|
- # 'atk = 1.12.2-1.fc6'
- if seg =~ /^'(.*)'$/
- ret << RPMProvide.parse($1)
- end
- end
- ret
+ # @api private
+ def python_helper
+ @python_helper ||= PythonHelper.instance
end
end # YumCache
diff --git a/lib/chef/provider/package/yum/yum_helper.py b/lib/chef/provider/package/yum/yum_helper.py
new file mode 100644
index 0000000000..72e1177e8e
--- /dev/null
+++ b/lib/chef/provider/package/yum/yum_helper.py
@@ -0,0 +1,198 @@
+#!/usr/bin/env python3
+# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
+
+#
+# NOTE: this actually needs to run under python2.4 and centos 5.x through python3 and centos 7.x
+# please manually test changes on centos5 boxes or you will almost certainly break things.
+#
+
+import sys
+import yum
+import signal
+import os
+sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'simplejson'))
+try: import json
+except ImportError: import simplejson as json
+import re
+from rpmUtils.miscutils import stringToVersion,compareEVR
+from rpmUtils.arch import getBaseArch, getArchList
+
+
+try: from yum.misc import string_to_prco_tuple
+except ImportError:
+ # RHEL5 compat
+ def string_to_prco_tuple(prcoString):
+ prco_split = prcoString.split()
+ n, f, v = prco_split
+ (prco_e, prco_v, prco_r) = stringToVersion(v)
+ return (n, f, (prco_e, prco_v, prco_r))
+
+base = None
+
+def get_base():
+ global base
+ if base is None:
+ base = yum.YumBase()
+ setup_exit_handler()
+ return base
+
+def versioncompare(versions):
+ arch_list = getArchList()
+ candidate_arch1 = versions[0].split(".")[-1]
+ candidate_arch2 = versions[1].split(".")[-1]
+
+ # The first version number passed to this method is always a valid nevra (the current version)
+ # If the second version number looks like it does not contain a valid arch
+ # then we'll chop the arch component (assuming it *is* a valid one) from the first version string
+ # so we're only comparing the evr portions.
+ if (candidate_arch2 not in arch_list) and (candidate_arch1 in arch_list):
+ final_version1 = versions[0].replace("." + candidate_arch1,"")
+ else:
+ final_version1 = versions[0]
+
+ final_version2 = versions[1]
+
+ (e1, v1, r1) = stringToVersion(final_version1)
+ (e2, v2, r2) = stringToVersion(final_version2)
+
+ evr_comparison = compareEVR((e1, v1, r1), (e2, v2, r2))
+ outpipe.write("%(e)s\n" % { 'e': evr_comparison })
+ outpipe.flush()
+
+def install_only_packages(name):
+ base = get_base()
+ if name in base.conf.installonlypkgs:
+ outpipe.write('True')
+ else:
+ outpipe.write('False')
+ outpipe.flush()
+
+# python2.4 / centos5 compat
+try:
+ any
+except NameError:
+ def any(s):
+ for v in s:
+ if v:
+ return True
+ return False
+
+def query(command):
+ base = get_base()
+
+ enabled_repos = base.repos.listEnabled()
+
+ # Handle any repocontrols passed in with our options
+ if 'enablerepos' in command:
+ base.repos.enableRepo(*command['enablerepos'])
+
+ if 'disablerepos' in command:
+ base.repos.disableRepo(*command['disablerepos'])
+
+ args = { 'name': command['provides'] }
+ do_nevra = False
+ if 'epoch' in command:
+ args['epoch'] = command['epoch']
+ do_nevra = True
+ if 'version' in command:
+ args['ver'] = command['version']
+ do_nevra = True
+ if 'release' in command:
+ args['rel'] = command['release']
+ do_nevra = True
+ if 'arch' in command:
+ desired_arch = command['arch']
+ args['arch'] = command['arch']
+ do_nevra = True
+ else:
+ desired_arch = getBaseArch()
+
+ obj = None
+ if command['action'] == "whatinstalled":
+ obj = base.rpmdb
+ else:
+ obj = base.pkgSack
+
+ # if we are given "name == 1.2.3" then we must use the getProvides() API.
+ # - this means that we ignore arch and version properties when given prco tuples as a package_name
+ # - in order to fix this, something would have to happen where getProvides was called first and
+ # then the result was searchNevra'd. please be extremely careful if attempting to fix that
+ # since searchNevra does not support prco tuples.
+ if any(elem in command['provides'] for elem in r"<=>"):
+ # handles flags (<, >, =, etc) and versions, but no wildcareds
+ pkgs = obj.getProvides(*string_to_prco_tuple(command['provides']))
+ elif do_nevra:
+ # now if we're given version or arch properties explicitly, then we do a SearchNevra.
+ # - this means that wildcard version in the package_name with an arch property will not work correctly
+ # - again don't try to fix this just by pushing bugs around in the code, you would need to call
+ # returnPackages and searchProvides and then apply the Nevra filters to those results.
+ pkgs = obj.searchNevra(**args)
+ if (command['action'] == "whatinstalled") and (not pkgs):
+ pkgs = obj.searchNevra(name=args['name'], arch=desired_arch)
+ else:
+ pats = [command['provides']]
+ pkgs = obj.returnPackages(patterns=pats)
+
+ if not pkgs:
+ # handles wildcards
+ pkgs = obj.searchProvides(command['provides'])
+
+ if not pkgs:
+ outpipe.write(command['provides'].split().pop(0)+' nil nil\n')
+ outpipe.flush()
+ else:
+ # make sure we picked the package with the highest version
+ pkgs = base.bestPackagesFromList(pkgs,single_name=True)
+ pkg = pkgs.pop(0)
+ outpipe.write("%(n)s %(e)s:%(v)s-%(r)s %(a)s\n" % { 'n': pkg.name, 'e': pkg.epoch, 'v': pkg.version, 'r': pkg.release, 'a': pkg.arch })
+ outpipe.flush()
+
+ # Reset any repos we were passed in enablerepo/disablerepo to the original state in enabled_repos
+ if 'enablerepos' in command:
+ for repo in command['enablerepos']:
+ if base.repos.getRepo(repo) not in enabled_repos:
+ base.repos.disableRepo(repo)
+
+ if 'disablerepos' in command:
+ for repo in command['disablerepos']:
+ if base.repos.getRepo(repo) in enabled_repos:
+ base.repos.enableRepo(repo)
+
+# the design of this helper is that it should try to be 'brittle' and fail hard and exit in order
+# to keep process tables clean. additional error handling should probably be added to the retry loop
+# on the ruby side.
+def exit_handler(signal, frame):
+ base.closeRpmDB()
+ sys.exit(0)
+
+def setup_exit_handler():
+ signal.signal(signal.SIGINT, exit_handler)
+ signal.signal(signal.SIGHUP, exit_handler)
+ signal.signal(signal.SIGPIPE, exit_handler)
+ signal.signal(signal.SIGQUIT, exit_handler)
+
+if len(sys.argv) < 3:
+ inpipe = sys.stdin
+ outpipe = sys.stdout
+else:
+ inpipe = os.fdopen(int(sys.argv[1]), "r")
+ outpipe = os.fdopen(int(sys.argv[2]), "w")
+
+while 1:
+ # kill self if we get orphaned (tragic)
+ ppid = os.getppid()
+ if ppid == 1:
+ sys.exit(0)
+ setup_exit_handler()
+ line = inpipe.readline()
+ command = json.loads(line)
+ if command['action'] == "whatinstalled":
+ query(command)
+ elif command['action'] == "whatavailable":
+ query(command)
+ elif command['action'] == "versioncompare":
+ versioncompare(command['versions'])
+ elif command['action'] == "installonlypkgs":
+ install_only_packages(command['package'])
+ else:
+ raise RuntimeError("bad command")
diff --git a/lib/chef/resource/yum_package.rb b/lib/chef/resource/yum_package.rb
index c20068cb06..f066e3f0ad 100644
--- a/lib/chef/resource/yum_package.rb
+++ b/lib/chef/resource/yum_package.rb
@@ -1,6 +1,6 @@
#
# Author:: AJ Christensen (<aj@chef.io>)
-# Copyright:: Copyright 2008-2017, Chef Software Inc.
+# Copyright:: Copyright 2008-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/spec/functional/assets/yumrepo/chef_rpm-1.10-1.aarch64.rpm b/spec/functional/assets/yumrepo/chef_rpm-1.10-1.aarch64.rpm
new file mode 100644
index 0000000000..808e5c64c9
--- /dev/null
+++ b/spec/functional/assets/yumrepo/chef_rpm-1.10-1.aarch64.rpm
Binary files differ
diff --git a/spec/functional/assets/yumrepo/chef_rpm-1.10-1.fc24.i686.rpm b/spec/functional/assets/yumrepo/chef_rpm-1.10-1.fc24.i686.rpm
deleted file mode 100644
index 29a4624971..0000000000
--- a/spec/functional/assets/yumrepo/chef_rpm-1.10-1.fc24.i686.rpm
+++ /dev/null
Binary files differ
diff --git a/spec/functional/assets/yumrepo/chef_rpm-1.10-1.fc24.src.rpm b/spec/functional/assets/yumrepo/chef_rpm-1.10-1.fc24.src.rpm
deleted file mode 100644
index b6a6ec3176..0000000000
--- a/spec/functional/assets/yumrepo/chef_rpm-1.10-1.fc24.src.rpm
+++ /dev/null
Binary files differ
diff --git a/spec/functional/assets/yumrepo/chef_rpm-1.10-1.fc24.x86_64.rpm b/spec/functional/assets/yumrepo/chef_rpm-1.10-1.fc24.x86_64.rpm
deleted file mode 100644
index 239b6ef145..0000000000
--- a/spec/functional/assets/yumrepo/chef_rpm-1.10-1.fc24.x86_64.rpm
+++ /dev/null
Binary files differ
diff --git a/spec/functional/assets/yumrepo/chef_rpm-1.10-1.i686.rpm b/spec/functional/assets/yumrepo/chef_rpm-1.10-1.i686.rpm
new file mode 100644
index 0000000000..ed7b6ddc8e
--- /dev/null
+++ b/spec/functional/assets/yumrepo/chef_rpm-1.10-1.i686.rpm
Binary files differ
diff --git a/spec/functional/assets/yumrepo/chef_rpm-1.10-1.ppc64.rpm b/spec/functional/assets/yumrepo/chef_rpm-1.10-1.ppc64.rpm
new file mode 100644
index 0000000000..f3683b3c89
--- /dev/null
+++ b/spec/functional/assets/yumrepo/chef_rpm-1.10-1.ppc64.rpm
Binary files differ
diff --git a/spec/functional/assets/yumrepo/chef_rpm-1.10-1.ppc64le.rpm b/spec/functional/assets/yumrepo/chef_rpm-1.10-1.ppc64le.rpm
new file mode 100644
index 0000000000..4f8de433d9
--- /dev/null
+++ b/spec/functional/assets/yumrepo/chef_rpm-1.10-1.ppc64le.rpm
Binary files differ
diff --git a/spec/functional/assets/yumrepo/chef_rpm-1.10-1.s390x.rpm b/spec/functional/assets/yumrepo/chef_rpm-1.10-1.s390x.rpm
new file mode 100644
index 0000000000..98538293ff
--- /dev/null
+++ b/spec/functional/assets/yumrepo/chef_rpm-1.10-1.s390x.rpm
Binary files differ
diff --git a/spec/functional/assets/yumrepo/chef_rpm-1.10-1.src.rpm b/spec/functional/assets/yumrepo/chef_rpm-1.10-1.src.rpm
new file mode 100644
index 0000000000..03a92f1cfc
--- /dev/null
+++ b/spec/functional/assets/yumrepo/chef_rpm-1.10-1.src.rpm
Binary files differ
diff --git a/spec/functional/assets/yumrepo/chef_rpm-1.10-1.x86_64.rpm b/spec/functional/assets/yumrepo/chef_rpm-1.10-1.x86_64.rpm
new file mode 100644
index 0000000000..3533640780
--- /dev/null
+++ b/spec/functional/assets/yumrepo/chef_rpm-1.10-1.x86_64.rpm
Binary files differ
diff --git a/spec/functional/assets/yumrepo/chef_rpm-1.2-1.aarch64.rpm b/spec/functional/assets/yumrepo/chef_rpm-1.2-1.aarch64.rpm
new file mode 100644
index 0000000000..73d59bf3e2
--- /dev/null
+++ b/spec/functional/assets/yumrepo/chef_rpm-1.2-1.aarch64.rpm
Binary files differ
diff --git a/spec/functional/assets/yumrepo/chef_rpm-1.2-1.fc24.i686.rpm b/spec/functional/assets/yumrepo/chef_rpm-1.2-1.fc24.i686.rpm
deleted file mode 100644
index 3421c3628f..0000000000
--- a/spec/functional/assets/yumrepo/chef_rpm-1.2-1.fc24.i686.rpm
+++ /dev/null
Binary files differ
diff --git a/spec/functional/assets/yumrepo/chef_rpm-1.2-1.fc24.src.rpm b/spec/functional/assets/yumrepo/chef_rpm-1.2-1.fc24.src.rpm
deleted file mode 100644
index d420659fd5..0000000000
--- a/spec/functional/assets/yumrepo/chef_rpm-1.2-1.fc24.src.rpm
+++ /dev/null
Binary files differ
diff --git a/spec/functional/assets/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm b/spec/functional/assets/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm
deleted file mode 100644
index 93c1f5e3e3..0000000000
--- a/spec/functional/assets/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm
+++ /dev/null
Binary files differ
diff --git a/spec/functional/assets/yumrepo/chef_rpm-1.2-1.i686.rpm b/spec/functional/assets/yumrepo/chef_rpm-1.2-1.i686.rpm
new file mode 100644
index 0000000000..6637756abb
--- /dev/null
+++ b/spec/functional/assets/yumrepo/chef_rpm-1.2-1.i686.rpm
Binary files differ
diff --git a/spec/functional/assets/yumrepo/chef_rpm-1.2-1.ppc64.rpm b/spec/functional/assets/yumrepo/chef_rpm-1.2-1.ppc64.rpm
new file mode 100644
index 0000000000..677e43f83b
--- /dev/null
+++ b/spec/functional/assets/yumrepo/chef_rpm-1.2-1.ppc64.rpm
Binary files differ
diff --git a/spec/functional/assets/yumrepo/chef_rpm-1.2-1.ppc64le.rpm b/spec/functional/assets/yumrepo/chef_rpm-1.2-1.ppc64le.rpm
new file mode 100644
index 0000000000..df21a68780
--- /dev/null
+++ b/spec/functional/assets/yumrepo/chef_rpm-1.2-1.ppc64le.rpm
Binary files differ
diff --git a/spec/functional/assets/yumrepo/chef_rpm-1.2-1.s390x.rpm b/spec/functional/assets/yumrepo/chef_rpm-1.2-1.s390x.rpm
new file mode 100644
index 0000000000..02a771c6f5
--- /dev/null
+++ b/spec/functional/assets/yumrepo/chef_rpm-1.2-1.s390x.rpm
Binary files differ
diff --git a/spec/functional/assets/yumrepo/chef_rpm-1.2-1.src.rpm b/spec/functional/assets/yumrepo/chef_rpm-1.2-1.src.rpm
new file mode 100644
index 0000000000..5d4d13e18a
--- /dev/null
+++ b/spec/functional/assets/yumrepo/chef_rpm-1.2-1.src.rpm
Binary files differ
diff --git a/spec/functional/assets/yumrepo/chef_rpm-1.2-1.x86_64.rpm b/spec/functional/assets/yumrepo/chef_rpm-1.2-1.x86_64.rpm
new file mode 100644
index 0000000000..314c52f22e
--- /dev/null
+++ b/spec/functional/assets/yumrepo/chef_rpm-1.2-1.x86_64.rpm
Binary files differ
diff --git a/spec/functional/assets/yumrepo/repodata/313329137b55fd333b2dc66394a6661a2befa6cc535d8460d92a4a78a9c581f0-primary.sqlite.bz2 b/spec/functional/assets/yumrepo/repodata/313329137b55fd333b2dc66394a6661a2befa6cc535d8460d92a4a78a9c581f0-primary.sqlite.bz2
deleted file mode 100644
index d7726b9df6..0000000000
--- a/spec/functional/assets/yumrepo/repodata/313329137b55fd333b2dc66394a6661a2befa6cc535d8460d92a4a78a9c581f0-primary.sqlite.bz2
+++ /dev/null
Binary files differ
diff --git a/spec/functional/assets/yumrepo/repodata/31ac4db5d5ac593728fcc26aef82b7b93c4cc4dbec843786b1845b939b658553-other.xml.gz b/spec/functional/assets/yumrepo/repodata/31ac4db5d5ac593728fcc26aef82b7b93c4cc4dbec843786b1845b939b658553-other.xml.gz
deleted file mode 100644
index 30d7778ac4..0000000000
--- a/spec/functional/assets/yumrepo/repodata/31ac4db5d5ac593728fcc26aef82b7b93c4cc4dbec843786b1845b939b658553-other.xml.gz
+++ /dev/null
Binary files differ
diff --git a/spec/functional/assets/yumrepo/repodata/4632d67cb92636e7575d911c24f0e04d3505a944e97c483abe0c3e73a7c62d33-filelists.sqlite.bz2 b/spec/functional/assets/yumrepo/repodata/4632d67cb92636e7575d911c24f0e04d3505a944e97c483abe0c3e73a7c62d33-filelists.sqlite.bz2
new file mode 100644
index 0000000000..3c5e406935
--- /dev/null
+++ b/spec/functional/assets/yumrepo/repodata/4632d67cb92636e7575d911c24f0e04d3505a944e97c483abe0c3e73a7c62d33-filelists.sqlite.bz2
Binary files differ
diff --git a/spec/functional/assets/yumrepo/repodata/4ac40fa3c6728c1401318e2e20a997436624e83dcf7a5f952b851ef422637773-filelists.sqlite.bz2 b/spec/functional/assets/yumrepo/repodata/4ac40fa3c6728c1401318e2e20a997436624e83dcf7a5f952b851ef422637773-filelists.sqlite.bz2
deleted file mode 100644
index 2df608aa34..0000000000
--- a/spec/functional/assets/yumrepo/repodata/4ac40fa3c6728c1401318e2e20a997436624e83dcf7a5f952b851ef422637773-filelists.sqlite.bz2
+++ /dev/null
Binary files differ
diff --git a/spec/functional/assets/yumrepo/repodata/66391e53f0510b98b3f0b79f40ba1048026d9a1ef20905d9c40ba6f5411f3243-primary.xml.gz b/spec/functional/assets/yumrepo/repodata/66391e53f0510b98b3f0b79f40ba1048026d9a1ef20905d9c40ba6f5411f3243-primary.xml.gz
deleted file mode 100644
index d9b7cb879a..0000000000
--- a/spec/functional/assets/yumrepo/repodata/66391e53f0510b98b3f0b79f40ba1048026d9a1ef20905d9c40ba6f5411f3243-primary.xml.gz
+++ /dev/null
Binary files differ
diff --git a/spec/functional/assets/yumrepo/repodata/74599b793e54d877323837d2d81a1c3c594c44e4335f9528234bb490f7b9b439-other.xml.gz b/spec/functional/assets/yumrepo/repodata/74599b793e54d877323837d2d81a1c3c594c44e4335f9528234bb490f7b9b439-other.xml.gz
new file mode 100644
index 0000000000..ddccd353ae
--- /dev/null
+++ b/spec/functional/assets/yumrepo/repodata/74599b793e54d877323837d2d81a1c3c594c44e4335f9528234bb490f7b9b439-other.xml.gz
Binary files differ
diff --git a/spec/functional/assets/yumrepo/repodata/8b34697595fcc87928e12d24644dda9462c3857bd932861e28bc77ae1f31be16-filelists.xml.gz b/spec/functional/assets/yumrepo/repodata/8b34697595fcc87928e12d24644dda9462c3857bd932861e28bc77ae1f31be16-filelists.xml.gz
deleted file mode 100644
index 35a973d170..0000000000
--- a/spec/functional/assets/yumrepo/repodata/8b34697595fcc87928e12d24644dda9462c3857bd932861e28bc77ae1f31be16-filelists.xml.gz
+++ /dev/null
Binary files differ
diff --git a/spec/functional/assets/yumrepo/repodata/a845d418f919d2115ab95a56b2c76f6825ad0d0bede49181a55c04f58995d057-primary.sqlite.bz2 b/spec/functional/assets/yumrepo/repodata/a845d418f919d2115ab95a56b2c76f6825ad0d0bede49181a55c04f58995d057-primary.sqlite.bz2
new file mode 100644
index 0000000000..50bbe1f37f
--- /dev/null
+++ b/spec/functional/assets/yumrepo/repodata/a845d418f919d2115ab95a56b2c76f6825ad0d0bede49181a55c04f58995d057-primary.sqlite.bz2
Binary files differ
diff --git a/spec/functional/assets/yumrepo/repodata/af9b7cf9ef23bd7b43068d74a460f3b5d06753d638e58e4a0c9edc35bfb9cdc4-other.sqlite.bz2 b/spec/functional/assets/yumrepo/repodata/af9b7cf9ef23bd7b43068d74a460f3b5d06753d638e58e4a0c9edc35bfb9cdc4-other.sqlite.bz2
new file mode 100644
index 0000000000..e341e1df69
--- /dev/null
+++ b/spec/functional/assets/yumrepo/repodata/af9b7cf9ef23bd7b43068d74a460f3b5d06753d638e58e4a0c9edc35bfb9cdc4-other.sqlite.bz2
Binary files differ
diff --git a/spec/functional/assets/yumrepo/repodata/b97cca3fe14bcf06c52be4449b6108f7731239ff221111dcce8aada5467f60dc-other.sqlite.bz2 b/spec/functional/assets/yumrepo/repodata/b97cca3fe14bcf06c52be4449b6108f7731239ff221111dcce8aada5467f60dc-other.sqlite.bz2
deleted file mode 100644
index e682fc0f0b..0000000000
--- a/spec/functional/assets/yumrepo/repodata/b97cca3fe14bcf06c52be4449b6108f7731239ff221111dcce8aada5467f60dc-other.sqlite.bz2
+++ /dev/null
Binary files differ
diff --git a/spec/functional/assets/yumrepo/repodata/bdb4f5f1492a3b9532f22c43110a81500dd744f23da0aec5c33b2a41317c737d-filelists.xml.gz b/spec/functional/assets/yumrepo/repodata/bdb4f5f1492a3b9532f22c43110a81500dd744f23da0aec5c33b2a41317c737d-filelists.xml.gz
new file mode 100644
index 0000000000..9636d5b868
--- /dev/null
+++ b/spec/functional/assets/yumrepo/repodata/bdb4f5f1492a3b9532f22c43110a81500dd744f23da0aec5c33b2a41317c737d-filelists.xml.gz
Binary files differ
diff --git a/spec/functional/assets/yumrepo/repodata/c10d1d34ce99e02f12ec96ef68360543ab1bb7c3cb81a4a2bf78df7d8597e9df-primary.xml.gz b/spec/functional/assets/yumrepo/repodata/c10d1d34ce99e02f12ec96ef68360543ab1bb7c3cb81a4a2bf78df7d8597e9df-primary.xml.gz
new file mode 100644
index 0000000000..afa4b4db9a
--- /dev/null
+++ b/spec/functional/assets/yumrepo/repodata/c10d1d34ce99e02f12ec96ef68360543ab1bb7c3cb81a4a2bf78df7d8597e9df-primary.xml.gz
Binary files differ
diff --git a/spec/functional/assets/yumrepo/repodata/filelists.xml.gz b/spec/functional/assets/yumrepo/repodata/filelists.xml.gz
new file mode 100644
index 0000000000..954b9abcd7
--- /dev/null
+++ b/spec/functional/assets/yumrepo/repodata/filelists.xml.gz
Binary files differ
diff --git a/spec/functional/assets/yumrepo/repodata/other.xml.gz b/spec/functional/assets/yumrepo/repodata/other.xml.gz
new file mode 100644
index 0000000000..db6ffa611d
--- /dev/null
+++ b/spec/functional/assets/yumrepo/repodata/other.xml.gz
Binary files differ
diff --git a/spec/functional/assets/yumrepo/repodata/primary.xml.gz b/spec/functional/assets/yumrepo/repodata/primary.xml.gz
new file mode 100644
index 0000000000..fe06057d60
--- /dev/null
+++ b/spec/functional/assets/yumrepo/repodata/primary.xml.gz
Binary files differ
diff --git a/spec/functional/assets/yumrepo/repodata/repomd.xml b/spec/functional/assets/yumrepo/repodata/repomd.xml
index 92937e151a..31be5c80f5 100644
--- a/spec/functional/assets/yumrepo/repodata/repomd.xml
+++ b/spec/functional/assets/yumrepo/repodata/repomd.xml
@@ -1,55 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
-<repomd xmlns="http://linux.duke.edu/metadata/repo" xmlns:rpm="http://linux.duke.edu/metadata/rpm">
- <revision>1479418959</revision>
-<data type="filelists">
- <checksum type="sha256">8b34697595fcc87928e12d24644dda9462c3857bd932861e28bc77ae1f31be16</checksum>
- <open-checksum type="sha256">9f5be999b4a535c19afc53703851577e1a325227fab651189c5c39708b9a1e38</open-checksum>
- <location href="repodata/8b34697595fcc87928e12d24644dda9462c3857bd932861e28bc77ae1f31be16-filelists.xml.gz"/>
- <timestamp>1479418959</timestamp>
- <size>419</size>
- <open-size>1127</open-size>
-</data>
-<data type="primary">
- <checksum type="sha256">66391e53f0510b98b3f0b79f40ba1048026d9a1ef20905d9c40ba6f5411f3243</checksum>
- <open-checksum type="sha256">dc25cfbf4520861130e0ba203d27cc40b183fbb7c576aac33d838fb20a68aa32</open-checksum>
- <location href="repodata/66391e53f0510b98b3f0b79f40ba1048026d9a1ef20905d9c40ba6f5411f3243-primary.xml.gz"/>
- <timestamp>1479418959</timestamp>
- <size>859</size>
- <open-size>4529</open-size>
-</data>
-<data type="primary_db">
- <checksum type="sha256">313329137b55fd333b2dc66394a6661a2befa6cc535d8460d92a4a78a9c581f0</checksum>
- <open-checksum type="sha256">720b637c782cce8604b922e9989ecfff9091e26163d643bd1b676778beb1c933</open-checksum>
- <location href="repodata/313329137b55fd333b2dc66394a6661a2befa6cc535d8460d92a4a78a9c581f0-primary.sqlite.bz2"/>
- <timestamp>1479418959</timestamp>
- <database_version>10</database_version>
- <size>2460</size>
- <open-size>32768</open-size>
-</data>
-<data type="other_db">
- <checksum type="sha256">b97cca3fe14bcf06c52be4449b6108f7731239ff221111dcce8aada5467f60dc</checksum>
- <open-checksum type="sha256">938156bcfc95828cb6857e1b2790dceaef57196843a80464ba5749772fc15e83</open-checksum>
- <location href="repodata/b97cca3fe14bcf06c52be4449b6108f7731239ff221111dcce8aada5467f60dc-other.sqlite.bz2"/>
- <timestamp>1479418959</timestamp>
- <database_version>10</database_version>
- <size>967</size>
- <open-size>6144</open-size>
-</data>
-<data type="other">
- <checksum type="sha256">31ac4db5d5ac593728fcc26aef82b7b93c4cc4dbec843786b1845b939b658553</checksum>
- <open-checksum type="sha256">2ea64cdb2f5ba3859af29fe67a85d61d5b4de23f3da1ee71d5af175d8d887ab6</open-checksum>
- <location href="repodata/31ac4db5d5ac593728fcc26aef82b7b93c4cc4dbec843786b1845b939b658553-other.xml.gz"/>
- <timestamp>1479418959</timestamp>
- <size>413</size>
- <open-size>1035</open-size>
-</data>
-<data type="filelists_db">
- <checksum type="sha256">4ac40fa3c6728c1401318e2e20a997436624e83dcf7a5f952b851ef422637773</checksum>
- <open-checksum type="sha256">8bc15efa19d02a5112e20c6ed1be17c5851287ddfba17aee2283ddb216dd08d7</open-checksum>
- <location href="repodata/4ac40fa3c6728c1401318e2e20a997436624e83dcf7a5f952b851ef422637773-filelists.sqlite.bz2"/>
- <timestamp>1479418959</timestamp>
- <database_version>10</database_version>
- <size>1131</size>
- <open-size>7168</open-size>
-</data>
+<repomd xmlns="http://linux.duke.edu/metadata/repo">
+ <data type="other">
+ <location href="repodata/other.xml.gz"/>
+ <checksum type="sha">6d44b25ecb901d242a28a6a457d9c6a240e93a72</checksum>
+ <timestamp>1512520884</timestamp>
+ <open-checksum type="sha">f3e463916922801d1be801e28304c84b2ee58638</open-checksum>
+ </data>
+ <data type="filelists">
+ <location href="repodata/filelists.xml.gz"/>
+ <checksum type="sha">21dcce9b122a907aa94ec7ec6108006c0f26e7c8</checksum>
+ <timestamp>1512520884</timestamp>
+ <open-checksum type="sha">9241f39704584bd27bfc0cf7b5e8aaa21945deb9</open-checksum>
+ </data>
+ <data type="primary">
+ <location href="repodata/primary.xml.gz"/>
+ <checksum type="sha">6896c706000889416d769616f32e381db3a46ef2</checksum>
+ <timestamp>1512520884</timestamp>
+ <open-checksum type="sha">976e163091ffd175e2bad28d6b3564495ec4b1e9</open-checksum>
+ </data>
</repomd>
diff --git a/spec/functional/resource/dnf_package_spec.rb b/spec/functional/resource/dnf_package_spec.rb
index 4c9ee6ca97..01611ef996 100644
--- a/spec/functional/resource/dnf_package_spec.rb
+++ b/spec/functional/resource/dnf_package_spec.rb
@@ -66,47 +66,47 @@ gpgcheck=0
flush_cache
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
it "does not install if the package is installed" do
- preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.10-1.x86_64.rpm")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be false
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
it "does not install twice" do
flush_cache
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be false
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
it "does not install if the prior version package is installed" do
- preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.2-1.x86_64.rpm")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be false
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.x86_64")
end
it "does not install if the i686 package is installed" do
skip "FIXME: do nothing, or install the x86_64 version?"
- preinstall("chef_rpm-1.10-1.fc24.i686.rpm")
+ preinstall("chef_rpm-1.10-1.i686.rpm")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be false
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.i686")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.i686")
end
it "does not install if the prior version i686 package is installed" do
skip "FIXME: do nothing, or install the x86_64 version?"
- preinstall("chef_rpm-1.2-1.fc24.i686.rpm")
+ preinstall("chef_rpm-1.2-1.i686.rpm")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be false
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.i686")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.i686")
end
end
@@ -116,7 +116,7 @@ gpgcheck=0
dnf_package.package_name("chef_rpm-1.10")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
it "works with an older version" do
@@ -124,15 +124,15 @@ gpgcheck=0
dnf_package.package_name("chef_rpm-1.2")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.x86_64")
end
it "works with an evr" do
flush_cache
- dnf_package.package_name("chef_rpm-0:1.2-1.fc24")
+ dnf_package.package_name("chef_rpm-0:1.2-1")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.x86_64")
end
it "works with a version glob" do
@@ -140,7 +140,7 @@ gpgcheck=0
dnf_package.package_name("chef_rpm-1*")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
it "works with a name glob + version glob" do
@@ -148,7 +148,7 @@ gpgcheck=0
dnf_package.package_name("chef_rp*-1*")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
end
@@ -160,7 +160,7 @@ gpgcheck=0
dnf_package.version("1.10")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
it "matches with a glob" do
@@ -169,25 +169,25 @@ gpgcheck=0
dnf_package.version("1*")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
it "matches the vr" do
flush_cache
dnf_package.package_name("chef_rpm")
- dnf_package.version("1.10-1.fc24")
+ dnf_package.version("1.10-1")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
it "matches the evr" do
flush_cache
dnf_package.package_name("chef_rpm")
- dnf_package.version("0:1.10-1.fc24")
+ dnf_package.version("0:1.10-1")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
it "matches with a vr glob" do
@@ -197,7 +197,7 @@ gpgcheck=0
dnf_package.version("1.10-1*")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
it "matches with an evr glob" do
@@ -207,28 +207,28 @@ gpgcheck=0
dnf_package.version("0:1.10-1*")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
end
context "downgrades" do
it "just work with DNF" do
- preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.10-1.x86_64.rpm")
dnf_package.version("1.2")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.x86_64")
end
it "throws a deprecation warning with allow_downgrade" do
Chef::Config[:treat_deprecation_warnings_as_errors] = false
expect(Chef).to receive(:deprecated).with(:dnf_package_allow_downgrade, /^the allow_downgrade property on the dnf_package provider is not used/)
- preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.10-1.x86_64.rpm")
dnf_package.version("1.2")
dnf_package.run_action(:install)
dnf_package.allow_downgrade true
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.x86_64")
end
end
@@ -238,7 +238,7 @@ gpgcheck=0
dnf_package.package_name("chef_rpm.x86_64")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
it "installs with 32-bit arch in the name" do
@@ -246,7 +246,7 @@ gpgcheck=0
dnf_package.package_name("chef_rpm.i686")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.i686")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.i686")
end
it "installs with 64-bit arch in the property" do
@@ -255,7 +255,7 @@ gpgcheck=0
dnf_package.arch("x86_64")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
it "installs with 32-bit arch in the property" do
@@ -264,7 +264,7 @@ gpgcheck=0
dnf_package.arch("i686")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.i686")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.i686")
end
end
@@ -274,23 +274,23 @@ gpgcheck=0
dnf_package.package_name("chef_rpm >= 1.2")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
it "when it is met, it does nothing" do
- preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.2-1.x86_64.rpm")
dnf_package.package_name("chef_rpm >= 1.2")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be false
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.x86_64")
end
it "when it is met, it does nothing" do
- preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.10-1.x86_64.rpm")
dnf_package.package_name("chef_rpm >= 1.2")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be false
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
it "with nothing intalled, it installs the latest version" do
@@ -298,23 +298,23 @@ gpgcheck=0
dnf_package.package_name("chef_rpm > 1.2")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
it "when it is not met by an installed rpm, it upgrades" do
- preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.2-1.x86_64.rpm")
dnf_package.package_name("chef_rpm > 1.2")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
it "when it is met by an installed rpm, it does nothing" do
- preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.10-1.x86_64.rpm")
dnf_package.package_name("chef_rpm > 1.2")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be false
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
it "when there is no solution to the contraint" do
@@ -324,7 +324,7 @@ gpgcheck=0
end
it "when there is no solution to the contraint but an rpm is preinstalled" do
- preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.10-1.x86_64.rpm")
dnf_package.package_name("chef_rpm > 2.0")
expect { dnf_package.run_action(:install) }.to raise_error(Chef::Exceptions::Package, /No candidate version available/)
end
@@ -349,61 +349,61 @@ gpgcheck=0
flush_cache
dnf_package.name "something"
dnf_package.package_name "somethingelse"
- dnf_package.source("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm")
+ dnf_package.source("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.x86_64.rpm")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.x86_64")
end
it "installs the package when the name is a path to a file" do
flush_cache
- dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm")
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.x86_64.rpm")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.x86_64")
end
it "does not downgrade the package with :install" do
- preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
- dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.10-1.x86_64.rpm")
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.x86_64.rpm")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be false
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
it "does not upgrade the package with :install" do
- preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
- dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.10-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.2-1.x86_64.rpm")
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.10-1.x86_64.rpm")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be false
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.x86_64")
end
it "is idempotent when the package is already installed" do
- preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
- dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.2-1.x86_64.rpm")
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.x86_64.rpm")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be false
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.x86_64")
end
end
context "with no available version" do
it "works when a package is installed" do
FileUtils.rm_f "/etc/yum.repos.d/chef-dnf-localtesting.repo"
- preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.2-1.x86_64.rpm")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be false
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.x86_64")
end
it "works with a local source" do
FileUtils.rm_f "/etc/yum.repos.d/chef-dnf-localtesting.repo"
flush_cache
- dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm")
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.x86_64.rpm")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.x86_64")
end
end
@@ -413,12 +413,12 @@ gpgcheck=0
dnf_package.package_name([ "chef_rpm.x86_64", "chef_rpm.i686" ] )
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.x86_64/)
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.i686/)
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.x86_64/)
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.i686/)
end
it "does nothing if both are installed" do
- preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm", "chef_rpm-1.10-1.fc24.i686.rpm")
+ preinstall("chef_rpm-1.10-1.x86_64.rpm", "chef_rpm-1.10-1.i686.rpm")
flush_cache
dnf_package.package_name([ "chef_rpm.x86_64", "chef_rpm.i686" ] )
dnf_package.run_action(:install)
@@ -426,21 +426,21 @@ gpgcheck=0
end
it "installs the second rpm if the first is installed" do
- preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.10-1.x86_64.rpm")
dnf_package.package_name([ "chef_rpm.x86_64", "chef_rpm.i686" ] )
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.x86_64/)
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.i686/)
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.x86_64/)
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.i686/)
end
it "installs the first rpm if the second is installed" do
- preinstall("chef_rpm-1.10-1.fc24.i686.rpm")
+ preinstall("chef_rpm-1.10-1.i686.rpm")
dnf_package.package_name([ "chef_rpm.x86_64", "chef_rpm.i686" ] )
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.x86_64/)
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.i686/)
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.x86_64/)
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.i686/)
end
# unlikely to work consistently correct, okay to deprecate the arch-array in favor of the arch in the name
@@ -450,35 +450,35 @@ gpgcheck=0
dnf_package.arch(%w{x86_64 i686})
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.x86_64/)
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.i686/)
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.x86_64/)
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.i686/)
end
# unlikely to work consistently correct, okay to deprecate the arch-array in favor of the arch in the name
it "installs the second rpm if the first is installed (muti-arch)" do
- preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.10-1.x86_64.rpm")
dnf_package.package_name(%w{chef_rpm chef_rpm} )
dnf_package.arch(%w{x86_64 i686})
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.x86_64/)
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.i686/)
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.x86_64/)
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.i686/)
end
# unlikely to work consistently correct, okay to deprecate the arch-array in favor of the arch in the name
it "installs the first rpm if the second is installed (muti-arch)" do
- preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.10-1.x86_64.rpm")
dnf_package.package_name(%w{chef_rpm chef_rpm} )
dnf_package.arch(%w{x86_64 i686})
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.x86_64/)
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.fc24.i686/)
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.x86_64/)
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to match(/chef_rpm-1.10-1.i686/)
end
# unlikely to work consistently correct, okay to deprecate the arch-array in favor of the arch in the name
it "does nothing if both are installed (muti-arch)" do
- preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm", "chef_rpm-1.10-1.fc24.i686.rpm")
+ preinstall("chef_rpm-1.10-1.x86_64.rpm", "chef_rpm-1.10-1.i686.rpm")
dnf_package.package_name(%w{chef_rpm chef_rpm} )
dnf_package.arch(%w{x86_64 i686})
dnf_package.run_action(:install)
@@ -490,22 +490,22 @@ gpgcheck=0
describe ":upgrade" do
context "downgrades" do
it "just work with DNF" do
- preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.10-1.x86_64.rpm")
dnf_package.version("1.2")
dnf_package.run_action(:install)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.x86_64")
end
it "throws a deprecation warning with allow_downgrade" do
Chef::Config[:treat_deprecation_warnings_as_errors] = false
expect(Chef).to receive(:deprecated).with(:dnf_package_allow_downgrade, /^the allow_downgrade property on the dnf_package provider is not used/)
- preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.10-1.x86_64.rpm")
dnf_package.version("1.2")
dnf_package.run_action(:install)
dnf_package.allow_downgrade true
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.x86_64")
end
end
@@ -514,62 +514,62 @@ gpgcheck=0
flush_cache
dnf_package.name "something"
dnf_package.package_name "somethingelse"
- dnf_package.source("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm")
+ dnf_package.source("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.x86_64.rpm")
dnf_package.run_action(:upgrade)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.x86_64")
end
it "installs the package when the name is a path to a file" do
flush_cache
- dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm")
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.x86_64.rpm")
dnf_package.run_action(:upgrade)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.x86_64")
end
it "downgrades the package" do
- preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
- dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.10-1.x86_64.rpm")
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.x86_64.rpm")
dnf_package.run_action(:upgrade)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.x86_64")
end
it "upgrades the package" do
- preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
- dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.10-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.2-1.x86_64.rpm")
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.10-1.x86_64.rpm")
dnf_package.run_action(:upgrade)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
it "is idempotent when the package is already installed" do
- preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
- dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.2-1.x86_64.rpm")
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.x86_64.rpm")
dnf_package.run_action(:upgrade)
expect(dnf_package.updated_by_last_action?).to be false
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.x86_64")
end
end
context "with no available version" do
it "works when a package is installed" do
FileUtils.rm_f "/etc/yum.repos.d/chef-dnf-localtesting.repo"
- preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
- dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.2-1.x86_64.rpm")
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.x86_64.rpm")
dnf_package.run_action(:upgrade)
expect(dnf_package.updated_by_last_action?).to be false
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.x86_64")
end
it "works with a local source" do
FileUtils.rm_f "/etc/yum.repos.d/chef-dnf-localtesting.repo"
flush_cache
- dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.fc24.x86_64.rpm")
+ dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.x86_64.rpm")
dnf_package.run_action(:upgrade)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.x86_64")
end
end
end
@@ -585,14 +585,14 @@ gpgcheck=0
end
it "removes the package if the package is installed" do
- preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.10-1.x86_64.rpm")
dnf_package.run_action(:remove)
expect(dnf_package.updated_by_last_action?).to be true
expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("package chef_rpm is not installed")
end
it "does not remove the package twice" do
- preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.10-1.x86_64.rpm")
dnf_package.run_action(:remove)
expect(dnf_package.updated_by_last_action?).to be true
expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("package chef_rpm is not installed")
@@ -602,7 +602,7 @@ gpgcheck=0
end
it "removes the package if the prior version package is installed" do
- preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.2-1.x86_64.rpm")
dnf_package.run_action(:remove)
expect(dnf_package.updated_by_last_action?).to be true
expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("package chef_rpm is not installed")
@@ -610,7 +610,7 @@ gpgcheck=0
it "removes the package if the i686 package is installed" do
skip "FIXME: should this be fixed or is the current behavior correct?"
- preinstall("chef_rpm-1.10-1.fc24.i686.rpm")
+ preinstall("chef_rpm-1.10-1.i686.rpm")
dnf_package.run_action(:remove)
expect(dnf_package.updated_by_last_action?).to be true
expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("package chef_rpm is not installed")
@@ -618,7 +618,7 @@ gpgcheck=0
it "removes the package if the prior version i686 package is installed" do
skip "FIXME: should this be fixed or is the current behavior correct?"
- preinstall("chef_rpm-1.2-1.fc24.i686.rpm")
+ preinstall("chef_rpm-1.2-1.i686.rpm")
dnf_package.run_action(:remove)
expect(dnf_package.updated_by_last_action?).to be true
expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("package chef_rpm is not installed")
@@ -635,48 +635,48 @@ gpgcheck=0
end
it "removes the package if the package is installed" do
- preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.10-1.x86_64.rpm")
dnf_package.run_action(:remove)
expect(dnf_package.updated_by_last_action?).to be true
expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("package chef_rpm is not installed")
end
it "removes the package if the prior version package is installed" do
- preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.2-1.x86_64.rpm")
dnf_package.run_action(:remove)
expect(dnf_package.updated_by_last_action?).to be true
expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("package chef_rpm is not installed")
end
it "does nothing if the i686 package is installed" do
- preinstall("chef_rpm-1.10-1.fc24.i686.rpm")
+ preinstall("chef_rpm-1.10-1.i686.rpm")
dnf_package.run_action(:remove)
expect(dnf_package.updated_by_last_action?).to be false
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.i686")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.i686")
end
it "does nothing if the prior version i686 package is installed" do
- preinstall("chef_rpm-1.2-1.fc24.i686.rpm")
+ preinstall("chef_rpm-1.2-1.i686.rpm")
dnf_package.run_action(:remove)
expect(dnf_package.updated_by_last_action?).to be false
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.fc24.i686")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.2-1.i686")
end
end
context "with 32-bit arch" do
let(:package_name) { "chef_rpm.i686" }
it "removes only the 32-bit arch if both are installed" do
- preinstall("chef_rpm-1.10-1.fc24.x86_64.rpm", "chef_rpm-1.10-1.fc24.i686.rpm")
+ preinstall("chef_rpm-1.10-1.x86_64.rpm", "chef_rpm-1.10-1.i686.rpm")
dnf_package.run_action(:remove)
expect(dnf_package.updated_by_last_action?).to be true
- expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.fc24.x86_64")
+ expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("chef_rpm-1.10-1.x86_64")
end
end
context "with no available version" do
it "works when a package is installed" do
FileUtils.rm_f "/etc/yum.repos.d/chef-dnf-localtesting.repo"
- preinstall("chef_rpm-1.2-1.fc24.x86_64.rpm")
+ preinstall("chef_rpm-1.2-1.x86_64.rpm")
dnf_package.run_action(:remove)
expect(dnf_package.updated_by_last_action?).to be true
expect(shell_out("rpm -q chef_rpm").stdout.chomp).to eql("package chef_rpm is not installed")
diff --git a/spec/functional/resource/yum_package_spec.rb b/spec/functional/resource/yum_package_spec.rb
new file mode 100644
index 0000000000..b06bbe686a
--- /dev/null
+++ b/spec/functional/resource/yum_package_spec.rb
@@ -0,0 +1,949 @@
+#
+# Copyright:: Copyright 2016-2018, Chef Software Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require "spec_helper"
+require "functional/resource/base"
+require "chef/mixin/shell_out"
+
+# run this test only for following platforms.
+exclude_test = !(%w{rhel fedora}.include?(ohai[:platform_family]) && !File.exist?("/usr/bin/dnf"))
+describe Chef::Resource::YumPackage, :requires_root, :external => exclude_test do
+ include Chef::Mixin::ShellOut
+
+ # NOTE: every single test here either needs to explicitly call flush_cache or needs to explicitly
+ # call preinstall (which explicitly calls flush_cache). It is your responsibility to do one or the
+ # other in order to minimize calling flush_cache a half dozen times per test.
+
+ def flush_cache
+ Chef::Resource::YumPackage.new("shouldnt-matter", run_context).run_action(:flush_cache)
+ end
+
+ def preinstall(*rpms)
+ rpms.each do |rpm|
+ shell_out!("rpm -ivh #{CHEF_SPEC_ASSETS}/yumrepo/#{rpm}")
+ end
+ flush_cache
+ end
+
+ before(:all) do
+ shell_out!("yum -y install yum-utils")
+ end
+
+ before(:each) do
+ File.open("/etc/yum.repos.d/chef-yum-localtesting.repo", "w+") do |f|
+ f.write <<-EOF
+[chef-yum-localtesting]
+name=Chef DNF spec testing repo
+baseurl=file://#{CHEF_SPEC_ASSETS}/yumrepo
+enable=1
+gpgcheck=0
+ EOF
+ end
+ shell_out!("rpm -qa --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' | grep chef_rpm | xargs -r rpm -e")
+ # next line is useful cleanup if you happen to have been testing both yum + dnf func tests on the same box and
+ # have some dnf garbage left around
+ FileUtils.rm_f "/etc/yum.repos.d/chef-dnf-localtesting.repo"
+ end
+
+ after(:all) do
+ shell_out!("rpm -qa --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' | grep chef_rpm | xargs -r rpm -e")
+ FileUtils.rm_f "/etc/yum.repos.d/chef-yum-localtesting.repo"
+ end
+
+ let(:package_name) { "chef_rpm" }
+ let(:yum_package) do
+ r = Chef::Resource::YumPackage.new(package_name, run_context)
+ r.options("--nogpgcheck")
+ r
+ end
+
+ def pkg_arch
+ ohai[:kernel][:machine]
+ end
+
+ describe ":install" do
+ context "vanilla use case" do
+ let(:package_name) { "chef_rpm" }
+
+ it "installs if the package is not installed" do
+ flush_cache
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^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.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
+ it "does not install twice" do
+ flush_cache
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^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.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+
+ 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.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.i686$")
+ end
+
+ 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.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.i686$")
+ end
+ end
+
+ context "with versions or globs in the name" do
+ it "works with a version" do
+ flush_cache
+ yum_package.package_name("chef_rpm-1.10")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
+ it "works with an older version" do
+ flush_cache
+ yum_package.package_name("chef_rpm-1.2")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+
+ it "works with an evra" do
+ flush_cache
+ yum_package.package_name("chef_rpm-0:1.2-1.#{pkg_arch}")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+
+ it "works with version and release" do
+ flush_cache
+ yum_package.package_name("chef_rpm-1.2-1")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+
+ it "works with a version glob" do
+ flush_cache
+ yum_package.package_name("chef_rpm-1*")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
+ it "works with a name glob + version glob" do
+ flush_cache
+ yum_package.package_name("chef_rp*-1*")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ 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.package_name("chef_rpm-1.10")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}")
+ 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.allow_downgrade true
+ yum_package.package_name("chef_rpm-1.2")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+ end
+
+ # version only matches the actual yum version, does not work with epoch or release or combined evr
+ context "with version property" do
+ it "matches the full version" do
+ flush_cache
+ yum_package.package_name("chef_rpm")
+ yum_package.version("1.10")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ 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.package_name("chef_rpm")
+ yum_package.version("1*")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
+ it "matches the vr" do
+ flush_cache
+ yum_package.package_name("chef_rpm")
+ yum_package.version("1.10-1")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
+ it "matches the evr" do
+ flush_cache
+ yum_package.package_name("chef_rpm")
+ yum_package.version("0:1.10-1")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
+ it "matches with a vr glob" do
+ pending "doesn't work on command line either"
+ flush_cache
+ yum_package.package_name("chef_rpm")
+ yum_package.version("1.10-1*")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
+ it "matches with an evr glob" do
+ pending "doesn't work on command line either"
+ flush_cache
+ yum_package.package_name("chef_rpm")
+ yum_package.version("0:1.10-1*")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+ end
+
+ context "downgrades" do
+ it "downgrades the package when allow_downgrade" do
+ flush_cache
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ yum_package.package_name("chef_rpm")
+ yum_package.allow_downgrade true
+ yum_package.version("1.2-1")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-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.package_name("chef_rpm.#{pkg_arch}")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
+ it "installs with 32-bit arch in the name" do
+ flush_cache
+ yum_package.package_name("chef_rpm.i686")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.i686$")
+ end
+
+ it "installs with 64-bit arch in the property" do
+ flush_cache
+ yum_package.package_name("chef_rpm")
+ yum_package.arch("#{pkg_arch}")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
+ it "installs with 32-bit arch in the property" do
+ flush_cache
+ yum_package.package_name("chef_rpm")
+ yum_package.arch("i686")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.i686$")
+ end
+ end
+
+ context "with constraints" do
+ it "with nothing installed, it installs the latest version", not_rhel5: true do
+ flush_cache
+ yum_package.package_name("chef_rpm >= 1.2")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
+ it "when it is met, it does nothing", not_rhel5: true do
+ preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.package_name("chef_rpm >= 1.2")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+
+ it "when it is met, it does nothing", not_rhel5: true do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ yum_package.package_name("chef_rpm >= 1.2")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
+ it "with nothing intalled, it installs the latest version", not_rhel5: true do
+ flush_cache
+ yum_package.package_name("chef_rpm > 1.2")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
+ it "when it is not met by an installed rpm, it upgrades", not_rhel5: true do
+ preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.package_name("chef_rpm > 1.2")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
+ it "with an equality constraint, when it is not met by an installed rpm, it upgrades", not_rhel5: true do
+ preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.package_name("chef_rpm = 1.10")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
+ it "with an equality constraint, when it is met by an installed rpm, it does nothing", not_rhel5: true do
+ preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.package_name("chef_rpm = 1.2")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+
+ it "when it is met by an installed rpm, it does nothing", not_rhel5: true do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ yum_package.package_name("chef_rpm > 1.2")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
+ it "when there is no solution to the contraint", not_rhel5: true do
+ flush_cache
+ yum_package.package_name("chef_rpm > 2.0")
+ expect { yum_package.run_action(:install) }.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", not_rhel5: true do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ yum_package.package_name("chef_rpm > 2.0")
+ expect { yum_package.run_action(:install) }.to raise_error(Chef::Exceptions::Package, /No candidate version available/)
+ end
+
+ it "with a less than constraint, when nothing is installed, it installs", not_rhel5: true do
+ flush_cache
+ yum_package.allow_downgrade true
+ yum_package.package_name("chef_rpm < 1.10")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+
+ it "with a less than constraint, when the install version matches, it does nothing", not_rhel5: true do
+ preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.allow_downgrade true
+ yum_package.package_name("chef_rpm < 1.10")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+
+ it "with a less than constraint, when the install version fails, it should downgrade", not_rhel5: true do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ yum_package.allow_downgrade true
+ yum_package.package_name("chef_rpm < 1.10")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+ end
+
+ context "with source arguments" do
+ it "raises an exception when the package does not exist" do
+ flush_cache
+ yum_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/this-file-better-not-exist.rpm")
+ expect { yum_package.run_action(:install) }.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.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/this-file-better-not-exist.rpm")
+ yum_package.run_action(:install)
+ expect { yum_package.run_action(:install) }.not_to raise_error
+ end
+
+ it "installs the package when using the source argument" do
+ flush_cache
+ yum_package.name "something"
+ yum_package.package_name "somethingelse"
+ yum_package.source("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+
+ it "installs the package when the name is a path to a file" do
+ flush_cache
+ yum_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+
+ it "downgrade on a local file raises an error", not_rhel5: true do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ yum_package.version "1.2-1"
+ yum_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ expect { yum_package.run_action(:install) }.to raise_error(Mixlib::ShellOut::ShellCommandFailed)
+ end
+
+ it "downgrade on a local file with allow_downgrade true works" do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ yum_package.version "1.2-1"
+ yum_package.allow_downgrade true
+ yum_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+
+ it "does not downgrade the package with :install" do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ yum_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^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.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^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.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+ end
+
+ context "with no available version" 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.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+
+ it "works with a local source" do
+ FileUtils.rm_f "/etc/yum.repos.d/chef-yum-localtesting.repo"
+ flush_cache
+ yum_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+ end
+
+ context "multipackage with arches", :intel_64bit do
+ it "installs two rpms" do
+ flush_cache
+ yum_package.package_name([ "chef_rpm.#{pkg_arch}", "chef_rpm.i686" ] )
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match(/^chef_rpm-1.10-1.#{pkg_arch}$/)
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match(/^chef_rpm-1.10-1.i686$/)
+ 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.package_name([ "chef_rpm.#{pkg_arch}", "chef_rpm.i686" ] )
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be false
+ end
+
+ it "installs the second rpm if the first is installed" do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ yum_package.package_name([ "chef_rpm.#{pkg_arch}", "chef_rpm.i686" ] )
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match(/^chef_rpm-1.10-1.#{pkg_arch}$/)
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match(/^chef_rpm-1.10-1.i686$/)
+ end
+
+ it "installs the first rpm if the second is installed" do
+ preinstall("chef_rpm-1.10-1.i686.rpm")
+ yum_package.package_name([ "chef_rpm.#{pkg_arch}", "chef_rpm.i686" ] )
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match(/^chef_rpm-1.10-1.#{pkg_arch}$/)
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match(/^chef_rpm-1.10-1.i686$/)
+ end
+
+ # unlikely to work consistently correct, okay to deprecate the arch-array in favor of the arch in the name
+ it "installs two rpms with multi-arch" do
+ flush_cache
+ yum_package.package_name(%w{chef_rpm chef_rpm} )
+ yum_package.arch([pkg_arch, "i686"])
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match(/^chef_rpm-1.10-1.#{pkg_arch}$/)
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match(/^chef_rpm-1.10-1.i686$/)
+ end
+
+ # unlikely to work consistently correct, okay to deprecate the arch-array in favor of the arch in the name
+ it "installs the second rpm if the first is installed (muti-arch)" do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ yum_package.package_name(%w{chef_rpm chef_rpm} )
+ yum_package.arch([pkg_arch, "i686"])
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match(/^chef_rpm-1.10-1.#{pkg_arch}$/)
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match(/^chef_rpm-1.10-1.i686$/)
+ end
+
+ # unlikely to work consistently correct, okay to deprecate the arch-array in favor of the arch in the name
+ it "installs the first rpm if the second is installed (muti-arch)" do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ yum_package.package_name(%w{chef_rpm chef_rpm} )
+ yum_package.arch([pkg_arch, "i686"])
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match(/^chef_rpm-1.10-1.#{pkg_arch}$/)
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match(/^chef_rpm-1.10-1.i686$/)
+ end
+
+ # unlikely to work consistently correct, okay to deprecate the arch-array in favor of the arch in the name
+ it "does nothing if both are installed (muti-arch)" do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm", "chef_rpm-1.10-1.i686.rpm")
+ yum_package.package_name(%w{chef_rpm chef_rpm} )
+ yum_package.arch([pkg_arch, "i686"])
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be false
+ end
+ end
+
+ context "repo controls" do
+ it "should fail with the repo disabled" do
+ flush_cache
+ yum_package.options("--disablerepo=chef-yum-localtesting")
+ expect { yum_package.run_action(:install) }.to raise_error(Chef::Exceptions::Package, /No candidate version available/)
+ end
+
+ it "should work to enable a disabled repo", not_rhel5: true do
+ shell_out!("yum-config-manager --disable chef-yum-localtesting")
+ flush_cache
+ expect { yum_package.run_action(:install) }.to raise_error(Chef::Exceptions::Package, /No candidate version available/)
+ flush_cache
+ yum_package.options("--enablerepo=chef-yum-localtesting")
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
+ it "when an idempotent install action is run, does not leave repos disabled" do
+ flush_cache
+ # this is a bit tricky -- we need this action to be idempotent, so that it doesn't recycle any
+ # caches, but need it to hit whatavailable with the repo disabled. using :upgrade like this
+ # accomplishes both those goals (it would be easier if we had other rpms in this repo, but with
+ # one rpm we neeed to do this).
+ preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.options("--disablerepo=chef-yum-localtesting")
+ yum_package.run_action(:upgrade)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^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.package_name("chef_rpm-1.10-1.#{pkg_arch}")
+ yum_package.options(nil)
+ yum_package.run_action(:install)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+ end
+ end
+
+ describe ":upgrade" do
+
+ context "with source arguments" do
+ it "installs the package when using the source argument" do
+ flush_cache
+ yum_package.name "something"
+ yum_package.package_name "somethingelse"
+ yum_package.source("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.run_action(:upgrade)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+
+ it "installs the package when the name is a path to a file" do
+ flush_cache
+ yum_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.run_action(:upgrade)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+
+ it "downgrades the package when allow_downgrade is true" do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ yum_package.allow_downgrade true
+ yum_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.run_action(:upgrade)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+
+ it "upgrades the package" do
+ preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ yum_package.run_action(:upgrade)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-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.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.run_action(:upgrade)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+ end
+
+ context "with no available version" 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.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.run_action(:upgrade)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+
+ it "works with a local source" do
+ FileUtils.rm_f "/etc/yum.repos.d/chef-yum-localtesting.repo"
+ flush_cache
+ yum_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.run_action(:upgrade)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+ end
+
+ context "version pinning" do
+ it "with an equality pin in the name it upgrades a prior package" do
+ preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.package_name("chef_rpm-1.10")
+ yum_package.run_action(:upgrade)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
+ it "with a prco equality pin in the name it upgrades a prior package", not_rhel5: true do
+ preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.package_name("chef_rpm == 1.10")
+ yum_package.run_action(:upgrade)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
+ it "with an equality pin in the name it downgrades a later package" do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ yum_package.allow_downgrade true
+ yum_package.package_name("chef_rpm-1.2")
+ yum_package.run_action(:upgrade)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+
+ it "with a prco equality pin in the name it downgrades a later package", not_rhel5: true do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ yum_package.allow_downgrade true
+ yum_package.package_name("chef_rpm == 1.2")
+ yum_package.run_action(:upgrade)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+
+ it "with a > pin in the name and no rpm installed it installs", not_rhel5: true do
+ flush_cache
+ yum_package.package_name("chef_rpm > 1.2")
+ yum_package.run_action(:upgrade)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
+ it "with a < pin in the name and no rpm installed it installs", not_rhel5: true do
+ flush_cache
+ yum_package.package_name("chef_rpm < 1.10")
+ yum_package.run_action(:upgrade)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+
+ it "with a > pin in the name and matching rpm installed it does nothing", not_rhel5: true do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ yum_package.package_name("chef_rpm > 1.2")
+ yum_package.run_action(:upgrade)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
+ it "with a < pin in the name and no rpm installed it installs", not_rhel5: true do
+ preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.package_name("chef_rpm < 1.10")
+ yum_package.run_action(:upgrade)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+
+ it "with a > pin in the name and non-matching rpm installed it upgrades", not_rhel5: true do
+ preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.package_name("chef_rpm > 1.2")
+ yum_package.run_action(:upgrade)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+
+ it "with a < pin in the name and non-matching rpm installed it downgrades", not_rhel5: true do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ yum_package.allow_downgrade true
+ yum_package.package_name("chef_rpm < 1.10")
+ yum_package.run_action(:upgrade)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
+ end
+ end
+ end
+
+ describe ":remove" do
+ context "vanilla use case" do
+ let(:package_name) { "chef_rpm" }
+ it "does nothing if the package is not installed" do
+ flush_cache
+ yum_package.run_action(:remove)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^package chef_rpm is not installed$")
+ end
+
+ it "removes the package if the package is installed" do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ yum_package.run_action(:remove)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^package chef_rpm is not installed$")
+ end
+
+ it "does not remove the package twice" do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ yum_package.run_action(:remove)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^package chef_rpm is not installed$")
+ yum_package.run_action(:remove)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^package chef_rpm is not installed$")
+ end
+
+ it "removes the package if the prior version package is installed" do
+ preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.run_action(:remove)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^package chef_rpm is not installed$")
+ end
+
+ it "removes the package if the i686 package is installed", :intel_64bit do
+ skip "FIXME: should this be fixed or is the current behavior correct?"
+ preinstall("chef_rpm-1.10-1.i686.rpm")
+ yum_package.run_action(:remove)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^package chef_rpm is not installed$")
+ end
+
+ it "removes the package if the prior version i686 package is installed", :intel_64bit do
+ skip "FIXME: should this be fixed or is the current behavior correct?"
+ preinstall("chef_rpm-1.2-1.i686.rpm")
+ yum_package.run_action(:remove)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^package chef_rpm is not installed$")
+ end
+ end
+
+ context "with 64-bit arch", :intel_64bit do
+ let(:package_name) { "chef_rpm.#{pkg_arch}" }
+ it "does nothing if the package is not installed" do
+ flush_cache
+ yum_package.run_action(:remove)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^package chef_rpm is not installed$")
+ end
+
+ it "removes the package if the package is installed" do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ yum_package.run_action(:remove)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^package chef_rpm is not installed$")
+ end
+
+ it "removes the package if the prior version package is installed" do
+ preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ yum_package.run_action(:remove)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^package chef_rpm is not installed$")
+ end
+
+ it "does nothing if the i686 package is installed" do
+ preinstall("chef_rpm-1.10-1.i686.rpm")
+ yum_package.run_action(:remove)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.i686$")
+ end
+
+ it "does nothing if the prior version i686 package is installed" do
+ preinstall("chef_rpm-1.2-1.i686.rpm")
+ yum_package.run_action(:remove)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.i686$")
+ end
+ end
+
+ context "with 32-bit arch", :intel_64bit do
+ let(:package_name) { "chef_rpm.i686" }
+ it "removes only the 32-bit arch if both are installed" do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm", "chef_rpm-1.10-1.i686.rpm")
+ yum_package.run_action(:remove)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$")
+ end
+ end
+
+ context "with no available version" 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.run_action(:remove)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^package chef_rpm is not installed$")
+ end
+ end
+ end
+
+ describe ":lock and :unlock" do
+ before(:all) do
+ shell_out!("yum -y install yum-versionlock")
+ end
+
+ before(:each) do
+ shell_out("yum versionlock delete '*:chef_rpm-*'") # will exit with error when nothing is locked, we don't care
+ end
+
+ it "locks an rpm" do
+ flush_cache
+ yum_package.package_name("chef_rpm")
+ yum_package.run_action(:lock)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("yum versionlock list").stdout.chomp).to match("^0:chef_rpm-")
+ end
+
+ it "does not lock if its already locked" do
+ flush_cache
+ shell_out!("yum versionlock add chef_rpm")
+ yum_package.package_name("chef_rpm")
+ yum_package.run_action(:lock)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("yum versionlock list").stdout.chomp).to match("^0:chef_rpm-")
+ end
+
+ it "unlocks an rpm" do
+ flush_cache
+ shell_out!("yum versionlock add chef_rpm")
+ yum_package.package_name("chef_rpm")
+ yum_package.run_action(:unlock)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("yum versionlock list").stdout.chomp).not_to match("^0:chef_rpm-")
+ end
+
+ it "does not unlock an already locked rpm" do
+ flush_cache
+ yum_package.package_name("chef_rpm")
+ yum_package.run_action(:unlock)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("yum versionlock list").stdout.chomp).not_to match("^0:chef_rpm-")
+ end
+
+ it "check that we can lock based on provides" do
+ flush_cache
+ yum_package.package_name("chef_rpm_provides")
+ yum_package.run_action(:lock)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("yum versionlock list").stdout.chomp).to match("^0:chef_rpm-")
+ end
+
+ it "check that we can unlock based on provides" do
+ flush_cache
+ shell_out!("yum versionlock add chef_rpm")
+ yum_package.package_name("chef_rpm_provides")
+ yum_package.run_action(:unlock)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("yum versionlock list").stdout.chomp).not_to match("^0:chef_rpm-")
+ end
+ end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 78f8da7b51..c57c83e100 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -184,6 +184,16 @@ RSpec.configure do |config|
config.filter_run_excluding :broken => true
config.filter_run_excluding :not_wpar => true unless wpar?
config.filter_run_excluding :not_supported_under_fips => true if fips?
+ config.filter_run_excluding :rhel => true unless rhel?
+ config.filter_run_excluding :rhel5 => true unless rhel5?
+ config.filter_run_excluding :rhel6 => true unless rhel6?
+ config.filter_run_excluding :rhel7 => true unless rhel7?
+ config.filter_run_excluding :intel_64bit => true unless intel_64bit?
+ config.filter_run_excluding :not_rhel => true if rhel?
+ config.filter_run_excluding :not_rhel5 => true if rhel5?
+ config.filter_run_excluding :not_rhel6 => true if rhel6?
+ config.filter_run_excluding :not_rhel7 => true if rhel7?
+ config.filter_run_excluding :not_intel_64bit => true if intel_64bit?
# these let us use chef: ">= 13" or ruby: "~> 2.0.0" or any other Gem::Dependency-style constraint
config.filter_run_excluding chef: DependencyProc.with(Chef::VERSION)
diff --git a/spec/support/platform_helpers.rb b/spec/support/platform_helpers.rb
index f015a6cd50..1718632186 100644
--- a/spec/support/platform_helpers.rb
+++ b/spec/support/platform_helpers.rb
@@ -159,6 +159,26 @@ def freebsd?
!!(RUBY_PLATFORM =~ /freebsd/)
end
+def intel_64bit?
+ !!(ohai[:kernel][:machine] == "x86_64")
+end
+
+def rhel?
+ !!(ohai[:platform_family] == "rhel")
+end
+
+def rhel5?
+ rhel? && !!(ohai[:platform_version].to_i == 5)
+end
+
+def rhel6?
+ rhel? && !!(ohai[:platform_version].to_i == 6)
+end
+
+def rhel7?
+ rhel? && !!(ohai[:platform_version].to_i == 7)
+end
+
def debian_family?
!!(ohai[:platform_family] == "debian")
end
diff --git a/spec/unit/provider/package/yum/python_helper_spec.rb b/spec/unit/provider/package/yum/python_helper_spec.rb
new file mode 100644
index 0000000000..ba91e2f24a
--- /dev/null
+++ b/spec/unit/provider/package/yum/python_helper_spec.rb
@@ -0,0 +1,29 @@
+#
+# Copyright:: Copyright 2017-2017, Chef Software Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require "spec_helper"
+
+# NOTE: most of the tests of this functionality are baked into the func tests for the yum package provider
+
+describe Chef::Provider::Package::Yum::PythonHelper do
+ let(:helper) { Chef::Provider::Package::Yum::PythonHelper.instance }
+
+ it "propagates stacktraces on stderr from the forked subprocess", :rhel do
+ allow(helper).to receive(:yum_command).and_return("ruby -e 'raise \"your hands in the air\"'")
+ expect { helper.package_query(:whatprovides, "tcpdump") }.to raise_error(/your hands in the air/)
+ end
+end
diff --git a/spec/unit/provider/package/yum/yum_cache_spec.rb b/spec/unit/provider/package/yum/yum_cache_spec.rb
index e9d615d734..6b2a617ac8 100644
--- a/spec/unit/provider/package/yum/yum_cache_spec.rb
+++ b/spec/unit/provider/package/yum/yum_cache_spec.rb
@@ -1,6 +1,5 @@
#
-# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2016, Chef Software, Inc.
+# Copyright:: Copyright 2018-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,9 +18,92 @@
require "spec_helper"
describe Chef::Provider::Package::Yum::YumCache do
+ let(:yum_cache) { Chef::Provider::Package::Yum::YumCache.instance }
- it "can find yum-dump.py" do
- expect(File.exist?(Chef::Provider::Package::Yum::YumCache.instance.yum_dump_path)).to be true
+ let(:python_helper) { instance_double(Chef::Provider::Package::Yum::PythonHelper) }
+
+ def yum_version(name, version, arch)
+ Chef::Provider::Package::Yum::Version.new(name, version, arch)
+ end
+
+ before(:each) do
+ allow( yum_cache ).to receive(:python_helper).and_return(python_helper)
+ end
+
+ it "package_available? returns false if the helper reports the available version is nil" do
+ expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", arch: nil).and_return( yum_version("foo", nil, nil) )
+ expect( yum_cache.package_available?("foo") ).to be false
+ end
+
+ it "package_available? returns true if the helper returns an available version" do
+ expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", arch: nil).and_return( yum_version("foo", "1.2.3-1", "x86_64") )
+ expect( yum_cache.package_available?("foo") ).to be true
+ end
+
+ it "version_available? returns false if the helper reports the available version is nil" do
+ expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", version: "1.2.3", arch: nil).and_return( yum_version("foo", nil, nil) )
+ expect( yum_cache.version_available?("foo", "1.2.3") ).to be false
+ end
+
+ it "version_available? returns true if the helper returns an available version" do
+ expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", version: "1.2.3", arch: nil).and_return( yum_version("foo", "1.2.3-1", "x86_64") )
+ expect( yum_cache.version_available?("foo", "1.2.3") ).to be true
+ end
+
+ it "version_available? with an arch returns false if the helper reports the available version is nil" do
+ expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", version: "1.2.3", arch: "x86_64").and_return( yum_version("foo", nil, nil) )
+ expect( yum_cache.version_available?("foo", "1.2.3", "x86_64") ).to be false
+ end
+
+ it "version_available? with an arch returns true if the helper returns an available version" do
+ expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", version: "1.2.3", arch: "x86_64").and_return( yum_version("foo", "1.2.3-1", "x86_64") )
+ expect( yum_cache.version_available?("foo", "1.2.3", "x86_64") ).to be true
+ end
+
+ [ :refresh, :reload, :reload_installed, :reload_provides, :reset, :reset_installed ].each do |method|
+ it "restarts the python helper when #{method} is called" do
+ expect( python_helper ).to receive(:restart)
+ yum_cache.send(method)
+ end
+ end
+
+ it "installed_version? returns nil if the helper reports the installed version is nil" do
+ expect( python_helper ).to receive(:package_query).with(:whatinstalled, "foo", arch: nil).and_return( yum_version("foo", nil, nil) )
+ expect( yum_cache.installed_version("foo") ).to be nil
+ end
+
+ it "installed_version? returns version string if the helper returns an installed version" do
+ expect( python_helper ).to receive(:package_query).with(:whatinstalled, "foo", arch: nil).and_return( yum_version("foo", "1.2.3-1", "x86_64") )
+ expect( yum_cache.installed_version("foo") ).to eql("1.2.3-1.x86_64")
+ end
+
+ it "installed_version? returns nil if the helper reports the installed version is nil" do
+ expect( python_helper ).to receive(:package_query).with(:whatinstalled, "foo", arch: "x86_64").and_return( yum_version("foo", nil, nil) )
+ expect( yum_cache.installed_version("foo", "x86_64") ).to be nil
+ end
+
+ it "installed_version? returns version string if the helper returns an installed version" do
+ expect( python_helper ).to receive(:package_query).with(:whatinstalled, "foo", arch: "x86_64").and_return( yum_version("foo", "1.2.3-1", "x86_64") )
+ expect( yum_cache.installed_version("foo", "x86_64") ).to eql("1.2.3-1.x86_64")
+ end
+
+ it "available_version? returns nil if the helper reports the available version is nil" do
+ expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", arch: nil).and_return( yum_version("foo", nil, nil) )
+ expect( yum_cache.available_version("foo") ).to be nil
+ end
+
+ it "available_version? returns version string if the helper returns an available version" do
+ expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", arch: nil).and_return( yum_version("foo", "1.2.3-1", "x86_64") )
+ expect( yum_cache.available_version("foo") ).to eql("1.2.3-1.x86_64")
+ end
+
+ it "available_version? returns nil if the helper reports the available version is nil" do
+ expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", arch: "x86_64").and_return( yum_version("foo", nil, nil) )
+ expect( yum_cache.available_version("foo", "x86_64") ).to be nil
end
+ it "available_version? returns version string if the helper returns an available version" do
+ expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", arch: "x86_64").and_return( yum_version("foo", "1.2.3-1", "x86_64") )
+ expect( yum_cache.available_version("foo", "x86_64") ).to eql("1.2.3-1.x86_64")
+ end
end
diff --git a/spec/unit/provider/package/yum_spec.rb b/spec/unit/provider/package/yum_spec.rb
deleted file mode 100644
index c8fb04cc21..0000000000
--- a/spec/unit/provider/package/yum_spec.rb
+++ /dev/null
@@ -1,2294 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@chef.io>)
-# Copyright:: Copyright 2008-2017, Chef Software Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-require "spec_helper"
-require "securerandom"
-
-describe Chef::Provider::Package::Yum do
- before(:each) do
- @node = Chef::Node.new
- @events = Chef::EventDispatch::Dispatcher.new
- @run_context = Chef::RunContext.new(@node, {}, @events)
- @new_resource = Chef::Resource::YumPackage.new("cups")
- @status = double("Status", :exitstatus => 0)
- @yum_cache = double(
- "Chef::Provider::Yum::YumCache",
- :reload_installed => true,
- :reset => true,
- :installed_version => "1.2.4-11.18.el5",
- :candidate_version => "1.2.4-11.18.el5_2.3",
- :package_available? => true,
- :version_available? => true,
- :allow_multi_install => [ "kernel" ],
- :package_repository => "base",
- :disable_extra_repo_control => true
- )
- allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
- allow(@yum_cache).to receive(:yum_binary=).with("yum")
- allow(::File).to receive(:exist?).with("/usr/bin/yum-deprecated").and_return(false)
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @pid = double("PID")
- end
-
- describe "when loading the current system state" do
- it "should create a current resource with the name of the new_resource" do
- @provider.load_current_resource
- expect(@provider.current_resource.name).to eq("cups")
- end
-
- it "should set the current resources package name to the new resources package name" do
- @provider.load_current_resource
- expect(@provider.current_resource.package_name).to eq("cups")
- end
-
- it "should set the installed version to nil on the current resource if no installed package" do
- allow(@yum_cache).to receive(:installed_version).and_return(nil)
- @provider.load_current_resource
- expect(@provider.current_resource.version).to be_nil
- end
-
- it "should set the installed version if yum has one" do
- @provider.load_current_resource
- expect(@provider.current_resource.version).to eq("1.2.4-11.18.el5")
- end
-
- it "should set the candidate version if yum info has one" do
- @provider.load_current_resource
- expect(@provider.candidate_version).to eql("1.2.4-11.18.el5_2.3")
- end
-
- it "should return the current resouce" do
- expect(@provider.load_current_resource).to eql(@provider.current_resource)
- end
-
- describe "when source is provided" do
- it "should set the candidate version" do
- @new_resource = Chef::Resource::YumPackage.new("testing.source")
- @new_resource.source "chef-server-core-12.0.5-1.rpm"
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- allow(File).to receive(:exist?).with(@new_resource.source).and_return(true)
- allow(@yum_cache).to receive(:installed_version).and_return(nil)
- shellout_double = double(:stdout => "chef-server-core 12.0.5-1 i386")
- allow(@provider).to receive(:shell_out!).and_return(shellout_double)
- @provider.load_current_resource
- expect(@provider.candidate_version).to eql("12.0.5-1")
- expect(@provider.new_resource.arch).to eql("i386")
- end
- end
-
- describe "yum_binary accessor" do
- it "when yum-deprecated exists" do
- expect(File).to receive(:exist?).with("/usr/bin/yum-deprecated").and_return(true)
- expect(@yum_cache).to receive(:yum_binary=).with("yum-deprecated")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- expect(@provider.send(:yum_binary)).to eql("yum-deprecated")
- end
-
- it "when yum-deprecated does not exist" do
- expect(File).to receive(:exist?).with("/usr/bin/yum-deprecated").and_return(false)
- expect(@yum_cache).to receive(:yum_binary=).with("yum")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- expect(@provider.send(:yum_binary)).to eql("yum")
- end
-
- it "when the yum_binary is set on the resource" do
- @new_resource.yum_binary "/usr/bin/yum-something"
- expect(File).not_to receive(:exist?)
- expect(@yum_cache).to receive(:yum_binary=).with("/usr/bin/yum-something")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- expect(@provider.send(:yum_binary)).to eql("/usr/bin/yum-something")
- end
-
- it "when the new_resource is a vanilla package class and yum-deprecated exists" do
- @new_resource = Chef::Resource::YumPackage.new("cups")
- expect(File).to receive(:exist?).with("/usr/bin/yum-deprecated").and_return(true)
- expect(@yum_cache).to receive(:yum_binary=).with("yum-deprecated")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- expect(@provider.send(:yum_binary)).to eql("yum-deprecated")
- end
-
- it "when the new_resource is a vanilla package class and yum-deprecated does not exist" do
- @new_resource = Chef::Resource::YumPackage.new("cups")
- expect(File).to receive(:exist?).with("/usr/bin/yum-deprecated").and_return(false)
- expect(@yum_cache).to receive(:yum_binary=).with("yum")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- expect(@provider.send(:yum_binary)).to eql("yum")
- end
- end
-
- describe "when arch in package_name" do
- it "should set the arch if no existing package_name is found and new_package_name+new_arch is available" do
- @new_resource = Chef::Resource::YumPackage.new("testing.noarch")
- @yum_cache = double(
- "Chef::Provider::Yum::YumCache"
- )
- allow(@yum_cache).to receive(:installed_version) do |package_name, arch|
- # nothing installed for package_name/new_package_name
- nil
- end
- allow(@yum_cache).to receive(:candidate_version) do |package_name, arch|
- if package_name == "testing.noarch" || package_name == "testing.more.noarch"
- nil
- # candidate for new_package_name
- elsif package_name == "testing" || package_name == "testing.more"
- "1.1"
- end
- end
- allow(@yum_cache).to receive(:package_available?).and_return(true)
- allow(@yum_cache).to receive(:disable_extra_repo_control).and_return(true)
- allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
- allow(@yum_cache).to receive(:yum_binary=).with("yum")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @provider.load_current_resource
- expect(@provider.new_resource.package_name).to eq("testing")
- expect(@provider.new_resource.arch).to eq("noarch")
-
- @new_resource = Chef::Resource::YumPackage.new("testing.more.noarch")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @provider.load_current_resource
- expect(@provider.new_resource.package_name).to eq("testing.more")
- expect(@provider.new_resource.arch).to eq("noarch")
- end
-
- describe "when version constraint in package_name" do
- it "should set package_version if no existing package_name is found and new_package_name is available" do
- @new_resource = Chef::Resource::YumPackage.new("cups = 1.2.4-11.18.el5_2.3")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- allow(@yum_cache).to receive(:package_available?) { |pkg| pkg == "cups" ? true : false }
- allow(@yum_cache).to receive(:packages_from_require) do |pkg|
- [Chef::Provider::Package::Yum::RPMDbPackage.new("cups", "1.2.4-11.18.el5_2.3", "noarch", [], false, true, "base"),
- Chef::Provider::Package::Yum::RPMDbPackage.new("cups", "1.2.4-11.18.el5_2.2", "noarch", [], false, true, "base")]
- end
- expect(Chef::Log).to receive(:debug).exactly(1).times.with(%r{checking yum info})
- expect(Chef::Log).to receive(:debug).exactly(1).times.with(%r{installed version})
- expect(Chef::Log).to receive(:debug).exactly(1).times.with(%r{matched 2 packages,})
- @provider.load_current_resource
- expect(@provider.new_resource.package_name).to eq("cups")
- expect(@provider.new_resource.version).to eq("1.2.4-11.18.el5_2.3")
- expect(@provider.send(:new_version_array)).to eq(["1.2.4-11.18.el5_2.3"])
- expect(@provider.send(:package_name_array)).to eq(["cups"])
- end
- end
-
- it "should not set the arch when an existing package_name is found" do
- @new_resource = Chef::Resource::YumPackage.new("testing.beta3")
- @yum_cache = double(
- "Chef::Provider::Yum::YumCache"
- )
- allow(@yum_cache).to receive(:installed_version) do |package_name, arch|
- # installed for package_name
- if package_name == "testing.beta3" || package_name == "testing.beta3.more"
- "1.1"
- elsif package_name == "testing" || package_name == "testing.beta3"
- nil
- end
- end
- allow(@yum_cache).to receive(:candidate_version) do |package_name, arch|
- # no candidate for package_name/new_package_name
- nil
- end
- allow(@yum_cache).to receive(:package_available?).and_return(true)
- allow(@yum_cache).to receive(:disable_extra_repo_control).and_return(true)
- allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
- allow(@yum_cache).to receive(:yum_binary=).with("yum")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- # annoying side effect of the fun stub'ing above
- @provider.load_current_resource
- expect(@provider.new_resource.package_name).to eq("testing.beta3")
- expect(@provider.new_resource.arch).to eq(nil)
-
- @new_resource = Chef::Resource::YumPackage.new("testing.beta3.more")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @provider.load_current_resource
- expect(@provider.new_resource.package_name).to eq("testing.beta3.more")
- expect(@provider.new_resource.arch).to eq(nil)
- end
-
- it "should not set the arch when no existing package_name or new_package_name+new_arch is found" do
- @new_resource = Chef::Resource::YumPackage.new("testing.beta3")
- @yum_cache = double(
- "Chef::Provider::Yum::YumCache"
- )
- allow(@yum_cache).to receive(:installed_version) do |package_name, arch|
- # nothing installed for package_name/new_package_name
- nil
- end
- allow(@yum_cache).to receive(:candidate_version) do |package_name, arch|
- # no candidate for package_name/new_package_name
- nil
- end
- allow(@yum_cache).to receive(:package_available?).and_return(true)
- allow(@yum_cache).to receive(:disable_extra_repo_control).and_return(true)
- allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
- allow(@yum_cache).to receive(:yum_binary=).with("yum")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @provider.load_current_resource
- expect(@provider.new_resource.package_name).to eq("testing.beta3")
- expect(@provider.new_resource.arch).to eq(nil)
-
- @new_resource = Chef::Resource::YumPackage.new("testing.beta3.more")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @provider.load_current_resource
- expect(@provider.new_resource.package_name).to eq("testing.beta3.more")
- expect(@provider.new_resource.arch).to eq(nil)
- end
-
- it "should ensure it doesn't clobber an existing arch if passed" do
- @new_resource = Chef::Resource::YumPackage.new("testing.i386")
- @new_resource.arch("x86_64")
- @yum_cache = double(
- "Chef::Provider::Yum::YumCache"
- )
- allow(@yum_cache).to receive(:installed_version) do |package_name, arch|
- # nothing installed for package_name/new_package_name
- nil
- end
- allow(@yum_cache).to receive(:candidate_version) do |package_name, arch|
- if package_name == "testing.noarch"
- nil
- # candidate for new_package_name
- elsif package_name == "testing"
- "1.1"
- end
- end.and_return("something")
- allow(@yum_cache).to receive(:package_available?).and_return(true)
- allow(@yum_cache).to receive(:disable_extra_repo_control).and_return(true)
- allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
- allow(@yum_cache).to receive(:yum_binary=).with("yum")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @provider.load_current_resource
- expect(@provider.new_resource.package_name).to eq("testing.i386")
- expect(@provider.new_resource.arch).to eq("x86_64")
- end
- end
-
- it "should flush the cache if :before is true" do
- @new_resource.flush_cache({ :after => false, :before => true })
- expect(@yum_cache).to receive(:reload).once
- @provider.load_current_resource
- end
-
- it "should flush the cache if :before is false" do
- @new_resource.flush_cache({ :after => false, :before => false })
- expect(@yum_cache).not_to receive(:reload)
- @provider.load_current_resource
- end
-
- it "should detect --enablerepo or --disablerepo when passed among options, collect them preserving order and notify the yum cache" do
- @new_resource.options("--stuff --enablerepo=foo --otherthings --disablerepo=a,b,c --enablerepo=bar")
- expect(@yum_cache).to receive(:enable_extra_repo_control).with("--enablerepo=foo --disablerepo=a,b,c --enablerepo=bar")
- @provider.load_current_resource
- end
-
- it "should let the yum cache know extra repos are disabled if --enablerepo or --disablerepo aren't among options" do
- @new_resource.options("--stuff --otherthings")
- expect(@yum_cache).to receive(:disable_extra_repo_control)
- @provider.load_current_resource
- end
-
- it "should let the yum cache know extra repos are disabled if options aren't set" do
- @new_resource.options(nil)
- expect(@yum_cache).to receive(:disable_extra_repo_control)
- @provider.load_current_resource
- end
-
- context "when the package name isn't found" do
- let(:yum_cache) do
- double(
- "Chef::Provider::Yum::YumCache",
- :reload_installed => true,
- :reset => true,
- :installed_version => "1.0.1.el5",
- :candidate_version => "2.0.1.el5",
- :package_available? => false,
- :version_available? => true,
- :disable_extra_repo_control => true
- )
- end
-
- before do
- allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(yum_cache)
- allow(yum_cache).to receive(:yum_binary=).with("yum")
- @pkg = Chef::Provider::Package::Yum::RPMPackage.new("test-package", "2.0.1.el5", "x86_64", [])
- expect(yum_cache).to receive(:packages_from_require).and_return([@pkg])
- end
-
- it "should search provides then set package_name to match" do
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @provider.load_current_resource
- expect(@new_resource.package_name).to eq("test-package")
- expect(@new_resource.version).to eq(nil)
- end
-
- it "should search provides then set version to match if a requirement was passed in the package name" do
- @new_resource = Chef::Resource::YumPackage.new("test-package = 2.0.1.el5")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @provider.load_current_resource
- expect(@new_resource.package_name).to eq("test-package")
- expect(@new_resource.version).to eq("2.0.1.el5")
- end
-
- it "should search provides then set version to match if a requirement was passed in the version" do
- @new_resource = Chef::Resource::YumPackage.new("test-package")
- @new_resource.version("= 2.0.1.el5")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @provider.load_current_resource
- expect(@new_resource.package_name).to eq("test-package")
- expect(@new_resource.version).to eq("2.0.1.el5")
- end
-
- it "should search provides and not set the version to match if a specific version was requested" do
- @new_resource = Chef::Resource::YumPackage.new("test-package")
- @new_resource.version("3.0.1.el5")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @provider.load_current_resource
- expect(@new_resource.package_name).to eq("test-package")
- expect(@new_resource.version).to eq("3.0.1.el5")
- end
-
- it "should search provides then set versions to match if requirements were passed in the package name as an array" do
- @new_resource = Chef::Resource::YumPackage.new(["test-package = 2.0.1.el5"])
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @provider.load_current_resource
- expect(@new_resource.package_name).to eq(["test-package"])
- expect(@new_resource.version).to eq(["2.0.1.el5"])
- end
-
- it "should search provides and not set the versions to match if specific versions were requested in an array" do
- @new_resource = Chef::Resource::YumPackage.new(["test-package"])
- @new_resource.version(["3.0.1.el5"])
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @provider.load_current_resource
- expect(@new_resource.package_name).to eq(["test-package"])
- expect(@new_resource.version).to eq(["3.0.1.el5"])
- end
-
- end
-
- it "should not return an error if no version number is specified in the resource" do
- @new_resource = Chef::Resource::YumPackage.new("test-package")
- @yum_cache = double(
- "Chef::Provider::Yum::YumCache",
- :reload_installed => true,
- :reset => true,
- :installed_version => "1.0.1.el5",
- :candidate_version => "2.0.1.el5",
- :package_available? => false,
- :version_available? => true,
- :disable_extra_repo_control => true
- )
- allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
- allow(@yum_cache).to receive(:yum_binary=).with("yum")
- pkg = Chef::Provider::Package::Yum::RPMPackage.new("test-package", "2.0.1.el5", "x86_64", [])
- expect(@yum_cache).to receive(:packages_from_require).and_return([pkg])
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @provider.load_current_resource
- expect(@new_resource.package_name).to eq("test-package")
- expect(@new_resource.version).to eq(nil)
- end
-
- it "should give precedence to the version attribute when both a requirement in the resource name and a version attribute are specified" do
- @new_resource = Chef::Resource::YumPackage.new("test-package")
- @yum_cache = double(
- "Chef::Provider::Yum::YumCache",
- :reload_installed => true,
- :reset => true,
- :installed_version => "1.2.4-11.18.el5",
- :candidate_version => "1.2.4-11.18.el5",
- :package_available? => false,
- :version_available? => true,
- :disable_extra_repo_control => true
- )
- allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
- allow(@yum_cache).to receive(:yum_binary=).with("yum")
- pkg = Chef::Provider::Package::Yum::RPMPackage.new("test-package", "2.0.1.el5", "x86_64", [])
- expect(@yum_cache).to receive(:packages_from_require).and_return([pkg])
- @new_resource = Chef::Resource::YumPackage.new("test-package = 2.0.1.el5")
- @new_resource.version("3.0.1.el5")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @provider.load_current_resource
- expect(@new_resource.package_name).to eq("test-package")
- expect(@new_resource.version).to eq("3.0.1.el5")
- end
-
- it "should correctly detect the installed states of an array of package names and version numbers" do
- @yum_cache = double(
- "Chef::Provider::Yum::YumCache",
- :reload_installed => true,
- :reset => true,
- :installed_version => "1.0.1.el5",
- :candidate_version => "2.0.1.el5",
- :package_available? => false,
- :version_available? => true,
- :disable_extra_repo_control => true
- )
- allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
- allow(@yum_cache).to receive(:yum_binary=).with("yum")
-
- expect(@yum_cache).to receive(:packages_from_require).exactly(4).times.and_return([])
- expect(@yum_cache).to receive(:reload_provides).twice
-
- @new_resource = Chef::Resource::YumPackage.new(["test-package", "test-package2"])
- @new_resource.version(["2.0.1.el5", "3.0.1.el5"])
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @provider.load_current_resource
- expect(@new_resource.package_name).to eq(["test-package", "test-package2"])
- expect(@new_resource.version).to eq(["2.0.1.el5", "3.0.1.el5"])
- end
-
- it "should search provides if no package is available - if no match in installed provides then load the complete set" do
- @yum_cache = double(
- "Chef::Provider::Yum::YumCache",
- :reload_installed => true,
- :reset => true,
- :installed_version => "1.2.4-11.18.el5",
- :candidate_version => "1.2.4-11.18.el5",
- :package_available? => false,
- :version_available? => true,
- :disable_extra_repo_control => true
- )
- allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
- allow(@yum_cache).to receive(:yum_binary=).with("yum")
- expect(@yum_cache).to receive(:packages_from_require).twice.and_return([])
- expect(@yum_cache).to receive(:reload_provides)
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @provider.load_current_resource
- expect(@new_resource.version).to eq(nil)
- end
-
- it "should search provides if no package is available and not load the complete set if action is :remove or :purge" do
- @yum_cache = double(
- "Chef::Provider::Yum::YumCache",
- :reload_installed => true,
- :reset => true,
- :installed_version => "1.2.4-11.18.el5",
- :candidate_version => "1.2.4-11.18.el5",
- :package_available? => false,
- :version_available? => true,
- :disable_extra_repo_control => true
- )
- allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
- allow(@yum_cache).to receive(:yum_binary=).with("yum")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- expect(@yum_cache).to receive(:packages_from_require).once.and_return([])
- expect(@yum_cache).not_to receive(:reload_provides)
- @new_resource.action(:remove)
- @provider.load_current_resource
- expect(@yum_cache).to receive(:packages_from_require).once.and_return([])
- expect(@yum_cache).not_to receive(:reload_provides)
- @new_resource.action(:purge)
- @provider.load_current_resource
- end
-
- it "should search provides if no package is available - if no match in provides leave the name intact" do
- @yum_cache = double(
- "Chef::Provider::Yum::YumCache",
- :reload_provides => true,
- :reload_installed => true,
- :reset => true,
- :installed_version => "1.2.4-11.18.el5",
- :candidate_version => "1.2.4-11.18.el5",
- :package_available? => false,
- :version_available? => true,
- :disable_extra_repo_control => true
- )
- allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
- allow(@yum_cache).to receive(:yum_binary=).with("yum")
- expect(@yum_cache).to receive(:packages_from_require).twice.and_return([])
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @provider.load_current_resource
- expect(@new_resource.package_name).to eq("cups")
- end
- end
-
- describe "when installing a package" do
- it "should run yum install with the package name and version" do
- @provider.load_current_resource
- allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1)
- expect(@provider).to receive(:yum_command).with(
- "-d0 -e0 -y install cups-1.2.4-11.19.el5"
- )
- @provider.install_package("cups", "1.2.4-11.19.el5")
- end
-
- it "should run yum localinstall if given a path to an rpm" do
- @new_resource.source("/tmp/emacs-21.4-20.el5.i386.rpm")
- expect(@provider).to receive(:yum_command).with(
- "-d0 -e0 -y localinstall /tmp/emacs-21.4-20.el5.i386.rpm"
- )
- @provider.install_package("emacs", "21.4-20.el5")
- end
-
- it "should run yum localinstall if given a path to an rpm as the package" do
- @new_resource = Chef::Resource::YumPackage.new("/tmp/emacs-21.4-20.el5.i386.rpm")
- allow(::File).to receive(:exist?).with("/tmp/emacs-21.4-20.el5.i386.rpm").and_return(true)
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- expect(@new_resource.source).to eq("/tmp/emacs-21.4-20.el5.i386.rpm")
- expect(@provider).to receive(:yum_command).with(
- "-d0 -e0 -y localinstall /tmp/emacs-21.4-20.el5.i386.rpm"
- )
- @provider.install_package("/tmp/emacs-21.4-20.el5.i386.rpm", "21.4-20.el5")
- end
-
- it "should run yum install with the package name, version and arch" do
- @new_resource.arch("i386")
- allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1)
- @provider.load_current_resource
- expect(@provider).to receive(:yum_command).with(
- "-d0 -e0 -y install cups-1.2.4-11.19.el5.i386"
- )
- @provider.install_package("cups", "1.2.4-11.19.el5")
- end
-
- it "installs the package with the options given in the resource" do
- @provider.load_current_resource
- allow(@provider).to receive(:candidate_version).and_return("11")
- @new_resource.options("--disablerepo epmd")
- allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1)
- expect(@provider).to receive(:yum_command).with(
- "-d0 -e0 -y --disablerepo epmd install cups-11"
- )
- @provider.install_package(@new_resource.name, @provider.candidate_version)
- end
-
- it "should raise an exception if the package is not available" do
- @yum_cache = double(
- "Chef::Provider::Yum::YumCache",
- :reload_from_cache => true,
- :reset => true,
- :installed_version => "1.2.4-11.18.el5",
- :candidate_version => "1.2.4-11.18.el5_2.3",
- :package_available? => true,
- :version_available? => nil,
- :disable_extra_repo_control => true
- )
- allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
- allow(@yum_cache).to receive(:yum_binary=).with("yum")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- expect { @provider.install_package("lolcats", "0.99") }.to raise_error(Chef::Exceptions::Package, %r{Version .* not found})
- end
-
- it "should raise an exception if candidate version is older than the installed version and allow_downgrade is false" do
- @new_resource.allow_downgrade(false)
- @yum_cache = double(
- "Chef::Provider::Yum::YumCache",
- :reload_installed => true,
- :reset => true,
- :installed_version => "1.2.4-11.18.el5",
- :candidate_version => "1.2.4-11.15.el5",
- :package_available? => true,
- :version_available? => true,
- :allow_multi_install => [ "kernel" ],
- :disable_extra_repo_control => true
- )
- allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
- allow(@yum_cache).to receive(:yum_binary=).with("yum")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @provider.load_current_resource
- expect { @provider.install_package("cups", "1.2.4-11.15.el5") }.to raise_error(Chef::Exceptions::Package, %r{is newer than candidate package})
- end
-
- it "should not raise an exception if candidate version is older than the installed version and the package is list in yum's installonlypkg option" do
- @yum_cache = double(
- "Chef::Provider::Yum::YumCache",
- :reload_installed => true,
- :reset => true,
- :installed_version => "1.2.4-11.18.el5",
- :candidate_version => "1.2.4-11.15.el5",
- :package_available? => true,
- :version_available? => true,
- :allow_multi_install => [ "cups" ],
- :package_repository => "base",
- :disable_extra_repo_control => true
- )
- allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
- allow(@yum_cache).to receive(:yum_binary=).with("yum")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @provider.load_current_resource
- expect(@provider).to receive(:yum_command).with(
- "-d0 -e0 -y install cups-1.2.4-11.15.el5"
- )
- @provider.install_package("cups", "1.2.4-11.15.el5")
- end
-
- it "should run yum downgrade if candidate version is older than the installed version and allow_downgrade is true" do
- @new_resource.allow_downgrade(true)
- @yum_cache = double(
- "Chef::Provider::Yum::YumCache",
- :reload_installed => true,
- :reset => true,
- :installed_version => "1.2.4-11.18.el5",
- :candidate_version => "1.2.4-11.15.el5",
- :package_available? => true,
- :version_available? => true,
- :allow_multi_install => [],
- :package_repository => "base",
- :disable_extra_repo_control => true
- )
- allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
- allow(@yum_cache).to receive(:yum_binary=).with("yum")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @provider.load_current_resource
- expect(@provider).to receive(:yum_command).with(
- "-d0 -e0 -y downgrade cups-1.2.4-11.15.el5"
- )
- @provider.install_package("cups", "1.2.4-11.15.el5")
- end
-
- it "should run yum install then flush the cache if :after is true" do
- @new_resource.flush_cache({ :after => true, :before => false })
- @provider.load_current_resource
- allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1)
- expect(@provider).to receive(:yum_command).with(
- "-d0 -e0 -y install cups-1.2.4-11.15.el5"
- )
- expect(@yum_cache).to receive(:reload).once
- @provider.install_package("cups", "1.2.4-11.15.el5")
- end
-
- it "should run yum install then not flush the cache if :after is false" do
- @new_resource.flush_cache({ :after => false, :before => false })
- @provider.load_current_resource
- allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1)
- expect(@provider).to receive(:yum_command).with(
- "-d0 -e0 -y install cups-1.2.4-11.15.el5"
- )
- expect(@yum_cache).not_to receive(:reload)
- @provider.install_package("cups", "1.2.4-11.15.el5")
- end
- end
-
- describe "when upgrading a package" do
- it "should run yum install if the package is installed and a version is given" do
- @provider.load_current_resource
- allow(@provider).to receive(:candidate_version).and_return("11")
- allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1)
- expect(@provider).to receive(:yum_command).with(
- "-d0 -e0 -y install cups-11"
- )
- @provider.upgrade_package(@new_resource.name, @provider.candidate_version)
- end
-
- it "should run yum install if the package is not installed" do
- @provider.load_current_resource
- @current_resource = Chef::Resource::YumPackage.new("cups")
- allow(@provider).to receive(:candidate_version).and_return("11")
- allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1)
- expect(@provider).to receive(:yum_command).with(
- "-d0 -e0 -y install cups-11"
- )
- @provider.upgrade_package(@new_resource.name, @provider.candidate_version)
- end
-
- it "should raise an exception if candidate version is older than the installed version" do
- @yum_cache = double(
- "Chef::Provider::Yum::YumCache",
- :reload_installed => true,
- :reset => true,
- :installed_version => "1.2.4-11.18.el5",
- :candidate_version => "1.2.4-11.15.el5",
- :package_available? => true,
- :version_available? => true,
- :allow_multi_install => [ "kernel" ],
- :disable_extra_repo_control => true
- )
- allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
- allow(@yum_cache).to receive(:yum_binary=).with("yum")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @provider.load_current_resource
- expect { @provider.upgrade_package("cups", "1.2.4-11.15.el5") }.to raise_error(Chef::Exceptions::Package, %r{is newer than candidate package})
- end
-
- # Test our little workaround, some crossover into Chef::Provider::Package territory
- it "should call action_upgrade in the parent if the current resource version is nil" do
- allow(@yum_cache).to receive(:installed_version).and_return(nil)
- @current_resource = Chef::Resource::YumPackage.new("cups")
- allow(@provider).to receive(:candidate_version).and_return("11")
- expect(@provider).to receive(:upgrade_package).with(["cups"], ["11"])
- @provider.run_action(:upgrade)
- end
-
- it "should call action_upgrade in the parent if the candidate version is nil" do
- @provider.load_current_resource
- @current_resource = Chef::Resource::YumPackage.new("cups")
- allow(@provider).to receive(:candidate_version).and_return(nil)
- expect(@provider).not_to receive(:upgrade_package)
- @provider.run_action(:upgrade)
- end
-
- it "should call action_upgrade in the parent if the candidate is newer" do
- @provider.load_current_resource
- @current_resource = Chef::Resource::YumPackage.new("cups")
- allow(@provider).to receive(:candidate_version).and_return("11")
- expect(@provider).to receive(:upgrade_package).with(["cups"], ["11"])
- @provider.run_action(:upgrade)
- end
-
- it "should not call action_upgrade in the parent if the candidate is older" do
- allow(@yum_cache).to receive(:installed_version).and_return("12")
- @provider.load_current_resource
- @current_resource = Chef::Resource::YumPackage.new("cups")
- allow(@provider).to receive(:candidate_version).and_return("11")
- expect(@provider).not_to receive(:upgrade_package)
- @provider.run_action(:upgrade)
- end
- end
-
- describe "when removing a package" do
- it "should run yum remove with the package name" do
- expect(@provider).to receive(:yum_command).with(
- "-d0 -e0 -y remove emacs-1.0"
- )
- @provider.remove_package("emacs", "1.0")
- end
-
- it "should run yum remove with the package name and arch" do
- @new_resource.arch("x86_64")
- expect(@provider).to receive(:yum_command).with(
- "-d0 -e0 -y remove emacs-1.0.x86_64"
- )
- @provider.remove_package("emacs", "1.0")
- end
- end
-
- describe "when purging a package" do
- it "should run yum remove with the package name" do
- expect(@provider).to receive(:yum_command).with(
- "-d0 -e0 -y remove emacs-1.0"
- )
- @provider.purge_package("emacs", "1.0")
- end
- end
-
- describe "when locking a package" do
- it "should run yum versionlock add with the package name" do
- expect(@provider).to receive(:yum_command).with(
- "-d0 -e0 -y versionlock add emacs"
- )
- @provider.lock_package("emacs", nil)
- end
- end
-
- describe "when unlocking a package" do
- it "should run yum versionlock delete with the package name" do
- expect(@provider).to receive(:yum_command).with(
- "-d0 -e0 -y versionlock delete emacs"
- )
- @provider.unlock_package("emacs", nil)
- end
- end
-
- describe "when running yum" do
- it "should run yum once if it exits with a return code of 0" do
- @status = double("Status", :exitstatus => 0, :stdout => "", :stderr => "")
- allow(@provider).to receive(:shell_out).and_return(@status)
- expect(@provider).to receive(:shell_out).once.with(
- "yum -d0 -e0 -y install emacs-1.0",
- { :timeout => Chef::Config[:yum_timeout] }
- )
- @provider.send(:yum_command, "-d0 -e0 -y install emacs-1.0")
- end
-
- it "should run yum once if it exits with a return code > 0 and no scriptlet failures" do
- @status = double("Status", :exitstatus => 2, :stdout => "failure failure", :stderr => "problem problem")
- allow(@provider).to receive(:shell_out).and_return(@status)
- expect(@provider).to receive(:shell_out).once.with(
- "yum -d0 -e0 -y install emacs-1.0",
- { :timeout => Chef::Config[:yum_timeout] }
- )
- expect { @provider.send(:yum_command, "-d0 -e0 -y install emacs-1.0") }.to raise_error(Chef::Exceptions::Exec)
- end
-
- it "should run yum once if it exits with a return code of 1 and %pre scriptlet failures" do
- @status = double("Status", :exitstatus => 1, :stdout => "error: %pre(demo-1-1.el5.centos.x86_64) scriptlet failed, exit status 2",
- :stderr => "")
- allow(@provider).to receive(:shell_out).and_return(@status)
- expect(@provider).to receive(:shell_out).once.with(
- "yum -d0 -e0 -y install emacs-1.0",
- { :timeout => Chef::Config[:yum_timeout] }
- )
- # will still raise an exception, can't stub out the subsequent call
- expect { @provider.send(:yum_command, "-d0 -e0 -y install emacs-1.0") }.to raise_error(Chef::Exceptions::Exec)
- end
-
- it "should run yum twice if it exits with a return code of 1 and %post scriptlet failures" do
- @status = double("Status", :exitstatus => 1, :stdout => "error: %post(demo-1-1.el5.centos.x86_64) scriptlet failed, exit status 2",
- :stderr => "")
- allow(@provider).to receive(:shell_out).and_return(@status)
- expect(@provider).to receive(:shell_out).twice.with(
- "yum -d0 -e0 -y install emacs-1.0",
- { :timeout => Chef::Config[:yum_timeout] }
- )
- # will still raise an exception, can't stub out the subsequent call
- expect { @provider.send(:yum_command, "-d0 -e0 -y install emacs-1.0") }.to raise_error(Chef::Exceptions::Exec)
- end
-
- it "should pass the yum_binary to the command if its specified" do
- @new_resource.yum_binary "yum-deprecated"
- expect(@yum_cache).to receive(:yum_binary=).with("yum-deprecated")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @status = double("Status", :exitstatus => 0, :stdout => "", :stderr => "")
- allow(@provider).to receive(:shell_out).and_return(@status)
- expect(@provider).to receive(:shell_out).once.with(
- "yum-deprecated -d0 -e0 -y install emacs-1.0",
- { :timeout => Chef::Config[:yum_timeout] }
- )
- @provider.send(:yum_command, "-d0 -e0 -y install emacs-1.0")
- end
- end
-end
-
-describe Chef::Provider::Package::Yum::RPMUtils do
- describe "version_parse" do
- before do
- @rpmutils = Chef::Provider::Package::Yum::RPMUtils
- end
-
- it "parses known good epoch strings" do
- [
- [ "0:3.3", [ 0, "3.3", nil ] ],
- [ "9:1.7.3", [ 9, "1.7.3", nil ] ],
- [ "15:20020927", [ 15, "20020927", nil ] ],
- ].each do |x, y|
- expect(@rpmutils.version_parse(x)).to eq(y)
- end
- end
-
- it "parses strange epoch strings" do
- [
- [ ":3.3", [ 0, "3.3", nil ] ],
- [ "-1:1.7.3", [ nil, nil, "1:1.7.3" ] ],
- [ "-:20020927", [ nil, nil, ":20020927" ] ],
- ].each do |x, y|
- expect(@rpmutils.version_parse(x)).to eq(y)
- end
- end
-
- it "parses known good version strings" do
- [
- [ "3.3", [ nil, "3.3", nil ] ],
- [ "1.7.3", [ nil, "1.7.3", nil ] ],
- [ "20020927", [ nil, "20020927", nil ] ],
- ].each do |x, y|
- expect(@rpmutils.version_parse(x)).to eq(y)
- end
- end
-
- it "parses strange version strings" do
- [
- [ "3..3", [ nil, "3..3", nil ] ],
- [ "0001.7.3", [ nil, "0001.7.3", nil ] ],
- [ "20020927,3", [ nil, "20020927,3", nil ] ],
- ].each do |x, y|
- expect(@rpmutils.version_parse(x)).to eq(y)
- end
- end
-
- it "parses known good version release strings" do
- [
- [ "3.3-0.pre3.1.60.el5_5.1", [ nil, "3.3", "0.pre3.1.60.el5_5.1" ] ],
- [ "1.7.3-1jpp.2.el5", [ nil, "1.7.3", "1jpp.2.el5" ] ],
- [ "20020927-46.el5", [ nil, "20020927", "46.el5" ] ],
- ].each do |x, y|
- expect(@rpmutils.version_parse(x)).to eq(y)
- end
- end
-
- it "parses strange version release strings" do
- [
- [ "3.3-", [ nil, "3.3", nil ] ],
- [ "-1jpp.2.el5", [ nil, nil, "1jpp.2.el5" ] ],
- [ "-0020020927-46.el5", [ nil, "-0020020927", "46.el5" ] ],
- ].each do |x, y|
- expect(@rpmutils.version_parse(x)).to eq(y)
- end
- end
- end
-
- describe "rpmvercmp" do
- before do
- @rpmutils = Chef::Provider::Package::Yum::RPMUtils
- end
-
- it "should validate version compare logic for standard examples" do
- [
- # numeric
- [ "0.0.2", "0.0.1", 1 ],
- [ "0.2.0", "0.1.0", 1 ],
- [ "2.0.0", "1.0.0", 1 ],
- [ "0.0.1", "0.0.1", 0 ],
- [ "0.0.1", "0.0.2", -1 ],
- [ "0.1.0", "0.2.0", -1 ],
- [ "1.0.0", "2.0.0", -1 ],
- # alpha
- [ "bb", "aa", 1 ],
- [ "ab", "aa", 1 ],
- [ "aa", "aa", 0 ],
- [ "aa", "bb", -1 ],
- [ "aa", "ab", -1 ],
- [ "BB", "AA", 1 ],
- [ "AA", "AA", 0 ],
- [ "AA", "BB", -1 ],
- [ "aa", "AA", 1 ],
- [ "AA", "aa", -1 ],
- # alphanumeric
- [ "0.0.1b", "0.0.1a", 1 ],
- [ "0.1b.0", "0.1a.0", 1 ],
- [ "1b.0.0", "1a.0.0", 1 ],
- [ "0.0.1a", "0.0.1a", 0 ],
- [ "0.0.1a", "0.0.1b", -1 ],
- [ "0.1a.0", "0.1b.0", -1 ],
- [ "1a.0.0", "1b.0.0", -1 ],
- # alphanumeric against alphanumeric
- [ "0.0.1", "0.0.a", 1 ],
- [ "0.1.0", "0.a.0", 1 ],
- [ "1.0.0", "a.0.0", 1 ],
- [ "0.0.a", "0.0.a", 0 ],
- [ "0.0.a", "0.0.1", -1 ],
- [ "0.a.0", "0.1.0", -1 ],
- [ "a.0.0", "1.0.0", -1 ],
- # alphanumeric against numeric
- [ "0.0.2", "0.0.1a", 1 ],
- [ "0.0.2a", "0.0.1", 1 ],
- [ "0.0.1", "0.0.2a", -1 ],
- [ "0.0.1a", "0.0.2", -1 ],
- # length
- [ "0.0.1aa", "0.0.1a", 1 ],
- [ "0.0.1aa", "0.0.1aa", 0 ],
- [ "0.0.1a", "0.0.1aa", -1 ],
- ].each do |x, y, result|
- expect(@rpmutils.rpmvercmp(x, y)).to eq(result)
- end
- end
-
- it "should validate version compare logic for strange examples" do
- [
- [ "2,0,0", "1.0.0", 1 ],
- [ "0.0.1", "0,0.1", 0 ],
- [ "1.0.0", "2,0,0", -1 ],
- [ "002.0.0", "001.0.0", 1 ],
- [ "001..0.1", "001..0.0", 1 ],
- [ "-001..1", "-001..0", 1 ],
- [ "1.0.1", nil, 1 ],
- [ nil, nil, 0 ],
- [ nil, "1.0.1", -1 ],
- [ "1.0.1", "", 1 ],
- [ "", "", 0 ],
- [ "", "1.0.1", -1 ],
- ].each do |x, y, result|
- expect(@rpmutils.rpmvercmp(x, y)).to eq(result)
- end
- end
-
- it "tests isalnum good input" do
- %w{a z A Z 0 9}.each do |t|
- expect(@rpmutils.isalnum(t)).to eq(true)
- end
- end
-
- it "tests isalnum bad input" do
- [ "-", ".", "!", "^", ":", "_" ].each do |t|
- expect(@rpmutils.isalnum(t)).to eq(false)
- end
- end
-
- it "tests isalpha good input" do
- %w{a z A Z}.each do |t|
- expect(@rpmutils.isalpha(t)).to eq(true)
- end
- end
-
- it "tests isalpha bad input" do
- [ "0", "9", "-", ".", "!", "^", ":", "_" ].each do |t|
- expect(@rpmutils.isalpha(t)).to eq(false)
- end
- end
-
- it "tests isdigit good input" do
- %w{0 9}.each do |t|
- expect(@rpmutils.isdigit(t)).to eq(true)
- end
- end
-
- it "tests isdigit bad input" do
- [ "A", "z", "-", ".", "!", "^", ":", "_" ].each do |t|
- expect(@rpmutils.isdigit(t)).to eq(false)
- end
- end
- end
-
-end
-
-describe Chef::Provider::Package::Yum::RPMVersion do
- describe "new - with parsing" do
- before do
- @rpmv = Chef::Provider::Package::Yum::RPMVersion.new("1:1.6.5-9.36.el5")
- end
-
- it "should expose evr (name-version-release) available" do
- expect(@rpmv.e).to eq(1)
- expect(@rpmv.v).to eq("1.6.5")
- expect(@rpmv.r).to eq("9.36.el5")
-
- expect(@rpmv.evr).to eq("1:1.6.5-9.36.el5")
- end
-
- it "should output a version-release string" do
- expect(@rpmv.to_s).to eq("1.6.5-9.36.el5")
- end
- end
-
- describe "new - no parsing" do
- before do
- @rpmv = Chef::Provider::Package::Yum::RPMVersion.new("1", "1.6.5", "9.36.el5")
- end
-
- it "should expose evr (name-version-release) available" do
- expect(@rpmv.e).to eq(1)
- expect(@rpmv.v).to eq("1.6.5")
- expect(@rpmv.r).to eq("9.36.el5")
-
- expect(@rpmv.evr).to eq("1:1.6.5-9.36.el5")
- end
-
- it "should output a version-release string" do
- expect(@rpmv.to_s).to eq("1.6.5-9.36.el5")
- end
- end
-
- it "should raise an error unless passed 1 or 3 args" do
- expect do
- Chef::Provider::Package::Yum::RPMVersion.new()
- end.to raise_error(ArgumentError)
- expect do
- Chef::Provider::Package::Yum::RPMVersion.new("1:1.6.5-9.36.el5")
- end.not_to raise_error
- expect do
- Chef::Provider::Package::Yum::RPMVersion.new("1:1.6.5-9.36.el5", "extra")
- end.to raise_error(ArgumentError)
- expect do
- Chef::Provider::Package::Yum::RPMVersion.new("1", "1.6.5", "9.36.el5")
- end.not_to raise_error
- expect do
- Chef::Provider::Package::Yum::RPMVersion.new("1", "1.6.5", "9.36.el5", "extra")
- end.to raise_error(ArgumentError)
- end
-
- # thanks version_class_spec.rb!
- describe "compare" do
- it "should sort based on complete epoch-version-release data" do
- [
- # smaller, larger
- [ "0:1.6.5-9.36.el5",
- "1:1.6.5-9.36.el5" ],
- [ "0:2.3-15.el5",
- "0:3.3-15.el5" ],
- [ "0:alpha9.8-27.2",
- "0:beta9.8-27.2" ],
- [ "0:0.09-14jpp.3",
- "0:0.09-15jpp.3" ],
- [ "0:0.9.0-0.6.20110211.el5",
- "0:0.9.0-0.6.20120211.el5" ],
- [ "0:1.9.1-4.el5",
- "0:1.9.1-5.el5" ],
- [ "0:1.4.10-7.20090624svn.el5",
- "0:1.4.10-7.20090625svn.el5" ],
- [ "0:2.3.4-2.el5",
- "0:2.3.4-2.el6" ],
- ].each do |smaller, larger|
- sm = Chef::Provider::Package::Yum::RPMVersion.new(smaller)
- lg = Chef::Provider::Package::Yum::RPMVersion.new(larger)
- expect(sm).to be < lg
- expect(lg).to be > sm
- expect(sm).not_to eq(lg)
- end
- end
-
- it "should sort based on partial epoch-version-release data" do
- [
- # smaller, larger
- [ ":1.6.5-9.36.el5",
- "1:1.6.5-9.36.el5" ],
- [ "2.3-15.el5",
- "3.3-15.el5" ],
- [ "alpha9.8",
- "beta9.8" ],
- %w{14jpp
-15jpp},
- [ "0.9.0-0.6",
- "0.9.0-0.7" ],
- [ "0:1.9",
- "3:1.9" ],
- [ "2.3-2.el5",
- "2.3-2.el6" ],
- ].each do |smaller, larger|
- sm = Chef::Provider::Package::Yum::RPMVersion.new(smaller)
- lg = Chef::Provider::Package::Yum::RPMVersion.new(larger)
- expect(sm).to be < lg
- expect(lg).to be > sm
- expect(sm).not_to eq(lg)
- end
- end
-
- it "should verify equality of complete epoch-version-release data" do
- [
- [ "0:1.6.5-9.36.el5",
- "0:1.6.5-9.36.el5" ],
- [ "0:2.3-15.el5",
- "0:2.3-15.el5" ],
- [ "0:alpha9.8-27.2",
- "0:alpha9.8-27.2" ],
- ].each do |smaller, larger|
- sm = Chef::Provider::Package::Yum::RPMVersion.new(smaller)
- lg = Chef::Provider::Package::Yum::RPMVersion.new(larger)
- expect(sm).to eq(lg)
- end
- end
-
- it "should verify equality of partial epoch-version-release data" do
- [
- [ ":1.6.5-9.36.el5",
- "0:1.6.5-9.36.el5" ],
- [ "2.3-15.el5",
- "2.3-15.el5" ],
- [ "alpha9.8-3",
- "alpha9.8-3" ],
- ].each do |smaller, larger|
- sm = Chef::Provider::Package::Yum::RPMVersion.new(smaller)
- lg = Chef::Provider::Package::Yum::RPMVersion.new(larger)
- expect(sm).to eq(lg)
- end
- end
- end
-
- describe "partial compare" do
- it "should compare based on partial epoch-version-release data" do
- [
- # smaller, larger
- [ "0:1.1.1-1",
- "1:" ],
- [ "0:1.1.1-1",
- "0:1.1.2" ],
- [ "0:1.1.1-1",
- "0:1.1.2-1" ],
- [ "0:",
- "1:1.1.1-1" ],
- [ "0:1.1.1",
- "0:1.1.2-1" ],
- [ "0:1.1.1-1",
- "0:1.1.2-1" ],
- ].each do |smaller, larger|
- sm = Chef::Provider::Package::Yum::RPMVersion.new(smaller)
- lg = Chef::Provider::Package::Yum::RPMVersion.new(larger)
- expect(sm.partial_compare(lg)).to eq(-1)
- expect(lg.partial_compare(sm)).to eq(1)
- expect(sm.partial_compare(lg)).not_to eq(0)
- end
- end
-
- it "should verify equality based on partial epoch-version-release data" do
- [
- [ "0:",
- "0:1.1.1-1" ],
- [ "0:1.1.1",
- "0:1.1.1-1" ],
- [ "0:1.1.1-1",
- "0:1.1.1-1" ],
- ].each do |smaller, larger|
- sm = Chef::Provider::Package::Yum::RPMVersion.new(smaller)
- lg = Chef::Provider::Package::Yum::RPMVersion.new(larger)
- expect(sm.partial_compare(lg)).to eq(0)
- end
- end
- end
-
-end
-
-describe Chef::Provider::Package::Yum::RPMPackage do
- describe "new - with parsing" do
- before do
- @rpm = Chef::Provider::Package::Yum::RPMPackage.new("testing", "1:1.6.5-9.36.el5", "x86_64", [])
- end
-
- it "should expose nevra (name-epoch-version-release-arch) available" do
- expect(@rpm.name).to eq("testing")
- expect(@rpm.version.e).to eq(1)
- expect(@rpm.version.v).to eq("1.6.5")
- expect(@rpm.version.r).to eq("9.36.el5")
- expect(@rpm.arch).to eq("x86_64")
-
- expect(@rpm.nevra).to eq("testing-1:1.6.5-9.36.el5.x86_64")
- expect(@rpm.to_s).to eq(@rpm.nevra)
- end
-
- it "should always have at least one provide, itself" do
- expect(@rpm.provides.size).to eq(1)
- expect(@rpm.provides[0].name).to eql("testing")
- expect(@rpm.provides[0].version.evr).to eql("1:1.6.5-9.36.el5")
- expect(@rpm.provides[0].flag).to eql(:==)
- end
- end
-
- describe "new - no parsing" do
- before do
- @rpm = Chef::Provider::Package::Yum::RPMPackage.new("testing", "1", "1.6.5", "9.36.el5", "x86_64", [])
- end
-
- it "should expose nevra (name-epoch-version-release-arch) available" do
- expect(@rpm.name).to eq("testing")
- expect(@rpm.version.e).to eq(1)
- expect(@rpm.version.v).to eq("1.6.5")
- expect(@rpm.version.r).to eq("9.36.el5")
- expect(@rpm.arch).to eq("x86_64")
-
- expect(@rpm.nevra).to eq("testing-1:1.6.5-9.36.el5.x86_64")
- expect(@rpm.to_s).to eq(@rpm.nevra)
- end
-
- it "should always have at least one provide, itself" do
- expect(@rpm.provides.size).to eq(1)
- expect(@rpm.provides[0].name).to eql("testing")
- expect(@rpm.provides[0].version.evr).to eql("1:1.6.5-9.36.el5")
- expect(@rpm.provides[0].flag).to eql(:==)
- end
- end
-
- it "should raise an error unless passed 4 or 6 args" do
- expect do
- Chef::Provider::Package::Yum::RPMPackage.new()
- end.to raise_error(ArgumentError)
- expect do
- Chef::Provider::Package::Yum::RPMPackage.new("testing")
- end.to raise_error(ArgumentError)
- expect do
- Chef::Provider::Package::Yum::RPMPackage.new("testing", "1:1.6.5-9.36.el5")
- end.to raise_error(ArgumentError)
- expect do
- Chef::Provider::Package::Yum::RPMPackage.new("testing", "1:1.6.5-9.36.el5", "x86_64")
- end.to raise_error(ArgumentError)
- expect do
- Chef::Provider::Package::Yum::RPMPackage.new("testing", "1:1.6.5-9.36.el5", "x86_64", [])
- end.not_to raise_error
- expect do
- Chef::Provider::Package::Yum::RPMPackage.new("testing", "1", "1.6.5", "9.36.el5", "x86_64")
- end.to raise_error(ArgumentError)
- expect do
- Chef::Provider::Package::Yum::RPMPackage.new("testing", "1", "1.6.5", "9.36.el5", "x86_64", [])
- end.not_to raise_error
- expect do
- Chef::Provider::Package::Yum::RPMPackage.new("testing", "1", "1.6.5", "9.36.el5", "x86_64", [], "extra")
- end.to raise_error(ArgumentError)
- end
-
- describe "<=>" do
- it "should sort alphabetically based on package name" do
- [
- [ "a-test",
- "b-test" ],
- [ "B-test",
- "a-test" ],
- [ "A-test",
- "B-test" ],
- [ "Aa-test",
- "aA-test" ],
- %w{1test
-2test},
- ].each do |smaller, larger|
- sm = Chef::Provider::Package::Yum::RPMPackage.new(smaller, "0:0.0.1-1", "x86_64", [])
- lg = Chef::Provider::Package::Yum::RPMPackage.new(larger, "0:0.0.1-1", "x86_64", [])
- expect(sm).to be < lg
- expect(lg).to be > sm
- expect(sm).not_to eq(lg)
- end
- end
-
- it "should sort alphabetically based on package arch" do
- [
- %w{i386
-x86_64},
- %w{i386
-noarch},
- %w{noarch
-x86_64},
- ].each do |smaller, larger|
- sm = Chef::Provider::Package::Yum::RPMPackage.new("test-package", "0:0.0.1-1", smaller, [])
- lg = Chef::Provider::Package::Yum::RPMPackage.new("test-package", "0:0.0.1-1", larger, [])
- expect(sm).to be < lg
- expect(lg).to be > sm
- expect(sm).not_to eq(lg)
- end
- end
- end
-
-end
-
-describe Chef::Provider::Package::Yum::RPMDbPackage do
- before(:each) do
- # name, version, arch, installed, available, repoid
- @rpm_x = Chef::Provider::Package::Yum::RPMDbPackage.new("test-package-b", "0:1.6.5-9.36.el5", "noarch", [], false, true, "base")
- @rpm_y = Chef::Provider::Package::Yum::RPMDbPackage.new("test-package-b", "0:1.6.5-9.36.el5", "noarch", [], true, true, "extras")
- @rpm_z = Chef::Provider::Package::Yum::RPMDbPackage.new("test-package-b", "0:1.6.5-9.36.el5", "noarch", [], true, false, "other")
- end
-
- describe "initialize" do
- it "should return a Chef::Provider::Package::Yum::RPMDbPackage object" do
- expect(@rpm_x).to be_kind_of(Chef::Provider::Package::Yum::RPMDbPackage)
- end
- end
-
- describe "available" do
- it "should return true" do
- expect(@rpm_x.available).to eq(true)
- expect(@rpm_y.available).to eq(true)
- expect(@rpm_z.available).to eq(false)
- end
- end
-
- describe "installed" do
- it "should return true" do
- expect(@rpm_x.installed).to eq(false)
- expect(@rpm_y.installed).to eq(true)
- expect(@rpm_z.installed).to eq(true)
- end
- end
-
- describe "repoid" do
- it "should return the source repository repoid" do
- expect(@rpm_x.repoid).to eq("base")
- expect(@rpm_y.repoid).to eq("extras")
- expect(@rpm_z.repoid).to eq("other")
- end
- end
-end
-
-describe Chef::Provider::Package::Yum::RPMDependency do
- describe "new - with parsing" do
- before do
- @rpmdep = Chef::Provider::Package::Yum::RPMDependency.new("testing", "1:1.6.5-9.36.el5", :==)
- end
-
- it "should expose name, version, flag available" do
- expect(@rpmdep.name).to eq("testing")
- expect(@rpmdep.version.e).to eq(1)
- expect(@rpmdep.version.v).to eq("1.6.5")
- expect(@rpmdep.version.r).to eq("9.36.el5")
- expect(@rpmdep.flag).to eq(:==)
- end
- end
-
- describe "new - no parsing" do
- before do
- @rpmdep = Chef::Provider::Package::Yum::RPMDependency.new("testing", "1", "1.6.5", "9.36.el5", :==)
- end
-
- it "should expose name, version, flag available" do
- expect(@rpmdep.name).to eq("testing")
- expect(@rpmdep.version.e).to eq(1)
- expect(@rpmdep.version.v).to eq("1.6.5")
- expect(@rpmdep.version.r).to eq("9.36.el5")
- expect(@rpmdep.flag).to eq(:==)
- end
- end
-
- it "should raise an error unless passed 3 or 5 args" do
- expect do
- Chef::Provider::Package::Yum::RPMDependency.new()
- end.to raise_error(ArgumentError)
- expect do
- Chef::Provider::Package::Yum::RPMDependency.new("testing")
- end.to raise_error(ArgumentError)
- expect do
- Chef::Provider::Package::Yum::RPMDependency.new("testing", "1:1.6.5-9.36.el5")
- end.to raise_error(ArgumentError)
- expect do
- Chef::Provider::Package::Yum::RPMDependency.new("testing", "1:1.6.5-9.36.el5", :==)
- end.not_to raise_error
- expect do
- Chef::Provider::Package::Yum::RPMDependency.new("testing", "1:1.6.5-9.36.el5", :==, "extra")
- end.to raise_error(ArgumentError)
- expect do
- Chef::Provider::Package::Yum::RPMDependency.new("testing", "1", "1.6.5", "9.36.el5", :==)
- end.not_to raise_error
- expect do
- Chef::Provider::Package::Yum::RPMDependency.new("testing", "1", "1.6.5", "9.36.el5", :==, "extra")
- end.to raise_error(ArgumentError)
- end
-
- describe "parse" do
- it "should parse a name, flag, version string into a valid RPMDependency object" do
- @rpmdep = Chef::Provider::Package::Yum::RPMDependency.parse("testing >= 1:1.6.5-9.36.el5")
-
- expect(@rpmdep.name).to eq("testing")
- expect(@rpmdep.version.e).to eq(1)
- expect(@rpmdep.version.v).to eq("1.6.5")
- expect(@rpmdep.version.r).to eq("9.36.el5")
- expect(@rpmdep.flag).to eq(:>=)
- end
-
- it "should parse a name into a valid RPMDependency object" do
- @rpmdep = Chef::Provider::Package::Yum::RPMDependency.parse("testing")
-
- expect(@rpmdep.name).to eq("testing")
- expect(@rpmdep.version.e).to eq(nil)
- expect(@rpmdep.version.v).to eq(nil)
- expect(@rpmdep.version.r).to eq(nil)
- expect(@rpmdep.flag).to eq(:==)
- end
-
- it "should parse an invalid string into the name of a RPMDependency object" do
- @rpmdep = Chef::Provider::Package::Yum::RPMDependency.parse("testing blah >")
-
- expect(@rpmdep.name).to eq("testing blah >")
- expect(@rpmdep.version.e).to eq(nil)
- expect(@rpmdep.version.v).to eq(nil)
- expect(@rpmdep.version.r).to eq(nil)
- expect(@rpmdep.flag).to eq(:==)
- end
-
- it "should parse various valid flags" do
- [
- [ ">", :> ],
- [ ">=", :>= ],
- [ "=", :== ],
- [ "==", :== ],
- [ "<=", :<= ],
- [ "<", :< ],
- ].each do |before, after|
- @rpmdep = Chef::Provider::Package::Yum::RPMDependency.parse("testing #{before} 1:1.1-1")
- expect(@rpmdep.flag).to eq(after)
- end
- end
-
- it "should parse various invalid flags and treat them as names" do
- [
- [ "<>", :== ],
- [ "!=", :== ],
- [ ">>", :== ],
- [ "<<", :== ],
- [ "!", :== ],
- [ "~", :== ],
- ].each do |before, after|
- @rpmdep = Chef::Provider::Package::Yum::RPMDependency.parse("testing #{before} 1:1.1-1")
- expect(@rpmdep.name).to eq("testing #{before} 1:1.1-1")
- expect(@rpmdep.flag).to eq(after)
- end
- end
- end
-
- describe "satisfy?" do
- it "should raise an error unless a RPMDependency is passed" do
- @rpmprovide = Chef::Provider::Package::Yum::RPMDependency.new("testing", "1:1.6.5-9.36.el5", :==)
- @rpmrequire = Chef::Provider::Package::Yum::RPMDependency.new("testing", "1:1.6.5-9.36.el5", :>=)
- expect do
- @rpmprovide.satisfy?("hi")
- end.to raise_error(ArgumentError)
- expect do
- @rpmprovide.satisfy?(@rpmrequire)
- end.not_to raise_error
- end
-
- it "should validate dependency satisfaction logic for standard examples" do
- [
- # names
- [ "test", "test", true ],
- [ "test", "foo", false ],
- # full: epoch:version-relese
- [ "testing = 1:1.1-1", "testing > 1:1.1-0", true ],
- [ "testing = 1:1.1-1", "testing >= 1:1.1-0", true ],
- [ "testing = 1:1.1-1", "testing >= 1:1.1-1", true ],
- [ "testing = 1:1.1-1", "testing = 1:1.1-1", true ],
- [ "testing = 1:1.1-1", "testing == 1:1.1-1", true ],
- [ "testing = 1:1.1-1", "testing <= 1:1.1-1", true ],
- [ "testing = 1:1.1-1", "testing <= 1:1.1-0", false ],
- [ "testing = 1:1.1-1", "testing < 1:1.1-0", false ],
- # partial: epoch:version
- [ "testing = 1:1.1", "testing > 1:1.0", true ],
- [ "testing = 1:1.1", "testing >= 1:1.0", true ],
- [ "testing = 1:1.1", "testing >= 1:1.1", true ],
- [ "testing = 1:1.1", "testing = 1:1.1", true ],
- [ "testing = 1:1.1", "testing == 1:1.1", true ],
- [ "testing = 1:1.1", "testing <= 1:1.1", true ],
- [ "testing = 1:1.1", "testing <= 1:1.0", false ],
- [ "testing = 1:1.1", "testing < 1:1.0", false ],
- # partial: epoch
- [ "testing = 1:", "testing > 0:", true ],
- [ "testing = 1:", "testing >= 0:", true ],
- [ "testing = 1:", "testing >= 1:", true ],
- [ "testing = 1:", "testing = 1:", true ],
- [ "testing = 1:", "testing == 1:", true ],
- [ "testing = 1:", "testing <= 1:", true ],
- [ "testing = 1:", "testing <= 0:", false ],
- [ "testing = 1:", "testing < 0:", false ],
- # mix and match!
- [ "testing = 1:1.1-1", "testing == 1:1.1", true ],
- [ "testing = 1:1.1-1", "testing == 1:", true ],
- ].each do |prov, req, result|
- @rpmprovide = Chef::Provider::Package::Yum::RPMDependency.parse(prov)
- @rpmrequire = Chef::Provider::Package::Yum::RPMDependency.parse(req)
-
- expect(@rpmprovide.satisfy?(@rpmrequire)).to eq(result)
- expect(@rpmrequire.satisfy?(@rpmprovide)).to eq(result)
- end
- end
- end
-
-end
-
-# thanks resource_collection_spec.rb!
-describe Chef::Provider::Package::Yum::RPMDb do
- before(:each) do
- @rpmdb = Chef::Provider::Package::Yum::RPMDb.new
- # name, version, arch, installed, available
- deps_v = [
- Chef::Provider::Package::Yum::RPMDependency.parse("libz.so.1()(64bit)"),
- Chef::Provider::Package::Yum::RPMDependency.parse("test-package-a = 0:1.6.5-9.36.el5"),
- ]
- deps_z = [
- Chef::Provider::Package::Yum::RPMDependency.parse("libz.so.1()(64bit)"),
- Chef::Provider::Package::Yum::RPMDependency.parse("config(test) = 0:1.6.5-9.36.el5"),
- Chef::Provider::Package::Yum::RPMDependency.parse("test-package-c = 0:1.6.5-9.36.el5"),
- ]
- @rpm_v = Chef::Provider::Package::Yum::RPMDbPackage.new("test-package-a", "0:1.6.5-9.36.el5", "i386", deps_v, true, false, "base")
- @rpm_w = Chef::Provider::Package::Yum::RPMDbPackage.new("test-package-b", "0:1.6.5-9.36.el5", "i386", [], true, true, "extras")
- @rpm_x = Chef::Provider::Package::Yum::RPMDbPackage.new("test-package-b", "0:1.6.5-9.36.el5", "x86_64", [], false, true, "extras")
- @rpm_y = Chef::Provider::Package::Yum::RPMDbPackage.new("test-package-b", "1:1.6.5-9.36.el5", "x86_64", [], true, true, "extras")
- @rpm_z = Chef::Provider::Package::Yum::RPMDbPackage.new("test-package-c", "0:1.6.5-9.36.el5", "noarch", deps_z, true, true, "base")
- @rpm_z_mirror = Chef::Provider::Package::Yum::RPMDbPackage.new("test-package-c", "0:1.6.5-9.36.el5", "noarch", deps_z, true, true, "base")
- end
-
- describe "initialize" do
- it "should return a Chef::Provider::Package::Yum::RPMDb object" do
- expect(@rpmdb).to be_kind_of(Chef::Provider::Package::Yum::RPMDb)
- end
- end
-
- describe "push" do
- it "should accept an RPMDbPackage object through pushing" do
- expect { @rpmdb.push(@rpm_w) }.not_to raise_error
- end
-
- it "should accept multiple RPMDbPackage object through pushing" do
- expect { @rpmdb.push(@rpm_w, @rpm_x, @rpm_y, @rpm_z) }.not_to raise_error
- end
-
- it "should only accept an RPMDbPackage object" do
- expect { @rpmdb.push("string") }.to raise_error(ArgumentError)
- end
-
- it "should add the package to the package db" do
- @rpmdb.push(@rpm_w)
- expect(@rpmdb["test-package-b"]).not_to eq(nil)
- end
-
- it "should add conditionally add the package to the available list" do
- expect(@rpmdb.available_size).to eq(0)
- @rpmdb.push(@rpm_v, @rpm_w)
- expect(@rpmdb.available_size).to eq(1)
- end
-
- it "should add conditionally add the package to the installed list" do
- expect(@rpmdb.installed_size).to eq(0)
- @rpmdb.push(@rpm_w, @rpm_x)
- expect(@rpmdb.installed_size).to eq(1)
- end
-
- it "should have a total of 2 packages in the RPMDb" do
- expect(@rpmdb.size).to eq(0)
- @rpmdb.push(@rpm_w, @rpm_x, @rpm_y, @rpm_z)
- expect(@rpmdb.size).to eq(2)
- end
-
- it "should keep the Array unique when a duplicate is pushed" do
- @rpmdb.push(@rpm_z, @rpm_z_mirror)
- expect(@rpmdb["test-package-c"].size).to eq(1)
- end
-
- it "should register the package provides in the provides index" do
- @rpmdb.push(@rpm_v, @rpm_w, @rpm_z)
- expect(@rpmdb.lookup_provides("test-package-a")[0]).to eq(@rpm_v)
- expect(@rpmdb.lookup_provides("config(test)")[0]).to eq(@rpm_z)
- expect(@rpmdb.lookup_provides("libz.so.1()(64bit)")[0]).to eq(@rpm_v)
- expect(@rpmdb.lookup_provides("libz.so.1()(64bit)")[1]).to eq(@rpm_z)
- end
- end
-
- describe "<<" do
- it "should accept an RPMPackage object through the << operator" do
- expect { @rpmdb << @rpm_w }.not_to raise_error
- end
- end
-
- describe "lookup" do
- it "should return an Array of RPMPackage objects by index" do
- @rpmdb << @rpm_w
- expect(@rpmdb.lookup("test-package-b")).to be_kind_of(Array)
- end
- end
-
- describe "[]" do
- it "should return an Array of RPMPackage objects though the [index] operator" do
- @rpmdb << @rpm_w
- expect(@rpmdb["test-package-b"]).to be_kind_of(Array)
- end
-
- it "should return an Array of 3 RPMPackage objects" do
- @rpmdb.push(@rpm_w, @rpm_x, @rpm_y, @rpm_z)
- expect(@rpmdb["test-package-b"].size).to eq(3)
- end
-
- it "should return an Array of RPMPackage objects sorted from newest to oldest" do
- @rpmdb.push(@rpm_w, @rpm_x, @rpm_y, @rpm_z)
- expect(@rpmdb["test-package-b"][0]).to eq(@rpm_y)
- expect(@rpmdb["test-package-b"][1]).to eq(@rpm_x)
- expect(@rpmdb["test-package-b"][2]).to eq(@rpm_w)
- end
- end
-
- describe "lookup_provides" do
- it "should return an Array of RPMPackage objects by index" do
- @rpmdb << @rpm_z
- x = @rpmdb.lookup_provides("config(test)")
- expect(x).to be_kind_of(Array)
- expect(x[0]).to eq(@rpm_z)
- end
- end
-
- describe "clear" do
- it "should clear the RPMDb" do
- expect(@rpmdb).to receive(:clear_available).once
- expect(@rpmdb).to receive(:clear_installed).once
- @rpmdb.push(@rpm_w, @rpm_x, @rpm_y, @rpm_z)
- expect(@rpmdb.size).not_to eq(0)
- expect(@rpmdb.lookup_provides("config(test)")).to be_kind_of(Array)
- @rpmdb.clear
- expect(@rpmdb.lookup_provides("config(test)")).to eq(nil)
- expect(@rpmdb.size).to eq(0)
- end
- end
-
- describe "clear_available" do
- it "should clear the available list" do
- @rpmdb.push(@rpm_w, @rpm_x, @rpm_y, @rpm_z)
- expect(@rpmdb.available_size).not_to eq(0)
- @rpmdb.clear_available
- expect(@rpmdb.available_size).to eq(0)
- end
- end
-
- describe "available?" do
- it "should return true if a package is available" do
- expect(@rpmdb.available?(@rpm_w)).to eq(false)
- @rpmdb.push(@rpm_v, @rpm_w)
- expect(@rpmdb.available?(@rpm_v)).to eq(false)
- expect(@rpmdb.available?(@rpm_w)).to eq(true)
- end
- end
-
- describe "clear_installed" do
- it "should clear the installed list" do
- @rpmdb.push(@rpm_w, @rpm_x, @rpm_y, @rpm_z)
- expect(@rpmdb.installed_size).not_to eq(0)
- @rpmdb.clear_installed
- expect(@rpmdb.installed_size).to eq(0)
- end
- end
-
- describe "installed?" do
- it "should return true if a package is installed" do
- expect(@rpmdb.installed?(@rpm_w)).to eq(false)
- @rpmdb.push(@rpm_w, @rpm_x)
- expect(@rpmdb.installed?(@rpm_w)).to eq(true)
- expect(@rpmdb.installed?(@rpm_x)).to eq(false)
- end
- end
-
- describe "whatprovides" do
- it "should raise an error unless a RPMDependency is passed" do
- @rpmprovide = Chef::Provider::Package::Yum::RPMDependency.new("testing", "1:1.6.5-9.36.el5", :==)
- @rpmrequire = Chef::Provider::Package::Yum::RPMDependency.new("testing", "1:1.6.5-9.36.el5", :>=)
- expect do
- @rpmdb.whatprovides("hi")
- end.to raise_error(ArgumentError)
- expect do
- @rpmdb.whatprovides(@rpmrequire)
- end.not_to raise_error
- end
-
- it "should return an Array of packages statisfying a RPMDependency" do
- @rpmdb.push(@rpm_v, @rpm_w, @rpm_z)
-
- @rpmrequire = Chef::Provider::Package::Yum::RPMDependency.parse("test-package-a >= 1.6.5")
- x = @rpmdb.whatprovides(@rpmrequire)
- expect(x).to be_kind_of(Array)
- expect(x[0]).to eq(@rpm_v)
-
- @rpmrequire = Chef::Provider::Package::Yum::RPMDependency.parse("libz.so.1()(64bit)")
- x = @rpmdb.whatprovides(@rpmrequire)
- expect(x).to be_kind_of(Array)
- expect(x[0]).to eq(@rpm_v)
- expect(x[1]).to eq(@rpm_z)
- end
- end
-
-end
-
-describe Chef::Provider::Package::Yum::YumCache do
- # allow for the reset of a Singleton
- # thanks to Ian White (http://blog.ardes.com/2006/12/11/testing-singletons-with-ruby)
- class << Chef::Provider::Package::Yum::YumCache
- def reset_instance
- Singleton.send :__init__, self
- self
- end
- end
-
- let(:yum_exe) do
- StringIO.new("#!/usr/bin/python\n\naldsjfa\ldsajflkdsjf\lajsdfj")
- end
-
- let(:bin_exe) do
- StringIO.new(SecureRandom.random_bytes)
- end
-
- before(:each) do
- @stdin = double("STDIN", :nil_object => true)
- @stdout = double("STDOUT", :nil_object => true)
-
- @stdout_good = <<EOF
-[option installonlypkgs] kernel kernel-bigmem kernel-enterprise
-erlang-mochiweb 0 1.4.1 5.el5 x86_64 ['erlang-mochiweb = 1.4.1-5.el5', 'mochiweb = 1.4.1-5.el5'] i installed
-zip 0 2.31 2.el5 x86_64 ['zip = 2.31-2.el5'] r base
-zisofs-tools 0 1.0.6 3.2.2 x86_64 [] a extras
-zlib 0 1.2.3 3 x86_64 ['zlib = 1.2.3-3', 'libz.so.1()(64bit)'] r base
-zlib 0 1.2.3 3 i386 ['zlib = 1.2.3-3', 'libz.so.1'] r base
-zlib-devel 0 1.2.3 3 i386 [] a extras
-zlib-devel 0 1.2.3 3 x86_64 ['zlib-devel = 1.2.3-3'] r base
-znc 0 0.098 1.el5 x86_64 [] a base
-znc-devel 0 0.098 1.el5 i386 [] a extras
-znc-devel 0 0.098 1.el5 x86_64 [] a base
-znc-extra 0 0.098 1.el5 x86_64 [] a base
-znc-modtcl 0 0.098 1.el5 x86_64 [] a base
-znc-test.beta1 0 0.098 1.el5 x86_64 [] a extras
-znc-test.test.beta1 0 0.098 1.el5 x86_64 [] a base
-EOF
- @stdout_bad_type = <<EOF
-zip 0 2.31 2.el5 x86_64 ['zip = 2.31-2.el5'] r base
-zlib 0 1.2.3 3 x86_64 ['zlib = 1.2.3-3', 'libz.so.1()(64bit)'] c base
-zlib-devel 0 1.2.3 3 i386 [] a extras
-zlib-devel 0 1.2.3 3 x86_64 ['zlib-devel = 1.2.3-3'] bad installed
-znc-modtcl 0 0.098 1.el5 x86_64 [] a base
-EOF
-
- @stdout_bad_separators = <<EOF
-zip 0 2.31 2.el5 x86_64 ['zip = 2.31-2.el5'] r base
-zlib 0 1.2.3 3 x86_64 ['zlib = 1.2.3-3', 'libz.so.1()(64bit)'] i base bad
-zlib-devel 0 1.2.3 3 i386 [] a extras
-bad zlib-devel 0 1.2.3 3 x86_64 ['zlib-devel = 1.2.3-3'] i installed
-znc-modtcl 0 0.098 1.el5 x86_64 [] a base bad
-EOF
-
- @stdout_no_output = ""
-
- @stderr = <<EOF
-yum-dump Config Error: File contains no section headers.
-file: file://///etc/yum.repos.d/CentOS-Base.repo, line: 12
-'qeqwewe\n'
-EOF
- @status = double("Status", :exitstatus => 0, :stdin => @stdin, :stdout => @stdout_good, :stderr => @stderr)
- # new singleton each time
- Chef::Provider::Package::Yum::YumCache.reset_instance
- @yc = Chef::Provider::Package::Yum::YumCache.instance
- # load valid data
- @yc.yum_binary = "yum"
- allow(@yc).to receive(:shell_out!).and_return(@status)
- allow_any_instance_of(described_class).to receive(:which).with("yum").and_return("/usr/bin/yum")
- allow(::File).to receive(:open).with("/usr/bin/yum", "r") do |&block|
- res = block.call(yum_exe)
- # a bit of a hack. rewind this since it seem that no matter what
- # I do, we get the same StringIO objects on multiple calls to
- # ::File.open
- yum_exe.rewind; res
- end
- end
-
- describe "initialize" do
- it "should return a Chef::Provider::Package::Yum::YumCache object" do
- expect(@yc).to be_kind_of(Chef::Provider::Package::Yum::YumCache)
- end
-
- it "should register reload for start of Chef::Client runs" do
- Chef::Provider::Package::Yum::YumCache.reset_instance
- expect(Chef::Client).to receive(:when_run_starts) do |&b|
- expect(b).not_to be_nil
- end
- @yc = Chef::Provider::Package::Yum::YumCache.instance
- end
- end
-
- describe "python_bin" do
- it "should return the default python if an error occurs" do
- allow(::File).to receive(:open).with("/usr/bin/yum", "r").and_raise(StandardError)
- expect(@yc.python_bin).to eq("/usr/bin/python")
- end
-
- it "should return the default python if the yum-executable doesn't start with #!" do
- allow(::File).to receive(:open).with("/usr/bin/yum", "r") { |&b| r = b.call(bin_exe); bin_exe.rewind; r }
- expect(@yc.python_bin).to eq("/usr/bin/python")
- end
-
- it "should return /usr/bin/python if the interpreter is /bin/bash" do
- other = StringIO.new("#!/bin/bash\n# The yum executable redirecting to dnf from dnf-yum compatible package.")
- allow(::File).to receive(:open).with("/usr/bin/yum", "r") { |&b| r = b.call(other); other.rewind; r }
- expect(@yc.python_bin).to eq("/usr/bin/python")
- end
-
- it "should return the interpreter for yum" do
- other = StringIO.new("#!/usr/bin/super_python\n\nlasjdfdsaljf\nlasdjfs")
- allow(::File).to receive(:open).with("/usr/bin/yum", "r") { |&b| r = b.call(other); other.rewind; r }
- expect(@yc.python_bin).to eq("/usr/bin/super_python")
- end
- end
-
- describe "refresh" do
- it "should implicitly call yum-dump.py only once by default after being instantiated" do
- expect(@yc).to receive(:shell_out!).once
- @yc.installed_version("zlib")
- @yc.reset
- @yc.installed_version("zlib")
- end
-
- it "should run yum-dump.py using the system python when next_refresh is for :all" do
- @yc.reload
- expect(@yc).to receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --options --installed-provides --yum-lock-timeout 30$}, :timeout => Chef::Config[:yum_timeout])
- @yc.refresh
- end
-
- it "should run yum-dump.py with the installed flag when next_refresh is for :installed" do
- @yc.reload_installed
- expect(@yc).to receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --installed --yum-lock-timeout 30$}, :timeout => Chef::Config[:yum_timeout])
- @yc.refresh
- end
-
- it "should run yum-dump.py with the all-provides flag when next_refresh is for :provides" do
- @yc.reload_provides
- expect(@yc).to receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --options --all-provides --yum-lock-timeout 30$}, :timeout => Chef::Config[:yum_timeout])
- @yc.refresh
- end
-
- it "should pass extra_repo_control args to yum-dump.py" do
- @yc.enable_extra_repo_control("--enablerepo=foo --disablerepo=bar")
- expect(@yc).to receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --options --installed-provides --enablerepo=foo --disablerepo=bar --yum-lock-timeout 30$}, :timeout => Chef::Config[:yum_timeout])
- @yc.refresh
- end
-
- it "should pass extra_repo_control args and configured yum lock timeout to yum-dump.py" do
- Chef::Config[:yum_lock_timeout] = 999
- @yc.enable_extra_repo_control("--enablerepo=foo --disablerepo=bar")
- expect(@yc).to receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --options --installed-provides --enablerepo=foo --disablerepo=bar --yum-lock-timeout 999$}, :timeout => Chef::Config[:yum_timeout])
- @yc.refresh
- end
-
- it "should warn about invalid data with too many separators" do
- @status = double("Status", :exitstatus => 0, :stdin => @stdin, :stdout => @stdout_bad_separators, :stderr => @stderr)
- allow(@yc).to receive(:shell_out!).and_return(@status)
- expect(Chef::Log).to receive(:warn).exactly(3).times.with(%r{Problem parsing})
- @yc.refresh
- end
-
- it "should warn about invalid data with an incorrect type" do
- @status = double("Status", :exitstatus => 0, :stdin => @stdin, :stdout => @stdout_bad_type, :stderr => @stderr)
- allow(@yc).to receive(:shell_out!).and_return(@status)
- expect(Chef::Log).to receive(:warn).exactly(2).times.with(%r{Problem parsing})
- @yc.refresh
- end
-
- it "should warn about no output from yum-dump.py" do
- @status = double("Status", :exitstatus => 0, :stdin => @stdin, :stdout => @stdout_no_output, :stderr => @stderr)
- allow(@yc).to receive(:shell_out!).and_return(@status)
- expect(Chef::Log).to receive(:warn).exactly(1).times.with(%r{no output from yum-dump.py})
- @yc.refresh
- end
-
- it "should raise exception yum-dump.py exits with a non zero status" do
- @status = double("Status", :exitstatus => 1, :stdin => @stdin, :stdout => @stdout_no_output, :stderr => @stderr)
- allow(@yc).to receive(:shell_out!).and_return(@status)
- expect { @yc.refresh }.to raise_error(Chef::Exceptions::Package, %r{CentOS-Base.repo, line: 12})
- end
-
- it "should parse type 'i' into an installed state for a package" do
- expect(@yc.available_version("erlang-mochiweb")).to eq(nil)
- expect(@yc.installed_version("erlang-mochiweb")).not_to eq(nil)
- end
-
- it "should parse type 'a' into an available state for a package" do
- expect(@yc.available_version("znc")).not_to eq(nil)
- expect(@yc.installed_version("znc")).to eq(nil)
- end
-
- it "should parse type 'r' into an installed and available states for a package" do
- expect(@yc.available_version("zip")).not_to eq(nil)
- expect(@yc.installed_version("zip")).not_to eq(nil)
- end
-
- it "should parse installonlypkgs from yum-dump.py options output" do
- expect(@yc.allow_multi_install).to eq(%w{kernel kernel-bigmem kernel-enterprise})
- end
- end
-
- describe "installed_version" do
- it "should take one or two arguments" do
- expect { @yc.installed_version("zip") }.not_to raise_error
- expect { @yc.installed_version("zip", "i386") }.not_to raise_error
- expect { @yc.installed_version("zip", "i386", "extra") }.to raise_error(ArgumentError)
- end
-
- it "should return version-release for matching package regardless of arch" do
- expect(@yc.installed_version("zip", "x86_64")).to eq("2.31-2.el5")
- expect(@yc.installed_version("zip", nil)).to eq("2.31-2.el5")
- end
-
- it "should return version-release for matching package and arch" do
- expect(@yc.installed_version("zip", "x86_64")).to eq("2.31-2.el5")
- expect(@yc.installed_version("zisofs-tools", "i386")).to eq(nil)
- end
-
- it "should return nil for an unmatched package" do
- expect(@yc.installed_version(nil, nil)).to eq(nil)
- expect(@yc.installed_version("test1", nil)).to eq(nil)
- expect(@yc.installed_version("test2", "x86_64")).to eq(nil)
- end
- end
-
- describe "available_version" do
- it "should take one or two arguments" do
- expect { @yc.available_version("zisofs-tools") }.not_to raise_error
- expect { @yc.available_version("zisofs-tools", "i386") }.not_to raise_error
- expect { @yc.available_version("zisofs-tools", "i386", "extra") }.to raise_error(ArgumentError)
- end
-
- it "should return version-release for matching package regardless of arch" do
- expect(@yc.available_version("zip", "x86_64")).to eq("2.31-2.el5")
- expect(@yc.available_version("zip", nil)).to eq("2.31-2.el5")
- end
-
- it "should return version-release for matching package and arch" do
- expect(@yc.available_version("zip", "x86_64")).to eq("2.31-2.el5")
- expect(@yc.available_version("zisofs-tools", "i386")).to eq(nil)
- end
-
- it "should return nil for an unmatched package" do
- expect(@yc.available_version(nil, nil)).to eq(nil)
- expect(@yc.available_version("test1", nil)).to eq(nil)
- expect(@yc.available_version("test2", "x86_64")).to eq(nil)
- end
- end
-
- describe "version_available?" do
- it "should take two or three arguments" do
- expect { @yc.version_available?("zisofs-tools") }.to raise_error(ArgumentError)
- expect { @yc.version_available?("zisofs-tools", "1.0.6-3.2.2") }.not_to raise_error
- expect { @yc.version_available?("zisofs-tools", "1.0.6-3.2.2", "x86_64") }.not_to raise_error
- end
-
- it "should return true if our package-version-arch is available" do
- expect(@yc.version_available?("zisofs-tools", "1.0.6-3.2.2", "x86_64")).to eq(true)
- end
-
- it "should return true if our package-version, no arch, is available" do
- expect(@yc.version_available?("zisofs-tools", "1.0.6-3.2.2", nil)).to eq(true)
- expect(@yc.version_available?("zisofs-tools", "1.0.6-3.2.2")).to eq(true)
- end
-
- it "should return false if our package-version-arch isn't available" do
- expect(@yc.version_available?("zisofs-tools", "1.0.6-3.2.2", "pretend")).to eq(false)
- expect(@yc.version_available?("zisofs-tools", "pretend", "x86_64")).to eq(false)
- expect(@yc.version_available?("pretend", "1.0.6-3.2.2", "x86_64")).to eq(false)
- end
-
- it "should return false if our package-version, no arch, isn't available" do
- expect(@yc.version_available?("zisofs-tools", "pretend", nil)).to eq(false)
- expect(@yc.version_available?("zisofs-tools", "pretend")).to eq(false)
- expect(@yc.version_available?("pretend", "1.0.6-3.2.2")).to eq(false)
- end
- end
-
- describe "package_repository" do
- it "should take two or three arguments" do
- expect { @yc.package_repository("zisofs-tools") }.to raise_error(ArgumentError)
- expect { @yc.package_repository("zisofs-tools", "1.0.6-3.2.2") }.not_to raise_error
- expect { @yc.package_repository("zisofs-tools", "1.0.6-3.2.2", "x86_64") }.not_to raise_error
- end
-
- it "should return repoid for package-version-arch" do
- expect(@yc.package_repository("zlib-devel", "1.2.3-3", "i386")).to eq("extras")
- expect(@yc.package_repository("zlib-devel", "1.2.3-3", "x86_64")).to eq("base")
- end
-
- it "should return repoid for package-version, no arch" do
- expect(@yc.package_repository("zisofs-tools", "1.0.6-3.2.2", nil)).to eq("extras")
- expect(@yc.package_repository("zisofs-tools", "1.0.6-3.2.2")).to eq("extras")
- end
-
- it "should return nil when no match for package-version-arch" do
- expect(@yc.package_repository("zisofs-tools", "1.0.6-3.2.2", "pretend")).to eq(nil)
- expect(@yc.package_repository("zisofs-tools", "pretend", "x86_64")).to eq(nil)
- expect(@yc.package_repository("pretend", "1.0.6-3.2.2", "x86_64")).to eq(nil)
- end
-
- it "should return nil when no match for package-version, no arch" do
- expect(@yc.package_repository("zisofs-tools", "pretend", nil)).to eq(nil)
- expect(@yc.package_repository("zisofs-tools", "pretend")).to eq(nil)
- expect(@yc.package_repository("pretend", "1.0.6-3.2.2")).to eq(nil)
- end
- end
-
- describe "reset" do
- it "should empty the installed and available packages RPMDb" do
- expect(@yc.available_version("zip", "x86_64")).to eq("2.31-2.el5")
- expect(@yc.installed_version("zip", "x86_64")).to eq("2.31-2.el5")
- @yc.reset
- expect(@yc.available_version("zip", "x86_64")).to eq(nil)
- expect(@yc.installed_version("zip", "x86_64")).to eq(nil)
- end
- end
-
- describe "package_available?" do
- it "should return true a package name is available" do
- expect(@yc.package_available?("zisofs-tools")).to eq(true)
- expect(@yc.package_available?("moo")).to eq(false)
- expect(@yc.package_available?(nil)).to eq(false)
- end
-
- it "should return true a package name + arch is available" do
- expect(@yc.package_available?("zlib-devel.i386")).to eq(true)
- expect(@yc.package_available?("zisofs-tools.x86_64")).to eq(true)
- expect(@yc.package_available?("znc-test.beta1.x86_64")).to eq(true)
- expect(@yc.package_available?("znc-test.beta1")).to eq(true)
- expect(@yc.package_available?("znc-test.test.beta1")).to eq(true)
- expect(@yc.package_available?("moo.i386")).to eq(false)
- expect(@yc.package_available?("zisofs-tools.beta")).to eq(false)
- expect(@yc.package_available?("znc-test.test")).to eq(false)
- end
- end
-
- describe "enable_extra_repo_control" do
- it "should set @extra_repo_control to arg" do
- @yc.enable_extra_repo_control("--enablerepo=test")
- expect(@yc.extra_repo_control).to eq("--enablerepo=test")
- end
-
- it "should call reload once when set to flag cache for update" do
- expect(@yc).to receive(:reload).once
- @yc.enable_extra_repo_control("--enablerepo=test")
- @yc.enable_extra_repo_control("--enablerepo=test")
- end
- end
-
- describe "disable_extra_repo_control" do
- it "should set @extra_repo_control to nil" do
- @yc.enable_extra_repo_control("--enablerepo=test")
- @yc.disable_extra_repo_control
- expect(@yc.extra_repo_control).to eq(nil)
- end
-
- it "should call reload once when cleared to flag cache for update" do
- expect(@yc).to receive(:reload).once
- @yc.enable_extra_repo_control("--enablerepo=test")
- expect(@yc).to receive(:reload).once
- @yc.disable_extra_repo_control
- @yc.disable_extra_repo_control
- end
- end
-
-end
-
-describe "Chef::Provider::Package::Yum - Multi" do
- before(:each) do
- @node = Chef::Node.new
- @events = Chef::EventDispatch::Dispatcher.new
- @run_context = Chef::RunContext.new(@node, {}, @events)
- @new_resource = Chef::Resource::YumPackage.new(%w{cups vim})
- @status = double("Status", :exitstatus => 0)
- @yum_cache = double(
- "Chef::Provider::Yum::YumCache",
- :reload_installed => true,
- :reset => true,
- :installed_version => "XXXX",
- :candidate_version => "YYYY",
- :package_available? => true,
- :version_available? => true,
- :allow_multi_install => [ "kernel" ],
- :package_repository => "base",
- :disable_extra_repo_control => true
- )
- allow(Chef::Provider::Package::Yum::YumCache).to receive(:instance).and_return(@yum_cache)
- allow(@yum_cache).to receive(:yum_binary=).with("yum")
- allow(@yum_cache).to receive(:yum_binary=).with("yum")
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- @pid = double("PID")
- end
-
- describe "when evaluating the correctness of the resource" do
- it "raises an error if the array lengths of package name, arch, and version do not match up" do
- @new_resource.version(["1.1"])
- @new_resource.arch(%w{x86_64 i386 i686})
- expect { @provider.check_resource_semantics! }.to raise_error(Chef::Exceptions::InvalidResourceSpecification)
- end
- end
-
- describe "when loading the current system state" do
- it "should create a current resource with the name of the new_resource" do
- @provider.load_current_resource
- expect(@provider.current_resource.name).to eq("cups, vim")
- end
-
- it "should set the current resources package name to the new resources package name" do
- @provider.load_current_resource
- expect(@provider.current_resource.package_name).to eq(%w{cups vim})
- end
-
- it "should set the installed version to nil on the current resource if no installed package" do
- allow(@yum_cache).to receive(:installed_version).and_return(nil)
- @provider.load_current_resource
- expect(@provider.current_resource.version).to eq([nil, nil])
- end
-
- it "should set the installed version if yum has one" do
- allow(@yum_cache).to receive(:installed_version).with("cups", nil).and_return("1.2.4-11.18.el5")
- allow(@yum_cache).to receive(:installed_version).with("vim", nil).and_return("1.0")
- allow(@yum_cache).to receive(:candidate_version).with("cups", nil).and_return("1.2.4-11.18.el5_2.3")
- allow(@yum_cache).to receive(:candidate_version).with("vim", nil).and_return("1.5")
- @provider.load_current_resource
- expect(@provider.current_resource.version).to eq(["1.2.4-11.18.el5", "1.0"])
- end
-
- it "should set the candidate version if yum info has one" do
- allow(@yum_cache).to receive(:installed_version).with("cups", nil).and_return("1.2.4-11.18.el5")
- allow(@yum_cache).to receive(:installed_version).with("vim", nil).and_return("1.0")
- allow(@yum_cache).to receive(:candidate_version).with("cups", nil).and_return("1.2.4-11.18.el5_2.3")
- allow(@yum_cache).to receive(:candidate_version).with("vim", nil).and_return("1.5")
- @provider.load_current_resource
- expect(@provider.candidate_version).to eql(["1.2.4-11.18.el5_2.3", "1.5"])
- end
-
- it "should return the current resouce" do
- expect(@provider.load_current_resource).to eql(@provider.current_resource)
- end
-
- describe "when version constraint in package_name" do
- it "should set package_version if no existing package_name is found and new_package_name is available" do
- @new_resource = Chef::Resource::YumPackage.new(["cups = 1.2.4-11.18.el5_2.3", "emacs = 24.4"])
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- allow(@yum_cache).to receive(:package_available?) { |pkg| %w{cups emacs}.include?(pkg) ? true : false }
- allow(@yum_cache).to receive(:candidate_version) do |pkg|
- if pkg == "cups"
- "1.2.4-11.18.el5_2.3"
- elsif pkg == "emacs"
- "24.4"
- end
- end
- allow(@yum_cache).to receive(:packages_from_require) do |pkg|
- if pkg.name == "cups"
- [Chef::Provider::Package::Yum::RPMDbPackage.new("cups", "1.2.4-11.18.el5_2.3", "noarch", [], false, true, "base")]
- elsif pkg.name == "emacs"
- [Chef::Provider::Package::Yum::RPMDbPackage.new("emacs", "24.4", "noarch", [], false, true, "base")]
- end
- end
- expect(Chef::Log).to receive(:debug).exactly(2).times.with(%r{matched 1 package,})
- expect(Chef::Log).to receive(:debug).exactly(1).times.with(%r{candidate version: 1.2.4-11.18.el5_2.3})
- expect(Chef::Log).to receive(:debug).exactly(1).times.with(%r{candidate version: 24.4})
- expect(Chef::Log).to receive(:debug).at_least(2).times.with(%r{checking yum info})
- @provider.load_current_resource
- expect(@provider.new_resource.package_name).to eq(%w{cups emacs})
- expect(@provider.new_resource.version).to eq(["1.2.4-11.18.el5_2.3", "24.4"])
- expect(@provider.send(:package_name_array)).to eq(%w{cups emacs})
- expect(@provider.send(:new_version_array)).to eq(["1.2.4-11.18.el5_2.3", "24.4"])
- end
- end
- end
-
- describe "when installing a package" do
- it "should run yum install with the package name and version" do
- @provider.load_current_resource
- allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1)
- allow(@yum_cache).to receive(:installed_version).with("cups", nil).and_return("1.2.4-11.18.el5")
- allow(@yum_cache).to receive(:installed_version).with("vim", nil).and_return("0.9")
- expect(@provider).to receive(:yum_command).with(
- "-d0 -e0 -y install cups-1.2.4-11.19.el5 vim-1.0"
- )
- @provider.install_package(%w{cups vim}, ["1.2.4-11.19.el5", "1.0"])
- end
-
- it "should not run yum install with nil package name" do
- @provider.load_current_resource
- allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1)
- expect(@provider).to receive(:yum_command).with(
- "-d0 -e0 -y install cups-1.2.4-11.19.el5"
- )
- @provider.install_package(["cups", nil], ["1.2.4-11.19.el5", nil])
- end
-
- it "should run yum install with the package name, version and arch" do
- @provider.load_current_resource
- @new_resource.arch(%w{i386 i386})
- allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1)
- expect(@provider).to receive(:yum_command).with(
- "-d0 -e0 -y install cups-1.2.4-11.19.el5.i386 vim-1.0.i386"
- )
- @provider.install_package(%w{cups vim}, ["1.2.4-11.19.el5", "1.0"])
- end
-
- it "installs the package with the options given in the resource" do
- @provider.load_current_resource
- allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1)
- allow(@yum_cache).to receive(:installed_version).with("cups", nil).and_return("1.2.4-11.18.el5")
- allow(@yum_cache).to receive(:installed_version).with("vim", nil).and_return("0.9")
- expect(@provider).to receive(:yum_command).with(
- "-d0 -e0 -y --disablerepo epmd install cups-1.2.4-11.19.el5 vim-1.0"
- )
- @new_resource.options("--disablerepo epmd")
- @provider.install_package(%w{cups vim}, ["1.2.4-11.19.el5", "1.0"])
- end
-
- it "should run yum install with the package name and version when name has arch" do
- @new_resource = Chef::Resource::YumPackage.new(["cups.x86_64", "vim"])
- @provider = Chef::Provider::Package::Yum.new(@new_resource, @run_context)
- allow(Chef::Provider::Package::Yum::RPMUtils).to receive(:rpmvercmp).and_return(-1)
-
- # Inside of load_current_resource() we'll call parse_arch for cups,
- # and we need to craft the right response. The default mock setup above
- # will just return valid versions all the time which won't work for this
- # test.
- allow(@yum_cache).to receive(:installed_version).with("cups", "x86_64").and_return("XXXX")
- allow(@yum_cache).to receive(:candidate_version).with("cups", "x86_64").and_return("1.2.4-11.18.el5")
- allow(@yum_cache).to receive(:installed_version).with("cups.x86_64").and_return(nil)
- allow(@yum_cache).to receive(:candidate_version).with("cups.x86_64").and_return(nil)
-
- # Normal mock's for the idempotency check
- allow(@yum_cache).to receive(:installed_version).with("cups", nil).and_return("1.2.4-11.18.el5")
- allow(@yum_cache).to receive(:installed_version).with("vim", nil).and_return("0.9")
-
- @provider.load_current_resource
- expect(@provider).to receive(:yum_command).with(
- "-d0 -e0 -y install cups-1.2.4-11.19.el5.x86_64 vim-1.0"
- )
- @provider.install_package(%w{cups vim}, ["1.2.4-11.19.el5", "1.0"])
- end
-
- end
-end
diff --git a/spec/unit/provider_resolver_spec.rb b/spec/unit/provider_resolver_spec.rb
index a913c82a1e..66b53b2f4a 100644
--- a/spec/unit/provider_resolver_spec.rb
+++ b/spec/unit/provider_resolver_spec.rb
@@ -1,6 +1,6 @@
#
# Author:: Lamont Granquist (<lamont@chef.io>)
-# Copyright:: Copyright 2014-2016, Chef Software Inc.
+# Copyright:: Copyright 2014-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -601,13 +601,9 @@ describe Chef::ProviderResolver do
windows_package: [ Chef::Resource::WindowsPackage, Chef::Provider::Package::Windows ],
windows_service: [ Chef::Resource::WindowsService, Chef::Provider::Service::Windows ],
windows_user: [ Chef::Resource::User::WindowsUser, Chef::Provider::User::Windows ],
-
- # We want to check that these are unsupported:
- yum_package: nil,
+ yum_package: [ Chef::Resource::YumPackage, Chef::Provider::Package::Yum ],
"linux" => {
- yum_package: [ Chef::Resource::YumPackage, Chef::Provider::Package::Yum ],
-
"debian" => {
ifconfig: [ Chef::Resource::Ifconfig, Chef::Provider::Ifconfig::Debian ],
package: [ Chef::Resource::AptPackage, Chef::Provider::Package::Apt ],