diff --git a/acceptance/tests/allow_symlinks_as_config_directories.rb b/acceptance/tests/allow_symlinks_as_config_directories.rb index 66c6ccca0..1f450fe25 100644 --- a/acceptance/tests/allow_symlinks_as_config_directories.rb +++ b/acceptance/tests/allow_symlinks_as_config_directories.rb @@ -1,27 +1,34 @@ test_name "Should allow symlinks to directories as configuration directories" -step "Create the test confdir with a link to it" -confdir = "/tmp/puppet_conf-directory-#{$$}" -conflink = "/tmp/puppet_conf-symlink-#{$$}" +agents.each do |agent| + if agent['platform'].include?('windows') + skip_test "Test not supported on this platform" + next + end -on agents, "rm -rf #{conflink} #{confdir}" + step "Create the test confdir with a link to it" + confdir = agent.tmpdir('puppet_conf-directory') + conflink = agent.tmpfile('puppet_conf-symlink') -on agents, "mkdir #{confdir}" -on agents, "ln -s #{confdir} #{conflink}" + on agent, "rm -rf #{conflink} #{confdir}" -create_remote_file agents, "#{confdir}/puppet.conf", < manifest do - assert_match("My certname is awesome_certname", stdout) -end + step "Run Puppet and ensure it used the conf file in the confdir" + on agent, puppet_apply("--confdir #{conflink}"), :stdin => manifest do + assert_match("My certname is awesome_certname", stdout) + end -step "Check that the symlink and confdir are unchanged" -on agents, "[ -L #{conflink} ]" -on agents, "[ -d #{confdir} ]" -on agents, "[ $(readlink #{conflink}) = #{confdir} ]" + step "Check that the symlink and confdir are unchanged" + on agent, "[ -L #{conflink} ]" + on agent, "[ -d #{confdir} ]" + on agent, "[ $(readlink #{conflink}) = #{confdir} ]" +end diff --git a/acceptance/tests/apply/classes/should_allow_param_undef_override.rb b/acceptance/tests/apply/classes/should_allow_param_undef_override.rb index a4f37cba1..39904dc0d 100755 --- a/acceptance/tests/apply/classes/should_allow_param_undef_override.rb +++ b/acceptance/tests/apply/classes/should_allow_param_undef_override.rb @@ -1,29 +1,36 @@ test_name "should allow overriding a parameter to undef in inheritence" -out = "/tmp/class_undef_override_out-#{$$}" +agents.each do |agent| + dir = agent.tmpdir('class_undef_override') + out = File.join(dir, 'class_undef_override_out') + source = File.join(dir, 'class_undef_override_test') + manifest = %Q{ class parent { file { 'test': path => '#{out}', - source => '/tmp/class_undef_override_test-#{$$}', + source => '#{source}', } } class child inherits parent { File['test'] { source => undef, content => 'hello new world!', } } include parent include child } -step "prepare the target file on all systems" -on(agents, "echo 'hello world!' > #{out}") -step "apply the manifest" -apply_manifest_on(agents, manifest) -step "verify the file content" -on(agents, "cat #{out}") do + step "prepare the target file on all systems" + on(agent, "echo 'hello world!' > #{out}") + step "apply the manifest" + apply_manifest_on(agent, manifest) + step "verify the file content" + on(agent, "cat #{out}") do fail_test "the file was not touched" if stdout.include? "hello world!" fail_test "the file was not updated" unless stdout.include? "hello new world" + end + + on(agent, "rm -rf #{dir}") end diff --git a/acceptance/tests/apply/virtual/should_realize.rb b/acceptance/tests/apply/virtual/should_realize.rb index fd32ad859..7dc2406cd 100755 --- a/acceptance/tests/apply/virtual/should_realize.rb +++ b/acceptance/tests/apply/virtual/should_realize.rb @@ -1,22 +1,25 @@ test_name "should realize" -out = "/tmp/hosts-#{Time.new.to_i}" -name = "test-#{Time.new.to_i}-host" + +agents.each do |agent| + out = agent.tmpfile('should_realize') + name = "test-#{Time.new.to_i}-host" manifest = %Q{ @host{'#{name}': ip=>'127.0.0.2', target=>'#{out}', ensure=>present} realize(Host['#{name}']) } -step "clean the system ready for testing" -on agents, "rm -f #{out}" + step "clean the system ready for testing" + on agent, "rm -f #{out}" -step "realize the resource on the hosts" -apply_manifest_on agents, manifest + step "realize the resource on the host" + apply_manifest_on agent, manifest -step "verify the content of the file" -on(agents, "cat #{out}") do + step "verify the content of the file" + on(agent, "cat #{out}") do fail_test "missing host definition" unless stdout.include? name -end + end -step "final cleanup of the system" -on agents, "rm -f #{out}" + step "final cleanup of the system" + on agent, "rm -f #{out}" +end diff --git a/acceptance/tests/apply/virtual/should_realize_complex_query.rb b/acceptance/tests/apply/virtual/should_realize_complex_query.rb index 9782bbfac..512b5cbfc 100755 --- a/acceptance/tests/apply/virtual/should_realize_complex_query.rb +++ b/acceptance/tests/apply/virtual/should_realize_complex_query.rb @@ -1,36 +1,39 @@ test_name "should realize with complex query" -out = "/tmp/hosts-#{Time.new.to_i}" -name = "test-#{Time.new.to_i}-host" + +agents.each do |agent| + out = agent.tmpfile('should_realize_complex_query') + name = "test-#{Time.new.to_i}-host" manifest = %Q{ @host { '#{name}1': ip => '127.0.0.2', target => '#{out}', host_aliases => ['one', 'two', 'three'], ensure => present, } @host { '#{name}2': ip => '127.0.0.3', target => '#{out}', host_aliases => 'two', ensure => present, } Host<| host_aliases == 'two' and ip == '127.0.0.3' |> } -step "clean up target system for test" -on agents, "rm -f #{out}" + step "clean up target system for test" + on agent, "rm -f #{out}" -step "run the manifest" -apply_manifest_on agents, manifest + step "run the manifest" + apply_manifest_on agent, manifest -step "verify the file output" -on(agents, "cat #{out}") do + step "verify the file output" + on(agent, "cat #{out}") do fail_test "second host not found in output" unless stdout.include? "#{name}2" fail_test "first host was found in output" if stdout.include? "#{name}1" -end + end -step "clean up system after testing" -on agents, "rm -f #{out}" + step "clean up system after testing" + on agent, "rm -f #{out}" +end diff --git a/acceptance/tests/apply/virtual/should_realize_many.rb b/acceptance/tests/apply/virtual/should_realize_many.rb index 8f53caefe..80cf3f580 100755 --- a/acceptance/tests/apply/virtual/should_realize_many.rb +++ b/acceptance/tests/apply/virtual/should_realize_many.rb @@ -1,22 +1,24 @@ test_name "test that realize function takes a list" -out = "/tmp/hosts-#{Time.new.to_i}" -name = "test-#{Time.new.to_i}-host" + +agents.each do |agent| + out = agent.tmpfile('should_realize_many') + name = "test-#{Time.new.to_i}-host" manifest = %Q{ @host{'#{name}1': ip=>'127.0.0.2', target=>'#{out}', ensure=>present} @host{'#{name}2': ip=>'127.0.0.2', target=>'#{out}', ensure=>present} realize(Host['#{name}1'], Host['#{name}2']) } + step "clean up target system for test" + on agent, "rm -f #{out}" -step "clean up target system for test" -on agents, "rm -f #{out}" - -step "run the manifest" -apply_manifest_on agents, manifest + step "run the manifest" + apply_manifest_on agent, manifest -step "verify the file output" -on(agents, "cat #{out}") do + step "verify the file output" + on(agent, "cat #{out}") do fail_test "first host not found in output" unless stdout.include? "#{name}1" fail_test "second host not found in output" unless stdout.include? "#{name}2" + end end diff --git a/acceptance/tests/apply/virtual/should_realize_query.rb b/acceptance/tests/apply/virtual/should_realize_query.rb index 24d323373..ae1ff3eb3 100755 --- a/acceptance/tests/apply/virtual/should_realize_query.rb +++ b/acceptance/tests/apply/virtual/should_realize_query.rb @@ -1,24 +1,27 @@ test_name "should realize query" -out = "/tmp/hosts-#{Time.new.to_i}" -name = "test-#{Time.new.to_i}-host" + +agents.each do |agent| + out = agent.tmpfile('should_realize_query') + name = "test-#{Time.new.to_i}-host" manifest = %Q{ @host { '#{name}': ip => '127.0.0.2', target => '#{out}', host_aliases => 'alias', ensure => present, } Host<| ip == '127.0.0.2' |> } -step "clean up target system for test" -on agents, "rm -f #{out}" + step "clean up target system for test" + on agent, "rm -f #{out}" -step "run the manifest" -apply_manifest_on agents, manifest + step "run the manifest" + apply_manifest_on agent, manifest -step "verify the file output" -on(agents, "cat #{out}") do + step "verify the file output" + on(agent, "cat #{out}") do fail_test "host not found in output" unless stdout.include? name + end end diff --git a/acceptance/tests/apply/virtual/should_realize_query_array.rb b/acceptance/tests/apply/virtual/should_realize_query_array.rb index 137d93b1a..c2fa8f6ea 100755 --- a/acceptance/tests/apply/virtual/should_realize_query_array.rb +++ b/acceptance/tests/apply/virtual/should_realize_query_array.rb @@ -1,24 +1,27 @@ test_name "should realize query array" -out = "/tmp/hosts-#{Time.new.to_i}" -name = "test-#{Time.new.to_i}-host" + +agents.each do |agent| + out = agent.tmpfile('should_realize_query_array') + name = "test-#{Time.new.to_i}-host" manifest = %Q{ @host { '#{name}': ip => '127.0.0.2', target => '#{out}', host_aliases => ['one', 'two', 'three'], ensure => present, } Host<| host_aliases == 'two' |> } -step "clean up target system for test" -on agents, "rm -f #{out}" + step "clean up target system for test" + on agent, "rm -f #{out}" -step "run the manifest" -apply_manifest_on agents, manifest + step "run the manifest" + apply_manifest_on agent, manifest -step "verify the file output" -on(agents, "cat #{out}") do + step "verify the file output" + on(agent, "cat #{out}") do fail_test "host not found in output" unless stdout.include? name + end end diff --git a/acceptance/tests/file_hello_world.rb b/acceptance/tests/file_hello_world.rb index 683ff4672..b64ddd717 100644 --- a/acceptance/tests/file_hello_world.rb +++ b/acceptance/tests/file_hello_world.rb @@ -1,22 +1,23 @@ # Verify that a trivial manifest can be run to completion. - -filename = "/tmp/hello-world.txt" -content = "Hello, World" -manifest = "file { '#{filename}': content => '#{content}' }" - test_name "The challenging 'Hello, World' manifest" -step "ensure we are clean before testing..." -on agents, "rm -f #{filename}" +agents.each do |agent| + filename = agent.tmpfile('hello-world.txt') + content = "Hello, World" + manifest = "file { '#{filename}': content => '#{content}' }" -step "run the manifest itself" -apply_manifest_on(agents, manifest) do - fail_test "the expected notice of action was missing" unless - stdout.index 'File[/tmp/hello-world.txt]/ensure: defined content as' -end + step "ensure we are clean before testing..." + on(agent, "rm -f #{filename}") -step "verify the content of the generated files." -on agents, "grep '#{content}' #{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" + end -step "clean up after our test run." -on agents, "rm -f #{filename}" + 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/language/resource_refs_with_nested_arrays.rb b/acceptance/tests/language/resource_refs_with_nested_arrays.rb index 7bc797885..ead35a3f5 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" -test_manifest = < "echo the first command", - path => "/usr/bin:/bin", + command => "#{agent.echo('the first command')}", + path => "#{agent.path}", logoutput => true, } exec { "second": - command => "echo the second command", - path => "/usr/bin:/bin", + command => "#{agent.echo('the second command')}", + path => "#{agent.path}", logoutput => true, } exec { "third": - command => "echo the final command", - path => "/usr/bin:/bin", + command => "#{agent.echo('the final command')}", + path => "#{agent.path}", logoutput => true, require => Exec[$exec_names], } MANIFEST -results = apply_manifest_on agents, test_manifest - -results.each do |result| - assert_match(/Exec\[third\].*the final command/, "#{result.stdout}") + apply_manifest_on agent, test_manifest do + assert_match(/Exec\[third\].*the final command/, "#{stdout}") + end end diff --git a/acceptance/tests/puppet_apply_a_file_should_create_a_file_and_report_the_md5.rb b/acceptance/tests/puppet_apply_a_file_should_create_a_file_and_report_the_md5.rb index 44338520a..0358d1195 100644 --- a/acceptance/tests/puppet_apply_a_file_should_create_a_file_and_report_the_md5.rb +++ b/acceptance/tests/puppet_apply_a_file_should_create_a_file_and_report_the_md5.rb @@ -1,17 +1,17 @@ test_name "puppet apply should create a file and report an MD5" -file = "/tmp/hello.world.#{Time.new.to_i}.txt" -manifest = "file{'#{file}': content => 'test'}" +agents.each do |agent| + file = agent.tmpfile('hello-world') + manifest = "file{'#{file}': content => 'test'}" -step "clean up #{file} for testing" -on agents, "rm -f #{file}" + step "clean up #{file} for testing" + on(agent, "rm -f #{file}") -step "Run the manifest and verify MD5 was printed" -agents.each do |host| - apply_manifest_on(host, manifest) do - assert_match(/defined content as '{md5}098f6bcd4621d373cade4e832627b4f6'/, stdout, "#{host}: didn't find the content MD5 on output") + step "Run the manifest and verify MD5 was printed" + apply_manifest_on(agent, manifest) do + assert_match(/defined content as '{md5}098f6bcd4621d373cade4e832627b4f6'/, stdout, "#{agent}: didn't find the content MD5 on output") end -end -step "clean up #{file} after testing" -on agents, "rm -f #{file}" + step "clean up #{file} after testing" + on(agent, "rm -f #{file}") +end diff --git a/acceptance/tests/resource/cron/should_create_cron.rb b/acceptance/tests/resource/cron/should_create_cron.rb index d40228070..0e48e4640 100644 --- a/acceptance/tests/resource/cron/should_create_cron.rb +++ b/acceptance/tests/resource/cron/should_create_cron.rb @@ -1,29 +1,34 @@ test_name "should create cron" 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 }" 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 step "apply the resource on the host using puppet resource" on(host, puppet_resource("cron", "crontest", "user=#{tmpuser}", "command=/bin/true", "ensure=present")) do assert_match(/created/, stdout, "Did not create crontab for #{tmpuser} on #{host}") end step "verify that crontab -l contains what you expected" run_cron_on(host, :list, tmpuser) do assert_match(/\* \* \* \* \* \/bin\/true/, stdout, "Incorrect crontab 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/cron/should_match_existing.rb b/acceptance/tests/resource/cron/should_match_existing.rb index 92e7dc2cc..d4af8a9ea 100755 --- a/acceptance/tests/resource/cron/should_match_existing.rb +++ b/acceptance/tests/resource/cron/should_match_existing.rb @@ -1,32 +1,37 @@ test_name "puppet should match existing job" 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 }" 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 step "Create the existing cron 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=present")) do assert_match(/present/, stdout, "Failed creating crontab for #{tmpuser} on #{host}") end step "Verify that crontab -l contains what you expected" run_cron_on(host, :list, tmpuser) do assert_match(/\* \* \* \* \* \/bin\/true/, stdout, "Did not find crontab 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/cron/should_remove_cron.rb b/acceptance/tests/resource/cron/should_remove_cron.rb index 78afde4c3..051a4fcd7 100755 --- a/acceptance/tests/resource/cron/should_remove_cron.rb +++ b/acceptance/tests/resource/cron/should_remove_cron.rb @@ -1,32 +1,37 @@ 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 }" 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 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}") 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/cron/should_remove_matching.rb b/acceptance/tests/resource/cron/should_remove_matching.rb index bbfea349e..23dba7afe 100755 --- a/acceptance/tests/resource/cron/should_remove_matching.rb +++ b/acceptance/tests/resource/cron/should_remove_matching.rb @@ -1,35 +1,40 @@ test_name "puppet should remove a crontab entry based on command matching" tmpuser = "pl#{rand(999999).to_i}" tmpfile = "/tmp/cron-test-#{Time.new.to_i}" cron = '# Puppet Name: crontest\n* * * * * /bin/true\n1 1 1 1 1 /bin/true\n' create_user = "user { '#{tmpuser}': ensure => present, managehome => false }" delete_user = "user { '#{tmpuser}': ensure => absent, managehome => false }" 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 step "create the existing job by hand..." run_cron_on(host,:add,tmpuser,"* * * * * /bin/true") step "Remove cron resource" on(host, puppet_resource("cron", "bogus", "user=#{tmpuser}", "command=/bin/true", "ensure=absent")) do assert_match(/bogus\D+ensure: removed/, stdout, "Removing cron entry failed for #{tmpuser} on #{host}") end step "verify that crontab -l contains what you expected" run_cron_on(host,:list,tmpuser) do count = stdout.scan("/bin/true").length fail_test "found /bin/true the wrong number of times (#{count})" unless count == 0 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/cron/should_update_existing.rb b/acceptance/tests/resource/cron/should_update_existing.rb index b37952a63..1fa9cd9bb 100755 --- a/acceptance/tests/resource/cron/should_update_existing.rb +++ b/acceptance/tests/resource/cron/should_update_existing.rb @@ -1,37 +1,42 @@ test_name "puppet should update existing crontab entry" 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 }" 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 step "create the existing job by hand..." run_cron_on(host,:add,tmpuser,"* * * * * /bin/true") step "verify that crontab -l contains what you expected" run_cron_on(host,:list,tmpuser) do assert_match(/\* \* \* \* \* \/bin\/true/, stdout, "Didn't find correct crobtab entry for #{tmpuser} on #{host}") end step "apply the resource change on the host" on(host, puppet_resource("cron", "crontest", "user=#{tmpuser}", "command=/bin/true", "ensure=present", "hour='0-6'")) do assert_match(/hour\s+=>\s+\['0-6'\]/, stdout, "Modifying cron entry failed for #{tmpuser} on #{host}") end step "verify that crontab -l contains what you expected" run_cron_on(host,:list,tmpuser) do assert_match(/\* 0-6 \* \* \* \/bin\/true/, stdout, "Didn't find correctly modified time entry in crobtab 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/exec/accept_multi-line_commands.rb b/acceptance/tests/resource/exec/accept_multi-line_commands.rb index 1e9aaf15f..dafd86c05 100644 --- a/acceptance/tests/resource/exec/accept_multi-line_commands.rb +++ b/acceptance/tests/resource/exec/accept_multi-line_commands.rb @@ -1,24 +1,32 @@ test_name "Be able to execute multi-line commands (#9996)" -temp_file_name = "/tmp/9996-multi-line-commands.#{$$}" -test_manifest = < "/bin/echo '#Test' > #{temp_file_name}; /bin/echo 'bob' >> #{temp_file_name};" } HERE -expected_results = < '/bin/touch #{donottouch}', creates => "#{touch}"} + exec { "test#{Time.new.to_i}": command => '#{agent.touch(donottouch)}', creates => "#{touch}"} } -step "prepare the agents for the test" -on agents, "touch #{touch} ; rm -f #{donottouch}" + step "prepare the agents for the test" + on agent, "touch #{touch} && rm -f #{donottouch}" -step "test using puppet apply" -apply_manifest_on(agents, manifest) do + step "test using puppet apply" + apply_manifest_on(agent, manifest) do fail_test "looks like the thing executed, which it shouldn't" if - stdout.include? 'executed successfully' -end + stdout.include? 'executed successfully' + end -step "verify the file didn't get created" -on agents, "test -f #{donottouch}", :acceptable_exit_codes => [1] + step "verify the file didn't get created" + on agent, "test -f #{donottouch}", :acceptable_exit_codes => [1] -step "prepare the agents for the second part of the test" -on agents, "touch #{touch} ; rm -f #{donottouch}" + step "prepare the agents for the second part of the test" + on agent, "touch #{touch} ; rm -f #{donottouch}" -step "test using puppet resource" -on(agents, puppet_resource('exec', "test#{Time.new.to_i}", - "command='/bin/touch #{donottouch}'", - "creates='#{touch}'")) do + step "test using puppet resource" + on(agent, puppet_resource('exec', "test#{Time.new.to_i}", + "command='#{agent.touch(donottouch)}'", + "creates='#{touch}'")) do fail_test "looks like the thing executed, which it shouldn't" if - stdout.include? 'executed successfully' -end + stdout.include? 'executed successfully' + end -step "verify the file didn't get created the second time" -on agents, "test -f #{donottouch}", :acceptable_exit_codes => [1] + step "verify the file didn't get created the second time" + on agent, "test -f #{donottouch}", :acceptable_exit_codes => [1] +end diff --git a/acceptance/tests/resource/exec/should_run_command.rb b/acceptance/tests/resource/exec/should_run_command.rb index b7156c6c9..4a76cc4f3 100644 --- a/acceptance/tests/resource/exec/should_run_command.rb +++ b/acceptance/tests/resource/exec/should_run_command.rb @@ -1,31 +1,38 @@ test_name "tests that puppet correctly runs an exec." # original author: Dan Bode --daniel 2010-12-23 -$touch = "/tmp/test-exec-#{Time.new.to_i}" - -def before - step "file to be touched should not exist." - on agents, "rm -f #{$touch}" +def before(agent) + step "file to be touched should not exist." + touched = agent.tmpfile('test-exec') end -def after - step "checking the output worked" - on agents, "test -f #{$touch}" +def after(agent, touched) + step "checking the output worked" + on agent, "test -f #{touched}" - step "clean up the system" - on agents, "rm -f #{$touch}" + step "clean up the system" + on agent, "rm -f #{touched}" end -before -apply_manifest_on(agents, "exec {'test': command=>'/bin/touch #{$touch}'}") do +agents.each do |agent| + if agent['platform'].include?('windows') + Log.warn('Pending due to #11740') + next + end + + touched = before(agent) + apply_manifest_on(agent, "exec {'test': command=>'#{agent.touch(touched)}'}") do fail_test "didn't seem to run the command" unless - stdout.include? 'executed successfully' -end -after + stdout.include? 'executed successfully' + end + after(agent, touched) -before -on(agents, puppet_resource('-d', 'exec', 'test', "command='/bin/touch #{$touch}'")) do + touched = before(agent) + on(agent, puppet_resource('-d', 'exec', 'test', "command='#{agent.touch(touched)}'}")) do fail_test "didn't seem to run the command" unless - stdout.include? 'executed successfully' + stdout.include? 'executed successfully' + end + after(agent, touched) end -after + + diff --git a/acceptance/tests/resource/exec/should_set_path.rb b/acceptance/tests/resource/exec/should_set_path.rb index 4d9ccb060..e1b5aa09d 100644 --- a/acceptance/tests/resource/exec/should_set_path.rb +++ b/acceptance/tests/resource/exec/should_set_path.rb @@ -1,16 +1,18 @@ test_name "the path statement should work to locate commands" -file = "/tmp/touched-should-set-path-#{Time.new.to_i}" +agents.each do |agent| + file = agent.tmpfile('touched-should-set-path') -step "clean up the system for the test" -on agents, "rm -f #{file}" + step "clean up the system for the test" + on agent, "rm -f #{file}" -step "invoke the exec resource with a path set" -on(agents, puppet_resource('exec', 'test', - "command='touch #{file}'", 'path="/bin:/usr/bin"')) + step "invoke the exec resource with a path set" + on(agent, puppet_resource('exec', 'test', + "command='#{agent.touch(file, false)}'", "path='#{agent.path}'")) -step "verify that the files were created" -on agents, "test -f #{file}" + step "verify that the files were created" + on agent, "test -f #{file}" -step "clean up the system after testing" -on agents, "rm -f #{file}" + step "clean up the system after testing" + on agent, "rm -f #{file}" +end diff --git a/acceptance/tests/resource/file/content_attribute.rb b/acceptance/tests/resource/file/content_attribute.rb index 31dbac151..768cdb059 100644 --- a/acceptance/tests/resource/file/content_attribute.rb +++ b/acceptance/tests/resource/file/content_attribute.rb @@ -1,52 +1,51 @@ test_name "Content Attribute" -step "Ensure the test environment is clean" -on agents, 'rm -f /tmp/content_file_test.txt' +agents.each do |agent| + target = agent.tmpfile('content_file_test') + + step "Ensure the test environment is clean" + on agent, "rm -f #{target}" -step "Content Attribute: using raw content" + step "Content Attribute: using raw content" -manifest = "file { '/tmp/content_file_test.txt': content => 'This is the test file content', ensure => present }" -apply_manifest_on agents, manifest + manifest = "file { '#{target}': content => 'This is the test file content', ensure => present }" + apply_manifest_on agent, manifest -agents.each do |host| - on host, "cat /tmp/content_file_test.txt" do - assert_match(/This is the test file content/, stdout, "File content not matched on #{host}") + on agent, "cat #{target}" do + assert_match(/This is the test file content/, stdout, "File content not matched on #{agent}") end -end -step "Ensure the test environment is clean" -on agents, 'rm -f /tmp/content_file_test.txt' + step "Ensure the test environment is clean" + on agent, "rm -f #{target}" -step "Content Attribute: using a checksum from filebucket" -on agents, "echo 'This is the checksum file contents' > /tmp/checksum_test_file.txt" -step "Backup file into the filebucket" -on agents, puppet_filebucket("backup --local /tmp/checksum_test_file.txt") + step "Content Attribute: using a checksum from filebucket" + on agent, "echo 'This is the checksum file contents' > #{target}" + + step "Backup file into the filebucket" + on agent, puppet_filebucket("backup --local #{target}") -agents.each do |agent| bucketdir="not set" - on agent, puppet_filebucket("--configprint bucketdir") do + on agent, puppet_filebucket("--configprint bucketdir") do bucketdir = stdout.chomp end manifest = %Q| filebucket { 'local': path => '#{bucketdir}', } - file { '/tmp/content_file_test.txt': + file { '#{target}': content => '{md5}18571d3a04b2bb7ccfdbb2c44c72caa9', ensure => present, backup => local, } | - step "Applying Manifest on Agents" + step "Applying Manifest on Agent" apply_manifest_on agent, manifest -end -step "Validate filebucket checksum file contents" -agents.each do |host| - on host, "cat /tmp/content_file_test.txt" do - assert_match(/This is the checksum file content/, stdout, "File content not matched on #{host}") + step "Validate filebucket checksum file contents" + on agent, "cat #{target}" do + assert_match(/This is the checksum file content/, stdout, "File content not matched on #{agent}") end end diff --git a/acceptance/tests/resource/file/should_create_directory.rb b/acceptance/tests/resource/file/should_create_directory.rb index 37ad9dbf8..ebe8441cb 100755 --- a/acceptance/tests/resource/file/should_create_directory.rb +++ b/acceptance/tests/resource/file/should_create_directory.rb @@ -1,15 +1,17 @@ test_name "should create directory" -target = "/tmp/test-#{Time.new.to_i}" +agents.each do |agent| + target = agent.tmpfile("create-dir") -step "clean up the system before we begin" -on agents, "rm -rf #{target}" + step "clean up the system before we begin" + on(agent, "rm -rf #{target}") -step "verify we can create a directory" -on(agents, puppet_resource("file", target, 'ensure=directory')) + step "verify we can create a directory" + on(agent, puppet_resource("file", target, 'ensure=directory')) -step "verify the directory was created" -on agents, "test -d #{target}" + step "verify the directory was created" + on(agent, "test -d #{target}") -step "clean up after the test run" -on agents, "rm -rf #{target}" + step "clean up after the test run" + on(agent, "rm -rf #{target}") +end diff --git a/acceptance/tests/resource/file/should_create_empty.rb b/acceptance/tests/resource/file/should_create_empty.rb index e9d9d8e27..4c16c06aa 100755 --- a/acceptance/tests/resource/file/should_create_empty.rb +++ b/acceptance/tests/resource/file/should_create_empty.rb @@ -1,15 +1,17 @@ test_name "should create empty file for 'present'" -target = "/tmp/test-#{Time.new.to_i}" +agents.each do |agent| + target = agent.tmpfile("empty") -step "clean up the system before we begin" -on agents, "rm -rf #{target}" + step "clean up the system before we begin" + on(agent, "rm -rf #{target}") -step "verify we can create an empty file" -on(agents, puppet_resource("file", target, 'ensure=present')) + step "verify we can create an empty file" + on(agent, puppet_resource("file", target, 'ensure=present')) -step "verify the target was created" -on agents, "test -f #{target} && test ! -s #{target}" + step "verify the target was created" + on(agent, "test -f #{target} && test ! -s #{target}") -step "clean up after the test run" -on agents, "rm -rf #{target}" + step "clean up after the test run" + on(agent, "rm -rf #{target}") +end diff --git a/acceptance/tests/resource/file/should_create_symlink.rb b/acceptance/tests/resource/file/should_create_symlink.rb index 81fe4b4e3..0721bb29f 100755 --- a/acceptance/tests/resource/file/should_create_symlink.rb +++ b/acceptance/tests/resource/file/should_create_symlink.rb @@ -1,28 +1,35 @@ test_name "should create symlink" message = 'hello world' target = "/tmp/test-#{Time.new.to_i}" source = "/tmp/test-#{Time.new.to_i}-source" -step "clean up the system before we begin" -on agents, "rm -rf #{target}" -on agents, "echo '#{message}' > #{source}" +agents.each do |agent| + if agent['platform'].include?('windows') + skip_test "Test not supported on this platform" + next + end -step "verify we can create a symlink" -on(agents, puppet_resource("file", target, "ensure=#{source}")) + step "clean up the system before we begin" + on agent, "rm -rf #{target}" + on agent, "echo '#{message}' > #{source}" -step "verify the symlink was created" -on agents, "test -L #{target} && test -f #{target}" -step "verify source file" -on agents, "test -f #{source}" + step "verify we can create a symlink" + on(agent, puppet_resource("file", target, "ensure=#{source}")) -step "verify the content is identical on both sides" -on(agents, "cat #{source}") do + step "verify the symlink was created" + on agent, "test -L #{target} && test -f #{target}" + step "verify source file" + on agent, "test -f #{source}" + + step "verify the content is identical on both sides" + on(agent, "cat #{source}") do fail_test "source missing content" unless stdout.include? message -end -on(agents, "cat #{target}") do + end + on(agent, "cat #{target}") do fail_test "target missing content" unless stdout.include? message -end + end -step "clean up after the test run" -on agents, "rm -rf #{target} #{source}" + step "clean up after the test run" + on agent, "rm -rf #{target} #{source}" +end diff --git a/acceptance/tests/resource/file/should_remove_dir.rb b/acceptance/tests/resource/file/should_remove_dir.rb index 36fa1adee..ca8a003bb 100755 --- a/acceptance/tests/resource/file/should_remove_dir.rb +++ b/acceptance/tests/resource/file/should_remove_dir.rb @@ -1,21 +1,23 @@ test_name "should remove directory, but force required" -target = "/tmp/test-#{Time.new.to_i}" +agents.each do |agent| + target = agent.tmpdir("delete-dir") -step "clean up the system before we begin" -on agents, "rm -rf #{target} ; mkdir -p #{target}" + step "clean up the system before we begin" + on agent, "rm -rf #{target} ; mkdir -p #{target}" -step "verify we can't remove a directory without 'force'" -on(agents, puppet_resource("file", target, 'ensure=absent')) do + step "verify we can't remove a directory without 'force'" + on(agent, puppet_resource("file", target, 'ensure=absent')) do fail_test "didn't tell us that force was required" unless - stdout.include? "Not removing directory; use 'force' to override" -end + stdout.include? "Not removing directory; use 'force' to override" + end -step "verify the directory still exists" -on agents, "test -d #{target}" + step "verify the directory still exists" + on agent, "test -d #{target}" -step "verify we can remove a directory with 'force'" -on(agents, puppet_resource("file", target, 'ensure=absent', 'force=true')) + step "verify we can remove a directory with 'force'" + on(agent, puppet_resource("file", target, 'ensure=absent', 'force=true')) -step "verify that the directory is gone" -on agents, "test -d #{target}", :acceptable_exit_codes => [1] + step "verify that the directory is gone" + on agent, "test -d #{target}", :acceptable_exit_codes => [1] +end diff --git a/acceptance/tests/resource/file/should_remove_file.rb b/acceptance/tests/resource/file/should_remove_file.rb index aadb82971..60cf63251 100755 --- a/acceptance/tests/resource/file/should_remove_file.rb +++ b/acceptance/tests/resource/file/should_remove_file.rb @@ -1,12 +1,14 @@ test_name "should remove file" -target = "/tmp/test-#{Time.new.to_i}" +agents.each do |agent| + target = agent.tmpfile('delete-file') -step "clean up the system before we begin" -on agents, "rm -rf #{target} && touch #{target}" + step "clean up the system before we begin" + on agent, "rm -rf #{target} && touch #{target}" -step "verify we can remove a file" -on(agents, puppet_resource("file", target, 'ensure=absent')) + step "verify we can remove a file" + on(agent, puppet_resource("file", target, 'ensure=absent')) -step "verify that the file is gone" -on agents, "test -e #{target}", :acceptable_exit_codes => [1] + step "verify that the file is gone" + on agent, "test -e #{target}", :acceptable_exit_codes => [1] +end diff --git a/acceptance/tests/resource/file/source_attribtute.rb b/acceptance/tests/resource/file/source_attribtute.rb index 3fa447a8a..5308cb38b 100644 --- a/acceptance/tests/resource/file/source_attribtute.rb +++ b/acceptance/tests/resource/file/source_attribtute.rb @@ -1,106 +1,109 @@ test_name "The source attribute" -step "Ensure the test environment is clean" -on agents, 'rm -f /tmp/source_file_test.txt' +agents.each do |agent| + target = agent.tmpfile('source_file_test') + + step "Ensure the test environment is clean" + on agent, "rm -f #{target}" # TODO: Add tests for puppet:// URIs with master/agent setups. # step "when using a puppet:/// URI with a master/agent setup" # step "when using a puppet://$server/ URI with a master/agent setup" -step "Using a local file path" -on agents, "echo 'Yay, this is the local file.' > /tmp/local_source_file_test.txt" -manifest = "file { '/tmp/source_file_test.txt': source => '/tmp/local_source_file_test.txt', ensure => present }" + step "Using a local file path" + source = agent.tmpfile('local_source_file_test') + on agent, "echo 'Yay, this is the local file.' > #{source}" -apply_manifest_on agents, manifest -agents.each do |host| - on host, "cat /tmp/source_file_test.txt" do - assert_match(/Yay, this is the local file./, stdout, "FIRST: File contents not matched on #{host}") + manifest = "file { '#{target}': source => '#{source}', ensure => present }" + apply_manifest_on agent, manifest + on agent, "cat #{target}" do + assert_match(/Yay, this is the local file./, stdout, "FIRST: File contents not matched on #{agent}") end -end - -step "Ensure the test environment is clean" -on agents, 'rm -f /tmp/source_file_test.txt' -step "Using a puppet:/// URI with puppet apply" + step "Ensure the test environment is clean" + on agent, "rm -f #{target}" -on agents, puppet_agent("--configprint modulepath") do - modulepath = stdout.split(':')[0] - modulepath = modulepath.chomp - on agents, "mkdir -p #{modulepath}/test_module/files" - #on agents, "echo 'Yay, this is the puppet:/// file.' > #{modulepath}/test_module/files/test_file.txt" - on agents, "echo 'Yay, this is the puppetfile.' > #{modulepath}/test_module/files/test_file.txt" -end + step "Using a puppet:/// URI with puppet apply" + on agent, puppet_agent("--configprint modulepath") do + modulepath = agent.path_split(stdout)[0] + modulepath = modulepath.chomp + on agent, "mkdir -p '#{modulepath}/test_module/files'" + #on agent, "echo 'Yay, this is the puppet:/// file.' > #{modulepath}/test_module/files/test_file.txt" + on agent, "echo 'Yay, this is the puppetfile.' > '#{modulepath}/test_module/files/test_file.txt'" + end -on agents, %q{echo "file { '/tmp/source_file_test.txt': source => 'puppet:///modules/test_module/test_file.txt', ensure => present }" > /tmp/source_test_manifest.pp} -on agents, puppet_apply("/tmp/source_test_manifest.pp") + manifest = "file { '#{target}': source => 'puppet:///modules/test_module/test_file.txt', ensure => present }" + apply_manifest_on agent, manifest -agents.each do |host| - on host, "cat /tmp/source_file_test.txt" do - assert_match(/Yay, this is the puppetfile./, stdout, "SECOND: File contents not matched on #{host}") + on agent, "cat #{target}" do + assert_match(/Yay, this is the puppetfile./, stdout, "SECOND: File contents not matched on #{agent}") end + + step "Cleanup" + on agent, "rm -f #{target}; rm -rf #{source}" end # Oops. We (Jesse & Jacob) ended up writing this before realizing that you # can't actually specify "source => 'http://...'". However, we're leaving it # here, since there have been feature requests to support doing this. # -- Mon, 07 Mar 2011 16:12:56 -0800 # #step "Ensure the test environment is clean" #on agents, 'rm -f /tmp/source_file_test.txt' # #step "when using an http:// file path" # #File.open '/tmp/puppet-acceptance-webrick-script.rb', 'w' do |file| # file.puts %q{#!/usr/bin/env ruby # #require 'webrick' # #class Simple < WEBrick::HTTPServlet::AbstractServlet # def do_GET(request, response) # status, content_type, body = do_stuff_with(request) # # response.status = status # response['Content-Type'] = content_type # response.body = body # end # # def do_stuff_with(request) # return 200, "text/plain", "you got a page" # end #end # #class SimpleTwo < WEBrick::HTTPServlet::AbstractServlet # def do_GET(request, response) # status, content_type, body = do_stuff_with(request) # # response.status = status # response['Content-Type'] = content_type # response.body = body # end # # def do_stuff_with(request) # return 200, "text/plain", "you got a different page" # end #end # #server = WEBrick::HTTPServer.new :Port => 8081 #trap "INT" do server.shutdown end #trap "TERM" do server.shutdown end #trap "QUIT" do server.shutdown end # #server.mount "/", SimpleTwo #server.mount "/foo.txt", Simple #server.start #} #end # #scp_to master, '/tmp/puppet-acceptance-webrick-script.rb', '/tmp' #on master, "chmod +x /tmp/puppet-acceptance-webrick-script.rb && /tmp/puppet-acceptance-webrick-script.rb &" # #manifest = "file { '/tmp/source_file_test.txt': source => 'http://#{master}:8081/foo.txt', ensure => present }" # #apply_manifest_on agents, manifest # #on agents, 'test "$(cat /tmp/source_file_test.txt)" = "you got a page"' # #on master, "killall puppet-acceptance-webrick-script.rb" diff --git a/acceptance/tests/resource/file/symbolic_modes.rb b/acceptance/tests/resource/file/symbolic_modes.rb index 3d088eebc..46c61ca35 100644 --- a/acceptance/tests/resource/file/symbolic_modes.rb +++ b/acceptance/tests/resource/file/symbolic_modes.rb @@ -1,115 +1,114 @@ test_name "file resource: symbolic modes" def validate(path, mode) "ruby -e 'exit (File::Stat.new(#{path.inspect}).mode & 0777 == #{mode})'" end -def tmpfile(what) - "/tmp/symbolic-mode-#{what}-" + - "#{Time.now.strftime("%Y%m%d")}-#{$$}-" + - "#{rand(0x100000000).to_s(36)}.test" -end +agents.each do |agent| + if agent['platform'].include?('windows') + Log.warn("Pending: this does not currently work on Windows") + next + end -# Generate some standard, remote-safe names for our scratch content, and make -# sure that they exist already. Don't need to care about modes or owners, as -# we reset anything that matters inside the test loop. -file = tmpfile('file') -dir = tmpfile('dir') + user = agent['user'] + group = agent['group'] || user + file = agent.tmpfile('symbolic-mode-file') + dir = agent.tmpdir('symbolic-mode-dir') -on agents, "touch #{file} ; mkdir #{dir}" + on(agent, "touch #{file} ; mkdir -p #{dir}") # Infrastructure for a nice, table driven test. Yum. # # For your reference: # 4000 the set-user-ID-on-execution bit # 2000 the set-group-ID-on-execution bit # 1000 the sticky bit # 0400 Allow read by owner. # 0200 Allow write by owner. # 0100 For files, allow execution by owner. For directories, allow the # owner to search in the directory. # 0040 Allow read by group members. # 0020 Allow write by group members. # 0010 For files, allow execution by group members. For directories, allow # group members to search in the directory. # 0004 Allow read by others. # 0002 Allow write by others. # 0001 For files, allow execution by others. For directories allow others # to search in the directory. # # fields are: start_mode, symbolic_mode, file_mode, dir_mode # start_mode is passed to chmod on the target platform # symbolic_mode is the mode set in our test # the file and dir mode values are the numeric resultant values we should get tests = < [1]) do - assert_match(%r{Listing all file instances is not supported. Please specify a file or directory, e.g. puppet resource file /etc}, stderr) -end + 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}, stderr) + end -["/", "/etc"].each do |file| - step "query '#{file}' directory, which should return single entry" - on(agents, puppet_resource('file', file)) do - files = stdout.scan(/^file \{ '([^']+)'/).flatten + ["/", "/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") + assert_equal(1, files.size, "puppet returned multiple files: #{files.join(', ')}") + assert_match(file, files[0], "puppet did not return file") + end end -end -step "query file that does not exist, which should report the file is absent" -on(agents, puppet_resource('file', '/this/does/notexist')) do - assert_match(/ensure\s+=>\s+'absent'/, stdout) -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(agents, "rm -f #{target}") + step "remove UNIX domain socket" + on(agent, "rm -f #{target}") +end diff --git a/acceptance/tests/resource/group/should_create.rb b/acceptance/tests/resource/group/should_create.rb index efb80a4bc..16a74c7dd 100755 --- a/acceptance/tests/resource/group/should_create.rb +++ b/acceptance/tests/resource/group/should_create.rb @@ -1,20 +1,17 @@ -test_name "should create group" +test_name "should create a group" name = "pl#{rand(999999).to_i}" -def cleanup(name) - step "remove group #{name} if it exists" - on agents, "if getent group #{name}; then groupdel #{name}; fi" -end +agents.each do |agent| + step "ensure the group does not exist" + agent.group_absent(name) -cleanup(name) + step "create the group" + on agent, puppet_resource('group', name, 'ensure=present') -step "create the group #{name} with the resource agent" -on(agents, puppet_resource('group', name, 'ensure=present')) + step "verify the group exists" + agent.group_get(name) -step "verify the group #{name} was created" -on(agents, "getent group #{name}") do - fail_test "group information is not sensible" unless stdout =~ /^#{name}:.*:[0-9]+:/ + step "delete the group" + agent.group_absent(name) end - -cleanup(name) diff --git a/acceptance/tests/resource/group/should_destroy.rb b/acceptance/tests/resource/group/should_destroy.rb index 1551abe75..6b887579f 100755 --- a/acceptance/tests/resource/group/should_destroy.rb +++ b/acceptance/tests/resource/group/should_destroy.rb @@ -1,14 +1,14 @@ test_name "should destroy a group" -name = "test-group-#{Time.new.to_i}" +name = "pl#{rand(999999).to_i}" -step "ensure the group exists on the target system" -on agents, "getent group #{name} || groupadd #{name}" +agents.each do |agent| + step "ensure the group is present" + agent.group_present(name) -step "use puppet to remove the group" -on(agents, puppet_resource('group', name, 'ensure=absent')) + step "delete the group" + on agent, puppet_resource('group', name, 'ensure=absent') -step "verify that the group has been removed" -# REVISIT: I /think/ that exit code 2 is standard across Linux, but I have no -# idea what non-Linux platforms are going to return. --daniel 2010-12-24 -on agents, "getent group #{name}", :acceptable_exit_codes => [2] + step "verify the group was deleted" + agent.group_absent(name) +end diff --git a/acceptance/tests/resource/group/should_modify_gid.rb b/acceptance/tests/resource/group/should_modify_gid.rb index b54d40118..65e9a1f95 100755 --- a/acceptance/tests/resource/group/should_modify_gid.rb +++ b/acceptance/tests/resource/group/should_modify_gid.rb @@ -1,24 +1,31 @@ test_name "should modify gid of existing group" name = "pl#{rand(999999).to_i}" gid1 = rand(999999).to_i gid2 = rand(999999).to_i -step "ensure that the group exists with gid #{gid1}" -on(agents, puppet_resource('group', name, 'ensure=present', "gid=#{gid1}")) do +agents.each do |agent| + if agent['platform'].include?('windows') + skip_test "Test not supported on this platform" + next + end + + step "ensure that the group exists with gid #{gid1}" + on(agent, puppet_resource('group', name, 'ensure=present', "gid=#{gid1}")) do fail_test "missing gid notice" unless stdout =~ /gid +=> +'#{gid1}'/ -end + end -step "ensure that we can modify the GID of the group to #{gid2}" -on(agents, puppet_resource('group', name, 'ensure=present', "gid=#{gid2}")) do + step "ensure that we can modify the GID of the group to #{gid2}" + on(agent, puppet_resource('group', name, 'ensure=present', "gid=#{gid2}")) do fail_test "missing gid notice" unless stdout =~ /gid +=> +'#{gid2}'/ -end + end -step "verify that the GID changed" -on(agents, "getent group #{name}") do + step "verify that the GID changed" + on(agent, "getent group #{name}") do fail_test "gid is wrong through getent output" unless - stdout =~ /^#{name}:.*:#{gid2}:/ -end + stdout =~ /^#{name}:.*:#{gid2}:/ + end -step "clean up the system after the test run" -on(agents, puppet_resource('group', name, 'ensure=absent')) + step "clean up the system after the test run" + on(agent, puppet_resource('group', name, 'ensure=absent')) +end diff --git a/acceptance/tests/resource/group/should_not_create_existing.rb b/acceptance/tests/resource/group/should_not_create_existing.rb index ed4f54cdc..351ca0c74 100755 --- a/acceptance/tests/resource/group/should_not_create_existing.rb +++ b/acceptance/tests/resource/group/should_not_create_existing.rb @@ -1,15 +1,17 @@ test_name "group should not create existing group" name = "test-group-#{Time.new.to_i}" -step "ensure the group exists on the target node" -on(agents, puppet_resource('group', name, 'ensure=present')) +agents.each do |agent| + step "ensure the group exists on the target node" + agent.group_present(name) -step "verify that we don't try and create the existing group" -on(agents, puppet_resource('group', name, 'ensure=present')) do + step "verify that we don't try and create the existing group" + on(agent, puppet_resource('group', name, 'ensure=present')) do fail_test "looks like we created the group" if - stdout.include? '/Group[bozo]/ensure: created' -end + stdout.include? "/Group[#{name}]/ensure: created" + end -step "clean up the system after the test run" -on(agents, puppet_resource('group', name, 'ensure=absent')) + step "clean up the system after the test run" + agent.group_absent(name) +end diff --git a/acceptance/tests/resource/group/should_not_destoy_unexisting.rb b/acceptance/tests/resource/group/should_not_destoy_unexisting.rb index 256a8f146..287bb0fa6 100755 --- a/acceptance/tests/resource/group/should_not_destoy_unexisting.rb +++ b/acceptance/tests/resource/group/should_not_destoy_unexisting.rb @@ -1,13 +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" -on(agents, puppet_resource('group', name, 'ensure=absent')) +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" + fail_test "it looks like we tried to remove the group" if + stdout.include? "notice: /Group[#{name}]/ensure: removed" end diff --git a/acceptance/tests/resource/group/should_query.rb b/acceptance/tests/resource/group/should_query.rb index 3bbce071c..12da6ea1a 100755 --- a/acceptance/tests/resource/group/should_query.rb +++ b/acceptance/tests/resource/group/should_query.rb @@ -1,15 +1,16 @@ -test_name "group should query" +test_name "test that we can query and find a group that exists." -name = "test-group-#{Time.new.to_i}" +name = "pl#{rand(999999).to_i}" -step "ensure the group exists on the target systems" -on agents, "getent group #{name} || groupadd #{name}" +agents.each do |agent| + step "ensure that our test group exists" + agent.group_present(name) -step "ensure that the resource agent sees the group" -on(agents, puppet_resource('group', name)) do - fail_test "missing group identifier" unless stdout.include? "group { '#{name}':" - fail_test "missing present attributed" unless stdout.include? "ensure => 'present'" -end + step "query for the resource and verify it was found" + on(agent, puppet_resource('group', name)) do + fail_test "didn't find the group #{name}" unless stdout.include? 'present' + end -step "clean up the system after the test" -on(agents, puppet_resource('group', name, 'ensure=absent')) + step "clean up the group we added" + agent.group_absent(name) +end diff --git a/acceptance/tests/resource/group/should_query_all.rb b/acceptance/tests/resource/group/should_query_all.rb index 9abcfed21..87ce781a8 100755 --- a/acceptance/tests/resource/group/should_query_all.rb +++ b/acceptance/tests/resource/group/should_query_all.rb @@ -1,30 +1,23 @@ -test_name "puppet resource should query all groups" +test_name "should query all groups" -agents.each do |host| - groups = {} +agents.each do |agent| + step "query natively" + groups = agent.group_list - step "collect the list of groups on #{host} with getent group" - on(host, "getent group") do - stdout.each_line do |line| groups[line[/^[^:]+/]] = 'getent' end - end + fail_test("No groups found") unless groups - step "collect the list of groups on #{host} with puppet resource" - on(host, puppet_resource('group')) do - stdout.each_line do |line| - match = line.match(/^group \{ '([^']+)'/) - if match then - name = match[1] + step "query with puppet" + on(agent, puppet_resource('group')) do + stdout.each_line do |line| + name = ( line.match(/^group \{ '([^']+)'/) or next )[1] - if groups.include? name then - groups.delete name - else - fail_test "group #{name} found by puppet, not getent" - end - end - end + unless groups.delete(name) + fail_test "group #{name} found by puppet, not natively" + end end + end - groups.keys.each do |name| - fail_test "group #{name} found by getent, not puppet" - end + if groups.length > 0 then + fail_test "#{groups.length} groups found natively, not puppet: #{groups.join(', ')}" + end end diff --git a/acceptance/tests/resource/host/should_create.rb b/acceptance/tests/resource/host/should_create.rb index f5c0a17a5..6ad807f4e 100755 --- a/acceptance/tests/resource/host/should_create.rb +++ b/acceptance/tests/resource/host/should_create.rb @@ -1,15 +1,17 @@ test_name "host should create" -target = "/tmp/host-#{Time.new.to_i}" +agents.each do |agent| + target = agent.tmpfile('host-create') -step "clean up for the test" -on agents, "rm -f #{target}" + step "clean up for the test" + on agent, "rm -f #{target}" -step "create the host record" -on(agents, puppet_resource("host", "test", "ensure=present", + step "create the host record" + on(agent, puppet_resource("host", "test", "ensure=present", "ip=127.0.0.1", "target=#{target}")) -step "verify that the record was created" -on(agents, "cat #{target} ; rm -f #{target}") do + step "verify that the record was created" + on(agent, "cat #{target} ; rm -f #{target}") do fail_test "record was not present" unless stdout =~ /^127\.0\.0\.1[[:space:]]+test/ + end end diff --git a/acceptance/tests/resource/host/should_create_aliases.rb b/acceptance/tests/resource/host/should_create_aliases.rb index 71e92aef9..91031e6be 100755 --- a/acceptance/tests/resource/host/should_create_aliases.rb +++ b/acceptance/tests/resource/host/should_create_aliases.rb @@ -1,16 +1,18 @@ test_name "host should create aliases" -target = "/tmp/host-#{Time.new.to_i}" +agents.each do |agent| + target = agent.tmpfile('host-create-aliases') -step "clean up the system for testing" -on agents, "rm -f #{target}" + step "clean up the system for testing" + on agent, "rm -f #{target}" -step "create the record" -on(agents, puppet_resource('host', 'test', "ensure=present", + step "create the record" + on(agent, puppet_resource('host', 'test', "ensure=present", "ip=127.0.0.7", "target=#{target}", "host_aliases=alias")) -step "verify that the aliases were added" -on(agents, "cat #{target} ; rm -f #{target}") do + step "verify that the aliases were added" + on(agent, "cat #{target} ; rm -f #{target}") do fail_test "alias was missing" unless - stdout =~ /^127\.0\.0\.7[[:space:]]+test[[:space:]]alias/ + stdout =~ /^127\.0\.0\.7[[:space:]]+test[[:space:]]alias/ + end end diff --git a/acceptance/tests/resource/host/should_destroy.rb b/acceptance/tests/resource/host/should_destroy.rb index 69c74b824..75e8166b3 100755 --- a/acceptance/tests/resource/host/should_destroy.rb +++ b/acceptance/tests/resource/host/should_destroy.rb @@ -1,19 +1,21 @@ test_name "should be able to remove a host record" -file = "/tmp/hosts-#{Time.new.to_i}" -line = "127.0.0.7 test1" +agents.each do |agent| + file = agent.tmpfile('host-destroy') + line = "127.0.0.7 test1" -step "set up files for the test" -on agents, "printf '#{line}\n' > #{file}" + step "set up files for the test" + on agent, "printf '#{line}\n' > #{file}" -step "delete the resource from the file" -on(agents, puppet_resource('host', 'test1', "target=#{file}", + step "delete the resource from the file" + on(agent, puppet_resource('host', 'test1', "target=#{file}", 'ensure=absent', 'ip=127.0.0.7')) -step "verify that the content was removed" -on(agents, "cat #{file}; rm -f #{file}") do + step "verify that the content was removed" + on(agent, "cat #{file}; rm -f #{file}") do fail_test "the content was still present" if stdout.include? line -end + end -step "clean up after the test" -on agents, "rm -f #{file}" + step "clean up after the test" + on agent, "rm -f #{file}" +end diff --git a/acceptance/tests/resource/host/should_modify_alias.rb b/acceptance/tests/resource/host/should_modify_alias.rb index 1ebbf3339..df3ceb8ab 100755 --- a/acceptance/tests/resource/host/should_modify_alias.rb +++ b/acceptance/tests/resource/host/should_modify_alias.rb @@ -1,19 +1,21 @@ test_name "should be able to modify a host alias" -file = "/tmp/hosts-#{Time.new.to_i}" +agents.each do |agent| + file = agent.tmpfile('host-modify-alias') -step "set up files for the test" -on agents, "printf '127.0.0.8 test alias\n' > #{file}" + step "set up files for the test" + on agent, "printf '127.0.0.8 test alias\n' > #{file}" -step "modify the resource" -on(agents, puppet_resource('host', 'test', "target=#{file}", + step "modify the resource" + on(agent, puppet_resource('host', 'test', "target=#{file}", 'ensure=present', 'ip=127.0.0.8', 'host_aliases=banzai')) -step "verify that the content was updated" -on(agents, "cat #{file}; rm -f #{file}") do + step "verify that the content was updated" + on(agent, "cat #{file}; rm -f #{file}") do fail_test "the alias was not updated" unless - stdout =~ /^127\.0\.0\.8[[:space:]]+test[[:space:]]+banzai[[:space:]]*$/ -end + stdout =~ /^127\.0\.0\.8[[:space:]]+test[[:space:]]+banzai[[:space:]]*$/ + end -step "clean up after the test" -on agents, "rm -f #{file}" + step "clean up after the test" + on agent, "rm -f #{file}" +end diff --git a/acceptance/tests/resource/host/should_modify_ip.rb b/acceptance/tests/resource/host/should_modify_ip.rb index cf3c3f12d..75eee018b 100755 --- a/acceptance/tests/resource/host/should_modify_ip.rb +++ b/acceptance/tests/resource/host/should_modify_ip.rb @@ -1,19 +1,21 @@ test_name "should be able to modify a host address" -file = "/tmp/hosts-#{Time.new.to_i}" +agents.each do |agent| + file = agent.tmpfile('host-modify-ip') -step "set up files for the test" -on agents, "printf '127.0.0.9 test alias\n' > #{file}" + step "set up files for the test" + on agent, "printf '127.0.0.9 test alias\n' > #{file}" -step "modify the resource" -on(agents, puppet_resource('host', 'test', "target=#{file}", + step "modify the resource" + on(agent, puppet_resource('host', 'test', "target=#{file}", 'ensure=present', 'ip=127.0.0.10', 'host_aliases=alias')) -step "verify that the content was updated" -on(agents, "cat #{file}; rm -f #{file}") do + step "verify that the content was updated" + on(agent, "cat #{file}; rm -f #{file}") do fail_test "the address was not updated" unless - stdout =~ /^127\.0\.0\.10[[:space:]]+test[[:space:]]+alias[[:space:]]*$/ -end + stdout =~ /^127\.0\.0\.10[[:space:]]+test[[:space:]]+alias[[:space:]]*$/ + end -step "clean up after the test" -on agents, "rm -f #{file}" + step "clean up after the test" + on agent, "rm -f #{file}" +end diff --git a/acceptance/tests/resource/host/should_not_create_existing.rb b/acceptance/tests/resource/host/should_not_create_existing.rb index a8f902286..2f2161cf2 100755 --- a/acceptance/tests/resource/host/should_not_create_existing.rb +++ b/acceptance/tests/resource/host/should_not_create_existing.rb @@ -1,17 +1,18 @@ test_name "should not create host if it exists" -file = "/tmp/hosts-#{Time.new.to_i}" +agents.each do |agent| + file = agent.tmpfile('host-not-create-existing') -step "set up the system for the test" -on agents, "printf '127.0.0.2 test alias\n' > #{file}" + 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(agents, puppet_resource('host', 'test', "target=#{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' -end - -step "clean up after we created things" -on agents, "rm -f #{file}" + stdout.include? 'notice: /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/should_query.rb b/acceptance/tests/resource/host/should_query.rb index 76f84e498..a01889a9a 100755 --- a/acceptance/tests/resource/host/should_query.rb +++ b/acceptance/tests/resource/host/should_query.rb @@ -1,15 +1,17 @@ test_name "should query hosts out of a hosts file" -file = "/tmp/hosts-#{Time.new.to_i}" +agents.each do |agent| + file = agent.tmpfile('host-query') -step "set up the system for the test" -on agents, "printf '127.0.0.1 localhost.local localhost\n' > #{file}" + step "set up the system for the test" + on agent, "printf '127.0.0.1 localhost.local localhost\n' > #{file}" -step "fetch the list of hosts from puppet" -on(agents, puppet_resource('host', 'localhost', "target=#{file}")) do + step "fetch the list of hosts from puppet" + on(agent, puppet_resource('host', 'localhost', "target=#{file}")) do found = stdout.scan('present').length fail_test "found #{found} hosts, not 1" if found != 1 -end + end -step "clean up the system" -on agents, "rm -f #{file}" + step "clean up the system" + on agent, "rm -f #{file}" +end diff --git a/acceptance/tests/resource/host/should_query_all.rb b/acceptance/tests/resource/host/should_query_all.rb index bf1f1b89a..24eb438c6 100755 --- a/acceptance/tests/resource/host/should_query_all.rb +++ b/acceptance/tests/resource/host/should_query_all.rb @@ -1,26 +1,28 @@ test_name "should query all hosts from hosts file" content = %q{127.0.0.1 test1 test1.local 127.0.0.2 test2 test2.local 127.0.0.3 test3 test3.local 127.0.0.4 test4 test4.local } -backup = "/tmp/hosts.backup-#{Time.new.to_i}" +agents.each do |agent| + backup = agent.tmpfile('host-query-all') -step "configure the system for testing (including file backups)" -on agents, "cp /etc/hosts #{backup}" -on agents, "cat > /etc/hosts", :stdin => content + step "configure the system for testing (including file backups)" + on agent, "cp /etc/hosts #{backup}" + on agent, "cat > /etc/hosts", :stdin => content -step "query all host records using puppet" -on(agents, puppet_resource('host')) do + step "query all host records using puppet" + on(agent, puppet_resource('host')) do found = stdout.scan(/host \{ '([^']+)'/).flatten.sort fail_test "the list of returned hosts was wrong: #{found.join(', ')}" unless - found == %w{test1 test2 test3 test4} + found == %w{test1 test2 test3 test4} count = stdout.scan(/ensure\s+=>\s+'present'/).length fail_test "found #{count} records, wanted 4" unless count == 4 -end + end -step "clean up the system afterwards" -on agents, "mv -f #{backup} /etc/hosts" + step "clean up the system afterwards" + on agent, "mv -f #{backup} /etc/hosts" +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 9223da665..392678434 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,21 +1,23 @@ test_name "#4131: should not create host without IP attribute" -file = "/tmp/hosts-#{Time.new.to_i}" +agents.each do |agent| + file = agent.tmpfile('4131-require-ip') -step "configure the target system for the test" -on agents, "rm -vrf #{file} ; touch #{file}" + 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(agents, puppet_resource('host', 'test', "target=#{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' -end + stdout.include? 'ip is a required attribute for hosts' + end -step "verify that the host was not added to the file" -on(agents, "cat #{file} ; rm -f #{file}") do + 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/resource/tidy/should_remove_old_files.rb b/acceptance/tests/resource/tidy/should_remove_old_files.rb index 63af8a846..cb1430ff1 100644 --- a/acceptance/tests/resource/tidy/should_remove_old_files.rb +++ b/acceptance/tests/resource/tidy/should_remove_old_files.rb @@ -1,34 +1,37 @@ test_name "Tidying files by date" -step "Create a directory of old and new files" +agents.each do |agent| + step "Create a directory of old and new files" + dir = agent.tmpdir('tidy-test') + on agent, "mkdir -p #{dir}" -dir = "/tmp/tidy-test-#{$$}" -on agents, "mkdir -p #{dir}" -# YYMMddhhmm, so 03:04 Jan 2 1970 -old = %w[one two three four five] -new = %w[a b c d e] -on agents, "touch -t 7001020304 #{dir}/{#{old.join(',')}}" -on agents, "touch #{dir}/{#{new.join(',')}}" + # YYMMddhhmm, so 03:04 Jan 2 1970 + old = %w[one two three four five] + new = %w[a b c d e] -step "Run a tidy resource to remove the old files" + on agent, "touch -t 7001020304 #{dir}/{#{old.join(',')}}" + on agent, "touch #{dir}/{#{new.join(',')}}" + + step "Run a tidy resource to remove the old files" manifest = <<-MANIFEST tidy { "#{dir}": age => '1d', recurse => true, } MANIFEST -apply_manifest_on agents, manifest + apply_manifest_on agent, manifest -step "Ensure the old files are gone" + step "Ensure the old files are gone" -old_test = old.map {|name| "-f #{File.join(dir, name)}"}.join(' -o ') + old_test = old.map {|name| "-f #{File.join(dir, name)}"}.join(' -o ') -on agents, "[ #{old_test} ]", :acceptable_exit_codes => [1] + on agent, "[ #{old_test} ]", :acceptable_exit_codes => [1] -step "Ensure the new files are still present" + step "Ensure the new files are still present" -new_test = new.map {|name| "-f #{File.join(dir, name)}"}.join(' -a ') + new_test = new.map {|name| "-f #{File.join(dir, name)}"}.join(' -a ') -on agents, "[ #{new_test} ]" + on agent, "[ #{new_test} ]" +end diff --git a/acceptance/tests/resource/user/should_create.rb b/acceptance/tests/resource/user/should_create.rb index 0b2b0c65f..4889c062f 100755 --- a/acceptance/tests/resource/user/should_create.rb +++ b/acceptance/tests/resource/user/should_create.rb @@ -1,24 +1,26 @@ -test_name "should create a user, and the default matching group" +test_name "should create a user" name = "pl#{rand(999999).to_i}" -step "ensure that the user and group #{name} do not exist" -on agents, "if getent passwd #{name}; then userdel #{name}; fi" -on agents, "if getent group #{name}; then groupdel #{name}; fi" +agents.each do |agent| + step "ensure the user and group do not exist" + agent.user_absent(name) + agent.group_absent(name) -step "ask puppet to create the user" -on(agents, puppet_resource('user', name, 'ensure=present')) + step "create the user" + on agent, puppet_resource('user', name, 'ensure=present') -step "verify that the user and group now exist" -agents.each do |agent| - if agent['platform'].include? 'sles' or agent['platform'].include? 'solaris' # no private user groups by default - on agent, "getent passwd #{name}" + step "verify the user exists" + agent.user_get(name) + + case agent['platform'] + when /sles/, /solaris/, /windows/ + # no private user groups by default else - on agent, "getent passwd #{name} && getent group #{name}" + agent.group_get(name) end -end - -step "ensure that the user and group #{name} do not exist" -on agents, "if getent passwd #{name}; then userdel #{name}; fi" -on agents, "if getent group #{name}; then groupdel #{name}; fi" + step "delete the user, and group, if any" + agent.user_absent(name) + agent.group_absent(name) +end diff --git a/acceptance/tests/resource/user/should_create_with_gid.rb b/acceptance/tests/resource/user/should_create_with_gid.rb index c92d5c95d..0b9f00d64 100755 --- a/acceptance/tests/resource/user/should_create_with_gid.rb +++ b/acceptance/tests/resource/user/should_create_with_gid.rb @@ -1,30 +1,34 @@ test_name "verifies that puppet resource creates a user and assigns the correct group" user = "pl#{rand(999999).to_i}" group = "gp#{rand(999999).to_i}" agents.each do |host| + if host['platform'].include?('windows') + skip_test "Test not supported on this platform" + else step "user should not exist" on host, "if getent passwd #{user}; then userdel #{user}; fi" step "group should exist" on host, "getent group #{group} || groupadd #{group}" step "create user with group" on(host, puppet_resource('user', user, 'ensure=present', "gid=#{group}")) step "verify the group exists and find the gid" on(host, "getent group #{group}") do gid = stdout.split(':')[2] step "verify that the user has that as their gid" on(host, "getent passwd #{user}") do got = stdout.split(':')[3] fail_test "wanted gid #{gid} but found #{got}" unless gid == got end end step "clean up after the test is done" on(host, puppet_resource('user', user, 'ensure=absent')) on(host, puppet_resource('group', group, 'ensure=absent')) + end end diff --git a/acceptance/tests/resource/user/should_destroy.rb b/acceptance/tests/resource/user/should_destroy.rb index 655501231..73d73dbb7 100755 --- a/acceptance/tests/resource/user/should_destroy.rb +++ b/acceptance/tests/resource/user/should_destroy.rb @@ -1,19 +1,14 @@ -test_name "verify that puppet resource correctly destroys users" +test_name "should delete a user" -user = "pl#{rand(999999).to_i}" -group = user +name = "pl#{rand(999999).to_i}" -step "ensure that the user and associated group exist" -on(agents, puppet_resource('group', group, 'ensure=present')) -on(agents, puppet_resource('user', user, 'ensure=present', "gid=#{group}")) +agents.each do |agent| + step "ensure the user is present" + agent.user_present(name) -step "try and delete the user" -on(agents, puppet_resource('user', user, 'ensure=absent')) + step "delete the user" + on agent, puppet_resource('user', name, 'ensure=absent') -step "verify that the user is no longer present" -on(agents, "getent passwd #{user}", :acceptable_exit_codes => [2]) do - fail_test "found the user in the output" if stdout.include? "#{user}:" + step "verify the user was deleted" + agent.user_absent(name) end - -step "remove the group as well..." -on(agents, puppet_resource('group', group, 'ensure=absent')) diff --git a/acceptance/tests/resource/user/should_modify.rb b/acceptance/tests/resource/user/should_modify.rb new file mode 100644 index 000000000..24e901659 --- /dev/null +++ b/acceptance/tests/resource/user/should_modify.rb @@ -0,0 +1,20 @@ +test_name "should modify a user" + +name = "pl#{rand(999999).to_i}" + +agents.each do |agent| + step "ensure the user is present" + agent.user_present(name) + + step "modify the user" + on agent, puppet_resource('user', name, ["ensure=present", "comment=comment#{name}"]) + + step "verify the user was modified" + agent.user_get(name) do |result| + fail_test "didn't modify the user #{name}" unless result.stdout.include? "comment#{name}" + end + + step "delete the user" + agent.user_absent(name) + agent.group_absent(name) +end diff --git a/acceptance/tests/resource/user/should_modify_gid.rb b/acceptance/tests/resource/user/should_modify_gid.rb index d8bc60fc1..4c13dc40e 100755 --- a/acceptance/tests/resource/user/should_modify_gid.rb +++ b/acceptance/tests/resource/user/should_modify_gid.rb @@ -1,41 +1,45 @@ test_name "verify that we can modify the gid" user = "pl#{rand(99999).to_i}" group1 = "#{user}old" group2 = "#{user}new" agents.each do |host| + if host['platform'].include?('windows') + skip_test "Test not supported on this platform" + else step "ensure that the groups both exist" on(host, puppet_resource('group', group1, 'ensure=present')) on(host, puppet_resource('group', group2, 'ensure=present')) step "ensure the user exists and has the old group" on(host, puppet_resource('user', user, 'ensure=present', "gid=#{group1}")) step "verify that the user has the correct gid" on(host, "getent group #{group1}") do gid = stdout.split(':')[2] on(host, "getent passwd #{user}") do got = stdout.split(':')[3] fail_test "didn't have the expected old GID, but #{got}" unless got == gid end end step "modify the GID of the user" on(host, puppet_resource('user', user, 'ensure=present', "gid=#{group2}")) step "verify that the user has the updated gid" on(host, "getent group #{group2}") do gid = stdout.split(':')[2] on(host, "getent passwd #{user}") do got = stdout.split(':')[3] fail_test "didn't have the expected old GID, but #{got}" unless got == gid end end step "ensure that we remove the things we made" on(host, puppet_resource('user', user, 'ensure=absent')) on(host, puppet_resource('group', group1, 'ensure=absent')) on(host, puppet_resource('group', group2, 'ensure=absent')) + end end diff --git a/acceptance/tests/resource/user/should_not_create_existing.rb b/acceptance/tests/resource/user/should_not_create_existing.rb index 2f33a94df..994832284 100755 --- a/acceptance/tests/resource/user/should_not_create_existing.rb +++ b/acceptance/tests/resource/user/should_not_create_existing.rb @@ -1,6 +1,8 @@ test_name "tests that user resource will not add users that already exist." step "verify that we don't try to create a user account that already exists" -on(agents, puppet_resource('user', 'root', 'ensure=present')) do - fail_test "tried to create 'root' user" if stdout.include? 'created' +agents.each do |agent| + on(agent, puppet_resource('user', agent['user'], 'ensure=present')) do + fail_test "tried to create '#{agent['user']}' user" if stdout.include? 'created' + end end diff --git a/acceptance/tests/resource/user/should_not_destoy_unexisting.rb b/acceptance/tests/resource/user/should_not_destoy_unexisting.rb index 133d51395..5e6bcd2fa 100755 --- a/acceptance/tests/resource/user/should_not_destoy_unexisting.rb +++ b/acceptance/tests/resource/user/should_not_destoy_unexisting.rb @@ -1,11 +1,13 @@ test_name "ensure that puppet does not report removing a user that does not exist" name = "pl#{rand(999999).to_i}" step "verify that user #{name} does not exist" -on agents, "getent passwd #{name}", :acceptable_exit_codes => [2] +agents.each do |agent| + agent.user_absent(name) +end step "ensure absent doesn't try and do anything" on(agents, puppet_resource('user', name, 'ensure=absent')) do - fail_test "tried to remove the user, apparently" if stdout.include? 'removed' + fail_test "tried to remove the user, apparently" if stdout.include? 'removed' end diff --git a/acceptance/tests/resource/user/should_query.rb b/acceptance/tests/resource/user/should_query.rb index c976c878f..de9425b8a 100755 --- a/acceptance/tests/resource/user/should_query.rb +++ b/acceptance/tests/resource/user/should_query.rb @@ -1,15 +1,17 @@ test_name "test that we can query and find a user that exists." name = "pl#{rand(999999).to_i}" -step "ensure that our test user exists" -on(agents, puppet_resource('user', name, 'ensure=present')) +agents.each do |agent| + step "ensure that our test user exists" + agent.user_present(name) -step "query for the resource and verify it was found" -on(agents, puppet_resource('user', name)) do + step "query for the resource and verify it was found" + on(agent, puppet_resource('user', name)) do fail_test "didn't find the user #{name}" unless stdout.include? 'present' -end + end -step "clean up the user and group we added" -on(agents, puppet_resource('user', name, 'ensure=absent')) -on(agents, puppet_resource('group', name, 'ensure=absent')) + step "clean up the user and group we added" + agent.user_absent(name) + agent.group_absent(name) +end diff --git a/acceptance/tests/resource/user/should_query_all.rb b/acceptance/tests/resource/user/should_query_all.rb index 00d7b25c4..db7037cdd 100755 --- a/acceptance/tests/resource/user/should_query_all.rb +++ b/acceptance/tests/resource/user/should_query_all.rb @@ -1,30 +1,23 @@ -test_name "ensure that puppet queries the correct number of users" +test_name "should query all users" -agents.each do |host| - users = [] +agents.each do |agent| + step "query natively" + users = agent.user_list - step "collect the list of known users via getent" - on(host, "getent passwd") do - stdout.each_line do |line| - users << line.split(':')[0] - end - end + fail_test("No users found") unless users - step "collect the list of known users via puppet" - on(host, puppet_resource('user')) do - stdout.each_line do |line| - name = ( line.match(/^user \{ '([^']+)'/) or next )[1] + step "query with puppet" + on(agent, puppet_resource('user')) do + stdout.each_line do |line| + name = ( line.match(/^user \{ '([^']+)'/) or next )[1] - # OK: Was this name found in the list of users? - if users.member? name then - users.delete name - else - fail_test "user #{name} found by puppet, not by getent" - end - end + unless users.delete(name) + fail_test "user #{name} found by puppet, not natively" + end end + end - if users.length > 0 then - fail_test "#{users.length} users found with getent, not puppet: #{users.join(', ')}" - end + if users.length > 0 then + fail_test "#{users.length} users found natively, not puppet: #{users.join(', ')}" + end end diff --git a/acceptance/tests/stages/ticket_4655_default_stage_for_classes.rb b/acceptance/tests/stages/ticket_4655_default_stage_for_classes.rb index 1b0b537bf..be5a16746 100644 --- a/acceptance/tests/stages/ticket_4655_default_stage_for_classes.rb +++ b/acceptance/tests/stages/ticket_4655_default_stage_for_classes.rb @@ -1,39 +1,42 @@ test_name "#4655: Allow setting the default stage for parameterized classes" -temp_file_name = "/tmp/4655-stage-in-parameterized-class.#{$$}" +agents.each do |agent| + temp_file_name = agent.tmpfile('4655-stage-in-parameterized-class') test_manifest = < Stage[two] } stage { two: before => Stage[three] } stage { three: before => Stage[main] } class in_one { - exec { "echo 'in_one' > #{temp_file_name}": - path => '/usr/bin:/bin', + exec { "#{agent.echo('in_one', false)} > #{temp_file_name}": + path => '#{agent.path}', } } class { in_one: stage => "one" } class in_two( $stage=two ){ - exec { "echo 'in_two' >> #{temp_file_name}": - path => '/usr/bin:/bin', + exec { "#{agent.echo('in_two', false)} >> #{temp_file_name}": + path => '#{agent.path}', } } class { in_two: } class in_three { - exec { "echo 'in_three' >> #{temp_file_name}": - path => '/usr/bin:/bin', + exec { "#{agent.echo('in_three', false)} >> #{temp_file_name}": + path => '#{agent.path}', } } class { "in_three": stage => "three" } HERE -expected_results = "in_one + expected_results = "in_one in_two in_three " -apply_manifest_on agents, test_manifest + apply_manifest_on agent, test_manifest -on(agents, "cat #{temp_file_name}").each do |result| - assert_equal(expected_results, "#{result.stdout}", "Unexpected result for host '#{result.host}'") + on(agent, "cat #{temp_file_name}") do + # echo on windows adds \r\n, so do dotall regexp match + assert_match(/in_one\s*in_two\s*\in_three/m, stdout, "Unexpected result for host '#{agent}'") + end end diff --git a/acceptance/tests/ticket_3360_allow_duplicate_csr_with_option_set.rb b/acceptance/tests/ticket_3360_allow_duplicate_csr_with_option_set.rb index 005141e0a..08638d73a 100644 --- a/acceptance/tests/ticket_3360_allow_duplicate_csr_with_option_set.rb +++ b/acceptance/tests/ticket_3360_allow_duplicate_csr_with_option_set.rb @@ -1,45 +1,58 @@ test_name "#3360: Allow duplicate CSR when allow_duplicate_certs is on" agent_hostnames = agents.map {|a| a.to_s} with_master_running_on master, "--allow_duplicate_certs --dns_alt_names=\"puppet,$(hostname -s),$(hostname -f)\" --verbose --noop" do - step "Generate a certificate request for the agent" - on agents, "puppet certificate generate `hostname -f` --ca-location remote --server #{master}" + agents.each do |agent| + if agent['platform'].include?('windows') + Log.warn("Pending: Windows does not support hostname -f") + next + end + + step "Generate a certificate request for the agent" + on agent, "puppet certificate generate `hostname -f` --ca-location remote --server #{master}" + end step "Collect the original certs" on master, puppet_cert("--sign --all") original_certs = on master, puppet_cert("--list --all") old_certs = {} original_certs.stdout.each_line do |line| if line =~ /^\+ (\S+) \((.+)\)$/ old_certs[$1] = $2 puts "old cert: #{$1} #{$2}" end end - step "Make another request with the same certname" - on agents, "puppet certificate generate `hostname -f` --ca-location remote --server #{master}" + agents.each do |agent| + if agent['platform'].include?('windows') + Log.warn("Pending: Windows does not support hostname -f") + next + end - step "Collect the new certs" + step "Make another request with the same certname" + on agent, "puppet certificate generate `hostname -f` --ca-location remote --server #{master}" + end + step "Collect the new certs" on master, puppet_cert("--sign --all") new_cert_list = on master, puppet_cert("--list --all") new_certs = {} new_cert_list.stdout.each_line do |line| if line =~ /^\+ (\S+) \((.+)\)$/ new_certs[$1] = $2 puts "new cert: #{$1} #{$2}" end end step "Verify the certs have changed" # using the agent name as the key may cause errors; # agent name from cfg file is likely to have short name # where certs might be signed with long names. old_certs.each_key { |key| next if key.include? master # skip the masters cert, only care about agents assert_not_equal(old_certs[key], new_certs[key], "Expected #{key} to have a changed key") } 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 22a5b4b92..3f41aebbe 100644 --- a/acceptance/tests/ticket_3961_puppet_ca_should_produce_certs.rb +++ b/acceptance/tests/ticket_3961_puppet_ca_should_produce_certs.rb @@ -1,29 +1,35 @@ test_name "#3961: puppet ca should produce certs spec" -scratch = "/tmp/puppet-ssl-3961" target = "working3961.example.org" -options = { :confdir => scratch, :vardir => scratch } - 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'] +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 agents, "rm -vrf #{scratch}" + step "removing the SSL scratch directory..." + on(agent, "rm -vrf #{scratch}") -step "generate a certificate in #{scratch}" -on(agents,puppet_cert('--trace', '--generate', target, options)) do - expect.each do |line| - stdout.index(line) or fail_test("missing line in output: #{line}") + 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 -end -step "verify the certificate for #{target} exists" -on agents, "test -f #{scratch}/ssl/certs/#{target}.pem" + 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 agents, "grep -q 'BEGIN RSA PRIVATE KEY' #{scratch}/ssl/private_keys/#{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_4059_ralsh_can_change_settings.rb b/acceptance/tests/ticket_4059_ralsh_can_change_settings.rb index 83f5899f2..ea7b77cbf 100644 --- a/acceptance/tests/ticket_4059_ralsh_can_change_settings.rb +++ b/acceptance/tests/ticket_4059_ralsh_can_change_settings.rb @@ -1,21 +1,21 @@ test_name "#4059: ralsh can change settings" -target = "/tmp/hosts-#4059" -content = "host example.com ensure=present ip=127.0.0.1 target=#{target}" +agents.each do |agent| + target = agent.tmpfile('hosts-#4059') + content = "host example.com ensure=present ip=127.0.0.1 target=#{target}" -step "cleanup the target file" -on agents, "rm -f #{target}" + step "cleanup the target file" + on(agent, "rm -f #{target}") -step "run the resource agent" -on(agents, puppet_resource(content)) do - stdout.index('Host[example.com]/ensure: created') or - fail_test("missing notice about host record creation") -end -agents.each do |host| - on(host, "cat #{target}") do - assert_match(/^127\.0\.0\.1\s+example\.com/, stdout, "missing host record in #{target} on #{host}") + step "run the resource agent" + on(agent, puppet_resource(content)) do + stdout.index('Host[example.com]/ensure: created') or + fail_test("missing notice about host record creation") + end + on(agent, "cat #{target}") do + assert_match(/^127\.0\.0\.1\s+example\.com/, stdout, "missing host record in #{target} on #{agent}") end -end -step "cleanup at the end of the test" -on agents, "rm -f #{target}" + step "cleanup at the end of the test" + on(agent, "rm -f #{target}") +end diff --git a/acceptance/tests/ticket_4233_resource_with_a_newline.rb b/acceptance/tests/ticket_4233_resource_with_a_newline.rb index 11924b550..1ed1ce83b 100644 --- a/acceptance/tests/ticket_4233_resource_with_a_newline.rb +++ b/acceptance/tests/ticket_4233_resource_with_a_newline.rb @@ -1,16 +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| - apply_manifest_on(host, 'exec { \'/bin/echo -e "\nHello World\n"\': }') do + resource = host.echo('-e "\nHello World\n"') + apply_manifest_on(host, "exec { '#{resource}': }") do assert_no_match(/err:/, stdout, "error report in output on #{host}") end end diff --git a/acceptance/tests/ticket_4285_file_resource_fail_when_name_defined_instead_of_path.rb b/acceptance/tests/ticket_4285_file_resource_fail_when_name_defined_instead_of_path.rb index c1cdb0b9d..cc67fa872 100644 --- a/acceptance/tests/ticket_4285_file_resource_fail_when_name_defined_instead_of_path.rb +++ b/acceptance/tests/ticket_4285_file_resource_fail_when_name_defined_instead_of_path.rb @@ -1,19 +1,21 @@ test_name "Bug #4285: ArgumentError: Cannot alias File[mytitle] to [nil]" -manifest = %q{ +agents.each do |host| + dir = host.tmpdir('4285-aliasing') + +manifest = %Q{ file { "file1": - name => '/tmp/file1', - source => "/tmp/", + name => '#{dir}/file1', + source => "#{dir}/", } file { "file2": - name => '/tmp/file2', - source => "/tmp/", + name => '#{dir}/file2', + source => "#{dir}/", } } -agents.each do |host| apply_manifest_on(host, manifest) do assert_no_match(/Cannot alias/, stdout, "#{host}: found the bug report output") end end diff --git a/acceptance/tests/ticket_6418_file_recursion_and_audit.rb b/acceptance/tests/ticket_6418_file_recursion_and_audit.rb index b21e57ddb..acb72f535 100644 --- a/acceptance/tests/ticket_6418_file_recursion_and_audit.rb +++ b/acceptance/tests/ticket_6418_file_recursion_and_audit.rb @@ -1,33 +1,34 @@ # 2011-02-23 # # AffectedVersion: 2.6.0-2.6.5 # FixedVersion: test_name "#6418: file recursion and audit" -manifest = %q{ - file { "/tmp/6418": ensure => directory } - file { "/tmp/6418/dir": ensure => directory} - file { "/tmp/6418/dir/dir": ensure => directory} - file { "/tmp/6418/dir/dir/dir": ensure => directory} - file { "/tmp/6418-copy": ensure => present, source => "/tmp/6418/" } - - File["/tmp/6418"] -> File["/tmp/6418/dir"] -> File["/tmp/6418/dir/dir"] -> File["/tmp/6418/dir/dir/dir"] -> File["/tmp/6418-copy"] -} +agents.each do |agent| + dir = agent.tmpdir('6418-recurse-audit') -step "Query agent for statefile" -agent=agents.first -on agent, puppet_agent('--configprint statefile') -statefile=stdout.chomp +manifest = %Q{ + file { "#{dir}/6418": ensure => directory } + file { "#{dir}/6418/dir": ensure => directory} + file { "#{dir}/6418/dir/dir": ensure => directory} + file { "#{dir}/6418/dir/dir/dir": ensure => directory} + file { "#{dir}/6418-copy": ensure => present, source => "#{dir}/6418/" } -step "Remove the statefile on all Agents" -on agents, "rm -f #{statefile}" + File["#{dir}/6418"] -> File["#{dir}/6418/dir"] -> File["#{dir}/6418/dir/dir"] -> File["#{dir}/6418/dir/dir/dir"] -> File["#{dir}/6418-copy"] +} -step "Apply the manifest" -apply_manifest_on agents, manifest + step "Query agent for statefile" + on agent, puppet_agent('--configprint statefile') do + statefile=stdout.chomp + step "Remove the statefile on the agent" + on(agent, "rm -f '#{statefile}'") -step "Verify corecct file recursion and audit state" -agents.each do |agent| - on(agent, "grep ensure.*directory #{statefile}", :acceptable_exit_codes => [ 1 ]) + step "Apply the manifest" + apply_manifest_on agent, manifest + + step "Verify correct file recursion and audit state" + on(agent, "grep ensure.*directory '#{statefile}'", :acceptable_exit_codes => [ 1 ]) + end end diff --git a/acceptance/tests/ticket_6541_invalid_filebucket_files.rb b/acceptance/tests/ticket_6541_invalid_filebucket_files.rb index 2c7136ed0..11de0e6b2 100644 --- a/acceptance/tests/ticket_6541_invalid_filebucket_files.rb +++ b/acceptance/tests/ticket_6541_invalid_filebucket_files.rb @@ -1,36 +1,33 @@ test_name "#6541: file type truncates target when filebucket cannot retrieve hash" -target="/tmp/6541-$$" -on agents, host_command('rm -rf #{host["puppetvardir"]}/*bucket') +agents.each do |agent| + target=agent.tmpfile('6541-target') -step "write zero length file" -manifest = "file { '#{target}': content => '' }" -apply_manifest_on(agents, manifest) + on agent, host_command('rm -rf #{host["puppetvardir"]}/*bucket') -step "overwrite file, causing zero-length file to be backed up" -manifest = "file { '#{target}': content => 'some text' }" -apply_manifest_on(agents, manifest) + step "write zero length file" + manifest = "file { '#{target}': content => '' }" + apply_manifest_on(agent, manifest) -test_name "verify invalid hashes should not change the file" -manifest = "file { '#{target}': content => '{md5}notahash' }" -agents.each do |host| - apply_manifest_on(host, manifest) do - assert_no_match(/content changed/, stdout, "#{host}: shouldn't have overwrote the file") + step "overwrite file, causing zero-length file to be backed up" + manifest = "file { '#{target}': content => 'some text' }" + apply_manifest_on(agent, manifest) + + test_name "verify invalid hashes should not change the file" + manifest = "file { '#{target}': content => '{md5}notahash' }" + apply_manifest_on(agent, manifest) do + assert_no_match(/content changed/, stdout, "#{agent}: shouldn't have overwrote the file") end -end -test_name "verify valid but unbucketed hashes should not change the file" -manifest = "file { '#{target}': content => '{md5}13ad7345d56b566a4408ffdcd877bc78' }" -agents.each do |host| - apply_manifest_on(host, manifest) do - assert_no_match(/content changed/, stdout, "#{host}: shouldn't have overwrote the file") + test_name "verify valid but unbucketed hashes should not change the file" + manifest = "file { '#{target}': content => '{md5}13ad7345d56b566a4408ffdcd877bc78' }" + apply_manifest_on(agent, manifest) do + assert_no_match(/content changed/, stdout, "#{agent}: shouldn't have overwrote the file") end -end -test_name "verify that an empty file can be retrieved from the filebucket" -manifest = "file { '#{target}': content => '{md5}d41d8cd98f00b204e9800998ecf8427e' }" -agents.each do |host| - apply_manifest_on(host, manifest) do - assert_match(/content changed '\{md5\}552e21cd4cd9918678e3c1a0df491bc3' to '\{md5\}d41d8cd98f00b204e9800998ecf8427e'/, stdout, "#{host}: shouldn't have overwrote the file") + test_name "verify that an empty file can be retrieved from the filebucket" + manifest = "file { '#{target}': content => '{md5}d41d8cd98f00b204e9800998ecf8427e' }" + apply_manifest_on(agent, manifest) do + assert_match(/content changed '\{md5\}552e21cd4cd9918678e3c1a0df491bc3' to '\{md5\}d41d8cd98f00b204e9800998ecf8427e'/, stdout, "#{agent}: shouldn't have overwrote the file") end end diff --git a/acceptance/tests/ticket_6907_use_provider_in_same_run_it_becomes_suitable.rb b/acceptance/tests/ticket_6907_use_provider_in_same_run_it_becomes_suitable.rb index a9b0b8856..2a5d11333 100644 --- a/acceptance/tests/ticket_6907_use_provider_in_same_run_it_becomes_suitable.rb +++ b/acceptance/tests/ticket_6907_use_provider_in_same_run_it_becomes_suitable.rb @@ -1,40 +1,42 @@ test_name "providers should be useable in the same run they become suitable" -dir = "/tmp/#{$$}-6907" +agents.each do |agent| + dir = agent.tmpdir('provider-6907') -on agents, "mkdir -p #{dir}/lib/puppet/{type,provider/test6907}" -on agents, "cat > #{dir}/lib/puppet/type/test6907.rb", :stdin => < #{dir}/lib/puppet/type/test6907.rb", :stdin => < true) newproperty(:file) end TYPE -on agents, "cat > #{dir}/lib/puppet/provider/test6907/only.rb", :stdin => < #{dir}/lib/puppet/provider/test6907/only.rb", :stdin => < "#{dir}/must_exist" require 'fileutils' def file 'not correct' end def file=(value) FileUtils.touch(value) end end PROVIDER -on agents, puppet_apply("--libdir #{dir}/lib --trace"), :stdin => < < "#{dir}/test_file", } file { "#{dir}/must_exist": ensure => file, mode => 0755, } MANIFEST -on agents, "ls #{dir}/test_file" + on agent, "ls #{dir}/test_file" +end diff --git a/acceptance/tests/ticket_6928_puppet_master_parse_fails.rb b/acceptance/tests/ticket_6928_puppet_master_parse_fails.rb index 155e91d3f..039390cca 100644 --- a/acceptance/tests/ticket_6928_puppet_master_parse_fails.rb +++ b/acceptance/tests/ticket_6928_puppet_master_parse_fails.rb @@ -1,35 +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| - create_remote_file(host, '/tmp/good.pp', %w{notify{good:}} ) - create_remote_file(host, '/tmp/bad.pp', 'notify{bad:') -end + good = host.tmpfile('good-6928') + bad = host.tmpfile('bad-6928') -step "Agents: use --parseonly on an invalid manifest, should return 1 and issue deprecation warning" -agents.each do |host| - on(host, "puppet --parseonly /tmp/bad.pp}", :acceptable_exit_codes => [ 1 ]) do + 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('--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 -end -step "Test Face for ‘parser validate’ with good manifest -- should pass" -agents.each do |host| - on(host, "puppet parser validate /tmp/good.pp", :acceptable_exit_codes => [ 0 ]) -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" -agents.each do |host| - on(host, "puppet parser validate /tmp/bad.pp", :acceptable_exit_codes => [ 1 ]) do + 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}" ) end end diff --git a/acceptance/tests/ticket_7101_template_compile.rb b/acceptance/tests/ticket_7101_template_compile.rb index d2ebecd13..b2486b030 100644 --- a/acceptance/tests/ticket_7101_template_compile.rb +++ b/acceptance/tests/ticket_7101_template_compile.rb @@ -1,25 +1,24 @@ test_name "#7101: template compile" -manifest = %q{ +agents.each do |agent| + template = agent.tmpfile('template_7101.erb') + target = agent.tmpfile('file_7101.erb') + + manifest = %Q{ $bar = 'test 7101' -file { '/tmp/file_7101.erb': - content => template('/tmp/template_7101.erb') +file { '#{target}': + content => template("#{template}") } } + step "Agents: Create template file" + create_remote_file(agent, template, %w{<%= bar %>} ) -step "Agents: Create template file" -agents.each do |host| - create_remote_file(host, '/tmp/template_7101.erb', %w{<%= bar %>} ) -end - -step "Run manifest referencing template file" -apply_manifest_on(agents, manifest) - + step "Run manifest referencing template file" + apply_manifest_on(agent, manifest) -step "Agents: Verify file is created with correct contents " -agents.each do |host| - on(host, "cat /tmp/file_7101.erb") do - assert_match(/test 7101/, stdout, "File /tmp/file_7101.erb not created with correct contents on #{host}" ) + step "Agents: Verify file is created with correct contents " + on(agent, "cat #{target}") do + assert_match(/test 7101/, stdout, "File #{target} not created with correct contents on #{agent}" ) end end diff --git a/acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb b/acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb index bb0b0ab8c..5bace0854 100644 --- a/acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb +++ b/acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb @@ -1,27 +1,32 @@ test_name "#7117 Broke the environment criteria in auth.conf" # add to auth.conf add_2_authconf = %q{ path / environment override auth any allow * } step "Create a temp auth.conf" create_remote_file master, "/tmp/auth.conf-7117", add_2_authconf on master, "chmod 644 /tmp/auth.conf-7117" with_master_running_on(master, "--dns_alt_names=\"puppet, $(hostname -s), $(hostname -f)\" --rest_authconfig /tmp/auth.conf-7117 --verbose --autosign true") do - # Run test on Agents - step "Run agent to upload facts" - on agents, puppet_agent("--test --server #{master}") + agents.each do |agent| + if agent['platform'].include?('windows') + Log.warn("Pending: Window's doesn't support hostname -f") + next + end + + # Run test on Agents + step "Run agent to upload facts" + on agent, puppet_agent("--test --server #{master}") - step "Fetch agent facts from Puppet Master" - agents.each do |host| - on(host, "curl -k -H \"Accept: yaml\" https://#{master}:8140/override/facts/\`hostname -f\`") do - assert_match(/--- !ruby\/object:Puppet::Node::Facts/, stdout, "Agent Facts not returned for #{host}") + step "Fetch agent facts from Puppet Master" + on(agent, "curl -k -H \"Accept: yaml\" https://#{master}:8140/override/facts/\`hostname -f\`") do + assert_match(/--- !ruby\/object:Puppet::Node::Facts/, stdout, "Agent Facts not returned for #{agent}") end end end diff --git a/acceptance/tests/ticket_7139_puppet_resource_file_qualified_paths.rb b/acceptance/tests/ticket_7139_puppet_resource_file_qualified_paths.rb index f773ba17c..7a7b59434 100644 --- a/acceptance/tests/ticket_7139_puppet_resource_file_qualified_paths.rb +++ b/acceptance/tests/ticket_7139_puppet_resource_file_qualified_paths.rb @@ -1,11 +1,13 @@ -test_name "#7139: Puppet resource file failes on path with leading '/'" +test_name "#7139: Puppet resource file fails on path with leading '/'" -step "Agents: create valid, invalid formatted manifests" -create_remote_file(agents, '/tmp/ticket-7139', %w{foo bar contents} ) +agents.each do |agent| + target = agent.tmpfile('ticket-7139') -step "Run puppet file resource on /tmp/ticket-7139" -agents.each do |host| - on(host, "puppet resource file /tmp/ticket-7139") do - assert_match(/file \{ \'\/tmp\/ticket-7139\':/, stdout, "puppet resource file failed on #{host}") + step "Agents: create valid, invalid formatted manifests" + create_remote_file(agent, target, %w{foo bar contents} ) + + step "Run puppet file resource on #{target}" + on(agent, puppet_resource('file', target)) do + assert_match(/file \{ \'#{Regexp.escape(target)}\':/, stdout, "puppet resource file failed on #{agent}") end end