summaryrefslogtreecommitdiff
path: root/lib/chef/provider/dsc_script.rb
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2014-10-08 07:58:00 -0700
committerJay Mundrawala <jdmundrawala@gmail.com>2014-10-08 07:58:00 -0700
commit19adfd52154a227717ecb2823750dae4bc34a57c (patch)
treeba8ed7e5fa39ddbd10972ab7031d543feef6d755 /lib/chef/provider/dsc_script.rb
parent1343bdfff0d54e20b923211f6697d42c484c1627 (diff)
parentb16b6157be731425f922b911d8810e9996c6887a (diff)
downloadchef-19adfd52154a227717ecb2823750dae4bc34a57c.tar.gz
Merge pull request #2103 from opscode/jdmundrawala/issue-2027-master
We now check for powershell/dsc compat in provider.
Diffstat (limited to 'lib/chef/provider/dsc_script.rb')
-rw-r--r--lib/chef/provider/dsc_script.rb34
1 files changed, 31 insertions, 3 deletions
diff --git a/lib/chef/provider/dsc_script.rb b/lib/chef/provider/dsc_script.rb
index c979800cba..b8ca54f1b8 100644
--- a/lib/chef/provider/dsc_script.rb
+++ b/lib/chef/provider/dsc_script.rb
@@ -47,9 +47,11 @@ class Chef
end
def load_current_resource
- @dsc_resources_info = run_configuration(:test)
- @resource_converged = @dsc_resources_info.all? do |resource|
- !resource.changes_state?
+ if supports_dsc?
+ @dsc_resources_info = run_configuration(:test)
+ @resource_converged = @dsc_resources_info.all? do |resource|
+ !resource.changes_state?
+ end
end
end
@@ -57,8 +59,26 @@ class Chef
true
end
+ def define_resource_requirements
+ requirements.assert(:run) do |a|
+ err = [
+ 'Could not find Dsc on the system',
+ powershell_info_str,
+ "Powershell 4.0 or higher was not detected on your system and is required to use the dsc_script resource.",
+ ]
+ a.assertion { supports_dsc? }
+ a.failure_message Chef::Exceptions::NoProviderAvailable, err.join(' ')
+ a.whyrun err + ["Assuming a previous resource installs Powershell 4.0 or higher."]
+ a.block_action!
+ end
+ end
+
protected
+ def supports_dsc?
+ run_context && Chef::Platform.supports_dsc?(node)
+ end
+
def run_configuration(operation)
config_directory = ::Dir.mktmpdir("chef-dsc-script")
configuration_data_path = get_configuration_data_path(config_directory)
@@ -144,6 +164,14 @@ class Chef
end
end
end
+
+ def powershell_info_str
+ if run_context && run_context.node[:languages] && run_context.node[:languages][:powershell]
+ install_info = "Powershell #{run_context.node[:languages][:powershell][:version]} was found on the system."
+ else
+ install_info = 'Powershell was not found.'
+ end
+ end
end
end
end