puppet 0.23.1 → 0.23.2

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.

Files changed (55) hide show
  1. data/CHANGELOG +31 -0
  2. data/bin/puppetd +2 -1
  3. data/conf/redhat/puppet.spec +9 -6
  4. data/conf/redhat/server.init +4 -5
  5. data/examples/code/mac_dscl.pp +28 -0
  6. data/examples/code/mac_dscl_revert.pp +26 -0
  7. data/examples/code/mac_netinfo.pp +5 -0
  8. data/examples/code/mac_pkgdmg.pp +7 -0
  9. data/ext/puppet-test +69 -2
  10. data/lib/puppet.rb +2 -2
  11. data/lib/puppet/configuration.rb +5 -1
  12. data/lib/puppet/network/server/mongrel.rb +3 -3
  13. data/lib/puppet/parser/ast.rb +2 -2
  14. data/lib/puppet/parser/ast/component.rb +3 -3
  15. data/lib/puppet/parser/ast/node.rb +2 -2
  16. data/lib/puppet/parser/collector.rb +2 -2
  17. data/lib/puppet/parser/interpreter.rb +38 -215
  18. data/lib/puppet/parser/parser.rb +11 -228
  19. data/lib/puppet/parser/parser_support.rb +447 -0
  20. data/lib/puppet/parser/resource/param.rb +2 -2
  21. data/lib/puppet/provider.rb +5 -3
  22. data/lib/puppet/provider/cron/crontab.rb +22 -9
  23. data/lib/puppet/provider/group/directoryservice.rb +23 -0
  24. data/lib/puppet/provider/interface/redhat.rb +251 -0
  25. data/lib/puppet/provider/interface/sunos.rb +116 -0
  26. data/lib/puppet/provider/mount.rb +4 -1
  27. data/lib/puppet/provider/nameservice/directoryservice.rb +341 -0
  28. data/lib/puppet/provider/package/dpkg.rb +2 -2
  29. data/lib/puppet/provider/package/openbsd.rb +2 -2
  30. data/lib/puppet/provider/package/rpm.rb +2 -4
  31. data/lib/puppet/provider/package/sun.rb +2 -2
  32. data/lib/puppet/provider/parsedfile.rb +32 -29
  33. data/lib/puppet/provider/user/directoryservice.rb +116 -0
  34. data/lib/puppet/rails/host.rb +1 -1
  35. data/lib/puppet/reference/configuration.rb +7 -4
  36. data/lib/puppet/type/interface.rb +57 -0
  37. data/lib/puppet/type/pfile/group.rb +2 -2
  38. data/lib/puppet/util/config.rb +10 -3
  39. data/lib/puppet/util/fileparsing.rb +2 -2
  40. data/test/language/ast/hostclass.rb +1 -17
  41. data/test/language/interpreter.rb +18 -388
  42. data/test/language/node.rb +8 -8
  43. data/test/language/parser.rb +444 -45
  44. data/test/lib/puppettest/parsertesting.rb +2 -2
  45. data/test/lib/puppettest/support/collection.rb +2 -2
  46. data/test/network/server/mongrel_test.rb +24 -3
  47. data/test/rails/collection.rb +34 -1
  48. data/test/ral/providers/cron/crontab.rb +198 -40
  49. data/test/ral/providers/mount/parsed.rb +69 -46
  50. data/test/ral/providers/parsedfile.rb +20 -28
  51. data/test/ral/types/cron.rb +20 -24
  52. data/test/ral/types/interface.rb +40 -0
  53. data/test/ral/types/package.rb +6 -2
  54. data/test/util/config.rb +106 -30
  55. metadata +14 -2
