Micah Anderson
2013-Feb-22 02:20 UTC
[Puppet Users] using exit code from a command in a provider without causing puppet to fail
Hi, I''ve made some changes to the vcsrepo module[0] provider. It all works fine, but I''m trying to improve it to be more in-line with how the original module works. The original module uses ''optional_commands''[1] to define the ''git'' command and then when the provider needs to do something with git it uses a define called ''git_with_identity''[2] which makes sure that certain variables are set and then just runs git using the optional_commands methods. I want to do the same thing, but I want to operate on the exit code of the git command that I am running. So while the following works fine: def valid_repo? Dir.chdir(@resource.value(:path)){ system(''git rev-parse > /dev/null 2>&1'')} end it is using system() to call ''git rev-parse'' instead of ''git_with_identity''. If I simply change my ''system'' above to ''git_with_identity'', when ''git revparse'' fails with a non-zero exit code, it causes puppet to fail. It seems like optional_commands eventually uses Puppet::Util::Execution[4] and that has the optional parameter ''failonfail'', defaulting to ''true''. I am guessing that what I want to do is somehow toggle that so it wont fail, but I''m at a loss as to how. Any ideas or pointers to other providers that are doing this would be mighty appreciated! micah 0. https://github.com/puppetlabs/puppetlabs-vcsrepo 1. https://github.com/puppetlabs/puppetlabs-vcsrepo/blob/master/lib/puppet/provider/vcsrepo/git.rb#L7 2. https://github.com/puppetlabs/puppetlabs-vcsrepo/blob/master/lib/puppet/provider/vcsrepo/git.rb#L278 3. if you follow the indirection through this path: https://github.com/puppetlabs/puppet/blob/master/lib/puppet/provider.rb#L186-L201 https://github.com/puppetlabs/puppet/blob/master/lib/puppet/provider.rb#L221-L238 https://github.com/puppetlabs/puppet/blob/master/lib/puppet/provider.rb#L272 https://github.com/puppetlabs/puppet/blob/master/lib/puppet/util/execution.rb -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Felix Frank
2013-Feb-22 16:51 UTC
Re: [Puppet Users] using exit code from a command in a provider without causing puppet to fail
Hi, it might be sensible to ask that to puppet-dev. Anyway, is the call that causing you problems raising an exception? Could you catch/rescue that? Just an idle idea... Cheers, Felix On 02/22/2013 03:20 AM, Micah Anderson wrote:> > Hi, > > I''ve made some changes to the vcsrepo module[0] provider. It all works > fine, but I''m trying to improve it to be more in-line with how the > original module works. The original module uses ''optional_commands''[1] > to define the ''git'' command and then when the provider needs to do > something with git it uses a define called ''git_with_identity''[2] which > makes sure that certain variables are set and then just runs git using > the optional_commands methods. > > I want to do the same thing, but I want to operate on the exit code of > the git command that I am running. So while the following works fine: > > def valid_repo? > Dir.chdir(@resource.value(:path)){ system(''git rev-parse > /dev/null 2>&1'')} > end > > it is using system() to call ''git rev-parse'' instead of > ''git_with_identity''. > > If I simply change my ''system'' above to ''git_with_identity'', when ''git > revparse'' fails with a non-zero exit code, it causes puppet to fail. > > It seems like optional_commands eventually uses > Puppet::Util::Execution[4] and that has the optional parameter > ''failonfail'', defaulting to ''true''. I am guessing that what I want to do > is somehow toggle that so it wont fail, but I''m at a loss as to how. > > Any ideas or pointers to other providers that are doing this would be > mighty appreciated! > > micah > > > 0. https://github.com/puppetlabs/puppetlabs-vcsrepo > 1. https://github.com/puppetlabs/puppetlabs-vcsrepo/blob/master/lib/puppet/provider/vcsrepo/git.rb#L7 > 2. https://github.com/puppetlabs/puppetlabs-vcsrepo/blob/master/lib/puppet/provider/vcsrepo/git.rb#L278 > 3. if you follow the indirection through this path: > https://github.com/puppetlabs/puppet/blob/master/lib/puppet/provider.rb#L186-L201 > https://github.com/puppetlabs/puppet/blob/master/lib/puppet/provider.rb#L221-L238 > https://github.com/puppetlabs/puppet/blob/master/lib/puppet/provider.rb#L272 > https://github.com/puppetlabs/puppet/blob/master/lib/puppet/util/execution.rb > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.