Skip to content

Commit

Permalink
Merge branch 'maint/2.6.x/add_ported_resources_tests_from_enterpise_d…
Browse files Browse the repository at this point in the history
…ist' into 2.6.x
  • Loading branch information
Dominic Maraglia committed Jun 27, 2011
2 parents c974653 + 3e3fc69 commit 567589c
Show file tree
Hide file tree
Showing 29 changed files with 119 additions and 96 deletions.
6 changes: 3 additions & 3 deletions acceptance/tests/resource/cron/should_create_cron.rb
@@ -1,6 +1,6 @@
test_name "should create cron"

tmpuser = "cron-test-#{Time.new.to_i}"
tmpuser = "pl#{rand(999999).to_i}"
tmpfile = "/tmp/cron-test-#{Time.new.to_i}"

create_user = "user { '#{tmpuser}': ensure => present, managehome => false }"
Expand All @@ -18,13 +18,13 @@
end

step "verify that crontab -l contains what you expected"
on host, "crontab -l -u #{tmpuser}" do
run_cron_on(host, :list, tmpuser) do
fail_test "didn't find the command as expected" unless
stdout.include? "* * * * * /bin/true"
end

step "remove the crontab file for that user"
on host, "crontab -r -u #{tmpuser}"
run_cron_on(host, :remove, tmpuser)

step "remove the user from the system"
apply_manifest_on host, delete_user
Expand Down
13 changes: 5 additions & 8 deletions acceptance/tests/resource/cron/should_match_existing.rb
@@ -1,6 +1,6 @@
test_name "puppet should match existing job"


tmpuser = "cron-test-#{Time.new.to_i}"
tmpuser = "pl#{rand(999999).to_i}"
tmpfile = "/tmp/cron-test-#{Time.new.to_i}"

create_user = "user { '#{tmpuser}': ensure => present, managehome => false }"
Expand All @@ -11,14 +11,11 @@
apply_manifest_on host, create_user

step "create the existing job by hand..."
on host, "echo '* * * * * /bin/true' | crontab -u #{tmpuser} -"
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
# REVISIT: This is ported from the original test, which seems to me a
# weak test, but I don't want to improve it now. --daniel 2010-12-23
#
# This is a weak/fragile test. The output has changed
# causing this test to fail erronously. Changed to the correct
# output to match, but this code should be re-feactored.
Expand All @@ -27,13 +24,13 @@
end

step "verify that crontab -l contains what you expected"
on host, "crontab -l -u #{tmpuser}" do
run_cron_on(host, :list, tmpuser) do
fail_test "didn't find the command as expected" unless
stdout.include? "* * * * * /bin/true"
end

step "remove the crontab file for that user"
on host, "crontab -r -u #{tmpuser}"
run_cron_on(host, :remove, tmpuser)

step "remove the user from the system"
apply_manifest_on host, delete_user
Expand Down
12 changes: 6 additions & 6 deletions acceptance/tests/resource/cron/should_remove_cron.rb
@@ -1,6 +1,6 @@
test_name "puppet should remove a crontab entry as expected"

tmpuser = "cron-test-#{Time.new.to_i}"
tmpuser = "pl#{rand(999999).to_i}"
tmpfile = "/tmp/cron-test-#{Time.new.to_i}"

create_user = "user { '#{tmpuser}': ensure => present, managehome => false }"
Expand All @@ -11,7 +11,7 @@
apply_manifest_on host, create_user

step "create the existing job by hand..."
on host, "printf '# Puppet Name: crontest\n* * * * * /bin/true\n' | crontab -u #{tmpuser} -"
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}",
Expand All @@ -23,13 +23,13 @@
end

step "verify that crontab -l contains what you expected"
on host, "crontab -l -u #{tmpuser}" do
fail_test "didn't found the command we tried to remove" if
stdout.include? "/bin/true"
run_cron_on(host, :list, tmpuser) do
fail_test "didn't found the command we tried to remove" if
stdout.include? "/bin/true"
end

step "remove the crontab file for that user"
on host, "crontab -r -u #{tmpuser}"
run_cron_on(host, :remove, tmpuser)

step "remove the user from the system"
apply_manifest_on host, delete_user
Expand Down
8 changes: 4 additions & 4 deletions acceptance/tests/resource/cron/should_remove_matching.rb
@@ -1,6 +1,6 @@
test_name "puppet should remove a crontab entry based on command matching"

tmpuser = "cron-test-#{Time.new.to_i}"
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'
Expand All @@ -13,7 +13,7 @@
apply_manifest_on host, create_user

