diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2018-03-13 11:58:26 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2018-03-15 18:03:29 -0700 |
commit | f90c2bdfbffdca0b1c3f819cc5260ea890e9bb9c (patch) | |
tree | 21dc5588c2bff7096c6cc6383fb53414082c81fe | |
parent | 7b9e43f261bfa3b242431b175fe8bca004352e3f (diff) | |
download | chef-f90c2bdfbffdca0b1c3f819cc5260ea890e9bb9c.tar.gz |
add package locking back in
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r-- | lib/chef/provider/package/yum.rb | 39 | ||||
-rw-r--r-- | lib/chef/provider/package/yum/version.rb | 4 |
2 files changed, 41 insertions, 2 deletions
diff --git a/lib/chef/provider/package/yum.rb b/lib/chef/provider/package/yum.rb index 59f1db172d..037ee28f4c 100644 --- a/lib/chef/provider/package/yum.rb +++ b/lib/chef/provider/package/yum.rb @@ -144,8 +144,47 @@ class Chef flushcache end + # NB: the yum_package provider manages individual single packages, please do not submit issues or PRs to try to add wildcard + # support to lock / unlock. The best solution is to write an execute resource which does a not_if `yum versionlock | grep '^pattern`` kind of approach + def lock_package(names, versions) + yum("-d0 -e0 -y", options, "versionlock add", resolved_package_lock_names(names)) + end + + # NB: the yum_package provider manages individual single packages, please do not submit issues or PRs to try to add wildcard + # support to lock / unlock. The best solution is to write an execute resource which does a only_if `yum versionlock | grep '^pattern`` kind of approach + def unlock_package(names, versions) + yum("-d0 -e0 -y", options, "versionlock delete", resolved_package_lock_names(names)) + end + private + # this will resolve things like `/usr/bin/perl` or virtual packages like `mysql` + def resolved_package_lock_names(names) + names.each_with_index.map do |name, i| + if !name.nil? + if installed_version(i).version.nil? + candidate_version(i).name + else + installed_version(i).name + end + end + end + end + + def locked_packages + @locked_packages ||= + begin + locked = shell_out_with_timeout!("yum versionlock list") + locked.stdout.each_line.map do |line| + line.sub(/-[^-]*-[^-]*$/, "").split(":").last.strip + end + end + end + + def package_locked(name, version) + name.all? { |n| locked_packages.include? n } + end + def version_gt?(v1, v2) return false if v1.nil? || v2.nil? python_helper.compare_versions(v1, v2) == 1 diff --git a/lib/chef/provider/package/yum/version.rb b/lib/chef/provider/package/yum/version.rb index 4c586f9b53..b19f52fe09 100644 --- a/lib/chef/provider/package/yum/version.rb +++ b/lib/chef/provider/package/yum/version.rb @@ -1,5 +1,5 @@ # -# Copyright:: Copyright 2016, Chef Software, Inc. +# Copyright:: Copyright 2016-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,7 +33,7 @@ class Chef end def to_s - "#{name}-#{version}.#{arch}" + "#{name}-#{version}.#{arch}" unless version.nil? end def version_with_arch |