diff --git a/acceptance/tests/resource/group/should_create.rb b/acceptance/tests/resource/group/should_create.rb index efb80a4bc..16a74c7dd 100755 --- a/acceptance/tests/resource/group/should_create.rb +++ b/acceptance/tests/resource/group/should_create.rb @@ -1,20 +1,17 @@ -test_name "should create group" +test_name "should create a group" name = "pl#{rand(999999).to_i}" -def cleanup(name) - step "remove group #{name} if it exists" - on agents, "if getent group #{name}; then groupdel #{name}; fi" -end +agents.each do |agent| + step "ensure the group does not exist" + agent.group_absent(name) -cleanup(name) + step "create the group" + on agent, puppet_resource('group', name, 'ensure=present') -step "create the group #{name} with the resource agent" -on(agents, puppet_resource('group', name, 'ensure=present')) + step "verify the group exists" + agent.group_get(name) -step "verify the group #{name} was created" -on(agents, "getent group #{name}") do - fail_test "group information is not sensible" unless stdout =~ /^#{name}:.*:[0-9]+:/ + step "delete the group" + agent.group_absent(name) end - -cleanup(name) diff --git a/acceptance/tests/resource/group/should_destroy.rb b/acceptance/tests/resource/group/should_destroy.rb index 1551abe75..6b887579f 100755 --- a/acceptance/tests/resource/group/should_destroy.rb +++ b/acceptance/tests/resource/group/should_destroy.rb @@ -1,14 +1,14 @@ test_name "should destroy a group" -name = "test-group-#{Time.new.to_i}" +name = "pl#{rand(999999).to_i}" -step "ensure the group exists on the target system" -on agents, "getent group #{name} || groupadd #{name}" +agents.each do |agent| + step "ensure the group is present" + agent.group_present(name) -step "use puppet to remove the group" -on(agents, puppet_resource('group', name, 'ensure=absent')) + step "delete the group" + on agent, 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] + step "verify the group was deleted" + agent.group_absent(name) +end diff --git a/acceptance/tests/resource/group/should_modify_gid.rb b/acceptance/tests/resource/group/should_modify_gid.rb index b54d40118..65e9a1f95 100755 --- a/acceptance/tests/resource/group/should_modify_gid.rb +++ b/acceptance/tests/resource/group/should_modify_gid.rb @@ -1,24 +1,31 @@ test_name "should modify gid of existing group" name = "pl#{rand(999999).to_i}" gid1 = rand(999999).to_i gid2 = rand(999999).to_i -step "ensure that the group exists with gid #{gid1}" -on(agents, puppet_resource('group', name, 'ensure=present', "gid=#{gid1}")) do +agents.each do |agent| + if agent['platform'].include?('windows') + skip_test "Test not supported on this platform" + next + end + + step "ensure that the group exists with gid #{gid1}" + on(agent, puppet_resource('group', name, 'ensure=present', "gid=#{gid1}")) do fail_test "missing gid notice" unless stdout =~ /gid +=> +'#{gid1}'/ -end + end -step "ensure that we can modify the GID of the group to #{gid2}" -on(agents, puppet_resource('group', name, 'ensure=present', "gid=#{gid2}")) do + step "ensure that we can modify the GID of the group to #{gid2}" + on(agent, puppet_resource('group', name, 'ensure=present', "gid=#{gid2}")) do fail_test "missing gid notice" unless stdout =~ /gid +=> +'#{gid2}'/ -end + end -step "verify that the GID changed" -on(agents, "getent group #{name}") do + step "verify that the GID changed" + on(agent, "getent group #{name}") do fail_test "gid is wrong through getent output" unless - stdout =~ /^#{name}:.*:#{gid2}:/ -end + stdout =~ /^#{name}:.*:#{gid2}:/ + end -step "clean up the system after the test run" -on(agents, puppet_resource('group', name, 'ensure=absent')) + step "clean up the system after the test run" + on(agent, puppet_resource('group', name, 'ensure=absent')) +end diff --git a/acceptance/tests/resource/group/should_not_create_existing.rb b/acceptance/tests/resource/group/should_not_create_existing.rb index ed4f54cdc..351ca0c74 100755 --- a/acceptance/tests/resource/group/should_not_create_existing.rb +++ b/acceptance/tests/resource/group/should_not_create_existing.rb @@ -1,15 +1,17 @@ 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')) +agents.each do |agent| + step "ensure the group exists on the target node" + agent.group_present(name) -step "verify that we don't try and create the existing group" -on(agents, puppet_resource('group', name, 'ensure=present')) do + step "verify that we don't try and create the existing group" + on(agent, puppet_resource('group', name, 'ensure=present')) do fail_test "looks like we created the group" if - stdout.include? '/Group[bozo]/ensure: created' -end + stdout.include? "/Group[#{name}]/ensure: created" + end -step "clean up the system after the test run" -on(agents, puppet_resource('group', name, 'ensure=absent')) + step "clean up the system after the test run" + agent.group_absent(name) +end diff --git a/acceptance/tests/resource/group/should_not_destoy_unexisting.rb b/acceptance/tests/resource/group/should_not_destoy_unexisting.rb index 256a8f146..287bb0fa6 100755 --- a/acceptance/tests/resource/group/should_not_destoy_unexisting.rb +++ b/acceptance/tests/resource/group/should_not_destoy_unexisting.rb @@ -1,13 +1,15 @@ 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')) +agents.each do |agent| + agent.group_absent(name) +end 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" + 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 index 3bbce071c..12da6ea1a 100755 --- a/acceptance/tests/resource/group/should_query.rb +++ b/acceptance/tests/resource/group/should_query.rb @@ -1,15 +1,16 @@ -test_name "group should query" +test_name "test that we can query and find a group that exists." -name = "test-group-#{Time.new.to_i}" +name = "pl#{rand(999999).to_i}" -step "ensure the group exists on the target systems" -on agents, "getent group #{name} || groupadd #{name}" +agents.each do |agent| + step "ensure that our test group exists" + agent.group_present(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 "query for the resource and verify it was found" + on(agent, puppet_resource('group', name)) do + fail_test "didn't find the group #{name}" unless stdout.include? 'present' + end -step "clean up the system after the test" -on(agents, puppet_resource('group', name, 'ensure=absent')) + step "clean up the group we added" + agent.group_absent(name) +end diff --git a/acceptance/tests/resource/group/should_query_all.rb b/acceptance/tests/resource/group/should_query_all.rb index 9abcfed21..87ce781a8 100755 --- a/acceptance/tests/resource/group/should_query_all.rb +++ b/acceptance/tests/resource/group/should_query_all.rb @@ -1,30 +1,23 @@ -test_name "puppet resource should query all groups" +test_name "should query all groups" -agents.each do |host| - groups = {} +agents.each do |agent| + step "query natively" + groups = agent.group_list - 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 + fail_test("No groups found") unless groups - 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] + step "query with puppet" + on(agent, puppet_resource('group')) do + stdout.each_line do |line| + name = ( line.match(/^group \{ '([^']+)'/) or next )[1] - if groups.include? name then - groups.delete name - else - fail_test "group #{name} found by puppet, not getent" - end - end - end + unless groups.delete(name) + fail_test "group #{name} found by puppet, not natively" + end end + end - groups.keys.each do |name| - fail_test "group #{name} found by getent, not puppet" - end + if groups.length > 0 then + fail_test "#{groups.length} groups found natively, not puppet: #{groups.join(', ')}" + end end