summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2018-03-15 00:33:22 +0000
committerLamont Granquist <lamont@scriptkiddie.org>2018-03-15 18:03:30 -0700
commite48bda8af9be0d52333aa3d4a16339051bff937b (patch)
tree5d4559d744c281f4cbbbb1ca4fde0a1a60346084
parenta1d6e9863914dd4d93ae3a319aa86a24e6edbcb8 (diff)
downloadchef-e48bda8af9be0d52333aa3d4a16339051bff937b.tar.gz
add a few lock/unlock tests and fix a bug
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/provider/package/yum.rb2
-rw-r--r--spec/functional/resource/yum_package_spec.rb48
2 files changed, 49 insertions, 1 deletions
diff --git a/lib/chef/provider/package/yum.rb b/lib/chef/provider/package/yum.rb
index 7d23c25372..9e67c165db 100644
--- a/lib/chef/provider/package/yum.rb
+++ b/lib/chef/provider/package/yum.rb
@@ -159,7 +159,7 @@ class Chef
names.each_with_index.map do |name, i|
if !name.nil?
if installed_version(i).version.nil?
- candidate_version(i).name
+ available_version(i).name
else
installed_version(i).name
end
diff --git a/spec/functional/resource/yum_package_spec.rb b/spec/functional/resource/yum_package_spec.rb
index 732cffb1ad..f7cf54e020 100644
--- a/spec/functional/resource/yum_package_spec.rb
+++ b/spec/functional/resource/yum_package_spec.rb
@@ -24,6 +24,10 @@ exclude_test = !(%w{rhel fedora}.include?(ohai[:platform_family]) && !File.exist
describe Chef::Resource::YumPackage, :requires_root, :external => exclude_test do
include Chef::Mixin::ShellOut
+ # NOTE: every single test here either needs to explicitly call flush_cache or needs to explicitly
+ # call preinstall (which explicitly calls flush_cache). It is your responsibility to do one or the
+ # other in order to minimize calling flush_cache a half dozen times per test.
+
def flush_cache
Chef::Resource::YumPackage.new("shouldnt-matter", run_context).run_action(:flush_cache)
end
@@ -881,4 +885,48 @@ gpgcheck=0
end
end
end
+
+ describe ":lock and :unlock" do
+ before(:all) do
+ shell_out!("yum -y install yum-versionlock")
+ end
+
+ before(:each) do
+ shell_out("yum versionlock delete '*'") # will exit with error when nothing is locked, we don't care
+ end
+
+ it "locks an rpm" do
+ flush_cache
+ yum_package.package_name("chef_rpm")
+ yum_package.run_action(:lock)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("yum versionlock list").stdout.chomp).to match("^0:chef_rpm-")
+ end
+
+ it "does not lock if its already locked" do
+ flush_cache
+ shell_out!("yum versionlock add chef_rpm")
+ yum_package.package_name("chef_rpm")
+ yum_package.run_action(:lock)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("yum versionlock list").stdout.chomp).to match("^0:chef_rpm-")
+ end
+
+ it "unlocks an rpm" do
+ flush_cache
+ shell_out!("yum versionlock add chef_rpm")
+ yum_package.package_name("chef_rpm")
+ yum_package.run_action(:unlock)
+ expect(yum_package.updated_by_last_action?).to be true
+ expect(shell_out("yum versionlock list").stdout.chomp).not_to match("^0:chef_rpm-")
+ end
+
+ it "does not unlock an already locked rpm" do
+ flush_cache
+ yum_package.package_name("chef_rpm")
+ yum_package.run_action(:unlock)
+ expect(yum_package.updated_by_last_action?).to be false
+ expect(shell_out("yum versionlock list").stdout.chomp).not_to match("^0:chef_rpm-")
+ end
+ end
end