summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarc@opscode.com <marc@opscode.com>2012-08-07 11:16:17 -0400
committermarc@opscode.com <marc@opscode.com>2012-08-07 11:16:17 -0400
commite0afae05288e0346dd4a9e308926dac01924d800 (patch)
tree2e863542c636991c221fea3ef16841e1687a6a25
parentbba435487f46d7fea29eb0736a00e1a2f05645bc (diff)
downloadchef-e0afae05288e0346dd4a9e308926dac01924d800.tar.gz
add better support for whyrun to solaris package provider
-rw-r--r--chef/lib/chef/provider/package/solaris.rb33
-rw-r--r--chef/spec/unit/provider/package/solaris_spec.rb10
2 files changed, 27 insertions, 16 deletions
diff --git a/chef/lib/chef/provider/package/solaris.rb b/chef/lib/chef/provider/package/solaris.rb
index f87c30df1e..f502a0dc96 100644
--- a/chef/lib/chef/provider/package/solaris.rb
+++ b/chef/lib/chef/provider/package/solaris.rb
@@ -31,6 +31,18 @@ class Chef
# super
# @current_resource = Chef::Resource::Package.new(@new_resource.name)
# end
+ def define_resource_requirements
+ super
+ requirements.assert(:install) do |a|
+ a.assertion { @new_resource.source }
+ a.failure_message Chef::Exceptions::Package, "Source for package #{@new_resource.name} required for action install"
+ end
+ requirements.assert(:all_actions) do |a|
+ a.assertion { !@new_resource.source || @package_source_found }
+ a.failure_message Chef::Exceptions::Package, "Package #{@new_resource.name} not found: #{@new_resource.source}"
+ a.whyrun "would assume #{@new_resource.source} would be have previously been made available"
+ end
+ end
def load_current_resource
@current_resource = Chef::Resource::Package.new(@new_resource.name)
@@ -38,21 +50,18 @@ class Chef
@new_resource.version(nil)
if @new_resource.source
- unless ::File.exists?(@new_resource.source)
- raise Chef::Exceptions::Package, "Package #{@new_resource.name} not found: #{@new_resource.source}"
- end
-
- Chef::Log.debug("#{@new_resource} checking pkg status")
- status = popen4("pkginfo -l -d #{@new_resource.source} #{@new_resource.package_name}") do |pid, stdin, stdout, stderr|
- stdout.each do |line|
- case line
- when /VERSION:\s+(.+)/
- @new_resource.version($1)
+ @package_source_found = ::File.exists?(@new_resource.source)
+ if @package_source_found
+ Chef::Log.debug("#{@new_resource} checking pkg status")
+ status = popen4("pkginfo -l -d #{@new_resource.source} #{@new_resource.package_name}") do |pid, stdin, stdout, stderr|
+ stdout.each do |line|
+ case line
+ when /VERSION:\s+(.+)/
+ @new_resource.version($1)
+ end
end
end
end
- elsif Array(@new_resource.action).include?(:install)
- raise Chef::Exceptions::Package, "Source for package #{@new_resource.name} required for action install"
end
Chef::Log.debug("#{@new_resource} checking install state")
diff --git a/chef/spec/unit/provider/package/solaris_spec.rb b/chef/spec/unit/provider/package/solaris_spec.rb
index d74523e907..dd7cea2aaa 100644
--- a/chef/spec/unit/provider/package/solaris_spec.rb
+++ b/chef/spec/unit/provider/package/solaris_spec.rb
@@ -64,7 +64,9 @@ PKGINFO
it "should raise an exception if a source is supplied but not found" do
@provider.stub!(:popen4).and_return(@status)
::File.stub!(:exists?).and_return(false)
- lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package)
+ @provider.define_resource_requirements
+ @provider.load_current_resource
+ lambda { @provider.process_resource_requirements }.should raise_error(Chef::Exceptions::Package)
end
@@ -89,13 +91,13 @@ PKGINFO
end
it "should raise an exception if the source is not set but we are installing" do
- @provider.stub!(:popen4).and_return(@status)
@new_resource = Chef::Resource::Package.new("SUNWbash")
@provider = Chef::Provider::Package::Solaris.new(@new_resource, @run_context)
- lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package)
+ @provider.stub!(:popen4).and_return(@status)
+ lambda { @provider.run_action(:install) }.should raise_error(Chef::Exceptions::Package)
end
- it "should raise an exception if rpm fails to run" do
+ it "should raise an exception if pkginfo fails to run" do
@status = mock("Status", :exitstatus => -1)
@provider.stub!(:popen4).and_return(@status)
lambda { @provider.load_current_resource }.should raise_error(Chef::Exceptions::Package)