On May 4, 2012, at 11:08 AM, Philip Brown wrote: > I've looked through a few "ensure" providing .rb files, and would like to > verify something. > > None of the ones I've looked at, seem to explicitly return any kind of value > for "Hey, I updated something". > Nor do even may other kinds of utils that I look at. For example: > > def mode=(value) > begin > File.chmod(value.to_i(8), resource[:path]) > .. (and nothing else normal here) > end > > In OTHER code, however I see syntax such as > return "Some user visible string here" > > So, given the lack of documentation, I just wanted confirm that the "Right > way" to log a change, is that style. > eg: > > def exists? > if ! is_it_there? > return "Hey I made it for you" > end > end > > I dont see how to send some kind of message to the logs, "hey, something > changed, but I'm fixing it".
In all cases I can think of, Puppet will do the appropriate logging, so you only need to worry about extra information like debugging. E.g., if you are using 'ensure' present, then when the transaction successfully calls 'ensure' on the provider, it will create an Event that has the property set to 'ensure', the previous_value set to 'absent', and the current_value set to 'present' (or something like that). Then this Event calls the 'notice' log method with the appropriate log message. So, your provider should focus 100% on function, and throwing errors where it can't do what it is supposed to, and the transaction should handle all logging and error management. In case it's not clear, you should very rarely have a conditional like you do with the 'exists?' method above - return true if it's there, false if it's not, but don't return a string. The system will treat the string as true, but that's probably not what you want. Please let me know if that isn't clear. -- Luke Kanies | http://about.me/lak | http://puppetlabs.com/ | +1-615-594-8199 -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
