puppet 0.25.0 → 0.25.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.

Files changed (138) hide show
  1. data/CHANGELOG +4772 -19114
  2. data/README +1 -1
  3. data/Rakefile +7 -25
  4. data/{sbin → bin}/puppetca +0 -0
  5. data/{sbin → bin}/puppetd +0 -0
  6. data/{sbin → bin}/puppetmasterd +0 -0
  7. data/{sbin → bin}/puppetqd +0 -0
  8. data/{sbin → bin}/puppetrun +0 -0
  9. data/conf/osx/createpackage.sh +1 -1
  10. data/conf/redhat/client.init +6 -3
  11. data/conf/redhat/puppet.spec +26 -14
  12. data/conf/redhat/server.init +3 -2
  13. data/ext/vim/syntax/puppet.vim +4 -1
  14. data/install.rb +25 -7
  15. data/lib/puppet.rb +1 -1
  16. data/lib/puppet/agent.rb +2 -2
  17. data/lib/puppet/application/puppet.rb +3 -3
  18. data/lib/puppet/application/puppetd.rb +0 -7
  19. data/lib/puppet/application/puppetdoc.rb +1 -0
  20. data/lib/puppet/application/puppetmasterd.rb +2 -2
  21. data/lib/puppet/configurer.rb +6 -1
  22. data/lib/puppet/configurer/fact_handler.rb +2 -2
  23. data/lib/puppet/defaults.rb +2 -2
  24. data/lib/puppet/external/nagios/base.rb +4 -3
  25. data/lib/puppet/external/pson/common.rb +367 -0
  26. data/lib/puppet/external/pson/pure.rb +77 -0
  27. data/lib/puppet/external/pson/pure/generator.rb +429 -0
  28. data/lib/puppet/external/pson/pure/parser.rb +269 -0
  29. data/lib/puppet/external/pson/version.rb +8 -0
  30. data/lib/puppet/feature/pson.rb +6 -0
  31. data/lib/puppet/feature/rails.rb +1 -5
  32. data/lib/puppet/file_serving/configuration.rb +2 -2
  33. data/lib/puppet/indirector/certificate/rest.rb +6 -0
  34. data/lib/puppet/indirector/facts/facter.rb +1 -1
  35. data/lib/puppet/indirector/ldap.rb +1 -1
  36. data/lib/puppet/indirector/queue.rb +3 -3
  37. data/lib/puppet/indirector/rest.rb +1 -1
  38. data/lib/puppet/network/authstore.rb +34 -53
  39. data/lib/puppet/network/formats.rb +59 -9
  40. data/lib/puppet/network/http/mongrel/rest.rb +10 -9
  41. data/lib/puppet/network/http/webrick.rb +8 -1
  42. data/lib/puppet/network/http/webrick/rest.rb +2 -5
  43. data/lib/puppet/network/http_server/webrick.rb +1 -4
  44. data/lib/puppet/parser/ast/leaf.rb +1 -3
  45. data/lib/puppet/parser/collector.rb +14 -8
  46. data/lib/puppet/parser/compiler.rb +7 -0
  47. data/lib/puppet/parser/functions/fqdn_rand.rb +4 -10
  48. data/lib/puppet/parser/functions/regsubst.rb +44 -30
  49. data/lib/puppet/parser/functions/require.rb +18 -3
  50. data/lib/puppet/parser/functions/versioncmp.rb +1 -1
  51. data/lib/puppet/parser/interpreter.rb +1 -1
  52. data/lib/puppet/parser/lexer.rb +29 -31
  53. data/lib/puppet/parser/loaded_code.rb +4 -0
  54. data/lib/puppet/parser/parser_support.rb +5 -2
  55. data/lib/puppet/parser/resource.rb +31 -6
  56. data/lib/puppet/property.rb +3 -2
  57. data/lib/puppet/provider/macauthorization/macauthorization.rb +14 -14
  58. data/lib/puppet/provider/package/dpkg.rb +1 -1
  59. data/lib/puppet/provider/package/portage.rb +15 -5
  60. data/lib/puppet/provider/package/rug.rb +1 -1
  61. data/lib/puppet/provider/package/up2date.rb +1 -1
  62. data/lib/puppet/provider/package/urpmi.rb +1 -1
  63. data/lib/puppet/provider/service/daemontools.rb +7 -10
  64. data/lib/puppet/provider/service/runit.rb +7 -17
  65. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +7 -47
  66. data/lib/puppet/provider/zone/solaris.rb +12 -3
  67. data/lib/puppet/relationship.rb +12 -12
  68. data/lib/puppet/reports/rrdgraph.rb +1 -1
  69. data/lib/puppet/reports/store.rb +2 -2
  70. data/lib/puppet/reports/tagmail.rb +5 -16
  71. data/lib/puppet/resource.rb +15 -20
  72. data/lib/puppet/resource/catalog.rb +40 -29
  73. data/lib/puppet/ssl/certificate_revocation_list.rb +0 -2
  74. data/lib/puppet/ssl/host.rb +2 -3
  75. data/lib/puppet/sslcertificates/ca.rb +0 -5
  76. data/lib/puppet/type/cron.rb +1 -1
  77. data/lib/puppet/type/file/owner.rb +7 -4
  78. data/lib/puppet/type/resources.rb +17 -17
  79. data/lib/puppet/type/yumrepo.rb +10 -3
  80. data/lib/puppet/util.rb +6 -11
  81. data/lib/puppet/util/inifile.rb +8 -0
  82. data/lib/puppet/util/log.rb +2 -2
  83. data/lib/puppet/util/monkey_patches.rb +0 -43
  84. data/lib/puppet/util/{json.rb → pson.rb} +6 -6
  85. data/lib/puppet/util/rdoc.rb +5 -3
  86. data/lib/puppet/util/selinux.rb +12 -6
  87. data/lib/puppet/util/settings.rb +25 -16
  88. data/lib/puppet/util/settings/file_setting.rb +4 -2
  89. data/spec/integration/application/puppet.rb +4 -4
  90. data/spec/integration/defaults.rb +2 -2
  91. data/spec/integration/indirector/catalog/queue.rb +5 -5
  92. data/spec/integration/indirector/certificate/rest.rb +3 -1
  93. data/spec/integration/network/formats.rb +36 -36
  94. data/spec/integration/parser/functions/require.rb +5 -3
  95. data/spec/integration/provider/mailalias/aliases.rb +4 -4
  96. data/spec/integration/resource/catalog.rb +4 -4
  97. data/spec/unit/application/puppet.rb +16 -15
  98. data/spec/unit/application/puppetd.rb +1 -1
  99. data/spec/unit/application/puppetdoc.rb +6 -0
  100. data/spec/unit/application/puppetmasterd.rb +6 -6
  101. data/spec/unit/configurer/fact_handler.rb +3 -3
  102. data/spec/unit/file_serving/configuration.rb +16 -2
  103. data/spec/unit/indirector/certificate/rest.rb +34 -0
  104. data/spec/unit/indirector/queue.rb +15 -15
  105. data/spec/unit/indirector/rest.rb +31 -9
  106. data/spec/unit/network/authstore.rb +105 -26
  107. data/spec/unit/network/formats.rb +124 -39
  108. data/spec/unit/parser/ast/leaf.rb +15 -0
  109. data/spec/unit/parser/collector.rb +20 -9
  110. data/spec/unit/parser/compiler.rb +19 -0
  111. data/spec/unit/parser/functions/fqdn_rand.rb +62 -0
  112. data/spec/unit/parser/functions/regsubst.rb +80 -0
  113. data/spec/unit/parser/functions/require.rb +19 -7
  114. data/spec/unit/parser/interpreter.rb +2 -2
  115. data/spec/unit/parser/lexer.rb +32 -7
  116. data/spec/unit/parser/loaded_code.rb +18 -1
  117. data/spec/unit/parser/parser.rb +10 -2
  118. data/spec/unit/parser/resource.rb +53 -2
  119. data/spec/unit/parser/scope.rb +1 -1
  120. data/spec/unit/property.rb +14 -4
  121. data/spec/unit/provider/package/dpkg.rb +7 -0
  122. data/spec/unit/provider/service/daemontools.rb +19 -2
  123. data/spec/unit/provider/service/redhat.rb +2 -0
  124. data/spec/unit/provider/service/runit.rb +15 -4
  125. data/spec/unit/provider/ssh_authorized_key/parsed.rb +32 -55
  126. data/spec/unit/relationship.rb +21 -46
  127. data/spec/unit/resource.rb +30 -39
  128. data/spec/unit/resource/catalog.rb +66 -51
  129. data/spec/unit/ssl/certificate_revocation_list.rb +0 -12
  130. data/spec/unit/type/cron.rb +33 -0
  131. data/spec/unit/type/file/owner.rb +10 -4
  132. data/spec/unit/util/json.rb +9 -9
  133. data/spec/unit/util/log.rb +36 -0
  134. data/spec/unit/util/settings.rb +6 -0
  135. data/test/data/providers/ssh_authorized_key/parsed/authorized_keys2 +1 -0
  136. data/test/lib/puppettest/support/utils.rb +8 -16
  137. metadata +36 -13
  138. data/lib/puppet/feature/json.rb +0 -2
