diff options
author | Stuart Sears <stuart@sjsears.com> | 2023-01-03 20:05:09 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-03 15:05:09 -0500 |
commit | 1acfc3938533ea4128b30dd9273f68909025e42f (patch) | |
tree | 7f405a03e220e62e33fb68b51be2aa3b8ea5e723 | |
parent | 5b0f77576222375f34edf15a9a8ff3ffba983db9 (diff) | |
download | chef-1acfc3938533ea4128b30dd9273f68909025e42f.tar.gz |
Adds 'makecache_fast' property to `yum_repository` minimise cached repodata (#12915)
* Adds 'makecache_fast' property to minimise cached repodata
* add makecache_fast property to unit test
* no makecache fast on dnf systems
* correct property in unit test
Signed-off-by: Stuart Sears <stuart@sjsears.com>
-rw-r--r-- | lib/chef/provider/yum_repository.rb | 14 | ||||
-rw-r--r-- | lib/chef/resource/yum_repository.rb | 4 | ||||
-rw-r--r-- | spec/unit/resource/yum_repository_spec.rb | 4 |
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 |