summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/provider/yum_repository.rb14
-rw-r--r--lib/chef/resource/yum_repository.rb4
-rw-r--r--spec/unit/resource/yum_repository_spec.rb4
3 files changed, 21 insertions, 1 deletions
diff --git a/lib/chef/provider/yum_repository.rb b/lib/chef/provider/yum_repository.rb
index a3d19e95d3..9b32896733 100644
--- a/lib/chef/provider/yum_repository.rb
+++ b/lib/chef/provider/yum_repository.rb
@@ -44,7 +44,12 @@ class Chef
mode new_resource.mode
if new_resource.make_cache
notifies :run, "execute[yum clean metadata #{new_resource.repositoryid}]", :immediately if new_resource.clean_metadata || new_resource.clean_headers
- notifies :run, "execute[yum-makecache-#{new_resource.repositoryid}]", :immediately
+ # makecache fast only works on non-dnf systems.
+ if !which "dnf" && new_resource.makecache_fast
+ notifies :run, "execute[yum-makecache-fast-#{new_resource.repositoryid}]", :immediately
+ else
+ notifies :run, "execute[yum-makecache-#{new_resource.repositoryid}]", :immediately
+ end
notifies :flush_cache, "package[package-cache-reload-#{new_resource.repositoryid}]", :immediately
end
end
@@ -63,6 +68,13 @@ class Chef
only_if { new_resource.enabled }
end
+ # download only the minimum required metadata
+ execute "yum-makecache-fast-#{new_resource.repositoryid}" do
+ command "yum -q -y makecache fast --disablerepo=* --enablerepo=#{new_resource.repositoryid}"
+ action :nothing
+ only_if { new_resource.enabled }
+ end
+
package "package-cache-reload-#{new_resource.repositoryid}" do
action :nothing
end
diff --git a/lib/chef/resource/yum_repository.rb b/lib/chef/resource/yum_repository.rb
index fcddd8a50f..436734c003 100644
--- a/lib/chef/resource/yum_repository.rb
+++ b/lib/chef/resource/yum_repository.rb
@@ -114,6 +114,10 @@ class Chef
description: "Determines whether package files downloaded by Yum stay in cache directories. By using cached data, you can carry out certain operations without a network connection.",
default: true
+ property :makecache_fast, [TrueClass, FalseClass],
+ description: "if make_cache is true, uses `yum makecache fast`, which downloads only the minimum amount of data required. Useful over slower connections and when disk space is at a premium.",
+ default: false
+
property :max_retries, [String, Integer],
description: "Number of times any attempt to retrieve a file should retry before returning an error. Setting this to `0` makes Yum try forever."
diff --git a/spec/unit/resource/yum_repository_spec.rb b/spec/unit/resource/yum_repository_spec.rb
index 36d88450d1..0c6e4d5632 100644
--- a/spec/unit/resource/yum_repository_spec.rb
+++ b/spec/unit/resource/yum_repository_spec.rb
@@ -68,6 +68,10 @@ describe Chef::Resource::YumRepository do
expect(resource.make_cache).to eql(true)
end
+ it "makecache_fast property defaults to false" do
+ expect(resource.makecache_fast).to eql(false)
+ end
+
it "mode property defaults to '0644'" do
expect(resource.mode).to eql("0644")
end