@@ -4,13 +4,13 @@ require File.dirname(__FILE__) + '/../../spec_helper'
4
4
 
5
5
  require 'puppet/network/formats'
6
6
 
7
- class JsonTest
7
+ class PsonTest
8
8
  attr_accessor :string
9
9
  def ==(other)
10
10
  string == other.string
11
11
  end
12
12
 
13
- def self.from_json(data)
13
+ def self.from_pson(data)
14
14
  new(data)
15
15
  end
16
16
 
@@ -18,11 +18,11 @@ class JsonTest
18
18
  @string = string
19
19
  end
20
20
 
21
- def to_json(*args)
21
+ def to_pson(*args)
22
22
  {
23
- 'json_class' => self.class.name,
23
+ 'type' => self.class.name,
24
24
  'data' => @string
25
- }.to_json(*args)
25
+ }.to_pson(*args)
26
26
  end
27
27
  end
28
28
 
@@ -90,6 +90,91 @@ describe "Puppet Network Format" do
90
90
  end
91
91
  end
92
92
 
93
+ describe "base64 compressed yaml" do
94
+ before do
95
+ @yaml = Puppet::Network::FormatHandler.format(:b64_zlib_yaml)
96
+ end
97
+
98
+ it "should have its mime type set to text/b64_zlib_yaml" do
99
+ @yaml.mime.should == "text/b64_zlib_yaml"
100
+ end
101
+
102
+ it "should render by calling 'to_yaml' on the instance" do
103
+ instance = mock 'instance'
104
+ instance.expects(:to_yaml).returns "foo"
105
+ @yaml.render(instance)
106
+ end
107
+
108
+ it "should fixup generated yaml on render" do
109
+ instance = mock 'instance', :to_yaml => "foo"
110
+
111
+ @yaml.expects(:fixup).with("foo").returns "bar"
112
+
113
+ @yaml.render(instance)
114
+ end
115
+
116
+ it "should encode generated yaml on render" do
117
+ instance = mock 'instance', :to_yaml => "foo"
118
+
119
+ @yaml.expects(:encode).with("foo").returns "bar"
120
+
121
+ @yaml.render(instance).should == "bar"
122
+ end
123
+
124
+ it "should render multiple instances by calling 'to_yaml' on the array" do
125
+ instances = [mock('instance')]
126
+ instances.expects(:to_yaml).returns "foo"
127
+ @yaml.render_multiple(instances)
128
+ end
129
+
130
+ it "should fixup generated yaml on render" do
131
+ instances = [mock('instance')]
132
+ instances.stubs(:to_yaml).returns "foo"
133
+
134
+ @yaml.expects(:fixup).with("foo").returns "bar"
135
+
136
+ @yaml.render(instances)
137
+ end
138
+
139
+ it "should encode generated yaml on render" do
140
+ instances = [mock('instance')]
141
+ instances.stubs(:to_yaml).returns "foo"
142
+
143
+ @yaml.expects(:encode).with("foo").returns "bar"
144
+
145
+ @yaml.render(instances).should == "bar"
146
+ end
147
+
148
+ it "should intern by calling decode" do
149
+ text = "foo"
150
+ @yaml.expects(:decode).with("foo").returns "bar"
151
+ @yaml.intern(String, text).should == "bar"
152
+ end
153
+
154
+ it "should intern multiples by calling 'decode'" do
155
+ text = "foo"
156
+ @yaml.expects(:decode).with("foo").returns "bar"
157
+ @yaml.intern_multiple(String, text).should == "bar"
158
+ end
159
+
160
+ it "should decode by base64 decoding, uncompressing and Yaml loading" do
161
+ Base64.expects(:decode64).with("zorg").returns "foo"
162
+ Zlib::Inflate.expects(:inflate).with("foo").returns "baz"
163
+ YAML.expects(:load).with("baz").returns "bar"
164
+ @yaml.decode("zorg").should == "bar"
165
+ end
166
+
167
+ it "should encode by compressing and base64 encoding" do
168
+ Zlib::Deflate.expects(:deflate).with("foo", Zlib::BEST_COMPRESSION).returns "bar"
169
+ Base64.expects(:encode64).with("bar").returns "baz"
170
+ @yaml.encode("foo").should == "baz"
171
+ end
172
+
173
+ it "should fixup incorrect yaml to correct" do
174
+ @yaml.fixup("&id004 !ruby/object:Puppet::Relationship ?").should == "? &id004 !ruby/object:Puppet::Relationship"
175
+ end
176
+ end
177
+
93
178
  it "should include a marshal format" do
