summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-12-16 15:51:26 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2016-12-16 15:51:26 -0800
commit0c13033821905019a8d05ef5c1bb47efb638d57f (patch)
tree204f90814ce90d82f81157d043c0e13dfa529fc4
parentb18272eeef335cde79a21a96c4686271dc3d290c (diff)
downloadchef-lcg/dnf-install-supercharging.tar.gz
use the dnf-helper to do installs as a speed boostlcg/dnf-install-supercharging
eliminates the need to flush the cache entirely after doing install actions. speed boost on a set of 14 chef dnf_package resources (not multipackage) is: with the patch: 0.030000 0.060000 18.070000 ( 19.413037) without the patch: 0.060000 0.130000 24.470000 ( 27.511077) based on those numbers i think the major problem is that dnf is slow and that multipackage installs is a better approach to speeding them up. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/provider/package/dnf.rb6
-rw-r--r--lib/chef/provider/package/dnf/dnf_helper.py39
-rw-r--r--spec/functional/resource/dnf_package_spec.rb4
3 files changed, 40 insertions, 9 deletions
diff --git a/lib/chef/provider/package/dnf.rb b/lib/chef/provider/package/dnf.rb
index f48b1341a6..4038e1c999 100644
--- a/lib/chef/provider/package/dnf.rb
+++ b/lib/chef/provider/package/dnf.rb
@@ -88,8 +88,10 @@ class Chef
if new_resource.source
dnf(new_resource.options, "-y install", new_resource.source)
else
- resolved_names = names.each_with_index.map { |name, i| available_version(i).to_s unless name.nil? }
- dnf(new_resource.options, "-y install", resolved_names)
+ names.each_with_index.each do |name, i|
+ next if name.nil?
+ python_helper.query(:install, available_version(i).to_s, nil, nil)
+ end
end
flushcache_after
end
diff --git a/lib/chef/provider/package/dnf/dnf_helper.py b/lib/chef/provider/package/dnf/dnf_helper.py
index 236b967710..69cffadecc 100644
--- a/lib/chef/provider/package/dnf/dnf_helper.py
+++ b/lib/chef/provider/package/dnf/dnf_helper.py
@@ -26,7 +26,7 @@ def flushcache():
pass
get_sack().load_system_repo(build_cache=True)
-def query(command):
+def get_pkgspec(command):
sack = get_sack()
subj = dnf.subject.Subject(command['provides'])
@@ -56,12 +56,39 @@ def query(command):
pkgs = dnf.query.latest_limit_pkgs(q, 1)
if not pkgs:
+ return None
+
+ # make sure we picked the package with the highest version
+ pkgs.sort
+ return pkgs.pop()
+
+def query(command):
+ pkg_spec = get_pkgspec(command)
+
+ if pkg_spec is None:
sys.stdout.write('{} nil nil\n'.format(command['provides'].split().pop(0)))
else:
- # make sure we picked the package with the highest version
- pkgs.sort
- pkg = pkgs.pop()
- sys.stdout.write('{} {}:{}-{} {}\n'.format(pkg.name, pkg.epoch, pkg.version, pkg.release, pkg.arch))
+ sys.stdout.write('{} {}:{}-{} {}\n'.format(pkg_spec.name, pkg_spec.epoch, pkg_spec.version, pkg_spec.release, pkg_spec.arch))
+
+def install(command):
+ command['action'] = "whatavailable"
+ pkg_spec = get_pkgspec(command)
+ if pkg_spec is None:
+ raise RuntimeError("no available package")
+
+ sys.stderr.write('FOO1')
+ base.package_install(pkg_spec)
+ sys.stderr.write('FOO2')
+
+ base.resolve()
+ sys.stderr.write('FOO3')
+
+ base.download_packages(base.transaction.install_set)
+ sys.stderr.write('FOO4')
+
+ base.do_transaction()
+ sys.stderr.write('FOO5')
+ sys.stdout.write('{} {}:{}-{} {}\n'.format(pkg_spec.name, pkg_spec.epoch, pkg_spec.version, pkg_spec.release, pkg_spec.arch))
# 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
@@ -85,6 +112,8 @@ while 1:
query(command)
elif command['action'] == "whatavailable":
query(command)
+ elif command['action'] == "install":
+ install(command)
elif command['action'] == "flushcache":
flushcache()
else:
diff --git a/spec/functional/resource/dnf_package_spec.rb b/spec/functional/resource/dnf_package_spec.rb
index 4c9ee6ca97..89aa6c2a62 100644
--- a/spec/functional/resource/dnf_package_spec.rb
+++ b/spec/functional/resource/dnf_package_spec.rb
@@ -80,10 +80,10 @@ 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 match(/chef_rpm-1.10-1.fc24.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 match(/chef_rpm-1.10-1.fc24.x86_64/)
end
it "does not install if the prior version package is installed" do