puppet 0.23.0 → 0.23.1
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/Rakefile +1 -1
- data/bin/filebucket +6 -6
- data/bin/puppetca +11 -1
- data/bin/puppetmasterd +7 -6
- data/conf/redhat/client.init +1 -0
- data/conf/redhat/{puppetd.conf → puppet.conf} +1 -1
- data/conf/redhat/puppet.spec +43 -31
- data/conf/redhat/server.init +1 -0
- data/lib/puppet.rb +3 -3
- data/lib/puppet/configuration.rb +16 -5
- data/lib/puppet/metatype/attributes.rb +12 -19
- data/lib/puppet/metatype/evaluation.rb +10 -1
- data/lib/puppet/metatype/instances.rb +39 -15
- data/lib/puppet/metatype/manager.rb +1 -28
- data/lib/puppet/metatype/metaparams.rb +20 -16
- data/lib/puppet/metatype/providers.rb +8 -2
- data/lib/puppet/metatype/schedules.rb +14 -19
- data/lib/puppet/{modules.rb → module.rb} +2 -0
- data/lib/puppet/network/authstore.rb +5 -1
- data/lib/puppet/network/client/dipper.rb +2 -2
- data/lib/puppet/network/client/master.rb +18 -9
- data/lib/puppet/network/handler/fileserver.rb +3 -6
- data/lib/puppet/network/handler/report.rb +2 -1
- data/lib/puppet/network/server/mongrel.rb +4 -2
- data/lib/puppet/network/xmlrpc/client.rb +10 -3
- data/lib/puppet/parameter.rb +11 -4
- data/lib/puppet/parser/ast/collexpr.rb +10 -10
- data/lib/puppet/parser/ast/hostclass.rb +2 -2
- data/lib/puppet/parser/ast/resourceparam.rb +4 -3
- data/lib/puppet/parser/ast/resourceref.rb +16 -2
- data/lib/puppet/parser/collector.rb +8 -4
- data/lib/puppet/parser/functions.rb +5 -2
- data/lib/puppet/parser/interpreter.rb +48 -9
- data/lib/puppet/parser/lexer.rb +2 -1
- data/lib/puppet/parser/parser.rb +669 -589
- data/lib/puppet/parser/resource.rb +20 -11
- data/lib/puppet/parser/resource/param.rb +21 -10
- data/lib/puppet/parser/resource/reference.rb +2 -2
- data/lib/puppet/parser/scope.rb +22 -10
- data/lib/puppet/{type/property.rb → property.rb} +48 -15
- data/lib/puppet/propertychange.rb +3 -3
- data/lib/puppet/provider/cron/crontab.rb +38 -36
- data/lib/puppet/provider/host/netinfo.rb +1 -2
- data/lib/puppet/provider/mailalias/aliases.rb +31 -0
- data/lib/puppet/provider/maillist/mailman.rb +113 -0
- data/lib/puppet/provider/mount.rb +5 -11
- data/lib/puppet/provider/mount/parsed.rb +2 -2
- data/lib/puppet/provider/package/appdmg.rb +1 -2
- data/lib/puppet/provider/package/apt.rb +3 -1
- data/lib/puppet/provider/package/aptrpm.rb +14 -4
- data/lib/puppet/provider/package/blastwave.rb +6 -4
- data/lib/puppet/provider/package/dpkg.rb +12 -4
- data/lib/puppet/provider/package/pkgdmg.rb +2 -2
- data/lib/puppet/provider/package/rpm.rb +11 -1
- data/lib/puppet/provider/package/rug.rb +1 -0
- data/lib/puppet/provider/package/urpmi.rb +11 -1
- data/lib/puppet/provider/package/yum.rb +12 -2
- data/lib/puppet/provider/parsedfile.rb +36 -6
- data/lib/puppet/rails.rb +9 -2
- data/lib/puppet/rails/param_name.rb +2 -3
- data/lib/puppet/rails/param_value.rb +20 -1
- data/lib/puppet/rails/resource.rb +8 -2
- data/lib/puppet/reference/configuration.rb +14 -16
- data/lib/puppet/reference/type.rb +4 -4
- data/lib/puppet/transaction.rb +4 -4
- data/lib/puppet/type.rb +19 -6
- data/lib/puppet/type/component.rb +9 -3
- data/lib/puppet/type/cron.rb +10 -4
- data/lib/puppet/type/exec.rb +9 -5
- data/lib/puppet/type/group.rb +2 -3
- data/lib/puppet/type/mailalias.rb +50 -0
- data/lib/puppet/type/maillist.rb +57 -0
- data/lib/puppet/type/mount.rb +25 -11
- data/lib/puppet/type/package.rb +6 -27
- data/lib/puppet/type/pfile.rb +5 -6
- data/lib/puppet/type/pfile/source.rb +8 -2
- data/lib/puppet/type/pfilebucket.rb +4 -3
- data/lib/puppet/type/resources.rb +1 -3
- data/lib/puppet/type/schedule.rb +16 -16
- data/lib/puppet/type/service.rb +4 -1
- data/lib/puppet/type/tidy.rb +1 -2
- data/lib/puppet/type/user.rb +2 -3
- data/lib/puppet/type/yumrepo.rb +2 -2
- data/lib/puppet/util.rb +29 -4
- data/lib/puppet/util/autoload.rb +45 -16
- data/lib/puppet/util/fileparsing.rb +23 -6
- data/lib/puppet/util/filetype.rb +12 -1
- data/lib/puppet/util/log.rb +2 -2
- data/lib/puppet/util/log_paths.rb +16 -0
- data/lib/puppet/util/reference.rb +2 -2
- data/test/language/ast/hostclass.rb +21 -4
- data/test/language/ast/resourceref.rb +95 -0
- data/test/language/functions.rb +5 -5
- data/test/language/interpreter.rb +129 -1
- data/test/language/node.rb +13 -2
- data/test/language/resource.rb +26 -1
- data/test/language/scope.rb +25 -5
- data/test/lib/puppettest/support/collection.rb +2 -2
- data/test/network/client/master.rb +28 -42
- data/test/network/server/mongrel_test.rb +7 -1
- data/test/other/propertychange.rb +2 -2
- data/test/other/transactions.rb +44 -5
- data/test/puppet/modules.rb +2 -1
- data/test/rails/ast.rb +7 -8
- data/test/rails/collection.rb +2 -2
- data/test/rails/railsresource.rb +21 -5
- data/test/ral/manager/attributes.rb +33 -1
- data/test/ral/manager/instances.rb +33 -6
- data/test/ral/manager/type.rb +29 -49
- data/test/ral/providers/cron/crontab.rb +61 -13
- data/test/ral/providers/mailalias/aliases.rb +57 -0
- data/test/ral/providers/mount/parsed.rb +4 -4
- data/test/ral/providers/package/apt.rb +13 -1
- data/test/ral/providers/parsedfile.rb +20 -7
- data/test/ral/types/cron.rb +17 -1
- data/test/ral/types/mailalias.rb +50 -0
- data/test/ral/types/mount.rb +35 -2
- data/test/ral/types/package.rb +10 -2
- data/test/ral/types/parameter.rb +4 -4
- data/test/ral/types/property.rb +39 -1
- data/test/util/autoload.rb +33 -18
- data/test/util/filetype.rb +49 -3
- metadata +13 -6
- data/lib/puppet/element.rb +0 -52
data/lib/puppet/util.rb
CHANGED
@@ -306,12 +306,16 @@ module Util
|
|
306
306
|
output_file = Tempfile.new("puppet")
|
307
307
|
end
|
308
308
|
|
309
|
+
oldverb = $VERBOSE
|
310
|
+
$VERBOSE = false
|
309
311
|
child_pid = Kernel.fork
|
312
|
+
$VERBOSE = oldverb
|
310
313
|
if child_pid
|
311
314
|
# Parent process executes this
|
312
315
|
child_status = Process.waitpid2(child_pid)[1]
|
313
316
|
else
|
314
317
|
# Child process executes this
|
318
|
+
Process.setsid
|
315
319
|
begin
|
316
320
|
$stdin.reopen("/dev/null")
|
317
321
|
$stdout.reopen(output_file)
|
@@ -338,9 +342,30 @@ module Util
|
|
338
342
|
|
339
343
|
# read output in if required
|
340
344
|
if ! arguments[:squelch]
|
341
|
-
|
342
|
-
|
343
|
-
|
345
|
+
|
346
|
+
# Make sure the file's actually there. This is
|
347
|
+
# basically a race condition, and is probably a horrible
|
348
|
+
# way to handle it, but, well, oh well.
|
349
|
+
unless FileTest.exists?(output_file.path)
|
350
|
+
Puppet.warning "sleeping"
|
351
|
+
sleep 0.5
|
352
|
+
unless FileTest.exists?(output_file.path)
|
353
|
+
Puppet.warning "sleeping 2"
|
354
|
+
sleep 1
|
355
|
+
unless FileTest.exists?(output_file.path)
|
356
|
+
Puppet.warning "Could not get output"
|
357
|
+
output = ""
|
358
|
+
end
|
359
|
+
end
|
360
|
+
end
|
361
|
+
unless output
|
362
|
+
# We have to explicitly open here, so that it reopens
|
363
|
+
# after the child writes.
|
364
|
+
output = output_file.open.read
|
365
|
+
|
366
|
+
# The 'true' causes the file to get unlinked right away.
|
367
|
+
output_file.close(true)
|
368
|
+
end
|
344
369
|
end
|
345
370
|
|
346
371
|
if arguments[:failonfail]
|
@@ -436,4 +461,4 @@ require 'puppet/util/logging'
|
|
436
461
|
require 'puppet/util/package'
|
437
462
|
require 'puppet/util/warnings'
|
438
463
|
|
439
|
-
# $Id: util.rb
|
464
|
+
# $Id: util.rb 2717 2007-07-19 20:02:26Z luke $
|
data/lib/puppet/util/autoload.rb
CHANGED
@@ -3,20 +3,42 @@ class Puppet::Util::Autoload
|
|
3
3
|
include Puppet::Util
|
4
4
|
|
5
5
|
@autoloaders = {}
|
6
|
-
|
7
|
-
attr_accessor :object, :path, :objwarn, :wrap
|
8
|
-
|
6
|
+
@loaded = {}
|
9
7
|
|
10
8
|
class << self
|
11
9
|
attr_reader :autoloaders
|
12
10
|
private :autoloaders
|
13
11
|
end
|
14
|
-
Puppet::Util.classproxy self, :autoloaders, "[]", "[]=", :clear
|
15
12
|
|
16
|
-
|
17
|
-
|
13
|
+
# Send [], []=, and :clear to the @autloaders hash
|
14
|
+
Puppet::Util.classproxy self, :autoloaders, "[]", "[]="
|
15
|
+
|
16
|
+
# Clear the list of autoloaders and loaded files.
|
17
|
+
def self.clear
|
18
|
+
@autoloaders.clear
|
19
|
+
@loaded.clear
|
20
|
+
end
|
21
|
+
|
22
|
+
# List all loaded files.
|
23
|
+
def self.list_loaded
|
24
|
+
@loaded.sort { |a,b| a[0] <=> b[0] }.collect do |path, hash|
|
25
|
+
"%s: %s" % [path, hash[:file]]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Has a given path been loaded? This is used for testing whether a
|
30
|
+
# changed file should be loaded or just ignored.
|
31
|
+
def self.loaded?(path)
|
32
|
+
path = path.to_s.sub(/\.rb$/, '')
|
33
|
+
@loaded[path]
|
34
|
+
end
|
35
|
+
|
36
|
+
# Save the fact that a given path has been loaded
|
37
|
+
def self.loaded(path, file, loader)
|
38
|
+
@loaded[path] = {:file => file, :autoloader => loader}
|
39
|
+
end
|
18
40
|
|
19
|
-
|
41
|
+
attr_accessor :object, :path, :objwarn, :wrap
|
20
42
|
|
21
43
|
def initialize(obj, path, options = {})
|
22
44
|
@path = path.to_s
|
@@ -39,11 +61,10 @@ class Puppet::Util::Autoload
|
|
39
61
|
unless defined? @wrap
|
40
62
|
@wrap = true
|
41
63
|
end
|
42
|
-
|
43
|
-
@loaded = {}
|
44
64
|
end
|
45
65
|
|
46
|
-
# Load a single plugin by name.
|
66
|
+
# Load a single plugin by name. We use 'load' here so we can reload a
|
67
|
+
# given plugin.
|
47
68
|
def load(name)
|
48
69
|
path = name.to_s + ".rb"
|
49
70
|
|
@@ -53,7 +74,7 @@ class Puppet::Util::Autoload
|
|
53
74
|
begin
|
54
75
|
Kernel.load file, @wrap
|
55
76
|
name = symbolize(name)
|
56
|
-
|
77
|
+
loaded name, file
|
57
78
|
return true
|
58
79
|
rescue LoadError => detail
|
59
80
|
# I have no idea what's going on here, but different versions
|
@@ -70,11 +91,19 @@ class Puppet::Util::Autoload
|
|
70
91
|
return false
|
71
92
|
end
|
72
93
|
|
94
|
+
# Mark the named object as loaded. Note that this supports unqualified
|
95
|
+
# queries, while we store the result as a qualified query in the class.
|
96
|
+
def loaded(name, file)
|
97
|
+
self.class.loaded(File.join(@path, name.to_s), file, object)
|
98
|
+
end
|
99
|
+
|
73
100
|
# Indicate whether the specfied plugin has been loaded.
|
74
101
|
def loaded?(name)
|
75
|
-
|
102
|
+
self.class.loaded?(File.join(@path, name.to_s))
|
76
103
|
end
|
77
104
|
|
105
|
+
# Load all instances that we can. This uses require, rather than load,
|
106
|
+
# so that already-loaded files don't get reloaded unnecessarily.
|
78
107
|
def loadall
|
79
108
|
# Load every instance of everything we can find.
|
80
109
|
eachdir do |dir|
|
@@ -84,12 +113,12 @@ class Puppet::Util::Autoload
|
|
84
113
|
# believe, but it works as long as real classes
|
85
114
|
# aren't used.
|
86
115
|
name = File.basename(file).sub(".rb", '').intern
|
87
|
-
next if
|
116
|
+
next if loaded?(name)
|
88
117
|
next if $".include?(File.join(@path, name.to_s + ".rb"))
|
89
118
|
filepath = File.join(@path, name.to_s + ".rb")
|
90
119
|
begin
|
91
|
-
Kernel.require
|
92
|
-
|
120
|
+
Kernel.require file
|
121
|
+
loaded(name, file)
|
93
122
|
rescue => detail
|
94
123
|
if Puppet[:trace]
|
95
124
|
puts detail.backtrace
|
@@ -116,4 +145,4 @@ class Puppet::Util::Autoload
|
|
116
145
|
end
|
117
146
|
end
|
118
147
|
|
119
|
-
# $Id: autoload.rb
|
148
|
+
# $Id: autoload.rb 2668 2007-07-10 04:00:28Z luke $
|
@@ -117,6 +117,11 @@ module Puppet::Util::FileParsing
|
|
117
117
|
meta_def(:pre_gen, &block)
|
118
118
|
end
|
119
119
|
|
120
|
+
# Are we a text type?
|
121
|
+
def text?
|
122
|
+
type == :text
|
123
|
+
end
|
124
|
+
|
120
125
|
def to_line=(block)
|
121
126
|
meta_def(:to_line, &block)
|
122
127
|
end
|
@@ -163,8 +168,12 @@ module Puppet::Util::FileParsing
|
|
163
168
|
if match = regex.match(line)
|
164
169
|
fields = []
|
165
170
|
ret = {}
|
166
|
-
record.fields.zip(match.captures).each do |
|
167
|
-
|
171
|
+
record.fields.zip(match.captures).each do |field, value|
|
172
|
+
if value == record.absent
|
173
|
+
ret[field] = :absent
|
174
|
+
else
|
175
|
+
ret[field] = value
|
176
|
+
end
|
168
177
|
end
|
169
178
|
else
|
170
179
|
nil
|
@@ -188,7 +197,7 @@ module Puppet::Util::FileParsing
|
|
188
197
|
end
|
189
198
|
end
|
190
199
|
|
191
|
-
|
200
|
+
if record.rollup and ! line_fields.empty?
|
192
201
|
last_field = record.fields[-1]
|
193
202
|
val = ([ret[last_field]] + line_fields).join(record.joiner)
|
194
203
|
ret[last_field] = val
|
@@ -219,8 +228,16 @@ module Puppet::Util::FileParsing
|
|
219
228
|
|
220
229
|
# Split a bunch of text into lines and then parse them individually.
|
221
230
|
def parse(text)
|
231
|
+
count = 1
|
222
232
|
lines(text).collect do |line|
|
223
|
-
|
233
|
+
count += 1
|
234
|
+
if val = parse_line(line)
|
235
|
+
val
|
236
|
+
else
|
237
|
+
error = Puppet::Error.new("Could not parse line %s" % line.inspect)
|
238
|
+
error.line = count
|
239
|
+
raise error
|
240
|
+
end
|
224
241
|
end
|
225
242
|
end
|
226
243
|
|
@@ -371,10 +388,10 @@ module Puppet::Util::FileParsing
|
|
371
388
|
return record
|
372
389
|
end
|
373
390
|
|
374
|
-
#
|
391
|
+
# Retrieve the record object.
|
375
392
|
def record_type(type)
|
376
393
|
@record_types[symbolize(type)]
|
377
394
|
end
|
378
395
|
end
|
379
396
|
|
380
|
-
# $Id: fileparsing.rb
|
397
|
+
# $Id: fileparsing.rb 2697 2007-07-14 21:13:04Z luke $
|
data/lib/puppet/util/filetype.rb
CHANGED
@@ -67,6 +67,16 @@ class Puppet::Util::FileType
|
|
67
67
|
@filetypes[type]
|
68
68
|
end
|
69
69
|
|
70
|
+
# Back the file up before replacing it.
|
71
|
+
def backup
|
72
|
+
bucket.backup(@path) if FileTest.exists?(@path)
|
73
|
+
end
|
74
|
+
|
75
|
+
# Pick or create a filebucket to use.
|
76
|
+
def bucket
|
77
|
+
Puppet::Type.type(:filebucket).mkdefaultbucket.bucket
|
78
|
+
end
|
79
|
+
|
70
80
|
def initialize(path)
|
71
81
|
@path = path
|
72
82
|
end
|
@@ -91,6 +101,7 @@ class Puppet::Util::FileType
|
|
91
101
|
|
92
102
|
# Overwrite the file.
|
93
103
|
def write(text)
|
104
|
+
backup()
|
94
105
|
File.open(@path, "w") { |f| f.print text; f.flush }
|
95
106
|
end
|
96
107
|
end
|
@@ -297,4 +308,4 @@ class Puppet::Util::FileType
|
|
297
308
|
end
|
298
309
|
end
|
299
310
|
|
300
|
-
# $Id: filetype.rb
|
311
|
+
# $Id: filetype.rb 2679 2007-07-11 20:23:49Z luke $
|
data/lib/puppet/util/log.rb
CHANGED
@@ -518,7 +518,7 @@ class Puppet::Util::Log
|
|
518
518
|
# We can't store the actual source, we just store the path.
|
519
519
|
# We can't just check for whether it responds to :path, because
|
520
520
|
# plenty of providers respond to that in their normal function.
|
521
|
-
if source.is_a?(Puppet::
|
521
|
+
if (source.is_a?(Puppet::Type) or source.is_a?(Puppet::Parameter)) and source.respond_to?(:path)
|
522
522
|
@objectsource = true
|
523
523
|
@source = source.path
|
524
524
|
else
|
@@ -546,4 +546,4 @@ class Puppet::Util::Log
|
|
546
546
|
end
|
547
547
|
Puppet::Log = Puppet::Util::Log
|
548
548
|
|
549
|
-
# $Id: log.rb
|
549
|
+
# $Id: log.rb 2647 2007-07-04 22:25:23Z luke $
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Created by Luke Kanies on 2007-07-04.
|
2
|
+
# Copyright (c) 2007. All rights reserved.
|
3
|
+
|
4
|
+
module Puppet::Util::LogPaths
|
5
|
+
# return the full path to us, for logging and rollback
|
6
|
+
# some classes (e.g., FileTypeRecords) will have to override this
|
7
|
+
def path
|
8
|
+
unless defined? @path
|
9
|
+
@path = pathbuilder
|
10
|
+
end
|
11
|
+
|
12
|
+
return "/" + @path.join("/")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# $Id: log_paths.rb 2647 2007-07-04 22:25:23Z luke $
|
@@ -173,7 +173,7 @@ class Puppet::Util::Reference
|
|
173
173
|
end
|
174
174
|
|
175
175
|
puts "Writing %s reference to trac as %s" % [@name, @page]
|
176
|
-
cmd = %{sudo trac-admin /
|
176
|
+
cmd = %{sudo trac-admin /opt/rl/trac/puppet wiki import %s /tmp/puppetdoc.txt} % self.page
|
177
177
|
output = %x{#{cmd}}
|
178
178
|
unless $? == 0
|
179
179
|
$stderr.puts "trac-admin failed"
|
@@ -186,4 +186,4 @@ class Puppet::Util::Reference
|
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
189
|
-
# $Id: reference.rb
|
189
|
+
# $Id: reference.rb 2636 2007-06-19 23:52:34Z luke $
|
@@ -8,6 +8,7 @@ $:.unshift("../../lib") if __FILE__ =~ /\.rb$/
|
|
8
8
|
require 'puppettest'
|
9
9
|
require 'puppettest/parsertesting'
|
10
10
|
require 'puppettest/resourcetesting'
|
11
|
+
require 'mocha'
|
11
12
|
|
12
13
|
class TestASTHostClass < Test::Unit::TestCase
|
13
14
|
include PuppetTest
|
@@ -34,7 +35,7 @@ class TestASTHostClass < Test::Unit::TestCase
|
|
34
35
|
klass.evaluate(:scope => scope)
|
35
36
|
end
|
36
37
|
|
37
|
-
assert(scope.
|
38
|
+
assert(scope.class_scope(klass), "Class was not considered evaluated")
|
38
39
|
|
39
40
|
tmp = scope.findresource("File[/tmp]")
|
40
41
|
assert(tmp, "Could not find file /tmp")
|
@@ -74,8 +75,8 @@ class TestASTHostClass < Test::Unit::TestCase
|
|
74
75
|
moresub.evaluate(:scope => scope)
|
75
76
|
end
|
76
77
|
|
77
|
-
assert(scope.
|
78
|
-
assert(scope.
|
78
|
+
assert(scope.class_scope(newbase), "Did not eval newbase")
|
79
|
+
assert(scope.class_scope(newsub), "Did not eval newsub")
|
79
80
|
|
80
81
|
yay = scope.findresource("File[/tmp/yay]")
|
81
82
|
assert(yay, "Did not find file /tmp/yay")
|
@@ -157,6 +158,22 @@ class TestASTHostClass < Test::Unit::TestCase
|
|
157
158
|
assert(result, "could not find parent-defined definition from sub")
|
158
159
|
assert(fun == result, "found incorrect parent-defined definition from sub")
|
159
160
|
end
|
161
|
+
|
162
|
+
# Make sure the subscopes we generate get the right type and name
|
163
|
+
def test_subscope
|
164
|
+
interp = mkinterp
|
165
|
+
|
166
|
+
klass = interp.newclass("base")
|
167
|
+
scope = mkscope(:interp => interp)
|
168
|
+
scope.expects(:newscope).with(:name => "base", :type => "class", :namespace => "base").returns(mkscope(:interp => interp))
|
169
|
+
klass.subscope(scope)
|
170
|
+
|
171
|
+
# Now make sure it works for namespaces
|
172
|
+
klass = interp.newclass("sub::type")
|
173
|
+
scope = mkscope(:interp => interp)
|
174
|
+
scope.expects(:newscope).with(:name => "sub::type", :type => "class", :namespace => "sub::type").returns(mkscope(:interp => interp))
|
175
|
+
klass.subscope(scope)
|
176
|
+
end
|
160
177
|
end
|
161
178
|
|
162
|
-
# $Id: hostclass.rb
|
179
|
+
# $Id: hostclass.rb 2715 2007-07-19 19:23:56Z luke $
|
@@ -0,0 +1,95 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created by Luke A. Kanies on 2007-07-8.
|
4
|
+
# Copyright (c) 2007. All rights reserved.
|
5
|
+
|
6
|
+
$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
|
7
|
+
|
8
|
+
require 'puppettest'
|
9
|
+
require 'puppettest/parsertesting'
|
10
|
+
|
11
|
+
class TestASTResourceRef < Test::Unit::TestCase
|
12
|
+
include PuppetTest
|
13
|
+
include PuppetTest::ParserTesting
|
14
|
+
AST = Puppet::Parser::AST
|
15
|
+
|
16
|
+
def newref(type, title)
|
17
|
+
AST::ResourceRef.new(:type => type, :title => AST::String.new(:value => title))
|
18
|
+
end
|
19
|
+
|
20
|
+
def setup
|
21
|
+
super
|
22
|
+
@interp = mkinterp
|
23
|
+
@scope = mkscope :interp => @interp
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_evaluate
|
27
|
+
@interp.newdefine "one::two"
|
28
|
+
@interp.newdefine "one-two"
|
29
|
+
[%w{file /tmp/yay}, %w{one::two three}, %w{one-two three}].each do |type, title|
|
30
|
+
ref = newref(type, title)
|
31
|
+
|
32
|
+
evaled = nil
|
33
|
+
assert_nothing_raised("Could not evaluate resource ref") do
|
34
|
+
evaled = ref.evaluate(:scope => @scope)
|
35
|
+
end
|
36
|
+
|
37
|
+
assert_equal(type, evaled.type, "Type did not translate correctly")
|
38
|
+
assert_equal(title, evaled.title, "Title did not translate correctly")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Related to #706, make sure resource references correctly translate to qualified types.
|
43
|
+
def test_scoped_references
|
44
|
+
@interp.newdefine "one"
|
45
|
+
@interp.newdefine "one::two"
|
46
|
+
@interp.newdefine "three"
|
47
|
+
twoscope = @scope.newscope(:type => "one", :namespace => "one")
|
48
|
+
assert(twoscope.finddefine("two"), "Could not find 'two' definition")
|
49
|
+
title = "title"
|
50
|
+
|
51
|
+
# First try a qualified type
|
52
|
+
assert_equal("one::two", newref("two", title).evaluate(:scope => twoscope).type,
|
53
|
+
"Defined type was not made fully qualified")
|
54
|
+
|
55
|
+
# Then try a type that does not need to be qualified
|
56
|
+
assert_equal("one", newref("one", title).evaluate(:scope => twoscope).type,
|
57
|
+
"Unqualified defined type was not handled correctly")
|
58
|
+
|
59
|
+
# Then an unqualified type from within the one namespace
|
60
|
+
assert_equal("three", newref("three", title).evaluate(:scope => twoscope).type,
|
61
|
+
"Defined type was not made fully qualified")
|
62
|
+
|
63
|
+
# Then a builtin type
|
64
|
+
assert_equal("file", newref("file", title).evaluate(:scope => twoscope).type,
|
65
|
+
"Builtin type was not handled correctly")
|
66
|
+
|
67
|
+
# Now try a type that does not exist, which should throw an error.
|
68
|
+
assert_raise(Puppet::ParseError, "Did not fail on a missing type in a resource reference") do
|
69
|
+
newref("nosuchtype", title).evaluate(:scope => twoscope)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Now run the same tests, but with the classes
|
73
|
+
@interp.newclass "four"
|
74
|
+
@interp.newclass "one::five"
|
75
|
+
|
76
|
+
# First try an unqualified type
|
77
|
+
assert_equal("four", newref("class", "four").evaluate(:scope => twoscope).title,
|
78
|
+
"Unqualified class was not found")
|
79
|
+
|
80
|
+
# Then a qualified class
|
81
|
+
assert_equal("one::five", newref("class", "five").evaluate(:scope => twoscope).title,
|
82
|
+
"Class was not made fully qualified")
|
83
|
+
|
84
|
+
# Then try a type that does not need to be qualified
|
85
|
+
assert_equal("four", newref("class", "four").evaluate(:scope => twoscope).title,
|
86
|
+
"Unqualified class was not handled correctly")
|
87
|
+
|
88
|
+
# Now try a type that does not exist, which should throw an error.
|
89
|
+
assert_raise(Puppet::ParseError, "Did not fail on a missing type in a resource reference") do
|
90
|
+
newref("class", "nosuchclass").evaluate(:scope => twoscope)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# $Id: resourceref.rb 2715 2007-07-19 19:23:56Z luke $
|