diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2021-05-06 20:03:37 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2021-05-06 20:03:37 -0700 |
commit | ab14480498e1d29095d13c17f1195c9d8414dcda (patch) | |
tree | 0d8fa109765cea8ec3f01b5064d36217ff91c672 | |
parent | 364b9236f4a90b00aee9a91a18651cbcc4e38e6b (diff) | |
download | chef-ab14480498e1d29095d13c17f1195c9d8414dcda.tar.gz |
Use buffered i/o for yum and disable repos in testing
This sync's the yum provider back up with the further work done
on the dnf provider.
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r-- | lib/chef/provider/package/yum/python_helper.rb | 14 | ||||
-rw-r--r-- | lib/chef/provider/package/yum/yum_helper.py | 4 | ||||
-rw-r--r-- | spec/functional/resource/yum_package_spec.rb | 12 |
3 files changed, 14 insertions, 16 deletions
diff --git a/lib/chef/provider/package/yum/python_helper.rb b/lib/chef/provider/package/yum/python_helper.rb index 926efef8f3..db929ea88b 100644 --- a/lib/chef/provider/package/yum/python_helper.rb +++ b/lib/chef/provider/package/yum/python_helper.rb @@ -51,9 +51,6 @@ class Chef end def start - # For some reason we have to force python to unbuffered here, and then force the input pipe back to line - # buffered in the python code. XXX: I tried to remove this but hit more issues in the python side. - ENV["PYTHONUNBUFFERED"] = "1" @inpipe, inpipe_write = IO.pipe outpipe_read, @outpipe = IO.pipe @stdin, @stdout, @stderr, @wait_thr = Open3.popen3("#{yum_command} #{outpipe_read.fileno} #{inpipe_write.fileno}", outpipe_read.fileno => outpipe_read, inpipe_write.fileno => inpipe_write, close_others: false) @@ -76,7 +73,7 @@ class Chef stderr.close unless stderr.nil? inpipe.close unless inpipe.nil? outpipe.close unless outpipe.nil? - stdin = stdout = stderr = inpipe = outpipe = wait_thr = nil + @stdin = @stdout = @stderr = @inpipe = @outpipe = @wait_thr = nil end end @@ -163,8 +160,9 @@ class Chef with_helper do json = build_query(action, parameters) Chef::Log.trace "sending '#{json}' to python helper" - outpipe.syswrite json + "\n" - output = inpipe.sysread(4096).chomp + outpipe.puts json + outpipe.flush + output = inpipe.readline.chomp Chef::Log.trace "got '#{output}' from python helper" output end @@ -214,13 +212,13 @@ class Chef Chef::Log.trace "discarding output on stderr/stdout from python helper: #{output}" end ret - rescue EOFError, Errno::EPIPE, Timeout::Error, Errno::ESRCH => e + rescue => e output = drain_fds + restart if ( max_retries -= 1 ) > 0 && !ENV["YUM_HELPER_NO_RETRIES"] unless output.empty? Chef::Log.trace "discarding output on stderr/stdout from python helper: #{output}" end - restart retry else raise e if output.empty? diff --git a/lib/chef/provider/package/yum/yum_helper.py b/lib/chef/provider/package/yum/yum_helper.py index 7e6f193054..4dfe0cb24b 100644 --- a/lib/chef/provider/package/yum/yum_helper.py +++ b/lib/chef/provider/package/yum/yum_helper.py @@ -47,9 +47,9 @@ def versioncompare(versions): def install_only_packages(base, name): if name in base.conf.installonlypkgs: - outpipe.write('True') + outpipe.write('True\n') else: - outpipe.write('False') + outpipe.write('False\n') outpipe.flush() def query(base, command): diff --git a/spec/functional/resource/yum_package_spec.rb b/spec/functional/resource/yum_package_spec.rb index 2b08736d5b..d401651f70 100644 --- a/spec/functional/resource/yum_package_spec.rb +++ b/spec/functional/resource/yum_package_spec.rb @@ -71,7 +71,7 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do FileUtils.rm_f "/etc/yum.repos.d/chef-yum-localtesting.repo" end - let(:default_options) { "--nogpgcheck" } # --disablerepo=* --enablerepo=chef-yum-localtesting' } + let(:default_options) { "--nogpgcheck --disablerepo=* --enablerepo=chef-yum-localtesting" } def pkg_arch OHAI_SYSTEM[:kernel][:machine] @@ -526,7 +526,7 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do FileUtils.rm_f "/etc/yum.repos.d/chef-yum-localtesting.repo" preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") yum_package "chef_rpm" do - options default_options + options "--nogpgcheck" end.should_not_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") end @@ -535,7 +535,7 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do FileUtils.rm_f "/etc/yum.repos.d/chef-yum-localtesting.repo" flush_cache yum_package("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm") do - options default_options + options "--nogpgcheck" end.should_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") end @@ -731,7 +731,7 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do FileUtils.rm_f "/etc/yum.repos.d/chef-yum-localtesting.repo" preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") yum_package("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm") do - options default_options + options "--nogpgcheck" action :upgrade end.should_not_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") @@ -741,7 +741,7 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do FileUtils.rm_f "/etc/yum.repos.d/chef-yum-localtesting.repo" flush_cache yum_package("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm") do - options default_options + options "--nogpgcheck" action :upgrade end.should_be_updated expect_matching_installed_version("^chef_rpm-1.2-1.#{pkg_arch}$") @@ -971,7 +971,7 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do FileUtils.rm_f "/etc/yum.repos.d/chef-yum-localtesting.repo" preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm") yum_package "chef_rpm" do - options default_options + options "--nogpgcheck" action :remove end.should_be_updated expect_matching_installed_version("^package chef_rpm is not installed$") |