forked from puppetlabs/puppet
/
should_remove_cron.rb
executable file
·36 lines (28 loc) · 1.38 KB
/
should_remove_cron.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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