On Sunday, July 16, 2017 at 6:04:04 AM UTC-7, bert hajee wrote:
>
> Trevor, Reid,
>
> Thanks for taking the time to look at this. 
>
> Exists should be checking the @property_hash object which is populated by 
>> the instances method.
>> Something like:
>> def exists?
>>   @property_hash[:ensure] == :present
>> end
>
>
>
> The real type does implement the exists? method by looking at the property 
> hash. But when using the transition type, the property hash is not yet 
> filled correctly, because the instances and prefetched methods are not 
> (yet) called.
>
>
> On Friday, 14 July 2017 22:57:54 UTC+2, Reid Vandewiele wrote:
>>
>> I haven't dived into the code recently but depending on when prefetching 
>> happens, it might be possible the Transition type is causing an "early" 
>> invocation of #exists?. This is because Transition invokes a check of the 
>> resource it is "prior to", thusly: 
>> https://github.com/puppetlabs/puppetlabs-transition/blob/0.1.1/lib/puppet/provider/transition/ruby.rb#L68
>>
>> If it's the case that prefetch isn't called until the first instance of a 
>> given type is evaluated, that might be something that's happening *after* 
>> the Transition resource does its thing. Which could help explain why your 
>> exists?() method, which uses prefetched data, isn't working.
>>
>>  
>  This seems to b what is happening.
>  
> But what is the best way forward to solve this?
>

This could be seen as a problem with Transition, which would be best to see 
fixed in the Transition module. The basic idea would be to make sure a 
provider has done any prefetching it needs to before calling safe_insync?() 
on a resource. That module is effectively opensource though so it depends 
on someone being aware of the problem and having spare time to fix it.

Since that may not happen quickly, a workaround might be to ensure that at 
least one instance of the type in question is evaluated prior to the 
transition resource being evaluated. E.g.

file { 'prefetch':
  path   => '/dev/null',
  ensure => present,
}

transition { 'transition a file resource':
  require    => File['prefetch'],
  resource   => File['/path/to/real/file'],
  attributes => { ensure => absent },
  prior_to   => Service['example'],
}


This is just a mock example. The only thing it's really showing is that a 
file "resource" called prefetch exists, doesn't really do anything, but is 
guaranteed to be evaluated before a transition involving a different, real 
file.

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-dev/4e6e2c67-dd82-4f6b-9d34-e5e8775df04a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to