puppet 0.13.1 → 0.13.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 (44) hide show
  1. data/CHANGELOG +4 -0
  2. data/Rakefile +2 -2
  3. data/bin/puppet +29 -0
  4. data/bin/puppetd +35 -1
  5. data/conf/redhat/puppet.spec +1 -1
  6. data/lib/puppet.rb +1 -1
  7. data/lib/puppet/client/master.rb +34 -3
  8. data/lib/puppet/filetype.rb +6 -2
  9. data/lib/puppet/networkclient.rb +4 -1
  10. data/lib/puppet/parameter.rb +35 -38
  11. data/lib/puppet/parser/ast/node.rb +1 -0
  12. data/lib/puppet/parser/interpreter.rb +129 -2
  13. data/lib/puppet/parser/scope.rb +44 -6
  14. data/lib/puppet/type.rb +47 -37
  15. data/lib/puppet/type/cron.rb +25 -10
  16. data/lib/puppet/type/exec.rb +165 -71
  17. data/lib/puppet/type/nameservice.rb +2 -17
  18. data/lib/puppet/type/package.rb +31 -7
  19. data/lib/puppet/type/package/sun.rb +11 -6
  20. data/lib/puppet/type/parsedtype.rb +94 -60
  21. data/lib/puppet/type/parsedtype/host.rb +5 -12
  22. data/lib/puppet/type/parsedtype/port.rb +53 -32
  23. data/lib/puppet/type/parsedtype/sshkey.rb +8 -4
  24. data/lib/puppet/type/pfile.rb +6 -4
  25. data/lib/puppet/type/pfile/ensure.rb +1 -6
  26. data/lib/puppet/type/state.rb +34 -74
  27. data/lib/puppet/type/symlink.rb +30 -19
  28. data/lib/puppet/type/user.rb +63 -11
  29. data/lib/puppet/util.rb +54 -60
  30. data/test/client/master.rb +72 -0
  31. data/test/language/interpreter.rb +94 -0
  32. data/test/other/log.rb +8 -1
  33. data/test/puppet/utiltest.rb +101 -1
  34. data/test/test +12 -5
  35. data/test/types/cron.rb +21 -1
  36. data/test/types/exec.rb +46 -2
  37. data/test/types/group.rb +15 -3
  38. data/test/types/host.rb +43 -4
  39. data/test/types/port.rb +67 -6
  40. data/test/types/sshkey.rb +45 -4
  41. data/test/types/symlink.rb +4 -4
  42. data/test/types/type.rb +41 -3
  43. data/test/types/user.rb +23 -2
  44. metadata +3 -2
@@ -27,7 +27,11 @@ module Puppet
27
27
  # We actually want to return the whole array here, not just the first
28
28
  # value.
29
29
  def should
30
- @should
30
+ if defined? @should
31
+ return @should
32
+ else
33
+ return nil
34
+ end
31
35
  end
32
36
 
33
37
  validate do |value|
@@ -119,11 +123,11 @@ module Puppet
119
123
  def to_record
120
124
  name = self[:name]
121
125
  if @states.include?(:alias)
122
- name += "," + @states[:alias].should.join(",")
126
+ name += "," + @states[:alias].value.join(",")
123
127
  end
124
- [name, @states[:type].should, @states[:key].should].join(" ")
128
+ [name, @states[:type].value, @states[:key].value].join(" ")
125
129
  end
126
130
  end
127
131
  end
128
132
 
129
- # $Id: sshkey.rb 831 2006-01-16 20:01:20Z luke $
133
+ # $Id: sshkey.rb 910 2006-02-15 07:20:36Z luke $
@@ -98,7 +98,7 @@ module Puppet
98
98
  cur = []
99
99
  # Skip the nil in the beginning and don't add ourselves as a prereq
100
100
  # either.
