diff --git a/acceptance/pending/ticket_3360_allow_duplicate_csr_with_option_set.rb b/acceptance/pending/ticket_3360_allow_duplicate_csr_with_option_set.rb new file mode 100644 index 000000000..ba02227ea --- /dev/null +++ b/acceptance/pending/ticket_3360_allow_duplicate_csr_with_option_set.rb @@ -0,0 +1,50 @@ +test_name "#3360: Allow duplicate CSR when allow_duplicate_certs is on" + +agent_hostnames = agents.map {|a| a.to_s} + +# Kill running Puppet Master -- should not be running at this point +step "Master: kill running Puppet Master" +on master, "ps -U puppet | awk '/puppet/ { print \$1 }' | xargs kill || echo \"Puppet Master not running\"" + +step "Master: Start Puppet Master" +on master, puppet_master("--allow_duplicate_certs --certdnsnames=\"puppet:$(hostname -s):$(hostname -f)\" --verbose --noop") + +step "Generate a certificate request for the agent" +on agents, "puppet certificate generate `hostname -f` --ca-location remote --server #{master}" + +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}" + +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 + fail_test("#{key} does not have a new signed certificate") if old_certs[key] == new_certs[key] +} diff --git a/acceptance/pending/ticket_3360_reject_duplicate_csr_with_option_unset.rb b/acceptance/pending/ticket_3360_reject_duplicate_csr_with_option_unset.rb new file mode 100644 index 000000000..e69de29bb diff --git a/acceptance/pending/ticket_4149_parseonly_should_not_fail.rb b/acceptance/pending/ticket_4149_parseonly_should_not_fail.rb new file mode 100644 index 000000000..228dec307 --- /dev/null +++ b/acceptance/pending/ticket_4149_parseonly_should_not_fail.rb @@ -0,0 +1,18 @@ +test_name "#4149: parseonly should do the right thing" + +step "test with a manifest with syntax errors" +manifest = 'class someclass { notify { "hello, world" } }' +apply_manifest_on(agents, manifest, :parseonly => true, :acceptable_exit_codes => [1]) { + stdout =~ /Could not parse for .*: Syntax error/ or + fail_test("didn't get a reported systax error") +} + +step "test with a manifest with correct syntax" +apply_manifest_on agents,'class someclass { notify("hello, world") }', :parseonly => true + +# REVISIT: This tests the current behaviour, which is IMO not actually the +# correct behaviour. On the other hand, if we change this we might +# unexpectedly break things out in the wild, so better to be warned than to be +# surprised by it. --daniel 2010-12-22 +step "test with a class with an invalid attribute" +apply_manifest_on agents, 'file { "/tmp/whatever": fooble => 1 }', :parseonly => true diff --git a/acceptance/pending/ticket_4151_defined_function_should_not_return_true_for_unrealized_virtual_resources.rb b/acceptance/pending/ticket_4151_defined_function_should_not_return_true_for_unrealized_virtual_resources.rb new file mode 100644 index 000000000..2da392a62 --- /dev/null +++ b/acceptance/pending/ticket_4151_defined_function_should_not_return_true_for_unrealized_virtual_resources.rb @@ -0,0 +1,24 @@ +test_name "#4151: defined function should not return true for unrealized virtual resources" + +# Jeff McCune +# 2010-07-06 +# +# This script is expected to exit non-zero if ticket 4151 has not been +# fixed. +# +# The expected behavior is for defined() to only return true if a virtual +# resource has been realized. +# +# This test creates a virtual resource, does NOT realize it, then calls +# the defined() function against it. If defined returns true, there will +# be an error since Notify["goodbye"] will require a resource which has +# not been realized. + + +manifest1 = %q{ + @notify { "hello": } + if (defined(Notify["hello"])) { $requires = [ Notify["hello"] ] } + notify { "goodbye": require => $requires } +} + +apply_manifest_on(agents, manifest1) diff --git a/acceptance/pending/ticket_5027_warn_on_dynamic_scope.rb b/acceptance/pending/ticket_5027_warn_on_dynamic_scope.rb new file mode 100644 index 000000000..762116ce9 --- /dev/null +++ b/acceptance/pending/ticket_5027_warn_on_dynamic_scope.rb @@ -0,0 +1,28 @@ +test_name "#5027: Issue warnings when using dynamic scope" + +step "Apply dynamic scoping manifest on agents" +apply_manifest_on agents, %q{ + $foo = 'foo_value' + + class a { + $bar = 'bar_value' + + include b + } + + class b inherits c { + notify { $baz: } # should not generate a warning -- inherited from class c + notify { $bar: } # should generate a warning -- uses dynamic scoping + notify { $foo: } # should not generate a warning -- comes from top scope + } + + class c { + $baz = 'baz_value' + } + + include a +} + +step "Verify deprecation warning" +fail_test "Deprecation warning not issued" unless + stdout.include? 'warning: Dynamic lookup of $bar will not be supported in future versions. Use a fully-qualified variable name or parameterized classes.' diff --git a/acceptance/pending/ticket_6710_relationship_syntax_should_work_with_title_arrays.rb b/acceptance/pending/ticket_6710_relationship_syntax_should_work_with_title_arrays.rb new file mode 100644 index 000000000..60da19e45 --- /dev/null +++ b/acceptance/pending/ticket_6710_relationship_syntax_should_work_with_title_arrays.rb @@ -0,0 +1,15 @@ +test_name "#6710: Relationship syntax should work with title arraysA" + +# Jeff McCune +# 2011-03-14 +# +# If bug 6710 is closed, then this manifests should apply cleanly. +# There should be a many-to-many relationship established. +# + +apply_manifest_on agents, %q{ + notify { [ left_one, left_two ]: } -> notify { [ right_one, right_two ]: } + notify { left: } -> notify { right: } + notify { left_one_to_many: } -> notify { [ right_one_to_many_1, right_one_to_many_2 ]: } +} + diff --git a/acceptance/pending/ticket_6928_puppet_master_parse_fails.rb b/acceptance/pending/ticket_6928_puppet_master_parse_fails.rb new file mode 100644 index 000000000..aac53138a --- /dev/null +++ b/acceptance/pending/ticket_6928_puppet_master_parse_fails.rb @@ -0,0 +1,38 @@ +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 ] + fail_test "Deprecation warning not issued for --parseonly" unless + stdout.include? '--parseonly has been removed. Please use \'puppet parser validate \'' + +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 + +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 + fail_test "Deprecation warning not issued for --parseonly" unless + stdout.include? '--parseonly has been removed. Please use \'puppet parser validate \'' + 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 bad manifest -- should fail" +agents.each do |host| + on(host, "puppet parser validate /tmp/bad.pp", :acceptable_exit_codes => [ 1 ]) do + fail_test "Bad manifest detection failed" unless + stderr.include? 'Could not run: Could not parse for environment production' + end +end diff --git a/acceptance/tests/apply/classes/parameterized_classes.rb b/acceptance/tests/apply/classes/parameterized_classes.rb new file mode 100755 index 000000000..9a7029425 --- /dev/null +++ b/acceptance/tests/apply/classes/parameterized_classes.rb @@ -0,0 +1,56 @@ +test_name "parametrized classes" + +######################################################################## +step "should allow param classes" +manifest = %q{ +class x($y, $z) { + notice("${y}-${z}") +} +class {x: y => '1', z => '2'} +} + +apply_manifest_on(agents, manifest) do + fail_test "inclusion after parameterization failed" unless stdout.include? "1-2" +end + +######################################################################## +# REVISIT: This was ported from the old set of tests, but I think that +# the desired behaviour has recently changed. --daniel 2010-12-23 +step "should allow param class post inclusion" +manifest = %q{ +class x($y, $z) { + notice("${y}-${z}") +} +class {x: y => '1', z => '2'} +include x +} + +apply_manifest_on(agents, manifest) do + fail_test "inclusion after parameterization failed" unless stdout.include? "1-2" +end + +######################################################################## +step "should allow param classes defaults" +manifest = %q{ +class x($y, $z='2') { + notice("${y}-${z}") +} +class {x: y => '1'} +} + +apply_manifest_on(agents, manifest) do + fail_test "the default didn't apply as expected" unless stdout.include? "1-2" +end + +######################################################################## +step "should allow param class defaults to be overriden" +manifest = %q{ +class x($y, $z='2') { + notice("${y}-${z}") +} +class {x: y => '1', z => '3'} +} + +apply_manifest_on(agents, manifest) do + fail_test "the override didn't happen as we expected" unless stdout.include? "1-3" +end diff --git a/acceptance/tests/apply/classes/should_allow_param_override.rb b/acceptance/tests/apply/classes/should_allow_param_override.rb new file mode 100755 index 000000000..09592ec8b --- /dev/null +++ b/acceptance/tests/apply/classes/should_allow_param_override.rb @@ -0,0 +1,20 @@ +test_name "should allow param override" + +manifest = %q{ +class parent { + notify { 'msg': + message => parent, + } +} +class child inherits parent { + Notify['msg'] {message => 'child'} +} +include parent +include child +} + +apply_manifest_on(agents, manifest) do + fail_test "parameter override didn't work" unless + stdout.include? "defined 'message' as 'child'" +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 new file mode 100755 index 000000000..a4f37cba1 --- /dev/null +++ b/acceptance/tests/apply/classes/should_allow_param_undef_override.rb @@ -0,0 +1,29 @@ +test_name "should allow overriding a parameter to undef in inheritence" + +out = "/tmp/class_undef_override_out-#{$$}" +manifest = %Q{ + class parent { + file { 'test': + path => '#{out}', + source => '/tmp/class_undef_override_test-#{$$}', + } + } + 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 + 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 diff --git a/acceptance/tests/apply/classes/should_include_resources_from_class.rb b/acceptance/tests/apply/classes/should_include_resources_from_class.rb new file mode 100755 index 000000000..b78be6cec --- /dev/null +++ b/acceptance/tests/apply/classes/should_include_resources_from_class.rb @@ -0,0 +1,11 @@ +test_name "resources declared in a class can be applied with include" +manifest = %q{ +class x { + notify{'a':} +} +include x +} +apply_manifest_on(agents, manifest) do + fail_test "the resource did not apply" unless + stdout.include? "defined 'message' as 'a'" +end diff --git a/acceptance/tests/apply/classes/should_not_auto_include_resources_from_class.rb b/acceptance/tests/apply/classes/should_not_auto_include_resources_from_class.rb new file mode 100755 index 000000000..25721eb4c --- /dev/null +++ b/acceptance/tests/apply/classes/should_not_auto_include_resources_from_class.rb @@ -0,0 +1,6 @@ +test_name "resources declared in classes are not applied without include" +manifest = %q{ class x { notify { 'test': message => 'never invoked' } } } +apply_manifest_on(agents, manifest) do + fail_test "found the notify despite not including it" if + stdout.include? "never invoked" +end diff --git a/acceptance/tests/apply/conditionals/should_evaluate_else.rb b/acceptance/tests/apply/conditionals/should_evaluate_else.rb new file mode 100755 index 000000000..7bdceb1d1 --- /dev/null +++ b/acceptance/tests/apply/conditionals/should_evaluate_else.rb @@ -0,0 +1,15 @@ +test_name "else clause will be reached if no expressions match" +manifest = %q{ +if( 1 == 2) { + notice('if') +} elsif(2 == 3) { + notice('elsif') +} else { + notice('else') +} +} + +apply_manifest_on(agents, manifest) do + fail_test "the else clause did not evaluate" unless stdout.include? 'else' +end + diff --git a/acceptance/tests/apply/conditionals/should_evaluate_elsif.rb b/acceptance/tests/apply/conditionals/should_evaluate_elsif.rb new file mode 100755 index 000000000..027e247c9 --- /dev/null +++ b/acceptance/tests/apply/conditionals/should_evaluate_elsif.rb @@ -0,0 +1,15 @@ +test_name "should evaluate the elsif block in a conditional" +manifest = %q{ +if( 1 == 3) { + notice('if') +} elsif(2 == 2) { + notice('elsif') +} else { + notice('else') +} +} + +apply_manifest_on(agents, manifest) do + fail_test "didn't evaluate elsif" unless stdout.include? 'elsif' +end + diff --git a/acceptance/tests/apply/conditionals/should_evaluate_empty.rb b/acceptance/tests/apply/conditionals/should_evaluate_empty.rb new file mode 100644 index 000000000..85b0792b4 --- /dev/null +++ b/acceptance/tests/apply/conditionals/should_evaluate_empty.rb @@ -0,0 +1,12 @@ +test_name "ensure that undefined variables evaluate as false" +manifest = %q{ +if $undef_var { +} else { + notice('undef') +} +} + +apply_manifest_on(agents, manifest) do + fail_test "did not evaluate as expected" unless stdout.include? 'undef' +end + diff --git a/acceptance/tests/apply/conditionals/should_evaluate_false.rb b/acceptance/tests/apply/conditionals/should_evaluate_false.rb new file mode 100755 index 000000000..9a64e1663 --- /dev/null +++ b/acceptance/tests/apply/conditionals/should_evaluate_false.rb @@ -0,0 +1,12 @@ +test_name "test that false evaluates to false" +manifest = %q{ +if false { +} else { + notice('false') +} +} + +apply_manifest_on(agents, manifest) do + fail_test "didn't evaluate false correcly" unless stdout.include? 'false' +end + diff --git a/acceptance/tests/apply/conditionals/should_evaluate_if.rb b/acceptance/tests/apply/conditionals/should_evaluate_if.rb new file mode 100755 index 000000000..d0113e518 --- /dev/null +++ b/acceptance/tests/apply/conditionals/should_evaluate_if.rb @@ -0,0 +1,15 @@ +test_name = "should evaluate an if block correctly" +manifest = %q{ +if( 1 == 1) { + notice('if') +} elsif(2 == 2) { + notice('elsif') +} else { + notice('else') +} +} + +apply_manifest_on(agents, manifest) do + fail_test "didn't evaluate correctly" unless stdout.include? 'if' +end + diff --git a/acceptance/tests/apply/conditionals/should_evaluate_strings_true.rb b/acceptance/tests/apply/conditionals/should_evaluate_strings_true.rb new file mode 100755 index 000000000..14b753085 --- /dev/null +++ b/acceptance/tests/apply/conditionals/should_evaluate_strings_true.rb @@ -0,0 +1,13 @@ +test_name "test that the string 'false' evaluates to true" +manifest = %q{ +if 'false' { + notice('true') +} else { + notice('false') +} +} + +apply_manifest_on(agents, manifest) do + fail_test "string 'false' didn't evaluate as true" unless + stdout.include? 'true' +end diff --git a/acceptance/tests/apply/conditionals/should_evaluate_undef.rb b/acceptance/tests/apply/conditionals/should_evaluate_undef.rb new file mode 100755 index 000000000..ba5d6403e --- /dev/null +++ b/acceptance/tests/apply/conditionals/should_evaluate_undef.rb @@ -0,0 +1,11 @@ +test_name "empty string should evaluate as false" +manifest = %q{ +if '' { +} else { + notice('empty') +} +} + +apply_manifest_on(agents, manifest) do + fail_test "didn't evaluate as false" unless stdout.include? 'empty' +end diff --git a/acceptance/tests/apply/hashes/should_not_reassign.rb b/acceptance/tests/apply/hashes/should_not_reassign.rb new file mode 100755 index 000000000..2b0f9cc13 --- /dev/null +++ b/acceptance/tests/apply/hashes/should_not_reassign.rb @@ -0,0 +1,10 @@ +test_name "hash reassignment should fail" +manifest = %q{ +$my_hash = {'one' => '1', 'two' => '2' } +$my_hash['one']='1.5' +} + +apply_manifest_on(agents, manifest, :acceptable_exit_codes => [1]) do + fail_test "didn't find the failure" unless + stderr.include? "Assigning to the hash 'my_hash' with an existing key 'one'" +end diff --git a/acceptance/tests/apply/virtual/should_realize.rb b/acceptance/tests/apply/virtual/should_realize.rb new file mode 100755 index 000000000..fd32ad859 --- /dev/null +++ b/acceptance/tests/apply/virtual/should_realize.rb @@ -0,0 +1,22 @@ +test_name "should realize" +out = "/tmp/hosts-#{Time.new.to_i}" +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 "realize the resource on the hosts" +apply_manifest_on agents, manifest + +step "verify the content of the file" +on(agents, "cat #{out}") do + fail_test "missing host definition" unless stdout.include? name +end + +step "final cleanup of the system" +on agents, "rm -f #{out}" diff --git a/acceptance/tests/apply/virtual/should_realize_complex_query.rb b/acceptance/tests/apply/virtual/should_realize_complex_query.rb new file mode 100755 index 000000000..9782bbfac --- /dev/null +++ b/acceptance/tests/apply/virtual/should_realize_complex_query.rb @@ -0,0 +1,36 @@ +test_name "should realize with complex query" +out = "/tmp/hosts-#{Time.new.to_i}" +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 "run the manifest" +apply_manifest_on agents, manifest + +step "verify the file output" +on(agents, "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 + +step "clean up system after testing" +on agents, "rm -f #{out}" diff --git a/acceptance/tests/apply/virtual/should_realize_many.rb b/acceptance/tests/apply/virtual/should_realize_many.rb new file mode 100755 index 000000000..8f53caefe --- /dev/null +++ b/acceptance/tests/apply/virtual/should_realize_many.rb @@ -0,0 +1,22 @@ +test_name "test that realize function takes a list" +out = "/tmp/hosts-#{Time.new.to_i}" +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 agents, "rm -f #{out}" + +step "run the manifest" +apply_manifest_on agents, manifest + +step "verify the file output" +on(agents, "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 diff --git a/acceptance/tests/apply/virtual/should_realize_query.rb b/acceptance/tests/apply/virtual/should_realize_query.rb new file mode 100755 index 000000000..24d323373 --- /dev/null +++ b/acceptance/tests/apply/virtual/should_realize_query.rb @@ -0,0 +1,24 @@ +test_name "should realize query" +out = "/tmp/hosts-#{Time.new.to_i}" +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 "run the manifest" +apply_manifest_on agents, manifest + +step "verify the file output" +on(agents, "cat #{out}") do + fail_test "host not found in output" unless stdout.include? name +end diff --git a/acceptance/tests/apply/virtual/should_realize_query_array.rb b/acceptance/tests/apply/virtual/should_realize_query_array.rb new file mode 100755 index 000000000..137d93b1a --- /dev/null +++ b/acceptance/tests/apply/virtual/should_realize_query_array.rb @@ -0,0 +1,24 @@ +test_name "should realize query array" +out = "/tmp/hosts-#{Time.new.to_i}" +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 "run the manifest" +apply_manifest_on agents, manifest + +step "verify the file output" +on(agents, "cat #{out}") do + fail_test "host not found in output" unless stdout.include? name +end diff --git a/acceptance/tests/doc/should_print_function_reference.rb b/acceptance/tests/doc/should_print_function_reference.rb new file mode 100644 index 000000000..3ffcf8097 --- /dev/null +++ b/acceptance/tests/doc/should_print_function_reference.rb @@ -0,0 +1,5 @@ +test_name "verify we can print the function reference" +on(agents, puppet_doc("-r", "function")) do + fail_test "didn't print function reference" unless + stdout.include? 'Function Reference' +end diff --git a/acceptance/tests/doc/ticket_4120_cannot_generate_type_reference.rb b/acceptance/tests/doc/ticket_4120_cannot_generate_type_reference.rb new file mode 100755 index 000000000..7f721c272 --- /dev/null +++ b/acceptance/tests/doc/ticket_4120_cannot_generate_type_reference.rb @@ -0,0 +1,5 @@ +test_name "verify we can print the function reference" +on(agents, puppet_doc("-r", "type")) do + fail_test "didn't print type reference" unless + stdout.include? 'Type Reference' +end diff --git a/acceptance/tests/file_hello_world.rb b/acceptance/tests/file_hello_world.rb new file mode 100644 index 000000000..683ff4672 --- /dev/null +++ b/acceptance/tests/file_hello_world.rb @@ -0,0 +1,22 @@ +# 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}" + +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 "verify the content of the generated files." +on agents, "grep '#{content}' #{filename}" + +step "clean up after our test run." +on agents, "rm -f #{filename}" diff --git a/acceptance/tests/jeff_append_to_array.rb b/acceptance/tests/jeff_append_to_array.rb new file mode 100644 index 000000000..415d59fe8 --- /dev/null +++ b/acceptance/tests/jeff_append_to_array.rb @@ -0,0 +1,19 @@ +# Ported from the acceptance test suite. +test_name "Jeff: Append to Array" + +manifest = %q{ + class parent { + $arr1 = [ "parent array element" ] + } + class parent::child inherits parent { + $arr1 += [ "child array element" ] + notify { $arr1: } + } + include parent::child +} + +apply_manifest_on(agents, manifest) do + stdout =~ /notice: parent array element/ or fail_test("parent missing") + stdout =~ /notice: child array element/ or fail_test("child missing") +end + diff --git a/acceptance/tests/key_compare_puppet_conf_configprint.rb b/acceptance/tests/key_compare_puppet_conf_configprint.rb new file mode 100644 index 000000000..b986d8831 --- /dev/null +++ b/acceptance/tests/key_compare_puppet_conf_configprint.rb @@ -0,0 +1,65 @@ +# Check for the existance of keys found in puppet.conf in +# --configprint all output +# +# Checking against key=>val pairs will cause erroneous errors: +# +# classfile +# Puppet.conf --configprint +# $vardir/classes.txt /var/opt/lib/pe-puppet/classes.txt + +test_name "Validate keys found in puppet.conf vs.--configprint all" + +puppet_conf_h = Hash.new +config_print_h = Hash.new + +# Run tests against Master first +step "Master: get puppet.conf file contents" +on master, "cat /etc/puppetlabs/puppet/puppet.conf | tr -d \" \"" do + stdout.split("\n").select{ |v| v =~ /=/ }.each do |line| + k,v = line.split("=") + puppet_conf_h[k]=v + end +end + +step "Master: get --configprint all output" +on master, puppet_master("--configprint all | tr -d \" \"") do + stdout.split("\n").select{ |v| v =~ /=/ }.each do |line| + k,v = line.split("=") + config_print_h[k]=v + end +end + +step "Master: compare puppet.conf to --configprint output" +puppet_conf_h.each do |k,v| + puts "#{k}: #{puppet_conf_h[k]} #{config_print_h[k]}" + fail_test "puppet.conf contains a key not found in configprint" unless config_print_h.include?(k) + # fail_test "puppet.conf: #{puppet_conf_h[k]} differs from --configprintall: #{config_print_h[k]}" if ( puppet_conf_h[k] != config_print_h[k] ) +end + +# Run test on Agents +agents.each { |agent| + puppet_conf_h.clear + config_print_h.clear + step "Agent #{agent}: get puppet.conf file contents" + on agent, "cat /etc/puppetlabs/puppet/puppet.conf | tr -d \" \"" do + stdout.split("\n").select{ |v| v =~ /=/ }.each do |line| + k,v = line.split("=") + puppet_conf_h[k]=v + end + end + + step "Agent #{agent}: get --configprint all output" + on agent, puppet_agent("--configprint all | tr -d \" \"") do + stdout.split("\n").select{ |v| v =~ /=/ }.each do |line| + k,v = line.split("=") + config_print_h[k]=v + end + end + + step "Agent #{agent}: compare puppet.conf to --configprint output" + puppet_conf_h.each do |k,v| + puts "#{k}: #{puppet_conf_h[k]} #{config_print_h[k]}" + fail_test "puppet.conf contains a key not found in configprint" unless config_print_h.include?(k) + # fail_test "puppet.conf: #{puppet_conf_h[k]} differs from --configprintall: #{config_print_h[k]}" if ( puppet_conf_h[k] != config_print_h[k] ) + 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 new file mode 100644 index 000000000..abb06fbaf --- /dev/null +++ b/acceptance/tests/puppet_apply_a_file_should_create_a_file_and_report_the_md5.rb @@ -0,0 +1,16 @@ +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'}" + +step "clean up #{file} for testing" +on agents, "rm -f #{file}" + +step "run the manifest and verify MD5 was printed" +apply_manifest_on(agents, manifest) do + fail_test "didn't find the content MD5 on output" unless + stdout.include? "defined content as '{md5}098f6bcd4621d373cade4e832627b4f6'" +end + +step "clean up #{file} after testing" +on agents, "rm -f #{file}" diff --git a/acceptance/tests/puppet_apply_basics.rb b/acceptance/tests/puppet_apply_basics.rb new file mode 100644 index 000000000..bbbdefc15 --- /dev/null +++ b/acceptance/tests/puppet_apply_basics.rb @@ -0,0 +1,15 @@ +# Ported from a collection of small spec tests in acceptance. +# +# Unified into a single file because they are literally one-line tests! + +test_name "Trivial puppet tests" + +step "check that puppet apply displays notices" +apply_manifest_on(agents, "notice 'Hello World'") do + stdout =~ /notice:.*Hello World/ or fail_test("missing notice!") +end + +step "verify help displays something for puppet master" +on master, puppet_master("--help") do + stdout =~ /puppet master/ or fail_test("improper help output") +end diff --git a/acceptance/tests/puppet_apply_should_show_a_notice.rb b/acceptance/tests/puppet_apply_should_show_a_notice.rb new file mode 100644 index 000000000..af6f41ca7 --- /dev/null +++ b/acceptance/tests/puppet_apply_should_show_a_notice.rb @@ -0,0 +1,5 @@ +test_name "puppet apply should show a notice" +apply_manifest_on(agents, "notice 'Hello World'") do + fail_test "the notice didn't show" unless + stdout =~ /notice: .*: Hello World/ +end diff --git a/acceptance/tests/puppet_master_help_should_mention_puppet_master.rb b/acceptance/tests/puppet_master_help_should_mention_puppet_master.rb new file mode 100644 index 000000000..ba7b39cb0 --- /dev/null +++ b/acceptance/tests/puppet_master_help_should_mention_puppet_master.rb @@ -0,0 +1,4 @@ +test_name "puppet master help should mention puppet master" +on master, puppet_master('--help') do + fail_test "puppet master wasn't mentioned" unless stdout.include? 'puppet master' +end diff --git a/acceptance/tests/resource/cron/should_create_cron.rb b/acceptance/tests/resource/cron/should_create_cron.rb new file mode 100644 index 000000000..e45561491 --- /dev/null +++ b/acceptance/tests/resource/cron/should_create_cron.rb @@ -0,0 +1,31 @@ +test_name "should create cron" + +tmpuser = "cron-test-#{Time.new.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| + 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 + fail_test "didn't notice creation of the cron stuff" unless + stdout.include? 'created' + end + + step "verify that crontab -l contains what you expected" + on host, "crontab -l -u #{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}" + + 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 new file mode 100755 index 000000000..b34a0498c --- /dev/null +++ b/acceptance/tests/resource/cron/should_match_existing.rb @@ -0,0 +1,40 @@ + + +tmpuser = "cron-test-#{Time.new.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| + step "ensure the user exist via puppet" + apply_manifest_on host, create_user + + step "create the existing job by hand..." + on host, "echo '* * * * * /bin/true' | crontab -u #{tmpuser} -" + + 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. + fail_test "didn't see the output we expected..." unless + stdout.include? 'present' + end + + step "verify that crontab -l contains what you expected" + on host, "crontab -l -u #{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}" + + 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 new file mode 100755 index 000000000..035a0f7b9 --- /dev/null +++ b/acceptance/tests/resource/cron/should_remove_cron.rb @@ -0,0 +1,36 @@ +test_name "puppet should remove a crontab entry as expected" + +tmpuser = "cron-test-#{Time.new.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| + step "ensure the user exist via puppet" + 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} -" + + step "apply the resource on the host using puppet resource" + on(host, puppet_resource("cron", "crontest", "user=#{tmpuser}", + "command=/bin/true", "ensure=absent")) 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 + fail_test "didn't see the output we expected..." unless + stdout.include? 'removed' + 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" + end + + step "remove the crontab file for that user" + on host, "crontab -r -u #{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 new file mode 100755 index 000000000..e669f2959 --- /dev/null +++ b/acceptance/tests/resource/cron/should_remove_matching.rb @@ -0,0 +1,36 @@ +test_name "puppet should remove a crontab entry based on command matching" + +tmpuser = "cron-test-#{Time.new.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| + step "ensure the user exist via puppet" + apply_manifest_on host, create_user + + step "create the existing job by hand..." + on host, "printf '#{cron}' | crontab -u #{tmpuser} -" + + step "apply the resource change on the host" + on(host, puppet_resource("cron", "bogus", "user=#{tmpuser}", + "command=/bin/true", "ensure=absent")) do + fail_test "didn't see the output we expected..." unless + stdout.include? 'removed' + end + + step "verify that crontab -l contains what you expected" + on host, "crontab -l -u #{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}" + + 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 new file mode 100755 index 000000000..3a2a53769 --- /dev/null +++ b/acceptance/tests/resource/cron/should_update_existing.rb @@ -0,0 +1,42 @@ +test_name "puppet should update existing crontab entry" + +tmpuser = "cron-test-#{Time.new.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 }" + +agents.each do |host| + step "ensure the user exist via puppet" + apply_manifest_on host, create_user + + step "create the existing job by hand..." + on host, "printf '#{cron}' | crontab -u #{tmpuser} -" + + step "verify that crontab -l contains what you expected" + on host, "crontab -l -u #{tmpuser}" do + fail_test "didn't find the content in the crontab" unless + stdout.include? '* * * * * /bin/true' + 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 + fail_test "didn't update the time as expected" unless + stdout.include? "defined 'hour' as '0-6'" + end + + step "verify that crontab -l contains what you expected" + on host, "crontab -l -u #{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}" + + step "remove the user from the system" + apply_manifest_on host, delete_user +end diff --git a/acceptance/tests/resource/exec/should_not_run_command_creates.rb b/acceptance/tests/resource/exec/should_not_run_command_creates.rb new file mode 100644 index 000000000..583ae4306 --- /dev/null +++ b/acceptance/tests/resource/exec/should_not_run_command_creates.rb @@ -0,0 +1,34 @@ +test_name "should not run command creates" + +touch = "/tmp/touched-#{Time.new.to_i}" +donottouch = "/tmp/not-touched-#{Time.new.to_i}" + +manifest = %Q{ + exec { "test#{Time.new.to_i}": command => '/bin/touch #{donottouch}', creates => "#{touch}"} +} + +step "prepare the agents for the test" +on agents, "touch #{touch} ; rm -f #{donottouch}" + +step "test using puppet apply" +apply_manifest_on(agents, manifest) do + fail_test "looks like the thing executed, which it shouldn't" if + stdout.include? 'executed successfully' +end + +step "verify the file didn't get created" +on agents, "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 "test using puppet resource" +on(agents, puppet_resource('exec', "test#{Time.new.to_i}", + "command='/bin/touch #{donottouch}'", + "creates='#{touch}'")) do + fail_test "looks like the thing executed, which it shouldn't" if + 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] diff --git a/acceptance/tests/resource/exec/should_run_command.rb b/acceptance/tests/resource/exec/should_run_command.rb new file mode 100644 index 000000000..b7156c6c9 --- /dev/null +++ b/acceptance/tests/resource/exec/should_run_command.rb @@ -0,0 +1,31 @@ +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}" +end + +def after + step "checking the output worked" + on agents, "test -f #{$touch}" + + step "clean up the system" + on agents, "rm -f #{$touch}" +end + +before +apply_manifest_on(agents, "exec {'test': command=>'/bin/touch #{$touch}'}") do + fail_test "didn't seem to run the command" unless + stdout.include? 'executed successfully' +end +after + +before +on(agents, puppet_resource('-d', 'exec', 'test', "command='/bin/touch #{$touch}'")) do + fail_test "didn't seem to run the command" unless + stdout.include? 'executed successfully' +end +after diff --git a/acceptance/tests/resource/exec/should_set_path.rb b/acceptance/tests/resource/exec/should_set_path.rb new file mode 100644 index 000000000..4d9ccb060 --- /dev/null +++ b/acceptance/tests/resource/exec/should_set_path.rb @@ -0,0 +1,16 @@ +test_name "the path statement should work to locate commands" + +file = "/tmp/touched-should-set-path-#{Time.new.to_i}" + +step "clean up the system for the test" +on agents, "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 "verify that the files were created" +on agents, "test -f #{file}" + +step "clean up the system after testing" +on agents, "rm -f #{file}" diff --git a/acceptance/tests/resource/file/content_attribute.rb b/acceptance/tests/resource/file/content_attribute.rb new file mode 100644 index 000000000..4458e07a4 --- /dev/null +++ b/acceptance/tests/resource/file/content_attribute.rb @@ -0,0 +1,37 @@ +test_name "The content attribute" +pass_test "Pass forced pending test failure investigation" + +step "Ensure the test environment is clean" +on agents, 'rm -f /tmp/content_file_test.txt' + +step "When 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"' + +step "Ensure the test environment is clean" +on agents, 'rm -f /tmp/content_file_test.txt' + +step "When using a filebucket 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" + +get_remote_option(agents, 'filebucket', 'bucketdir') do |bucketdir| + manifest = %Q| + filebucket { 'local': + path => '#{bucketdir}', + } + + file { '/tmp/content_file_test.txt': + content => '{md5}18571d3a04b2bb7ccfdbb2c44c72caa9', + ensure => present, + backup => local, + } + | + apply_manifest_on agents, manifest +end + +on agents, 'test "$(cat /tmp/content_file_test.txt)" = "This is the checksum file contents"' diff --git a/acceptance/tests/resource/file/should_create_directory.rb b/acceptance/tests/resource/file/should_create_directory.rb new file mode 100755 index 000000000..859ebb3ba --- /dev/null +++ b/acceptance/tests/resource/file/should_create_directory.rb @@ -0,0 +1,15 @@ +test_name "should create directory" + +target = "/tmp/test-#{Time.new.to_i}" + +step "clean up the system before we begin" +on agents, "rm -vrf #{target}" + +step "verify we can create a directory" +on(agents, puppet_resource("file", target, 'ensure=directory')) + +step "verify the directory was created" +on agents, "test -d #{target}" + +step "clean up after the test run" +on agents, "rm -vrf #{target}" diff --git a/acceptance/tests/resource/file/should_create_empty.rb b/acceptance/tests/resource/file/should_create_empty.rb new file mode 100755 index 000000000..a38c35c2d --- /dev/null +++ b/acceptance/tests/resource/file/should_create_empty.rb @@ -0,0 +1,15 @@ +test_name "should create empty file for 'present'" + +target = "/tmp/test-#{Time.new.to_i}" + +step "clean up the system before we begin" +on agents, "rm -vrf #{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}" + +step "clean up after the test run" +on agents, "rm -vrf #{target}" diff --git a/acceptance/tests/resource/file/should_create_symlink.rb b/acceptance/tests/resource/file/should_create_symlink.rb new file mode 100755 index 000000000..0e58d213b --- /dev/null +++ b/acceptance/tests/resource/file/should_create_symlink.rb @@ -0,0 +1,27 @@ +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 -vrf #{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}" +on agents, "test -f #{source}" + +step "verify the content is identical on both sides" +on(agents, "cat #{source}") do + fail_test "source missing content" unless stdout.include? message +end +on(agents, "cat #{target}") do + fail_test "target missing content" unless stdout.include? message +end + +step "clean up after the test run" +on agents, "rm -vrf #{target} #{source}" diff --git a/acceptance/tests/resource/file/should_remove_dir.rb b/acceptance/tests/resource/file/should_remove_dir.rb new file mode 100755 index 000000000..943410d20 --- /dev/null +++ b/acceptance/tests/resource/file/should_remove_dir.rb @@ -0,0 +1,21 @@ +test_name "should remove directory, but force required" + +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}" + +step "verify we can't remove a directory without 'force'" +on(agents, 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 + +step "verify the directory still exists" +on agents, "test -d #{target}" + +step "verify we can remove a directory with 'force'" +on(agents, puppet_resource("file", target, 'ensure=absent', 'force=true')) + +step "verify that the directory is gone" +on agents, "test -d #{target}", :acceptable_exit_codes => [1] diff --git a/acceptance/tests/resource/file/should_remove_file.rb b/acceptance/tests/resource/file/should_remove_file.rb new file mode 100755 index 000000000..3ad7510ad --- /dev/null +++ b/acceptance/tests/resource/file/should_remove_file.rb @@ -0,0 +1,12 @@ +test_name "should remove file" + +target = "/tmp/test-#{Time.new.to_i}" + +step "clean up the system before we begin" +on agents, "rm -vrf #{target} && touch #{target}" + +step "verify we can remove a file" +on(agents, puppet_resource("file", target, 'ensure=absent')) + +step "verify that the file is gone" +on agents, "test -e #{target}", :acceptable_exit_codes => [1] diff --git a/acceptance/tests/resource/file/source_attribtute.rb b/acceptance/tests/resource/file/source_attribtute.rb new file mode 100644 index 000000000..95a7f36b3 --- /dev/null +++ b/acceptance/tests/resource/file/source_attribtute.rb @@ -0,0 +1,100 @@ +test_name "The source attribute" + +step "Ensure the test environment is clean" +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" + +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."' + +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" + +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" +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, 'test "$(cat /tmp/source_file_test.txt)" = "Yay, this is the puppet:/// file."' + +# 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/group/should_create.rb b/acceptance/tests/resource/group/should_create.rb new file mode 100755 index 000000000..122c31a8f --- /dev/null +++ b/acceptance/tests/resource/group/should_create.rb @@ -0,0 +1,20 @@ +test_name "should create group" + +name = "test-group-#{Time.new.to_i}" + +def cleanup(name) + step "remove group #{name} if it exists" + on agents, "if getent group #{name}; then groupdel #{name}; fi" +end + +cleanup(name) + +step "create the group #{name} with the resource agent" +on(agents, puppet_resource('group', name, 'ensure=present')) + +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]+:/ +end + +cleanup(name) diff --git a/acceptance/tests/resource/group/should_destroy.rb b/acceptance/tests/resource/group/should_destroy.rb new file mode 100755 index 000000000..1551abe75 --- /dev/null +++ b/acceptance/tests/resource/group/should_destroy.rb @@ -0,0 +1,14 @@ +test_name "should destroy a group" + +name = "test-group-#{Time.new.to_i}" + +step "ensure the group exists on the target system" +on agents, "getent group #{name} || groupadd #{name}" + +step "use puppet to remove the group" +on(agents, 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] diff --git a/acceptance/tests/resource/group/should_modify_gid.rb b/acceptance/tests/resource/group/should_modify_gid.rb new file mode 100755 index 000000000..95405b24c --- /dev/null +++ b/acceptance/tests/resource/group/should_modify_gid.rb @@ -0,0 +1,23 @@ +test_name "should modify gid of existing group" + +name = "test-group-#{Time.new.to_i}" +gid = 12345 + +step "ensure that the group exists with gid #{gid}" +on(agents, puppet_resource('group', name, 'ensure=present', "gid=#{gid}")) do + fail_test "missing gid notice" unless stdout =~ /gid +=> +'#{gid}'/ +end + +step "ensure that we can modify the GID of the group to #{gid*2}" +on(agents, puppet_resource('group', name, 'ensure=present', "gid=#{gid*2}")) do + fail_test "missing gid notice" unless stdout =~ /gid +=> +'#{gid*2}'/ +end + +step "verify that the GID changed" +on(agents, "getent group #{name}") do + fail_test "gid is wrong through getent output" unless + stdout =~ /^#{name}:x:#{gid*2}:/ +end + +step "clean up the system after the test run" +on(agents, puppet_resource('group', name, 'ensure=absent')) diff --git a/acceptance/tests/resource/group/should_not_create_existing.rb b/acceptance/tests/resource/group/should_not_create_existing.rb new file mode 100755 index 000000000..ed4f54cdc --- /dev/null +++ b/acceptance/tests/resource/group/should_not_create_existing.rb @@ -0,0 +1,15 @@ +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')) + +step "verify that we don't try and create the existing group" +on(agents, puppet_resource('group', name, 'ensure=present')) do + fail_test "looks like we created the group" if + stdout.include? '/Group[bozo]/ensure: created' +end + +step "clean up the system after the test run" +on(agents, puppet_resource('group', name, 'ensure=absent')) diff --git a/acceptance/tests/resource/group/should_not_destoy_unexisting.rb b/acceptance/tests/resource/group/should_not_destoy_unexisting.rb new file mode 100755 index 000000000..256a8f146 --- /dev/null +++ b/acceptance/tests/resource/group/should_not_destoy_unexisting.rb @@ -0,0 +1,13 @@ +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')) + +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" +end + diff --git a/acceptance/tests/resource/group/should_query.rb b/acceptance/tests/resource/group/should_query.rb new file mode 100755 index 000000000..3bbce071c --- /dev/null +++ b/acceptance/tests/resource/group/should_query.rb @@ -0,0 +1,15 @@ +test_name "group should query" + +name = "test-group-#{Time.new.to_i}" + +step "ensure the group exists on the target systems" +on agents, "getent group #{name} || groupadd #{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 "clean up the system after the test" +on(agents, puppet_resource('group', name, 'ensure=absent')) diff --git a/acceptance/tests/resource/group/should_query_all.rb b/acceptance/tests/resource/group/should_query_all.rb new file mode 100755 index 000000000..9abcfed21 --- /dev/null +++ b/acceptance/tests/resource/group/should_query_all.rb @@ -0,0 +1,30 @@ +test_name "puppet resource should query all groups" + +agents.each do |host| + groups = {} + + 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 + + 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] + + if groups.include? name then + groups.delete name + else + fail_test "group #{name} found by puppet, not getent" + end + end + end + end + + groups.keys.each do |name| + fail_test "group #{name} found by getent, not puppet" + end +end diff --git a/acceptance/tests/resource/host/should_create.rb b/acceptance/tests/resource/host/should_create.rb new file mode 100755 index 000000000..d5bd9e6e7 --- /dev/null +++ b/acceptance/tests/resource/host/should_create.rb @@ -0,0 +1,15 @@ +test_name "host should create" + +target = "/tmp/host-#{Time.new.to_i}" + +step "clean up for the test" +on agents, "rm -vf #{target}" + +step "create the host record" +on(agents, 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 + fail_test "record was not present" unless stdout =~ /^127\.0\.0\.1[[:space:]]+test/ +end diff --git a/acceptance/tests/resource/host/should_create_aliases.rb b/acceptance/tests/resource/host/should_create_aliases.rb new file mode 100755 index 000000000..4cc0014f6 --- /dev/null +++ b/acceptance/tests/resource/host/should_create_aliases.rb @@ -0,0 +1,16 @@ +test_name "host should create aliases" + +target = "/tmp/host-#{Time.new.to_i}" + +step "clean up the system for testing" +on agents, "rm -vf #{target}" + +step "create the record" +on(agents, 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 + fail_test "alias was missing" unless + stdout =~ /^127\.0\.0\.7[[:space:]]+test[[:space:]]alias/ +end diff --git a/acceptance/tests/resource/host/should_destroy.rb b/acceptance/tests/resource/host/should_destroy.rb new file mode 100755 index 000000000..451b2d061 --- /dev/null +++ b/acceptance/tests/resource/host/should_destroy.rb @@ -0,0 +1,19 @@ +test_name "should be able to remove a host record" + +file = "/tmp/hosts-#{Time.new.to_i}" +line = "127.0.0.7 test1" + +step "set up files for the test" +on agents, "printf '#{line}\n' > #{file}" + +step "delete the resource from the file" +on(agents, 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 + fail_test "the content was still present" if stdout.include? line +end + +step "clean up after the test" +on agents, "rm -vf #{file}" diff --git a/acceptance/tests/resource/host/should_modify_alias.rb b/acceptance/tests/resource/host/should_modify_alias.rb new file mode 100755 index 000000000..312078fef --- /dev/null +++ b/acceptance/tests/resource/host/should_modify_alias.rb @@ -0,0 +1,19 @@ +test_name "should be able to modify a host alias" + +file = "/tmp/hosts-#{Time.new.to_i}" + +step "set up files for the test" +on agents, "printf '127.0.0.8 test alias\n' > #{file}" + +step "modify the resource" +on(agents, 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 + fail_test "the alias was not updated" unless + stdout =~ /^127\.0\.0\.8[[:space:]]+test[[:space:]]+banzai[[:space:]]*$/ +end + +step "clean up after the test" +on agents, "rm -vf #{file}" diff --git a/acceptance/tests/resource/host/should_modify_ip.rb b/acceptance/tests/resource/host/should_modify_ip.rb new file mode 100755 index 000000000..b16db5979 --- /dev/null +++ b/acceptance/tests/resource/host/should_modify_ip.rb @@ -0,0 +1,19 @@ +test_name "should be able to modify a host address" + +file = "/tmp/hosts-#{Time.new.to_i}" + +step "set up files for the test" +on agents, "printf '127.0.0.9 test alias\n' > #{file}" + +step "modify the resource" +on(agents, 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 + fail_test "the address was not updated" unless + stdout =~ /^127\.0\.0\.10[[:space:]]+test[[:space:]]+alias[[:space:]]*$/ +end + +step "clean up after the test" +on agents, "rm -vf #{file}" diff --git a/acceptance/tests/resource/host/should_not_create_existing.rb b/acceptance/tests/resource/host/should_not_create_existing.rb new file mode 100755 index 000000000..c8a40df93 --- /dev/null +++ b/acceptance/tests/resource/host/should_not_create_existing.rb @@ -0,0 +1,17 @@ +test_name "should not create host if it exists" + +file = "/tmp/hosts-#{Time.new.to_i}" + +step "set up the system for the test" +on agents, "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}", + '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 -vf #{file}" + diff --git a/acceptance/tests/resource/host/should_query.rb b/acceptance/tests/resource/host/should_query.rb new file mode 100755 index 000000000..983812ce0 --- /dev/null +++ b/acceptance/tests/resource/host/should_query.rb @@ -0,0 +1,15 @@ +test_name "should query hosts out of a hosts file" + +file = "/tmp/hosts-#{Time.new.to_i}" + +step "set up the system for the test" +on agents, "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 + found = stdout.scan('present').length + fail_test "found #{found} hosts, not 1" if found != 1 +end + +step "clean up the system" +on agents, "rm -vf #{file}" diff --git a/acceptance/tests/resource/host/should_query_all.rb b/acceptance/tests/resource/host/should_query_all.rb new file mode 100755 index 000000000..654883aa0 --- /dev/null +++ b/acceptance/tests/resource/host/should_query_all.rb @@ -0,0 +1,26 @@ +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}" + +step "configure the system for testing (including file backups)" +on agents, "cp /etc/hosts #{backup}" +on agents, "cat > /etc/hosts", :stdin => content + +step "query all host records using puppet" +on(agents, 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} + + count = stdout.scan(/ensure\s+=>\s+'present'/).length + fail_test "found #{count} records, wanted 4" unless count == 4 +end + +step "clean up the system afterwards" +on agents, "mv -vf #{backup} /etc/hosts" 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 new file mode 100755 index 000000000..9223da665 --- /dev/null +++ b/acceptance/tests/resource/host/ticket_4131_should_not_create_without_ip.rb @@ -0,0 +1,21 @@ +test_name "#4131: should not create host without IP attribute" + +file = "/tmp/hosts-#{Time.new.to_i}" + +step "configure the target system for the test" +on agents, "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}", + "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 + +step "verify that the host was not added to the file" +on(agents, "cat #{file} ; rm -f #{file}") do + fail_test "the host was apparently added to the file" if stdout.include? 'test' +end diff --git a/acceptance/tests/resource/service/ticket_4123_should_list_all_running_redhat.rb b/acceptance/tests/resource/service/ticket_4123_should_list_all_running_redhat.rb new file mode 100755 index 000000000..b4c2bc14d --- /dev/null +++ b/acceptance/tests/resource/service/ticket_4123_should_list_all_running_redhat.rb @@ -0,0 +1,12 @@ +test_name "#4123: should list all running services on Redhat/CentOS" +step "Validate services running agreement ralsh vs. OS service count" +# This will remotely exec: +# ticket_4123_should_list_all_running_redhat.sh + +hosts.each do |host| + unless host['platform'].include? 'centos' or host['platform'].include? 'redhat' + skip_test "Test not supported on this plaform" + else + run_script_on(host,'tests/acceptance/resource/service/ticket_4123_should_list_all_running_redhat.sh') + end +end diff --git a/acceptance/tests/resource/service/ticket_4123_should_list_all_running_redhat.sh b/acceptance/tests/resource/service/ticket_4123_should_list_all_running_redhat.sh new file mode 100755 index 000000000..1d5e49524 --- /dev/null +++ b/acceptance/tests/resource/service/ticket_4123_should_list_all_running_redhat.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# A platform must be specified the only command line arg +# This will facilitate expansion of this tests to include +# the ability to test other OSes + +#if [ -z $1 ] ; then +# echo "No platform specified" +# exit 1 +#fi + +# redhat or centos only +#if echo $1 | grep -e centos -e redhat + RALSH_FILE=/tmp/ralsh-running-list-$$ + SERVICE_FILE=/tmp/service-running-list-$$ + + puppet resource service | egrep -B1 "ensure\s*=>\s*'running" | grep 'service {' | gawk -F"\'" '{print $2}' | sort > $RALSH_FILE + + if [ -e $SERVICE_FILE ]; then + rm $SERVICE_FILE + fi + SERVICEDIR='/etc/init.d' + for SERVICE in $( ls $SERVICEDIR | sort | egrep -v "(functions|halt|killall|single|linuxconf)" ) ; do + if env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "${SERVICEDIR}/${SERVICE}" status; then + echo $SERVICE >> $SERVICE_FILE + fi + done + + if diff $RALSH_FILE $SERVICE_FILE ; then + echo "Ralsh and system service count agree" + exit 0 + else + echo "Ralsh and system service count NOT in agreement" + exit 1 + fi +#fi # end redhat/centos diff --git a/acceptance/tests/resource/service/ticket_4124_should_list_all_disabled.rb b/acceptance/tests/resource/service/ticket_4124_should_list_all_disabled.rb new file mode 100755 index 000000000..4add108ff --- /dev/null +++ b/acceptance/tests/resource/service/ticket_4124_should_list_all_disabled.rb @@ -0,0 +1,12 @@ +test_name "#4124: should list all disabled services on Redhat/CentOS" +step "Validate disabled services agreement ralsh vs. OS service count" +# This will remotely exec: +# ticket_4124_should_list_all_disabled.sh + +hosts.each do |host| + unless host['platform'].include? 'centos' or host['platform'].include? 'redhat' + skip_test "Test not supported on this plaform" + else + run_script_on(host,'tests/acceptance/resource/service/ticket_4124_should_list_all_disabled.sh') + end +end diff --git a/acceptance/tests/resource/service/ticket_4124_should_list_all_disabled.sh b/acceptance/tests/resource/service/ticket_4124_should_list_all_disabled.sh new file mode 100755 index 000000000..7cc463d5e --- /dev/null +++ b/acceptance/tests/resource/service/ticket_4124_should_list_all_disabled.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# A platform must be specified the only command line arg +# This will facilitate expansion of this tests to include +# the ability to test other OSes + +#if [ -z $1 ] ; then +# echo "No platform specified" +# exit 1 +#fi + +# redhat or centos only +#if echo $1 | grep -e centos -e redhat + RALSH_FILE=/tmp/ralsh-disabled-list-$$ + SERVICE_FILE=/tmp/service-disabled-list-$$ + + # collect all service namevars + puppet resource service | egrep -B2 "enable\s*=>\s*'false" | grep "service {" | awk -F"'" '{print $2}' | sort > $RALSH_FILE + + if [ -e $SERVICE_FILE ]; then + rm $SERVICE_FILE + fi + SERVICEDIR='/etc/init.d' + for SERVICE in $( ls $SERVICEDIR | sort | egrep -v "(functions|halt|killall|single|linuxconf)" ) ; do + if ! chkconfig $SERVICE; then + echo $SERVICE >> $SERVICE_FILE + fi + done + + if diff $RALSH_FILE $SERVICE_FILE ; then + echo "Ralsh and system service count agree" + exit 0 + else + echo "Ralsh and system service count NOT in agreement" + exit 1 + fi +#fi # end redhat/centos diff --git a/acceptance/tests/resource/user/should_create.rb b/acceptance/tests/resource/user/should_create.rb new file mode 100755 index 000000000..062883da3 --- /dev/null +++ b/acceptance/tests/resource/user/should_create.rb @@ -0,0 +1,20 @@ +test_name "should create a user, and the default matching group" +# REVISIT: This is a direct port of the original test, but it contains a +# non-portable assumption that "user private groups" are used by default by +# everything that we target. --daniel 2010-12-24 + +name = "test-user-#{Time.new.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" + +step "ask puppet to create the user" +on(agents, puppet_resource('user', name, 'ensure=present')) + +step "verify that the user and group now exist" +on agents, "getent passwd #{name} && getent group #{name}" + +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" diff --git a/acceptance/tests/resource/user/should_create_with_gid.rb b/acceptance/tests/resource/user/should_create_with_gid.rb new file mode 100755 index 000000000..be36bf4e6 --- /dev/null +++ b/acceptance/tests/resource/user/should_create_with_gid.rb @@ -0,0 +1,30 @@ +test_name "verifies that puppet resource creates a user and assigns the correct group" + +user = "test-user-#{Time.new.to_i}" +group = "test-user-#{Time.new.to_i}-group" + +agents.each do |host| + step "user should not exist" + on host, "if getent passwd #{user}; then userdel #{user}; fi" + + step "group should exist" + on host, "if ! getent group #{group}; then groupadd #{group}; fi" + + 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 diff --git a/acceptance/tests/resource/user/should_destroy.rb b/acceptance/tests/resource/user/should_destroy.rb new file mode 100755 index 000000000..8ba7ace41 --- /dev/null +++ b/acceptance/tests/resource/user/should_destroy.rb @@ -0,0 +1,19 @@ +test_name "verify that puppet resource correctly destroys users" + +user = "test-user-#{Time.new.to_i}" +group = user + +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}")) + +step "try and delete the user" +on(agents, puppet_resource('user', user, '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}:" +end + +step "remove the group as well..." +on(agents, puppet_resource('group', group, 'ensure=absent')) diff --git a/acceptance/tests/resource/user/should_modify_gid.rb b/acceptance/tests/resource/user/should_modify_gid.rb new file mode 100755 index 000000000..6aba4aa7a --- /dev/null +++ b/acceptance/tests/resource/user/should_modify_gid.rb @@ -0,0 +1,41 @@ +test_name "verify that we can modify the gid" + +user = "test-user-#{Time.new.to_i}" +group1 = "#{user}-old" +group2 = "#{user}-new" + +agents.each do |host| + 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 diff --git a/acceptance/tests/resource/user/should_not_create_existing.rb b/acceptance/tests/resource/user/should_not_create_existing.rb new file mode 100755 index 000000000..2f33a94df --- /dev/null +++ b/acceptance/tests/resource/user/should_not_create_existing.rb @@ -0,0 +1,6 @@ +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' +end diff --git a/acceptance/tests/resource/user/should_not_destoy_unexisting.rb b/acceptance/tests/resource/user/should_not_destoy_unexisting.rb new file mode 100755 index 000000000..ceeea7da1 --- /dev/null +++ b/acceptance/tests/resource/user/should_not_destoy_unexisting.rb @@ -0,0 +1,11 @@ +test_name "ensure that puppet does not report removing a user that does not exist" + +name = "test-user-#{Time.new.to_i}" + +step "verify that user #{name} does not exist" +on agents, "getent passwd #{name}", :acceptable_exit_codes => [2] + +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' +end diff --git a/acceptance/tests/resource/user/should_query.rb b/acceptance/tests/resource/user/should_query.rb new file mode 100755 index 000000000..6e2df534d --- /dev/null +++ b/acceptance/tests/resource/user/should_query.rb @@ -0,0 +1,15 @@ +test_name "test that we can query and find a user that exists." + +name = "test-user-#{Time.new.to_i}" + +step "ensure that our test user exists" +on(agents, puppet_resource('user', name, 'ensure=present')) + +step "query for the resource and verify it was found" +on(agents, puppet_resource('user', name)) do + fail_test "didn't find the user #{name}" unless stdout.include? 'present' +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')) diff --git a/acceptance/tests/resource/user/should_query_all.rb b/acceptance/tests/resource/user/should_query_all.rb new file mode 100755 index 000000000..00d7b25c4 --- /dev/null +++ b/acceptance/tests/resource/user/should_query_all.rb @@ -0,0 +1,30 @@ +test_name "ensure that puppet queries the correct number of users" + +agents.each do |host| + users = [] + + 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 + + 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] + + # 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 + end + + if users.length > 0 then + fail_test "#{users.length} users found with getent, 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 new file mode 100644 index 000000000..1b0b537bf --- /dev/null +++ b/acceptance/tests/stages/ticket_4655_default_stage_for_classes.rb @@ -0,0 +1,39 @@ +test_name "#4655: Allow setting the default stage for parameterized classes" + +temp_file_name = "/tmp/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', + } +} +class { in_one: stage => "one" } + +class in_two( $stage=two ){ + exec { "echo 'in_two' >> #{temp_file_name}": + path => '/usr/bin:/bin', + } +} +class { in_two: } + +class in_three { + exec { "echo 'in_three' >> #{temp_file_name}": + path => '/usr/bin:/bin', + } +} +class { "in_three": stage => "three" } +HERE + +expected_results = "in_one +in_two +in_three +" +apply_manifest_on agents, test_manifest + +on(agents, "cat #{temp_file_name}").each do |result| + assert_equal(expected_results, "#{result.stdout}", "Unexpected result for host '#{result.host}'") +end diff --git a/acceptance/tests/ticket_3172_puppet_kick_with_hostnames_on_the_command_line.rb b/acceptance/tests/ticket_3172_puppet_kick_with_hostnames_on_the_command_line.rb new file mode 100644 index 000000000..436ce29fe --- /dev/null +++ b/acceptance/tests/ticket_3172_puppet_kick_with_hostnames_on_the_command_line.rb @@ -0,0 +1,7 @@ +test_name "#3172: puppet kick with hostnames on the command line" +step "verify that we trigger our host" + +target = 'working.example.org' +on(agents, puppet_kick(target), :acceptable_exit_codes => [3]) { + fail_test "didn't trigger #{target}" unless stdout.include? "Triggering #{target}" +} diff --git a/acceptance/tests/ticket_3656_requiring_multiple_resources.rb b/acceptance/tests/ticket_3656_requiring_multiple_resources.rb new file mode 100644 index 000000000..754e6415b --- /dev/null +++ b/acceptance/tests/ticket_3656_requiring_multiple_resources.rb @@ -0,0 +1,8 @@ +test_name "#3656: requiring multiple resources" +apply_manifest_on agents, %q{ + notify { 'foo': } + notify { 'bar': } + notify { 'baz': + require => [Notify['foo'], Notify['bar']], + } +} diff --git a/acceptance/tests/ticket_4059_ralsh_can_change_settings.rb b/acceptance/tests/ticket_4059_ralsh_can_change_settings.rb new file mode 100644 index 000000000..c97bbdbe6 --- /dev/null +++ b/acceptance/tests/ticket_4059_ralsh_can_change_settings.rb @@ -0,0 +1,20 @@ +test_name "#4059: ralsh can change settings" + +target = "/tmp/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 "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 +on(agents, "cat #{target}") do + stdout =~ /^127\.0\.0\.1\s+example\.com/ or + fail_test("missing host record in #{target}") +end + +step "cleanup at the end of the test" +on agents, "rm -f #{target}" diff --git a/acceptance/tests/ticket_4110_puppet_apply_should_not_create_a_user_that_already_exists.rb b/acceptance/tests/ticket_4110_puppet_apply_should_not_create_a_user_that_already_exists.rb new file mode 100644 index 000000000..9704250d9 --- /dev/null +++ b/acceptance/tests/ticket_4110_puppet_apply_should_not_create_a_user_that_already_exists.rb @@ -0,0 +1,5 @@ +test_name "#4110: puppet apply should not create a user that already exists" + +apply_manifest_on(agents, "user { 'root': ensure => 'present' }") do + fail_test("we tried to create root on this host") if stdout =~ /created/ +end diff --git a/acceptance/tests/ticket_4233_resource_with_a_newline.rb b/acceptance/tests/ticket_4233_resource_with_a_newline.rb new file mode 100644 index 000000000..7bb7dc3c3 --- /dev/null +++ b/acceptance/tests/ticket_4233_resource_with_a_newline.rb @@ -0,0 +1,13 @@ +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. +apply_manifest_on(agents, 'exec { \'/bin/echo -e "\nHello World\n"\': }') do + stdout =~ /err:/ and fail_test("error report in output, sorry") +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 new file mode 100644 index 000000000..d2297fbc4 --- /dev/null +++ b/acceptance/tests/ticket_4285_file_resource_fail_when_name_defined_instead_of_path.rb @@ -0,0 +1,17 @@ +test_name "Bug #4285: ArgumentError: Cannot alias File[mytitle] to [nil]" + +manifest = %q{ + file { "file1": + name => '/tmp/file1', + source => "/tmp/", + } + + file { "file2": + name => '/tmp/file2', + source => "/tmp/", + } +} + +apply_manifest_on(agents, manifest) do + fail_test "found the bug report output" if stdout =~ /Cannot alias/ +end diff --git a/acceptance/tests/ticket_4287_undefined_method_evaluate_match_when_function_call_used_in_an_if_statement.rb b/acceptance/tests/ticket_4287_undefined_method_evaluate_match_when_function_call_used_in_an_if_statement.rb new file mode 100644 index 000000000..e9a17df36 --- /dev/null +++ b/acceptance/tests/ticket_4287_undefined_method_evaluate_match_when_function_call_used_in_an_if_statement.rb @@ -0,0 +1,13 @@ +test_name "Bug #4287: undefined method 'evaluate_match' when function call used in an 'if' statement" + +manifest = %q{ + $foo='abc' + if $foo != regsubst($foo,'abc','def') { + notify { 'No issue here...': } + } +} + +apply_manifest_on(agents, manifest) do + fail_test "didn't get the expected notice" unless + stdout.include? 'notice: No issue here...' +end diff --git a/acceptance/tests/ticket_4289_facter_should_recognize_OEL_operatingsystemrelease.rb b/acceptance/tests/ticket_4289_facter_should_recognize_OEL_operatingsystemrelease.rb new file mode 100644 index 000000000..653fcb274 --- /dev/null +++ b/acceptance/tests/ticket_4289_facter_should_recognize_OEL_operatingsystemrelease.rb @@ -0,0 +1,21 @@ +# 2010-08-02 Nan Liu +# +# http://projects.puppetlabs.com/issues/4289 +# +# NL: Facter should return OS version instead of kernel version for OEL +# test script only applicable to OEL, provided based on ticked info, not verified. + +test_name "#4289: facter should recognize OEL operatingsystemrelease" + +# REVISIT: We don't actually have support for this yet - we need a "not +# applicable" option, I guess, that can be based on detected stuff, which is +# cleaner than this is... --daniel 2010-12-22 +agents.each do |host| + step "determine the operating system of #{host}" + on host, facter("operatingsystem") + if stdout =~ /oel/i then + step "test operatingsystemrelease fact on OEL host #{host}" + on host, facter("operatingsystemrelease") + stdout =~ /^\d\.\d$/ or fail_test "operatingsystemrelease not as expected" + end +end diff --git a/acceptance/tests/ticket_4293_define_and_use_a_define_within_a_class.rb b/acceptance/tests/ticket_4293_define_and_use_a_define_within_a_class.rb new file mode 100644 index 000000000..830da99b4 --- /dev/null +++ b/acceptance/tests/ticket_4293_define_and_use_a_define_within_a_class.rb @@ -0,0 +1,22 @@ +# 2010-07-22 Jeff McCune +# +# AffectedVersion: 2.6.0rc4 +# FixedVersion: 2.6.0 +# +# Description: using a defined type in the class it's declared in +# causes an error. + +manifest = < "a_message_for_you" } +} +include foo +PP + +apply_manifest_on(agents, manifest) do + stdout =~ /notice.*?Foo::Do_notify.*?a_message_for_you/ or + fail_test("the notification didn't show up in stdout") +end diff --git a/acceptance/tests/ticket_4404_should_allow_stage_main_on_left_side_of_relationship.rb b/acceptance/tests/ticket_4404_should_allow_stage_main_on_left_side_of_relationship.rb new file mode 100644 index 000000000..db7d5a4d3 --- /dev/null +++ b/acceptance/tests/ticket_4404_should_allow_stage_main_on_left_side_of_relationship.rb @@ -0,0 +1,21 @@ +# Jeff McCune +# 2010-07-29 +# +# AffectedVersion: <= 2.6.0rc1 +# FixedVersion: +# +# This specification makes sure the syntax: +# Stage[main] -> Stage[last] +# works as expected + +apply_manifest_on agents, %q{ + stage { [ "pre", "post" ]: } + Stage["pre"] -> Stage["main"] -> Stage["post"] + class one { notify { "class one, first stage": } } + class two { notify { "class two, second stage": } } + class three { notify { "class three, third stage": } } + class { "one": stage => pre } + class { "two": } + class { "three": stage => post } +} + diff --git a/acceptance/tests/ticket_4423_cannot_declare_two_parameterized_classes.rb b/acceptance/tests/ticket_4423_cannot_declare_two_parameterized_classes.rb new file mode 100644 index 000000000..4c4111dfb --- /dev/null +++ b/acceptance/tests/ticket_4423_cannot_declare_two_parameterized_classes.rb @@ -0,0 +1,50 @@ +# Jeff McCune +# 2010-07-31 +# +# AffectedVersion: 2.6.0, 2.6.1rc1 +# FixedVersion: +# +# Make sure two parameterized classes are able to be declared. + +test_name "#4423: cannot declare two parameterized classes" + +class1 = %q{ + class rainbow($color) { + notify { "color": message => "Color is [${color}]" } + } + class { "rainbow": color => "green" } +} + +class2 = %q{ + class planet($moons) { + notify { "planet": message => "Moons are [${moons}]" } + } + class { "planet": moons => "1" } +} + +step "Declaring one parameterized class works just fine" +apply_manifest_on(agents, class1) + +step "Make sure we try both classes stand-alone" +apply_manifest_on(agents, class2) + +step "Putting both classes in the same manifest should work." +apply_manifest_on agents, class1 + class2 + +step "Putting both classes in the same manifest should work." +apply_manifest_on agents, class1+class2+%q{ + + class rainbow::location($prism=false, $water=true) { + notify { "${name}": + message => "prism:[${prism}] water:[${water}]"; + } + } + class { "rainbow::location": prism => true, water => false; } + + class rainbow::type($pretty=true, $ugly=false) { + notify { "${name}": + message => "pretty:[${pretty}] ugly:[${ugly}]"; + } + } + class { "rainbow::type": pretty => false, ugly => true; } +} diff --git a/acceptance/tests/ticket_5477_master_not_dectect_sitepp.rb b/acceptance/tests/ticket_5477_master_not_dectect_sitepp.rb new file mode 100644 index 000000000..d05735e50 --- /dev/null +++ b/acceptance/tests/ticket_5477_master_not_dectect_sitepp.rb @@ -0,0 +1,43 @@ +# In 2.6, compile does not fail when site.pp does not exist. +# +# However, if a catalog is compiled when site.pp does not exist, +# puppetmaster does not detect when site.pp is created. This requires a restart +# + +test_name "Ticket 5477, Puppet Master does not detect newly created site.pp file" + +# Kill running Puppet Master +step "Master: kill running Puppet Master" +on master, "ps -U puppet | awk '/puppet/ { print \$1 }' | xargs kill" + +# Run tests against Master first +step "Master: mv site.pp file to /tmp, if existing" +on master, "if [ -e /etc/puppet/manifests/site.pp ] ; then mv /etc/puppet/manifests/site.pp /tmp/site.pp-5477 ; fi" + +# Start Puppet Master +#step "Master: Run Puppet Master in verbose mode" +#on master, puppet_master("--verbose") +step "Master: Start Puppet Master" +on master, puppet_master("--certdnsnames=\"puppet:$(hostname -s):$(hostname -f)\" --verbose") + +# Allow puppet server to start accepting conections +sleep 10 + +# Run test on Agents +step "Agent: agent --test" +agents.each { |agent| + on agent, puppet_agent("--test") +} + +# Create a new site.pp +step "Master: create basic site.pp file" +on master, "echo 'notify{ticket_5477_notify:}' > /etc/puppet/manifests/site.pp" + +sleep 20 + +step "Agent: puppet agent --test" +agents.each { |agent| + on agent, "puppet agent -t", :acceptable_exit_codes => [2] + fail_test "Site.pp not detect at Master?" unless + stdout.include? 'ticket_5477_notify' +} diff --git a/acceptance/tests/ticket_6418_file_recursion_and_audit.rb b/acceptance/tests/ticket_6418_file_recursion_and_audit.rb new file mode 100644 index 000000000..f0a55d029 --- /dev/null +++ b/acceptance/tests/ticket_6418_file_recursion_and_audit.rb @@ -0,0 +1,22 @@ +# 2011-02-23 +# +# AffectedVersion: 2.6.0-2.6.5 +# FixedVersion: +# + +test_name "#6418: file recursion and audit" + +on agents, "rm -f /var/lib/puppet/state/state.yaml " +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"] +} + +step "Apply the manifest" +apply_manifest_on agents, manifest +on agents, "! grep ensure.*directory /var/lib/puppet/state/state.yaml" diff --git a/acceptance/tests/ticket_6541_invalid_filebucket_files.rb b/acceptance/tests/ticket_6541_invalid_filebucket_files.rb new file mode 100644 index 000000000..25bcff452 --- /dev/null +++ b/acceptance/tests/ticket_6541_invalid_filebucket_files.rb @@ -0,0 +1,26 @@ +test_name "start with a file" +manifest = "file { '/tmp/6541': content => 'some text' }" +apply_manifest_on(agents, manifest) + +test_name "verify invalid hashes should not change the file" +manifest = "file { '/tmp/6541': content => '{md5}notahash' }" +apply_manifest_on(agents, manifest) do + fail_test "shouldn't have overwrote the file" if + stdout =~ /content changed/ +end + +test_name "verify valid but unbucketed hashes should not change the file" +manifest = "file { '/tmp/6541': content => '{md5}13ad7345d56b566a4408ffdcd877bc78' }" +apply_manifest_on(agents, manifest) do + fail_test "shouldn't have overwrote the file" if + stdout =~ /content changed/ +end + +on(agents, puppet_filebucket("backup -l /dev/null") ) + +test_name "verify that an empty file can be retrieved from the filebucket" +manifest = "file { '/tmp/6541': content => '{md5}d41d8cd98f00b204e9800998ecf8427e' }" +apply_manifest_on(agents, manifest) do + fail_test "shouldn't have overwrote the file" unless + stdout =~ /content changed '\{md5\}552e21cd4cd9918678e3c1a0df491bc3' to '\{md5\}d41d8cd98f00b204e9800998ecf8427e'/ +end diff --git a/acceptance/tests/ticket_6734_6256_5530_5503.rb b/acceptance/tests/ticket_6734_6256_5530_5503.rb new file mode 100644 index 000000000..fe8866901 --- /dev/null +++ b/acceptance/tests/ticket_6734_6256_5530_5503.rb @@ -0,0 +1,16 @@ +# Puppet master fails to start due to impropper +# permissons on the puppet/ dir. Specially, the rrd +# sub dir is not created when puppet master starts + +test_name "Tickets 6734 6256 5530 5503i Puppet Master fails to start" + +# Kill running Puppet Master +step "Check for running Puppet Master" +on master, "ps -ef | grep puppet" + fail_test "Puppet Master not running" unless + stdout.include? 'master' + +step "Check permissions on puppet/rrd/" +on master, "ls -l /var/lib/puppet | grep rrd | awk '{print $3\" \"$4}'" + fail_test "puppet/rrd does not exist/wrong permission" unless + stdout.include? 'puppet puppet'