94
179
  Puppet::Network::FormatHandler.format(:marshal).should_not be_nil
95
180
  end
@@ -173,76 +258,76 @@ describe "Puppet Network Format" do
173
258
  end
174
259
  end
175
260
 
176
- it "should include a json format" do
177
- Puppet::Network::FormatHandler.format(:json).should_not be_nil
261
+ it "should include a pson format" do
262
+ Puppet::Network::FormatHandler.format(:pson).should_not be_nil
178
263
  end
179
264
 
180
- describe "json" do
181
- confine "Missing 'json' library" => Puppet.features.json?
265
+ describe "pson" do
266
+ confine "Missing 'pson' library" => Puppet.features.pson?
182
267
 
183
268
  before do
184
- @json = Puppet::Network::FormatHandler.format(:json)
269
+ @pson = Puppet::Network::FormatHandler.format(:pson)
185
270
  end
186
271
 
187
- it "should have its mime type set to text/json" do
188
- Puppet::Network::FormatHandler.format(:json).mime.should == "text/json"
272
+ it "should have its mime type set to text/pson" do
273
+ Puppet::Network::FormatHandler.format(:pson).mime.should == "text/pson"
189
274
  end
190
275
 
191
276
  it "should require the :render_method" do
192
- Puppet::Network::FormatHandler.format(:json).required_methods.should be_include(:render_method)
277
+ Puppet::Network::FormatHandler.format(:pson).required_methods.should be_include(:render_method)
193
278
  end
