summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-09-25 10:35:38 -0700
committerGitHub <noreply@github.com>2018-09-25 10:35:38 -0700
commite53ed456e6f7a99ac05c8842481b6e4c681f591b (patch)
treed4ceada6a696f42d07374cd9272e5e4cf5b4a149
parent3e62d56eeff8bdd090222fab5f393df71d6916d0 (diff)
parent5e0fc35704828f2cb0745451e2a45fe2003abddd (diff)
downloadchef-e53ed456e6f7a99ac05c8842481b6e4c681f591b.tar.gz
Merge pull request #7518 from MsysTechnologiesllc/dh/MSYS-870_zypper_global_options
zypper_package: Add new global_options property
-rw-r--r--.travis.yml17
-rw-r--r--kitchen-tests/kitchen.travis.yml3
-rw-r--r--lib/chef/provider/package/zypper.rb20
-rw-r--r--lib/chef/resource/zypper_package.rb5
-rw-r--r--spec/functional/assets/zypprepo/chef_rpm-1.10-1.aarch64.rpmbin0 -> 2096 bytes
-rw-r--r--spec/functional/assets/zypprepo/chef_rpm-1.10-1.i686.rpmbin0 -> 2148 bytes
-rw-r--r--spec/functional/assets/zypprepo/chef_rpm-1.10-1.ppc64.rpmbin0 -> 2118 bytes
-rw-r--r--spec/functional/assets/zypprepo/chef_rpm-1.10-1.ppc64le.rpmbin0 -> 2098 bytes
-rw-r--r--spec/functional/assets/zypprepo/chef_rpm-1.10-1.s390x.rpmbin0 -> 2102 bytes
-rw-r--r--spec/functional/assets/zypprepo/chef_rpm-1.10-1.src.rpmbin0 -> 2132 bytes
-rw-r--r--spec/functional/assets/zypprepo/chef_rpm-1.10-1.x86_64.rpmbin0 -> 2110 bytes
-rw-r--r--spec/functional/assets/zypprepo/chef_rpm-1.2-1.aarch64.rpmbin0 -> 2096 bytes
-rw-r--r--spec/functional/assets/zypprepo/chef_rpm-1.2-1.i686.rpmbin0 -> 2149 bytes
-rw-r--r--spec/functional/assets/zypprepo/chef_rpm-1.2-1.ppc64.rpmbin0 -> 2119 bytes
-rw-r--r--spec/functional/assets/zypprepo/chef_rpm-1.2-1.ppc64le.rpmbin0 -> 2098 bytes
-rw-r--r--spec/functional/assets/zypprepo/chef_rpm-1.2-1.s390x.rpmbin0 -> 2102 bytes
-rw-r--r--spec/functional/assets/zypprepo/chef_rpm-1.2-1.src.rpmbin0 -> 2133 bytes
-rw-r--r--spec/functional/assets/zypprepo/chef_rpm-1.2-1.x86_64.rpmbin0 -> 2113 bytes
-rw-r--r--spec/functional/resource/zypper_package_spec.rb233
-rw-r--r--spec/spec_helper.rb1
-rw-r--r--spec/unit/provider/package/zypper_spec.rb51
21 files changed, 322 insertions, 8 deletions
diff --git a/.travis.yml b/.travis.yml
index d6c6cd0f04..0594a68eab 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -340,6 +340,23 @@ matrix:
env:
- RSPEC_CENTOS=7
- KITCHEN_YAML=kitchen.travis.yml
+ - rvm: 2.4.4
+ services: docker
+ sudo: required
+ gemfile: kitchen-tests/Gemfile
+ before_install:
+ - gem update --system $(grep rubygems omnibus_overrides.rb | cut -d'"' -f2)
+ - gem install bundler -v $(grep :bundler omnibus_overrides.rb | cut -d'"' -f2)
+ before_script:
+ - sudo iptables -L DOCKER || ( echo "DOCKER iptables chain missing" ; sudo iptables -N DOCKER )
+ - cd kitchen-tests
+ script:
+ - bundle exec kitchen test rspec-opensuse-leap
+ after_failure:
+ - cat .kitchen/logs/kitchen.log
+ env:
+ - RSPEC_OPENSUSELEAP=42
+ - KITCHEN_YAML=kitchen.travis.yml
notifications:
on_change: true
diff --git a/kitchen-tests/kitchen.travis.yml b/kitchen-tests/kitchen.travis.yml
index aa15da8795..06b789a3c2 100644
--- a/kitchen-tests/kitchen.travis.yml
+++ b/kitchen-tests/kitchen.travis.yml
@@ -104,6 +104,9 @@ platforms:
driver:
image: dokken/opensuse-leap
pid_one_command: /bin/systemd
+ intermediate_instructions:
+ - RUN /usr/bin/zypper --non-interactive update
+ - RUN /usr/bin/zypper --non-interactive install cron
suites:
- name: end-to-end
diff --git a/lib/chef/provider/package/zypper.rb b/lib/chef/provider/package/zypper.rb
index 058fcf1a6b..2a333c4f5f 100644
--- a/lib/chef/provider/package/zypper.rb
+++ b/lib/chef/provider/package/zypper.rb
@@ -109,7 +109,7 @@ class Chef
end
def install_package(name, version)
- zypper_package("install", *options, "--auto-agree-with-licenses", allow_downgrade, name, version)
+ zypper_package("install", global_options, *options, "--auto-agree-with-licenses", allow_downgrade, name, version)
end
def upgrade_package(name, version)
@@ -118,19 +118,19 @@ class Chef
end
def remove_package(name, version)
- zypper_package("remove", *options, name, version)
+ zypper_package("remove", global_options, *options, name, version)
end
def purge_package(name, version)
- zypper_package("remove", *options, "--clean-deps", name, version)
+ zypper_package("remove", global_options, *options, "--clean-deps", name, version)
end
def lock_package(name, version)
- zypper_package("addlock", *options, name, version)
+ zypper_package("addlock", global_options, *options, name, version)
end
def unlock_package(name, version)
- zypper_package("removelock", *options, name, version)
+ zypper_package("removelock", global_options, *options, name, version)
end
private
@@ -141,12 +141,12 @@ class Chef
end
end
- def zypper_package(command, *options, names, versions)
+ def zypper_package(command, global_options, *options, names, versions)
zipped_names = zip(names, versions)
if zypper_version < 1.0
- shell_out!("zypper", gpg_checks, command, *options, "-y", names)
+ shell_out!("zypper", global_options, gpg_checks, command, *options, "-y", names)
else
- shell_out!("zypper", "--non-interactive", gpg_checks, command, *options, zipped_names)
+ shell_out!("zypper", global_options, "--non-interactive", gpg_checks, command, *options, zipped_names)
end
end
@@ -157,6 +157,10 @@ class Chef
def allow_downgrade
"--oldpackage" if new_resource.allow_downgrade
end
+
+ def global_options
+ new_resource.global_options if new_resource.global_options
+ end
end
end
end
diff --git a/lib/chef/resource/zypper_package.rb b/lib/chef/resource/zypper_package.rb
index 6caa14c1a3..e969049856 100644
--- a/lib/chef/resource/zypper_package.rb
+++ b/lib/chef/resource/zypper_package.rb
@@ -34,6 +34,11 @@ class Chef
property :allow_downgrade, [ TrueClass, FalseClass ],
description: "Allow downgrading a package to satisfy requested version requirements.",
default: false, introduced: "13.6"
+
+ property :global_options, [ String, Array ],
+ description: "One (or more) additional options that are passed to the package resource other than options to the command.",
+ coerce: proc { |x| x.is_a?(String) ? x.shellsplit : x },
+ introduced: "14.5"
end
end
end
diff --git a/spec/functional/assets/zypprepo/chef_rpm-1.10-1.aarch64.rpm b/spec/functional/assets/zypprepo/chef_rpm-1.10-1.aarch64.rpm
new file mode 100644
index 0000000000..808e5c64c9
--- /dev/null
+++ b/spec/functional/assets/zypprepo/chef_rpm-1.10-1.aarch64.rpm
Binary files differ
diff --git a/spec/functional/assets/zypprepo/chef_rpm-1.10-1.i686.rpm b/spec/functional/assets/zypprepo/chef_rpm-1.10-1.i686.rpm
new file mode 100644
index 0000000000..ed7b6ddc8e
--- /dev/null
+++ b/spec/functional/assets/zypprepo/chef_rpm-1.10-1.i686.rpm
Binary files differ
diff --git a/spec/functional/assets/zypprepo/chef_rpm-1.10-1.ppc64.rpm b/spec/functional/assets/zypprepo/chef_rpm-1.10-1.ppc64.rpm
new file mode 100644
index 0000000000..f3683b3c89
--- /dev/null
+++ b/spec/functional/assets/zypprepo/chef_rpm-1.10-1.ppc64.rpm
Binary files differ
diff --git a/spec/functional/assets/zypprepo/chef_rpm-1.10-1.ppc64le.rpm b/spec/functional/assets/zypprepo/chef_rpm-1.10-1.ppc64le.rpm
new file mode 100644
index 0000000000..4f8de433d9
--- /dev/null
+++ b/spec/functional/assets/zypprepo/chef_rpm-1.10-1.ppc64le.rpm
Binary files differ
diff --git a/spec/functional/assets/zypprepo/chef_rpm-1.10-1.s390x.rpm b/spec/functional/assets/zypprepo/chef_rpm-1.10-1.s390x.rpm
new file mode 100644
index 0000000000..98538293ff
--- /dev/null
+++ b/spec/functional/assets/zypprepo/chef_rpm-1.10-1.s390x.rpm
Binary files differ
diff --git a/spec/functional/assets/zypprepo/chef_rpm-1.10-1.src.rpm b/spec/functional/assets/zypprepo/chef_rpm-1.10-1.src.rpm
new file mode 100644
index 0000000000..03a92f1cfc
--- /dev/null
+++ b/spec/functional/assets/zypprepo/chef_rpm-1.10-1.src.rpm
Binary files differ
diff --git a/spec/functional/assets/zypprepo/chef_rpm-1.10-1.x86_64.rpm b/spec/functional/assets/zypprepo/chef_rpm-1.10-1.x86_64.rpm
new file mode 100644
index 0000000000..3533640780
--- /dev/null
+++ b/spec/functional/assets/zypprepo/chef_rpm-1.10-1.x86_64.rpm
Binary files differ
diff --git a/spec/functional/assets/zypprepo/chef_rpm-1.2-1.aarch64.rpm b/spec/functional/assets/zypprepo/chef_rpm-1.2-1.aarch64.rpm
new file mode 100644
index 0000000000..73d59bf3e2
--- /dev/null
+++ b/spec/functional/assets/zypprepo/chef_rpm-1.2-1.aarch64.rpm
Binary files differ
diff --git a/spec/functional/assets/zypprepo/chef_rpm-1.2-1.i686.rpm b/spec/functional/assets/zypprepo/chef_rpm-1.2-1.i686.rpm
new file mode 100644
index 0000000000..6637756abb
--- /dev/null
+++ b/spec/functional/assets/zypprepo/chef_rpm-1.2-1.i686.rpm
Binary files differ
diff --git a/spec/functional/assets/zypprepo/chef_rpm-1.2-1.ppc64.rpm b/spec/functional/assets/zypprepo/chef_rpm-1.2-1.ppc64.rpm
new file mode 100644
index 0000000000..677e43f83b
--- /dev/null
+++ b/spec/functional/assets/zypprepo/chef_rpm-1.2-1.ppc64.rpm
Binary files differ
diff --git a/spec/functional/assets/zypprepo/chef_rpm-1.2-1.ppc64le.rpm b/spec/functional/assets/zypprepo/chef_rpm-1.2-1.ppc64le.rpm
new file mode 100644
index 0000000000..df21a68780
--- /dev/null
+++ b/spec/functional/assets/zypprepo/chef_rpm-1.2-1.ppc64le.rpm
Binary files differ
diff --git a/spec/functional/assets/zypprepo/chef_rpm-1.2-1.s390x.rpm b/spec/functional/assets/zypprepo/chef_rpm-1.2-1.s390x.rpm
new file mode 100644
index 0000000000..02a771c6f5
--- /dev/null
+++ b/spec/functional/assets/zypprepo/chef_rpm-1.2-1.s390x.rpm
Binary files differ
diff --git a/spec/functional/assets/zypprepo/chef_rpm-1.2-1.src.rpm b/spec/functional/assets/zypprepo/chef_rpm-1.2-1.src.rpm
new file mode 100644
index 0000000000..5d4d13e18a
--- /dev/null
+++ b/spec/functional/assets/zypprepo/chef_rpm-1.2-1.src.rpm
Binary files differ
diff --git a/spec/functional/assets/zypprepo/chef_rpm-1.2-1.x86_64.rpm b/spec/functional/assets/zypprepo/chef_rpm-1.2-1.x86_64.rpm
new file mode 100644
index 0000000000..314c52f22e
--- /dev/null
+++ b/spec/functional/assets/zypprepo/chef_rpm-1.2-1.x86_64.rpm
Binary files differ
diff --git a/spec/functional/resource/zypper_package_spec.rb b/spec/functional/resource/zypper_package_spec.rb
new file mode 100644
index 0000000000..c95c3575ca
--- /dev/null
+++ b/spec/functional/resource/zypper_package_spec.rb
@@ -0,0 +1,233 @@
+#
+# Author:: Dheeraj Dubey (<dheeraj.dubey@msystechnologies.com>)
+# Copyright:: Copyright 2016-2018, Chef Software Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require "spec_helper"
+require "functional/resource/base"
+require "chef/mixin/shell_out"
+
+describe Chef::Resource::ZypperPackage, :requires_root, :suse_only do
+ include Chef::Mixin::ShellOut
+
+ # NOTE: every single test here needs to explicitly call preinstall.
+
+ def preinstall(*rpms)
+ rpms.each do |rpm|
+ shell_out!("rpm -ivh #{CHEF_SPEC_ASSETS}/zypprepo/#{rpm}")
+ end
+ end
+
+ before(:each) do
+ File.open("/etc/zypp/repos.d/chef-zypp-localtesting.repo", "w+") do |f|
+ f.write <<~EOF
+ [chef-zypp-localtesting]
+ name=Chef zypper spec testing repo
+ baseurl=file://#{CHEF_SPEC_ASSETS}/zypprepo
+ enable=1
+ gpgcheck=0
+ EOF
+ end
+ shell_out!("rpm -qa --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm | xargs -r rpm -e")
+ # next line is useful cleanup if you happen to have been testing zypper func tests on the same box and
+ # have some zypper garbage left around
+ # FileUtils.rm_f "/etc/zypp/repos.d/chef-zypp-localtesting.repo"
+ end
+
+ after(:all) do
+ shell_out!("rpm -qa --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm | xargs -r rpm -e")
+ FileUtils.rm_f "/etc/zypp/repos.d/chef-zypp-localtesting.repo"
+ end
+
+ let(:package_name) { "chef_rpm" }
+ let(:zypper_package) do
+ r = Chef::Resource::ZypperPackage.new(package_name, run_context)
+ r.global_options("--no-gpg-checks")
+ r
+ end
+
+ def pkg_arch
+ ohai[:kernel][:machine]
+ end
+
+ context "installing a package" do
+ after { remove_package }
+ it "installs the latest version" do
+ zypper_package.run_action(:install)
+ expect(zypper_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 "does not install if the package is installed" do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ zypper_package.run_action(:install)
+ expect(zypper_package.updated_by_last_action?).to be false
+ 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 "does not install twice" do
+ zypper_package.run_action(:install)
+ expect(zypper_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}$")
+ zypper_package.run_action(:install)
+ expect(zypper_package.updated_by_last_action?).to be false
+ 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 "does not install if the prior version package is installed" do
+ preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ zypper_package.run_action(:install)
+ expect(zypper_package.updated_by_last_action?).to be false
+ 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
+ end
+
+ context "with versions" do
+ it "works with a version" do
+ zypper_package.package_name("chef_rpm")
+ zypper_package.version("1.10")
+ zypper_package.run_action(:install)
+ expect(zypper_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 "works with an older version" do
+ zypper_package.package_name("chef_rpm")
+ zypper_package.version("1.2")
+ zypper_package.run_action(:install)
+ expect(zypper_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.2-1.#{pkg_arch}$")
+ end
+
+ it "works with version and release" do
+ zypper_package.package_name("chef_rpm")
+ zypper_package.version("1.2-1")
+ zypper_package.run_action(:install)
+ expect(zypper_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.2-1.#{pkg_arch}$")
+ end
+
+ it "downgrades when the installed version is higher than the package_name version" do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ zypper_package.allow_downgrade true
+ zypper_package.package_name("chef_rpm")
+ zypper_package.version("1.2-1")
+ zypper_package.run_action(:install)
+ expect(zypper_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.2-1.#{pkg_arch}$")
+ end
+ end
+
+ describe ":remove" do
+ context "vanilla use case" do
+ let(:package_name) { "chef_rpm" }
+ it "does nothing if the package is not installed" do
+ zypper_package.run_action(:remove)
+ expect(zypper_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^package chef_rpm is not installed$")
+ end
+
+ it "removes the package if the package is installed" do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ zypper_package.run_action(:remove)
+ expect(zypper_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("^package chef_rpm is not installed$")
+ end
+
+ it "does not remove the package twice" do
+ preinstall("chef_rpm-1.10-1.#{pkg_arch}.rpm")
+ zypper_package.run_action(:remove)
+ expect(zypper_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("^package chef_rpm is not installed$")
+ zypper_package.run_action(:remove)
+ expect(zypper_package.updated_by_last_action?).to be false
+ expect(shell_out("rpm -q --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n' chef_rpm").stdout.chomp).to match("^package chef_rpm is not installed$")
+ end
+
+ it "removes the package if the prior version package is installed" do
+ preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ zypper_package.run_action(:remove)
+ expect(zypper_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("^package chef_rpm is not installed$")
+ end
+ end
+
+ context "with no available version" do
+ it "works when a package is installed" do
+ FileUtils.rm_f "/etc/zypp/repos.d/chef-zypp-localtesting.repo"
+ preinstall("chef_rpm-1.2-1.#{pkg_arch}.rpm")
+ zypper_package.run_action(:remove)
+ expect(zypper_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("^package chef_rpm is not installed$")
+ end
+ end
+ end
+
+ describe ":lock and :unlock" do
+ before(:each) do
+ shell_out("zypper removelock chef_rpm") # will exit with error when nothing is locked, we don't care
+ end
+
+ it "locks an rpm" do
+ zypper_package.package_name("chef_rpm")
+ zypper_package.run_action(:lock)
+ expect(zypper_package.updated_by_last_action?).to be true
+ expect(shell_out("zypper locks | grep chef_rpm").stdout.chomp).to match("chef_rpm")
+ end
+
+ it "does not lock if its already locked" do
+ shell_out!("zypper addlock chef_rpm")
+ zypper_package.package_name("chef_rpm")
+ zypper_package.run_action(:lock)
+ expect(zypper_package.updated_by_last_action?).to be false
+ expect(shell_out("zypper locks | grep chef_rpm").stdout.chomp).to match("chef_rpm")
+ end
+
+ it "unlocks an rpm" do
+ shell_out!("zypper addlock chef_rpm")
+ zypper_package.package_name("chef_rpm")
+ zypper_package.run_action(:unlock)
+ expect(zypper_package.updated_by_last_action?).to be true
+ expect(shell_out("zypper locks | grep chef_rpm").stdout.chomp).not_to match("chef_rpm")
+ end
+
+ it "does not unlock an already locked rpm" do
+ zypper_package.package_name("chef_rpm")
+ zypper_package.run_action(:unlock)
+ expect(zypper_package.updated_by_last_action?).to be false
+ expect(shell_out("zypper locks | grep chef_rpm").stdout.chomp).not_to match("chef_rpm")
+ end
+
+ it "check that we can lock based on provides" do
+ zypper_package.package_name("chef_rpm_provides")
+ zypper_package.run_action(:lock)
+ expect(zypper_package.updated_by_last_action?).to be true
+ expect(shell_out("zypper locks | grep chef_rpm_provides").stdout.chomp).to match("chef_rpm_provides")
+ end
+
+ it "check that we can unlock based on provides" do
+ shell_out!("zypper addlock chef_rpm_provides")
+ zypper_package.package_name("chef_rpm_provides")
+ zypper_package.run_action(:unlock)
+ expect(zypper_package.updated_by_last_action?).to be true
+ expect(shell_out("zypper locks | grep chef_rpm_provides").stdout.chomp).not_to match("chef_rpm_provides")
+ end
+ end
+ def remove_package
+ pkg_to_remove = Chef::Resource::ZypperPackage.new(package_name, run_context)
+ pkg_to_remove.run_action(:remove)
+ end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index e77f5dc8d6..e87308e9ed 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -171,6 +171,7 @@ RSpec.configure do |config|
config.filter_run_excluding unix_only: true unless unix?
config.filter_run_excluding linux_only: true unless linux?
config.filter_run_excluding aix_only: true unless aix?
+ config.filter_run_excluding suse_only: true unless suse?
config.filter_run_excluding debian_family_only: true unless debian_family?
config.filter_run_excluding supports_cloexec: true unless supports_cloexec?
config.filter_run_excluding selinux_only: true unless selinux_enabled?
diff --git a/spec/unit/provider/package/zypper_spec.rb b/spec/unit/provider/package/zypper_spec.rb
index 6795f9e051..50f2bb0b5f 100644
--- a/spec/unit/provider/package/zypper_spec.rb
+++ b/spec/unit/provider/package/zypper_spec.rb
@@ -163,6 +163,22 @@ describe Chef::Provider::Package::Zypper do
)
provider.install_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"
+ )
+ provider.install_package(["emacs"], ["1.0"])
+ end
+
+ 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"
+ )
+ provider.install_package(["emacs"], ["1.0"])
+ end
end
describe "upgrade_package" do
@@ -193,6 +209,13 @@ describe Chef::Provider::Package::Zypper do
)
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"
+ )
+ provider.upgrade_package(["emacs"], ["1.0"])
+ end
end
describe "remove_package" do
@@ -234,6 +257,13 @@ describe Chef::Provider::Package::Zypper do
)
provider.remove_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", "remove", "emacs=1.0"
+ )
+ provider.remove_package(["emacs"], ["1.0"])
+ end
end
end
@@ -265,6 +295,13 @@ describe Chef::Provider::Package::Zypper do
)
provider.purge_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", "remove", "--clean-deps", "emacs=1.0"
+ )
+ provider.purge_package(["emacs"], ["1.0"])
+ end
end
describe "action_lock" do
@@ -320,6 +357,13 @@ describe Chef::Provider::Package::Zypper do
)
provider.lock_package(["emacs"], [nil])
end
+ it "should add user provided global options" do
+ new_resource.global_options "--user-provided"
+ shell_out_expectation!(
+ "zypper", "--user-provided", "--non-interactive", "addlock", "emacs"
+ )
+ provider.lock_package(["emacs"], [nil])
+ end
end
describe "action_unlock" do
@@ -374,6 +418,13 @@ describe Chef::Provider::Package::Zypper do
)
provider.unlock_package(["emacs"], [nil])
end
+ it "should add user provided global options" do
+ new_resource.global_options "--user-provided"
+ shell_out_expectation!(
+ "zypper", "--user-provided", "--non-interactive", "removelock", "emacs"
+ )
+ provider.unlock_package(["emacs"], [nil])
+ end
end
describe "on an older zypper" do