From 859a5036201ccdbb1c7e82f9aac093380e956b51 Mon Sep 17 00:00:00 2001 From: Mark Vanderwiel Date: Thu, 29 May 2014 11:14:12 -0500 Subject: [PATCH 1/2] Merge branch 'master', remote-tracking branch 'upstream/master' From 785a2452e0b6ed6d7d485ef5c00a7bd43a19e116 Mon Sep 17 00:00:00 2001 From: Mark Vanderwiel Date: Wed, 14 May 2014 15:44:37 -0500 Subject: [PATCH 2/2] CHEF-3193: LOCK_TIMEOUT in yum-dump.py should be configurable Allow yum lock timeout from Chef Config yum_timeout. Issue: CHEF-3193 --- lib/chef/config.rb | 1 + lib/chef/provider/package/yum-dump.py | 12 ++++++------ lib/chef/provider/package/yum.rb | 2 ++ spec/unit/provider/package/yum_spec.rb | 15 +++++++++++---- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/lib/chef/config.rb b/lib/chef/config.rb index d884aabc3dd..694b43ff377 100644 --- a/lib/chef/config.rb +++ b/lib/chef/config.rb @@ -313,6 +313,7 @@ def self.derive_path_from_chef_repo_path(child_path) default :rest_timeout, 300 default :yum_timeout, 900 + default :yum_lock_timeout, 30 default :solo, false default :splay, nil default :why_run, false diff --git a/lib/chef/provider/package/yum-dump.py b/lib/chef/provider/package/yum-dump.py index a8f3995e8cc..7e86994c649 100644 --- a/lib/chef/provider/package/yum-dump.py +++ b/lib/chef/provider/package/yum-dump.py @@ -43,9 +43,6 @@ YUM_PID_FILE='/var/run/yum.pid' -# Seconds to wait for exclusive access to yum -LOCK_TIMEOUT = 10 - YUM_VER = version.StrictVersion(yum.__version__) YUM_MAJOR = YUM_VER.version[0] @@ -219,8 +216,8 @@ def yum_dump(options): # Wrap the collection and output of packages in yum's global lock to prevent # any inconsistencies. try: - # Spin up to LOCK_TIMEOUT - countdown = LOCK_TIMEOUT + # Spin up to --yum-lock-timeout option + countdown = options.yum_lock_timeout while True: try: yb.doLock(YUM_PID_FILE) @@ -230,7 +227,7 @@ def yum_dump(options): countdown -= 1 if countdown == 0: print >> sys.stderr, "yum-dump Locking Error! Couldn't obtain an " \ - "exclusive yum lock in %d seconds. Giving up." % LOCK_TIMEOUT + "exclusive yum lock in %d seconds. Giving up." % options.yum_lock_timeout return 200 else: break @@ -281,6 +278,9 @@ def main(): parser.add_option("--disablerepo", action="callback", callback=gather_repo_opts, type="string", dest="repo_control", default=[], help="disable repositories by id or glob") + parser.add_option("--yum-lock-timeout", + action="callback", type="int", dest="yum_lock_timeout", default=30, + help="Time in seconds to wait for yum process lock") (options, args) = parser.parse_args() diff --git a/lib/chef/provider/package/yum.rb b/lib/chef/provider/package/yum.rb index f56d3140b6d..c241c7fd6d4 100644 --- a/lib/chef/provider/package/yum.rb +++ b/lib/chef/provider/package/yum.rb @@ -704,6 +704,8 @@ def refresh opts << " #{@extra_repo_control}" end + opts << " --yum-lock-timeout #{Chef::Config[:yum_lock_timeout]}" + one_line = false error = nil diff --git a/spec/unit/provider/package/yum_spec.rb b/spec/unit/provider/package/yum_spec.rb index adbcd867227..9b3b6b60e00 100644 --- a/spec/unit/provider/package/yum_spec.rb +++ b/spec/unit/provider/package/yum_spec.rb @@ -1619,25 +1619,32 @@ def reset_instance it "should run yum-dump.py using the system python when next_refresh is for :all" do @yc.reload - @yc.should_receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --options --installed-provides$}, :timeout=>Chef::Config[:yum_timeout]) + @yc.should_receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --options --installed-provides --yum-lock-timeout 30$}, :timeout=>Chef::Config[:yum_timeout]) @yc.refresh end it "should run yum-dump.py with the installed flag when next_refresh is for :installed" do @yc.reload_installed - @yc.should_receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --installed$}, :timeout=>Chef::Config[:yum_timeout]) + @yc.should_receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --installed --yum-lock-timeout 30$}, :timeout=>Chef::Config[:yum_timeout]) @yc.refresh end it "should run yum-dump.py with the all-provides flag when next_refresh is for :provides" do @yc.reload_provides - @yc.should_receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --options --all-provides$}, :timeout=>Chef::Config[:yum_timeout]) + @yc.should_receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --options --all-provides --yum-lock-timeout 30$}, :timeout=>Chef::Config[:yum_timeout]) @yc.refresh end it "should pass extra_repo_control args to yum-dump.py" do @yc.enable_extra_repo_control("--enablerepo=foo --disablerepo=bar") - @yc.should_receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --options --installed-provides --enablerepo=foo --disablerepo=bar$}, :timeout=>Chef::Config[:yum_timeout]) + @yc.should_receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --options --installed-provides --enablerepo=foo --disablerepo=bar --yum-lock-timeout 30$}, :timeout=>Chef::Config[:yum_timeout]) + @yc.refresh + end + + it "should pass extra_repo_control args and configured yum lock timeout to yum-dump.py" do + Chef::Config[:yum_lock_timeout] = 999 + @yc.enable_extra_repo_control("--enablerepo=foo --disablerepo=bar") + @yc.should_receive(:shell_out!).with(%r{^/usr/bin/python .*/yum-dump.py --options --installed-provides --enablerepo=foo --disablerepo=bar --yum-lock-timeout 999$}, :timeout=>Chef::Config[:yum_timeout]) @yc.refresh end