194
279
 
195
280
  it "should require the :intern_method" do
196
- Puppet::Network::FormatHandler.format(:json).required_methods.should be_include(:intern_method)
281
+ Puppet::Network::FormatHandler.format(:pson).required_methods.should be_include(:intern_method)
197
282
  end
198
283
 
199
284
  it "should have a weight of 10" do
200
- @json.weight.should == 10
285
+ @pson.weight.should == 10
201
286
  end
202
287
 
203
288
  describe "when supported" do
204
- it "should render by calling 'to_json' on the instance" do
205
- instance = JsonTest.new("foo")
206
- instance.expects(:to_json).returns "foo"
207
- @json.render(instance).should == "foo"
289
+ it "should render by calling 'to_pson' on the instance" do
290
+ instance = PsonTest.new("foo")
291
+ instance.expects(:to_pson).returns "foo"
292
+ @pson.render(instance).should == "foo"
208
293
  end
209
294
 
210
- it "should render multiple instances by calling 'to_json' on the array" do
295
+ it "should render multiple instances by calling 'to_pson' on the array" do
211
296
  instances = [mock('instance')]
212
297
 
213
- instances.expects(:to_json).returns "foo"
298
+ instances.expects(:to_pson).returns "foo"
214
299
 
215
- @json.render_multiple(instances).should == "foo"
300
+ @pson.render_multiple(instances).should == "foo"
216
301
  end
