diff --git a/acceptance/tests/allow_arbitrary_node_name_fact_for_agent.rb b/acceptance/tests/allow_arbitrary_node_name_fact_for_agent.rb index c9ff3e4a8..4d7c43107 100644 --- a/acceptance/tests/allow_arbitrary_node_name_fact_for_agent.rb +++ b/acceptance/tests/allow_arbitrary_node_name_fact_for_agent.rb @@ -1,50 +1,50 @@ test_name "node_name_fact should be used to determine the node name for puppet agent" success_message = "node_name_fact setting was correctly used to determine the node name" node_names = [] on agents, facter('kernel') do node_names << stdout.chomp end node_names.uniq! authfile = "/tmp/auth.conf-2128-#{$$}" authconf = node_names.map do |node_name| %Q[ path /catalog/#{node_name} auth yes allow * path /node/#{node_name} auth yes allow * ] end.join("\n") manifest_file = "/tmp/node_name_value-test-#{$$}.pp" manifest = %Q[ Exec { path => "/usr/bin:/bin" } node default { exec { "false": } } ] manifest << node_names.map do |node_name| %Q[ node "#{node_name}" { - exec { "echo #{success_message}": } + exec { "echo #{success_message}": logoutput => true } } ] end.join("\n") create_remote_file master, authfile, authconf create_remote_file master, manifest_file, manifest on master, "chmod 644 #{authfile} #{manifest_file}" with_master_running_on(master, "--rest_authconfig #{authfile} --manifest #{manifest_file} --daemonize --dns_alt_names=\"puppet, $(hostname -s), $(hostname -f)\" --autosign true") do run_agent_on(agents, "--no-daemonize --verbose --onetime --node_name_fact kernel --server #{master}") do assert_match(success_message, stdout) end end diff --git a/acceptance/tests/allow_arbitrary_node_name_for_apply.rb b/acceptance/tests/allow_arbitrary_node_name_for_apply.rb index 4daa8a65b..f620cd95f 100644 --- a/acceptance/tests/allow_arbitrary_node_name_for_apply.rb +++ b/acceptance/tests/allow_arbitrary_node_name_for_apply.rb @@ -1,17 +1,17 @@ test_name "node_name_value should be used as the node name for puppet apply" success_message = "node_name_value setting was correctly used as the node name" manifest = %Q[ Exec { path => "/usr/bin:/bin" } node default { exec { "false": } } node a_different_node_name { - exec { "echo #{success_message}": } + exec { "echo #{success_message}": logoutput => true } } ] on agents, puppet_apply("--verbose --node_name_value a_different_node_name"), :stdin => manifest do assert_match(success_message, stdout) end diff --git a/acceptance/tests/apply/hashes/should_not_reassign.rb b/acceptance/tests/apply/hashes/should_not_reassign.rb index dd8fc1c22..2b0f9cc13 100755 --- a/acceptance/tests/apply/hashes/should_not_reassign.rb +++ b/acceptance/tests/apply/hashes/should_not_reassign.rb @@ -1,10 +1,10 @@ test_name "hash reassignment should fail" manifest = %q{ $my_hash = {'one' => '1', 'two' => '2' } $my_hash['one']='1.5' } apply_manifest_on(agents, manifest, :acceptable_exit_codes => [1]) do fail_test "didn't find the failure" unless - stdout.include? "Assigning to the hash 'my_hash' with an existing key 'one'" + stderr.include? "Assigning to the hash 'my_hash' with an existing key 'one'" end diff --git a/acceptance/tests/cycle_detection.rb b/acceptance/tests/cycle_detection.rb index c59ca9e0f..44fb11dd9 100644 --- a/acceptance/tests/cycle_detection.rb +++ b/acceptance/tests/cycle_detection.rb @@ -1,26 +1,26 @@ test_name "cycle detection and reporting" step "check we report a simple cycle" manifest = < Notify["a2"] } notify { "a2": require => Notify["a1"] } EOT apply_manifest_on(agents, manifest) do - assert_match(/Found 1 dependency cycle/, stdout, + assert_match(/Found 1 dependency cycle/, stderr, "found and reported the cycle correctly") end step "report multiple cycles in the same graph" manifest = < Notify["a2"] } notify { "a2": require => Notify["a1"] } notify { "b1": require => Notify["b2"] } notify { "b2": require => Notify["b1"] } EOT apply_manifest_on(agents, manifest) do - assert_match(/Found 2 dependency cycles/, stdout, + assert_match(/Found 2 dependency cycles/, stderr, "found and reported the cycle correctly") end diff --git a/acceptance/tests/file_hello_world.rb b/acceptance/tests/file_hello_world.rb index b64ddd717..940f0fc4a 100644 --- a/acceptance/tests/file_hello_world.rb +++ b/acceptance/tests/file_hello_world.rb @@ -1,23 +1,22 @@ # Verify that a trivial manifest can be run to completion. test_name "The challenging 'Hello, World' manifest" agents.each do |agent| filename = agent.tmpfile('hello-world.txt') content = "Hello, World" manifest = "file { '#{filename}': content => '#{content}' }" step "ensure we are clean before testing..." on(agent, "rm -f #{filename}") step "run the manifest itself" apply_manifest_on(agent, manifest) do - fail_test "the expected notice of action was missing" unless - stdout.index "File[#{filename}]/ensure: defined content as" + assert_match("File[#{filename}]/ensure: defined content as", stdout, "the expected notice of action was missing") end step "verify the content of the generated files." on agent, "grep '#{content}' #{filename}" step "clean up after our test run." on(agent, "rm -f #{filename}") end diff --git a/acceptance/tests/helpful_error_message_when_hostname_not_match_server_certificate.rb b/acceptance/tests/helpful_error_message_when_hostname_not_match_server_certificate.rb index 40818a856..02c46649d 100644 --- a/acceptance/tests/helpful_error_message_when_hostname_not_match_server_certificate.rb +++ b/acceptance/tests/helpful_error_message_when_hostname_not_match_server_certificate.rb @@ -1,9 +1,9 @@ test_name "generate a helpful error message when hostname doesn't match server certificate" # Start the master with a certname not matching its hostname with_master_running_on(master, "--certname foobar_not_my_hostname --dns_alt_names one_cert,two_cert,red_cert,blue_cert --autosign true") do run_agent_on(agents, "--no-usecacheonfailure --no-daemonize --verbose --onetime --server #{master}", :acceptable_exit_codes => (1..255)) do msg = "Server hostname '#{master}' did not match server certificate; expected one of foobar_not_my_hostname, DNS:blue_cert, DNS:foobar_not_my_hostname, DNS:one_cert, DNS:red_cert, DNS:two_cert" - assert_match(msg, stdout) + assert_match(msg, stderr) end end diff --git a/acceptance/tests/jeff_append_to_array.rb b/acceptance/tests/jeff_append_to_array.rb index 20f43665e..1fab8ad3c 100644 --- a/acceptance/tests/jeff_append_to_array.rb +++ b/acceptance/tests/jeff_append_to_array.rb @@ -1,20 +1,20 @@ # Ported from the acceptance test suite. test_name "Jeff: Append to Array" manifest = %q{ class parent { $arr1 = [ "parent array element" ] } class parent::child inherits parent { $arr1 += [ "child array element" ] notify { $arr1: } } include parent::child } agents.each do |host| apply_manifest_on(host, manifest) do - assert_match(/notice: parent array element/, stdout, "#{host}: parent missing") - assert_match(/notice: child array element/, stdout, "#{host}: child missing") + assert_match(/parent array element/, stdout, "#{host}: parent missing") + assert_match(/child array element/, stdout, "#{host}: child missing") end end diff --git a/acceptance/tests/language/resource_refs_with_nested_arrays.rb b/acceptance/tests/language/resource_refs_with_nested_arrays.rb index ead35a3f5..5b11854d9 100644 --- a/acceptance/tests/language/resource_refs_with_nested_arrays.rb +++ b/acceptance/tests/language/resource_refs_with_nested_arrays.rb @@ -1,27 +1,27 @@ test_name "#7681: Allow using array variables in resource references" agents.each do |agent| test_manifest = < "#{agent.echo('the first command')}", path => "#{agent.path}", logoutput => true, } exec { "second": command => "#{agent.echo('the second command')}", path => "#{agent.path}", logoutput => true, } exec { "third": command => "#{agent.echo('the final command')}", path => "#{agent.path}", logoutput => true, require => Exec[$exec_names], } MANIFEST apply_manifest_on agent, test_manifest do - assert_match(/Exec\[third\].*the final command/, "#{stdout}") + assert_match(/Exec\[third\].*the final command/, stdout) end end diff --git a/acceptance/tests/puppet_apply_basics.rb b/acceptance/tests/puppet_apply_basics.rb index 23c57d84d..c11546ebf 100644 --- a/acceptance/tests/puppet_apply_basics.rb +++ b/acceptance/tests/puppet_apply_basics.rb @@ -1,17 +1,17 @@ # Ported from a collection of small spec tests in acceptance. # # Unified into a single file because they are literally one-line tests! test_name "Trivial puppet tests" step "check that puppet apply displays notices" agents.each do |host| apply_manifest_on(host, "notice 'Hello World'") do - assert_match(/notice:.*Hello World/, stdout, "#{host}: missing notice!") + assert_match(/Hello World/, stdout, "#{host}: missing notice!") end end step "verify help displays something for puppet master" on master, puppet_master("--help") do assert_match(/puppet master/, stdout, "improper help output") end diff --git a/acceptance/tests/puppet_apply_should_show_a_notice.rb b/acceptance/tests/puppet_apply_should_show_a_notice.rb index 757d29bbf..df3922f44 100644 --- a/acceptance/tests/puppet_apply_should_show_a_notice.rb +++ b/acceptance/tests/puppet_apply_should_show_a_notice.rb @@ -1,7 +1,7 @@ test_name "puppet apply should show a notice" agents.each do |host| apply_manifest_on(host, "notice 'Hello World'") do - assert_match(/notice: .*: Hello World/, stdout, "#{host}: the notice didn't show") + assert_match(/.*: Hello World/, stdout, "#{host}: the notice didn't show") end end diff --git a/acceptance/tests/resource/cron/should_remove_cron.rb b/acceptance/tests/resource/cron/should_remove_cron.rb index fa72f5a05..0e8a30d72 100755 --- a/acceptance/tests/resource/cron/should_remove_cron.rb +++ b/acceptance/tests/resource/cron/should_remove_cron.rb @@ -1,40 +1,40 @@ test_name "puppet should remove a crontab entry as expected" tmpuser = "pl#{rand(999999).to_i}" tmpfile = "/tmp/cron-test-#{Time.new.to_i}" create_user = "user { '#{tmpuser}': ensure => present, managehome => false }" delete_user = "user { '#{tmpuser}': ensure => absent, managehome => false }" package_cron = "case $operatingsystem { centos, redhat: {$cron = 'cronie'}\n default: {$cron ='cron'} } package {'cron': name=> $cron, ensure=>present, }" agents.each do |host| if host['platform'].include?('windows') skip_test "Test not supported on this platform" next end step "ensure the user exist via puppet" apply_manifest_on host, create_user apply_manifest_on host, package_cron step "create the existing job by hand..." run_cron_on(host,:add,tmpuser,"* * * * * /bin/true") step "apply the resource on the host using puppet resource" on(host, puppet_resource("cron", "crontest", "user=#{tmpuser}", "command=/bin/true", "ensure=absent")) do assert_match(/crontest\D+ensure:\s+removed/, stdout, "Didn't remove crobtab entry for #{tmpuser} on #{host}") end step "verify that crontab -l contains what you expected" run_cron_on(host, :list, tmpuser) do - assert_no_match(/\/bin\/true/, stdout, "Error: Found entry for #{tmpuser} on #{host}") + assert_no_match(/\/bin\/true/, stderr, "Error: Found entry for #{tmpuser} on #{host}") end step "remove the crontab file for that user" run_cron_on(host, :remove, tmpuser) step "remove the user from the system" apply_manifest_on host, delete_user end diff --git a/acceptance/tests/resource/file/ticket_8740_should_not_enumerate_root_directory.rb b/acceptance/tests/resource/file/ticket_8740_should_not_enumerate_root_directory.rb index 6cef5690e..a918f8ccb 100644 --- a/acceptance/tests/resource/file/ticket_8740_should_not_enumerate_root_directory.rb +++ b/acceptance/tests/resource/file/ticket_8740_should_not_enumerate_root_directory.rb @@ -1,39 +1,39 @@ test_name "#8740: should not enumerate root directory" target = "/test-socket-#{$$}" agents.each do |agent| if agent['platform'].include?('windows') skip_test "Test not supported on this platform" next end step "clean up the system before we begin" on(agent, "rm -f #{target}") step "create UNIX domain socket" on(agent, %Q{ruby -e "require 'socket'; UNIXServer::new('#{target}').close"}) step "query for all files, which should return nothing" on(agent, puppet_resource('file'), :acceptable_exit_codes => [1]) do - assert_match(%r{Listing all file instances is not supported. Please specify a file or directory, e.g. puppet resource file /etc}, stdout) + assert_match(%r{Listing all file instances is not supported. Please specify a file or directory, e.g. puppet resource file /etc}, stderr) end ["/", "/etc"].each do |file| step "query '#{file}' directory, which should return single entry" on(agent, puppet_resource('file', file)) do files = stdout.scan(/^file \{ '([^']+)'/).flatten assert_equal(1, files.size, "puppet returned multiple files: #{files.join(', ')}") assert_match(file, files[0], "puppet did not return file") end end step "query file that does not exist, which should report the file is absent" on(agent, puppet_resource('file', '/this/does/notexist')) do assert_match(/ensure\s+=>\s+'absent'/, stdout) end step "remove UNIX domain socket" on(agent, "rm -f #{target}") end diff --git a/acceptance/tests/resource/group/should_not_destoy_unexisting.rb b/acceptance/tests/resource/group/should_not_destoy_unexisting.rb index 287bb0fa6..53147f08d 100755 --- a/acceptance/tests/resource/group/should_not_destoy_unexisting.rb +++ b/acceptance/tests/resource/group/should_not_destoy_unexisting.rb @@ -1,15 +1,15 @@ test_name "should not destroy a group that doesn't exist" name = "test-group-#{Time.new.to_i}" step "verify the group does not already exist" agents.each do |agent| agent.group_absent(name) end step "verify that we don't remove the group when it doesn't exist" on(agents, puppet_resource('group', name, 'ensure=absent')) do fail_test "it looks like we tried to remove the group" if - stdout.include? "notice: /Group[#{name}]/ensure: removed" + stdout.include? "/Group[#{name}]/ensure: removed" end diff --git a/acceptance/tests/resource/host/should_not_create_existing.rb b/acceptance/tests/resource/host/should_not_create_existing.rb index 2f2161cf2..89a052bfd 100755 --- a/acceptance/tests/resource/host/should_not_create_existing.rb +++ b/acceptance/tests/resource/host/should_not_create_existing.rb @@ -1,18 +1,18 @@ test_name "should not create host if it exists" agents.each do |agent| file = agent.tmpfile('host-not-create-existing') step "set up the system for the test" on agent, "printf '127.0.0.2 test alias\n' > #{file}" step "tell puppet to ensure the host exists" on(agent, puppet_resource('host', 'test', "target=#{file}", 'ensure=present', 'ip=127.0.0.2', 'host_aliases=alias')) do fail_test "darn, we created the host record" if - stdout.include? 'notice: /Host[test1]/ensure: created' + stdout.include? '/Host[test1]/ensure: created' end step "clean up after we created things" on agent, "rm -f #{file}" end diff --git a/acceptance/tests/resource/host/ticket_4131_should_not_create_without_ip.rb b/acceptance/tests/resource/host/ticket_4131_should_not_create_without_ip.rb index 392678434..5d88c8366 100755 --- a/acceptance/tests/resource/host/ticket_4131_should_not_create_without_ip.rb +++ b/acceptance/tests/resource/host/ticket_4131_should_not_create_without_ip.rb @@ -1,23 +1,23 @@ test_name "#4131: should not create host without IP attribute" agents.each do |agent| file = agent.tmpfile('4131-require-ip') step "configure the target system for the test" on agent, "rm -vrf #{file} ; touch #{file}" step "try to create the host, which should fail" # REVISIT: This step should properly need to handle the non-zero exit code, # and #5668 has been filed to record that. When it is fixed this test will # start to fail, and this comment will tell you why. --daniel 2010-12-24 on(agent, puppet_resource('host', 'test', "target=#{file}", "host_aliases=alias")) do fail_test "puppet didn't complain about the missing attribute" unless - stdout.include? 'ip is a required attribute for hosts' + stderr.include? 'ip is a required attribute for hosts' end step "verify that the host was not added to the file" on(agent, "cat #{file} ; rm -f #{file}") do fail_test "the host was apparently added to the file" if stdout.include? 'test' end end diff --git a/acceptance/tests/ticket_3961_puppet_ca_should_produce_certs.rb b/acceptance/tests/ticket_3961_puppet_ca_should_produce_certs.rb index 3f41aebbe..d6871cbba 100644 --- a/acceptance/tests/ticket_3961_puppet_ca_should_produce_certs.rb +++ b/acceptance/tests/ticket_3961_puppet_ca_should_produce_certs.rb @@ -1,35 +1,35 @@ test_name "#3961: puppet ca should produce certs spec" target = "working3961.example.org" -expect = ['notice: Signed certificate request for ca', - 'notice: Rebuilding inventory file', - 'notice: working3961.example.org has a waiting certificate request', - 'notice: Signed certificate request for working3961.example.org', - 'notice: Removing file Puppet::SSL::CertificateRequest working3961.example.org'] +expect = ['Signed certificate request for ca', + 'Rebuilding inventory file', + 'working3961.example.org has a waiting certificate request', + 'Signed certificate request for working3961.example.org', + 'Removing file Puppet::SSL::CertificateRequest working3961.example.org'] agents.each do |agent| if agent['platform'].include?('windows') skip_test "Test not supported on this platform" next end scratch = agent.tmpdir('puppet-ssl-3961') options = { :confdir => scratch, :vardir => scratch } step "removing the SSL scratch directory..." on(agent, "rm -vrf #{scratch}") step "generate a certificate in #{scratch}" on(agent,puppet_cert('--trace', '--generate', target, options)) do expect.each do |line| stdout.index(line) or fail_test("missing line in output: #{line}") end end step "verify the certificate for #{target} exists" on agent, "test -f #{scratch}/ssl/certs/#{target}.pem" step "verify the private key for #{target} exists" on agent, "grep -q 'BEGIN RSA PRIVATE KEY' #{scratch}/ssl/private_keys/#{target}.pem" end diff --git a/acceptance/tests/ticket_4233_resource_with_a_newline.rb b/acceptance/tests/ticket_4233_resource_with_a_newline.rb index 61da2f722..b2e374584 100644 --- a/acceptance/tests/ticket_4233_resource_with_a_newline.rb +++ b/acceptance/tests/ticket_4233_resource_with_a_newline.rb @@ -1,17 +1,17 @@ test_name "#4233: resource with a newline" # 2010-07-22 Jeff McCune # AffectedVersion: 2.6.0rc3 # FixedVersion: 2.6.0 # JJM We expect 2.6.0rc3 to return an error # and 2.6.0 final to not return an error line. # Look for the line in the output and fail the test # if we find it. agents.each do |host| resource = host.echo('-e "\nHello World\n"') apply_manifest_on(host, "exec { '#{resource}': }") do - assert_match(/notice:.*Hello World.*success/, stdout) + assert_match(/Hello World.*success/, stdout) end end diff --git a/acceptance/tests/ticket_4287_undefined_method_evaluate_match_when_function_call_used_in_an_if_statement.rb b/acceptance/tests/ticket_4287_undefined_method_evaluate_match_when_function_call_used_in_an_if_statement.rb index f5a1c1685..532806346 100644 --- a/acceptance/tests/ticket_4287_undefined_method_evaluate_match_when_function_call_used_in_an_if_statement.rb +++ b/acceptance/tests/ticket_4287_undefined_method_evaluate_match_when_function_call_used_in_an_if_statement.rb @@ -1,14 +1,14 @@ test_name "Bug #4287: undefined method 'evaluate_match' when function call used in an 'if' statement" manifest = %q{ $foo='abc' if $foo != regsubst($foo,'abc','def') { notify { 'No issue here...': } } } agents.each do |host| apply_manifest_on(host, manifest) do - assert_match(/notice: No issue here.../, stdout, "didn't get the expected notice on #{host}") + assert_match(/No issue here.../, stdout, "didn't get the expected notice on #{host}") end end diff --git a/acceptance/tests/ticket_4293_define_and_use_a_define_within_a_class.rb b/acceptance/tests/ticket_4293_define_and_use_a_define_within_a_class.rb index aa42fd401..18aca2bd0 100644 --- a/acceptance/tests/ticket_4293_define_and_use_a_define_within_a_class.rb +++ b/acceptance/tests/ticket_4293_define_and_use_a_define_within_a_class.rb @@ -1,23 +1,23 @@ # 2010-07-22 Jeff McCune # # AffectedVersion: 2.6.0rc4 # FixedVersion: 2.6.0 # # Description: using a defined type in the class it's declared in # causes an error. manifest = < "a_message_for_you" } } include foo PP agents.each do |host| apply_manifest_on(host, manifest) do - assert_match(/notice.*?Foo::Do_notify.*?a_message_for_you/, stdout, "the notification didn't show up in stdout on #{host}") + assert_match(/.*?Foo::Do_notify.*?a_message_for_you/, stdout, "the notification didn't show up in stdout on #{host}") end end diff --git a/acceptance/tests/ticket_6928_puppet_master_parse_fails.rb b/acceptance/tests/ticket_6928_puppet_master_parse_fails.rb index 7141bdc04..55162a908 100644 --- a/acceptance/tests/ticket_6928_puppet_master_parse_fails.rb +++ b/acceptance/tests/ticket_6928_puppet_master_parse_fails.rb @@ -1,32 +1,32 @@ test_name "#6928: Puppet --parseonly should return deprication message" # Create good and bad formatted manifests step "Master: create valid, invalid formatted manifests" create_remote_file(master, '/tmp/good.pp', %w{notify{good:}} ) create_remote_file(master, '/tmp/bad.pp', 'notify{bad:') step "Master: use --parseonly on an invalid manifest, should return 1 and issue deprecation warning" on master, puppet_master( %w{--parseonly /tmp/bad.pp} ), :acceptable_exit_codes => [ 1 ] assert_match(/--parseonly has been removed. Please use \'puppet parser validate \'/, stdout, "Deprecation warning not issued for --parseonly on #{master}" ) step "Agents: create valid, invalid formatted manifests" agents.each do |host| good = host.tmpfile('good-6928') bad = host.tmpfile('bad-6928') create_remote_file(host, good, %w{notify{good:}} ) create_remote_file(host, bad, 'notify{bad:') step "Agents: use --parseonly on an invalid manifest, should return 1 and issue deprecation warning" on(host, puppet('apply', '--parseonly', bad), :acceptable_exit_codes => [ 1 ]) do assert_match(/--parseonly has been removed. Please use \'puppet parser validate \'/, stdout, "Deprecation warning not issued for --parseonly on #{host}" ) end step "Test Face for 'parser validate' with good manifest -- should pass" on(host, puppet('parser', 'validate', good), :acceptable_exit_codes => [ 0 ]) step "Test Faces for 'parser validate' with bad manifest -- should fail" on(host, puppet('parser', 'validate', bad), :acceptable_exit_codes => [ 1 ]) do - assert_match(/err: Could not parse for environment production/, stdout, "Bad manifest detection failed on #{host}" ) + assert_match(/Error: Could not parse for environment production/, stderr, "Bad manifest detection failed on #{host}" ) end end diff --git a/acceptance/tests/ticket_7728_don't_log_whits_on_failure.rb b/acceptance/tests/ticket_7728_don't_log_whits_on_failure.rb index eaa95ff55..c5fe7e4ef 100644 --- a/acceptance/tests/ticket_7728_don't_log_whits_on_failure.rb +++ b/acceptance/tests/ticket_7728_don't_log_whits_on_failure.rb @@ -1,18 +1,18 @@ test_name "#7728: Don't log whits on resource failure" manifest = %Q{ class foo { exec { "test": command => "false", path => ['/bin', '/usr/bin'] } notify { "before": before => Exec["test"] } notify { "after": require => Exec["test"] } } include foo } apply_manifest_on(agents, manifest) do - assert_match(Regexp.new(Regexp.quote('notice: /Stage[main]/Foo/Notify[after]: Dependency Exec[test] has failures: true')), stdout, "the after dependency must be reported") + assert_match(Regexp.new(Regexp.quote('/Stage[main]/Foo/Notify[after]: Dependency Exec[test] has failures: true')), stdout, "the after dependency must be reported") assert_no_match(Regexp.new(Regexp.quote('Class[Foo]')), stdout, 'the class should not be mentioned') assert_no_match(Regexp.new(Regexp.quote('Stage[Main]')), stdout, 'the class should not be mentioned') end diff --git a/lib/puppet/application/module.rb b/lib/puppet/application/module.rb index e10766035..8526974bc 100644 --- a/lib/puppet/application/module.rb +++ b/lib/puppet/application/module.rb @@ -1,11 +1,4 @@ require 'puppet/application/face_base' class Puppet::Application::Module < Puppet::Application::FaceBase - def setup - super - if self.render_as.name == :console - Puppet::Util::Log.close(:console) - Puppet::Util::Log.newdestination(:telly_prototype_console) - end - end end diff --git a/lib/puppet/util/log/destinations.rb b/lib/puppet/util/log/destinations.rb index 4dc1da4a7..22fcb36ca 100644 --- a/lib/puppet/util/log/destinations.rb +++ b/lib/puppet/util/log/destinations.rb @@ -1,270 +1,253 @@ Puppet::Util::Log.newdesttype :syslog do def self.suitable?(obj) Puppet.features.syslog? end def close Syslog.close end def initialize Syslog.close if Syslog.opened? name = "puppet-#{Puppet.run_mode.name}" options = Syslog::LOG_PID | Syslog::LOG_NDELAY # XXX This should really be configurable. str = Puppet[:syslogfacility] begin facility = Syslog.const_get("LOG_#{str.upcase}") rescue NameError raise Puppet::Error, "Invalid syslog facility #{str}" end @syslog = Syslog.open(name, options, facility) end def handle(msg) # XXX Syslog currently has a bug that makes it so you # cannot log a message with a '%' in it. So, we get rid # of them. if msg.source == "Puppet" msg.to_s.split("\n").each do |line| @syslog.send(msg.level, line.gsub("%", '%%')) end else msg.to_s.split("\n").each do |line| @syslog.send(msg.level, "(%s) %s" % [msg.source.to_s.gsub("%", ""), line.gsub("%", '%%') ] ) end end end end Puppet::Util::Log.newdesttype :file do require 'fileutils' def self.match?(obj) Puppet::Util.absolute_path?(obj) end def close if defined?(@file) @file.close @file = nil end end def flush @file.flush if defined?(@file) end attr_accessor :autoflush def initialize(path) @name = path # first make sure the directory exists # We can't just use 'Config.use' here, because they've # specified a "special" destination. unless FileTest.exist?(File.dirname(path)) FileUtils.mkdir_p(File.dirname(path), :mode => 0755) Puppet.info "Creating log directory #{File.dirname(path)}" end # create the log file, if it doesn't already exist file = File.open(path, File::WRONLY|File::CREAT|File::APPEND) @file = file @autoflush = Puppet[:autoflush] end def handle(msg) @file.puts("#{msg.time} #{msg.source} (#{msg.level}): #{msg}") @file.flush if @autoflush end end Puppet::Util::Log.newdesttype :console do require 'puppet/util/colors' include Puppet::Util::Colors - def initialize - # Flush output immediately. - $stdout.sync = true - end - - def handle(msg) - if msg.source == "Puppet" - puts colorize(msg.level, "#{msg.level}: #{msg}") - else - puts colorize(msg.level, "#{msg.level}: #{msg.source}: #{msg}") - end - end -end - -Puppet::Util::Log.newdesttype :telly_prototype_console do - require 'puppet/util/colors' - include Puppet::Util::Colors - def initialize # Flush output immediately. $stderr.sync = true $stdout.sync = true end def handle(msg) error_levels = { :warning => 'Warning', :err => 'Error', :alert => 'Alert', :emerg => 'Emergency', :crit => 'Critical' } str = msg.respond_to?(:multiline) ? msg.multiline : msg.to_s + str = msg.source == "Puppet" ? str : "#{msg.source}: #{str}" case msg.level when *error_levels.keys $stderr.puts colorize(:hred, "#{error_levels[msg.level]}: #{str}") when :info $stdout.puts "#{colorize(:green, 'Info')}: #{str}" when :debug $stdout.puts "#{colorize(:cyan, 'Debug')}: #{str}" else $stdout.puts str end end end Puppet::Util::Log.newdesttype :host do def initialize(host) Puppet.info "Treating #{host} as a hostname" args = {} if host =~ /:(\d+)/ args[:Port] = $1 args[:Server] = host.sub(/:\d+/, '') else args[:Server] = host end @name = host @driver = Puppet::Network::Client::LogClient.new(args) end def handle(msg) unless msg.is_a?(String) or msg.remote @hostname ||= Facter["hostname"].value unless defined?(@domain) @domain = Facter["domain"].value @hostname += ".#{@domain}" if @domain end if Puppet::Util.absolute_path?(msg.source) msg.source = @hostname + ":#{msg.source}" elsif msg.source == "Puppet" msg.source = @hostname + " #{msg.source}" else msg.source = @hostname + " #{msg.source}" end begin #puts "would have sent #{msg}" #puts "would have sent %s" % # CGI.escape(YAML.dump(msg)) begin tmp = CGI.escape(YAML.dump(msg)) rescue => detail puts "Could not dump: #{detail}" return end # Add the hostname to the source @driver.addlog(tmp) rescue => detail Puppet.log_exception(detail) Puppet::Util::Log.close(self) end end end end # Log to a transaction report. Puppet::Util::Log.newdesttype :report do attr_reader :report match "Puppet::Transaction::Report" def initialize(report) @report = report end def handle(msg) @report << msg end end # Log to an array, just for testing. module Puppet::Test class LogCollector def initialize(logs) @logs = logs end def <<(value) @logs << value end end end Puppet::Util::Log.newdesttype :array do match "Puppet::Test::LogCollector" def initialize(messages) @messages = messages end def handle(msg) @messages << msg end end Puppet::Util::Log.newdesttype :eventlog do def self.suitable?(obj) Puppet.features.eventlog? end def initialize @eventlog = Win32::EventLog.open("Application") end def to_native(level) case level when :debug,:info,:notice [Win32::EventLog::INFO, 0x01] when :warning [Win32::EventLog::WARN, 0x02] when :err,:alert,:emerg,:crit [Win32::EventLog::ERROR, 0x03] end end def handle(msg) native_type, native_id = to_native(msg.level) @eventlog.report_event( :source => "Puppet", :event_type => native_type, :event_id => native_id, :data => (msg.source and msg.source != 'Puppet' ? "#{msg.source}: " : '') + msg.to_s ) end def close if @eventlog @eventlog.close @eventlog = nil end end end diff --git a/spec/unit/application/facts_spec.rb b/spec/unit/application/facts_spec.rb index 00f79fb67..1c4e8321f 100755 --- a/spec/unit/application/facts_spec.rb +++ b/spec/unit/application/facts_spec.rb @@ -1,28 +1,28 @@ #!/usr/bin/env rspec require 'spec_helper' require 'puppet/application/facts' describe Puppet::Application::Facts do before :each do subject.command_line.stubs(:subcommand_name).returns 'facts' end it "should fail if no key is given to find" do subject.command_line.stubs(:args).returns %w{find} expect { expect { subject.run }.to exit_with 1 - }.to have_printed /err: puppet facts find takes 1 argument, but you gave 0/ + }.to have_printed /Error: puppet facts find takes 1 argument, but you gave 0/ @logs.first.to_s.should =~ /puppet facts find takes 1 argument, but you gave 0/ end it "should return facts if a key is given to find" do Puppet::Node::Facts.indirection.reset_terminus_class subject.command_line.stubs(:args).returns %w{find whatever --render-as yaml} expect { expect { subject.run }.to exit_with 0 }.should have_printed(/object:Puppet::Node::Facts/) @logs.should be_empty end end diff --git a/spec/unit/util/log/destinations_spec.rb b/spec/unit/util/log/destinations_spec.rb index b44b77762..7903803ed 100755 --- a/spec/unit/util/log/destinations_spec.rb +++ b/spec/unit/util/log/destinations_spec.rb @@ -1,168 +1,149 @@ #!/usr/bin/env ruby -S rspec require 'spec_helper' require 'puppet/util/log' describe Puppet::Util::Log.desttypes[:report] do before do @dest = Puppet::Util::Log.desttypes[:report] end it "should require a report at initialization" do @dest.new("foo").report.should == "foo" end it "should send new messages to the report" do report = mock 'report' dest = @dest.new(report) report.expects(:<<).with("my log") dest.handle "my log" end end describe Puppet::Util::Log.desttypes[:file] do include PuppetSpec::Files before do File.stubs(:open) # prevent actually creating the file @class = Puppet::Util::Log.desttypes[:file] end it "should default to autoflush false" do @class.new(tmpfile('log')).autoflush.should == true end describe "when matching" do shared_examples_for "file destination" do it "should match an absolute path" do @class.match?(abspath).should be_true end it "should not match a relative path" do @class.match?(relpath).should be_false end end describe "on POSIX systems", :as_platform => :posix do let (:abspath) { '/tmp/log' } let (:relpath) { 'log' } it_behaves_like "file destination" end describe "on Windows systems", :as_platform => :windows do let (:abspath) { 'C:\\temp\\log.txt' } let (:relpath) { 'log.txt' } it_behaves_like "file destination" end end end describe Puppet::Util::Log.desttypes[:syslog] do let (:klass) { Puppet::Util::Log.desttypes[:syslog] } # these tests can only be run when syslog is present, because # we can't stub the top-level Syslog module describe "when syslog is available", :if => Puppet.features.syslog? do before :each do Syslog.stubs(:opened?).returns(false) Syslog.stubs(:const_get).returns("LOG_KERN").returns(0) Syslog.stubs(:open) end it "should open syslog" do Syslog.expects(:open) klass.new end it "should close syslog" do Syslog.expects(:close) dest = klass.new dest.close end it "should send messages to syslog" do syslog = mock 'syslog' syslog.expects(:info).with("don't panic") Syslog.stubs(:open).returns(syslog) msg = Puppet::Util::Log.new(:level => :info, :message => "don't panic") dest = klass.new dest.handle(msg) end end describe "when syslog is unavailable" do it "should not be a suitable log destination" do Puppet.features.stubs(:syslog?).returns(false) klass.suitable?(:syslog).should be_false end end end describe Puppet::Util::Log.desttypes[:console] do + let (:klass) { Puppet::Util::Log.desttypes[:console] } + describe "when color is available" do before :each do subject.stubs(:console_has_color?).returns(true) end it "should support color output" do Puppet[:color] = true subject.colorize(:red, 'version').should == "\e[0;31mversion\e[0m" end it "should withhold color output when not appropriate" do Puppet[:color] = false subject.colorize(:red, 'version').should == "version" end it "should handle multiple overlapping colors in a stack-like way" do Puppet[:color] = true vstring = subject.colorize(:red, 'version') subject.colorize(:green, "(#{vstring})").should == "\e[0;32m(\e[0;31mversion\e[0;32m)\e[0m" end it "should handle resets in a stack-like way" do Puppet[:color] = true vstring = subject.colorize(:reset, 'version') subject.colorize(:green, "(#{vstring})").should == "\e[0;32m(\e[mversion\e[0;32m)\e[0m" end - end -end - -describe Puppet::Util::Log.desttypes[:telly_prototype_console] do - describe "when color is available" do - before :each do - subject.stubs(:console_has_color?).returns(true) - end - it "should support color output" do - Puppet[:color] = true - subject.colorize(:red, 'version').should == "\e[0;31mversion\e[0m" - end - - it "should withhold color output when not appropriate" do + it "should include the log message's source/context in the output when available" do Puppet[:color] = false - subject.colorize(:red, 'version').should == "version" - end - - it "should handle multiple overlapping colors in a stack-like way" do - Puppet[:color] = true - vstring = subject.colorize(:red, 'version') - subject.colorize(:green, "(#{vstring})").should == "\e[0;32m(\e[0;31mversion\e[0;32m)\e[0m" - end + $stdout.expects(:puts).with("Info: a hitchhiker: don't panic") - it "should handle resets in a stack-like way" do - Puppet[:color] = true - vstring = subject.colorize(:reset, 'version') - subject.colorize(:green, "(#{vstring})").should == "\e[0;32m(\e[mversion\e[0;32m)\e[0m" + msg = Puppet::Util::Log.new(:level => :info, :message => "don't panic", :source => "a hitchhiker") + dest = klass.new + dest.handle(msg) end end end