From ac428b9557e2da251e4b51e48de844833ca0aa2a Mon Sep 17 00:00:00 2001 From: Dominic Maraglia Date: Wed, 20 Apr 2011 14:58:26 -0700 Subject: Move tests from Puppet-acceptance repo --- .../ticket_4149_parseonly_should_not_fail.rb | 18 ++++ ...return_true_for_unrealized_virtual_resources.rb | 24 +++++ ...ionship_syntax_should_work_with_title_arrays.rb | 15 ++++ .../tests/apply/classes/parameterized_classes.rb | 56 ++++++++++++ .../apply/classes/should_allow_param_override.rb | 20 +++++ .../classes/should_allow_param_undef_override.rb | 29 ++++++ .../classes/should_include_resources_from_class.rb | 11 +++ ...should_not_auto_include_resources_from_class.rb | 6 ++ .../apply/conditionals/should_evaluate_else.rb | 15 ++++ .../apply/conditionals/should_evaluate_elsif.rb | 15 ++++ .../apply/conditionals/should_evaluate_empty.rb | 12 +++ .../apply/conditionals/should_evaluate_false.rb | 12 +++ .../tests/apply/conditionals/should_evaluate_if.rb | 15 ++++ .../conditionals/should_evaluate_strings_true.rb | 13 +++ .../apply/conditionals/should_evaluate_undef.rb | 11 +++ .../tests/apply/hashes/should_not_reassign.rb | 10 +++ acceptance/tests/apply/virtual/should_realize.rb | 22 +++++ .../apply/virtual/should_realize_complex_query.rb | 36 ++++++++ .../tests/apply/virtual/should_realize_many.rb | 22 +++++ .../tests/apply/virtual/should_realize_query.rb | 24 +++++ .../apply/virtual/should_realize_query_array.rb | 24 +++++ .../tests/doc/should_print_function_reference.rb | 5 ++ .../ticket_4120_cannot_generate_type_reference.rb | 5 ++ acceptance/tests/file_hello_world.rb | 22 +++++ acceptance/tests/jeff_append_to_array.rb | 19 ++++ .../tests/key_compare_puppet_conf_configprint.rb | 65 ++++++++++++++ ...file_should_create_a_file_and_report_the_md5.rb | 16 ++++ acceptance/tests/puppet_apply_basics.rb | 15 ++++ .../tests/puppet_apply_should_show_a_notice.rb | 5 ++ ...pet_master_help_should_mention_puppet_master.rb | 4 + .../tests/resource/cron/should_create_cron.rb | 31 +++++++ .../tests/resource/cron/should_match_existing.rb | 40 +++++++++ .../tests/resource/cron/should_remove_cron.rb | 36 ++++++++ .../tests/resource/cron/should_remove_matching.rb | 36 ++++++++ .../tests/resource/cron/should_update_existing.rb | 42 +++++++++ .../exec/should_not_run_command_creates.rb | 34 +++++++ .../tests/resource/exec/should_run_command.rb | 31 +++++++ acceptance/tests/resource/exec/should_set_path.rb | 16 ++++ .../tests/resource/file/content_attribute.rb | 37 ++++++++ .../tests/resource/file/should_create_directory.rb | 15 ++++ .../tests/resource/file/should_create_empty.rb | 15 ++++ .../tests/resource/file/should_create_symlink.rb | 27 ++++++ .../tests/resource/file/should_remove_dir.rb | 21 +++++ .../tests/resource/file/should_remove_file.rb | 12 +++ .../tests/resource/file/source_attribtute.rb | 100 +++++++++++++++++++++ acceptance/tests/resource/group/should_create.rb | 20 +++++ acceptance/tests/resource/group/should_destroy.rb | 14 +++ .../tests/resource/group/should_modify_gid.rb | 23 +++++ .../resource/group/should_not_create_existing.rb | 15 ++++ .../resource/group/should_not_destoy_unexisting.rb | 13 +++ acceptance/tests/resource/group/should_query.rb | 15 ++++ .../tests/resource/group/should_query_all.rb | 30 +++++++ acceptance/tests/resource/host/should_create.rb | 15 ++++ .../tests/resource/host/should_create_aliases.rb | 16 ++++ acceptance/tests/resource/host/should_destroy.rb | 19 ++++ .../tests/resource/host/should_modify_alias.rb | 19 ++++ acceptance/tests/resource/host/should_modify_ip.rb | 19 ++++ .../resource/host/should_not_create_existing.rb | 17 ++++ acceptance/tests/resource/host/should_query.rb | 15 ++++ acceptance/tests/resource/host/should_query_all.rb | 26 ++++++ .../ticket_4131_should_not_create_without_ip.rb | 21 +++++ .../ticket_4123_should_list_all_running_redhat.rb | 12 +++ .../ticket_4123_should_list_all_running_redhat.sh | 36 ++++++++ .../ticket_4124_should_list_all_disabled.rb | 12 +++ .../ticket_4124_should_list_all_disabled.sh | 37 ++++++++ acceptance/tests/resource/user/should_create.rb | 20 +++++ .../tests/resource/user/should_create_with_gid.rb | 30 +++++++ acceptance/tests/resource/user/should_destroy.rb | 19 ++++ .../tests/resource/user/should_modify_gid.rb | 41 +++++++++ .../resource/user/should_not_create_existing.rb | 6 ++ .../resource/user/should_not_destoy_unexisting.rb | 11 +++ acceptance/tests/resource/user/should_query.rb | 15 ++++ acceptance/tests/resource/user/should_query_all.rb | 30 +++++++ ...ppet_kick_with_hostnames_on_the_command_line.rb | 7 ++ ...ket_3360_allow_duplicate_csr_with_option_set.rb | 50 +++++++++++ .../ticket_3656_requiring_multiple_resources.rb | 8 ++ .../ticket_3961_puppet_ca_should_produce_certs.rb | 29 ++++++ .../tests/ticket_4059_ralsh_can_change_settings.rb | 20 +++++ ...should_not_create_a_user_that_already_exists.rb | 5 ++ .../tests/ticket_4233_resource_with_a_newline.rb | 13 +++ ...ource_fail_when_name_defined_instead_of_path.rb | 17 ++++ ...h_when_function_call_used_in_an_if_statement.rb | 13 +++ ..._should_recognize_OEL_operatingsystemrelease.rb | 21 +++++ ..._4293_define_and_use_a_define_within_a_class.rb | 22 +++++ ...llow_stage_main_on_left_side_of_relationship.rb | 21 +++++ ...423_cannot_declare_two_parameterized_classes.rb | 50 +++++++++++ .../tests/ticket_5027_warn_on_dynamic_scope.rb | 28 ++++++ .../tests/ticket_5477_master_not_dectect_sitepp.rb | 43 +++++++++ .../tests/ticket_6418_file_recursion_and_audit.rb | 22 +++++ .../tests/ticket_6541_invalid_filebucket_files.rb | 26 ++++++ acceptance/tests/ticket_6734_6256_5530_5503.rb | 16 ++++ .../tests/ticket_6928_puppet_master_parse_fails.rb | 38 ++++++++ 92 files changed, 2074 insertions(+) create mode 100644 acceptance/pending/ticket_4149_parseonly_should_not_fail.rb create mode 100644 acceptance/pending/ticket_4151_defined_function_should_not_return_true_for_unrealized_virtual_resources.rb create mode 100644 acceptance/pending/ticket_6710_relationship_syntax_should_work_with_title_arrays.rb create mode 100755 acceptance/tests/apply/classes/parameterized_classes.rb create mode 100755 acceptance/tests/apply/classes/should_allow_param_override.rb create mode 100755 acceptance/tests/apply/classes/should_allow_param_undef_override.rb create mode 100755 acceptance/tests/apply/classes/should_include_resources_from_class.rb create mode 100755 acceptance/tests/apply/classes/should_not_auto_include_resources_from_class.rb create mode 100755 acceptance/tests/apply/conditionals/should_evaluate_else.rb create mode 100755 acceptance/tests/apply/conditionals/should_evaluate_elsif.rb create mode 100644 acceptance/tests/apply/conditionals/should_evaluate_empty.rb create mode 100755 acceptance/tests/apply/conditionals/should_evaluate_false.rb create mode 100755 acceptance/tests/apply/conditionals/should_evaluate_if.rb create mode 100755 acceptance/tests/apply/conditionals/should_evaluate_strings_true.rb create mode 100755 acceptance/tests/apply/conditionals/should_evaluate_undef.rb create mode 100755 acceptance/tests/apply/hashes/should_not_reassign.rb create mode 100755 acceptance/tests/apply/virtual/should_realize.rb create mode 100755 acceptance/tests/apply/virtual/should_realize_complex_query.rb create mode 100755 acceptance/tests/apply/virtual/should_realize_many.rb create mode 100755 acceptance/tests/apply/virtual/should_realize_query.rb create mode 100755 acceptance/tests/apply/virtual/should_realize_query_array.rb create mode 100644 acceptance/tests/doc/should_print_function_reference.rb create mode 100755 acceptance/tests/doc/ticket_4120_cannot_generate_type_reference.rb create mode 100644 acceptance/tests/file_hello_world.rb create mode 100644 acceptance/tests/jeff_append_to_array.rb create mode 100644 acceptance/tests/key_compare_puppet_conf_configprint.rb create mode 100644 acceptance/tests/puppet_apply_a_file_should_create_a_file_and_report_the_md5.rb create mode 100644 acceptance/tests/puppet_apply_basics.rb create mode 100644 acceptance/tests/puppet_apply_should_show_a_notice.rb create mode 100644 acceptance/tests/puppet_master_help_should_mention_puppet_master.rb create mode 100644 acceptance/tests/resource/cron/should_create_cron.rb create mode 100755 acceptance/tests/resource/cron/should_match_existing.rb create mode 100755 acceptance/tests/resource/cron/should_remove_cron.rb create mode 100755 acceptance/tests/resource/cron/should_remove_matching.rb create mode 100755 acceptance/tests/resource/cron/should_update_existing.rb create mode 100644 acceptance/tests/resource/exec/should_not_run_command_creates.rb create mode 100644 acceptance/tests/resource/exec/should_run_command.rb create mode 100644 acceptance/tests/resource/exec/should_set_path.rb create mode 100644 acceptance/tests/resource/file/content_attribute.rb create mode 100755 acceptance/tests/resource/file/should_create_directory.rb create mode 100755 acceptance/tests/resource/file/should_create_empty.rb create mode 100755 acceptance/tests/resource/file/should_create_symlink.rb create mode 100755 acceptance/tests/resource/file/should_remove_dir.rb create mode 100755 acceptance/tests/resource/file/should_remove_file.rb create mode 100644 acceptance/tests/resource/file/source_attribtute.rb create mode 100755 acceptance/tests/resource/group/should_create.rb create mode 100755 acceptance/tests/resource/group/should_destroy.rb create mode 100755 acceptance/tests/resource/group/should_modify_gid.rb create mode 100755 acceptance/tests/resource/group/should_not_create_existing.rb create mode 100755 acceptance/tests/resource/group/should_not_destoy_unexisting.rb create mode 100755 acceptance/tests/resource/group/should_query.rb create mode 100755 acceptance/tests/resource/group/should_query_all.rb create mode 100755 acceptance/tests/resource/host/should_create.rb create mode 100755 acceptance/tests/resource/host/should_create_aliases.rb create mode 100755 acceptance/tests/resource/host/should_destroy.rb create mode 100755 acceptance/tests/resource/host/should_modify_alias.rb create mode 100755 acceptance/tests/resource/host/should_modify_ip.rb create mode 100755 acceptance/tests/resource/host/should_not_create_existing.rb create mode 100755 acceptance/tests/resource/host/should_query.rb create mode 100755 acceptance/tests/resource/host/should_query_all.rb create mode 100755 acceptance/tests/resource/host/ticket_4131_should_not_create_without_ip.rb create mode 100755 acceptance/tests/resource/service/ticket_4123_should_list_all_running_redhat.rb create mode 100755 acceptance/tests/resource/service/ticket_4123_should_list_all_running_redhat.sh create mode 100755 acceptance/tests/resource/service/ticket_4124_should_list_all_disabled.rb create mode 100755 acceptance/tests/resource/service/ticket_4124_should_list_all_disabled.sh create mode 100755 acceptance/tests/resource/user/should_create.rb create mode 100755 acceptance/tests/resource/user/should_create_with_gid.rb create mode 100755 acceptance/tests/resource/user/should_destroy.rb create mode 100755 acceptance/tests/resource/user/should_modify_gid.rb create mode 100755 acceptance/tests/resource/user/should_not_create_existing.rb create mode 100755 acceptance/tests/resource/user/should_not_destoy_unexisting.rb create mode 100755 acceptance/tests/resource/user/should_query.rb create mode 100755 acceptance/tests/resource/user/should_query_all.rb create mode 100644 acceptance/tests/ticket_3172_puppet_kick_with_hostnames_on_the_command_line.rb create mode 100644 acceptance/tests/ticket_3360_allow_duplicate_csr_with_option_set.rb create mode 100644 acceptance/tests/ticket_3656_requiring_multiple_resources.rb create mode 100644 acceptance/tests/ticket_3961_puppet_ca_should_produce_certs.rb create mode 100644 acceptance/tests/ticket_4059_ralsh_can_change_settings.rb create mode 100644 acceptance/tests/ticket_4110_puppet_apply_should_not_create_a_user_that_already_exists.rb create mode 100644 acceptance/tests/ticket_4233_resource_with_a_newline.rb create mode 100644 acceptance/tests/ticket_4285_file_resource_fail_when_name_defined_instead_of_path.rb create mode 100644 acceptance/tests/ticket_4287_undefined_method_evaluate_match_when_function_call_used_in_an_if_statement.rb create mode 100644 acceptance/tests/ticket_4289_facter_should_recognize_OEL_operatingsystemrelease.rb create mode 100644 acceptance/tests/ticket_4293_define_and_use_a_define_within_a_class.rb create mode 100644 acceptance/tests/ticket_4404_should_allow_stage_main_on_left_side_of_relationship.rb create mode 100644 acceptance/tests/ticket_4423_cannot_declare_two_parameterized_classes.rb create mode 100644 acceptance/tests/ticket_5027_warn_on_dynamic_scope.rb create mode 100644 acceptance/tests/ticket_5477_master_not_dectect_sitepp.rb create mode 100644 acceptance/tests/ticket_6418_file_recursion_and_audit.rb create mode 100644 acceptance/tests/ticket_6541_invalid_filebucket_files.rb create mode 100644 acceptance/tests/ticket_6734_6256_5530_5503.rb create mode 100644 acceptance/tests/ticket_6928_puppet_master_parse_fails.rb 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_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/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/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_3360_allow_duplicate_csr_with_option_set.rb b/acceptance/tests/ticket_3360_allow_duplicate_csr_with_option_set.rb new file mode 100644 index 000000000..ba02227ea --- /dev/null +++ b/acceptance/tests/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/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_3961_puppet_ca_should_produce_certs.rb b/acceptance/tests/ticket_3961_puppet_ca_should_produce_certs.rb new file mode 100644 index 000000000..4b5bc377b --- /dev/null +++ b/acceptance/tests/ticket_3961_puppet_ca_should_produce_certs.rb @@ -0,0 +1,29 @@ +test_name "#3961: puppet ca should produce certs spec" + +scratch = "/tmp/puppet-ssl-3961" +target = "working3961.example.org" + +options = { :confdir => scratch, :vardir => scratch, :ssldir => scratch } + +expect = ['notice: Signed certificate request for ca', + 'notice: Rebuilding inventory file', + 'notice: working3961.example.org has a waiting certificate request', + 'notice: Signed certificate request for working3961.example.org', + 'notice: Removing file Puppet::SSL::CertificateRequest working3961.example.org'] + + +step "removing the SSL scratch directory..." +on agents, "rm -vrf #{scratch}" + +step "generate a certificate in #{scratch}" +on(agents,puppet_cert('--trace', '--generate', target, options)) do + expect.each do |line| + stdout.index(line) or fail_test("missing line in output: #{line}") + end +end + +step "verify the certificate for #{target} exists" +on agents, "test -f #{scratch}/certs/#{target}.pem" + +step "verify the private key for #{target} exists" +on agents, "grep -q 'BEGIN RSA PRIVATE KEY' #{scratch}/private_keys/#{target}.pem" 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_5027_warn_on_dynamic_scope.rb b/acceptance/tests/ticket_5027_warn_on_dynamic_scope.rb new file mode 100644 index 000000000..a918f0788 --- /dev/null +++ b/acceptance/tests/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' 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' diff --git a/acceptance/tests/ticket_6928_puppet_master_parse_fails.rb b/acceptance/tests/ticket_6928_puppet_master_parse_fails.rb new file mode 100644 index 000000000..aac53138a --- /dev/null +++ b/acceptance/tests/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 -- cgit From cb43cfc853249015ebea9e5be2091235c1e38b89 Mon Sep 17 00:00:00 2001 From: Dominic Maraglia Date: Wed, 20 Apr 2011 14:56:34 -0700 Subject: Moving tests from Puppet-acceptance repo --- .../ticket_4149_parseonly_should_not_fail.rb | 18 ++++ ...return_true_for_unrealized_virtual_resources.rb | 24 +++++ ...ionship_syntax_should_work_with_title_arrays.rb | 15 ++++ .../tests/apply/classes/parameterized_classes.rb | 56 ++++++++++++ .../apply/classes/should_allow_param_override.rb | 20 +++++ .../classes/should_allow_param_undef_override.rb | 29 ++++++ .../classes/should_include_resources_from_class.rb | 11 +++ ...should_not_auto_include_resources_from_class.rb | 6 ++ .../apply/conditionals/should_evaluate_else.rb | 15 ++++ .../apply/conditionals/should_evaluate_elsif.rb | 15 ++++ .../apply/conditionals/should_evaluate_empty.rb | 12 +++ .../apply/conditionals/should_evaluate_false.rb | 12 +++ .../tests/apply/conditionals/should_evaluate_if.rb | 15 ++++ .../conditionals/should_evaluate_strings_true.rb | 13 +++ .../apply/conditionals/should_evaluate_undef.rb | 11 +++ .../tests/apply/hashes/should_not_reassign.rb | 10 +++ acceptance/tests/apply/virtual/should_realize.rb | 22 +++++ .../apply/virtual/should_realize_complex_query.rb | 36 ++++++++ .../tests/apply/virtual/should_realize_many.rb | 22 +++++ .../tests/apply/virtual/should_realize_query.rb | 24 +++++ .../apply/virtual/should_realize_query_array.rb | 24 +++++ .../tests/doc/should_print_function_reference.rb | 5 ++ .../ticket_4120_cannot_generate_type_reference.rb | 5 ++ acceptance/tests/file_hello_world.rb | 22 +++++ acceptance/tests/jeff_append_to_array.rb | 19 ++++ .../tests/key_compare_puppet_conf_configprint.rb | 65 ++++++++++++++ ...file_should_create_a_file_and_report_the_md5.rb | 16 ++++ acceptance/tests/puppet_apply_basics.rb | 15 ++++ .../tests/puppet_apply_should_show_a_notice.rb | 5 ++ ...pet_master_help_should_mention_puppet_master.rb | 4 + .../tests/resource/cron/should_create_cron.rb | 31 +++++++ .../tests/resource/cron/should_match_existing.rb | 40 +++++++++ .../tests/resource/cron/should_remove_cron.rb | 36 ++++++++ .../tests/resource/cron/should_remove_matching.rb | 36 ++++++++ .../tests/resource/cron/should_update_existing.rb | 42 +++++++++ .../exec/should_not_run_command_creates.rb | 34 +++++++ .../tests/resource/exec/should_run_command.rb | 31 +++++++ acceptance/tests/resource/exec/should_set_path.rb | 16 ++++ .../tests/resource/file/content_attribute.rb | 37 ++++++++ .../tests/resource/file/should_create_directory.rb | 15 ++++ .../tests/resource/file/should_create_empty.rb | 15 ++++ .../tests/resource/file/should_create_symlink.rb | 27 ++++++ .../tests/resource/file/should_remove_dir.rb | 21 +++++ .../tests/resource/file/should_remove_file.rb | 12 +++ .../tests/resource/file/source_attribtute.rb | 100 +++++++++++++++++++++ acceptance/tests/resource/group/should_create.rb | 20 +++++ acceptance/tests/resource/group/should_destroy.rb | 14 +++ .../tests/resource/group/should_modify_gid.rb | 23 +++++ .../resource/group/should_not_create_existing.rb | 15 ++++ .../resource/group/should_not_destoy_unexisting.rb | 13 +++ acceptance/tests/resource/group/should_query.rb | 15 ++++ .../tests/resource/group/should_query_all.rb | 30 +++++++ acceptance/tests/resource/host/should_create.rb | 15 ++++ .../tests/resource/host/should_create_aliases.rb | 16 ++++ acceptance/tests/resource/host/should_destroy.rb | 19 ++++ .../tests/resource/host/should_modify_alias.rb | 19 ++++ acceptance/tests/resource/host/should_modify_ip.rb | 19 ++++ .../resource/host/should_not_create_existing.rb | 17 ++++ acceptance/tests/resource/host/should_query.rb | 15 ++++ acceptance/tests/resource/host/should_query_all.rb | 26 ++++++ .../ticket_4131_should_not_create_without_ip.rb | 21 +++++ .../ticket_4123_should_list_all_running_redhat.rb | 12 +++ .../ticket_4123_should_list_all_running_redhat.sh | 36 ++++++++ .../ticket_4124_should_list_all_disabled.rb | 12 +++ .../ticket_4124_should_list_all_disabled.sh | 37 ++++++++ acceptance/tests/resource/user/should_create.rb | 20 +++++ .../tests/resource/user/should_create_with_gid.rb | 30 +++++++ acceptance/tests/resource/user/should_destroy.rb | 19 ++++ .../tests/resource/user/should_modify_gid.rb | 41 +++++++++ .../resource/user/should_not_create_existing.rb | 6 ++ .../resource/user/should_not_destoy_unexisting.rb | 11 +++ acceptance/tests/resource/user/should_query.rb | 15 ++++ acceptance/tests/resource/user/should_query_all.rb | 30 +++++++ .../ticket_4655_default_stage_for_classes.rb | 39 ++++++++ ...ppet_kick_with_hostnames_on_the_command_line.rb | 7 ++ ...ket_3360_allow_duplicate_csr_with_option_set.rb | 50 +++++++++++ .../ticket_3656_requiring_multiple_resources.rb | 8 ++ .../ticket_3961_puppet_ca_should_produce_certs.rb | 29 ++++++ .../tests/ticket_4059_ralsh_can_change_settings.rb | 20 +++++ ...should_not_create_a_user_that_already_exists.rb | 5 ++ .../tests/ticket_4233_resource_with_a_newline.rb | 13 +++ ...ource_fail_when_name_defined_instead_of_path.rb | 17 ++++ ...h_when_function_call_used_in_an_if_statement.rb | 13 +++ ..._should_recognize_OEL_operatingsystemrelease.rb | 21 +++++ ..._4293_define_and_use_a_define_within_a_class.rb | 22 +++++ ...llow_stage_main_on_left_side_of_relationship.rb | 21 +++++ ...423_cannot_declare_two_parameterized_classes.rb | 50 +++++++++++ .../tests/ticket_5027_warn_on_dynamic_scope.rb | 28 ++++++ .../tests/ticket_5477_master_not_dectect_sitepp.rb | 43 +++++++++ .../tests/ticket_6418_file_recursion_and_audit.rb | 22 +++++ .../tests/ticket_6541_invalid_filebucket_files.rb | 26 ++++++ acceptance/tests/ticket_6734_6256_5530_5503.rb | 16 ++++ .../tests/ticket_6928_puppet_master_parse_fails.rb | 38 ++++++++ 93 files changed, 2113 insertions(+) create mode 100644 acceptance/pending/ticket_4149_parseonly_should_not_fail.rb create mode 100644 acceptance/pending/ticket_4151_defined_function_should_not_return_true_for_unrealized_virtual_resources.rb create mode 100644 acceptance/pending/ticket_6710_relationship_syntax_should_work_with_title_arrays.rb create mode 100755 acceptance/tests/apply/classes/parameterized_classes.rb create mode 100755 acceptance/tests/apply/classes/should_allow_param_override.rb create mode 100755 acceptance/tests/apply/classes/should_allow_param_undef_override.rb create mode 100755 acceptance/tests/apply/classes/should_include_resources_from_class.rb create mode 100755 acceptance/tests/apply/classes/should_not_auto_include_resources_from_class.rb create mode 100755 acceptance/tests/apply/conditionals/should_evaluate_else.rb create mode 100755 acceptance/tests/apply/conditionals/should_evaluate_elsif.rb create mode 100644 acceptance/tests/apply/conditionals/should_evaluate_empty.rb create mode 100755 acceptance/tests/apply/conditionals/should_evaluate_false.rb create mode 100755 acceptance/tests/apply/conditionals/should_evaluate_if.rb create mode 100755 acceptance/tests/apply/conditionals/should_evaluate_strings_true.rb create mode 100755 acceptance/tests/apply/conditionals/should_evaluate_undef.rb create mode 100755 acceptance/tests/apply/hashes/should_not_reassign.rb create mode 100755 acceptance/tests/apply/virtual/should_realize.rb create mode 100755 acceptance/tests/apply/virtual/should_realize_complex_query.rb create mode 100755 acceptance/tests/apply/virtual/should_realize_many.rb create mode 100755 acceptance/tests/apply/virtual/should_realize_query.rb create mode 100755 acceptance/tests/apply/virtual/should_realize_query_array.rb create mode 100644 acceptance/tests/doc/should_print_function_reference.rb create mode 100755 acceptance/tests/doc/ticket_4120_cannot_generate_type_reference.rb create mode 100644 acceptance/tests/file_hello_world.rb create mode 100644 acceptance/tests/jeff_append_to_array.rb create mode 100644 acceptance/tests/key_compare_puppet_conf_configprint.rb create mode 100644 acceptance/tests/puppet_apply_a_file_should_create_a_file_and_report_the_md5.rb create mode 100644 acceptance/tests/puppet_apply_basics.rb create mode 100644 acceptance/tests/puppet_apply_should_show_a_notice.rb create mode 100644 acceptance/tests/puppet_master_help_should_mention_puppet_master.rb create mode 100644 acceptance/tests/resource/cron/should_create_cron.rb create mode 100755 acceptance/tests/resource/cron/should_match_existing.rb create mode 100755 acceptance/tests/resource/cron/should_remove_cron.rb create mode 100755 acceptance/tests/resource/cron/should_remove_matching.rb create mode 100755 acceptance/tests/resource/cron/should_update_existing.rb create mode 100644 acceptance/tests/resource/exec/should_not_run_command_creates.rb create mode 100644 acceptance/tests/resource/exec/should_run_command.rb create mode 100644 acceptance/tests/resource/exec/should_set_path.rb create mode 100644 acceptance/tests/resource/file/content_attribute.rb create mode 100755 acceptance/tests/resource/file/should_create_directory.rb create mode 100755 acceptance/tests/resource/file/should_create_empty.rb create mode 100755 acceptance/tests/resource/file/should_create_symlink.rb create mode 100755 acceptance/tests/resource/file/should_remove_dir.rb create mode 100755 acceptance/tests/resource/file/should_remove_file.rb create mode 100644 acceptance/tests/resource/file/source_attribtute.rb create mode 100755 acceptance/tests/resource/group/should_create.rb create mode 100755 acceptance/tests/resource/group/should_destroy.rb create mode 100755 acceptance/tests/resource/group/should_modify_gid.rb create mode 100755 acceptance/tests/resource/group/should_not_create_existing.rb create mode 100755 acceptance/tests/resource/group/should_not_destoy_unexisting.rb create mode 100755 acceptance/tests/resource/group/should_query.rb create mode 100755 acceptance/tests/resource/group/should_query_all.rb create mode 100755 acceptance/tests/resource/host/should_create.rb create mode 100755 acceptance/tests/resource/host/should_create_aliases.rb create mode 100755 acceptance/tests/resource/host/should_destroy.rb create mode 100755 acceptance/tests/resource/host/should_modify_alias.rb create mode 100755 acceptance/tests/resource/host/should_modify_ip.rb create mode 100755 acceptance/tests/resource/host/should_not_create_existing.rb create mode 100755 acceptance/tests/resource/host/should_query.rb create mode 100755 acceptance/tests/resource/host/should_query_all.rb create mode 100755 acceptance/tests/resource/host/ticket_4131_should_not_create_without_ip.rb create mode 100755 acceptance/tests/resource/service/ticket_4123_should_list_all_running_redhat.rb create mode 100755 acceptance/tests/resource/service/ticket_4123_should_list_all_running_redhat.sh create mode 100755 acceptance/tests/resource/service/ticket_4124_should_list_all_disabled.rb create mode 100755 acceptance/tests/resource/service/ticket_4124_should_list_all_disabled.sh create mode 100755 acceptance/tests/resource/user/should_create.rb create mode 100755 acceptance/tests/resource/user/should_create_with_gid.rb create mode 100755 acceptance/tests/resource/user/should_destroy.rb create mode 100755 acceptance/tests/resource/user/should_modify_gid.rb create mode 100755 acceptance/tests/resource/user/should_not_create_existing.rb create mode 100755 acceptance/tests/resource/user/should_not_destoy_unexisting.rb create mode 100755 acceptance/tests/resource/user/should_query.rb create mode 100755 acceptance/tests/resource/user/should_query_all.rb create mode 100644 acceptance/tests/stages/ticket_4655_default_stage_for_classes.rb create mode 100644 acceptance/tests/ticket_3172_puppet_kick_with_hostnames_on_the_command_line.rb create mode 100644 acceptance/tests/ticket_3360_allow_duplicate_csr_with_option_set.rb create mode 100644 acceptance/tests/ticket_3656_requiring_multiple_resources.rb create mode 100644 acceptance/tests/ticket_3961_puppet_ca_should_produce_certs.rb create mode 100644 acceptance/tests/ticket_4059_ralsh_can_change_settings.rb create mode 100644 acceptance/tests/ticket_4110_puppet_apply_should_not_create_a_user_that_already_exists.rb create mode 100644 acceptance/tests/ticket_4233_resource_with_a_newline.rb create mode 100644 acceptance/tests/ticket_4285_file_resource_fail_when_name_defined_instead_of_path.rb create mode 100644 acceptance/tests/ticket_4287_undefined_method_evaluate_match_when_function_call_used_in_an_if_statement.rb create mode 100644 acceptance/tests/ticket_4289_facter_should_recognize_OEL_operatingsystemrelease.rb create mode 100644 acceptance/tests/ticket_4293_define_and_use_a_define_within_a_class.rb create mode 100644 acceptance/tests/ticket_4404_should_allow_stage_main_on_left_side_of_relationship.rb create mode 100644 acceptance/tests/ticket_4423_cannot_declare_two_parameterized_classes.rb create mode 100644 acceptance/tests/ticket_5027_warn_on_dynamic_scope.rb create mode 100644 acceptance/tests/ticket_5477_master_not_dectect_sitepp.rb create mode 100644 acceptance/tests/ticket_6418_file_recursion_and_audit.rb create mode 100644 acceptance/tests/ticket_6541_invalid_filebucket_files.rb create mode 100644 acceptance/tests/ticket_6734_6256_5530_5503.rb create mode 100644 acceptance/tests/ticket_6928_puppet_master_parse_fails.rb 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_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/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_3360_allow_duplicate_csr_with_option_set.rb b/acceptance/tests/ticket_3360_allow_duplicate_csr_with_option_set.rb new file mode 100644 index 000000000..ba02227ea --- /dev/null +++ b/acceptance/tests/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/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_3961_puppet_ca_should_produce_certs.rb b/acceptance/tests/ticket_3961_puppet_ca_should_produce_certs.rb new file mode 100644 index 000000000..4b5bc377b --- /dev/null +++ b/acceptance/tests/ticket_3961_puppet_ca_should_produce_certs.rb @@ -0,0 +1,29 @@ +test_name "#3961: puppet ca should produce certs spec" + +scratch = "/tmp/puppet-ssl-3961" +target = "working3961.example.org" + +options = { :confdir => scratch, :vardir => scratch, :ssldir => scratch } + +expect = ['notice: Signed certificate request for ca', + 'notice: Rebuilding inventory file', + 'notice: working3961.example.org has a waiting certificate request', + 'notice: Signed certificate request for working3961.example.org', + 'notice: Removing file Puppet::SSL::CertificateRequest working3961.example.org'] + + +step "removing the SSL scratch directory..." +on agents, "rm -vrf #{scratch}" + +step "generate a certificate in #{scratch}" +on(agents,puppet_cert('--trace', '--generate', target, options)) do + expect.each do |line| + stdout.index(line) or fail_test("missing line in output: #{line}") + end +end + +step "verify the certificate for #{target} exists" +on agents, "test -f #{scratch}/certs/#{target}.pem" + +step "verify the private key for #{target} exists" +on agents, "grep -q 'BEGIN RSA PRIVATE KEY' #{scratch}/private_keys/#{target}.pem" 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_5027_warn_on_dynamic_scope.rb b/acceptance/tests/ticket_5027_warn_on_dynamic_scope.rb new file mode 100644 index 000000000..a918f0788 --- /dev/null +++ b/acceptance/tests/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' 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' diff --git a/acceptance/tests/ticket_6928_puppet_master_parse_fails.rb b/acceptance/tests/ticket_6928_puppet_master_parse_fails.rb new file mode 100644 index 000000000..aac53138a --- /dev/null +++ b/acceptance/tests/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 -- cgit From 6981ee5f526e00f46f6b5460662bf09cddf832ef Mon Sep 17 00:00:00 2001 From: Jesse Wolfe Date: Wed, 20 Apr 2011 15:41:52 -0700 Subject: Maint: Fix a #4655 introduced log inconsistency When we moved code from the compiler to parser/resource, we lost a conditional that prevented defined resources from gaining containment edges to stages. Adding a stage to a defined resource was usually harmless, but it violated the invariant of "resources should only have exactly one container as their direct parent", producing a 50% chance of a malformed containment path in log messages. Reviewed-By: Jacob Helwig --- lib/puppet/parser/resource.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index cd0e8c742..3bb5f8601 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -66,6 +66,8 @@ class Puppet::Parser::Resource < Puppet::Resource # is drawn from the class to the stage. The stage for containment # defaults to main, if none is specified. def add_edge_to_stage + return unless self.type.to_s.downcase == "class" + unless stage = catalog.resource(:stage, self[:stage] || (scope && scope.resource && scope.resource[:stage]) || :main) raise ArgumentError, "Could not find stage #{self[:stage] || :main} specified by #{self}" end -- cgit From 74498afecdc0a64f9435ef20065e08d549a510c9 Mon Sep 17 00:00:00 2001 From: Dominic Maraglia Date: Tue, 26 Apr 2011 13:54:53 -0700 Subject: add test for ticket 7101 --- acceptance/tests/ticket_7101_template_compile.rb | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 acceptance/tests/ticket_7101_template_compile.rb diff --git a/acceptance/tests/ticket_7101_template_compile.rb b/acceptance/tests/ticket_7101_template_compile.rb new file mode 100644 index 000000000..d2ebecd13 --- /dev/null +++ b/acceptance/tests/ticket_7101_template_compile.rb @@ -0,0 +1,25 @@ +test_name "#7101: template compile" + +manifest = %q{ +$bar = 'test 7101' +file { '/tmp/file_7101.erb': + content => template('/tmp/template_7101.erb') +} +} + + +step "Agents: Create template file" +agents.each do |host| + create_remote_file(host, '/tmp/template_7101.erb', %w{<%= bar %>} ) +end + +step "Run manifest referencing template file" +apply_manifest_on(agents, manifest) + + +step "Agents: Verify file is created with correct contents " +agents.each do |host| + on(host, "cat /tmp/file_7101.erb") do + assert_match(/test 7101/, stdout, "File /tmp/file_7101.erb not created with correct contents on #{host}" ) + end +end -- cgit From 89e9a212e7c2426fa89f65e57a3d225a73ae0613 Mon Sep 17 00:00:00 2001 From: Dominic Maraglia Date: Tue, 26 Apr 2011 13:57:20 -0700 Subject: add test for ticket 7101 --- acceptance/tests/ticket_7101_template_compile.rb | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 acceptance/tests/ticket_7101_template_compile.rb diff --git a/acceptance/tests/ticket_7101_template_compile.rb b/acceptance/tests/ticket_7101_template_compile.rb new file mode 100644 index 000000000..d2ebecd13 --- /dev/null +++ b/acceptance/tests/ticket_7101_template_compile.rb @@ -0,0 +1,25 @@ +test_name "#7101: template compile" + +manifest = %q{ +$bar = 'test 7101' +file { '/tmp/file_7101.erb': + content => template('/tmp/template_7101.erb') +} +} + + +step "Agents: Create template file" +agents.each do |host| + create_remote_file(host, '/tmp/template_7101.erb', %w{<%= bar %>} ) +end + +step "Run manifest referencing template file" +apply_manifest_on(agents, manifest) + + +step "Agents: Verify file is created with correct contents " +agents.each do |host| + on(host, "cat /tmp/file_7101.erb") do + assert_match(/test 7101/, stdout, "File /tmp/file_7101.erb not created with correct contents on #{host}" ) + end +end -- cgit From 9d2500e7169bc8eba58d9157db49586be24d6ded Mon Sep 17 00:00:00 2001 From: Max Martin Date: Wed, 27 Apr 2011 12:45:47 -0700 Subject: (#7101) Fix template error messages in Ruby 1.8.5 lib/puppet/parser/templatewrapper.rb#script_line was calling .first on a String object, which in Ruby > 1.8.5 will return the entire string, but in 1.8.5 will cause an exception. This change (proposed by Markus Roberts) removes the call to .first and adds a condition for when the template error involves the file not being found. Reviewed-by: Jesse Wolfe --- lib/puppet/parser/templatewrapper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/parser/templatewrapper.rb b/lib/puppet/parser/templatewrapper.rb index 180a03dc9..27d75bf92 100644 --- a/lib/puppet/parser/templatewrapper.rb +++ b/lib/puppet/parser/templatewrapper.rb @@ -20,7 +20,7 @@ class Puppet::Parser::TemplateWrapper def script_line # find which line in the template (if any) we were called from - caller.find { |l| l =~ /#{file}:/ }.first[/:(\d+):/,1] + (caller.find { |l| l =~ /#{file}:/ }||"")[/:(\d+):/,1] end # Should return true if a variable is defined, false if it is not -- cgit From ac0581f16ca17962a23c244424d83dbd6e721479 Mon Sep 17 00:00:00 2001 From: Max Martin Date: Wed, 27 Apr 2011 13:09:30 -0700 Subject: (#7101) Fix template error messages in Ruby 1.8.5 lib/puppet/parser/templatewrapper.rb#script_line was calling .first on a String object, which in Ruby > 1.8.5 will return the entire string, but in 1.8.5 will cause an exception. This change (proposed by Markus Roberts) removes the call to .first and adds a condition for when the template error involves the file not being found. Reviewed-by: Jesse Wolfe --- lib/puppet/parser/templatewrapper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/parser/templatewrapper.rb b/lib/puppet/parser/templatewrapper.rb index 180a03dc9..27d75bf92 100644 --- a/lib/puppet/parser/templatewrapper.rb +++ b/lib/puppet/parser/templatewrapper.rb @@ -20,7 +20,7 @@ class Puppet::Parser::TemplateWrapper def script_line # find which line in the template (if any) we were called from - caller.find { |l| l =~ /#{file}:/ }.first[/:(\d+):/,1] + (caller.find { |l| l =~ /#{file}:/ }||"")[/:(\d+):/,1] end # Should return true if a variable is defined, false if it is not -- cgit From 1695daca385bb0aef16cdb6aa840ca16a8823b11 Mon Sep 17 00:00:00 2001 From: nfagerlund Date: Wed, 11 May 2011 13:49:24 -0700 Subject: (#7264) Docs: Clarify that subscribe/notify imply require/before This is a doc string only commit. The metaparameter reference was not clear about subscribe and notify being supersets of require and before, respectively. This commit also cleans up some unrelated quoting, arrow-alignment, and language flow issues. --- lib/puppet/type.rb | 84 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 656b8f264..1dbf12451 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -957,13 +957,13 @@ class Type schedule object, and then reference the name of that object to use that for your schedule: - schedule { daily: + schedule { 'daily': period => daily, - range => \"2-4\" + range => \"2-4\" } exec { \"/usr/bin/apt-get update\": - schedule => daily + schedule => 'daily' } The creation of the schedule object does not need to appear in the @@ -1055,9 +1055,9 @@ class Type newmetaparam(:alias) do desc "Creates an alias for the object. Puppet uses this internally when you - provide a symbolic name: + provide a symbolic title: - file { sshdconfig: + file { 'sshdconfig': path => $operatingsystem ? { solaris => \"/usr/local/etc/ssh/sshd_config\", default => \"/etc/ssh/sshd_config\" @@ -1065,30 +1065,30 @@ class Type source => \"...\" } - service { sshd: - subscribe => File[sshdconfig] + service { 'sshd': + subscribe => File['sshdconfig'] } - When you use this feature, the parser sets `sshdconfig` as the name, + When you use this feature, the parser sets `sshdconfig` as the title, and the library sets that as an alias for the file so the dependency - lookup for `sshd` works. You can use this parameter yourself, + lookup in `Service['sshd']` works. You can use this metaparameter yourself, but note that only the library can use these aliases; for instance, the following code will not work: file { \"/etc/ssh/sshd_config\": owner => root, group => root, - alias => sshdconfig + alias => 'sshdconfig' } - file { sshdconfig: + file { 'sshdconfig': mode => 644 } There's no way here for the Puppet parser to know that these two stanzas should be affecting the same file. - See the [Language Tutorial](http://docs.puppetlabs.com/guides/language_tutorial.html) for more information. + See the [Language Guide](http://docs.puppetlabs.com/guides/language_guide.html) for more information. " @@ -1222,7 +1222,7 @@ class Type # solution, but it works. newmetaparam(:require, :parent => RelationshipMetaparam, :attributes => {:direction => :in, :events => :NONE}) do - desc "One or more objects that this object depends on. + desc "References to one or more objects that this object depends on. This is used purely for guaranteeing that changes to required objects happen before the dependent object. For instance: @@ -1232,8 +1232,8 @@ class Type } file { \"/usr/local/scripts/myscript\": - source => \"puppet://server/module/myscript\", - mode => 755, + source => \"puppet://server/module/myscript\", + mode => 755, require => File[\"/usr/local/scripts\"] } @@ -1247,7 +1247,7 @@ class Type ways to autorequire objects, so if you think Puppet could be smarter here, let us know. - In fact, the above code was redundant -- Puppet will autorequire + In fact, the above code was redundant --- Puppet will autorequire any parent directories that are being managed; it will automatically realize that the parent directory should be created before the script is pulled down. @@ -1263,40 +1263,41 @@ class Type end newmetaparam(:subscribe, :parent => RelationshipMetaparam, :attributes => {:direction => :in, :events => :ALL_EVENTS, :callback => :refresh}) do - desc "One or more objects that this object depends on. Changes in the - subscribed to objects result in the dependent objects being - refreshed (e.g., a service will get restarted). For instance: + desc "References to one or more objects that this object depends on. This + metaparameter creates a dependency relationship like **require,** + and also causes the dependent object to be refreshed when the + subscribed object is changed. For instance: class nagios { - file { \"/etc/nagios/nagios.conf\": + file { 'nagconf': + path => \"/etc/nagios/nagios.conf\" source => \"puppet://server/module/nagios.conf\", - alias => nagconf # just to make things easier for me } - service { nagios: - ensure => running, - subscribe => File[nagconf] + service { 'nagios': + ensure => running, + subscribe => File['nagconf'] } } - Currently the `exec`, `mount` and `service` type support + Currently the `exec`, `mount` and `service` types support refreshing. " end newmetaparam(:before, :parent => RelationshipMetaparam, :attributes => {:direction => :out, :events => :NONE}) do - desc %{This parameter is the opposite of **require** -- it guarantees - that the specified object is applied later than the specifying - object: + desc %{References to one or more objects that depend on this object. This + parameter is the opposite of **require** --- it guarantees that + the specified object is applied later than the specifying object: file { "/var/nagios/configuration": source => "...", recurse => true, - before => Exec["nagios-rebuid"] + before => Exec["nagios-rebuid"] } exec { "nagios-rebuild": command => "/usr/bin/make", - cwd => "/var/nagios/configuration" + cwd => "/var/nagios/configuration" } This will make sure all of the files are up to date before the @@ -1304,15 +1305,18 @@ class Type end newmetaparam(:notify, :parent => RelationshipMetaparam, :attributes => {:direction => :out, :events => :ALL_EVENTS, :callback => :refresh}) do - desc %{This parameter is the opposite of **subscribe** -- it sends events - to the specified object: + desc %{References to one or more objects that depend on this object. This + parameter is the opposite of **subscribe** --- it creates a + dependency relationship like **before,** and also causes the + dependent object(s) to be refreshed when this object is changed. For + instance: file { "/etc/sshd_config": source => "....", - notify => Service[sshd] + notify => Service['sshd'] } - service { sshd: + service { 'sshd': ensure => running } @@ -1328,24 +1332,24 @@ class Type By default, all classes get directly added to the 'main' stage. You can create new stages as resources: - stage { [pre, post]: } + stage { ['pre', 'post']: } To order stages, use standard relationships: - stage { pre: before => Stage[main] } + stage { 'pre': before => Stage['main'] } Or use the new relationship syntax: - Stage[pre] -> Stage[main] -> Stage[post] + Stage['pre'] -> Stage['main'] -> Stage['post'] Then use the new class parameters to specify a stage: - class { foo: stage => pre } + class { 'foo': stage => 'pre' } Stages can only be set on classes, not individual resources. This will fail: - file { '/foo': stage => pre, ensure => file } + file { '/foo': stage => 'pre', ensure => file } } end @@ -1478,7 +1482,7 @@ class Type newparam(:provider) do desc "The specific backend for #{self.name.to_s} to use. You will - seldom need to specify this -- Puppet will usually discover the + seldom need to specify this --- Puppet will usually discover the appropriate provider for your platform." # This is so we can refer back to the type to get a list of -- cgit From 81d566f216468c69d5c2e592afb66fe834261aa7 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Wed, 11 May 2011 10:03:36 +1000 Subject: Fixed #7481 - Added MIT license to Thomas Bellman's function code --- lib/puppet/parser/functions/regsubst.rb | 26 ++++++++++++++++++++++++++ lib/puppet/parser/functions/shellquote.rb | 26 ++++++++++++++++++++++++++ lib/puppet/parser/functions/sprintf.rb | 26 ++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) diff --git a/lib/puppet/parser/functions/regsubst.rb b/lib/puppet/parser/functions/regsubst.rb index b6bb5afcf..397d2b2ee 100644 --- a/lib/puppet/parser/functions/regsubst.rb +++ b/lib/puppet/parser/functions/regsubst.rb @@ -1,3 +1,29 @@ +# Copyright (C) 2009 Thomas Bellman +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THOMAS BELLMAN BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# +# Except as contained in this notice, the name of Thomas Bellman shall +# not be used in advertising or otherwise to promote the sale, use or +# other dealings in this Software without prior written authorization +# from Thomas Bellman. + module Puppet::Parser::Functions newfunction( diff --git a/lib/puppet/parser/functions/shellquote.rb b/lib/puppet/parser/functions/shellquote.rb index 3ddb988f2..ee070c740 100644 --- a/lib/puppet/parser/functions/shellquote.rb +++ b/lib/puppet/parser/functions/shellquote.rb @@ -1,3 +1,29 @@ +# Copyright (C) 2009 Thomas Bellman +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THOMAS BELLMAN BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# +# Except as contained in this notice, the name of Thomas Bellman shall +# not be used in advertising or otherwise to promote the sale, use or +# other dealings in this Software without prior written authorization +# from Thomas Bellman. + module Puppet::Parser::Functions Safe = 'a-zA-Z0-9@%_+=:,./-' # Safe unquoted diff --git a/lib/puppet/parser/functions/sprintf.rb b/lib/puppet/parser/functions/sprintf.rb index 5eb4a4f9d..118020412 100644 --- a/lib/puppet/parser/functions/sprintf.rb +++ b/lib/puppet/parser/functions/sprintf.rb @@ -1,3 +1,29 @@ +# Copyright (C) 2009 Thomas Bellman +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THOMAS BELLMAN BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# +# Except as contained in this notice, the name of Thomas Bellman shall +# not be used in advertising or otherwise to promote the sale, use or +# other dealings in this Software without prior written authorization +# from Thomas Bellman. + module Puppet::Parser::Functions newfunction( -- cgit From 6bb2a85a2d1bfdf0fd3fb09339c4b98c627610bf Mon Sep 17 00:00:00 2001 From: Paul Boyd Date: Wed, 11 May 2011 21:21:38 -0400 Subject: (#1853) Pacman package provider Adds support for use Archlinux's pacman package manager in Puppet. Originally written by Miah Johnson, with bug fixes from Thomas Hatch and myself. --- lib/puppet/provider/package/pacman.rb | 94 ++++++++++++ spec/unit/provider/package/pacman_spec.rb | 237 ++++++++++++++++++++++++++++++ 2 files changed, 331 insertions(+) create mode 100644 lib/puppet/provider/package/pacman.rb create mode 100644 spec/unit/provider/package/pacman_spec.rb diff --git a/lib/puppet/provider/package/pacman.rb b/lib/puppet/provider/package/pacman.rb new file mode 100644 index 000000000..6eb7dbe3d --- /dev/null +++ b/lib/puppet/provider/package/pacman.rb @@ -0,0 +1,94 @@ +require 'puppet/provider/package' + +Puppet::Type.type(:package).provide :pacman, :parent => Puppet::Provider::Package do + desc "Support for the Package Manager Utility (pacman) used in Archlinux." + + commands :pacman => "/usr/bin/pacman" + defaultfor :operatingsystem => :archlinux + confine :operatingsystem => :archlinux + has_feature :upgradeable + + # Install a package using 'pacman'. + # Installs quietly, without confirmation or progressbar, updates package + # list from servers defined in pacman.conf. + def install + pacman "--noconfirm", "--noprogressbar", "-Sy", @resource[:name] + + unless self.query + raise Puppet::ExecutionFailure.new("Could not find package %s" % self.name) + end + end + + def self.listcmd + [command(:pacman), " -Q"] + end + + # Fetch the list of packages currently installed on the system. + def self.instances + packages = [] + begin + execpipe(listcmd()) do |process| + # pacman -Q output is 'packagename version-rel' + regex = %r{^(\S+)\s(\S+)} + fields = [:name, :ensure] + hash = {} + + process.each { |line| + if match = regex.match(line) + fields.zip(match.captures) { |field,value| + hash[field] = value + } + + name = hash[:name] + hash[:provider] = self.name + + packages << new(hash) + hash = {} + else + warning("Failed to match line %s" % line) + end + } + end + rescue Puppet::ExecutionFailure + return nil + end + packages + end + + # Because Archlinux is a rolling release based distro, installing a package + # should always result in the newest release. + def update + # Install in pacman can be used for update, too + self.install + end + + def latest + pacman "-Sy" + output = pacman "-Sp", "--print-format", "%v", @resource[:name] + output.chomp + end + + # Querys the pacman master list for information about the package. + def query + begin + output = pacman("-Qi", @resource[:name]) + + if output =~ /Version.*:\s(.+)/ + return { :ensure => $1 } + end + rescue Puppet::ExecutionFailure + return { + :ensure => :purged, + :status => 'missing', + :name => @resource[:name], + :error => 'ok', + } + end + nil + end + + # Removes a package from the system. + def uninstall + pacman "--noconfirm", "--noprogressbar", "-R", @resource[:name] + end +end diff --git a/spec/unit/provider/package/pacman_spec.rb b/spec/unit/provider/package/pacman_spec.rb new file mode 100644 index 000000000..499ccca6a --- /dev/null +++ b/spec/unit/provider/package/pacman_spec.rb @@ -0,0 +1,237 @@ +#!/usr/bin/env ruby + +Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } + +provider = Puppet::Type.type(:package).provider(:pacman) + +describe provider do + before do + @resource = stub 'resource' + @resource.stubs(:[]).returns("package") + @resource.stubs(:name).returns("name") + @provider = provider.new(@resource) + end + + describe "when installing" do + before do + @provider.stubs(:query).returns({ + :ensure => '1.0' + }) + end + + it "should call pacman" do + provider. + expects(:execute). + at_least_once. + with { |args| + args[0] == "/usr/bin/pacman" + }. + returns "" + + @provider.install + end + + it "should be quiet" do + provider. + expects(:execute). + with { |args| + args[1,2] == ["--noconfirm", "--noprogressbar"] + }. + returns("") + + @provider.install + end + + it "should install the right package" do + provider. + expects(:execute). + with { |args| + args[3,4] == ["-Sy", @resource[0]] + }. + returns("") + + @provider.install + end + + it "should raise an ExecutionFailure if the installation failed" do + provider.stubs(:execute).returns("") + @provider.expects(:query).returns(nil) + + lambda { @provider.install }.should raise_exception(Puppet::ExecutionFailure) + end + end + + describe "when updating" do + it "should call install" do + @provider.expects(:install).returns("install return value") + @provider.update.should == "install return value" + end + end + + describe "when uninstalling" do + it "should call pacman" do + provider. + expects(:execute). + with { |args| + args[0] == "/usr/bin/pacman" + }. + returns "" + + @provider.uninstall + end + + it "should be quiet" do + provider. + expects(:execute). + with { |args| + args[1,2] == ["--noconfirm", "--noprogressbar"] + }. + returns("") + + @provider.uninstall + end + + it "should remove the right package" do + provider. + expects(:execute). + with { |args| + args[3,4] == ["-R", @resource[0]] + }. + returns("") + + @provider.uninstall + end + end + + describe "when querying" do + it "should query pacman" do + provider. + expects(:execute). + with(["/usr/bin/pacman", "-Qi", @resource[0]]) + @provider.query + end + + it "should return the version" do + query_output = <=2.7.1 libfetch>=2.25 pacman-mirrorlist +Optional Deps : fakeroot: for makepkg usage as normal user + curl: for rankmirrors usage +Required By : None +Conflicts With : None +Replaces : None +Installed Size : 2352.00 K +Packager : Dan McGee +Architecture : i686 +Build Date : Sat 22 Jan 2011 03:56:41 PM EST +Install Date : Thu 27 Jan 2011 06:45:49 AM EST +Install Reason : Explicitly installed +Install Script : Yes +Description : A library-based package manager with dependency support +EOF + + provider.expects(:execute).returns(query_output) + @provider.query.should == {:ensure => "1.01.3-2"} + end + + it "should return a nil if the package isn't found" do + provider.expects(:execute).returns("") + @provider.query.should be_nil + end + + it "should return a hash indicating that the package is missing on error" do + provider.expects(:execute).raises(Puppet::ExecutionFailure.new("ERROR!")) + @provider.query.should == { + :ensure => :purged, + :status => 'missing', + :name => @resource[0], + :error => 'ok', + } + end + end + + describe "when fetching a package list" do + it "should query pacman" do + provider.expects(:execpipe).with(["/usr/bin/pacman", ' -Q']) + provider.instances + end + + it "should return installed packages with their versions" do + provider.expects(:execpipe).yields("package1 1.23-4\npackage2 2.00\n") + packages = provider.instances + + packages.length.should == 2 + + packages[0].properties.should == { + :provider => :pacman, + :ensure => '1.23-4', + :name => 'package1' + } + + packages[1].properties.should == { + :provider => :pacman, + :ensure => '2.00', + :name => 'package2' + } + end + + it "should return nil on error" do + provider.expects(:execpipe).raises(Puppet::ExecutionFailure.new("ERROR!")) + provider.instances.should be_nil + end + + it "should warn on invalid input" do + provider.expects(:execpipe).yields("blah") + provider.expects(:warning).with("Failed to match line blah") + provider.instances.should == [] + end + end + + describe "when determining the latest version" do + it "should refresh package list" do + refreshed = states('refreshed').starts_as('unrefreshed') + provider. + expects(:execute). + when(refreshed.is('unrefreshed')). + with(['/usr/bin/pacman', '-Sy']). + then(refreshed.is('refreshed')) + + provider. + stubs(:execute). + when(refreshed.is('refreshed')). + returns("") + + @provider.latest + end + + it "should get query pacman for the latest version" do + refreshed = states('refreshed').starts_as('unrefreshed') + provider. + stubs(:execute). + when(refreshed.is('unrefreshed')). + then(refreshed.is('refreshed')) + + provider. + expects(:execute). + when(refreshed.is('refreshed')). + with(['/usr/bin/pacman', '-Sp', '--print-format', '%v', @resource[0]]). + returns("") + + @provider.latest + end + + it "should return the version number from pacman" do + provider. + expects(:execute). + at_least_once(). + returns("1.00.2-3\n") + + @provider.latest.should == "1.00.2-3" + end + end +end -- cgit From 1dc662a0988fee83c92d2d46462f0662710ce7ad Mon Sep 17 00:00:00 2001 From: Paul Boyd Date: Sat, 14 May 2011 08:08:47 -0400 Subject: (#1853) Pacman package provider Stub the command method, so it doesn't give an error. --- spec/unit/provider/package/pacman_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/unit/provider/package/pacman_spec.rb b/spec/unit/provider/package/pacman_spec.rb index 499ccca6a..fbe4c446e 100644 --- a/spec/unit/provider/package/pacman_spec.rb +++ b/spec/unit/provider/package/pacman_spec.rb @@ -6,6 +6,7 @@ provider = Puppet::Type.type(:package).provider(:pacman) describe provider do before do + provider.stubs(:command).with(:pacman).returns('/usr/bin/pacman') @resource = stub 'resource' @resource.stubs(:[]).returns("package") @resource.stubs(:name).returns("name") -- cgit From c81f5c6e6cdb4d7f8bef6814f63f82acbdbdbe33 Mon Sep 17 00:00:00 2001 From: Dominic Maraglia Date: Wed, 18 May 2011 12:12:35 -0700 Subject: Adding a sleep state post starting master Occasional spurious errors seen when running this test -- curl reports an SSL protocol error; I suspect this is actually a timing issue related to starting up the master and not being ready to to accecpt connections. --- acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb b/acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb index 76a6bf818..3f762bcca 100644 --- a/acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb +++ b/acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb @@ -16,6 +16,9 @@ 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("--certdnsnames=\"puppet:$(hostname -s):$(hostname -f)\" --verbose --noop") +# allow Master to start and initialize environment +sleep 1 + # Run test on Agents -- cgit From 8f0cecfb46aface34d5189e60e924c9bfa7f4b13 Mon Sep 17 00:00:00 2001 From: James Turnbull Date: Mon, 23 May 2011 06:19:28 +1000 Subject: Added the vcsrepo type and providers to the core --- lib/puppet/provider/vcsrepo.rb | 34 +++++ lib/puppet/provider/vcsrepo/bzr.rb | 64 +++++++++ lib/puppet/provider/vcsrepo/cvs.rb | 80 +++++++++++ lib/puppet/provider/vcsrepo/git.rb | 264 +++++++++++++++++++++++++++++++++++++ lib/puppet/provider/vcsrepo/hg.rb | 101 ++++++++++++++ lib/puppet/provider/vcsrepo/svn.rb | 82 ++++++++++++ lib/puppet/type/vcsrepo.rb | 138 +++++++++++++++++++ 7 files changed, 763 insertions(+) create mode 100644 lib/puppet/provider/vcsrepo.rb create mode 100644 lib/puppet/provider/vcsrepo/bzr.rb create mode 100644 lib/puppet/provider/vcsrepo/cvs.rb create mode 100644 lib/puppet/provider/vcsrepo/git.rb create mode 100644 lib/puppet/provider/vcsrepo/hg.rb create mode 100644 lib/puppet/provider/vcsrepo/svn.rb create mode 100644 lib/puppet/type/vcsrepo.rb diff --git a/lib/puppet/provider/vcsrepo.rb b/lib/puppet/provider/vcsrepo.rb new file mode 100644 index 000000000..2c026ba86 --- /dev/null +++ b/lib/puppet/provider/vcsrepo.rb @@ -0,0 +1,34 @@ +require 'tmpdir' +require 'digest/md5' +require 'fileutils' + +# Abstract +class Puppet::Provider::Vcsrepo < Puppet::Provider + + private + + def set_ownership + owner = @resource.value(:owner) || nil + group = @resource.value(:group) || nil + FileUtils.chown_R(owner, group, @resource.value(:path)) + end + + def path_exists? + File.directory?(@resource.value(:path)) + end + + # Note: We don't rely on Dir.chdir's behavior of automatically returning the + # value of the last statement -- for easier stubbing. + def at_path(&block) #:nodoc: + value = nil + Dir.chdir(@resource.value(:path)) do + value = yield + end + value + end + + def tempdir + @tempdir ||= File.join(Dir.tmpdir, 'vcsrepo-' + Digest::MD5.hexdigest(@resource.value(:path))) + end + +end diff --git a/lib/puppet/provider/vcsrepo/bzr.rb b/lib/puppet/provider/vcsrepo/bzr.rb new file mode 100644 index 000000000..a0605624b --- /dev/null +++ b/lib/puppet/provider/vcsrepo/bzr.rb @@ -0,0 +1,64 @@ +require File.join(File.dirname(__FILE__), '..', 'vcsrepo') + +Puppet::Type.type(:vcsrepo).provide(:bzr, :parent => Puppet::Provider::Vcsrepo) do + desc "Supports Bazaar repositories" + + commands :bzr => 'bzr' + defaultfor :bzr => :exists + has_features :reference_tracking + + def create + if !@resource.value(:source) + create_repository(@resource.value(:path)) + else + clone_repository(@resource.value(:revision)) + end + end + + def exists? + File.directory?(File.join(@resource.value(:path), '.bzr')) + end + + def destroy + FileUtils.rm_rf(@resource.value(:path)) + end + + def revision + at_path do + current_revid = bzr('version-info')[/^revision-id:\s+(\S+)/, 1] + desired = @resource.value(:revision) + begin + desired_revid = bzr('revision-info', desired).strip.split(/\s+/).last + rescue Puppet::ExecutionFailure + # Possible revid available during update (but definitely not current) + desired_revid = nil + end + if current_revid == desired_revid + desired + else + current_revid + end + end + end + + def revision=(desired) + bzr('update', '-r', desired, @resource.value(:path)) + end + + private + + def create_repository(path) + bzr('init', path) + end + + def clone_repository(revision) + args = ['branch'] + if revision + args.push('-r', revision) + end + args.push(@resource.value(:source), + @resource.value(:path)) + bzr(*args) + end + +end diff --git a/lib/puppet/provider/vcsrepo/cvs.rb b/lib/puppet/provider/vcsrepo/cvs.rb new file mode 100644 index 000000000..e82c23afe --- /dev/null +++ b/lib/puppet/provider/vcsrepo/cvs.rb @@ -0,0 +1,80 @@ +require File.join(File.dirname(__FILE__), '..', 'vcsrepo') + +Puppet::Type.type(:vcsrepo).provide(:cvs, :parent => Puppet::Provider::Vcsrepo) do + desc "Supports CVS repositories/workspaces" + + commands :cvs => 'cvs' + defaultfor :cvs => :exists + has_features :gzip_compression, :reference_tracking + + def create + if !@resource.value(:source) + create_repository(@resource.value(:path)) + else + checkout_repository + end + end + + def exists? + if @resource.value(:source) + directory = File.join(@resource.value(:path), 'CVS') + else + directory = File.join(@resource.value(:path), 'CVSROOT') + end + File.directory?(directory) + end + + def destroy + FileUtils.rm_rf(@resource.value(:path)) + end + + def revision + if File.exist?(tag_file) + contents = File.read(tag_file) + # Note: Doesn't differentiate between N and T entries + contents[1..-1] + else + 'MAIN' + end + end + + def revision=(desired) + at_path do + cvs('update', '-r', desired, '.') + end + end + + private + + def tag_file + File.join(@resource.value(:path), 'CVS', 'Tag') + end + + def checkout_repository + dirname, basename = File.split(@resource.value(:path)) + Dir.chdir(dirname) do + args = ['-d', @resource.value(:source)] + if @resource.value(:compression) + args.push('-z', @resource.value(:compression)) + end + args.push('checkout', '-d', basename, module_name) + cvs(*args) + end + if @resource.value(:revision) + self.revision = @resource.value(:revision) + end + end + + # When the source: + # * Starts with ':' (eg, :pserver:...) + def module_name + if (source = @resource.value(:source)) + source[0, 1] == ':' ? File.basename(source) : '.' + end + end + + def create_repository(path) + cvs('-d', path, 'init') + end + +end diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb new file mode 100644 index 000000000..fa7e492cf --- /dev/null +++ b/lib/puppet/provider/vcsrepo/git.rb @@ -0,0 +1,264 @@ +require File.join(File.dirname(__FILE__), '..', 'vcsrepo') + +Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo) do + desc "Supports Git repositories" + + ##TODO modify the commands below so that the su - is included + commands :git => 'git' + defaultfor :git => :exists + has_features :bare_repositories, :reference_tracking + + def create + if !@resource.value(:source) + init_repository(@resource.value(:path)) + else + clone_repository(@resource.value(:source), @resource.value(:path)) + if @resource.value(:revision) + if @resource.value(:ensure) == :bare + notice "Ignoring revision for bare repository" + else + checkout_or_reset + end + end + if @resource.value(:ensure) != :bare + update_submodules + end + end + update_owner_and_excludes + end + + def destroy + FileUtils.rm_rf(@resource.value(:path)) + end + + def latest? + at_path do + return self.revision == self.latest + end + end + + def latest + branch = on_branch? + if branch == 'master' + return get_revision('origin/HEAD') + else + return get_revision('origin/%s' % branch) + end + end + + def revision + update_references + current = at_path { git('rev-parse', 'HEAD') } + canonical = at_path { git('rev-parse', @resource.value(:revision)) } + if current == canonical + @resource.value(:revision) + else + current + end + end + + def revision=(desired) + checkout_or_reset(desired) + if local_branch_revision?(desired) + # reset instead of pull to avoid merge conflicts. assuming remote is + # authoritative. + # might be worthwhile to have an allow_local_changes param to decide + # whether to reset or pull when we're ensuring latest. + at_path { git('reset', '--hard', "origin/#{desired}") } + end + if @resource.value(:ensure) != :bare + update_submodules + end + update_owner_and_excludes + end + + def bare_exists? + bare_git_config_exists? && !working_copy_exists? + end + + def working_copy_exists? + File.directory?(File.join(@resource.value(:path), '.git')) + end + + def exists? + working_copy_exists? || bare_exists? + end + + def update_references + at_path do + git('fetch', '--tags', 'origin') + end + end + + private + + def bare_git_config_exists? + File.exist?(File.join(@resource.value(:path), 'config')) + end + + def clone_repository(source, path) + check_force + args = ['clone'] + if @resource.value(:ensure) == :bare + args << '--bare' + end + if !File.exist?(File.join(@resource.value(:path), '.git')) + args.push(source, path) + git(*args) + else + notice "Repo has already been cloned" + end + end + + def check_force + if path_exists? + if @resource.value(:force) + notice "Removing %s to replace with vcsrepo." % @resource.value(:path) + destroy + else + raise Puppet::Error, "Could not create repository (non-repository at path)" + end + end + end + + def init_repository(path) + check_force + if @resource.value(:ensure) == :bare && working_copy_exists? + convert_working_copy_to_bare + elsif @resource.value(:ensure) == :present && bare_exists? + convert_bare_to_working_copy + else + # normal init + FileUtils.mkdir(@resource.value(:path)) + args = ['init'] + if @resource.value(:ensure) == :bare + args << '--bare' + end + at_path do + git(*args) + end + end + end + + # Convert working copy to bare + # + # Moves: + # /.git + # to: + # / + def convert_working_copy_to_bare + notice "Converting working copy repository to bare repository" + FileUtils.mv(File.join(@resource.value(:path), '.git'), tempdir) + FileUtils.rm_rf(@resource.value(:path)) + FileUtils.mv(tempdir, @resource.value(:path)) + end + + # Convert bare to working copy + # + # Moves: + # / + # to: + # /.git + def convert_bare_to_working_copy + notice "Converting bare repository to working copy repository" + FileUtils.mv(@resource.value(:path), tempdir) + FileUtils.mkdir(@resource.value(:path)) + FileUtils.mv(tempdir, File.join(@resource.value(:path), '.git')) + if commits_in?(File.join(@resource.value(:path), '.git')) + reset('HEAD') + git('checkout', '-f') + update_owner_and_excludes + end + end + + def commits_in?(dot_git) + Dir.glob(File.join(dot_git, 'objects/info/*'), File::FNM_DOTMATCH) do |e| + return true unless %w(. ..).include?(File::basename(e)) + end + false + end + + def checkout_or_reset(revision = @resource.value(:revision)) + if local_branch_revision? + reset(revision) + elsif tag_revision? + at_path { git('checkout', '-b', revision) } + elsif remote_branch_revision? + at_path { git('checkout', '-b', revision, '--track', "origin/#{revision}") } + end + end + + def reset(desired) + at_path do + git('reset', '--hard', desired) + end + end + + def update_submodules + at_path do + git('submodule', 'init') + git('submodule', 'update') + git('submodule', 'foreach', 'git', 'submodule', 'init') + git('submodule', 'foreach', 'git', 'submodule', 'update') + end + end + + def remote_branch_revision?(revision = @resource.value(:revision)) + # git < 1.6 returns 'origin/#{revision}' + # git 1.6+ returns 'remotes/origin/#{revision}' + at_path { branches.grep /(remotes\/)?origin\/#{revision}/ } + end + + def local_branch_revision?(revision = @resource.value(:revision)) + at_path { branches.include?(revision) } + end + + def tag_revision?(revision = @resource.value(:revision)) + at_path { tags.include?(revision) } + end + + def branches + at_path { git('branch', '-a') }.gsub('*', ' ').split(/\n/).map { |line| line.strip } + end + + def on_branch? + at_path { git('branch', '-a') }.split(/\n/).grep(/\*/).to_s.gsub('*', '').strip + end + + def tags + at_path { git('tag', '-l') }.split(/\n/).map { |line| line.strip } + end + + def set_excludes + at_path { open('.git/info/exclude', 'w') { |f| @resource.value(:excludes).each { |ex| f.write(ex + "\n") }}} + end + + def get_revision(rev) + if !working_copy_exists? + create + end + at_path do + git('fetch', 'origin') + git('fetch', '--tags', 'origin') + end + current = at_path { git('rev-parse', rev).strip } + if @resource.value(:revision) + if local_branch_revision? + canonical = at_path { git('rev-parse', @resource.value(:revision)).strip } + elsif remote_branch_revision? + canonical = at_path { git('rev-parse', 'origin/' + @resource.value(:revision)).strip } + end + current = @resource.value(:revision) if current == canonical + end + return current + end + + def update_owner_and_excludes + if @resource.value(:owner) or @resource.value(:group) + set_ownership + end + if @resource.value(:excludes) + set_excludes + end + end +end diff --git a/lib/puppet/provider/vcsrepo/hg.rb b/lib/puppet/provider/vcsrepo/hg.rb new file mode 100644 index 000000000..f96758612 --- /dev/null +++ b/lib/puppet/provider/vcsrepo/hg.rb @@ -0,0 +1,101 @@ +require File.join(File.dirname(__FILE__), '..', 'vcsrepo') + +Puppet::Type.type(:vcsrepo).provide(:hg, :parent => Puppet::Provider::Vcsrepo) do + desc "Supports Mercurial repositories" + + commands :hg => 'hg' + defaultfor :hg => :exists + has_features :reference_tracking + + def create + if !@resource.value(:source) + create_repository(@resource.value(:path)) + else + clone_repository(@resource.value(:revision)) + end + update_owner + end + + def working_copy_exists? + File.directory?(File.join(@resource.value(:path), '.hg')) + end + + def exists? + working_copy_exists? + end + + def destroy + FileUtils.rm_rf(@resource.value(:path)) + end + + def latest? + at_path do + return self.revision == self.latest + end + end + + def latest + at_path do + begin + hg('incoming', '--branch', '.', '--newest-first', '--limit', '1')[/^changeset:\s+(?:-?\d+):(\S+)/m, 1] + rescue Puppet::ExecutionFailure + # If there are no new changesets, return the current nodeid + self.revision + end + end + end + + def revision + at_path do + current = hg('parents')[/^changeset:\s+(?:-?\d+):(\S+)/m, 1] + desired = @resource.value(:revision) + if desired + # Return the tag name if it maps to the current nodeid + mapped = hg('tags')[/^#{Regexp.quote(desired)}\s+\d+:(\S+)/m, 1] + if current == mapped + desired + else + current + end + else + current + end + end + end + + def revision=(desired) + at_path do + hg('pull') + begin + hg('merge') + rescue Puppet::ExecutionFailure + # If there's nothing to merge, just skip + end + hg('update', '--clean', '-r', desired) + end + update_owner + end + + private + + def create_repository(path) + hg('init', path) + end + + def clone_repository(revision) + args = ['clone'] + if revision + args.push('-u', revision) + end + args.push(@resource.value(:source), + @resource.value(:path)) + hg(*args) + end + + def update_owner + if @resource.value(:owner) or @resource.value(:group) + set_ownership + end + end + +end diff --git a/lib/puppet/provider/vcsrepo/svn.rb b/lib/puppet/provider/vcsrepo/svn.rb new file mode 100644 index 000000000..680188c1e --- /dev/null +++ b/lib/puppet/provider/vcsrepo/svn.rb @@ -0,0 +1,82 @@ +require File.join(File.dirname(__FILE__), '..', 'vcsrepo') + +Puppet::Type.type(:vcsrepo).provide(:svn, :parent => Puppet::Provider::Vcsrepo) do + desc "Supports Subversion repositories" + + commands :svn => 'svn', + :svnadmin => 'svnadmin' + + defaultfor :svn => :exists + has_features :filesystem_types, :reference_tracking + + def create + if !@resource.value(:source) + create_repository(@resource.value(:path)) + else + checkout_repository(@resource.value(:source), + @resource.value(:path), + @resource.value(:revision)) + end + end + + def working_copy_exists? + File.directory?(File.join(@resource.value(:path), '.svn')) + end + + def exists? + working_copy_exists? + end + + def destroy + FileUtils.rm_rf(@resource.value(:path)) + end + + def latest? + at_path do + if self.revision < self.latest then + return false + else + return true + end + end + end + + def latest + at_path do + svn('info', '-r', 'HEAD')[/^Revision:\s+(\d+)/m, 1] + end + end + + def revision + at_path do + svn('info')[/^Revision:\s+(\d+)/m, 1] + end + end + + def revision=(desired) + at_path do + svn('update', '-r', desired) + end + end + + private + + def checkout_repository(source, path, revision = nil) + args = ['checkout'] + if revision + args.push('-r', revision) + end + args.push(source, path) + svn(*args) + end + + def create_repository(path) + args = ['create'] + if @resource.value(:fstype) + args.push('--fs-type', @resource.value(:fstype)) + end + args << path + svnadmin(*args) + end + +end diff --git a/lib/puppet/type/vcsrepo.rb b/lib/puppet/type/vcsrepo.rb new file mode 100644 index 000000000..f0d2613ca --- /dev/null +++ b/lib/puppet/type/vcsrepo.rb @@ -0,0 +1,138 @@ +require 'pathname' + +Puppet::Type.newtype(:vcsrepo) do + desc "A local version control repository" + + feature :gzip_compression, + "The provider supports explicit GZip compression levels" + + feature :bare_repositories, + "The provider differentiates between bare repositories + and those with working copies", + :methods => [:bare_exists?, :working_copy_exists?] + + feature :filesystem_types, + "The provider supports different filesystem types" + + feature :reference_tracking, + "The provider supports tracking revision references that can change + over time (eg, some VCS tags and branch names)" + + ensurable do + attr_accessor :latest + + def insync?(is) + @should ||= [] + + case should + when :present + return true unless [:absent, :purged, :held].include?(is) + when :latest + if is == :latest + return true + else + self.debug "%s repo revision is %s, latest is %s" % + [@resource.name, provider.revision, provider.latest] + return false + end + end + end + + newvalue :present do + provider.create + end + + newvalue :bare, :required_features => [:bare_repositories] do + provider.create + end + + newvalue :absent do + provider.destroy + end + + newvalue :latest, :required_features => [:reference_tracking] do + if provider.exists? + if provider.respond_to?(:update_references) + provider.update_references + end + if provider.respond_to?(:latest?) + reference = provider.latest || provider.revision + else + reference = resource.value(:revision) || provider.revision + end + notice "Updating to latest '#{reference}' revision" + provider.revision = reference + else + provider.create + end + end + + def retrieve + prov = @resource.provider + if prov + if prov.working_copy_exists? + prov.latest? ? :latest : :present + elsif prov.class.feature?(:bare_repositories) and prov.bare_exists? + :bare + else + :absent + end + else + raise Puppet::Error, "Could not find provider" + end + end + + end + + newparam(:path) do + desc "Absolute path to repository" + isnamevar + validate do |value| + path = Pathname.new(value) + unless path.absolute? + raise ArgumentError, "Path must be absolute: #{path}" + end + end + end + + newparam(:source) do + desc "The source URI for the repository" + end + + newparam(:fstype, :required_features => [:filesystem_types]) do + desc "Filesystem type" + end + + newproperty(:revision) do + desc "The revision of the repository" + newvalue(/^\S+$/) + end + + newparam(:owner) do + desc "The user/uid that owns the repository files" + end + + newparam(:group) do + desc "The group/gid that owns the repository files" + end + + newparam(:excludes) do + desc "Files to be excluded from the repository" + end + + newparam(:force) do + desc "Force repository creation, destroying any files on the path in the process." + newvalues(:true, :false) + defaultto false + end + + newparam :compression, :required_features => [:gzip_compression] do + desc "Compression level" + validate do |amount| + unless Integer(amount).between?(0, 6) + raise ArgumentError, "Unsupported compression level: #{amount} (expected 0-6)" + end + end + end + +end -- cgit From 107b38a94f8b4e4a0fcca4879a167ab4c955fe4d Mon Sep 17 00:00:00 2001 From: Matt Robinson Date: Tue, 24 May 2011 09:31:39 -0700 Subject: maint: Fix pacman provider to work with Ruby 1.9 Ruby 1.9 doesn't allow the lambda to walk up the directory structure to require the spec helper This is the same issue as with commit: f6da3339f59bbd9243a03dc1e417b1fed7955c7e Also, you can't call each on a string in Ruby 1.9 directly since it doesn't implicitly do a split on \n like it did in older Rubies, but each_line works all the way back to 1.8.5 Reviewed-by: Nick Lewis --- lib/puppet/provider/package/pacman.rb | 2 +- spec/unit/provider/package/pacman_spec.rb | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/puppet/provider/package/pacman.rb b/lib/puppet/provider/package/pacman.rb index 6eb7dbe3d..5e05d147e 100644 --- a/lib/puppet/provider/package/pacman.rb +++ b/lib/puppet/provider/package/pacman.rb @@ -33,7 +33,7 @@ Puppet::Type.type(:package).provide :pacman, :parent => Puppet::Provider::Packag fields = [:name, :ensure] hash = {} - process.each { |line| + process.each_line { |line| if match = regex.match(line) fields.zip(match.captures) { |field,value| hash[field] = value diff --git a/spec/unit/provider/package/pacman_spec.rb b/spec/unit/provider/package/pacman_spec.rb index fbe4c446e..679172621 100644 --- a/spec/unit/provider/package/pacman_spec.rb +++ b/spec/unit/provider/package/pacman_spec.rb @@ -1,6 +1,5 @@ -#!/usr/bin/env ruby - -Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } +#!/usr/bin/env rspec +require 'spec_helper' provider = Puppet::Type.type(:package).provider(:pacman) -- cgit From b101804f5825e9f69a690f9a974222dd7b83a330 Mon Sep 17 00:00:00 2001 From: Dominic Maraglia Date: Tue, 24 May 2011 11:28:40 -0700 Subject: add puppet master polling step for ticket 7117 The test for ticket 7117 producedes spurious failures due to timing: a curl command is executed from an agent to a freshly started Puppet Master; if the Puppet Master is not ready to accept the connection the test will fail. Added an until loop that issues simple curl command to see if the Puppet Master is up and ready --- acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb b/acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb index 3f762bcca..37c71893c 100644 --- a/acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb +++ b/acceptance/tests/ticket_7117_broke_env_criteria_authconf.rb @@ -17,9 +17,17 @@ on master, "ps -U puppet | awk '/puppet/ { print \$1 }' | xargs kill || echo \"P step "Master: Start Puppet Master" on master, puppet_master("--certdnsnames=\"puppet:$(hostname -s):$(hostname -f)\" --verbose --noop") # allow Master to start and initialize environment -sleep 1 - +step "Verify Puppet Master is ready to accept connections" +host=agents.first +time1 = Time.new +until + on(host, "curl -k https://#{master}:8140") do + sleep 1 + end +time2 = Time.new +elapsed = time2 - time1 +Log.notify "Slept for #{elapsed} seconds waiting for Puppet Master to become ready" # Run test on Agents step "Agent: agent --test" -- cgit From 92a8f4a1cbb4e11a9bacf571b4c9f3d8181392fb Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Fri, 17 Jun 2011 11:23:21 -0700 Subject: Remove order dependency from functions integration spec The test in spec/integration/parser/functions_spec.rb would fail when the spec tests were run in the order (among other orderings): spec/unit/parser/functions/tag_spec.rb spec/unit/parser/templatewrapper_spec.rb spec/integration/parser/functions_spec.rb There are tests that would cause the "template" function to be loaded into the root environment. Puppet::Parser::Functions.function("template") would then detect its presence and P::P::F.rmfunction("template") would fail since #function(...) looks in more than just the current environment to see if a function is defined, while #rmfunction(...) only looks in the current environment to see if a function can be removed. In the test ordering specified earlier, tag_spec.rb would load the "template" function, and templatewrapper_spec.rb would create a current environment that would mask the root environment for #rmfunction(...), but not for #function(...) Since #rmfunction(...) only looks in the current environment, we should be using #functions.include?("template") since that matches the check that #rmfunction(...) itself uses. Paired-with: Nick Lewis --- spec/integration/parser/functions_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/integration/parser/functions_spec.rb b/spec/integration/parser/functions_spec.rb index 6791987d7..6a8fbca9c 100755 --- a/spec/integration/parser/functions_spec.rb +++ b/spec/integration/parser/functions_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Puppet::Parser::Functions do before :each do - Puppet::Parser::Functions.rmfunction("template") if Puppet::Parser::Functions.function("template") + Puppet::Parser::Functions.rmfunction("template") if Puppet::Parser::Functions.functions.include?("template") end it "should support multiple threads autoloading the same function" do -- cgit From 51608221da248e679326087303ecd0c649225d5b Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Fri, 17 Jun 2011 11:26:58 -0700 Subject: Clean up indentation, whitespace, and commented out code The mis-indented code, extra newlines, and commented out code were noticed while investigating the order dependent test failure fixed in 4365c8ba. Reviewed-by: Max Martin --- lib/puppet/parser/functions.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb index 5807c0bbe..e19ac127f 100644 --- a/lib/puppet/parser/functions.rb +++ b/lib/puppet/parser/functions.rb @@ -16,11 +16,9 @@ module Puppet::Parser::Functions def self.autoloader unless defined?(@autoloader) - - @autoloader = Puppet::Util::Autoload.new( + @autoloader = Puppet::Util::Autoload.new( self, "puppet/parser/functions", - :wrap => false ) end @@ -88,7 +86,6 @@ module Puppet::Parser::Functions ret = "" functions.sort { |a,b| a[0].to_s <=> b[0].to_s }.each do |name, hash| - #ret += "#{name}\n#{hash[:type]}\n" ret += "#{name}\n#{"-" * name.to_s.length}\n" if hash[:doc] ret += Puppet::Util::Docs.scrub(hash[:doc]) @@ -114,11 +111,9 @@ module Puppet::Parser::Functions end # Runs a newfunction to create a function for each of the log levels - Puppet::Util::Log.levels.each do |level| newfunction(level, :doc => "Log a message on the server at level #{level.to_s}.") do |vals| send(level, vals.join(" ")) end end - end -- cgit