217
302
 
218
- it "should intern by calling 'JSON.parse' on the text and then using from_json to convert the data into an instance" do
303
+ it "should intern by calling 'PSON.parse' on the text and then using from_pson to convert the data into an instance" do
219
304
  text = "foo"
220
- JSON.expects(:parse).with("foo").returns("json_class" => "JsonTest", "data" => "foo")
221
- JsonTest.expects(:from_json).with("foo").returns "parsed_json"
222
- @json.intern(JsonTest, text).should == "parsed_json"
305
+ PSON.expects(:parse).with("foo").returns("type" => "PsonTest", "data" => "foo")
306
+ PsonTest.expects(:from_pson).with("foo").returns "parsed_pson"
307
+ @pson.intern(PsonTest, text).should == "parsed_pson"
223
308
  end
224
309
 
225
- it "should not render twice if 'JSON.parse' creates the appropriate instance" do
310
+ it "should not render twice if 'PSON.parse' creates the appropriate instance" do
226
311
  text = "foo"
227
- instance = JsonTest.new("foo")
228
- JSON.expects(:parse).with("foo").returns(instance)
229
- JsonTest.expects(:from_json).never
230
- @json.intern(JsonTest, text).should equal(instance)
312
+ instance = PsonTest.new("foo")
313
+ PSON.expects(:parse).with("foo").returns(instance)
314
+ PsonTest.expects(:from_pson).never
315
+ @pson.intern(PsonTest, text).should equal(instance)
231
316
  end
232
317
 
233
- it "should intern by calling 'JSON.parse' on the text and then using from_json to convert the actual into an instance if the json has no class/data separation" do
318
+ it "should intern by calling 'PSON.parse' on the text and then using from_pson to convert the actual into an instance if the pson has no class/data separation" do
234
319
  text = "foo"
235
- JSON.expects(:parse).with("foo").returns("foo")
236
- JsonTest.expects(:from_json).with("foo").returns "parsed_json"
237
- @json.intern(JsonTest, text).should == "parsed_json"
320
+ PSON.expects(:parse).with("foo").returns("foo")
321
+ PsonTest.expects(:from_pson).with("foo").returns "parsed_pson"
322
+ @pson.intern(PsonTest, text).should == "parsed_pson"
238
323
  end
239
324
 
240
325
  it "should intern multiples by parsing the text and using 'class.intern' on each resulting data structure" do
241
326
  text = "foo"
242
- JSON.expects(:parse).with("foo").returns ["bar", "baz"]
243
- JsonTest.expects(:from_json).with("bar").returns "BAR"
244
- JsonTest.expects(:from_json).with("baz").returns "BAZ"
245
- @json.intern_multiple(JsonTest, text).should == %w{BAR BAZ}
327
+ PSON.expects(:parse).with("foo").returns ["bar", "baz"]
328
+ PsonTest.expects(:from_pson).with("bar").returns "BAR"
329
+ PsonTest.expects(:from_pson).with("baz").returns "BAZ"
330
+ @pson.intern_multiple(PsonTest, text).should == %w{BAR BAZ}
246
331
  end
247
332
  end
248
333
  end
@@ -195,11 +195,26 @@ describe Puppet::Parser::AST::HostName do
195
195
  host.to_classname.should == "klassname"
196
196
  end
197
197
 
198
+ it "should preserve '_' in to_classname with a string nodename" do
199
+ host = Puppet::Parser::AST::HostName.new( :value => "node_with_underscore")
200
+ host.to_classname.should == "node_with_underscore"
201
+ end
202
+
203
+ it "should preserve '_' in to_classname with a regex nodename" do
204
+ host = Puppet::Parser::AST::HostName.new( :value => Puppet::Parser::AST::Regex.new(:value => "/\dnode_with_underscore\.+/") )
205
+ host.to_classname.should == "dnode_with_underscore."
206
+ end
207
+
198
208
  it "should return a string usable as classname when calling to_classname" do
