summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2018-11-19 11:41:01 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2018-11-19 12:30:21 -0800
commit79a2ae80fda0e0656d54d0ff295fb911f89e8e57 (patch)
treea19a72e958491b9f4fd9b76b39b9a5cbdc0cf322
parent7f79a630893ad4aa64cd9507f16ac7008364ea0f (diff)
downloadchef-79a2ae80fda0e0656d54d0ff295fb911f89e8e57.tar.gz
Chef-15: switch default of allow_downgrade to true
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/resource/package.rb2
-rw-r--r--lib/chef/resource/rpm_package.rb2
-rw-r--r--lib/chef/resource/yum_package.rb3
-rw-r--r--lib/chef/resource/zypper_package.rb4
-rw-r--r--spec/unit/provider/package/rpm_spec.rb25
-rw-r--r--spec/unit/provider/package/zypper_spec.rb36
6 files changed, 43 insertions, 29 deletions
diff --git a/lib/chef/resource/package.rb b/lib/chef/resource/package.rb
index 670671e22b..71f030244b 100644
--- a/lib/chef/resource/package.rb
+++ b/lib/chef/resource/package.rb
@@ -1,7 +1,7 @@
#
# Author:: Adam Jacob (<adam@chef.io>)
# Author:: Tyler Cloke (<tyler@chef.io>)
-# Copyright:: Copyright 2008-2017, Chef Software Inc.
+# Copyright:: Copyright 2008-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/lib/chef/resource/rpm_package.rb b/lib/chef/resource/rpm_package.rb
index 4d79ba98d1..cf408cd094 100644
--- a/lib/chef/resource/rpm_package.rb
+++ b/lib/chef/resource/rpm_package.rb
@@ -26,7 +26,7 @@ class Chef
description "Use the rpm_package resource to manage packages for the RPM Package Manager platform."
- property :allow_downgrade, [ true, false ], default: false, desired_state: false
+ property :allow_downgrade, [ true, false ], default: true, desired_state: false
end
end
diff --git a/lib/chef/resource/yum_package.rb b/lib/chef/resource/yum_package.rb
index f0ea7dbf50..602fe489fb 100644
--- a/lib/chef/resource/yum_package.rb
+++ b/lib/chef/resource/yum_package.rb
@@ -69,7 +69,8 @@ class Chef
property :allow_downgrade, [ true, false ],
description: "Downgrade a package to satisfy requested version requirements.",
- default: false
+ default: true,
+ desired_state: false
property :yum_binary, String
end
diff --git a/lib/chef/resource/zypper_package.rb b/lib/chef/resource/zypper_package.rb
index f31dbe2f93..c8d776cebb 100644
--- a/lib/chef/resource/zypper_package.rb
+++ b/lib/chef/resource/zypper_package.rb
@@ -33,7 +33,9 @@ class Chef
property :allow_downgrade, [ TrueClass, FalseClass ],
description: "Allow downgrading a package to satisfy requested version requirements.",
- default: false, introduced: "13.6"
+ default: true,
+ desired_state: false,
+ introduced: "13.6"
property :global_options, [ String, Array ],
description: "One (or more) additional command options that are passed to the command. For example, common zypper directives, such as '--no-recommends'. See the zypper man page at https://en.opensuse.org/SDB:Zypper_manual_(plain) for the full list.",
diff --git a/spec/unit/provider/package/rpm_spec.rb b/spec/unit/provider/package/rpm_spec.rb
index 284e201e92..1c4f9d31ee 100644
--- a/spec/unit/provider/package/rpm_spec.rb
+++ b/spec/unit/provider/package/rpm_spec.rb
@@ -162,17 +162,16 @@ describe Chef::Provider::Package::Rpm do
let(:rpm_q_stdout) { "imagemagick-c++ 0.5.4.7-7.el6_5" }
it "runs rpm -u with the package source to upgrade" do
- expect(provider).to receive(:shell_out_compacted!).with("rpm", "-U", "/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", timeout: 900)
+ expect(provider).to receive(:shell_out_compacted!).with("rpm", "-U", "--oldpackage", "/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", timeout: 900)
provider.action_install
end
end
context "when an older version is desired" do
let(:new_resource) do
- Chef::Resource::RpmPackage.new(package_name).tap do |r|
- r.source(package_source)
- r.allow_downgrade(true)
- end
+ r = Chef::Resource::RpmPackage.new(package_name)
+ r.source(package_source)
+ r
end
let(:rpm_q_stdout) { "imagemagick-c++ 21.4-19.el6_5" }
@@ -182,6 +181,12 @@ describe Chef::Provider::Package::Rpm do
provider.action_install
end
+ it "if downgrades are not allowed it should not downgrade" do
+ new_resource.allow_downgrade(false)
+ expect(provider).not_to receive(:shell_out_compacted!)
+ provider.action_install
+ end
+
end
end
@@ -203,7 +208,7 @@ describe Chef::Provider::Package::Rpm do
let(:rpm_q_stdout) { "imagemagick-c++ 0.5.4.7-7.el6_5" }
it "runs rpm -u with the package source to upgrade" do
- expect(provider).to receive(:shell_out_compacted!).with("rpm", "-U", "/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", timeout: 900)
+ expect(provider).to receive(:shell_out_compacted!).with("rpm", "-U", "--oldpackage", "/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", timeout: 900)
provider.action_upgrade
end
end
@@ -223,6 +228,12 @@ describe Chef::Provider::Package::Rpm do
provider.action_upgrade
end
+ it "should run rpm -u --oldpackage with the package source to downgrade" do
+ new_resource.allow_downgrade(false)
+ expect(provider).not_to receive(:shell_out_compacted!).with("rpm", "-U", any_args)
+ provider.action_upgrade
+ end
+
end
end
@@ -421,7 +432,7 @@ describe Chef::Provider::Package::Rpm do
expect(new_resource.source).to eq("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm")
current_resource.version("21.4-19.el5")
provider.current_resource = current_resource
- expect(provider).to receive(:shell_out_compacted!).with("rpm", "-U", "/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", timeout: 900)
+ expect(provider).to receive(:shell_out_compacted!).with("rpm", "-U", "--oldpackage", "/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", timeout: 900)
provider.upgrade_package("/tmp/ImageMagick-c++-6.5.4.7-7.el6_5.x86_64.rpm", "6.5.4.7-7.el6_5")
end
end
diff --git a/spec/unit/provider/package/zypper_spec.rb b/spec/unit/provider/package/zypper_spec.rb
index 50f2bb0b5f..c17eeba1bb 100644
--- a/spec/unit/provider/package/zypper_spec.rb
+++ b/spec/unit/provider/package/zypper_spec.rb
@@ -120,14 +120,14 @@ describe Chef::Provider::Package::Zypper do
describe "install_package" do
it "should run zypper install with the package name and version" do
shell_out_expectation!(
- "zypper", "--non-interactive", "install", "--auto-agree-with-licenses", "emacs=1.0"
+ "zypper", "--non-interactive", "install", "--auto-agree-with-licenses", "--oldpackage", "emacs=1.0"
)
provider.install_package(["emacs"], ["1.0"])
end
it "should run zypper install with gpg checks" do
shell_out_expectation!(
- "zypper", "--non-interactive", "install", "--auto-agree-with-licenses", "emacs=1.0"
+ "zypper", "--non-interactive", "install", "--auto-agree-with-licenses", "--oldpackage", "emacs=1.0"
)
provider.install_package(["emacs"], ["1.0"])
end
@@ -135,7 +135,7 @@ describe Chef::Provider::Package::Zypper do
it "setting the property should disable gpg checks" do
new_resource.gpg_check false
shell_out_expectation!(
- "zypper", "--non-interactive", "--no-gpg-checks", "install", "--auto-agree-with-licenses", "emacs=1.0"
+ "zypper", "--non-interactive", "--no-gpg-checks", "install", "--auto-agree-with-licenses", "--oldpackage", "emacs=1.0"
)
provider.install_package(["emacs"], ["1.0"])
end
@@ -143,15 +143,15 @@ describe Chef::Provider::Package::Zypper do
it "setting the config variable should disable gpg checks" do
Chef::Config[:zypper_check_gpg] = false
shell_out_expectation!(
- "zypper", "--non-interactive", "--no-gpg-checks", "install", "--auto-agree-with-licenses", "emacs=1.0"
+ "zypper", "--non-interactive", "--no-gpg-checks", "install", "--auto-agree-with-licenses", "--oldpackage", "emacs=1.0"
)
provider.install_package(["emacs"], ["1.0"])
end
- it "setting the property should allow downgrade" do
- new_resource.allow_downgrade true
+ it "setting the property should disallow downgrade" do
+ new_resource.allow_downgrade false
shell_out_expectation!(
- "zypper", "--non-interactive", "install", "--auto-agree-with-licenses", "--oldpackage", "emacs=1.0"
+ "zypper", "--non-interactive", "install", "--auto-agree-with-licenses", "emacs=1.0"
)
provider.install_package(["emacs"], ["1.0"])
end
@@ -159,7 +159,7 @@ describe Chef::Provider::Package::Zypper do
it "should add user provided options to the command" do
new_resource.options "--user-provided"
shell_out_expectation!(
- "zypper", "--non-interactive", "install", "--user-provided", "--auto-agree-with-licenses", "emacs=1.0"
+ "zypper", "--non-interactive", "install", "--user-provided", "--auto-agree-with-licenses", "--oldpackage", "emacs=1.0"
)
provider.install_package(["emacs"], ["1.0"])
end
@@ -167,7 +167,7 @@ describe Chef::Provider::Package::Zypper do
it "should add user provided global options" do
new_resource.global_options "--user-provided"
shell_out_expectation!(
- "zypper", "--user-provided", "--non-interactive", "install", "--auto-agree-with-licenses", "emacs=1.0"
+ "zypper", "--user-provided", "--non-interactive", "install", "--auto-agree-with-licenses", "--oldpackage", "emacs=1.0"
)
provider.install_package(["emacs"], ["1.0"])
end
@@ -175,7 +175,7 @@ describe Chef::Provider::Package::Zypper do
it "should add multiple user provided global options" do
new_resource.global_options "--user-provided1 --user-provided2"
shell_out_expectation!(
- "zypper", "--user-provided1", "--user-provided2", "--non-interactive", "install", "--auto-agree-with-licenses", "emacs=1.0"
+ "zypper", "--user-provided1", "--user-provided2", "--non-interactive", "install", "--auto-agree-with-licenses", "--oldpackage", "emacs=1.0"
)
provider.install_package(["emacs"], ["1.0"])
end
@@ -184,35 +184,35 @@ describe Chef::Provider::Package::Zypper do
describe "upgrade_package" do
it "should run zypper update with the package name and version" do
shell_out_expectation!(
- "zypper", "--non-interactive", "install", "--auto-agree-with-licenses", "emacs=1.0"
+ "zypper", "--non-interactive", "install", "--auto-agree-with-licenses", "--oldpackage", "emacs=1.0"
)
provider.upgrade_package(["emacs"], ["1.0"])
end
it "should run zypper update without gpg checks when setting the property" do
new_resource.gpg_check false
shell_out_expectation!(
- "zypper", "--non-interactive", "--no-gpg-checks", "install", "--auto-agree-with-licenses", "emacs=1.0"
+ "zypper", "--non-interactive", "--no-gpg-checks", "install", "--auto-agree-with-licenses", "--oldpackage", "emacs=1.0"
)
provider.upgrade_package(["emacs"], ["1.0"])
end
it "should run zypper update without gpg checks when setting the config variable" do
Chef::Config[:zypper_check_gpg] = false
shell_out_expectation!(
- "zypper", "--non-interactive", "--no-gpg-checks", "install", "--auto-agree-with-licenses", "emacs=1.0"
+ "zypper", "--non-interactive", "--no-gpg-checks", "install", "--auto-agree-with-licenses", "--oldpackage", "emacs=1.0"
)
provider.upgrade_package(["emacs"], ["1.0"])
end
it "should add user provided options to the command" do
new_resource.options "--user-provided"
shell_out_expectation!(
- "zypper", "--non-interactive", "install", "--user-provided", "--auto-agree-with-licenses", "emacs=1.0"
+ "zypper", "--non-interactive", "install", "--user-provided", "--auto-agree-with-licenses", "--oldpackage", "emacs=1.0"
)
provider.upgrade_package(["emacs"], ["1.0"])
end
it "should add user provided global options" do
new_resource.global_options "--user-provided"
shell_out_expectation!(
- "zypper", "--user-provided", "--non-interactive", "install", "--auto-agree-with-licenses", "emacs=1.0"
+ "zypper", "--user-provided", "--non-interactive", "install", "--auto-agree-with-licenses", "--oldpackage", "emacs=1.0"
)
provider.upgrade_package(["emacs"], ["1.0"])
end
@@ -435,7 +435,7 @@ describe Chef::Provider::Package::Zypper do
describe "install_package" do
it "should run zypper install with the package name and version" do
shell_out_expectation!(
- "zypper", "install", "--auto-agree-with-licenses", "-y", "emacs"
+ "zypper", "install", "--auto-agree-with-licenses", "--oldpackage", "-y", "emacs"
)
provider.install_package(["emacs"], ["1.0"])
end
@@ -444,7 +444,7 @@ describe Chef::Provider::Package::Zypper do
describe "upgrade_package" do
it "should run zypper update with the package name and version" do
shell_out_expectation!(
- "zypper", "install", "--auto-agree-with-licenses", "-y", "emacs"
+ "zypper", "install", "--auto-agree-with-licenses", "--oldpackage", "-y", "emacs"
)
provider.upgrade_package(["emacs"], ["1.0"])
end
@@ -463,7 +463,7 @@ describe Chef::Provider::Package::Zypper do
describe "when installing multiple packages" do # https://github.com/chef/chef/issues/3570
it "should install an array of package names and versions" do
shell_out_expectation!(
- "zypper", "--non-interactive", "install", "--auto-agree-with-licenses", "emacs=1.0", "vim=2.0"
+ "zypper", "--non-interactive", "install", "--auto-agree-with-licenses", "--oldpackage", "emacs=1.0", "vim=2.0"
)
provider.install_package(%w{emacs vim}, ["1.0", "2.0"])
end