diff options
author | Phil Dibowitz <phil@ipom.com> | 2015-01-15 16:48:09 -0800 |
---|---|---|
committer | Phil Dibowitz <phil@ipom.com> | 2015-02-03 19:32:36 -0800 |
commit | 48e2d436830528cd2364868981cf9b46f3c91d6a (patch) | |
tree | e4d87bd695ae0dc58b6046764d97a16947730dc2 /lib | |
parent | 1c0134bacd2248b5d5c31c94a941d7ccf5784911 (diff) | |
download | chef-48e2d436830528cd2364868981cf9b46f3c91d6a.tar.gz |
Revert "Make yum always use arrays internally"
This reverts commit a88c852e7166c2d209d0670f668cf67feab19222.
We can't easily do this without changing a LOT of other assumptions. Since all
the consumer sites already call `as_array` functions, it's easier to keep those
safe.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/provider/package/apt.rb | 16 | ||||
-rw-r--r-- | lib/chef/provider/package/yum.rb | 82 |
2 files changed, 40 insertions, 58 deletions
diff --git a/lib/chef/provider/package/apt.rb b/lib/chef/provider/package/apt.rb index b523cdc7cc..099a4a9b61 100644 --- a/lib/chef/provider/package/apt.rb +++ b/lib/chef/provider/package/apt.rb @@ -51,17 +51,19 @@ class Chef end def check_package_state(package) - final_installed_version = [] - final_candidate_version = [] - final_installed = [] - final_virtual = [] + if package.is_a?(Array) + final_installed_version = [] + final_candidate_version = [] + final_installed = [] + final_virtual = [] + end installed = virtual = false installed_version = candidate_version = nil [package].flatten.each do |pkg| installed = virtual = false installed_version = candidate_version = nil - shell_out!("apt-cache#{expand_options(default_release_options)} policy #{pkg}", {:timeout=>900}).stdout.each_line do |line| + shell_out!("apt-cache#{expand_options(default_release_options)} policy #{pkg}").stdout.each_line do |line| case line when /^\s{2}Installed: (.+)$/ installed_version = $1 @@ -77,9 +79,9 @@ class Chef if candidate_version == '(none)' # This may not be an appropriate assumption, but it shouldn't break anything that already worked -- btm virtual = true - showpkg = shell_out!("apt-cache showpkg #{package}", {:timeout => 900}).stdout + showpkg = shell_out!("apt-cache showpkg #{package}").stdout providers = Hash.new - showpkg.rpartition(/Reverse Provides: ?#{$/}/)[2].each_line do |line| + showpkg.rpartition(/Reverse Provides:? #{$/}/)[2].each_line do |line| provider, version = line.split providers[provider] = version end diff --git a/lib/chef/provider/package/yum.rb b/lib/chef/provider/package/yum.rb index 670437c297..c85cfd20c8 100644 --- a/lib/chef/provider/package/yum.rb +++ b/lib/chef/provider/package/yum.rb @@ -1068,9 +1068,6 @@ class Chef parse_arch end - # normalize internal representation as an array - @new_resource.package_name(as_array(@new_resource.package_name)) - @current_resource = Chef::Resource::Package.new(@new_resource.name) @current_resource.package_name(@new_resource.package_name) @@ -1103,12 +1100,12 @@ class Chef installed_version << @yum.installed_version(pkg, arch) @candidate_version << @yum.candidate_version(pkg, arch) end - #if installed_version.size == 1 - # @current_resource.version(installed_version[0]) - # @candidate_version = @candidate_version[0] - #else - @current_resource.version(installed_version.flatten) - #end + if installed_version.size == 1 + @current_resource.version(installed_version[0]) + @candidate_version = @candidate_version[0] + else + @current_resource.version(installed_version) + end Chef::Log.debug("#{@new_resource} installed version: #{installed_version || "(none)"} candidate version: " + "#{@candidate_version || "(none)"}") @@ -1119,62 +1116,45 @@ class Chef 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)).any? do |n, v| - @yum.version_available?(n, v, arch) - end - method = log_method = nil - methods = [] - if all_avail + if !name.is_a?(Array) && @yum.version_available?(name, version, arch) + method = "install" + log_method = "installing" + # 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(as_array(version)).each do |n, v| - method = "install" - log_method = "installing" - idx = package_name_array.index(n) - unless @yum.allow_multi_install.include?(n) - if RPMVersion.parse(current_version_array[idx]) > 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 #{name}-#{@current_resource.version} is newer " + - "than candidate package #{name}-#{version}" - end + unless @yum.allow_multi_install.include?(name) + if RPMVersion.parse(@current_resource.version) > RPMVersion.parse(version) + # Unless they want this... + if allow_downgrade + method = "downgrade" + log_method = "downgrading" + else + # we bail like yum when the package is older + raise Chef::Exceptions::Package, "Installed package #{name}-#{@current_resource.version} is newer " + + "than candidate package #{name}-#{version}" end end - # methods don't count for packages we won't be touching - next if RPMVersion.parse(current_version_array[idx]) == RPMVersion.parse(v) - methods << method - 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 - repos = [] - pkg_string_bits = [] + repo = @yum.package_repository(name, version, arch) + Chef::Log.info("#{@new_resource} #{log_method} #{name}-#{version}#{yum_arch} from #{repo} repository") + + yum_command("yum -d0 -e0 -y#{expand_options(@new_resource.options)} #{method} #{name}-#{version}#{yum_arch}") + elsif name.is_a?(Array) index = 0 - as_array(name).zip(as_array(version)).each do |n, v| + pkg_string = name.zip(version).map do |x| s = '' - unless v == current_version_array[index] - s = "#{n}-#{v}#{yum_arch}" - repo = @yum.package_repository(n, v, arch) - repos << "#{s} from #{repo} repository" - pkg_string_bits << s + unless x[1] == @current_resource.version[index] + s = "#{x.join('-')}#{yum_arch}" end index += 1 - end - pkg_string = pkg_string_bits.join(' ') - Chef::Log.info("#{@new_resource} #{log_method} #{repos.join(' ')}") - yum_command("yum -d0 -e0 -y#{expand_options(@new_resource.options)} #{method} #{pkg_string}") + s + end.join(' ') + yum_command("yum -d0 -e0 -y#{expand_options(@new_resource.options)} install #{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)" |