199
209
  host = Puppet::Parser::AST::HostName.new( :value => Puppet::Parser::AST::Regex.new(:value => "/^this-is not@a classname$/") )
200
210
  host.to_classname.should == "this-isnotaclassname"
201
211
  end
202
212
 
213
+ it "should return a string usable as a tag when calling to_classname" do
214
+ host = Puppet::Parser::AST::HostName.new( :value => Puppet::Parser::AST::Regex.new(:value => "/.+.reductivelabs\.com/") )
215
+ host.to_classname.should == "reductivelabs.com"
216
+ end
217
+
203
218
  it "should delegate 'match' to the underlying value if it is an HostName" do
204
219
  @value.expects(:match).with("value")
205
220
  @host.match("value")
@@ -498,35 +498,46 @@ describe Puppet::Parser::Collector, "when building its ActiveRecord query for co
498
498
  Puppet::Rails::Host.expects(:find_by_name).with(@scope.host).returns(@host)
499
499
 
500
500
  Puppet::Rails::Resource.stubs(:find).with { |*arguments|
501
- options = arguments[3]
501
+ options = arguments[1]
502
502
  options[:conditions][0] =~ /^host_id != \?/ and options[:conditions][1] == 5
503
503
  }.returns([@resource])
504
504
 
505
505
  @collector.evaluate.should == [@resource]
506
506
  end
507
507
 
508
- it "should return parameter names, parameter values when querying ActiveRecord" do
508
+ it "should join with parameter names, parameter values when querying ActiveRecord" do
509
+ @collector.equery = "param_names.name = title"
509
510
  Puppet::Rails::Resource.stubs(:find).with { |*arguments|
510
- options = arguments[3]
511
- options[:include] == {:param_values => :param_name}
511
+ options = arguments[1]
512
+ options[:joins] == {:param_values => :param_name}
512
513
  }.returns([@resource])
513
514
 
514
515
  @collector.evaluate.should == [@resource]
515
516
  end
516
517
 
517
- it "should return tags when querying ActiveRecord with a tag exported query" do
518
+ it "should join with tag tables when querying ActiveRecord with a tag exported query" do
518
519
  @collector.equery = "puppet_tags.name = test"
519
520
  Puppet::Rails::Resource.stubs(:find).with { |*arguments|
520
- options = arguments[3]
521
- options[:include] == {:param_values => :param_name, :puppet_tags => :resource_tags}
521
+ options = arguments[1]
522
+ options[:joins] == {:resource_tags => :puppet_tag}
522
523
  }.returns([@resource])
523
524
 
524
525
  @collector.evaluate.should == [@resource]
525
526
  end
526
527
 
528
+ it "should not join parameters when querying ActiveRecord with a tag exported query" do
529
+ @collector.equery = "puppet_tags.name = test"
530
+ Puppet::Rails::Resource.stubs(:find).with { |*arguments|
531
+ options = arguments[1]
532
+ options[:joins] == {:param_values => :param_name}
533
+ }.returns([@resource])
534
+
535
+ @collector.evaluate.should be_false
536
+ end
537
+
527
538
  it "should only search for exported resources with the matching type" do
528
539
  Puppet::Rails::Resource.stubs(:find).with { |*arguments|
529
- options = arguments[3]
540
+ options = arguments[1]
530
541
  options[:conditions][0].include?("(exported=? AND restype=?)") and options[:conditions][1] == true and options[:conditions][2] == "Mytype"
531
542
  }.returns([@resource])
532
543
 
@@ -536,7 +547,7 @@ describe Puppet::Parser::Collector, "when building its ActiveRecord query for co
536
547
  it "should include the export query if one is provided" do
537
548
  @collector.equery = "test = true"
