- From: Steven Danna <
>
- To:
- Subject: [chef] Re: Does remote_file not support lazy attributes?
- Date: Thu, 27 Mar 2014 21:48:39 -0700
Hi,
Unfortunately, this looks like a bug. When the lazy method is called,
it creates a Chef::DelayedEvaluator object. This
Chef::DelayedEvaluator is what gets passed to the source attribute's
setter method in the resource. Most resource attribute setter methods
use the helper function set_or_return(). When Chef::DelayedEvaluator
was introduced, set_or_return was patched to ignore validatons if it
got a DelayedEvaluator. The tradeoff for the power of lazy evaluation
is no "compile phase" type checking of arguments.
remote_file's source resource, however, uses a custom method for validation:
def validate_source(source)
raise ArgumentError, "#{resource_name} has an empty source" if
source.empty?
source.each do |src|
unless absolute_uri?(src)
raise Exceptions::InvalidRemoteFileURI,
"#{src.inspect} is not a valid `source` parameter for
#{resource_name}. `source` must be an absolute URI or an array of
URIs."
end
end
end
This function and others like it need to be patched to accept
DelayedEvaluators. I shall make with the typing into JIRA.
Sincerely,
Steven
On Tue, Mar 25, 2014 at 4:58 AM, Jeppe Nejsum Madsen
<
>
wrote:
>
I get the following when trying to use a lazy attribute:
>
>
>
This is the chef-shell.
>
Chef Version: 11.10.4
>
>
chef:recipe > remote_file "/tmp/g2" do
>
chef:recipe > source lazy {"http://www.google.com"}
>
chef:recipe ?> end
>
Chef::Exceptions::InvalidRemoteFileURI:
>
#<Chef::DelayedEvaluator:0x007fd464c092a8@(irb#1):7> is not a valid `source`
>
parameter for remote_file. `source` must be an absolute URI or an array of
>
URIs.
>
>
Any hints?
>
>
/Jeppe
>
Archive powered by MHonArc 2.6.16.