diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2018-04-12 09:26:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-12 09:26:28 -0700 |
commit | 870f1aeb7574f02116fb2e46014cf82c090070d4 (patch) | |
tree | a97cf2c9f1782519a7635525aea4e36290fea0cc | |
parent | 415c82c77489b25000ef22040168eee33950ebaf (diff) | |
parent | 0df0f951daf96ad8c80d5915cf83d281ccd5e862 (diff) | |
download | chef-870f1aeb7574f02116fb2e46014cf82c090070d4.tar.gz |
Merge pull request #7148 from chef/lcg/enable-repo-fix
fix for enable/disable repo ordering
-rw-r--r-- | lib/chef/provider/package/yum/python_helper.rb | 8 | ||||
-rw-r--r-- | lib/chef/provider/package/yum/yum_helper.py | 27 | ||||
-rw-r--r-- | spec/functional/resource/yum_package_spec.rb | 8 |
3 files changed, 26 insertions, 17 deletions
diff --git a/lib/chef/provider/package/yum/python_helper.rb b/lib/chef/provider/package/yum/python_helper.rb index df21a9f091..0a09e12c3d 100644 --- a/lib/chef/provider/package/yum/python_helper.rb +++ b/lib/chef/provider/package/yum/python_helper.rb @@ -93,14 +93,14 @@ class Chef options.each_with_object({}) do |opt, h| if opt =~ /--enablerepo=(.+)/ $1.split(",").each do |repo| - h["enablerepos"] ||= [] - h["enablerepos"].push(repo) + h["repos"] ||= [] + h["repos"].push( { "enable" => repo } ) end end if opt =~ /--disablerepo=(.+)/ $1.split(",").each do |repo| - h["disablerepos"] ||= [] - h["disablerepos"].push(repo) + h["repos"] ||= [] + h["repos"].push( { "disable" => repo } ) end end end diff --git a/lib/chef/provider/package/yum/yum_helper.py b/lib/chef/provider/package/yum/yum_helper.py index 72e1177e8e..090b101316 100644 --- a/lib/chef/provider/package/yum/yum_helper.py +++ b/lib/chef/provider/package/yum/yum_helper.py @@ -83,11 +83,13 @@ def query(command): enabled_repos = base.repos.listEnabled() # Handle any repocontrols passed in with our options - if 'enablerepos' in command: - base.repos.enableRepo(*command['enablerepos']) - if 'disablerepos' in command: - base.repos.disableRepo(*command['disablerepos']) + if 'repos' in command: + for repo in command['repos']: + if 'enable' in repo: + base.repos.enableRepo(repo['enable']) + if 'disable' in repo: + base.repos.disableRepo(repo['disable']) args = { 'name': command['provides'] } do_nevra = False @@ -148,15 +150,14 @@ def query(command): outpipe.flush() # Reset any repos we were passed in enablerepo/disablerepo to the original state in enabled_repos - if 'enablerepos' in command: - for repo in command['enablerepos']: - if base.repos.getRepo(repo) not in enabled_repos: - base.repos.disableRepo(repo) - - if 'disablerepos' in command: - for repo in command['disablerepos']: - if base.repos.getRepo(repo) in enabled_repos: - base.repos.enableRepo(repo) + if 'repos' in command: + for repo in command['repos']: + if 'enable' in repo: + if base.repos.getRepo(repo['enable']) not in enabled_repos: + base.repos.disableRepo(repo['enable']) + if 'disable' in repo: + if base.repos.getRepo(repo['disable']) in enabled_repos: + base.repos.enableRepo(repo['disable']) # 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 diff --git a/spec/functional/resource/yum_package_spec.rb b/spec/functional/resource/yum_package_spec.rb index b06bbe686a..7c45a64ae5 100644 --- a/spec/functional/resource/yum_package_spec.rb +++ b/spec/functional/resource/yum_package_spec.rb @@ -590,6 +590,14 @@ gpgcheck=0 expect { yum_package.run_action(:install) }.to raise_error(Chef::Exceptions::Package, /No candidate version available/) end + it "should work with disablerepo first" do + flush_cache + yum_package.options(["--disablerepo=*", "--enablerepo=chef-yum-localtesting"]) + yum_package.run_action(:install) + expect(yum_package.updated_by_last_action?).to be true + expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.10-1.#{pkg_arch}$") + end + it "should work to enable a disabled repo", not_rhel5: true do shell_out!("yum-config-manager --disable chef-yum-localtesting") flush_cache |