puppet 0.16.0 → 0.18.4
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 +98 -0
- data/Rakefile +5 -1
- data/bin/puppet +1 -1
- data/bin/puppetca +25 -11
- data/bin/puppetd +189 -66
- data/bin/puppetdoc +79 -62
- data/bin/puppetmasterd +93 -49
- data/bin/puppetrun +385 -0
- data/conf/redhat/client.init +5 -2
- data/conf/redhat/fileserver.conf +1 -1
- data/conf/redhat/lsb-config.patch +51 -0
- data/conf/redhat/puppet.spec +45 -18
- data/conf/redhat/puppetd.conf +32 -4
- data/conf/redhat/server.init +5 -2
- data/conf/solaris/pkginfo +7 -0
- data/conf/solaris/smf/puppetd.xml +77 -0
- data/conf/solaris/smf/puppetmasterd.xml +77 -0
- data/conf/solaris/smf/svc-puppetd +66 -0
- data/conf/solaris/smf/svc-puppetmasterd +62 -0
- data/examples/code/failers/noobjectrvalue +1 -0
- data/examples/code/snippets/deepclassheirarchy.pp +23 -0
- data/examples/code/snippets/defineoverrides.pp +17 -0
- data/examples/code/snippets/emptyexec.pp +3 -0
- data/examples/code/snippets/selectorvalues.pp +6 -1
- data/examples/code/snippets/tagged.pp +35 -0
- data/ext/ldap/puppet.schema +2 -2
- data/install.rb +4 -2
- data/lib/puppet.rb +206 -15
- data/lib/puppet/client.rb +30 -20
- data/lib/puppet/client/ca.rb +2 -2
- data/lib/puppet/client/dipper.rb +5 -9
- data/lib/puppet/client/master.rb +224 -44
- data/lib/puppet/client/pelement.rb +54 -9
- data/lib/puppet/client/proxy.rb +3 -2
- data/lib/puppet/client/reporter.rb +34 -0
- data/lib/puppet/client/runner.rb +17 -0
- data/lib/puppet/config.rb +136 -55
- data/lib/puppet/daemon.rb +59 -37
- data/lib/puppet/element.rb +2 -1
- data/lib/puppet/event.rb +14 -3
- data/lib/puppet/filetype.rb +28 -19
- data/lib/puppet/log.rb +297 -132
- data/lib/puppet/metric.rb +31 -131
- data/lib/puppet/networkclient.rb +73 -46
- data/lib/puppet/parameter.rb +49 -1
- data/lib/puppet/parsedfile.rb +32 -12
- data/lib/puppet/parser/ast.rb +6 -1
- data/lib/puppet/parser/ast/astarray.rb +32 -6
- data/lib/puppet/parser/ast/collection.rb +91 -0
- data/lib/puppet/parser/ast/compdef.rb +2 -2
- data/lib/puppet/parser/ast/component.rb +24 -11
- data/lib/puppet/parser/ast/function.rb +50 -0
- data/lib/puppet/parser/ast/hostclass.rb +70 -22
- data/lib/puppet/parser/ast/node.rb +17 -8
- data/lib/puppet/parser/ast/nodedef.rb +1 -1
- data/lib/puppet/parser/ast/objectdef.rb +28 -10
- data/lib/puppet/parser/ast/selector.rb +4 -1
- data/lib/puppet/parser/functions.rb +145 -0
- data/lib/puppet/parser/interpreter.rb +243 -86
- data/lib/puppet/parser/lexer.rb +5 -4
- data/lib/puppet/parser/parser.rb +586 -505
- data/lib/puppet/parser/scope.rb +337 -187
- data/lib/puppet/rails.rb +115 -0
- data/lib/puppet/rails/database.rb +40 -0
- data/lib/puppet/rails/host.rb +83 -0
- data/lib/puppet/rails/rails_object.rb +42 -0
- data/lib/puppet/rails/rails_parameter.rb +5 -0
- data/lib/puppet/reports/rrdgraph.rb +20 -0
- data/lib/puppet/reports/tagmail.rb +94 -0
- data/lib/puppet/server.rb +20 -4
- data/lib/puppet/server/authconfig.rb +14 -3
- data/lib/puppet/server/authstore.rb +2 -2
- data/lib/puppet/server/ca.rb +23 -11
- data/lib/puppet/server/filebucket.rb +10 -10
- data/lib/puppet/server/fileserver.rb +4 -8
- data/lib/puppet/server/master.rb +19 -22
- data/lib/puppet/server/pelement.rb +28 -16
- data/lib/puppet/server/report.rb +184 -0
- data/lib/puppet/server/runner.rb +62 -0
- data/lib/puppet/server/servlet.rb +23 -9
- data/lib/puppet/sslcertificates/ca.rb +25 -1
- data/lib/puppet/statechange.rb +34 -53
- data/lib/puppet/storage.rb +1 -2
- data/lib/puppet/transaction.rb +305 -133
- data/lib/puppet/transaction/report.rb +42 -0
- data/lib/puppet/transportable.rb +57 -33
- data/lib/puppet/type.rb +260 -127
- data/lib/puppet/type/component.rb +9 -21
- data/lib/puppet/type/cron.rb +367 -116
- data/lib/puppet/type/exec.rb +15 -16
- data/lib/puppet/type/group.rb +9 -1
- data/lib/puppet/type/nameservice.rb +2 -5
- data/lib/puppet/type/nameservice/netinfo.rb +3 -0
- data/lib/puppet/type/nameservice/objectadd.rb +23 -10
- data/lib/puppet/type/nameservice/pw.rb +16 -3
- data/lib/puppet/type/package.rb +25 -75
- data/lib/puppet/type/package/apple.rb +15 -1
- data/lib/puppet/type/package/apt.rb +37 -2
- data/lib/puppet/type/package/blastwave.rb +136 -0
- data/lib/puppet/type/package/dpkg.rb +4 -4
- data/lib/puppet/type/package/gem.rb +119 -0
- data/lib/puppet/type/package/openbsd.rb +7 -6
- data/lib/puppet/type/package/ports.rb +7 -2
- data/lib/puppet/type/package/rpm.rb +1 -1
- data/lib/puppet/type/package/sun.rb +23 -9
- data/lib/puppet/type/package/sunfreeware.rb +7 -0
- data/lib/puppet/type/package/yum.rb +16 -9
- data/lib/puppet/type/parsedtype.rb +7 -5
- data/lib/puppet/type/parsedtype/mount.rb +55 -34
- data/lib/puppet/type/parsedtype/port.rb +7 -1
- data/lib/puppet/type/parsedtype/sshkey.rb +6 -16
- data/lib/puppet/type/pfile.rb +115 -23
- data/lib/puppet/type/pfile/checksum.rb +18 -5
- data/lib/puppet/type/pfile/content.rb +2 -2
- data/lib/puppet/type/pfile/ensure.rb +3 -3
- data/lib/puppet/type/pfile/group.rb +2 -2
- data/lib/puppet/type/pfile/source.rb +28 -17
- data/lib/puppet/type/pfile/target.rb +25 -17
- data/lib/puppet/type/pfilebucket.rb +25 -6
- data/lib/puppet/type/schedule.rb +6 -6
- data/lib/puppet/type/service.rb +24 -14
- data/lib/puppet/type/service/debian.rb +1 -1
- data/lib/puppet/type/service/redhat.rb +13 -10
- data/lib/puppet/type/service/smf.rb +3 -3
- data/lib/puppet/type/state.rb +1 -2
- data/lib/puppet/type/symlink.rb +3 -4
- data/lib/puppet/type/user.rb +22 -10
- data/lib/puppet/type/yumrepo.rb +6 -1
- data/lib/puppet/type/zone.rb +595 -0
- data/lib/puppet/util.rb +58 -12
- data/test/client/client.rb +2 -2
- data/test/client/master.rb +92 -3
- data/test/client/pelement.rb +99 -0
- data/test/executables/puppetbin.rb +3 -4
- data/test/executables/puppetca.rb +3 -3
- data/test/executables/puppetd.rb +3 -3
- data/test/executables/puppetmasterd.rb +1 -5
- data/test/executables/puppetmodule.rb +2 -2
- data/test/language/ast.rb +200 -11
- data/test/language/functions.rb +245 -0
- data/test/language/interpreter.rb +155 -6
- data/test/language/lexer.rb +35 -2
- data/test/language/node.rb +48 -1
- data/test/language/parser.rb +250 -1
- data/test/language/rails.rb +105 -0
- data/test/language/scope.rb +304 -10
- data/test/language/snippets.rb +54 -5
- data/test/language/transportable.rb +60 -28
- data/test/other/config.rb +214 -1
- data/test/other/events.rb +67 -9
- data/test/other/log.rb +31 -5
- data/test/other/metrics.rb +23 -21
- data/test/other/parsedfile.rb +29 -2
- data/test/other/puppet.rb +79 -0
- data/test/other/report.rb +106 -0
- data/test/other/storage.rb +2 -2
- data/test/other/transactions.rb +128 -2
- data/test/puppet/utiltest.rb +10 -5
- data/test/puppettest.rb +193 -21
- data/test/server/authstore.rb +13 -4
- data/test/server/bucket.rb +33 -8
- data/test/server/ca.rb +44 -6
- data/test/server/master.rb +6 -7
- data/test/server/pelement.rb +15 -5
- data/test/server/report.rb +93 -0
- data/test/server/runner.rb +107 -0
- data/test/server/server.rb +28 -1
- data/test/types/cron.rb +339 -31
- data/test/types/file.rb +256 -24
- data/test/types/filebucket.rb +6 -2
- data/test/types/filesources.rb +41 -92
- data/test/types/group.rb +31 -1
- data/test/types/host.rb +2 -1
- data/test/types/mount.rb +18 -1
- data/test/types/package.rb +200 -18
- data/test/types/service.rb +5 -1
- data/test/types/sshkey.rb +2 -1
- data/test/types/symlink.rb +3 -2
- data/test/types/type.rb +180 -1
- data/test/types/user.rb +65 -27
- data/test/types/yumrepo.rb +15 -0
- data/test/types/zone.rb +437 -0
- metadata +43 -4
- data/bin/cf2puppet +0 -186
- data/conf/redhat/puppetmasterd.conf +0 -5
data/test/server/ca.rb
CHANGED
@@ -11,7 +11,7 @@ require 'openssl'
|
|
11
11
|
require 'test/unit'
|
12
12
|
require 'puppettest.rb'
|
13
13
|
|
14
|
-
# $Id: ca.rb
|
14
|
+
# $Id: ca.rb 1304 2006-06-20 18:10:06Z luke $
|
15
15
|
|
16
16
|
if ARGV.length > 0 and ARGV[0] == "short"
|
17
17
|
$short = true
|
@@ -21,11 +21,6 @@ end
|
|
21
21
|
|
22
22
|
class TestCA < Test::Unit::TestCase
|
23
23
|
include ServerTest
|
24
|
-
def teardown
|
25
|
-
super
|
26
|
-
#print "\n\n" if Puppet[:debug]
|
27
|
-
end
|
28
|
-
|
29
24
|
# Verify that we're autosigning. We have to autosign a "different" machine,
|
30
25
|
# since we always autosign the CA server's certificate.
|
31
26
|
def test_autocertgeneration
|
@@ -147,6 +142,13 @@ class TestCA < Test::Unit::TestCase
|
|
147
142
|
assert_nothing_raised {
|
148
143
|
OpenSSL::X509::Certificate.new(newtext)
|
149
144
|
}
|
145
|
+
|
146
|
+
# Now verify that we can clean a given host's certs
|
147
|
+
assert_nothing_raised {
|
148
|
+
ca.clean("anothertest.domain.com")
|
149
|
+
}
|
150
|
+
|
151
|
+
assert(!File.exists?(cert.certfile), "Cert still exists after clean")
|
150
152
|
end
|
151
153
|
|
152
154
|
# and now test the autosign file
|
@@ -198,4 +200,40 @@ class TestCA < Test::Unit::TestCase
|
|
198
200
|
)
|
199
201
|
}
|
200
202
|
end
|
203
|
+
|
204
|
+
# Make sure true/false causes the file to be ignored.
|
205
|
+
def test_autosign_true_beats_file
|
206
|
+
caserv = nil
|
207
|
+
assert_nothing_raised {
|
208
|
+
caserv = Puppet::Server::CA.new()
|
209
|
+
}
|
210
|
+
|
211
|
+
host = "hostname.domain.com"
|
212
|
+
|
213
|
+
# Create an autosign file
|
214
|
+
file = tempfile()
|
215
|
+
Puppet[:autosign] = file
|
216
|
+
|
217
|
+
File.open(file, "w") { |f|
|
218
|
+
f.puts host
|
219
|
+
}
|
220
|
+
|
221
|
+
# Start with "false"
|
222
|
+
Puppet[:autosign] = false
|
223
|
+
|
224
|
+
assert(! caserv.autosign?(host), "Host was incorrectly autosigned")
|
225
|
+
|
226
|
+
# Then set it to true
|
227
|
+
Puppet[:autosign] = true
|
228
|
+
assert(caserv.autosign?(host), "Host was not autosigned")
|
229
|
+
# And try a different host
|
230
|
+
assert(caserv.autosign?("other.yay.com"), "Host was not autosigned")
|
231
|
+
|
232
|
+
# And lastly the file
|
233
|
+
Puppet[:autosign] = file
|
234
|
+
assert(caserv.autosign?(host), "Host was not autosigned")
|
235
|
+
|
236
|
+
# And try a different host
|
237
|
+
assert(! caserv.autosign?("other.yay.com"), "Host was autosigned")
|
238
|
+
end
|
201
239
|
end
|
data/test/server/master.rb
CHANGED
@@ -102,6 +102,8 @@ class TestMaster < Test::Unit::TestCase
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def test_filereread
|
105
|
+
# Start with a normal setting
|
106
|
+
Puppet[:filetimeout] = 15
|
105
107
|
manifest = mktestmanifest()
|
106
108
|
|
107
109
|
file2 = @createdfile + "2"
|
@@ -113,8 +115,7 @@ class TestMaster < Test::Unit::TestCase
|
|
113
115
|
master = Puppet::Server::Master.new(
|
114
116
|
:Manifest => manifest,
|
115
117
|
:UseNodes => false,
|
116
|
-
:Local => true
|
117
|
-
:FileTimeout => 15
|
118
|
+
:Local => true
|
118
119
|
)
|
119
120
|
}
|
120
121
|
assert_nothing_raised() {
|
@@ -153,10 +154,8 @@ class TestMaster < Test::Unit::TestCase
|
|
153
154
|
assert_equal(parse1, master.freshness, "Master did not wait through timeout")
|
154
155
|
assert(client.fresh?, "Client is not up to date")
|
155
156
|
|
156
|
-
|
157
|
-
|
158
|
-
}
|
159
|
-
assert_equal(0, master.filetimeout)
|
157
|
+
# Then eliminate it
|
158
|
+
Puppet[:filetimeout] = 0
|
160
159
|
|
161
160
|
# Now make sure the master does reparse
|
162
161
|
#Puppet.notice "%s vs %s" % [parse1, master.freshness]
|
@@ -198,5 +197,5 @@ class TestMaster < Test::Unit::TestCase
|
|
198
197
|
end
|
199
198
|
end
|
200
199
|
|
201
|
-
# $Id: master.rb
|
200
|
+
# $Id: master.rb 1421 2006-07-21 23:12:51Z luke $
|
202
201
|
|
data/test/server/pelement.rb
CHANGED
@@ -196,7 +196,7 @@ class TestPElementServer < Test::Unit::TestCase
|
|
196
196
|
Puppet.warning "%s does not respond to :list" % type.name
|
197
197
|
next
|
198
198
|
end
|
199
|
-
|
199
|
+
next unless type.name == :package
|
200
200
|
Puppet.info "Describing each %s" % type.name
|
201
201
|
|
202
202
|
# First do a listing from the server
|
@@ -220,6 +220,7 @@ class TestPElementServer < Test::Unit::TestCase
|
|
220
220
|
|
221
221
|
count = 0
|
222
222
|
described = {}
|
223
|
+
Puppet.info "listing again"
|
223
224
|
type.list.each do |obj|
|
224
225
|
assert_instance_of(type, obj)
|
225
226
|
|
@@ -259,33 +260,42 @@ class TestPElementServer < Test::Unit::TestCase
|
|
259
260
|
|
260
261
|
Puppet::Type.type(:file).clear
|
261
262
|
|
263
|
+
Puppet.err filetrans[:parent].inspect
|
264
|
+
|
265
|
+
#p filetrans
|
266
|
+
|
262
267
|
bucket = Puppet::TransBucket.new
|
263
268
|
bucket.type = "file"
|
264
269
|
bucket.push filetrans
|
265
270
|
|
271
|
+
#p bucket
|
272
|
+
|
273
|
+
oldbucket = bucket.dup
|
266
274
|
File.unlink(file)
|
267
275
|
assert_nothing_raised {
|
268
276
|
server.apply(bucket)
|
269
277
|
}
|
270
278
|
|
279
|
+
|
271
280
|
assert(FileTest.exists?(file), "File did not get recreated")
|
272
281
|
|
273
282
|
# Now try it as a "nonlocal" server
|
274
283
|
server.local = false
|
275
284
|
yaml = nil
|
276
285
|
assert_nothing_raised {
|
277
|
-
yaml =
|
286
|
+
yaml = Base64.encode64(YAML::dump(bucket))
|
278
287
|
}
|
279
288
|
|
280
289
|
Puppet::Type.type(:file).clear
|
281
290
|
File.unlink(file)
|
282
291
|
|
283
|
-
if yaml =~ /(.{20}Loglevel.{20})/
|
292
|
+
if Base64.decode64(yaml) =~ /(.{20}Loglevel.{20})/
|
284
293
|
Puppet.warning "YAML is broken on this machine"
|
285
294
|
return
|
286
295
|
end
|
296
|
+
#puts Base64.decode64(yaml)
|
287
297
|
assert_nothing_raised("Could not reload yaml") {
|
288
|
-
YAML::load(
|
298
|
+
YAML::load(Base64.decode64(yaml))
|
289
299
|
}
|
290
300
|
|
291
301
|
assert_nothing_raised {
|
@@ -295,4 +305,4 @@ class TestPElementServer < Test::Unit::TestCase
|
|
295
305
|
end
|
296
306
|
end
|
297
307
|
|
298
|
-
# $Id: pelement.rb
|
308
|
+
# $Id: pelement.rb 1224 2006-05-25 06:24:44Z luke $
|
@@ -0,0 +1,93 @@
|
|
1
|
+
if __FILE__ == $0
|
2
|
+
$:.unshift '../../lib'
|
3
|
+
$:.unshift '..'
|
4
|
+
$puppetbase = "../.."
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'puppet'
|
8
|
+
require 'puppet/server/report'
|
9
|
+
require 'puppet/client/reporter'
|
10
|
+
require 'test/unit'
|
11
|
+
require 'puppettest.rb'
|
12
|
+
|
13
|
+
class TestReportServer < Test::Unit::TestCase
|
14
|
+
include TestPuppet
|
15
|
+
Puppet::Util.logmethods(self)
|
16
|
+
|
17
|
+
def mkserver
|
18
|
+
server = nil
|
19
|
+
assert_nothing_raised {
|
20
|
+
server = Puppet::Server::Report.new()
|
21
|
+
}
|
22
|
+
server
|
23
|
+
end
|
24
|
+
|
25
|
+
def mkclient(server = nil)
|
26
|
+
server ||= mkserver()
|
27
|
+
client = nil
|
28
|
+
assert_nothing_raised {
|
29
|
+
client = Puppet::Client::Reporter.new(:Report => server)
|
30
|
+
}
|
31
|
+
|
32
|
+
client
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_report
|
36
|
+
# Create a bunch of log messages in an array.
|
37
|
+
report = Puppet::Transaction::Report.new
|
38
|
+
|
39
|
+
10.times { |i|
|
40
|
+
log = warning("Report test message %s" % i)
|
41
|
+
log.tags = %w{a list of tags}
|
42
|
+
log.tags << "tag%s" % i
|
43
|
+
|
44
|
+
report.newlog(log)
|
45
|
+
}
|
46
|
+
|
47
|
+
# Now make our reporting client
|
48
|
+
client = mkclient()
|
49
|
+
|
50
|
+
# Now send the report
|
51
|
+
file = nil
|
52
|
+
assert_nothing_raised("Reporting failed") {
|
53
|
+
file = client.report(report)
|
54
|
+
}
|
55
|
+
|
56
|
+
# And make sure our YAML file exists.
|
57
|
+
assert(FileTest.exists?(file),
|
58
|
+
"Report file did not get created")
|
59
|
+
|
60
|
+
# And then try to reconstitute the report.
|
61
|
+
newreport = nil
|
62
|
+
assert_nothing_raised("Failed to load report file") {
|
63
|
+
newreport = YAML.load(File.read(file))
|
64
|
+
}
|
65
|
+
|
66
|
+
# Make sure our report is valid and stuff.
|
67
|
+
report.logs.zip(newreport.logs).each do |ol,nl|
|
68
|
+
%w{level message time tags source}.each do |method|
|
69
|
+
assert_equal(ol.send(method), nl.send(method),
|
70
|
+
"%s got changed" % method)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Make sure we don't have problems with calling mkclientdir multiple
|
76
|
+
# times.
|
77
|
+
def test_multiple_clients
|
78
|
+
server ||= mkserver()
|
79
|
+
|
80
|
+
%w{hostA hostB hostC}.each do |host|
|
81
|
+
dir = tempfile()
|
82
|
+
assert_nothing_raised("Could not create multiple host report dirs") {
|
83
|
+
server.send(:mkclientdir, host, dir)
|
84
|
+
}
|
85
|
+
|
86
|
+
assert(FileTest.directory?(dir),
|
87
|
+
"Directory was not created")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# $Id: report.rb 1390 2006-07-11 20:22:27Z luke $
|
93
|
+
|
@@ -0,0 +1,107 @@
|
|
1
|
+
if __FILE__ == $0
|
2
|
+
$:.unshift '../../lib'
|
3
|
+
$:.unshift '..'
|
4
|
+
$puppetbase = "../.."
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'puppet'
|
8
|
+
require 'puppet/server/runner'
|
9
|
+
require 'test/unit'
|
10
|
+
require 'puppettest.rb'
|
11
|
+
|
12
|
+
class TestServerRunner < Test::Unit::TestCase
|
13
|
+
include TestPuppet
|
14
|
+
|
15
|
+
def mkclient(file)
|
16
|
+
master = nil
|
17
|
+
client = nil
|
18
|
+
# create our master
|
19
|
+
assert_nothing_raised() {
|
20
|
+
# this is the default server setup
|
21
|
+
master = Puppet::Server::Master.new(
|
22
|
+
:Manifest => file,
|
23
|
+
:UseNodes => false,
|
24
|
+
:Local => true
|
25
|
+
)
|
26
|
+
}
|
27
|
+
|
28
|
+
# and our client
|
29
|
+
assert_nothing_raised() {
|
30
|
+
client = Puppet::Client::MasterClient.new(
|
31
|
+
:Master => master
|
32
|
+
)
|
33
|
+
}
|
34
|
+
|
35
|
+
client
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_runner
|
39
|
+
Puppet[:ignoreschedules] = false
|
40
|
+
# Okay, make our manifest
|
41
|
+
file = tempfile()
|
42
|
+
created = tempfile()
|
43
|
+
File.open(file, "w") do |f|
|
44
|
+
f.puts %{
|
45
|
+
class yayness {
|
46
|
+
file { "#{created}": ensure => file, schedule => weekly }
|
47
|
+
}
|
48
|
+
|
49
|
+
include yayness
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
client = mkclient(file)
|
54
|
+
|
55
|
+
runner = nil
|
56
|
+
assert_nothing_raised {
|
57
|
+
runner = Puppet::Server::Runner.new
|
58
|
+
}
|
59
|
+
# First: tags
|
60
|
+
# Second: ignore schedules true/false
|
61
|
+
# Third: background true/false
|
62
|
+
# Fourth: whether file should exist true/false
|
63
|
+
[
|
64
|
+
["with no backgrounding",
|
65
|
+
nil, true, true, true],
|
66
|
+
["in the background",
|
67
|
+
nil, true, false, true],
|
68
|
+
["with a bad tag",
|
69
|
+
["coolness"], true, false, false],
|
70
|
+
["with another bad tag",
|
71
|
+
"coolness", true, false, false],
|
72
|
+
["with a good tag",
|
73
|
+
["coolness", "yayness"], true, false, true],
|
74
|
+
["with another good tag",
|
75
|
+
["yayness"], true, false, true],
|
76
|
+
["with a third good tag",
|
77
|
+
"yayness", true, false, true],
|
78
|
+
["not ignoring schedules",
|
79
|
+
nil, false, false, false],
|
80
|
+
["ignoring schedules",
|
81
|
+
nil, true, false, true],
|
82
|
+
].each do |msg, tags, ignore, fg, shouldexist|
|
83
|
+
if FileTest.exists?(created)
|
84
|
+
File.unlink(created)
|
85
|
+
end
|
86
|
+
assert_nothing_raised {
|
87
|
+
# Try it without backgrounding
|
88
|
+
runner.run(tags, ignore, fg)
|
89
|
+
}
|
90
|
+
|
91
|
+
unless fg
|
92
|
+
Puppet.join
|
93
|
+
end
|
94
|
+
|
95
|
+
if shouldexist
|
96
|
+
assert(FileTest.exists?(created), "File did not get created " +
|
97
|
+
msg)
|
98
|
+
else
|
99
|
+
assert(!FileTest.exists?(created), "File got created incorrectly " +
|
100
|
+
msg)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# $Id: runner.rb 1325 2006-06-28 15:17:56Z luke $
|
107
|
+
|
data/test/server/server.rb
CHANGED
@@ -13,7 +13,7 @@ require 'xmlrpc/client'
|
|
13
13
|
require 'test/unit'
|
14
14
|
require 'puppettest.rb'
|
15
15
|
|
16
|
-
# $Id: server.rb
|
16
|
+
# $Id: server.rb 1306 2006-06-20 18:38:48Z luke $
|
17
17
|
|
18
18
|
if ARGV.length > 0 and ARGV[0] == "short"
|
19
19
|
$short = true
|
@@ -122,4 +122,31 @@ class TestServer < Test::Unit::TestCase
|
|
122
122
|
retval = client.getconfig
|
123
123
|
}
|
124
124
|
end
|
125
|
+
|
126
|
+
def test_setpidfile_setting
|
127
|
+
Puppet[:setpidfile] = false
|
128
|
+
server = nil
|
129
|
+
assert_nothing_raised() {
|
130
|
+
server = Puppet::Server.new(
|
131
|
+
:Port => @@port,
|
132
|
+
:Handlers => {
|
133
|
+
:CA => {}, # so that certs autogenerate
|
134
|
+
:Status => nil
|
135
|
+
}
|
136
|
+
)
|
137
|
+
|
138
|
+
}
|
139
|
+
|
140
|
+
assert_nothing_raised {
|
141
|
+
server.setpidfile
|
142
|
+
}
|
143
|
+
|
144
|
+
assert(! FileTest.exists?(server.pidfile), "PID file was created")
|
145
|
+
Puppet[:setpidfile] = true
|
146
|
+
|
147
|
+
assert_nothing_raised {
|
148
|
+
server.setpidfile
|
149
|
+
}
|
150
|
+
assert(FileTest.exists?(server.pidfile), "PID file was not created")
|
151
|
+
end
|
125
152
|
end
|
data/test/types/cron.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
if __FILE__ == $0
|
4
4
|
$:.unshift '..'
|
5
|
-
$:.unshift '
|
6
|
-
$puppetbase = "
|
5
|
+
$:.unshift '../lib'
|
6
|
+
$puppetbase = "../.."
|
7
7
|
end
|
8
8
|
|
9
9
|
require 'puppettest'
|
@@ -11,14 +11,6 @@ require 'puppet'
|
|
11
11
|
require 'test/unit'
|
12
12
|
require 'facter'
|
13
13
|
|
14
|
-
|
15
|
-
# Here we just want to unit-test our cron type, to verify that
|
16
|
-
#class TestCronType < Test::Unit::TestCase
|
17
|
-
# include TestPuppet
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#end
|
21
|
-
|
22
14
|
class TestCron < Test::Unit::TestCase
|
23
15
|
include TestPuppet
|
24
16
|
def setup
|
@@ -43,6 +35,7 @@ class TestCron < Test::Unit::TestCase
|
|
43
35
|
|
44
36
|
def teardown
|
45
37
|
@crontype.filetype = @oldfiletype
|
38
|
+
Puppet::FileType.filetype(:ram).clear
|
46
39
|
super
|
47
40
|
end
|
48
41
|
|
@@ -91,23 +84,32 @@ class TestCron < Test::Unit::TestCase
|
|
91
84
|
|
92
85
|
# Run the cron through its paces -- install it then remove it.
|
93
86
|
def cyclecron(cron)
|
87
|
+
obj = Puppet::Type::Cron.cronobj(@me)
|
88
|
+
|
89
|
+
text = obj.read
|
94
90
|
name = cron.name
|
95
91
|
comp = newcomp(name, cron)
|
96
92
|
|
97
93
|
assert_events([:cron_created], comp)
|
98
94
|
cron.retrieve
|
99
95
|
|
100
|
-
assert(cron.insync
|
96
|
+
assert(cron.insync?, "Cron is not in sync")
|
101
97
|
|
102
98
|
assert_events([], comp)
|
103
99
|
|
100
|
+
curtext = obj.read
|
101
|
+
text.split("\n").each do |line|
|
102
|
+
assert(curtext.include?(line), "Missing '%s'" % line)
|
103
|
+
end
|
104
|
+
obj = Puppet::Type::Cron.cronobj(@me)
|
105
|
+
|
104
106
|
cron[:ensure] = :absent
|
105
107
|
|
106
108
|
assert_events([:cron_removed], comp)
|
107
109
|
|
108
110
|
cron.retrieve
|
109
111
|
|
110
|
-
assert(cron.insync
|
112
|
+
assert(cron.insync?, "Cron is not in sync")
|
111
113
|
assert_events([], comp)
|
112
114
|
end
|
113
115
|
|
@@ -141,6 +143,29 @@ class TestCron < Test::Unit::TestCase
|
|
141
143
|
"Cron did not generate correctly")
|
142
144
|
end
|
143
145
|
|
146
|
+
def test_simpleparsing
|
147
|
+
@fakefiletype = Puppet::FileType.filetype(:ram)
|
148
|
+
@crontype.filetype = @fakefiletype
|
149
|
+
|
150
|
+
@crontype.retrieve(@me)
|
151
|
+
obj = Puppet::Type::Cron.cronobj(@me)
|
152
|
+
|
153
|
+
text = "5 1,2 * 1 0 /bin/echo funtest"
|
154
|
+
|
155
|
+
assert_nothing_raised {
|
156
|
+
@crontype.parse(@me, text)
|
157
|
+
}
|
158
|
+
|
159
|
+
@crontype.each do |obj|
|
160
|
+
assert_equal(["5"], obj.is(:minute), "Minute was not parsed correctly")
|
161
|
+
assert_equal(["1", "2"], obj.is(:hour), "Hour was not parsed correctly")
|
162
|
+
assert_equal([:absent], obj.is(:monthday), "Monthday was not parsed correctly")
|
163
|
+
assert_equal(["1"], obj.is(:month), "Month was not parsed correctly")
|
164
|
+
assert_equal(["0"], obj.is(:weekday), "Weekday was not parsed correctly")
|
165
|
+
assert_equal(["/bin/echo funtest"], obj.is(:command), "Command was not parsed correctly")
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
144
169
|
# Test that changing any field results in the cron tab being rewritten.
|
145
170
|
# it directly
|
146
171
|
def test_any_field_changes
|
@@ -192,12 +217,13 @@ class TestCron < Test::Unit::TestCase
|
|
192
217
|
def test_retain_comments
|
193
218
|
str = "# this is a comment\n#and another comment\n"
|
194
219
|
user = "fakeuser"
|
220
|
+
@crontype.retrieve(@me)
|
195
221
|
assert_nothing_raised {
|
196
|
-
@crontype.parse(
|
222
|
+
@crontype.parse(@me, str)
|
197
223
|
}
|
198
224
|
|
199
225
|
assert_nothing_raised {
|
200
|
-
newstr = @crontype.tab(
|
226
|
+
newstr = @crontype.tab(@me)
|
201
227
|
assert(newstr.include?(str), "Comments were lost")
|
202
228
|
}
|
203
229
|
end
|
@@ -207,10 +233,6 @@ class TestCron < Test::Unit::TestCase
|
|
207
233
|
def test_matchcron
|
208
234
|
str = "0,30 * * * * date\n"
|
209
235
|
|
210
|
-
assert_nothing_raised {
|
211
|
-
@crontype.parse(@me, str)
|
212
|
-
}
|
213
|
-
|
214
236
|
assert_nothing_raised {
|
215
237
|
cron = @crontype.create(
|
216
238
|
:name => "yaycron",
|
@@ -220,6 +242,16 @@ class TestCron < Test::Unit::TestCase
|
|
220
242
|
)
|
221
243
|
}
|
222
244
|
|
245
|
+
assert_nothing_raised {
|
246
|
+
@crontype.parse(@me, str)
|
247
|
+
}
|
248
|
+
|
249
|
+
count = @crontype.inject(0) do |c, obj|
|
250
|
+
c + 1
|
251
|
+
end
|
252
|
+
|
253
|
+
assert_equal(1, count, "Did not match cron job")
|
254
|
+
|
223
255
|
modstr = "# Puppet Name: yaycron\n%s" % str
|
224
256
|
|
225
257
|
assert_nothing_raised {
|
@@ -234,14 +266,15 @@ class TestCron < Test::Unit::TestCase
|
|
234
266
|
tab = @fakefiletype.new(@me)
|
235
267
|
tab.remove
|
236
268
|
|
269
|
+
@crontype.retrieve(@me)
|
237
270
|
cron = mkcron("testwithnotab")
|
238
271
|
cyclecron(cron)
|
239
272
|
end
|
240
273
|
|
241
274
|
def test_mkcronwithtab
|
242
|
-
|
243
|
-
|
244
|
-
|
275
|
+
@crontype.retrieve(@me)
|
276
|
+
obj = Puppet::Type::Cron.cronobj(@me)
|
277
|
+
obj.write(
|
245
278
|
"1 1 1 1 * date > %s/crontesting\n" % tstdir()
|
246
279
|
)
|
247
280
|
|
@@ -253,17 +286,18 @@ class TestCron < Test::Unit::TestCase
|
|
253
286
|
tab = @fakefiletype.new(@me)
|
254
287
|
tab.remove
|
255
288
|
|
256
|
-
name
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
289
|
+
%w{storeandretrieve a-name another-name more_naming SomeName}.each do |name|
|
290
|
+
cron = mkcron(name)
|
291
|
+
comp = newcomp(name, cron)
|
292
|
+
trans = assert_events([:cron_created], comp, name)
|
293
|
+
|
294
|
+
cron = nil
|
262
295
|
|
263
|
-
|
296
|
+
Puppet.type(:cron).retrieve(@me)
|
264
297
|
|
265
|
-
|
266
|
-
|
298
|
+
assert(cron = Puppet.type(:cron)[name], "Could not retrieve named cron")
|
299
|
+
assert_instance_of(Puppet.type(:cron), cron)
|
300
|
+
end
|
267
301
|
end
|
268
302
|
|
269
303
|
# Do input validation testing on all of the parameters.
|
@@ -405,6 +439,280 @@ class TestCron < Test::Unit::TestCase
|
|
405
439
|
@crontype.retrieve("nosuchuser")
|
406
440
|
end
|
407
441
|
end
|
442
|
+
|
443
|
+
def test_names
|
444
|
+
cron = mkcron("nametest")
|
445
|
+
|
446
|
+
["bad name", "bad.name"].each do |name|
|
447
|
+
assert_raise(ArgumentError) do
|
448
|
+
cron[:name] = name
|
449
|
+
end
|
450
|
+
end
|
451
|
+
|
452
|
+
["good-name", "good-name", "AGoodName"].each do |name|
|
453
|
+
assert_nothing_raised do
|
454
|
+
cron[:name] = name
|
455
|
+
end
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
# Make sure we don't puke on env settings
|
460
|
+
def test_envsettings
|
461
|
+
cron = mkcron("envtst")
|
462
|
+
|
463
|
+
assert_apply(cron)
|
464
|
+
|
465
|
+
obj = Puppet::Type::Cron.cronobj(@me)
|
466
|
+
|
467
|
+
assert(obj)
|
468
|
+
|
469
|
+
text = obj.read
|
470
|
+
|
471
|
+
text = "SHELL = /path/to/some/thing\n" + text
|
472
|
+
|
473
|
+
obj.write(text)
|
474
|
+
|
475
|
+
assert_nothing_raised {
|
476
|
+
cron.retrieve
|
477
|
+
}
|
478
|
+
|
479
|
+
cron[:command] = "/some/other/command"
|
480
|
+
|
481
|
+
assert_apply(cron)
|
482
|
+
|
483
|
+
assert(obj.read =~ /SHELL/, "lost env setting")
|
484
|
+
|
485
|
+
env1 = "TEST = /bin/true"
|
486
|
+
env2 = "YAY = fooness"
|
487
|
+
assert_nothing_raised {
|
488
|
+
cron[:environment] = [env1, env2]
|
489
|
+
}
|
490
|
+
|
491
|
+
assert_apply(cron)
|
492
|
+
cron.retrieve
|
493
|
+
|
494
|
+
vals = cron.is(:environment)
|
495
|
+
assert(vals, "Did not get environment settings")
|
496
|
+
assert(vals != :absent, "Env is incorrectly absent")
|
497
|
+
assert_instance_of(Array, vals)
|
498
|
+
|
499
|
+
assert(vals.include?(env1), "Missing first env setting")
|
500
|
+
assert(vals.include?(env2), "Missing second env setting")
|
501
|
+
|
502
|
+
end
|
503
|
+
|
504
|
+
def test_divisionnumbers
|
505
|
+
cron = mkcron("divtest")
|
506
|
+
cron[:minute] = "*/5"
|
507
|
+
|
508
|
+
assert_apply(cron)
|
509
|
+
|
510
|
+
cron.retrieve
|
511
|
+
|
512
|
+
assert_equal(["*/5"], cron.is(:minute))
|
513
|
+
end
|
514
|
+
|
515
|
+
def test_ranges
|
516
|
+
cron = mkcron("rangetest")
|
517
|
+
cron[:minute] = "2-4"
|
518
|
+
|
519
|
+
assert_apply(cron)
|
520
|
+
|
521
|
+
cron.retrieve
|
522
|
+
|
523
|
+
assert_equal(["2-4"], cron.is(:minute))
|
524
|
+
end
|
525
|
+
|
526
|
+
def test_data
|
527
|
+
@fakefiletype = Puppet::FileType.filetype(:ram)
|
528
|
+
@crontype.filetype = @fakefiletype
|
529
|
+
|
530
|
+
@crontype.retrieve(@me)
|
531
|
+
obj = Puppet::Type::Cron.cronobj(@me)
|
532
|
+
|
533
|
+
fakedata("data/types/cron").each do |file|
|
534
|
+
names = []
|
535
|
+
text = File.read(file)
|
536
|
+
obj.write(File.read(file))
|
537
|
+
|
538
|
+
@crontype.retrieve(@me)
|
539
|
+
|
540
|
+
@crontype.each do |cron|
|
541
|
+
names << cron.name
|
542
|
+
end
|
543
|
+
|
544
|
+
name = File.basename(file)
|
545
|
+
cron = mkcron("filetest-#{name}")
|
546
|
+
|
547
|
+
assert_apply(cron)
|
548
|
+
|
549
|
+
@crontype.retrieve(@me)
|
550
|
+
|
551
|
+
names.each do |name|
|
552
|
+
assert(@crontype[name], "Could not retrieve %s" % name)
|
553
|
+
end
|
554
|
+
|
555
|
+
tablines = @crontype.tab(@me).split("\n")
|
556
|
+
|
557
|
+
text.split("\n").each do |line|
|
558
|
+
assert(tablines.include?(line),
|
559
|
+
"Did not get %s back out" % line.inspect)
|
560
|
+
end
|
561
|
+
end
|
562
|
+
end
|
563
|
+
|
564
|
+
def test_value
|
565
|
+
cron = mkcron("valuetesting")
|
566
|
+
|
567
|
+
# First, test the normal states
|
568
|
+
[:minute, :hour, :month].each do |param|
|
569
|
+
state = cron.state(param)
|
570
|
+
|
571
|
+
assert(state, "Did not get %s state" % param)
|
572
|
+
|
573
|
+
assert_nothing_raised {
|
574
|
+
state.should = :absent
|
575
|
+
state.is = :absent
|
576
|
+
}
|
577
|
+
|
578
|
+
# Make sure our minute default is 0, not *
|
579
|
+
val = if param == :minute
|
580
|
+
"*" # the "0" thing is disabled for now
|
581
|
+
else
|
582
|
+
"*"
|
583
|
+
end
|
584
|
+
assert_equal(val, cron.value(param))
|
585
|
+
|
586
|
+
# Make sure we correctly get the "is" value if that's all there is
|
587
|
+
cron.is = [param, "1"]
|
588
|
+
assert_equal("1", cron.value(param))
|
589
|
+
|
590
|
+
# Make sure arrays work, too
|
591
|
+
cron.is = [param, ["1"]]
|
592
|
+
assert_equal("1", cron.value(param))
|
593
|
+
|
594
|
+
# Make sure values get comma-joined
|
595
|
+
cron.is = [param, ["2", "3"]]
|
596
|
+
assert_equal("2,3", cron.value(param))
|
597
|
+
|
598
|
+
# Make sure "should" values work, too
|
599
|
+
cron[param] = "4"
|
600
|
+
assert_equal("4", cron.value(param))
|
601
|
+
|
602
|
+
cron[param] = ["4"]
|
603
|
+
assert_equal("4", cron.value(param))
|
604
|
+
|
605
|
+
cron[param] = ["4", "5"]
|
606
|
+
assert_equal("4,5", cron.value(param))
|
607
|
+
|
608
|
+
cron.is = [param, :absent]
|
609
|
+
assert_equal("4,5", cron.value(param))
|
610
|
+
end
|
611
|
+
|
612
|
+
# Now make sure that :command works correctly
|
613
|
+
state = cron.state(:command)
|
614
|
+
|
615
|
+
assert_nothing_raised {
|
616
|
+
state.should = :absent
|
617
|
+
state.is = :absent
|
618
|
+
}
|
619
|
+
|
620
|
+
assert(state, "Did not get command state")
|
621
|
+
assert_raise(Puppet::DevError) do
|
622
|
+
cron.value(:command)
|
623
|
+
end
|
624
|
+
|
625
|
+
param = :command
|
626
|
+
# Make sure we correctly get the "is" value if that's all there is
|
627
|
+
cron.is = [param, "1"]
|
628
|
+
assert_equal("1", cron.value(param))
|
629
|
+
|
630
|
+
# Make sure arrays work, too
|
631
|
+
cron.is = [param, ["1"]]
|
632
|
+
assert_equal("1", cron.value(param))
|
633
|
+
|
634
|
+
# Make sure values are not comma-joined
|
635
|
+
cron.is = [param, ["2", "3"]]
|
636
|
+
assert_equal("2", cron.value(param))
|
637
|
+
|
638
|
+
# Make sure "should" values work, too
|
639
|
+
cron[param] = "4"
|
640
|
+
assert_equal("4", cron.value(param))
|
641
|
+
|
642
|
+
cron[param] = ["4"]
|
643
|
+
assert_equal("4", cron.value(param))
|
644
|
+
|
645
|
+
cron[param] = ["4", "5"]
|
646
|
+
assert_equal("4", cron.value(param))
|
647
|
+
|
648
|
+
cron.is = [param, :absent]
|
649
|
+
assert_equal("4", cron.value(param))
|
650
|
+
end
|
651
|
+
|
652
|
+
# Make sure we can successfully list all cron jobs on all users
|
653
|
+
def test_cron_listing
|
654
|
+
crons = []
|
655
|
+
%w{fake1 fake2 fake3 fake4 fake5}.each do |user|
|
656
|
+
crons << @crontype.create(
|
657
|
+
:name => "#{user}-1",
|
658
|
+
:command => "/usr/bin/#{user}",
|
659
|
+
:minute => "0",
|
660
|
+
:user => user,
|
661
|
+
:hour => user.sub("fake",'')
|
662
|
+
)
|
663
|
+
|
664
|
+
crons << @crontype.create(
|
665
|
+
:name => "#{user}-2",
|
666
|
+
:command => "/usr/sbin/#{user}",
|
667
|
+
:minute => "0",
|
668
|
+
:user => user,
|
669
|
+
:weekday => user.sub("fake",'')
|
670
|
+
)
|
671
|
+
|
672
|
+
assert_apply(*crons)
|
673
|
+
end
|
674
|
+
|
675
|
+
list = @crontype.list.collect { |c| c.name }
|
676
|
+
|
677
|
+
crons.each do |cron|
|
678
|
+
assert(list.include?(cron.name), "Did not match cron %s" % name)
|
679
|
+
end
|
680
|
+
end
|
681
|
+
|
682
|
+
# Make sure we can create a cron in an empty tab
|
683
|
+
def test_mkcron_if_empty
|
684
|
+
@crontype.filetype = @oldfiletype
|
685
|
+
|
686
|
+
@crontype.retrieve(@me)
|
687
|
+
|
688
|
+
# Backup our tab
|
689
|
+
text = @crontype.tabobj(@me).read
|
690
|
+
|
691
|
+
cleanup do
|
692
|
+
if text == ""
|
693
|
+
@crontype.tabobj(@me).remove
|
694
|
+
else
|
695
|
+
@crontype.tabobj(@me).write(text)
|
696
|
+
end
|
697
|
+
end
|
698
|
+
|
699
|
+
# Now get rid of it
|
700
|
+
@crontype.tabobj(@me).remove
|
701
|
+
@crontype.clear
|
702
|
+
|
703
|
+
cron = mkcron("emptycron")
|
704
|
+
|
705
|
+
assert_apply(cron)
|
706
|
+
|
707
|
+
# Clear the type, but don't clear the filetype
|
708
|
+
@crontype.clear
|
709
|
+
|
710
|
+
# Get the stuff again
|
711
|
+
@crontype.retrieve(@me)
|
712
|
+
|
713
|
+
assert(@crontype["emptycron"],
|
714
|
+
"Did not retrieve cron")
|
715
|
+
end
|
408
716
|
end
|
409
717
|
|
410
|
-
# $Id: cron.rb
|
718
|
+
# $Id: cron.rb 1402 2006-07-18 15:35:15Z luke $
|