step "create the existing job by hand..."
on host, "printf '#{cron}' | crontab -u #{tmpuser} -"
run_cron_on(host,:add,tmpuser,"* * * * * /bin/true")

step "apply the resource change on the host"
on(host, puppet_resource("cron", "bogus", "user=#{tmpuser}",
Expand All @@ -23,13 +23,13 @@
end

step "verify that crontab -l contains what you expected"
on host, "crontab -l -u #{tmpuser}" do
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 == 1
end

step "remove the crontab file for that user"
on host, "crontab -r -u #{tmpuser}"
run_cron_on(host,:remove,tmpuser)

step "remove the user from the system"
apply_manifest_on host, delete_user
Expand Down
14 changes: 6 additions & 8 deletions acceptance/tests/resource/cron/should_update_existing.rb
@@ -1,10 +1,8 @@
test_name "puppet should update existing crontab entry"

tmpuser = "cron-test-#{Time.new.to_i}"
tmpuser = "pl#{rand(999999).to_i}"
tmpfile = "/tmp/cron-test-#{Time.new.to_i}"

cron = '# Puppet Name: crontest\n* * * * * /bin/true\n'

create_user = "user { '#{tmpuser}': ensure => present, managehome => false }"
delete_user = "user { '#{tmpuser}': ensure => absent, managehome => false }"

Expand All @@ -13,10 +11,10 @@
apply_manifest_on host, create_user

step "create the existing job by hand..."
on host, "printf '#{cron}' | crontab -u #{tmpuser} -"
run_cron_on(host,:add,tmpuser,"* * * * * /bin/true")

step "verify that crontab -l contains what you expected"
on host, "crontab -l -u #{tmpuser}" do
run_cron_on(host,:list,tmpuser) do
fail_test "didn't find the content in the crontab" unless
stdout.include? '* * * * * /bin/true'
end
Expand All @@ -25,17 +23,17 @@
on(host, puppet_resource("cron", "crontest", "user=#{tmpuser}",
"command=/bin/true", "ensure=present", "hour='0-6'")) do
fail_test "didn't update the time as expected" unless
stdout.include? "defined 'hour' as '0-6'"
stdout.include? "hour => ['0-6']"
end

step "verify that crontab -l contains what you expected"
on host, "crontab -l -u #{tmpuser}" do
run_cron_on(host,:list,tmpuser) do
fail_test "didn't find the content in the crontab" unless
stdout.include? '* 0-6 * * * /bin/true'
end

step "remove the crontab file for that user"
on host, "crontab -r -u #{tmpuser}"
run_cron_on(host,:remove,tmpuser)

step "remove the user from the system"
apply_manifest_on host, delete_user
Expand Down
35 changes: 25 additions & 10 deletions acceptance/tests/resource/file/content_attribute.rb
@@ -1,25 +1,33 @@
test_name "The content attribute"
pass_test "Pass forced pending test failure investigation"
test_name "Content Attribute"

step "Ensure the test environment is clean"
on agents, 'rm -f /tmp/content_file_test.txt'

step "When 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

on agents, 'test "$(cat /tmp/content_file_test.txt)" = "This is the test file content"'
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}")
end
end

step "Ensure the test environment is clean"
on agents, 'rm -f /tmp/content_file_test.txt'

step "When using a filebucket checksum from filebucket"

step "Content Attribute: using a checksum from filebucket"
on agents, "echo 'This is the checksum file contents' > /tmp/checksum_test_file.txt"
on agents, "puppet filebucket backup --local /tmp/checksum_test_file.txt"
step "Backup file into the filebucket"
on agents, puppet_filebucket("backup --local /tmp/checksum_test_file.txt")

agents.each do |agent|
bucketdir="not set"
on agent, puppet_filebucket("--configprint bucketdir") do
bucketdir = stdout.chomp
end

get_remote_option(agents, 'filebucket', 'bucketdir') do |bucketdir|
manifest = %Q|
filebucket { 'local':
path => '#{bucketdir}',
Expand All @@ -31,7 +39,14 @@
backup => local,
}
|
apply_manifest_on agents, manifest

step "Applying Manifest on Agents"
apply_manifest_on agent, manifest
end

on agents, 'test "$(cat /tmp/content_file_test.txt)" = "This is the checksum file contents"'
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}")
end
end
4 changes: 2 additions & 2 deletions acceptance/tests/resource/file/should_create_directory.rb
Expand Up @@ -3,7 +3,7 @@
target = "/tmp/test-#{Time.new.to_i}"