data/CHANGELOG CHANGED
@@ -1,3 +1,34 @@
1
+ Fixed the problem in cron jobs where environment settings
2
+ tended to multiple. (#749)
3
+
4
+ Collection of resources now correctly only collects exported
5
+ resources again. This was broken in 0.23.0. (#731)
6
+
7
+ 'gen_config' now generates a configuration with
8
+ all parameters under a heading that matches the
9
+ process name, rather than keeping section headings.
10
+
11
+ Refactored how the parser and interpreter relate,
12
+ so parsing is now effectively an atomic process (thus
13
+ fixing #314 and #729). This makes the interpreter less
14
+ prone to error and less prone to show the error to the
15
+ clients. Note that this means that if a configuration
16
+ fails to parse, then the previous, parseable configuration
17
+ will be used instead, so the client will not know that
18
+ the configuration failed to parse.
19
+
20
+ Added support for managing interfaces, thanks to work
21
+ by Paul Rose.
22
+
23
+ Fixed #652, thanks to a patch by emerose; --fqdn again
24
+ works with puppetd.
25
+
26
+ Added an extra check to the Mongrel support so that
27
+ Apache can be used with optional cert checking, instead
28
+ of mandatory, thus allowing Mongrel to function as the CA.
29
+ This is thanks to work done by Marcin Owsiany.
30
+
31
+ 0.23.1
1
32
  You can now specify relationships to classes, which work
2
33
  exactly like relationships to defined types:
3
34
  require => Class[myclass]
@@ -295,6 +295,7 @@ end
295
295
  args[:Server] = Puppet[:server]
296
296
  if options[:fqdn]
297
297
  args[:FQDN] = options[:fqdn]
298
+ Puppet[:certname] = options[:fqdn]
298
299
  end
299
300
 
300
301
  if options[:centrallogs]
@@ -446,4 +447,4 @@ else
446
447
  Puppet.start
447
448
  end
448
449
 
449
- # $Id: puppetd 2594 2007-06-15 23:11:43Z luke $
450
+ # $Id: puppetd 2729 2007-07-30 22:05:44Z luke $
@@ -7,7 +7,7 @@
7
7
 
8
8
  Summary: A network tool for managing many disparate systems
9
9
  Name: puppet
10
- Version: 0.23.1
10
+ Version: 0.23.2
11
11
  Release: 1%{?dist}
12
12
  License: GPL
13
13
  Group: System Environment/Base
@@ -43,8 +43,6 @@ The server can also function as a certificate authority and file server.
43
43
 
44
44
  %prep
45
45
  %setup -q
46
- cp -p conf/redhat/puppetd.conf conf/redhat/puppet.conf
47
- sed -i -e 's/^\[puppet\]$/[main]/' conf/redhat/puppet.conf
48
46
 
49
47
  %build
50
48
  for f in bin/* ; do
@@ -75,10 +73,12 @@ install -Dp -m0644 %{confdir}/server.sysconfig %{buildroot}%{_sysconfdir}/syscon
75
73
  install -Dp -m0755 %{confdir}/server.init %{buildroot}%{_initrddir}/puppetmaster
76
74
  install -Dp -m0644 %{confdir}/fileserver.conf %{buildroot}%{_sysconfdir}/puppet/fileserver.conf
77
75
  install -Dp -m0644 %{confdir}/puppet.conf %{buildroot}%{_sysconfdir}/puppet/puppet.conf
78
- ln -s puppetd.conf %{buildroot}%{_sysconfdir}/puppet/puppetmasterd.conf
79
- ln -s puppetd.conf %{buildroot}%{_sysconfdir}/puppet/puppetca.conf
80
- install -Dp -m0644 %{confdir}/puppetd.conf %{buildroot}%{_sysconfdir}/puppet/puppetd.conf
81
76
  install -Dp -m0644 %{confdir}/logrotate %{buildroot}%{_sysconfdir}/logrotate.d/puppet
77
+ # We need something for these ghosted files, otherwise rpmbuild
78
+ # will complain loudly. They won't be included in the binary packages
79
+ touch %{buildroot}%{_sysconfdir}/puppet/puppetmasterd.conf
80
+ touch %{buildroot}%{_sysconfdir}/puppet/puppetca.conf
81
+ touch %{buildroot}%{_sysconfdir}/puppet/puppetd.conf
82
82
 
83
83
  %files
84
84
  %defattr(-, root, root, 0755)
@@ -148,6 +148,9 @@ fi
148
148
  rm -rf %{buildroot}
149
149
 
150
150
  %changelog
151
+ * Thu Jul 26 2007 David Lutterkort <dlutter@redhat.com> - 0.23.1-1
152
+ - Remove old config files
153
+
151
154
  * Wed Jun 20 2007 David Lutterkort <dlutter@redhat.com> - 0.23.0-1
152
155
  - Install one puppet.conf instead of old config files, keep old configs
153
156
  around to ease update
@@ -20,11 +20,10 @@ if [ -f /etc/sysconfig/puppetmaster ]; then
20
20
  . /etc/sysconfig/puppetmaster
21
21
  fi
22
22
 
23
- [ -z "$PUPPETMASTER_MANIFEST" ] && PUPPETMASTER_MANIFEST=/etc/puppet/manifests/site.pp
24
- [ -z "$PUPPETMASTER_LOG" ] && PUPPETMASTER_LOG="/var/log/puppet/puppetmaster.log"
25
- PUPPETMASTER_OPTS="
26
- --manifest=$PUPPETMASTER_MANIFEST \
27
- --logdest=${PUPPETMASTER_LOG} \
23
+ PUPPETMASTER_OPTS=""
24
+ [ -n "$PUPPETMASTER_MANIFEST" ] && PUPPETMASTER_OPTS="--manifest=${PUPPETMASTER_MANIFEST}"
25
+ [ -n "$PUPPETMASTER_LOG" ] && PUPPETMASTER_OPTS="${PUPPETMASTER_OPTS} --logdest=${PUPPETMASTER_LOG}"
26
+ PUPPETMASTER_OPTS="${PUPPETMASTER_OPTS} \
28
27
  ${PUPPETMASTER_EXTRA_OPTS}"
29
28
 
30
29
  RETVAL=0
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env puppet --debug --verbose --trace
2
+ #
3
+ # Jeff McCune: I use this for developing and testing the directory service
4
+ # provider.
5
+
6
+ User { provider => "directoryservice" }
7
+ Group { provider => "directoryservice" }
8
+
9
+ user {
10
+ "testgone":
11
+ ensure => absent,
12
+ uid => 550;
13
+ "testhere":
14
+ ensure => present,
15
+ password => "foobar",
16
+ shell => "/bin/bash",
17
+ uid => 551;
18
+ }
19
+
20
+ group {
21
+ "testgone":
22
+ ensure => absent,
23
+ gid => 550;
24
+ "testhere":
25
+ ensure => present,
26
+ gid => 551;
27
+
28
+ }
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env puppet --debug --verbose --trace
2
+ #
3
+ # Jeff McCune: I use this for developing and testing the directory service
4
+ # provider.
5
+
6
+ User { provider => "directoryservice" }
7
+ Group { provider => "directoryservice" }
8
+
9
+ user {
10
+ "testgone":
11
+ ensure => absent,
12
+ uid => 550;
13
+ "testhere":
14
+ ensure => absent,
15
+ uid => 551;
16
+ }
17
+
18
+ group {
19
+ "testgone":
20
+ ensure => absent,
21
+ gid => 550;
22
+ "testhere":
23
+ ensure => absent,
24
+ gid => 551;
25
+
26
+ }
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env puppet --debug
2
+
3
+ user {
4
+ "jmccune": provider => "netinfo", ensure => present;
5
+ }
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env puppet
2
+ #
3
+
4
+ package
5
+ {
6
+ "Foobar.pkg.dmg": ensure => present, provider => pkgdmg;
7
+ }
@@ -176,7 +176,8 @@ class Suite
176
176
  }
177
177
  end
178
178
 
179
- $options[:repeat].times do
179
+ $options[:repeat].times do |i|
180
+ @count = i
180
181
  if forked?
181
182
  msg = doc + " in PID %s" % Process.pid
182
183
  else
@@ -256,6 +257,72 @@ Suite.new :file, "File interactions" do
256
257
  end
257
258
  end
258
259
 
260
+ # Note that this uses an env variable to determine how many resources per
261
+ # host to create (with a default of 10). 'repeat' determines how
262
+ # many hosts to create. You probably will get mad failures if you
263
+ # use forking and sqlite.
264
+ # Here's an example run of this test, using sqlite:
265
+ # RESOURCE_COUNT=50 ext/puppet-test --suite rails --test storage --confdir /tmp/storagetesting --vardir /tmp/storagetesting --repeat 10
266
+ Suite.new :rails, "Rails Interactions" do
267
+ def prepare
268
+ Puppet::Rails.init
269
+ @facts = Facter.to_hash
270
+
271
+ if num = ENV["RESOURCECOUNT"]
272
+ @resources = Integer(num)
273
+ else
274
+ @resources = 10
275
+ end
276
+ end
277
+
278
+ Resource = Puppet::Parser::Resource
279
+
280
+ def execute(test, msg)
281
+ begin
282
+ send(test)
283
+ rescue => detail
284
+ puts detail.backtrace if Puppet[:trace]
285
+ Puppet.err "%s failed: %s" % [@name, detail.to_s]
286
+ end
287
+ end
288
+
289
+ def mkresource(type, title, parameters)
290
+ source = "fakesource"
291
+ res = Resource.new(:type => type, :title => title, :source => source, :scope => "fakescope")
292
+
293
+ parameters.each do |param, value|
294
+ res.set(param, value, source)
295
+ end
296
+ res
297
+ end
298
+
299
+ def ref(type, title)
300
+ Resource::Reference.new(:type => type, :title => title)
301
+ end
302
+
303
+ newtest :storage, "Stored resources" do
304
+ hostname = "host%s" % @count
305
+ @facts["hostname"] = hostname
306
+ args = {:facts => @facts, :name => hostname}
307
+
308
+ # Make all of the resources we want. Make them at least slightly complex,
309
+ # so we model real resources as close as we can.
310
+ resources = []
311
+ args[:resources] = resources
312
+ @resources.times do |resnum|
313
+ exec = mkresource("exec", "exec%s" % resnum, :command => "/bin/echo do something %s" % resnum)
314
+ exec.tags = %w{exec one} << "exec%s" % resnum
315
+ user = mkresource("user", "user%s" % resnum, :uid => resnum.to_s, :require => ref("exec", "exec%s" % resnum))
316
+ user.tags = %w{user one two} << "user%s" % resnum
317
+ file = mkresource("file", "/tmp/file%s" % resnum, :owner => resnum.to_s, :require => [ref("exec", "exec%s" % resnum), ref("user", "user%s" % resnum)])
318
+ file.tags = %w{file one three} << "file%s" % resnum
319
+ file.exported = true
320
+ resources << exec << user << file
321
+ end
322
+ Puppet::Rails::Host.store(args)
323
+ end
324
+ end
325
+
259
326
  $cmdargs = [
260
327
  [ "--compile", "-c", GetoptLong::NO_ARGUMENT ],
261
328
  [ "--describe", "-D", GetoptLong::REQUIRED_ARGUMENT ],
@@ -371,4 +438,4 @@ if $options[:fork] > 0
371
438
  Process.waitall
372
439
  end
373
440
 
374
- # $Id: puppet-test 2628 2007-06-19 20:04:52Z luke $
441
+ # $Id: puppet-test 2731 2007-07-31 02:34:28Z luke $
@@ -25,7 +25,7 @@ require 'puppet/util/suidmanager'
25
25
  # it's also a place to find top-level commands like 'debug'
26
26
 
27
27
  module Puppet
28
- PUPPETVERSION = '0.23.1'
28
+ PUPPETVERSION = '0.23.2'
29
29
 
30
30
  def Puppet.version
31
31
  return PUPPETVERSION
@@ -428,4 +428,4 @@ if Puppet[:storeconfigs]
428
428
  require 'puppet/rails'
429
429
  end
430
430
 
431
- # $Id: puppet.rb 2724 2007-07-20 19:23:33Z luke $
431
+ # $Id: puppet.rb 2754 2007-08-07 02:41:06Z luke $
@@ -313,6 +313,10 @@ module Puppet
313
313
  :ssl_client_header => ["HTTP_X_CLIENT_DN", "The header containing an authenticated
314
314
  client's SSL DN. Only used with Mongrel. This header must be set by the proxy
315
315
  to the authenticated client's SSL DN (e.g., ``/CN=puppet.reductivelabs.com``).
316
+ See the `UsingMongrel`:trac: wiki page for more information."],
317
+ :ssl_client_verify_header => ["HTTP_X_CLIENT_VERIFY", "The header containing the status
318
+ message of the client verification. Only used with Mongrel. This header must be set by the proxy
319
+ to 'SUCCESS' if the client successfully authenticated, and anything else otherwise.
316
320
  See the `UsingMongrel`:trac: wiki page for more information."]
317
321
  )
318
322
 
@@ -634,4 +638,4 @@ module Puppet
634
638
  )
635
639
  end
636
640
 
637
- # $Id: configuration.rb 2669 2007-07-10 04:17:07Z luke $
641
+ # $Id: configuration.rb 2752 2007-08-06 20:05:28Z luke $
@@ -116,9 +116,9 @@ module Puppet::Network
116
116
  def client_info(request)
117
117
  params = request.params
118
118
  ip = params["REMOTE_ADDR"]
119
- if dn = params[Puppet[:ssl_client_header]]
119
+ if dn = params[Puppet[:ssl_client_header]] and dn.include?("/CN=")
120
120
  client = dn.sub("/CN=", '')
121
- valid = true
121
+ valid = (params[Puppet[:ssl_client_verify_header]] == 'SUCCESS')
122
122
  else
123
123
  client = Resolv.getname(ip)
124
124
  valid = false
@@ -137,4 +137,4 @@ module Puppet::Network
137
137
  end
138
138
  end
139
139
 
140
- # $Id: mongrel.rb 2659 2007-07-08 23:02:06Z luke $
140
+ # $Id: mongrel.rb 2752 2007-08-06 20:05:28Z luke $
@@ -86,7 +86,7 @@ class Puppet::Parser::AST
86
86
  error = Puppet::Error.new(detail.to_s)
87
87
  # We can't use self.fail here because it always expects strings,
88
88
  # not exceptions.
89
- raise adderrorcontext(error)
89
+ raise adderrorcontext(error, detail)
90
90
  end
91
91
  end
92
92
 
@@ -117,4 +117,4 @@ end
117
117
 
118
118
  require 'puppet/parser/ast/leaf'
119
119
 
120
- # $Id: ast.rb 2463 2007-05-04 23:09:34Z luke $
120
+ # $Id: ast.rb 2742 2007-08-03 23:49:53Z luke $
@@ -16,7 +16,7 @@ class Puppet::Parser::AST
16
16
  @name = :definition
17
17
 
18
18
  attr_accessor :classname, :arguments, :code, :scope, :keyword
19
- attr_accessor :exported, :namespace, :interp, :virtual
19
+ attr_accessor :exported, :namespace, :parser, :virtual
20
20
 
21
21
  # These are retrieved when looking up the superclass
22
22
  attr_accessor :name
@@ -140,7 +140,7 @@ class Puppet::Parser::AST
140
140
  end
141
141
 
142
142
  def find_parentclass
143
- @interp.findclass(namespace, parentclass)
143
+ @parser.findclass(namespace, parentclass)
144
144
  end
145
145
 
146
146
  # Set our parent class, with a little check to avoid some potential
@@ -223,4 +223,4 @@ class Puppet::Parser::AST
223
223
  end
224
224
  end
225
225
 
226
- # $Id: component.rb 2562 2007-06-11 21:54:37Z luke $
226
+ # $Id: component.rb 2742 2007-08-03 23:49:53Z luke $
@@ -56,9 +56,9 @@ class Puppet::Parser::AST
56
56
  private
57
57
  # Search for the object matching our parent class.
58
58
  def find_parentclass
59
- @interp.nodesearch(parentclass)
59
+ @parser.findnode(parentclass)
60
60
  end
61
61
  end
62
62
  end
63
63
 
64
- # $Id: node.rb 2511 2007-05-14 15:19:48Z luke $
64
+ # $Id: node.rb 2742 2007-08-03 23:49:53Z luke $
@@ -23,7 +23,7 @@ class Puppet::Parser::Collector
23
23
  host = Puppet::Rails::Host.find_by_name(@scope.host)
24
24
 
25
25
  args = {:include => {:param_values => :param_name}}
26
- args[:conditions] = "restype = '%s'" % [@type]
26
+ args[:conditions] = "(exported = 't' AND restype = '%s')" % [@type]
27
27
  if @equery
28
28
  args[:conditions] += " AND (%s)" % [@equery]
29
29
  end
@@ -182,4 +182,4 @@ class Puppet::Parser::Collector
182
182
  end
183
183
  end
184
184
 
185
- # $Id: collector.rb 2705 2007-07-18 17:32:46Z luke $
185
+ # $Id: collector.rb 2746 2007-08-05 17:57:31Z luke $
@@ -30,6 +30,7 @@ class Puppet::Parser::Interpreter
30
30
  begin
31
31
  options[:scope].function_include(classes.find_all { |c| options[:scope].findclass(c) })
32
32
  rescue => detail
33
+ puts detail.backtrace
33
34
  raise Puppet::ParseError, "Could not evaluate classes for %s: %s" % [name, detail]
34
35
  end
35
36
  end
@@ -59,6 +60,7 @@ class Puppet::Parser::Interpreter
59
60
  class << self
60
61
  attr_writer :ldap
61
62
  end
63
+
62
64
  # just shorten the constant path a bit, using what amounts to an alias
63
65
  AST = Puppet::Parser::AST
64
66
 
@@ -105,10 +107,6 @@ class Puppet::Parser::Interpreter
105
107
  end
106
108
  end
107
109
 
108
- def clear
109
- initparsevars
110
- end
111
-
112
110
  # Iteratively evaluate all of the objects. This finds all of the objects
113
111
  # that represent definitions and evaluates the definitions appropriately.
114
112
  # It also adds defaults and overrides as appropriate.
@@ -264,48 +262,13 @@ class Puppet::Parser::Interpreter
264
262
  check_resource_collections(scope)
265
263
  end
266
264
 
267
- # Find a class definition, relative to the current namespace.
265
+ # Create proxy methods, so the scopes can call the interpreter, since
266
+ # they don't have access to the parser.
268
267
  def findclass(namespace, name)
269
- #find_or_load namespace, name, @classtable
270
- fqfind namespace, name, @classtable
268
+ @parser.findclass(namespace, name)
271
269
  end
272
-
273
- # Find a component definition, relative to the current namespace.
274
270
  def finddefine(namespace, name)
275
- #find_or_load namespace, name, @definetable
276
- fqfind namespace, name, @definetable
277
- end
278
-
279
- # The recursive method used to actually look these objects up.
280
- def fqfind(namespace, name, table)
281
- namespace = namespace.downcase
282
- name = name.downcase
283
- if name =~ /^::/ or namespace == ""
284
- classname = name.sub(/^::/, '')
285
- unless table[classname]
286
- self.load(classname)
287
- end
288
- return table[classname]
289
- end
290
- ary = namespace.split("::")
291
-
292
- while ary.length > 0
293
- newname = (ary + [name]).join("::").sub(/^::/, '')
294
- if obj = table[newname] or (self.load(newname) and obj = table[newname])
295
- return obj
296
- end
297
-
298
- # Delete the second to last object, which reduces our namespace by one.
299
- ary.pop
300
- end
301
-
302
- # If we've gotten to this point without finding it, see if the name
303
- # exists at the top namespace
304
- if obj = table[name] or (self.load(name) and obj = table[name])
305
- return obj
306
- end
307
-
308
- return nil
271
+ @parser.finddefine(namespace, name)
309
272
  end
310
273
 
311
274
  # create our interpreter
@@ -335,8 +298,6 @@ class Puppet::Parser::Interpreter
335
298
 
336
299
  @setup = false
337
300
 
338
- initparsevars()
339
-
340
301
  # Set it to either the value or nil. This is currently only used
341
302
  # by the cfengine module.
342
303
  @classes = hash[:Classes] || []
@@ -361,55 +322,11 @@ class Puppet::Parser::Interpreter
361
322
  end
362
323
 
363
324
  @files = []
364
- @loaded = []
365
325
 
366
326
  # Create our parser object
367
327
  parsefiles
368
328
  end
369
329
 
370
- # Initialize or reset the variables related to parsing.
371
- def initparsevars
372
- @classtable = {}
373
- @namespace = "main"
374
-
375
- @nodetable = {}
376
-
377
- @definetable = {}
378
- end
379
-
380
- # Try to load a class, since we could not find it.
381
- def load(classname)
382
- return false if classname == ""
383
- filename = classname.gsub("::", File::SEPARATOR)
384
-
385
- loaded = false
386
- # First try to load the top-level module
387
- mod = filename.scan(/^[\w-]+/).shift
388
- unless @loaded.include?(mod)
389
- @loaded << mod
390
- begin
391
- @parser.import(mod)
392
- Puppet.info "Autoloaded module %s" % mod
393
- loaded = true
394
- rescue Puppet::ImportError => detail
395
- # We couldn't load the module
396
- end
397
- end
398
-
399
- unless filename == mod and ! @loaded.include?(mod)
400
- @loaded << mod
401
- # Then the individual file
402
- begin
403
- @parser.import(filename)
404
- Puppet.info "Autoloaded file %s from module %s" % [filename, mod]
405
- loaded = true
406
- rescue Puppet::ImportError => detail
407
- # We couldn't load the file
408
- end
409
- end
410
- return loaded
411
- end
412
-
413
330
  # Find the ldap node, return the class list and parent node specially,
414
331
  # and everything else in a parameter hash.
415
332
  def ldapsearch(node)
@@ -505,115 +422,10 @@ class Puppet::Parser::Interpreter
505
422
  end
506
423
  end
507
424
 
508
- # Split an fq name into a namespace and name
509
- def namesplit(fullname)
510
- ary = fullname.split("::")
511
- n = ary.pop || ""
512
- ns = ary.join("::")
513
- return ns, n
514
- end
515
-
516
- # Create a new class, or merge with an existing class.
517
- def newclass(name, options = {})
518
- name = name.downcase
519
- if @definetable.include?(name)
520
- raise Puppet::ParseError, "Cannot redefine class %s as a definition" %
521
- name
522
- end
523
- code = options[:code]
524
- parent = options[:parent]
525
-
526
- # If the class is already defined, then add code to it.
527
- if other = @classtable[name]
528
- # Make sure the parents match
529
- if parent and other.parentclass and (parent != other.parentclass)
530
- @parser.error("Class %s is already defined at %s:%s; cannot redefine" % [name, other.file, other.line])
531
- end
532
-
533
- # This might be dangerous...
534
- if parent and ! other.parentclass
535
- other.parentclass = parent
536
- end
537
-
538
- # This might just be an empty, stub class.
539
- if code
540
- tmp = name
541
- if tmp == ""
542
- tmp = "main"
543
- end
544
-
545
- Puppet.debug @parser.addcontext("Adding code to %s" % tmp)
546
- # Else, add our code to it.
547
- if other.code and code
548
- other.code.children += code.children
549
- else
550
- other.code ||= code
551
- end
552
- end
553
- else
554
- # Define it anew.
555
- # Note we're doing something somewhat weird here -- we're setting
556
- # the class's namespace to its fully qualified name. This means
557
- # anything inside that class starts looking in that namespace first.
558
- args = {:namespace => name, :classname => name, :interp => self}
559
- args[:code] = code if code
560
- args[:parentclass] = parent if parent
561
- @classtable[name] = @parser.ast AST::HostClass, args
562
- end
563
-
564
- return @classtable[name]
565
- end
566
-
567
- # Create a new definition.
568
- def newdefine(name, options = {})
569
- name = name.downcase
570
- if @classtable.include?(name)
571
- raise Puppet::ParseError, "Cannot redefine class %s as a definition" %
572
- name
573
- end
574
- # Make sure our definition doesn't already exist
575
- if other = @definetable[name]
576
- @parser.error("%s is already defined at %s:%s; cannot redefine" % [name, other.file, other.line])
577
- end
578
-
579
- ns, whatever = namesplit(name)
580
- args = {
581
- :namespace => ns,
582
- :arguments => options[:arguments],
583
- :code => options[:code],
584
- :classname => name
585
- }
586
-
587
- [:code, :arguments].each do |param|
588
- args[param] = options[param] if options[param]
589
- end
590
-
591
- @definetable[name] = @parser.ast AST::Component, args
592
- end
593
-
594
- # Create a new node. Nodes are special, because they're stored in a global
595
- # table, not according to namespaces.
596
- def newnode(names, options = {})
597
- names = [names] unless names.instance_of?(Array)
598
- names.collect do |name|
599
- name = name.to_s.downcase
600
- if other = @nodetable[name]
601
- @parser.error("Node %s is already defined at %s:%s; cannot redefine" % [other.name, other.file, other.line])
602
- end
603
- name = name.to_s if name.is_a?(Symbol)
604
- args = {
605
- :name => name,
606
- }
607
- if options[:code]
608
- args[:code] = options[:code]
609
- end
610
- if options[:parent]
611
- args[:parentclass] = options[:parent]
612
- end
613
- @nodetable[name] = @parser.ast(AST::Node, args)
614
- @nodetable[name].classname = name
615
- @nodetable[name].interp = self
616
- @nodetable[name]
425
+ # Pass these methods through to the parser.
426
+ [:newclass, :newdefine, :newnode].each do |name|
427
+ define_method(name) do |*args|
428
+ @parser.send(name, *args)
617
429
  end
618
430
  end
619
431
 
@@ -662,7 +474,7 @@ class Puppet::Parser::Interpreter
662
474
 
663
475
  # See if our node was defined in the code.
664
476
  def nodesearch_code(name)
665
- @nodetable[name]
477
+ @parser.nodes[name]
666
478
  end
667
479
 
668
480
  # Look for external node definitions.
@@ -815,29 +627,40 @@ class Puppet::Parser::Interpreter
815
627
  end
816
628
  end
817
629
 
818
- # Reset our parse tables.
819
- clear()
820
-
821
- # Create a new parser, just to keep things fresh.
822
- @parser = Puppet::Parser::Parser.new(self)
630
+ # Create a new parser, just to keep things fresh. Don't replace our
631
+ # current parser until we know weverything works.
632
+ newparser = Puppet::Parser::Parser.new()
823
633
  if @code
824
- @parser.string = @code
634
+ newparser.string = @code
825
635
  else
826
- @parser.file = @file
827
- # Mark when we parsed, so we can check freshness
828
- @parsedate = File.stat(@file).ctime.to_i
636
+ newparser.file = @file
829
637
  end
830
638
 
831
639
  # Parsing stores all classes and defines and such in their
832
640
  # various tables, so we don't worry about the return.
833
- if @local
834
- @parser.parse
835
- else
836
- benchmark(:info, "Parsed manifest") do
837
- @parser.parse
641
+ begin
642
+ if @local
643
+ newparser.parse
644
+ else
645
+ benchmark(:info, "Parsed manifest") do
646
+ newparser.parse
647
+ end
648
+ end
649
+ # We've gotten this far, so it's ok to swap the parsers.
650
+ oldparser = @parser
651
+ @parser = newparser
652
+ if oldparser
653
+ oldparser.clear
654
+ end
655
+
656
+ # Mark when we parsed, so we can check freshness
657
+ @parsedate = Time.now.to_i
658
+ rescue => detail
659
+ if Puppet[:trace]
660
+ puts detail.backtrace
838
661
  end
662
+ Puppet.err "Could not parse; using old configuration: %s" % detail
839
663
  end
840
- @parsedate = Time.now.to_i
841
664
  end
842
665
 
843
666
  # Store the configs into the database.
@@ -882,4 +705,4 @@ class Puppet::Parser::Interpreter
882
705
  end
883
706
  end
884
707
 
885
- # $Id: interpreter.rb 2720 2007-07-20 03:36:54Z luke $
708
+ # $Id: interpreter.rb 2742 2007-08-03 23:49:53Z luke $