lib/rspec-system-puppet/helpers.rb in rspec-system-puppet-0.3.2 vs lib/rspec-system-puppet/helpers.rb in rspec-system-puppet-0.3.3
- old
+ new
@@ -79,22 +79,38 @@
end
# Run puppet agent
#
# @param opts [Hash] a hash of opts
+ # @option opts [RSpecSystem::Node] :node node to execute DSL on
+ # @option opts [Boolean] :debug true if debugging required
+ # @option opts [Boolean] :trace true if trace required
# @return [Hash] a hash of results
# @yield [result] yields result when called as a block
# @yieldparam result [Hash] a hash containing :exit_code, :stdout and :stderr
- def puppet_agent
+ # @example
+ # puppet_agent.do |r|
+ # r[:exit_code].should == 0
+ # end
+ # @example with debugging enabled
+ # puppet_agent(:debug => true).do |r|
+ # r[:exit_code].should == 0
+ # end
+ def puppet_agent(opts = {})
# Defaults etc.
opts = {
:node => rspec_system_node_set.default_node,
- }
+ :debug => false,
+ :trace => true,
+ }.merge(opts)
node = opts[:node]
- result = system_run(:n => node, :c => 'puppet agent -t --detailed-exitcodes')
+ cmd = "puppet agent -t --detailed-exitcodes"
+ cmd += " --debug" if opts[:debug]
+ cmd += " --trace" if opts[:trace]
+ result = system_run(:n => node, :c => cmd)
if block_given?
yield(result)
else
result
@@ -157,30 +173,31 @@
#
# @param opts [Hash, String] a hash of opts, or a string containing the
# code to execute with option defaults
# @option opts [String] :code the Puppet DSL code to execute
# @option opts [RSpecSystem::Node] :node node to execute DSL on
+ # @option opts [Boolean] :debug true if debugging required
+ # @option opts [Boolean] :trace true if trace required
# @return [Hash] a hash of results
# @yield [result] yields result when called as a block
# @yieldparam result [Hash] a hash containing :exit_code, :stdout and :stderr
# @example
# it "run notice" do
# puppet_apply("notice('foo')") do |r|
# r[:stdout].should =~ /foo/
# end
# end
- # @todo Support for custom switches perhaps?
- # @todo The destination path is static, need a good remote random path
- # generator
def puppet_apply(opts)
if opts.is_a?(String)
opts = {:code => opts}
end
# Defaults
opts = {
- :node => rspec_system_node_set.default_node
+ :node => rspec_system_node_set.default_node,
+ :debug => false,
+ :trace => true,
}.merge(opts)
code = opts[:code]
node = opts[:node]
@@ -197,10 +214,14 @@
log.info("Cat file to see contents")
system_run(:n => node, :c => "cat #{remote_path}")
log.info("Now running puppet apply")
- result = system_run(:n => node, :c => "puppet apply --detailed-exitcodes #{remote_path}")
+ cmd = "puppet apply --detailed-exitcodes"
+ cmd += " --debug" if opts[:debug]
+ cmd += " --trace" if opts[:trace]
+ cmd += " #{remote_path}"
+ result = system_run(:n => node, :c => cmd)
if block_given?
yield(result)
else
result