diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2018-02-26 14:51:21 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2018-03-15 18:03:29 -0700 |
commit | 1b38da9eba33b0c6e6628022c9343cca5037abd4 (patch) | |
tree | f3c02603a86261b9a8f45ed1ae0e98e8914006b1 | |
parent | c231f3d74fd8ebad0d2759b60fd45f4116a2402c (diff) | |
download | chef-1b38da9eba33b0c6e6628022c9343cca5037abd4.tar.gz |
fix yum_cache arch options and use positional parameters
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r-- | lib/chef/provider/package/yum.rb | 6 | ||||
-rw-r--r-- | lib/chef/provider/package/yum/python_helper.rb | 4 | ||||
-rw-r--r-- | lib/chef/provider/package/yum/yum_cache.rb | 14 | ||||
-rw-r--r-- | spec/unit/provider/package/yum/yum_cache_spec.rb | 40 |
4 files changed, 42 insertions, 22 deletions
diff --git a/lib/chef/provider/package/yum.rb b/lib/chef/provider/package/yum.rb index 26af052074..59f1db172d 100644 --- a/lib/chef/provider/package/yum.rb +++ b/lib/chef/provider/package/yum.rb @@ -187,7 +187,7 @@ class Chef @available_version[index] ||= if new_resource.source resolve_source_to_version_obj else - python_helper.package_query(:whatavailable, package_name_array[index], safe_version_array[index], safe_arch_array[index], options) + python_helper.package_query(:whatavailable, package_name_array[index], version: safe_version_array[index], arch: safe_arch_array[index], options: options) end @available_version[index] @@ -197,9 +197,9 @@ class Chef def installed_version(index) @installed_version ||= [] @installed_version[index] ||= if new_resource.source - python_helper.package_query(:whatinstalled, available_version(index).name, safe_version_array[index], safe_arch_array[index]) + python_helper.package_query(:whatinstalled, available_version(index).name, version: safe_version_array[index], arch: safe_arch_array[index]) else - python_helper.package_query(:whatinstalled, package_name_array[index], safe_version_array[index], safe_arch_array[index]) + python_helper.package_query(:whatinstalled, package_name_array[index], version: safe_version_array[index], arch: safe_arch_array[index]) end @installed_version[index] end diff --git a/lib/chef/provider/package/yum/python_helper.rb b/lib/chef/provider/package/yum/python_helper.rb index cbdd85bbbd..5f00763813 100644 --- a/lib/chef/provider/package/yum/python_helper.rb +++ b/lib/chef/provider/package/yum/python_helper.rb @@ -107,9 +107,9 @@ class Chef end # @returns Array<Version> - def package_query(action, provides, version = nil, arch = nil, options = nil) + def package_query(action, provides, version: nil, arch: nil, options: {}) parameters = { "provides" => provides, "version" => version, "arch" => arch } - repo_opts = options_params(options || {}) + repo_opts = options_params(options) parameters.merge!(repo_opts) query_output = query(action, parameters) version = parse_response(query_output.lines.last) diff --git a/lib/chef/provider/package/yum/yum_cache.rb b/lib/chef/provider/package/yum/yum_cache.rb index 2c29e6ad71..fa0930109f 100644 --- a/lib/chef/provider/package/yum/yum_cache.rb +++ b/lib/chef/provider/package/yum/yum_cache.rb @@ -57,18 +57,18 @@ class Chef python_helper.restart end - def available_version(name) - p = python_helper.package_query(:whatavailable, name) + def available_version(name, arch = nil) + p = python_helper.package_query(:whatavailable, name, arch: arch) "#{p.version}.#{p.arch}" unless p.version.nil? end - def installed_version(name) - p = python_helper.package_query(:whatinstalled, name) + def installed_version(name, arch = nil) + p = python_helper.package_query(:whatinstalled, name, arch: arch) "#{p.version}.#{p.arch}" unless p.version.nil? end - def package_available?(name) - p = python_helper.package_query(:whatavailable, name) + def package_available?(name, arch = nil) + p = python_helper.package_query(:whatavailable, name, arch: arch) !p.version.nil? end @@ -77,7 +77,7 @@ class Chef # (because the bigger issue there is a buggy+broken python_helper -- so don't try to fix those # kinds of bugs here) def version_available?(name, version, arch = nil) - p = python_helper.package_query(:whatavailable, name, version, arch) + p = python_helper.package_query(:whatavailable, name, version: version, arch: arch) !p.version.nil? end diff --git a/spec/unit/provider/package/yum/yum_cache_spec.rb b/spec/unit/provider/package/yum/yum_cache_spec.rb index ba78987de7..6b2a617ac8 100644 --- a/spec/unit/provider/package/yum/yum_cache_spec.rb +++ b/spec/unit/provider/package/yum/yum_cache_spec.rb @@ -31,32 +31,32 @@ describe Chef::Provider::Package::Yum::YumCache do end it "package_available? returns false if the helper reports the available version is nil" do - expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo").and_return( yum_version("foo", nil, nil) ) + expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", arch: nil).and_return( yum_version("foo", nil, nil) ) expect( yum_cache.package_available?("foo") ).to be false end it "package_available? returns true if the helper returns an available version" do - expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo").and_return( yum_version("foo", "1.2.3-1", "x86_64") ) + expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", arch: nil).and_return( yum_version("foo", "1.2.3-1", "x86_64") ) expect( yum_cache.package_available?("foo") ).to be true end it "version_available? returns false if the helper reports the available version is nil" do - expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", "1.2.3", nil).and_return( yum_version("foo", nil, nil) ) + expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", version: "1.2.3", arch: nil).and_return( yum_version("foo", nil, nil) ) expect( yum_cache.version_available?("foo", "1.2.3") ).to be false end it "version_available? returns true if the helper returns an available version" do - expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", "1.2.3", nil).and_return( yum_version("foo", "1.2.3-1", "x86_64") ) + expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", version: "1.2.3", arch: nil).and_return( yum_version("foo", "1.2.3-1", "x86_64") ) expect( yum_cache.version_available?("foo", "1.2.3") ).to be true end it "version_available? with an arch returns false if the helper reports the available version is nil" do - expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", "1.2.3", "x86_64").and_return( yum_version("foo", nil, nil) ) + expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", version: "1.2.3", arch: "x86_64").and_return( yum_version("foo", nil, nil) ) expect( yum_cache.version_available?("foo", "1.2.3", "x86_64") ).to be false end it "version_available? with an arch returns true if the helper returns an available version" do - expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", "1.2.3", "x86_64").and_return( yum_version("foo", "1.2.3-1", "x86_64") ) + expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", version: "1.2.3", arch: "x86_64").and_return( yum_version("foo", "1.2.3-1", "x86_64") ) expect( yum_cache.version_available?("foo", "1.2.3", "x86_64") ).to be true end @@ -68,22 +68,42 @@ describe Chef::Provider::Package::Yum::YumCache do end it "installed_version? returns nil if the helper reports the installed version is nil" do - expect( python_helper ).to receive(:package_query).with(:whatinstalled, "foo").and_return( yum_version("foo", nil, nil) ) + expect( python_helper ).to receive(:package_query).with(:whatinstalled, "foo", arch: nil).and_return( yum_version("foo", nil, nil) ) expect( yum_cache.installed_version("foo") ).to be nil end it "installed_version? returns version string if the helper returns an installed version" do - expect( python_helper ).to receive(:package_query).with(:whatinstalled, "foo").and_return( yum_version("foo", "1.2.3-1", "x86_64") ) + expect( python_helper ).to receive(:package_query).with(:whatinstalled, "foo", arch: nil).and_return( yum_version("foo", "1.2.3-1", "x86_64") ) expect( yum_cache.installed_version("foo") ).to eql("1.2.3-1.x86_64") end + it "installed_version? returns nil if the helper reports the installed version is nil" do + expect( python_helper ).to receive(:package_query).with(:whatinstalled, "foo", arch: "x86_64").and_return( yum_version("foo", nil, nil) ) + expect( yum_cache.installed_version("foo", "x86_64") ).to be nil + end + + it "installed_version? returns version string if the helper returns an installed version" do + expect( python_helper ).to receive(:package_query).with(:whatinstalled, "foo", arch: "x86_64").and_return( yum_version("foo", "1.2.3-1", "x86_64") ) + expect( yum_cache.installed_version("foo", "x86_64") ).to eql("1.2.3-1.x86_64") + end + it "available_version? returns nil if the helper reports the available version is nil" do - expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo").and_return( yum_version("foo", nil, nil) ) + expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", arch: nil).and_return( yum_version("foo", nil, nil) ) expect( yum_cache.available_version("foo") ).to be nil end it "available_version? returns version string if the helper returns an available version" do - expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo").and_return( yum_version("foo", "1.2.3-1", "x86_64") ) + expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", arch: nil).and_return( yum_version("foo", "1.2.3-1", "x86_64") ) expect( yum_cache.available_version("foo") ).to eql("1.2.3-1.x86_64") end + + it "available_version? returns nil if the helper reports the available version is nil" do + expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", arch: "x86_64").and_return( yum_version("foo", nil, nil) ) + expect( yum_cache.available_version("foo", "x86_64") ).to be nil + end + + it "available_version? returns version string if the helper returns an available version" do + expect( python_helper ).to receive(:package_query).with(:whatavailable, "foo", arch: "x86_64").and_return( yum_version("foo", "1.2.3-1", "x86_64") ) + expect( yum_cache.available_version("foo", "x86_64") ).to eql("1.2.3-1.x86_64") + end end |