101
- self.name.split(File::SEPARATOR)[1..-2].collect { |dir|
101
+ self[:path].split(File::SEPARATOR)[1..-2].collect { |dir|
102
102
  cur << dir
103
103
  "/" + cur.join(File::SEPARATOR)
104
104
  }
@@ -248,7 +248,7 @@ module Puppet
248
248
  # clean up the args a lot for links
249
249
  old = args.dup
250
250
  args = {
251
- :target => old[:source],
251
+ :ensure => old[:source],
252
252
  :path => path
253
253
  }
254
254
  else
@@ -440,9 +440,11 @@ module Puppet
440
440
  end
441
441
  end
442
442
 
443
+ #ignore = self[:ignore] || false
443
444
  ignore = self[:ignore]
444
445
 
445
- #self.warning "Listing path %s" % path.inspect
446
+ #self.warning "Listing path %s with ignore %s" %
447
+ # [path.inspect, ignore.inspect]
446
448
  desc = server.list(path, r, ignore)
447
449
 
448
450
  desc.split("\n").each { |line|
@@ -596,4 +598,4 @@ module Puppet
596
598
  require 'puppet/type/pfile/mode'
597
599
  require 'puppet/type/pfile/type'
598
600
  end
599
- # $Id: pfile.rb 896 2006-02-10 22:00:30Z luke $
601
+ # $Id: pfile.rb 915 2006-02-15 21:56:54Z luke $
@@ -12,11 +12,6 @@ module Puppet
12
12
  # Most 'ensure' states have a default, but with files we, um, don't.
13
13
  nodefault
14
14
 
15
- #newvalue(:false) do
16
- # # If they say "false" here, we just don't do anything at all; either
17
- # # the file is there or it's not.
18
- #end
19
-
20
15
  newvalue(:absent) do
21
16
  File.unlink(@parent.name)
22
17
  end
@@ -209,4 +204,4 @@ module Puppet
209
204
  end
210
205
  end
211
206
 
212
- # $Id: ensure.rb 885 2006-02-08 17:44:44Z luke $
207
+ # $Id: ensure.rb 912 2006-02-15 18:23:33Z luke $
@@ -39,42 +39,6 @@ class State < Puppet::Parameter
39
39
 
40
40
  define_method("set_" + name.to_s, &block)
41
41
  end
42
- #
43
- # def self.aliasvalue(name, other)
44
- # @statevalues ||= {}
45
- # unless @statevalues.include?(other)
46
- # raise Puppet::DevError, "Cannot alias nonexistent value %s" % other
47
- # end
48
- #
49
- # @aliasvalues ||= {}
50
- # @aliasvalues[name] = other
51
- # end
52
- #
53
- # def self.alias(name)
54
- # @aliasvalues[name]
55
- # end
56
- #
57
- def self.defaultvalues
58
- newvalue(:present) do
59
- @parent.create
60
- end
61
-
62
- newvalue(:absent) do
63
- @parent.destroy
64
- end
65
-
66
- # This doc will probably get overridden
67
- @doc ||= "The basic state that the object should be in."
68
- end
69
- #
70
- # # Return the list of valid values.
71
- # def self.values
72
- # @statevalues ||= {}
73
- # @aliasvalues ||= {}
74
- #
75
- # #[@aliasvalues.keys, @statevalues.keys].flatten
76
- # @statevalues.keys
77
- # end
78
42
 
79
43
  # Call the method associated with a given value.
80
44
  def set
@@ -278,46 +242,13 @@ class State < Puppet::Parameter
278
242
  self.set
279
243
  end
280
244
 
281
- # munge do |value|
282
- # if self.class.values.empty?
283
- # # This state isn't using defined values to do its work.
284
- # return value
285
- # end
286
- # intern = value.to_s.intern
287
- # # If it's a valid value, always return it as a symbol.
288
- # if self.class.values.include?(intern)
289
- # retval = intern
290
- # elsif other = self.class.alias(intern)
291
- # self.info "returning alias %s for %s" % [other, intern]
292
- # retval = other
293
- # else
294
- # retval = value
295
- # end
296
- # retval
297
- # end
298
- #
299
- # # Verify that the passed value is valid.
300
- # validate do |value|
301
- # if self.class.values.empty?
302
- # # This state isn't using defined values to do its work.
303
- # return
304
- # end
305
- # unless value.is_a?(Symbol)
306
- # value = value.to_s.intern
307
- # end
308
- # unless self.class.values.include?(value) or self.class.alias(value)
309
- # self.fail "Invalid '%s' value '%s'. Valid values are '%s'" %
310
- # [self.class.name, value, self.class.values.join(", ")]
311
- # end
312
- # end
313
-
314
245
  # How should a state change be printed as a string?
315
246
  def change_to_s
316
247
  begin
317
248
  if @is == :absent
318
249
  return "defined '%s' as '%s'" %
319
250
  [self.name, self.should_to_s]
320
- elsif self.should == :absent
251
+ elsif self.should == :absent or self.should == [:absent]
321
252
  return "undefined %s from '%s'" %
322
253
  [self.name, self.is_to_s]
323
254
  else
@@ -341,7 +272,11 @@ class State < Puppet::Parameter
341
272
  end
342
273
 
343
274
  def should_to_s
344
- @should.join(" ")
275
+ if defined? @should
276
+ @should.join(" ")
277
+ else
278
+ return nil
279
+ end
345
280
  end
346
281
 
347
282
  def to_s
@@ -349,10 +284,23 @@ class State < Puppet::Parameter
349
284
  end
350
285
 
351
286
  # This state will get automatically added to any type that responds
352
- # to the methods 'exists?', 'create', and 'remove'.
287
+ # to the methods 'exists?', 'create', and 'destroy'.
353
288
  class Ensure < Puppet::State
354
289
  @name = :ensure
355
290
 
291
+ def self.defaultvalues
292
+ newvalue(:present) do
293
+ @parent.create
294
+ end
295
+
296
+ newvalue(:absent) do
297
+ @parent.destroy
298
+ end
299
+
300
+ # This doc will probably get overridden
301
+ @doc ||= "The basic state that the object should be in."
302
+ end
303
+
356
304
  def self.inherited(sub)
357
305
  # Add in the two states that everyone will have.
358
306
  sub.class_eval do
@@ -378,6 +326,11 @@ class State < Puppet::Parameter
378
326
  end
379
327
 
380
328
  def retrieve
329
+ # XXX This is a problem -- whether the object exists or not often
330
+ # depends on the results of other states, yet we're the first state
331
+ # to get checked, which means that those other states do not have
332
+ # @is values set. This seems to be the source of quite a few bugs,
333
+ # although they're mostly logging bugs, not functional ones.
381
334
  if @parent.exists?
382
335
  @is = :present
383
336
  else
@@ -387,9 +340,16 @@ class State < Puppet::Parameter
387
340
 
388
341
  # If they're talking about the thing at all, they generally want to
389
342
  # say it should exist.
390
- defaultto :present
343
+ #defaultto :present
344
+ defaultto do
345
+ if @parent.managed?
346
+ :present
347
+ else
348
+ nil
349
+ end
350
+ end
391
351
  end
392
352
  end
393
353
  end
394
354
 
395
- # $Id: state.rb 883 2006-02-08 16:53:34Z luke $
355
+ # $Id: state.rb 912 2006-02-15 18:23:33Z luke $
@@ -5,20 +5,26 @@ require 'puppet/type/pfile'
5
5
  module Puppet
6
6
  newtype(:symlink) do
7
7
  @doc = "Create symbolic links to existing files."
8
- newstate(:target) do
8
+ #newstate(:ensure) do
9
+ ensurable do
9
10
  require 'etc'
10
11
  attr_accessor :file
11
12
 
12
- @doc = "Create a link to another file. Currently only symlinks
13
+ desc "Create a link to another file. Currently only symlinks
13
14
  are supported, and attempts to replace normal files with
14
15
  links will currently fail, while existing but incorrect symlinks
15
16
  will be removed."
16
- @name = :target
17
+
18
+ validate do |value|
19
+ unless value == :absent or value =~ /^#{File::SEPARATOR}/
20
+ raise Puppet::Error, "Invalid symlink %s" % value
21
+ end
22
+ end
23
+
24
+ nodefault
17
25
 
18
26
  def create
19
27
  begin
20
- @parent.debug("Creating symlink '%s' to '%s'" %
21
- [self.parent[:path],self.should])
22
28
  unless File.symlink(self.should,self.parent[:path])
23
29
  self.fail "Could not create symlink '%s'" %
24
30
  self.parent[:path]
@@ -31,7 +37,6 @@ module Puppet
31
37
 
32
38
  def remove
33
39
  if FileTest.symlink?(self.parent[:path])
34
- debug("Removing symlink '%s'" % self.parent[:path])
35
40
  begin
36
41
  File.unlink(self.parent[:path])
37
42
  rescue
@@ -52,10 +57,9 @@ module Puppet
52
57
 
53
58
  if FileTest.symlink?(self.parent[:path])
54
59
  self.is = File.readlink(self.parent[:path])
55
- debug("link value is '%s'" % self.is)
56
60
  return
57
61
  else
58
- self.is = nil
62
+ self.is = :absent
59
63
  return
60
64
  end
61
65
  end
@@ -63,28 +67,36 @@ module Puppet
63
67
  # this is somewhat complicated, because it could exist and be
64
68
  # a file
65
69
  def sync
66
- if self.should.nil?
70
+ case self.should
71
+ when :absent
67
72
  self.remove()
68
- else # it should exist and be a symlink
73
+ return :symlink_removed
74
+ when /^#{File::SEPARATOR}/
69
75
  if FileTest.symlink?(self.parent[:path])
70
76
  path = File.readlink(self.parent[:path])
71
77
  if path != self.should
72
78
  self.remove()
73
79
  self.create()
80
+ return :symlink_changed
81
+ else
82
+ self.info "Already in sync"
83
+ return nil
74
84
  end
75
85
  elsif FileTest.exists?(self.parent[:path])
76
86
  self.fail "Cannot replace normal file '%s'" %
77
87
  self.parent[:path]
78
88
  else
79
89
  self.create()
90
+ return :symlink_created
80
91
  end
92
+ else
93
+ raise Puppet::DevError, "Got invalid symlink value %s" %
94
+ self.should
81
95
  end
82
-
83
- #self.parent.newevent(:event => :inode_changed)
84
96
  end
85
97
  end
86
98
 
87
- attr_reader :stat, :path, :params
99
+ attr_reader :stat, :params
88
100
 
89
101
  copyparam(Puppet.type(:file), :path)
90
102
 
@@ -96,7 +108,7 @@ module Puppet
96
108
  # The Solaris Blastwave repository installs everything
97
109
  # in /opt/csw; link it into /usr/local
98
110
  symlink { \"/usr/local\":
99
- target => \"/opt/csw\",
111
+ ensure => \"/opt/csw\",
100
112
  recurse => 1
101
113
  }
102
114
 
@@ -106,7 +118,7 @@ module Puppet
106
118
 
107
119
  munge do |value|
108
120
  @stat = nil
109
- @target = @parent.state(:target).should
121
+ @target = @parent.state(:ensure).should
110
122
 
111
123
  # we want to remove our state, because we're creating children
112
124
  # to do the links
@@ -124,7 +136,7 @@ module Puppet
124
136
  return
125
137
  end
126
138
 
127
- @parent.delete(:target)
139
+ @parent.delete(:ensure)
128
140
 
129
141
  recurse = value
130
142
  # we might have a string, rather than a number
@@ -147,7 +159,7 @@ module Puppet
147
159
  # working in pfile
148
160
 
149
161
  args = {
150
- :name => @parent.name,
162
+ :path => @parent.name,
151
163
  :linkmaker => true,
152
164
  :recurse => recurse,
153
165
  :source => @target
@@ -155,7 +167,6 @@ module Puppet
155
167
 
156
168
  dir = Puppet.type(:file).implicitcreate(args)
157
169
  dir.parent = @parent
158
- @parent.debug "Got dir %s" % dir.name
159
170
  @parent.push dir
160
171
  end
161
172
  end
@@ -168,4 +179,4 @@ module Puppet
168
179
  end # Puppet.type(:symlink)
169
180
  end
170
181
 
171
- # $Id: symlink.rb 841 2006-01-18 17:24:15Z luke $
182
+ # $Id: symlink.rb 903 2006-02-13 21:46:29Z luke $
@@ -82,19 +82,30 @@ module Puppet
82
82
  return gid
83
83
  end
84
84
 
85
- # FIXME this should really check to see if we already have a
86
- # group ready to be managed; if so, then we should just mark it
87
- # as a prereq
88
- begin
89
- ginfo = Etc.send(method, gid)
90
- rescue ArgumentError => detail
91
- self.fail "Could not find group %s: %s" %
92
- [gid, detail]
85
+ if group = Puppet::Util.gid(gid)
86
+ @found = true
87
+ return group
88
+ else
89
+ @found = false
90
+ return gid
93
91
  end
92
+ end
94
93
 
95
- self.notice "setting gid to %s" % ginfo.gid.inspect
96
- return ginfo.gid
94
+ # *shudder* Make sure that we've looked up the group and gotten
95
+ # an ID for it. Yuck-o.
96
+ def should
97
+ unless defined? @should
98
+ return super
99
+ end
100
+ unless defined? @found and @found
101
+ @should = @should.each { |val|
102
+ next unless val
103
+ Puppet::Util.gid(val)
104
+ }
105
+ end
106
+ super
97
107
  end
108
+
98
109
  end
99
110
 
100
111
  newstate(:comment, @parentstate) do
@@ -167,6 +178,47 @@ module Puppet
167
178
 
168
179
  @netinfodir = "users"
169
180
 
181
+ # Autorequire the group, if it's around
182
+ autorequire(:group) do
183
+ #return nil unless @states.include?(:gid)
184
+ #return nil unless groups = @states[:gid].shouldorig
185
+ autos = []
186
+
187
+ if @states.include?(:gid) and groups = @states[:gid].shouldorig
188
+ groups = groups.collect { |group|
189
+ if group =~ /^\d+$/
190
+ Integer(group)
191
+ else
192
+ group
193
+ end
194
+ }
195
+ groups.each { |group|
196
+ case group
197
+ when Integer:
198
+ if obj = Puppet.type(:group).find { |gobj|
199
+ gobj.should(:gid) == group
200
+ }
201
+ autos << obj
202
+
203
+ end
204
+ else
205
+ autos << group
206
+ end
207
+ }
208
+ end
209
+
210
+ autos
211
+ end
212
+
213
+ autorequire(:file) do
214
+ dir = self.should(:home) or self.is(:home)
215
+ if dir =~ /^#{File::SEPARATOR}/
216
+ dir
217
+ else
218
+ nil
219
+ end
220
+ end
221
+
170
222
  def exists?
171
223
  self.class.parentmodule.exists?(self)
172
224
  end
@@ -225,4 +277,4 @@ module Puppet
225
277
  end
226
278
  end
227
279
 
228
- # $Id: user.rb 841 2006-01-18 17:24:15Z luke $
280
+ # $Id: user.rb 912 2006-02-15 18:23:33Z luke $