puppet 0.9.2 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puppet might be problematic. Click here for more details.
- data/CHANGELOG +58 -0
- data/README +21 -18
- data/Rakefile +176 -36
- data/bin/puppet +34 -48
- data/bin/puppetca +41 -28
- data/bin/puppetd +87 -65
- data/bin/puppetdoc +99 -23
- data/bin/puppetmasterd +72 -91
- data/conf/redhat/client.init +80 -0
- data/conf/redhat/client.sysconfig +11 -0
- data/conf/redhat/fileserver.conf +12 -0
- data/conf/redhat/puppet.spec +130 -0
- data/conf/redhat/server.init +89 -0
- data/conf/redhat/server.sysconfig +9 -0
- data/examples/code/allatonce +2 -2
- data/examples/code/assignments +1 -1
- data/examples/code/classing +2 -2
- data/examples/code/components +2 -2
- data/examples/code/file.bl +5 -5
- data/examples/code/filedefaults +2 -2
- data/examples/code/fileparsing +1 -1
- data/examples/code/filerecursion +1 -1
- data/examples/code/functions +1 -1
- data/examples/code/groups +1 -1
- data/examples/code/importing +1 -1
- data/examples/code/nodes +1 -1
- data/examples/code/one +1 -1
- data/examples/code/relationships +2 -2
- data/examples/code/simpletests +5 -5
- data/examples/code/snippets/argumentdefaults +2 -2
- data/examples/code/snippets/casestatement +16 -8
- data/examples/code/snippets/classheirarchy.pp +4 -4
- data/examples/code/snippets/classincludes.pp +4 -4
- data/examples/code/snippets/classpathtest +2 -2
- data/examples/code/snippets/componentmetaparams.pp +11 -0
- data/examples/code/snippets/dirchmod +5 -5
- data/examples/code/snippets/emptyclass.pp +9 -0
- data/examples/code/snippets/failmissingexecpath.pp +1 -1
- data/examples/code/snippets/falsevalues.pp +1 -1
- data/examples/code/snippets/filecreate +5 -5
- data/examples/code/snippets/implicititeration +5 -5
- data/examples/code/snippets/multipleinstances +4 -4
- data/examples/code/snippets/namevartest +3 -3
- data/examples/code/snippets/scopetest +1 -1
- data/examples/code/snippets/selectorvalues.pp +3 -3
- data/examples/code/snippets/simpledefaults +2 -2
- data/examples/code/snippets/simpleselector +5 -5
- data/examples/code/snippets/singleary.pp +19 -0
- data/examples/root/etc/init.d/sleeper +3 -2
- data/ext/emacs/puppet-mode-init.el +6 -0
- data/ext/emacs/puppet-mode.el +189 -0
- data/ext/ldap/puppet.schema +17 -0
- data/ext/{module:puppet → module_puppet} +30 -31
- data/ext/vim/filetype.vim +9 -0
- data/ext/vim/puppet.vim +87 -0
- data/install.rb +63 -30
- data/lib/puppet.rb +216 -122
- data/lib/puppet/client.rb +51 -416
- data/lib/puppet/client/ca.rb +17 -0
- data/lib/puppet/client/dipper.rb +78 -0
- data/lib/puppet/client/file.rb +20 -0
- data/lib/puppet/client/log.rb +17 -0
- data/lib/puppet/client/master.rb +246 -0
- data/lib/puppet/client/proxy.rb +27 -0
- data/lib/puppet/client/status.rb +7 -0
- data/lib/puppet/config.rb +563 -13
- data/lib/puppet/daemon.rb +50 -22
- data/lib/puppet/element.rb +4 -4
- data/lib/puppet/event-loop.rb +1 -0
- data/lib/puppet/event-loop/better-definers.rb +367 -0
- data/lib/puppet/event-loop/event-loop.rb +355 -0
- data/lib/puppet/event-loop/signal-system.rb +220 -0
- data/lib/puppet/event.rb +9 -11
- data/lib/puppet/filetype.rb +195 -0
- data/lib/puppet/log.rb +35 -12
- data/lib/puppet/metric.rb +2 -2
- data/lib/puppet/networkclient.rb +145 -0
- data/lib/puppet/parameter.rb +335 -0
- data/lib/puppet/parser/ast.rb +42 -1453
- data/lib/puppet/parser/ast/astarray.rb +88 -0
- data/lib/puppet/parser/ast/branch.rb +47 -0
- data/lib/puppet/parser/ast/caseopt.rb +66 -0
- data/lib/puppet/parser/ast/casestatement.rb +78 -0
- data/lib/puppet/parser/ast/classdef.rb +78 -0
- data/lib/puppet/parser/ast/compdef.rb +111 -0
- data/lib/puppet/parser/ast/component.rb +105 -0
- data/lib/puppet/parser/ast/hostclass.rb +82 -0
- data/lib/puppet/parser/ast/leaf.rb +86 -0
- data/lib/puppet/parser/ast/node.rb +103 -0
- data/lib/puppet/parser/ast/nodedef.rb +68 -0
- data/lib/puppet/parser/ast/objectdef.rb +336 -0
- data/lib/puppet/parser/ast/objectparam.rb +30 -0
- data/lib/puppet/parser/ast/objectref.rb +76 -0
- data/lib/puppet/parser/ast/selector.rb +60 -0
- data/lib/puppet/parser/ast/typedefaults.rb +45 -0
- data/lib/puppet/parser/ast/vardef.rb +44 -0
- data/lib/puppet/parser/interpreter.rb +31 -14
- data/lib/puppet/parser/lexer.rb +2 -4
- data/lib/puppet/parser/parser.rb +332 -242
- data/lib/puppet/parser/scope.rb +55 -38
- data/lib/puppet/server.rb +43 -44
- data/lib/puppet/server/authstore.rb +3 -6
- data/lib/puppet/server/ca.rb +5 -2
- data/lib/puppet/server/filebucket.rb +2 -4
- data/lib/puppet/server/fileserver.rb +28 -12
- data/lib/puppet/server/logger.rb +15 -4
- data/lib/puppet/server/master.rb +62 -7
- data/lib/puppet/sslcertificates.rb +41 -607
- data/lib/puppet/sslcertificates/ca.rb +291 -0
- data/lib/puppet/sslcertificates/certificate.rb +283 -0
- data/lib/puppet/statechange.rb +6 -1
- data/lib/puppet/storage.rb +67 -56
- data/lib/puppet/transaction.rb +25 -9
- data/lib/puppet/transportable.rb +102 -22
- data/lib/puppet/type.rb +1096 -315
- data/lib/puppet/type/component.rb +30 -21
- data/lib/puppet/type/cron.rb +409 -448
- data/lib/puppet/type/exec.rb +234 -174
- data/lib/puppet/type/group.rb +65 -82
- data/lib/puppet/type/nameservice.rb +247 -3
- data/lib/puppet/type/nameservice/netinfo.rb +29 -40
- data/lib/puppet/type/nameservice/objectadd.rb +52 -66
- data/lib/puppet/type/nameservice/posix.rb +6 -194
- data/lib/puppet/type/package.rb +447 -295
- data/lib/puppet/type/package/apt.rb +51 -50
- data/lib/puppet/type/package/bsd.rb +82 -0
- data/lib/puppet/type/package/dpkg.rb +85 -88
- data/lib/puppet/type/package/rpm.rb +67 -63
- data/lib/puppet/type/package/sun.rb +119 -98
- data/lib/puppet/type/package/yum.rb +41 -37
- data/lib/puppet/type/parsedtype.rb +295 -0
- data/lib/puppet/type/parsedtype/host.rb +143 -0
- data/lib/puppet/type/parsedtype/port.rb +232 -0
- data/lib/puppet/type/parsedtype/sshkey.rb +129 -0
- data/lib/puppet/type/pfile.rb +484 -460
- data/lib/puppet/type/pfile/checksum.rb +237 -181
- data/lib/puppet/type/pfile/content.rb +67 -0
- data/lib/puppet/type/pfile/ensure.rb +212 -0
- data/lib/puppet/type/pfile/group.rb +106 -105
- data/lib/puppet/type/pfile/mode.rb +98 -101
- data/lib/puppet/type/pfile/source.rb +228 -209
- data/lib/puppet/type/pfile/type.rb +18 -21
- data/lib/puppet/type/pfile/uid.rb +127 -130
- data/lib/puppet/type/pfilebucket.rb +68 -63
- data/lib/puppet/type/schedule.rb +341 -0
- data/lib/puppet/type/service.rb +351 -255
- data/lib/puppet/type/service/base.rb +9 -14
- data/lib/puppet/type/service/debian.rb +32 -38
- data/lib/puppet/type/service/init.rb +130 -130
- data/lib/puppet/type/service/smf.rb +48 -20
- data/lib/puppet/type/state.rb +229 -16
- data/lib/puppet/type/symlink.rb +51 -63
- data/lib/puppet/type/tidy.rb +105 -102
- data/lib/puppet/type/user.rb +118 -180
- data/lib/puppet/util.rb +100 -6
- data/test/certmgr/certmgr.rb +0 -1
- data/test/client/client.rb +4 -4
- data/test/executables/puppetbin.rb +7 -14
- data/test/executables/puppetca.rb +18 -24
- data/test/executables/puppetd.rb +7 -16
- data/test/executables/puppetmasterd.rb +7 -9
- data/test/executables/puppetmodule.rb +11 -16
- data/test/language/ast.rb +11 -7
- data/test/language/interpreter.rb +1 -1
- data/test/language/scope.rb +2 -0
- data/test/language/snippets.rb +30 -5
- data/test/language/transportable.rb +77 -0
- data/test/other/config.rb +316 -0
- data/test/other/events.rb +22 -21
- data/test/other/log.rb +14 -14
- data/test/other/metrics.rb +4 -8
- data/test/other/overrides.rb +5 -5
- data/test/other/relationships.rb +4 -2
- data/test/other/storage.rb +64 -3
- data/test/other/transactions.rb +20 -20
- data/test/parser/parser.rb +7 -4
- data/test/puppet/conffiles.rb +12 -12
- data/test/puppet/defaults.rb +13 -11
- data/test/puppet/utiltest.rb +14 -11
- data/test/puppettest.rb +156 -48
- data/test/server/bucket.rb +2 -2
- data/test/server/fileserver.rb +6 -6
- data/test/server/logger.rb +19 -11
- data/test/server/master.rb +33 -4
- data/test/server/server.rb +2 -7
- data/test/types/basic.rb +5 -7
- data/test/types/component.rb +22 -18
- data/test/types/cron.rb +111 -44
- data/test/types/exec.rb +116 -59
- data/test/types/file.rb +262 -137
- data/test/types/filebucket.rb +13 -15
- data/test/types/fileignoresource.rb +12 -16
- data/test/types/filesources.rb +73 -48
- data/test/types/filetype.rb +13 -15
- data/test/types/group.rb +15 -13
- data/test/types/host.rb +146 -0
- data/test/types/package.rb +74 -63
- data/test/types/port.rb +139 -0
- data/test/types/query.rb +8 -8
- data/test/types/schedule.rb +335 -0
- data/test/types/service.rb +137 -21
- data/test/types/sshkey.rb +140 -0
- data/test/types/symlink.rb +3 -5
- data/test/types/tidy.rb +5 -14
- data/test/types/type.rb +67 -11
- data/test/types/user.rb +25 -23
- metadata +186 -122
- data/lib/puppet/type/pfile/create.rb +0 -108
- data/lib/puppet/type/pprocess.rb +0 -97
- data/lib/puppet/type/typegen.rb +0 -149
- data/lib/puppet/type/typegen/filerecord.rb +0 -243
- data/lib/puppet/type/typegen/filetype.rb +0 -316
- data/test/other/state.rb +0 -106
data/test/types/port.rb
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
# Test host job creation, modification, and destruction
|
2
|
+
|
3
|
+
if __FILE__ == $0
|
4
|
+
$:.unshift '..'
|
5
|
+
$:.unshift '../../lib'
|
6
|
+
$puppetbase = "../.."
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'puppettest'
|
10
|
+
require 'puppet'
|
11
|
+
require 'puppet/type/parsedtype/port'
|
12
|
+
require 'test/unit'
|
13
|
+
require 'facter'
|
14
|
+
|
15
|
+
class TestPort < Test::Unit::TestCase
|
16
|
+
include TestPuppet
|
17
|
+
def setup
|
18
|
+
super
|
19
|
+
@porttype = Puppet.type(:port)
|
20
|
+
@oldfiletype = @porttype.filetype
|
21
|
+
end
|
22
|
+
|
23
|
+
def teardown
|
24
|
+
@porttype.filetype = @oldfiletype
|
25
|
+
Puppet.type(:file).clear
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
# Here we just create a fake host type that answers to all of the methods
|
30
|
+
# but does not modify our actual system.
|
31
|
+
def mkfaketype
|
32
|
+
@faketype = Puppet::FileType.filetype(:ram)
|
33
|
+
@porttype.filetype = @faketype
|
34
|
+
end
|
35
|
+
|
36
|
+
def mkport
|
37
|
+
port = nil
|
38
|
+
assert_nothing_raised {
|
39
|
+
port = Puppet.type(:port).create(
|
40
|
+
:name => "puppet",
|
41
|
+
:number => "8139",
|
42
|
+
:protocols => "tcp",
|
43
|
+
:description => "The port that Puppet runs on",
|
44
|
+
:alias => "coolness"
|
45
|
+
)
|
46
|
+
}
|
47
|
+
|
48
|
+
return port
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_simpleport
|
52
|
+
mkfaketype
|
53
|
+
host = nil
|
54
|
+
assert_nothing_raised {
|
55
|
+
assert_nil(Puppet.type(:port).retrieve)
|
56
|
+
}
|
57
|
+
|
58
|
+
port = mkport
|
59
|
+
|
60
|
+
assert_nothing_raised {
|
61
|
+
Puppet.type(:port).store
|
62
|
+
}
|
63
|
+
|
64
|
+
assert_nothing_raised {
|
65
|
+
assert(
|
66
|
+
Puppet.type(:port).to_file.include?(
|
67
|
+
Puppet.type(:port).fileobj.read
|
68
|
+
),
|
69
|
+
"File does not include all of our objects"
|
70
|
+
)
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_portsparse
|
75
|
+
fakedata("data/types/ports").each { |file|
|
76
|
+
@porttype.path = file
|
77
|
+
Puppet.info "Parsing %s" % file
|
78
|
+
assert_nothing_raised {
|
79
|
+
@porttype.retrieve
|
80
|
+
}
|
81
|
+
|
82
|
+
# Now just make we've got some ports we know will be there
|
83
|
+
dns = @porttype["domain"]
|
84
|
+
assert(dns, "Could not retrieve DNS port")
|
85
|
+
|
86
|
+
assert_equal("53", dns.is(:number), "DNS number was wrong")
|
87
|
+
%w{udp tcp}.each { |v|
|
88
|
+
assert(dns.is(:protocols).include?(v), "DNS did not include proto %s" % v)
|
89
|
+
}
|
90
|
+
|
91
|
+
@porttype.clear
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_moddingport
|
96
|
+
mkfaketype
|
97
|
+
port = nil
|
98
|
+
port = mkport
|
99
|
+
|
100
|
+
assert_events([:port_created], port)
|
101
|
+
|
102
|
+
port.retrieve
|
103
|
+
|
104
|
+
port[:protocols] = %w{tcp udp}
|
105
|
+
|
106
|
+
assert_events([:port_changed], port)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_multivalues
|
110
|
+
port = mkport
|
111
|
+
assert_raise(Puppet::Error) {
|
112
|
+
port[:protocols] = "udp tcp"
|
113
|
+
}
|
114
|
+
assert_raise(Puppet::Error) {
|
115
|
+
port[:alias] = "puppetmasterd yayness"
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_removal
|
120
|
+
mkfaketype
|
121
|
+
port = mkport()
|
122
|
+
assert_nothing_raised {
|
123
|
+
port[:ensure] = :present
|
124
|
+
}
|
125
|
+
assert_events([:port_created], port)
|
126
|
+
|
127
|
+
port.retrieve
|
128
|
+
assert(port.insync?)
|
129
|
+
assert_nothing_raised {
|
130
|
+
port[:ensure] = :absent
|
131
|
+
}
|
132
|
+
|
133
|
+
assert_events([:port_removed], port)
|
134
|
+
port.retrieve
|
135
|
+
assert_events([], port)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# $Id: port.rb 831 2006-01-16 20:01:20Z luke $
|
data/test/types/query.rb
CHANGED
@@ -8,7 +8,7 @@ require 'puppet'
|
|
8
8
|
require 'puppettest'
|
9
9
|
require 'test/unit'
|
10
10
|
|
11
|
-
# $Id: query.rb
|
11
|
+
# $Id: query.rb 787 2006-01-08 00:02:23Z luke $
|
12
12
|
|
13
13
|
class TestQuery < Test::Unit::TestCase
|
14
14
|
include TestPuppet
|
@@ -18,21 +18,21 @@ class TestQuery < Test::Unit::TestCase
|
|
18
18
|
def file
|
19
19
|
assert_nothing_raised() {
|
20
20
|
cfile = File.join($puppetbase,"examples/root/etc/configfile")
|
21
|
-
unless Puppet
|
22
|
-
Puppet
|
21
|
+
unless Puppet.type(:file).has_key?(cfile)
|
22
|
+
Puppet.type(:file).create(
|
23
23
|
:path => cfile,
|
24
24
|
:check => [:mode, :owner, :checksum]
|
25
25
|
)
|
26
26
|
end
|
27
|
-
@configfile = Puppet
|
27
|
+
@configfile = Puppet.type(:file)[cfile]
|
28
28
|
}
|
29
29
|
return @configfile
|
30
30
|
end
|
31
31
|
|
32
32
|
def service
|
33
33
|
assert_nothing_raised() {
|
34
|
-
unless Puppet
|
35
|
-
Puppet
|
34
|
+
unless Puppet.type(:service).has_key?("sleeper")
|
35
|
+
Puppet.type(:service).create(
|
36
36
|
:name => "sleeper",
|
37
37
|
:type => "init",
|
38
38
|
:path => File.join($puppetbase,"examples/root/etc/init.d"),
|
@@ -40,7 +40,7 @@ class TestQuery < Test::Unit::TestCase
|
|
40
40
|
:check => [:running]
|
41
41
|
)
|
42
42
|
end
|
43
|
-
@sleeper = Puppet
|
43
|
+
@sleeper = Puppet.type(:service)["sleeper"]
|
44
44
|
}
|
45
45
|
|
46
46
|
return @sleeper
|
@@ -48,7 +48,7 @@ class TestQuery < Test::Unit::TestCase
|
|
48
48
|
|
49
49
|
def component(name,*args)
|
50
50
|
assert_nothing_raised() {
|
51
|
-
@component = Puppet
|
51
|
+
@component = Puppet.type(:component).create(:name => name)
|
52
52
|
}
|
53
53
|
|
54
54
|
args.each { |arg|
|
@@ -0,0 +1,335 @@
|
|
1
|
+
if __FILE__ == $0
|
2
|
+
$:.unshift '..'
|
3
|
+
$:.unshift '../../lib'
|
4
|
+
$puppetbase = "../.."
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'puppet'
|
8
|
+
require 'test/unit'
|
9
|
+
require 'puppet/type/schedule'
|
10
|
+
require 'puppettest'
|
11
|
+
|
12
|
+
class TestSchedule < Test::Unit::TestCase
|
13
|
+
include TestPuppet
|
14
|
+
|
15
|
+
def setup
|
16
|
+
super
|
17
|
+
@stype = Puppet::Type::Schedule
|
18
|
+
|
19
|
+
# This will probably get overridden by different tests
|
20
|
+
@now = Time.now
|
21
|
+
Puppet[:ignoreschedules] = false
|
22
|
+
end
|
23
|
+
|
24
|
+
def mksched
|
25
|
+
s = nil
|
26
|
+
assert_nothing_raised {
|
27
|
+
s = @stype.create(
|
28
|
+
:name => "testsched"
|
29
|
+
)
|
30
|
+
}
|
31
|
+
|
32
|
+
s
|
33
|
+
end
|
34
|
+
|
35
|
+
def diff(unit, incr, method, count)
|
36
|
+
diff = @now.to_i.send(method, incr * count)
|
37
|
+
t = Time.at(diff)
|
38
|
+
|
39
|
+
#Puppet.notice "%s: %s %s %s = %s" %
|
40
|
+
# [unit, @now.send(unit), method, count, t]
|
41
|
+
#t.strftime("%H:%M:%S")
|
42
|
+
t
|
43
|
+
end
|
44
|
+
|
45
|
+
def month(method, count)
|
46
|
+
diff(:hour, 3600 * 24 * 30, method, count)
|
47
|
+
end
|
48
|
+
|
49
|
+
def week(method, count)
|
50
|
+
diff(:hour, 3600 * 24 * 7, method, count)
|
51
|
+
end
|
52
|
+
|
53
|
+
def day(method, count)
|
54
|
+
diff(:hour, 3600 * 24, method, count)
|
55
|
+
end
|
56
|
+
|
57
|
+
def hour(method, count)
|
58
|
+
diff(:hour, 3600, method, count)
|
59
|
+
end
|
60
|
+
|
61
|
+
def min(method, count)
|
62
|
+
diff(:min, 60, method, count)
|
63
|
+
end
|
64
|
+
|
65
|
+
def sec(method, count)
|
66
|
+
diff(:sec, 1, method, count)
|
67
|
+
end
|
68
|
+
|
69
|
+
def settimes
|
70
|
+
unless defined? @@times
|
71
|
+
@@times = [Time.now]
|
72
|
+
|
73
|
+
# Make one with an edge year on each side
|
74
|
+
ary = Time.now.to_a
|
75
|
+
[1999, 2000, 2001].each { |y|
|
76
|
+
ary[5] = y; @@times << Time.local(*ary)
|
77
|
+
}
|
78
|
+
|
79
|
+
# And with edge hours
|
80
|
+
ary = Time.now.to_a
|
81
|
+
#[23, 0].each { |h| ary[2] = h; @@times << Time.local(*ary) }
|
82
|
+
# 23 hour
|
83
|
+
ary[2] = 23
|
84
|
+
@@times << Time.local(*ary)
|
85
|
+
# 0 hour, next day
|
86
|
+
ary[2] = 0
|
87
|
+
@@times << addday(Time.local(*ary))
|
88
|
+
|
89
|
+
# And with edge minutes
|
90
|
+
#[59, 0].each { |m| ary[1] = m; @@times << Time.local(*ary) }
|
91
|
+
ary = Time.now.to_a
|
92
|
+
ary[1] = 59; @@times << Time.local(*ary)
|
93
|
+
ary[1] = 0
|
94
|
+
#if ary[2] == 23
|
95
|
+
@@times << Time.local(*ary)
|
96
|
+
#else
|
97
|
+
# @@times << addday(Time.local(*ary))
|
98
|
+
#end
|
99
|
+
end
|
100
|
+
|
101
|
+
Puppet.err @@times.inspect
|
102
|
+
|
103
|
+
@@times.each { |time|
|
104
|
+
@now = time
|
105
|
+
yield time
|
106
|
+
}
|
107
|
+
|
108
|
+
@now = Time.now
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_range
|
112
|
+
s = mksched
|
113
|
+
|
114
|
+
ary = @now.to_a
|
115
|
+
ary[2] = 12
|
116
|
+
@now = Time.local(*ary)
|
117
|
+
data = {
|
118
|
+
true => [
|
119
|
+
# An hour previous, an hour after
|
120
|
+
[hour("-", 1), hour("+", 1)],
|
121
|
+
|
122
|
+
# an hour previous but a couple minutes later, and an hour plus
|
123
|
+
[min("-", 57), hour("+", 1)]
|
124
|
+
],
|
125
|
+
false => [
|
126
|
+
# five minutes from now, an hour from now
|
127
|
+
[min("+", 5), hour("+", 1)],
|
128
|
+
|
129
|
+
# an hour ago, 20 minutes ago
|
130
|
+
[hour("-", 1), min("-", 20)]
|
131
|
+
]
|
132
|
+
}
|
133
|
+
|
134
|
+
data.each { |result, values|
|
135
|
+
values = values.collect { |value|
|
136
|
+
"%s - %s" % [value[0].strftime("%H:%M:%S"),
|
137
|
+
value[1].strftime("%H:%M:%S")]
|
138
|
+
}
|
139
|
+
values.each { |value|
|
140
|
+
assert_nothing_raised("Could not parse %s" % value) {
|
141
|
+
s[:range] = value
|
142
|
+
}
|
143
|
+
|
144
|
+
assert_equal(result, s.match?(nil, @now),
|
145
|
+
"%s matched %s incorrectly" % [value.inspect, @now])
|
146
|
+
}
|
147
|
+
|
148
|
+
assert_nothing_raised("Could not parse %s" % values) {
|
149
|
+
s[:range] = values
|
150
|
+
}
|
151
|
+
|
152
|
+
assert_equal(result, s.match?(nil, @now),
|
153
|
+
"%s matched %s incorrectly" % [values.inspect, @now])
|
154
|
+
}
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_period_by_distance
|
158
|
+
previous = @now
|
159
|
+
|
160
|
+
s = mksched
|
161
|
+
|
162
|
+
assert_nothing_raised {
|
163
|
+
s[:period] = :daily
|
164
|
+
}
|
165
|
+
|
166
|
+
assert(s.match?(day("-", 1)), "did not match minus a day")
|
167
|
+
assert(s.match?(day("-", 2)), "did not match two days")
|
168
|
+
assert(! s.match?(@now), "matched today")
|
169
|
+
assert(! s.match?(hour("-", 11)), "matched minus 11 hours")
|
170
|
+
|
171
|
+
# Now test hourly
|
172
|
+
assert_nothing_raised {
|
173
|
+
s[:period] = :hourly
|
174
|
+
}
|
175
|
+
|
176
|
+
assert(s.match?(hour("-", 1)), "did not match minus an hour")
|
177
|
+
assert(s.match?(hour("-", 2)), "did not match two hours")
|
178
|
+
assert(! s.match?(@now), "matched now")
|
179
|
+
assert(! s.match?(min("-", 59)), "matched minus 11 hours")
|
180
|
+
|
181
|
+
# and weekly
|
182
|
+
assert_nothing_raised {
|
183
|
+
s[:period] = :weekly
|
184
|
+
}
|
185
|
+
|
186
|
+
assert(s.match?(week("-", 1)), "did not match minus a week")
|
187
|
+
assert(s.match?(day("-", 7)), "did not match minus 7 days")
|
188
|
+
assert(s.match?(day("-", 8)), "did not match minus 8 days")
|
189
|
+
assert(s.match?(week("-", 2)), "did not match two weeks")
|
190
|
+
assert(! s.match?(@now), "matched now")
|
191
|
+
assert(! s.match?(day("-", 6)), "matched minus 6 days")
|
192
|
+
|
193
|
+
# and monthly
|
194
|
+
assert_nothing_raised {
|
195
|
+
s[:period] = :monthly
|
196
|
+
}
|
197
|
+
|
198
|
+
assert(s.match?(month("-", 1)), "did not match minus a month")
|
199
|
+
assert(s.match?(week("-", 5)), "did not match minus 5 weeks")
|
200
|
+
assert(s.match?(week("-", 7)), "did not match minus 7 weeks")
|
201
|
+
assert(s.match?(day("-", 50)), "did not match minus 50 days")
|
202
|
+
assert(s.match?(month("-", 2)), "did not match two months")
|
203
|
+
assert(! s.match?(@now), "matched now")
|
204
|
+
assert(! s.match?(week("-", 3)), "matched minus 3 weeks")
|
205
|
+
assert(! s.match?(day("-", 20)), "matched minus 20 days")
|
206
|
+
end
|
207
|
+
|
208
|
+
# A shortened test...
|
209
|
+
def test_period_by_number
|
210
|
+
s = mksched
|
211
|
+
assert_nothing_raised {
|
212
|
+
s[:periodmatch] = :number
|
213
|
+
}
|
214
|
+
|
215
|
+
assert_nothing_raised {
|
216
|
+
s[:period] = :daily
|
217
|
+
}
|
218
|
+
|
219
|
+
assert(s.match?(day("+", 1)), "didn't match plus a day")
|
220
|
+
assert(s.match?(week("+", 1)), "didn't match plus a week")
|
221
|
+
assert(! s.match?(@now), "matched today")
|
222
|
+
assert(! s.match?(hour("-", 1)), "matched minus an hour")
|
223
|
+
assert(! s.match?(hour("-", 2)), "matched plus two hours")
|
224
|
+
|
225
|
+
# Now test hourly
|
226
|
+
assert_nothing_raised {
|
227
|
+
s[:period] = :hourly
|
228
|
+
}
|
229
|
+
|
230
|
+
assert(s.match?(hour("+", 1)), "did not match plus an hour")
|
231
|
+
assert(s.match?(hour("+", 2)), "did not match plus two hours")
|
232
|
+
assert(! s.match?(@now), "matched now")
|
233
|
+
assert(! s.match?(sec("+", 20)), "matched plus 20 seconds")
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_periodmatch_default
|
237
|
+
s = mksched
|
238
|
+
|
239
|
+
match = s[:periodmatch]
|
240
|
+
assert(match, "Could not find periodmatch")
|
241
|
+
|
242
|
+
assert_equal(:distance, match, "Periodmatch was %s" % match)
|
243
|
+
end
|
244
|
+
|
245
|
+
def test_scheduled_objects
|
246
|
+
s = mksched
|
247
|
+
s[:period] = :hourly
|
248
|
+
|
249
|
+
f = nil
|
250
|
+
path = tempfile()
|
251
|
+
assert_nothing_raised {
|
252
|
+
f = Puppet.type(:file).create(
|
253
|
+
:name => path,
|
254
|
+
:schedule => s.name,
|
255
|
+
:ensure => "file"
|
256
|
+
)
|
257
|
+
}
|
258
|
+
|
259
|
+
assert(f.scheduled?, "File is not scheduled to run")
|
260
|
+
|
261
|
+
assert_apply(f)
|
262
|
+
|
263
|
+
assert(! f.scheduled?, "File is scheduled to run already")
|
264
|
+
File.unlink(path)
|
265
|
+
|
266
|
+
assert_apply(f)
|
267
|
+
|
268
|
+
assert(! FileTest.exists?(path), "File was created when not scheduled")
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_latebinding_schedules
|
272
|
+
f = nil
|
273
|
+
path = tempfile()
|
274
|
+
assert_nothing_raised {
|
275
|
+
f = Puppet.type(:file).create(
|
276
|
+
:name => path,
|
277
|
+
:schedule => "testsched",
|
278
|
+
:ensure => "file"
|
279
|
+
)
|
280
|
+
}
|
281
|
+
|
282
|
+
s = mksched
|
283
|
+
s[:period] = :hourly
|
284
|
+
|
285
|
+
assert_nothing_raised {
|
286
|
+
f.schedule
|
287
|
+
}
|
288
|
+
|
289
|
+
assert(f.scheduled?, "File is not scheduled to run")
|
290
|
+
end
|
291
|
+
|
292
|
+
# Verify that each of our default schedules exist
|
293
|
+
def test_defaultschedules
|
294
|
+
Puppet.type(:schedule).mkdefaultschedules
|
295
|
+
%w{puppet hourly daily weekly monthly}.each { |period|
|
296
|
+
assert(Puppet.type(:schedule)[period], "Could not find %s schedule" %
|
297
|
+
period)
|
298
|
+
}
|
299
|
+
end
|
300
|
+
|
301
|
+
def test_period_with_repeat
|
302
|
+
previous = @now
|
303
|
+
|
304
|
+
s = mksched
|
305
|
+
s[:period] = :hourly
|
306
|
+
|
307
|
+
assert_nothing_raised("Was not able to set periodmatch") {
|
308
|
+
s[:periodmatch] = :number
|
309
|
+
}
|
310
|
+
assert_raise(Puppet::Error) {
|
311
|
+
s[:repeat] = 2
|
312
|
+
}
|
313
|
+
assert_nothing_raised("Was not able to reset periodmatch") {
|
314
|
+
s[:periodmatch] = :distance
|
315
|
+
}
|
316
|
+
|
317
|
+
assert(! s.match?(min("-", 40)), "matched minus 40 minutes")
|
318
|
+
|
319
|
+
assert_nothing_raised("Was not able to set period") {
|
320
|
+
s[:repeat] = 2
|
321
|
+
}
|
322
|
+
|
323
|
+
assert(! s.match?(min("-", 20)), "matched minus 20 minutes with half-hourly")
|
324
|
+
assert(s.match?(min("-", 40)), "Did not match minus 40 with half-hourly")
|
325
|
+
|
326
|
+
assert_nothing_raised("Was not able to set period") {
|
327
|
+
s[:repeat] = 3
|
328
|
+
}
|
329
|
+
|
330
|
+
assert(! s.match?(min("-", 15)), "matched minus 15 minutes with half-hourly")
|
331
|
+
assert(s.match?(min("-", 25)), "Did not match minus 25 with half-hourly")
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
# $Id: schedule.rb 858 2006-01-30 19:22:25Z luke $
|