summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLance Albertson <lance@osuosl.org>2023-04-18 12:21:47 -0700
committerGitHub <noreply@github.com>2023-04-18 15:21:47 -0400
commit6fdfe6ba975bd03da6b03225d7fe19f10b0f7306 (patch)
tree581cab969a90b4bf572bf68d65dcc26ff1b5e3cb
parent09403f49de67b31fb1d6a8fbd4767dd0b22b9dee (diff)
downloadchef-6fdfe6ba975bd03da6b03225d7fe19f10b0f7306.tar.gz
zypper_package: Fix idempotency issue (#13691)
Installing the apache2-mod_wsgi-python3 package is not idempotent due to the fact that zypper will also return the apache2-mod_wsgi package. The resolve_available_version method, incorrectly assumes this will only return one item, but in this case it returns four items and will pick the first package listed. To work around this, we should verify that the package name listed in the output matches what we are expecting to install. Signed-off-by: Lance Albertson <lance@osuosl.org>
-rw-r--r--lib/chef/provider/package/zypper.rb1
-rw-r--r--spec/unit/provider/package/zypper_spec.rb10
2 files changed, 11 insertions, 0 deletions
diff --git a/lib/chef/provider/package/zypper.rb b/lib/chef/provider/package/zypper.rb
index 9cd95aade7..80d6f6daeb 100644
--- a/lib/chef/provider/package/zypper.rb
+++ b/lib/chef/provider/package/zypper.rb
@@ -141,6 +141,7 @@ class Chef
if md = line.match(/^(\S*)\s+\|\s+(\S+)\s+\|\s+(\S+)\s+\|\s+(\S+)\s+\|\s+(\S+)\s+\|\s+(.*)$/)
(status, name, type, version, arch, repo) = [ md[1], md[2], md[3], md[4], md[5], md[6] ]
next if version == "Version" # header
+ next if name != package_name
# sometimes even though we request a specific version in the search string above and have match exact, we wind up
# with other versions in the output, particularly getting the installed version when downgrading.
diff --git a/spec/unit/provider/package/zypper_spec.rb b/spec/unit/provider/package/zypper_spec.rb
index 2850a70560..c26443a148 100644
--- a/spec/unit/provider/package/zypper_spec.rb
+++ b/spec/unit/provider/package/zypper_spec.rb
@@ -491,4 +491,14 @@ describe Chef::Provider::Package::Zypper do
provider.remove_package(%w{emacs vim}, ["1.0", "2.0"])
end
end
+
+ describe "resolve_available_version" do
+ it "should return correct version if multiple packages are shown" do
+ status = double(stdout: "S | Name | Type | Version | Arch | Repository\n---+--------------------------+---------+---------------------+--------+-------------------------------------------------------------\n | apache2-mod_wsgi | package | 4.7.1-150400.3.3.1 | x86_64 | Update repository with updates from SUSE Linux Enterprise 15\n | apache2-mod_wsgi | package | 4.7.1-150400.1.52 | x86_64 | Main Repository\ni+ | apache2-mod_wsgi-python3 | package | 4.5.18-150000.4.6.1 | x86_64 | Update repository with updates from SUSE Linux Enterprise 15\nv | apache2-mod_wsgi-python3 | package | 4.5.18-4.3.1 | x86_64 | Main Repository\n", exitstatus: 0)
+
+ allow(provider).to receive(:shell_out_compacted!).and_return(status)
+ result = provider.send(:resolve_available_version, "apache2-mod_wsgi-python3", nil)
+ expect(result).to eq("4.5.18-150000.4.6.1")
+ end
+ end
end