summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2018-11-19 16:29:26 -0800
committerGitHub <noreply@github.com>2018-11-19 16:29:26 -0800
commitab8b2f8661ace775449d47b05745195e83b35bc4 (patch)
treee6d054cca8e109d6a03d7c80cebe7afd5324988d
parent076c7dd49d864d9dbc9613123dc0b9a2f15ffd58 (diff)
parent155c41c133b94a2157d92bc1c40edf70242b4bd0 (diff)
downloadchef-ab8b2f8661ace775449d47b05745195e83b35bc4.tar.gz
Merge pull request #7953 from chef/lcg/chef-15-allow-downgrade
Chef-15: switch default of allow_downgrade to true
-rw-r--r--RELEASE_NOTES.md21
-rw-r--r--lib/chef/provider/package/yum.rb2
-rw-r--r--lib/chef/provider/package/yum/version.rb4
-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/functional/resource/yum_package_spec.rb3
-rw-r--r--spec/unit/provider/package/rpm_spec.rb25
-rw-r--r--spec/unit/provider/package/zypper_spec.rb36
10 files changed, 71 insertions, 31 deletions
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index a83367df59..1db0112b57 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -6,6 +6,27 @@ Chef 15 release notes will be added here as development progresses.
## Breaking Changes
+### Package provider allow_downgrade is now true by default
+
+A package provider without any `allow_downgrade` flag now will allow downgrades, which is opposite from previous versions. This behavior change will mostly affect users of the rpm and zypper package providers.
+
+```
+package "foo" do
+ version "1.2.3"
+end
+```
+
+That code should now be read as asserting that the package `foo` must be version `1.2.3` after that resource is run.
+
+```
+package "foo" do
+ allow_downgrade false
+ version "1.2.3"
+end
+```
+
+That code is now what is necessary to specify that `foo` must be version `1.2.3` or higher. Note that the yum provider supports syntax like `package "foo > 1.2.3"` which should be used and is preferred over using allow_downgrade.
+
### Node Attributes deep merge nil values
Writing a nil to a precedence level in the node object now acts like any other value and can be used to override values back to nil.
diff --git a/lib/chef/provider/package/yum.rb b/lib/chef/provider/package/yum.rb
index e991e4541e..ad045c77e6 100644
--- a/lib/chef/provider/package/yum.rb
+++ b/lib/chef/provider/package/yum.rb
@@ -96,7 +96,7 @@ class Chef
name = av.name # resolve the name via the available/candidate version
- iv = python_helper.package_query(:whatinstalled, name)
+ iv = python_helper.package_query(:whatinstalled, av.name_with_arch)
method = "install"
diff --git a/lib/chef/provider/package/yum/version.rb b/lib/chef/provider/package/yum/version.rb
index b19f52fe09..6ff59009f9 100644
--- a/lib/chef/provider/package/yum/version.rb
+++ b/lib/chef/provider/package/yum/version.rb
@@ -40,6 +40,10 @@ class Chef
"#{version}.#{arch}" unless version.nil?
end
+ def name_with_arch
+ "#{name}.#{arch}" unless name.nil?
+ end
+
def matches_name_and_arch?(other)
other.version == version && other.arch == arch
end
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/functional/resource/yum_package_spec.rb b/spec/functional/resource/yum_package_spec.rb
index cde193db70..f99f03bdf1 100644
--- a/spec/functional/resource/yum_package_spec.rb
+++ b/spec/functional/resource/yum_package_spec.rb
@@ -443,8 +443,9 @@ describe Chef::Resource::YumPackage, :requires_root, external: exclude_test do
expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^chef_rpm-1.2-1.#{pkg_arch}$")
end
- it "downgrade on a local file is ignored" do
+ it "downgrade on a local file is ignored when allow_downgrade is false" do
preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ yum_package.allow_downgrade false
yum_package.version "1.2-1"
yum_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/chef_rpm-1.2-1.#{pkg_arch}.rpm")
yum_package.run_action(:install)
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