538
549
  Puppet::Rails::Resource.stubs(:find).with { |*arguments|
539
- options = arguments[3]
550
+ options = arguments[1]
540
551
  options[:conditions][0].include?("test = true")
541
552
  }.returns([@resource])
542
553
 
@@ -86,6 +86,16 @@ describe Puppet::Parser::Compiler do
86
86
  it "should copy the parser version to the catalog" do
87
87
  @compiler.catalog.version.should == @parser.version
88
88
  end
89
+
90
+ it "should copy any node classes into the class list" do
91
+ node = Puppet::Node.new("mynode")
92
+ node.classes = %w{foo bar}
93
+ compiler = Puppet::Parser::Compiler.new(node, @parser)
94
+ p compiler.classlist
95
+
96
+ compiler.classlist.should include("foo")
97
+ compiler.classlist.should include("bar")
98
+ end
89
99
  end
90
100
 
91
101
  describe "when managing scopes" do
@@ -131,6 +141,15 @@ describe Puppet::Parser::Compiler do
131
141
  @compiler.topscope.lookupvar("c").should == "d"
132
142
  end
133
143
 
144
+ it "should set the client and server versions on the catalog" do
145
+ params = {"clientversion" => "2", "serverversion" => "3"}
146
+ @node.stubs(:parameters).returns(params)
147
+ compile_stub(:set_node_parameters)
148
+ @compiler.compile
149
+ @compiler.catalog.client_version.should == "2"
150
+ @compiler.catalog.server_version.should == "3"
151
+ end
152
+
134
153
  it "should evaluate any existing classes named in the node" do
135
154
  classes = %w{one two three four}
136
155
  main = stub 'main'
@@ -0,0 +1,62 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../../../spec_helper'
4
+
5
+ describe "the fqdn_rand function" do
6
+
7
+ before :each do
8
+ @scope = Puppet::Parser::Scope.new()
9
+ end
10
+
11
+ it "should exist" do
12
+ Puppet::Parser::Functions.function("fqdn_rand").should == "function_fqdn_rand"
13
+ end
14
+
15
+ it "should handle 0 arguments" do
16
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
17
+ lambda { @scope.function_fqdn_rand([]) }.should_not raise_error(Puppet::ParseError)
18
+ end
19
+
20
+ it "should handle 1 argument'}" do
21
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
22
+ lambda { @scope.function_fqdn_rand([3]) }.should_not raise_error(Puppet::ParseError)
23
+ end
24
+
25
+
26
+ (1..10).each { |n|
27
+ it "should handle #{n} additional arguments" do
28
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
29
+ lambda { @scope.function_fqdn_rand([3,1,2,3,4,5,6,7,8,9,10][0..n]) }.should_not raise_error(Puppet::ParseError)
30
+ end
31
+ it "should handle #{n} additional string arguments" do
32
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
33
+ lambda { @scope.function_fqdn_rand([3,%w{ 1 2 3 4 5 6 7 8 9 10}].flatten[0..n]) }.should_not raise_error(Puppet::ParseError)
34
+ end
35
+ }
36
+
37
+ it "should return a value less than max" do
38
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
39
+ @scope.function_fqdn_rand([3]).should satisfy {|n| n.to_i < 3 }
40
+ end
41
+
42
+ it "should return the same values on subsequent invocations for the same host" do
43
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1").twice
44
+ @scope.function_fqdn_rand([3,4]).should eql(@scope.function_fqdn_rand([3, 4]))
45
+ end
46
+
47
+ it "should return different sequences of value for different hosts" do
48
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
49
+ val1 = @scope.function_fqdn_rand([10000000,4])
50
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.2")
51
+ val2 = @scope.function_fqdn_rand([10000000,4])
52
+ val1.should_not eql(val2)
53
+ end
54
+
55
+ it "should return different values for the same hosts with different seeds" do
56
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
57
+ val1 = @scope.function_fqdn_rand([10000000,4])
58
+ @scope.expects(:lookupvar).with("fqdn").returns("127.0.0.1")
59
+ val2 = @scope.function_fqdn_rand([10000000,42])
60
+ val1.should_not eql(val2)
61
+ end
62
+ end
@@ -28,6 +28,26 @@ describe "the regsubst function" do
28
28
  raise_error(Puppet::ParseError))
