Julian Simpson
2007-Feb-12 22:09 UTC
How to validate puppet manifests without actually executing puppet?
Hi, I want to validate my puppet manifests before I check them into source control. I just want to make sure that the manifest syntaxes are legal, not to do any more complex testing - the checkin may be on my laptop and not on the system that the manifests may be intended to run on. Ideally I''d be able to do this from ruby code - and I did try to instantiate some classes and override the location for the manifests: hash = Hash[:Manifest => "/home/jsimpson/blah/blah/site.pp" ] interpreter = Puppet::Parser::Interpreter.new(hash) I''m guessing that I actually need to mess with the Puppet::Parser class, but I don''t yet understand that generated code - any hints very welcome! best Julian. _______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
Luke Kanies
2007-Feb-12 22:16 UTC
Re: How to validate puppet manifests without actually executing puppet?
On Feb 12, 2007, at 4:09 PM, Julian Simpson wrote:> Hi, > > I want to validate my puppet manifests before I check them into > source control. I just want to make sure that the manifest > syntaxes are legal, not to do any more complex testing - the > checkin may be on my laptop and not on the system that the > manifests may be intended to run on. > > Ideally I''d be able to do this from ruby code - and I did try to > instantiate some classes and override the location for the manifests: > > hash = Hash[:Manifest => "/home/jsimpson/blah/blah/site.pp" ] > interpreter = Puppet::Parser::Interpreter.new(hash) > > I''m guessing that I actually need to mess with the Puppet::Parser > class, but I don''t yet understand that generated code - any hints > very welcome!Your code should basically work; I just tested it: manifest = "/Users/luke/bin/test.pp" interp = Puppet::Parser::Interpreter.new(:Manifest => manifest) You can also use the --parseonly argument to puppetmasterd or puppetd, but if you want to use Ruby, you''re pretty close. -- Of the thirty-six ways of avoiding disaster, running away is best. -- Chinese Proverb --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
Digant C Kasundra
2007-Feb-12 22:26 UTC
Re: How to validate puppet manifests without actually executing puppet?
If you get this working, and can provide some details on how to set it up, please post them to the list. There are others (such as myself) that are interested in this as well. --On Monday, February 12, 2007 10:09 PM +0000 Julian Simpson <simpsonjulian@gmail.com> wrote:> Hi, > > I want to validate my puppet manifests before I check them into source > control. I just want to make sure that the manifest syntaxes are legal, > not to do any more complex testing - the checkin may be on my laptop and > not on the system that the manifests may be intended to run on. > > Ideally I''d be able to do this from ruby code - and I did try to > instantiate some classes and override the location for the manifests: > > hash = Hash[:Manifest => "/home/jsimpson/blah/blah/site.pp" ] > interpreter = Puppet::Parser::Interpreter.new(hash) > > I''m guessing that I actually need to mess with the Puppet::Parser class, > but I don''t yet understand that generated code - any hints very welcome! > > best > > Julian.-- Digant C Kasundra // www.diggyk.com //
Peter Abrahamsen
2007-Feb-13 02:48 UTC
Re: How to validate puppet manifests without actually executing puppet?
I tried implementing this briefly on Friday as a pre-commit hook. I wasted a bunch of time trying to do it the hard way (with the Ruby SVN bindings, which are undocumented) -- svnlook is the easy way. I was also confused where to enter the Ruby code, but it looks like you found that. The next problem was that you only get one file at a time, and you get it as a stream. Maybe you can just ignore file not found errors? Otherwise, you''ll need to hack the Puppet code to add a dont-follow-imports flag. The easiest thing is to run puppet --parseonly yourself before you commit. Peter Digant C Kasundra wrote:> If you get this working, and can provide some details on how to set it up, > please post them to the list. There are others (such as myself) that are > interested in this as well. > > --On Monday, February 12, 2007 10:09 PM +0000 Julian Simpson > <simpsonjulian@gmail.com> wrote: > >> Hi, >> >> I want to validate my puppet manifests before I check them into source >> control. I just want to make sure that the manifest syntaxes are legal, >> not to do any more complex testing - the checkin may be on my laptop and >> not on the system that the manifests may be intended to run on. >> >> Ideally I''d be able to do this from ruby code - and I did try to >> instantiate some classes and override the location for the manifests: >> >> hash = Hash[:Manifest => "/home/jsimpson/blah/blah/site.pp" ] >> interpreter = Puppet::Parser::Interpreter.new(hash) >> >> I''m guessing that I actually need to mess with the Puppet::Parser class, >> but I don''t yet understand that generated code - any hints very welcome! >> >> best >> >> Julian. > > >
Luke Kanies
2007-Feb-13 17:39 UTC
Re: How to validate puppet manifests without actually executing puppet?
On Feb 12, 2007, at 8:48 PM, Peter Abrahamsen wrote:> I tried implementing this briefly on Friday as a pre-commit hook. I > wasted a bunch of time trying to do it the hard way (with the Ruby SVN > bindings, which are undocumented) -- svnlook is the easy way. I was > also > confused where to enter the Ruby code, but it looks like you found > that. > > The next problem was that you only get one file at a time, and you get > it as a stream. Maybe you can just ignore file not found errors? > Otherwise, you''ll need to hack the Puppet code to add a > dont-follow-imports flag.This would be relatively straightforward to fix -- just add a config option that ignores imports. -- A diplomat is a man who can convince his wife she''d look stout in a fur coat. --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
Julian Simpson
2007-Feb-13 19:47 UTC
Re: How to validate puppet manifests without actually executing puppet?
Luke, Thank you! I should have written a proper test like this one: require ''puppet'' require ''test/unit'' class Spike < Test::Unit::TestCase def test_can_parse_my_config hash = Hash[:Manifest => "/home/jsimpson/.../manifests/site.pp" ] interpreter = Puppet::Parser::Interpreter.new(hash) puts interpreter.public_methods.sort end def test_cannot_parse_etc_passwd hash = Hash[:Manifest => "/etc/passwd" ] interpreter = Puppet::Parser::Interpreter.new(hash) end end Still, good to know about the --parseonly option. Thank you again! best, Julian. On 2/12/07, Luke Kanies <luke@madstop.com> wrote:> > On Feb 12, 2007, at 4:09 PM, Julian Simpson wrote: > > > Hi, > > > > I want to validate my puppet manifests before I check them into > > source control. I just want to make sure that the manifest > > syntaxes are legal, not to do any more complex testing - the > > checkin may be on my laptop and not on the system that the > > manifests may be intended to run on. > > > > Ideally I''d be able to do this from ruby code - and I did try to > > instantiate some classes and override the location for the manifests: > > > > hash = Hash[:Manifest => "/home/jsimpson/blah/blah/site.pp" ] > > interpreter = Puppet::Parser::Interpreter.new(hash) > > > > I''m guessing that I actually need to mess with the Puppet::Parser > > class, but I don''t yet understand that generated code - any hints > > very welcome! > > Your code should basically work; I just tested it: > > manifest = "/Users/luke/bin/test.pp" > > interp = Puppet::Parser::Interpreter.new(:Manifest => manifest) > > You can also use the --parseonly argument to puppetmasterd or > puppetd, but if you want to use Ruby, you''re pretty close. > > -- > Of the thirty-six ways of avoiding disaster, running away is best. > -- Chinese Proverb > --------------------------------------------------------------------- > Luke Kanies | http://reductivelabs.com | http://madstop.com > > > _______________________________________________ > Puppet-users mailing list > Puppet-users@madstop.com > https://mail.madstop.com/mailman/listinfo/puppet-users >_______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
Julian Simpson
2007-Feb-13 19:49 UTC
Re: How to validate puppet manifests without actually executing puppet?
Digant, I''ll let you know how I get on with the unit test I just posted. I''m hoping that''s pretty much all I need. Best Julian On 2/12/07, Digant C Kasundra <digant@stanford.edu> wrote:> > If you get this working, and can provide some details on how to set it up, > please post them to the list. There are others (such as myself) that are > interested in this as well. > > --On Monday, February 12, 2007 10:09 PM +0000 Julian Simpson > <simpsonjulian@gmail.com> wrote: > > > Hi, > > > > I want to validate my puppet manifests before I check them into source > > control. I just want to make sure that the manifest syntaxes are legal, > > not to do any more complex testing - the checkin may be on my laptop and > > not on the system that the manifests may be intended to run on. > > > > Ideally I''d be able to do this from ruby code - and I did try to > > instantiate some classes and override the location for the manifests: > > > > hash = Hash[:Manifest => "/home/jsimpson/blah/blah/site.pp" ] > > interpreter = Puppet::Parser::Interpreter.new(hash) > > > > I''m guessing that I actually need to mess with the Puppet::Parser class, > > but I don''t yet understand that generated code - any hints very welcome! > > > > best > > > > Julian. > > > > -- > Digant C Kasundra > // www.diggyk.com // > _______________________________________________ > Puppet-users mailing list > Puppet-users@madstop.com > https://mail.madstop.com/mailman/listinfo/puppet-users >_______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users
Luke Kanies
2007-Feb-13 20:09 UTC
Re: How to validate puppet manifests without actually executing puppet?
On Feb 13, 2007, at 1:49 PM, Julian Simpson wrote:> Digant, > > I''ll let you know how I get on with the unit test I just posted. > I''m hoping that''s pretty much all I need.As mentioned by others, this will not work when parse-testing individual files that import any other files. We''ll need to slightly modify the ''import'' function to enable something like this, although you could possibly trap ImportError and just continue through. -- The easiest way for your children to learn about money is for you not to have any. -- Katharine Whitehorn --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com
Julian Simpson
2007-Feb-13 21:30 UTC
Re: How to validate puppet manifests without actually executing puppet?
That worked a treat for the config I have. I''m parsing the site.pp and all it''s includes and imports - and I can break an imported file and cause the parse to fail, which is what I wanted as a first pass. Thanks all! Best Julian. On 2/13/07, Luke Kanies <luke@madstop.com> wrote:> > > As mentioned by others, this will not work when parse-testing > individual files that import any other files. We''ll need to slightly > modify the ''import'' function to enable something like this, although > you could possibly trap ImportError and just continue through. > > -- > The easiest way for your children to learn about money is for you > not to have any. -- Katharine Whitehorn > --------------------------------------------------------------------- > Luke Kanies | http://reductivelabs.com | http://madstop.com > > > _______________________________________________ > Puppet-users mailing list > Puppet-users@madstop.com > https://mail.madstop.com/mailman/listinfo/puppet-users >_______________________________________________ Puppet-users mailing list Puppet-users@madstop.com https://mail.madstop.com/mailman/listinfo/puppet-users