-
-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added dump_args statement function for debugging puppet code #30
Conversation
@logicminds thank you for updating this! diff --git a/lib/puppet/parser/functions/default_content.rb b/lib/puppet/parser/functions/default_content.rb
index dc38c02..8b16050 100644
--- a/lib/puppet/parser/functions/default_content.rb
+++ b/lib/puppet/parser/functions/default_content.rb
@@ -1,22 +1,20 @@
-module Puppet::Parser::Functions
- Puppet::Parser::Functions.newfunction(:default_content,
- :type => :rvalue,
- :doc => <<-'ENDOFDOC'
+Puppet::Parser::Functions.newfunction(:default_content,
+ :type => :rvalue,
+ :doc => <<-'ENDOFDOC'
Takes an optional content and an optional template name to calculate the actual
contents of a file.
This small function abbreviates the default initialisation boilerplate of
stdmod modules.
ENDOFDOC
- ) do |args|
- content = args[0]
- template_name = args[1]
+) do |args|
+ content = args[0]
+ template_name = args[1]
- Puppet::Parser::Functions.autoloader.loadall
+ Puppet::Parser::Functions.autoloader.loadall
- return content if content != ''
- return function_template(template_name) if template_name
+ return content if content != ''
+ return function_template(template_name) if template_name
- return nil
- end
+ return nil
end
diff --git a/lib/puppet/parser/functions/dump_args.rb b/lib/puppet/parser/functions/dump_args.rb
index 37f7587..1db1c6b 100644
--- a/lib/puppet/parser/functions/dump_args.rb
+++ b/lib/puppet/parser/functions/dump_args.rb
@@ -1,17 +1,13 @@
require 'json'
require 'puppet/parser/functions'
-module Puppet::Parser::Functions
- newfunction(:dump_args, :type => :statement,:doc => <<-EOS
+Puppet::Parser::Functions.newfunction(:dump_args, :type => :statement, :doc => <<-EOS
dump_args - prints the args to STDOUT in Pretty JSON format.
Useful for debugging purposes only. Ideally you would use this in
conjunction with a rspec-puppet unit test. Otherwise the output will
be shown during a puppet run when verbose/debug options are enabled.
-
EOS
- ) do |args|
- puts JSON.pretty_generate(args)
- end
-
+) do |args|
+ puts JSON.pretty_generate(args)
end
diff --git a/spec/unit/puppet/parser/functions/dump_args_spec.rb b/spec/unit/puppet/parser/functions/dump_args_spec.rb
index 79d32c9..b42e1e8 100644
--- a/spec/unit/puppet/parser/functions/dump_args_spec.rb
+++ b/spec/unit/puppet/parser/functions/dump_args_spec.rb
@@ -1,10 +1,9 @@
require 'spec_helper'
require 'json'
-describe "dump_args" do
+describe 'dump_args' do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
- it "should exist" do
- Puppet::Parser::Functions.function("dump_args").should == "function_dump_args"
+ it 'should exist' do
+ Puppet::Parser::Functions.function('dump_args').should == 'function_dump_args'
end
-
end |
you can join the rubocop discussion here: voxpupuli/modulesync_config#14 |
@igalic just rebased after applying the diff. Rubocop only warns on some things that should be excluded which I commented on in the rubocop discussion. |
@logicminds can you rebase and try again? |
fc46c63
to
82bd031
Compare
@jyaworski justed rebased |
Merging despite rubocop..... |
Added dump_args statement function for debugging puppet code
This adds a new function that outputs the variables to STDOUT. Its pretty dead simple and when used with an rspec test it can decrease debug time greatly. The only other option is to use a bunch of notify resources which to me is not as fast and does not display the variables correctly when you have hashes and arrays in your variables. If you think this is not useful imagine storing a large hash in hiera and wanting to know why your custom parser is blowing up on your data and the notify statement does a poor job of displaying your 50 line data hash. Its really nice to see whats in your puppet variables and this helps immensely.
Another use case is trying to find out why create_resources isn't working as expected because your data being passed in is all wrong.
Basically it works like this:
puppet code below:
yields the following in STDOUT