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/ticket_8740_should_not_enumerate_root_directory.rb b/acceptance/tests/resource/file/ticket_8740_should_not_enumerate_root_directory.rb index 5763a3c98..a918f8ccb 100644 --- a/acceptance/tests/resource/file/ticket_8740_should_not_enumerate_root_directory.rb +++ b/acceptance/tests/resource/file/ticket_8740_should_not_enumerate_root_directory.rb @@ -1,32 +1,39 @@ test_name "#8740: should not enumerate root directory" target = "/test-socket-#{$$}" -step "clean up the system before we begin" -on(agents, "rm -f #{target}") +agents.each do |agent| + if agent['platform'].include?('windows') + skip_test "Test not supported on this platform" + next + end -step "create UNIX domain socket" -on(agents, %Q{ruby -e "require 'socket'; UNIXServer::new('#{target}').close"}) + step "clean up the system before we begin" + on(agent, "rm -f #{target}") -step "query for all files, which should return nothing" -on(agents, 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 + 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