29
29
  end
30
30
 
31
+ it "should raise a ParseError for non-string and non-array target" do
32
+ lambda { @scope.function_regsubst([4711, "bar", "gazonk"]) }.should(
33
+ raise_error(Puppet::ParseError))
34
+ end
35
+
36
+ it "should raise a ParseError for array target with non-string element" do
37
+ lambda { @scope.function_regsubst([["x", ["y"], "z"], "bar", "gazonk"]) }.should(
38
+ raise_error(Puppet::ParseError))
39
+ end
40
+
41
+ it "should raise a ParseError for a bad regular expression" do
42
+ lambda { @scope.function_regsubst(["foo", "(bar", "gazonk"]) }.should(
43
+ raise_error(Puppet::ParseError))
44
+ end
45
+
46
+ it "should raise a ParseError for a non-string regular expression" do
47
+ lambda { @scope.function_regsubst(["foo", ["bar"], "gazonk"]) }.should(
48
+ raise_error(Puppet::ParseError))
49
+ end
50
+
31
51
  it "should handle groups" do
32
52
  result = @scope.function_regsubst(
33
53
  [ '130.236.254.10',
@@ -85,4 +105,64 @@ describe "the regsubst function" do
85
105
  result.should(eql('<130>.<236>.<254>.<10>'))
86
106
  end
87
107
 
108
+ it "should apply on all elements of an array" do
109
+ data = ['130.236.254.10', 'foo.example.com', 'coconut', '10.20.30.40']
110
+ result = @scope.function_regsubst([ data, '[.]', '-'])
111
+ result.should(eql(
112
+ ['130-236.254.10', 'foo-example.com', 'coconut', '10-20.30.40']))
113
+ end
114
+
115
+ it "should apply global substitutions on all elements of an array" do
116
+ data = ['130.236.254.10', 'foo.example.com', 'coconut', '10.20.30.40']
117
+ result = @scope.function_regsubst([ data, '[.]', '-', 'G'])
118
+ result.should(eql(
119
+ ['130-236-254-10', 'foo-example-com', 'coconut', '10-20-30-40']))
120
+ end
121
+
122
+ it "should handle groups on all elements of an array" do
123
+ data = ['130.236.254.10', 'foo.example.com', 'coconut', '10.20.30.40']
124
+ result = @scope.function_regsubst(
125
+ [ data,
126
+ '^([0-9]+)[.]([0-9]+)[.]([0-9]+)[.]([0-9]+)$',
127
+ '\4-\3-\2-\1'
128
+ ])
129
+ result.should(eql(
130
+ ['10-254-236-130', 'foo.example.com', 'coconut', '40-30-20-10']))
131
+ end
132
+
133
+ it "should handle global substitutions with groups on all elements of an array" do
134
+ data = ['130.236.254.10', 'foo.example.com', 'coconut', '10.20.30.40']
135
+ result = @scope.function_regsubst(
136
+ [ data,
137
+ '([^.]+)',
138
+ '<\1>',
139
+ 'G'
140
+ ])
141
+ result.should(eql(
142
+ ['<130>.<236>.<254>.<10>', '<foo>.<example>.<com>',
143
+ '<coconut>', '<10>.<20>.<30>.<40>']))
144
+ end
145
+
146
+ it "should return an array (not a string) for a single element array parameter" do
147
+ data = ['130.236.254.10']
148
+ result = @scope.function_regsubst(
149
+ [ data,
150
+ '([^.]+)',
151
+ '<\1>',
152
+ 'G'
153
+ ])
154
+ result.should(eql(['<130>.<236>.<254>.<10>']))
155
+ end
156
+
157
+ it "should return a string (not a one element array) for a simple string parameter" do
158
+ data = '130.236.254.10'
159
+ result = @scope.function_regsubst(
160
+ [ data,
161
+ '([^.]+)',
162
+ '<\1>',
163
+ 'G'
164
+ ])
165
+ result.should(eql('<130>.<236>.<254>.<10>'))
166
+ end
167
+
88
168
  end