diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-12-15 15:10:00 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-12-15 15:10:00 -0800 |
commit | 7b39f6dbfe18653123dbc9459d145dcf7f752479 (patch) | |
tree | d5eb18c4a528cbf9c7aba1eab248cfd8c917fe15 | |
parent | ee049ed97120993d1ef1ff99e697906e7a541eda (diff) | |
download | chef-7b39f6dbfe18653123dbc9459d145dcf7f752479.tar.gz |
fix FIXME in define_resource_requirements
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r-- | lib/chef/provider/package/dnf.rb | 12 | ||||
-rw-r--r-- | spec/functional/resource/dnf_package_spec.rb | 14 |
2 files changed, 22 insertions, 4 deletions
diff --git a/lib/chef/provider/package/dnf.rb b/lib/chef/provider/package/dnf.rb index c8ab82acdd..f48b1341a6 100644 --- a/lib/chef/provider/package/dnf.rb +++ b/lib/chef/provider/package/dnf.rb @@ -63,10 +63,12 @@ class Chef end def define_resource_requirements - # FIXME: - #unless ::File.exist?(new_resource.source) - # raise Chef::Exceptions::Package, "Package #{new_resource.name} not found: #{new_resource.source}" - #end + requirements.assert(:install, :upgrade, :remove, :purge) do |a| + a.assertion { !new_resource.source || ::File.exist?(new_resource.source) } + a.failure_message Chef::Exceptions::Package, "Package #{new_resource.package_name} not found: #{new_resource.source}" + a.whyrun "assuming #{new_resource.source} would have previously been created" + end + super end @@ -119,6 +121,8 @@ class Chef def resolve_source_to_version_obj shell_out_with_timeout!("rpm -qp --queryformat '%{NAME} %{EPOCH} %{VERSION} %{RELEASE} %{ARCH}\n' #{new_resource.source}").stdout.each_line do |line| + # this is another case of committing the sin of doing some lightweight mangling of RPM versions in ruby -- but the output of the rpm command + # does not match what the dnf library accepts. case line when /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/ return Version.new($1, "#{$2 == "(none)" ? "0" : $2}:#{$3}-#{$4}", $5) diff --git a/spec/functional/resource/dnf_package_spec.rb b/spec/functional/resource/dnf_package_spec.rb index a730a8c4b0..c3e812b2cb 100644 --- a/spec/functional/resource/dnf_package_spec.rb +++ b/spec/functional/resource/dnf_package_spec.rb @@ -320,6 +320,20 @@ gpgcheck=0 end context "with source arguments" do + it "raises an exception when the package does not exist" do + flush_cache + dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/this-file-better-not-exist.rpm") + expect { dnf_package.run_action(:install) }.to raise_error(Chef::Exceptions::Package, /No candidate version available/) + end + + it "does not raise a hard exception in why-run mode when the package does not exist" do + Chef::Config[:why_run] = true + flush_cache + dnf_package.package_name("#{CHEF_SPEC_ASSETS}/yumrepo/this-file-better-not-exist.rpm") + dnf_package.run_action(:install) + expect { dnf_package.run_action(:install) }.not_to raise_error + end + it "installs the package when using the source argument" do flush_cache dnf_package.name "something" |