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