diff --git a/lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb b/lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb index 7740f4a2..fa337389 100644 --- a/lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb +++ b/lib/puppet/provider/dsc_base_provider/dsc_base_provider.rb @@ -15,6 +15,7 @@ def initialize @cached_query_results = [] @cached_test_results = [] @logon_failures = [] + @timeout = nil # default timeout, ps_manager.execute is expecting nil by default.. super end @@ -251,13 +252,17 @@ def invoke_dsc_resource(context, name_hash, props, method) context.err('Logon credentials are invalid') return nil end + specify_dsc_timeout(name_hash) resource = invocable_resource(props, context, method) script_content = ps_script_content(resource) + context.debug("Invoke-DSC Timeout: #{@timeout} milliseconds") if @timeout context.debug("Script:\n #{redact_secrets(script_content)}") - output = ps_manager.execute(remove_secret_identifiers(script_content))[:stdout] + output = ps_manager.execute(remove_secret_identifiers(script_content), @timeout)[:stdout] if output.nil? - context.err('Nothing returned') + message = 'Nothing returned.' + message += " There is a timeout of #{@timeout} milliseconds set, ensure the DSC resource has enough time to apply." unless @timeout.nil? + context.err(message) return nil end @@ -295,6 +300,18 @@ def invoke_dsc_resource(context, name_hash, props, method) data end + # Sets the @timeout instance variable. + # @param name_hash [Hash] the hash of namevars to be passed as properties to `Invoke-DscResource` + # The @timeout variable is set to the value of name_hash[:dsc_timeout] in milliseconds + # If name_hash[:dsc_timeout] is nil, @timeout is not changed. + # If @timeout is already set to a value other than nil, + # it is changed only if it's different from name_hash[:dsc_timeout].. + def specify_dsc_timeout(name_hash) + return unless name_hash[:dsc_timeout] && (@timeout.nil? || @timeout != name_hash[:dsc_timeout]) + + @timeout = name_hash[:dsc_timeout] * 1000 + end + # Retries Invoke-DscResource when returned error matches error regex supplied as param. # @param context [Object] the Puppet runtime context to operate in and send feedback to # @param max_retry_count [Int] max number of times to retry Invoke-DscResource