step "clean up the system before we begin"
on agents, "rm -vrf #{target}"
on agents, "rm -rf #{target}"

step "verify we can create a directory"
on(agents, puppet_resource("file", target, 'ensure=directory'))
Expand All @@ -12,4 +12,4 @@
on agents, "test -d #{target}"

step "clean up after the test run"
on agents, "rm -vrf #{target}"
on agents, "rm -rf #{target}"
6 changes: 3 additions & 3 deletions acceptance/tests/resource/file/should_create_empty.rb
Expand Up @@ -3,13 +3,13 @@
target = "/tmp/test-#{Time.new.to_i}"

step "clean up the system before we begin"
on agents, "rm -vrf #{target}"
on agents, "rm -rf #{target}"

step "verify we can create an empty file"
on(agents, puppet_resource("file", target, 'ensure=present'))

step "verify the target was created"
on agents, "test -f #{target} && ! test -s #{target}"
on agents, "test -f #{target} && test ! -s #{target}"

step "clean up after the test run"
on agents, "rm -vrf #{target}"
on agents, "rm -rf #{target}"
5 changes: 3 additions & 2 deletions acceptance/tests/resource/file/should_create_symlink.rb
Expand Up @@ -5,14 +5,15 @@
source = "/tmp/test-#{Time.new.to_i}-source"

step "clean up the system before we begin"
on agents, "rm -vrf #{target}"
on agents, "rm -rf #{target}"
on agents, "echo '#{message}' > #{source}"

step "verify we can create a symlink"
on(agents, puppet_resource("file", target, "ensure=#{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 the content is identical on both sides"
Expand All @@ -24,4 +25,4 @@
end

step "clean up after the test run"
on agents, "rm -vrf #{target} #{source}"
on agents, "rm -rf #{target} #{source}"
2 changes: 1 addition & 1 deletion acceptance/tests/resource/file/should_remove_dir.rb
Expand Up @@ -3,7 +3,7 @@
target = "/tmp/test-#{Time.new.to_i}"

step "clean up the system before we begin"
on agents, "test -e #{target} && rm -vrf #{target} ; mkdir -p #{target}"
on agents, "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
Expand Down
2 changes: 1 addition & 1 deletion acceptance/tests/resource/file/should_remove_file.rb
Expand Up @@ -3,7 +3,7 @@
target = "/tmp/test-#{Time.new.to_i}"

step "clean up the system before we begin"
on agents, "rm -vrf #{target} && touch #{target}"
on agents, "rm -rf #{target} && touch #{target}"

step "verify we can remove a file"
on(agents, puppet_resource("file", target, 'ensure=absent'))
Expand Down
30 changes: 18 additions & 12 deletions acceptance/tests/resource/file/source_attribtute.rb
Expand Up @@ -4,35 +4,41 @@
on agents, 'rm -f /tmp/source_file_test.txt'

# 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 "when using a local file path"
# 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 }"

apply_manifest_on agents, manifest

on agents, 'test "$(cat /tmp/source_file_test.txt)" = "Yay, this is the local file."'
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}")
end
end

step "Ensure the test environment is clean"
on agents, 'rm -f /tmp/source_file_test.txt'

step "when using a puppet:/// URI with puppet apply"
step "Using a puppet:/// URI with puppet apply"

on agents, 'puppet agent --configprint modulepath' do
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 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

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"
on agents, puppet_apply("/tmp/source_test_manifest.pp")

on agents, 'test "$(cat /tmp/source_file_test.txt)" = "Yay, this is the puppet:/// file."'
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}")
end
end

# Oops. We (Jesse & Jacob) ended up writing this before realizing that you
# can't actually specify "source => 'http://...'". However, we're leaving it
Expand Down
4 changes: 2 additions & 2 deletions acceptance/tests/resource/group/should_create.rb
@@ -1,6 +1,6 @@
test_name "should create group"

name = "test-group-#{Time.new.to_i}"
name = "pl#{rand(999999).to_i}"

def cleanup(name)
step "remove group #{name} if it exists"
Expand All @@ -14,7 +14,7 @@ def cleanup(name)

step "verify the group #{name} was created"
on(agents, "getent group #{name}") do
fail_test "group information is not sensible" unless stdout =~ /^#{name}:x:[0-9]+:/
fail_test "group information is not sensible" unless stdout =~ /^#{name}:.*:[0-9]+:/
end

cleanup(name)

0 comments on commit 567589c

Please sign in to comment.