diff options
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/provider/package.rb | 14 | ||||
-rw-r--r-- | lib/chef/provider/package/dnf.rb | 36 |
2 files changed, 33 insertions, 17 deletions
diff --git a/lib/chef/provider/package.rb b/lib/chef/provider/package.rb index f96ce34fc0..514975b24d 100644 --- a/lib/chef/provider/package.rb +++ b/lib/chef/provider/package.rb @@ -53,7 +53,7 @@ class Chef # [ this may arguably be useful for all package providers and it greatly simplifies the logic # in the superclass that gets executed, so maybe this should always be used now? ] # - subclass_directive :installed_version_satisfies_version_constraints + subclass_directive :use_magic_version # # Hook that subclasses use to populate the candidate_version(s) @@ -434,7 +434,7 @@ class Chef case action when :upgrade if current_version.nil? - # with installed_version_satisfies_version_constraints there may be a package installed, but it fails the user's + # with use_magic_version there may be a package installed, but it fails the user's # requested new_resource.version constraints logger.trace("#{new_resource} has no existing installed version. Installing install #{candidate_version}") target_version_array.push(candidate_version) @@ -457,7 +457,7 @@ class Chef end when :install - if new_version && !installed_version_satisfies_version_constraints? + if new_version && !use_magic_version? if version_requirement_satisfied?(current_version, new_version) logger.trace("#{new_resource} #{package_name} #{current_version} satisfies #{new_version} requirement") target_version_array.push(nil) @@ -469,7 +469,7 @@ class Chef target_version_array.push(new_version) end elsif current_version.nil? - # with installed_version_satisfies_version_constraints there may be a package installed, but it fails the user's + # with use_magic_version there may be a package installed, but it fails the user's # requested new_resource.version constraints logger.trace("#{new_resource} #{package_name} not installed, installing #{candidate_version}") target_version_array.push(candidate_version) @@ -531,8 +531,8 @@ class Chef each_package do |package_name, new_version, current_version, candidate_version| next if new_version.nil? || current_version.nil? - if installed_version_satisfies_version_constraints? - if !current_version && candidate_version.nil? + if use_magic_version? + if !magic_version && candidate_version.nil? missing.push(package_name) end else @@ -551,7 +551,7 @@ class Chef def each_package package_name_array.each_with_index do |package_name, i| candidate_version = candidate_version_array[i] - current_version = current_version_array[i] + current_version = use_magic_version? ? magic_version[i] : current_version_array[i] new_version = new_version_array[i] yield package_name, new_version, current_version, candidate_version end diff --git a/lib/chef/provider/package/dnf.rb b/lib/chef/provider/package/dnf.rb index a0e1d299e6..5e1e767bb4 100644 --- a/lib/chef/provider/package/dnf.rb +++ b/lib/chef/provider/package/dnf.rb @@ -34,7 +34,7 @@ class Chef allow_nils use_multipackage_api use_package_name_for_source - installed_version_satisfies_version_constraints + use_magic_version # all rhel variants >= 8 will use DNF provides :package, platform_family: "rhel", platform_version: ">= 8" @@ -74,7 +74,7 @@ class Chef def load_after_resource # force the installed version array to repopulate - @installed_version = [] + @current_version = [] @after_resource = Chef::Resource::DnfPackage.new(new_resource.name) after_resource.package_name(new_resource.package_name) after_resource.version(get_current_versions) @@ -98,9 +98,15 @@ class Chef end end + def magic_version + package_name_array.each_with_index.map do |pkg, i| + magical_version(i).version_with_arch + end + end + def get_current_versions package_name_array.each_with_index.map do |pkg, i| - installed_version(i).version_with_arch + current_version(i).version_with_arch end end @@ -118,7 +124,7 @@ class Chef alias upgrade_package install_package def remove_package(names, versions) - resolved_names = names.each_with_index.map { |name, i| installed_version(i).to_s unless name.nil? } + resolved_names = names.each_with_index.map { |name, i| magical_version(i).to_s unless name.nil? } dnf(options, "-y", "remove", resolved_names) flushcache end @@ -148,10 +154,10 @@ class Chef def resolved_package_lock_names(names) names.each_with_index.map do |name, i| unless name.nil? - if installed_version(i).version.nil? + if magical_version(i).version.nil? available_version(i).name else - installed_version(i).name + magical_version(i).name end end end @@ -216,16 +222,26 @@ class Chef end # @return [Array<Version>] - def installed_version(index) - @installed_version ||= [] - @installed_version[index] ||= if new_resource.source + def magical_version(index) + @magical_version ||= [] + @magical_version[index] ||= if new_resource.source python_helper.package_query(:whatinstalled, available_version(index).name, version: safe_version_array[index], arch: safe_arch_array[index], options: options) else python_helper.package_query(:whatinstalled, package_name_array[index], version: safe_version_array[index], arch: safe_arch_array[index], options: options) end - @installed_version[index] + @magical_version[index] end + def current_version(index) + @current_version ||= [] + @current_version[index] ||= if new_resource.source + python_helper.package_query(:whatinstalled, available_version(index).name, arch: safe_arch_array[index], options: options) + else + python_helper.package_query(:whatinstalled, package_name_array[index], arch: safe_arch_array[index], options: options) + end + @current_version[index] + end + # 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. |