puppet 2.6.2 → 2.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. data/CHANGELOG +61 -0
  2. data/ext/envpuppet +80 -0
  3. data/ext/puppet-load.rb +62 -26
  4. data/ext/puppetstoredconfigclean.rb +0 -2
  5. data/lib/puppet.rb +1 -1
  6. data/lib/puppet/daemon.rb +2 -2
  7. data/lib/puppet/defaults.rb +10 -8
  8. data/lib/puppet/external/pson/pure/generator.rb +5 -12
  9. data/lib/puppet/indirector/catalog/compiler.rb +8 -4
  10. data/lib/puppet/network/handler/fileserver.rb +2 -0
  11. data/lib/puppet/network/server.rb +2 -2
  12. data/lib/puppet/node/environment.rb +4 -0
  13. data/lib/puppet/parser/ast/collection.rb +34 -51
  14. data/lib/puppet/parser/ast/leaf.rb +10 -2
  15. data/lib/puppet/parser/ast/resource.rb +4 -3
  16. data/lib/puppet/parser/compiler.rb +2 -2
  17. data/lib/puppet/parser/functions.rb +4 -2
  18. data/lib/puppet/parser/lexer.rb +2 -1
  19. data/lib/puppet/parser/parser_support.rb +3 -3
  20. data/lib/puppet/provider.rb +2 -2
  21. data/lib/puppet/provider/confine/exists.rb +1 -4
  22. data/lib/puppet/provider/mount.rb +1 -1
  23. data/lib/puppet/provider/nameservice.rb +3 -1
  24. data/lib/puppet/provider/package/openbsd.rb +6 -10
  25. data/lib/puppet/provider/service/freebsd.rb +4 -1
  26. data/lib/puppet/provider/service/launchd.rb +1 -1
  27. data/lib/puppet/provider/user/user_role_add.rb +8 -6
  28. data/lib/puppet/provider/user/useradd.rb +7 -8
  29. data/lib/puppet/rails.rb +2 -6
  30. data/lib/puppet/rails/host.rb +0 -72
  31. data/lib/puppet/resource.rb +22 -0
  32. data/lib/puppet/resource/type.rb +18 -13
  33. data/lib/puppet/type/exec.rb +1 -7
  34. data/lib/puppet/type/schedule.rb +5 -5
  35. data/lib/puppet/util.rb +20 -18
  36. data/lib/puppet/util/command_line.rb +1 -1
  37. data/lib/puppet/util/file_locking.rb +6 -3
  38. data/lib/puppet/util/metric.rb +1 -1
  39. data/lib/puppet/util/rdoc.rb +5 -4
  40. data/lib/puppet/util/rdoc/generators/puppet_generator.rb +6 -0
  41. data/lib/puppet/util/reference.rb +1 -10
  42. data/lib/puppet/util/suidmanager.rb +1 -1
  43. data/lib/puppet/util/zaml.rb +4 -1
  44. data/spec/integration/indirector/bucket_file/rest_spec.rb +10 -2
  45. data/spec/integration/indirector/certificate_revocation_list/rest_spec.rb +10 -2
  46. data/spec/integration/parser/functions_spec.rb +21 -0
  47. data/spec/integration/parser/ruby_manifest_spec.rb +1 -1
  48. data/spec/integration/ssl/certificate_authority_spec.rb +1 -3
  49. data/spec/integration/util/file_locking_spec.rb +31 -11
  50. data/spec/spec_helper.rb +1 -1
  51. data/spec/unit/application/apply_spec.rb +1 -1
  52. data/spec/unit/daemon_spec.rb +3 -9
  53. data/spec/unit/indirector/catalog/compiler_spec.rb +9 -8
  54. data/spec/unit/network/handler/fileserver_spec.rb +2 -4
  55. data/spec/unit/network/server_spec.rb +3 -10
  56. data/spec/unit/parser/ast/collection_spec.rb +4 -0
  57. data/spec/unit/parser/ast/leaf_spec.rb +43 -1
  58. data/spec/unit/parser/ast/resource_spec.rb +133 -88
  59. data/spec/unit/parser/compiler_spec.rb +8 -8
  60. data/spec/unit/parser/lexer_spec.rb +1 -0
  61. data/spec/unit/parser/parser_spec.rb +9 -2
  62. data/spec/unit/provider/confine/exists_spec.rb +6 -13
  63. data/spec/unit/provider/mount_spec.rb +8 -1
  64. data/spec/unit/provider/service/freebsd_spec.rb +50 -0
  65. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +1 -2
  66. data/spec/unit/provider/user/user_role_add_spec.rb +1 -1
  67. data/spec/unit/provider/user/useradd_spec.rb +42 -0
  68. data/spec/unit/rails_spec.rb +82 -22
  69. data/spec/unit/resource/type_spec.rb +13 -13
  70. data/spec/unit/type/schedule_spec.rb +21 -49
  71. data/spec/unit/util/command_line_spec.rb +2 -2
  72. data/spec/unit/util/file_locking_spec.rb +28 -24
  73. data/spec/unit/util/{json_spec.rb → pson_spec.rb} +17 -0
  74. data/spec/unit/util/rdoc_spec.rb +9 -1
  75. data/spec/unit/util/storage_spec.rb +2 -3
  76. data/test/other/provider.rb +1 -12
  77. data/test/other/report.rb +2 -5
  78. data/test/puppet/tc_suidmanager.rb +5 -14
  79. data/test/ral/manager/type.rb +1 -1
  80. data/test/ral/providers/provider.rb +3 -3
  81. data/test/util/metrics.rb +2 -2
  82. metadata +8 -6
  83. data/spec/integration/indirector/rest_spec.rb +0 -525
@@ -80,20 +80,11 @@ class TestSUIDManager < Test::Unit::TestCase
80
80
  warn "Cannot run this test on ruby < 1.8.4"
81
81
  else
82
82
  set_exit_status!
83
-
84
-
85
- Puppet::Util.expects(:execute).with(
86
- 'yay',
87
- { :failonfail => false,
88
- :uid => @user.uid,
89
-
90
- :gid => @user.gid }
91
- ).returns('output')
92
-
93
-
94
- output = Puppet::Util::SUIDManager.run_and_capture 'yay',
95
- @user.uid,
96
- @user.gid
83
+ Puppet::Util.
84
+ expects(:execute).
85
+ with('yay',:combine => true, :failonfail => false, :uid => @user.uid, :gid => @user.gid).
86
+ returns('output')
87
+ output = Puppet::Util::SUIDManager.run_and_capture 'yay', @user.uid, @user.gid
97
88
 
98
89
  assert_equal 'output', output.first
99
90
  assert_kind_of Process::Status, output.last
@@ -276,7 +276,7 @@ class TestType < Test::Unit::TestCase
276
276
  def test_isomorphic_names
277
277
  catalog = mk_catalog
278
278
  # First do execs, since they're not isomorphic.
279
- echo = Puppet::Util.binary "echo"
279
+ echo = Puppet::Util.which "echo"
280
280
  exec1 = exec2 = nil
281
281
  assert_nothing_raised do
282
282
 
@@ -9,7 +9,7 @@ class TestProvider < Test::Unit::TestCase
9
9
  include PuppetTest
10
10
 
11
11
  def echo
12
- echo = Puppet::Util.binary("echo")
12
+ echo = Puppet::Util.which("echo")
13
13
 
14
14
  raise "Could not find 'echo' binary; cannot complete test" unless echo
15
15
 
@@ -95,7 +95,7 @@ class TestProvider < Test::Unit::TestCase
95
95
 
96
96
  provider.commands :testing => "/no/such/path"
97
97
 
98
- provider.stubs(:binary).returns "/no/such/path"
98
+ provider.stubs(:which).returns "/no/such/path"
99
99
 
100
100
  provider.command(:testing)
101
101
  assert_equal("/no/such/path", provider.command(:testing), "Did not return correct binary path")
@@ -187,7 +187,7 @@ class TestProvider < Test::Unit::TestCase
187
187
 
188
188
  dir = tstdir
189
189
  file = File.join(dir, "mycmd")
190
- sh = Puppet::Util.binary("sh")
190
+ sh = Puppet::Util.which("sh")
191
191
  File.open(file, "w") { |f|
192
192
  f.puts %{#!#{sh}
193
193
  echo A Failure >&2
@@ -8,7 +8,7 @@ require 'puppettest'
8
8
  require 'puppet/type'
9
9
 
10
10
  class TestMetric < PuppetTest::TestCase
11
- confine "Missing RRDtool library" => Puppet.features.rrd?
11
+ confine "Missing RRDtool library" => (Puppet.features.rrd? || Puppet.features.rrd_legacy?)
12
12
  include PuppetTest
13
13
 
14
14
  def gendata
@@ -43,7 +43,7 @@ class TestMetric < PuppetTest::TestCase
43
43
  def rundata(report, time)
44
44
  assert_nothing_raised {
45
45
  gendata.each do |name, data|
46
- report.newmetric(name, data)
46
+ report.add_metric(name, data)
47
47
  end
48
48
  report.metrics.each { |n, m| m.store(time) }
49
49
  }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 6
9
- - 2
10
- version: 2.6.2
9
+ - 3
10
+ version: 2.6.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Puppet Labs
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-08 00:00:00 +11:00
18
+ date: 2010-11-17 00:00:00 +11:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -723,6 +723,7 @@ files:
723
723
  - ext/regexp_nodes/regexp_nodes.rb
724
724
  - ext/regexp_nodes/parameters/environment/qa
725
725
  - ext/regexp_nodes/parameters/environment/prod
726
+ - ext/envpuppet
726
727
  - ext/ldap/puppet.schema
727
728
  - ext/rack/files/apache2.conf
728
729
  - ext/rack/files/config.ru
@@ -1102,6 +1103,7 @@ files:
1102
1103
  - spec/unit/provider/group/groupadd_spec.rb
1103
1104
  - spec/unit/provider/zpool/solaris_spec.rb
1104
1105
  - spec/unit/provider/service/debian_spec.rb
1106
+ - spec/unit/provider/service/freebsd_spec.rb
1105
1107
  - spec/unit/provider/service/launchd_spec.rb
1106
1108
  - spec/unit/provider/service/runit_spec.rb
1107
1109
  - spec/unit/provider/service/init_spec.rb
@@ -1229,7 +1231,6 @@ files:
1229
1231
  - spec/unit/util/zaml_spec.rb
1230
1232
  - spec/unit/util/log/destinations_spec.rb
1231
1233
  - spec/unit/util/metric_spec.rb
1232
- - spec/unit/util/json_spec.rb
1233
1234
  - spec/unit/util/errors_spec.rb
1234
1235
  - spec/unit/util/autoload/file_cache_spec.rb
1235
1236
  - spec/unit/util/monkey_patches_spec.rb
@@ -1255,6 +1256,7 @@ files:
1255
1256
  - spec/unit/util/filetype_spec.rb
1256
1257
  - spec/unit/util/user_attr_spec.rb
1257
1258
  - spec/unit/util/cache_accumulator_spec.rb
1259
+ - spec/unit/util/pson_spec.rb
1258
1260
  - spec/unit/util/feature_spec.rb
1259
1261
  - spec/unit/util/backups_spec.rb
1260
1262
  - spec/unit/util/reference_serializer_spec.rb
@@ -1317,6 +1319,7 @@ files:
1317
1319
  - spec/integration/file_serving/fileset_spec.rb
1318
1320
  - spec/integration/file_serving/terminus_helper_spec.rb
1319
1321
  - spec/integration/node_spec.rb
1322
+ - spec/integration/parser/functions_spec.rb
1320
1323
  - spec/integration/parser/compiler_spec.rb
1321
1324
  - spec/integration/parser/functions/require_spec.rb
1322
1325
  - spec/integration/parser/ruby_manifest_spec.rb
@@ -1336,7 +1339,6 @@ files:
1336
1339
  - spec/integration/indirector/catalog/queue_spec.rb
1337
1340
  - spec/integration/indirector/catalog/compiler_spec.rb
1338
1341
  - spec/integration/indirector/file_metadata/file_server_spec.rb
1339
- - spec/integration/indirector/rest_spec.rb
1340
1342
  - spec/integration/indirector/direct_file_server_spec.rb
1341
1343
  - spec/integration/indirector/file_content/file_server_spec.rb
1342
1344
  - spec/integration/indirector/node/ldap_spec.rb
@@ -1,525 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require File.dirname(__FILE__) + '/../../spec_helper'
4
- require 'puppet/network/server'
5
- require 'puppet/indirector'
6
- require 'puppet/indirector/rest'
7
-
8
- # a fake class that will be indirected via REST
9
- class Puppet::TestIndirectedFoo
10
- extend Puppet::Indirector
11
- indirects :test_indirected_foo, :terminus_setting => :test_indirected_foo_terminus
12
-
13
- attr_reader :value
14
- attr_accessor :name
15
-
16
- def initialize(value = 0)
17
- @value = value
18
- end
19
-
20
- def self.from_yaml(yaml)
21
- YAML.load(yaml)
22
- end
23
-
24
- def name
25
- "bob"
26
- end
27
- end
28
-
29
- # empty Terminus class -- this would normally have to be in a directory findable by the autoloader, but we short-circuit that below
30
- class Puppet::TestIndirectedFoo::Rest < Puppet::Indirector::REST
31
- end
32
-
33
-
34
- describe Puppet::Indirector::REST do
35
- before do
36
- # Get a safe temporary file
37
- @tmpfile = Tempfile.new("webrick_integration_testing")
38
- @dir = @tmpfile.path + "_dir"
39
-
40
- Puppet.settings[:confdir] = @dir
41
- Puppet.settings[:vardir] = @dir
42
- Puppet.settings[:group] = Process.gid
43
- Puppet.settings[:server] = "127.0.0.1"
44
- Puppet.settings[:masterport] = "34343"
45
-
46
- Puppet::SSL::Host.ca_location = :local
47
-
48
- Puppet::TestIndirectedFoo.terminus_class = :rest
49
- end
50
-
51
- after do
52
- Puppet::Network::HttpPool.expire
53
- Puppet::SSL::Host.ca_location = :none
54
- Puppet.settings.clear
55
- end
56
-
57
- describe "when using webrick" do
58
- before :each do
59
- Puppet::Util::Cacher.expire
60
-
61
- Puppet[:servertype] = 'webrick'
62
- Puppet[:server] = '127.0.0.1'
63
- Puppet[:certname] = '127.0.0.1'
64
-
65
- ca = Puppet::SSL::CertificateAuthority.new
66
- ca.generate(Puppet[:certname]) unless Puppet::SSL::Certificate.find(Puppet[:certname])
67
-
68
- @params = { :port => 34343, :handlers => [ :test_indirected_foo ], :xmlrpc_handlers => [ :status ] }
69
- @server = Puppet::Network::Server.new(@params)
70
- @server.listen
71
-
72
- # LAK:NOTE We need to have a fake model here so that our indirected methods get
73
- # passed through REST; otherwise we'd be stubbing 'find', which would cause an immediate
74
- # return.
75
- @mock_model = stub('faked model', :name => "foo")
76
- Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
77
-
78
- # do not trigger the authorization layer
79
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:check_authorization).returns(true)
80
- end
81
-
82
- describe "when finding a model instance over REST" do
83
- describe "when a matching model instance can be found" do
84
- before :each do
85
- @model_instance = Puppet::TestIndirectedFoo.new(23)
86
- @mock_model.stubs(:find).returns @model_instance
87
- end
88
-
89
- it "should not fail" do
90
- lambda { Puppet::TestIndirectedFoo.find('bar') }.should_not raise_error
91
- end
92
-
93
- it 'should return an instance of the model class' do
94
- Puppet::TestIndirectedFoo.find('bar').class.should == Puppet::TestIndirectedFoo
95
- end
96
-
97
- it "should pass options all the way through" do
98
- @mock_model.expects(:find).with { |key, args| args[:one] == "two" and args[:three] == "four" }.returns @model_instance
99
- Puppet::TestIndirectedFoo.find('bar', :one => "two", :three => "four")
100
- end
101
-
102
- it 'should return the instance of the model class associated with the provided lookup key' do
103
- Puppet::TestIndirectedFoo.find('bar').value.should == @model_instance.value
104
- end
105
-
106
- it 'should set an expiration on model instance' do
107
- Puppet::TestIndirectedFoo.find('bar').expiration.should_not be_nil
108
- end
109
-
110
- it "should use a supported format" do
111
- Puppet::TestIndirectedFoo.expects(:supported_formats).returns ["marshal"]
112
- text = Marshal.dump(@model_instance)
113
- @model_instance.expects(:render).with(Puppet::Network::FormatHandler.format("marshal")).returns text
114
- Puppet::TestIndirectedFoo.find('bar')
115
- end
116
- end
117
-
118
- describe "when no matching model instance can be found" do
119
- before :each do
120
- @mock_model = stub('faked model', :name => "foo", :find => nil)
121
- Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
122
- end
123
-
124
- it "should return nil" do
125
- Puppet::TestIndirectedFoo.find('bar').should be_nil
126
- end
127
- end
128
-
129
- describe "when an exception is encountered in looking up a model instance" do
130
- before :each do
131
- @mock_model = stub('faked model', :name => "foo")
132
- @mock_model.stubs(:find).raises(RuntimeError)
133
- Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
134
- end
135
-
136
- it "should raise an exception" do
137
- lambda { Puppet::TestIndirectedFoo.find('bar') }.should raise_error(Net::HTTPError)
138
- end
139
- end
140
- end
141
-
142
- describe "when searching for model instances over REST" do
143
- describe "when matching model instances can be found" do
144
- before :each do
145
- @model_instances = [ Puppet::TestIndirectedFoo.new(23), Puppet::TestIndirectedFoo.new(24) ]
146
- @mock_model.stubs(:search).returns @model_instances
147
-
148
- # Force yaml, because otherwise our mocks can't work correctly
149
- Puppet::TestIndirectedFoo.stubs(:supported_formats).returns %w{yaml}
150
-
151
- @mock_model.stubs(:render_multiple).returns @model_instances.to_yaml
152
- end
153
-
154
- it "should not fail" do
155
- lambda { Puppet::TestIndirectedFoo.search('bar') }.should_not raise_error
156
- end
157
-
158
- it 'should return all matching results' do
159
- Puppet::TestIndirectedFoo.search('bar').length.should == @model_instances.length
160
- end
161
-
162
- it "should pass options all the way through" do
163
- @mock_model.expects(:search).with { |key, args| args[:one] == "two" and args[:three] == "four" }.returns @model_instances
164
- Puppet::TestIndirectedFoo.search("foo", :one => "two", :three => "four")
165
- end
166
-
167
- it 'should return model instances' do
168
- Puppet::TestIndirectedFoo.search('bar').each do |result|
169
- result.class.should == Puppet::TestIndirectedFoo
170
- end
171
- end
172
-
173
- it 'should return the instance of the model class associated with the provided lookup key' do
174
- Puppet::TestIndirectedFoo.search('bar').collect { |i| i.value }.should == @model_instances.collect { |i| i.value }
175
- end
176
- end
177
-
178
- describe "when no matching model instance can be found" do
179
- before :each do
180
- @mock_model = stub('faked model', :name => "foo", :find => nil)
181
- Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
182
- end
183
-
184
- it "should return nil" do
185
- Puppet::TestIndirectedFoo.find('bar').should be_nil
186
- end
187
- end
188
-
189
- describe "when an exception is encountered in looking up a model instance" do
190
- before :each do
191
- @mock_model = stub('faked model')
192
- @mock_model.stubs(:find).raises(RuntimeError)
193
- Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
194
- end
195
-
196
- it "should raise an exception" do
197
- lambda { Puppet::TestIndirectedFoo.find('bar') }.should raise_error(Net::HTTPError)
198
- end
199
- end
200
- end
201
-
202
- describe "when destroying a model instance over REST" do
203
- describe "when a matching model instance can be found" do
204
- before :each do
205
- @mock_model.stubs(:destroy).returns true
206
- end
207
-
208
- it "should not fail" do
209
- lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should_not raise_error
210
- end
211
-
212
- it 'should return success' do
213
- Puppet::TestIndirectedFoo.destroy('bar').should == true
214
- end
215
- end
216
-
217
- describe "when no matching model instance can be found" do
218
- before :each do
219
- @mock_model.stubs(:destroy).returns false
220
- end
221
-
222
- it "should return failure" do
223
- Puppet::TestIndirectedFoo.destroy('bar').should == false
224
- end
225
- end
226
-
227
- describe "when an exception is encountered in destroying a model instance" do
228
- before :each do
229
- @mock_model.stubs(:destroy).raises(RuntimeError)
230
- end
231
-
232
- it "should raise an exception" do
233
- lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should raise_error(Net::HTTPError)
234
- end
235
- end
236
- end
237
-
238
- describe "when saving a model instance over REST" do
239
- before :each do
240
- @instance = Puppet::TestIndirectedFoo.new(42)
241
- @mock_model.stubs(:save_object).returns @instance
242
- @mock_model.stubs(:convert_from).returns @instance
243
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:save_object).returns(@instance)
244
- end
245
-
246
- describe "when a successful save can be performed" do
247
- before :each do
248
- end
249
-
250
- it "should not fail" do
251
- lambda { @instance.save }.should_not raise_error
252
- end
253
-
254
- it 'should return an instance of the model class' do
255
- @instance.save.class.should == Puppet::TestIndirectedFoo
256
- end
257
-
258
- it 'should return a matching instance of the model class' do
259
- @instance.save.value.should == @instance.value
260
- end
261
- end
262
-
263
- describe "when a save cannot be completed" do
264
- before :each do
265
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:save_object).returns(false)
266
- end
267
-
268
- it "should return failure" do
269
- @instance.save.should == false
270
- end
271
- end
272
-
273
- describe "when an exception is encountered in performing a save" do
274
- before :each do
275
- Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:save_object).raises(RuntimeError)
276
- end
277
-
278
- it "should raise an exception" do
279
- lambda { @instance.save }.should raise_error(Net::HTTPError)
280
- end
281
- end
282
- end
283
-
284
- after :each do
285
- @server.unlisten
286
- end
287
- end
288
-
289
- describe "when using mongrel" do
290
- confine "Mongrel is not available" => Puppet.features.mongrel?
291
-
292
- before :each do
293
- Puppet[:servertype] = 'mongrel'
294
- @params = { :port => 34343, :handlers => [ :test_indirected_foo ] }
295
-
296
- # Make sure we never get a cert, since mongrel can't speak ssl
297
- Puppet::SSL::Certificate.stubs(:find).returns nil
298
-
299
- # We stub ssl to be off, since mongrel can't speak ssl
300
- Net::HTTP.any_instance.stubs(:use_ssl?).returns false
301
-
302
- @server = Puppet::Network::Server.new(@params)
303
- @server.listen
304
-
305
- # LAK:NOTE We need to have a fake model here so that our indirected methods get
306
- # passed through REST; otherwise we'd be stubbing 'find', which would cause an immediate
307
- # return.
308
- @mock_model = stub('faked model', :name => "foo")
309
- Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
310
-
311
- # do not trigger the authorization layer
312
- Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:check_authorization).returns(true)
313
- end
314
-
315
- after do
316
- @server.unlisten
317
- end
318
-
319
- describe "when finding a model instance over REST" do
320
- describe "when a matching model instance can be found" do
321
- before :each do
322
- @model_instance = Puppet::TestIndirectedFoo.new(23)
323
- @mock_model.stubs(:find).returns @model_instance
324
- end
325
-
326
- it "should not fail" do
327
- lambda { Puppet::TestIndirectedFoo.find('bar') }.should_not raise_error
328
- end
329
-
330
- it 'should return an instance of the model class' do
331
- Puppet::TestIndirectedFoo.find('bar').class.should == Puppet::TestIndirectedFoo
332
- end
333
-
334
- it "should pass options all the way through" do
335
- @mock_model.expects(:find).with { |key, args| args[:one] == "two" and args[:three] == "four" }.returns @model_instance
336
- Puppet::TestIndirectedFoo.find('bar', :one => "two", :three => "four")
337
- end
338
-
339
- it 'should return the instance of the model class associated with the provided lookup key' do
340
- Puppet::TestIndirectedFoo.find('bar').value.should == @model_instance.value
341
- end
342
-
343
- it 'should set an expiration on model instance' do
344
- Puppet::TestIndirectedFoo.find('bar').expiration.should_not be_nil
345
- end
346
-
347
- it "should use a supported format" do
348
- Puppet::TestIndirectedFoo.expects(:supported_formats).returns ["marshal"]
349
- format = stub 'format'
350
- text = Marshal.dump(@model_instance)
351
- @model_instance.expects(:render).with(Puppet::Network::FormatHandler.format("marshal")).returns text
352
- Puppet::TestIndirectedFoo.find('bar')
353
- end
354
- end
355
-
356
- describe "when no matching model instance can be found" do
357
- before :each do
358
- @mock_model.stubs(:find).returns nil
359
- end
360
-
361
- it "should return nil" do
362
- Puppet::TestIndirectedFoo.find('bar').should be_nil
363
- end
364
- end
365
-
366
- describe "when an exception is encountered in looking up a model instance" do
367
- before :each do
368
- @mock_model.stubs(:find).raises(RuntimeError)
369
- end
370
-
371
- it "should raise an exception" do
372
- lambda { Puppet::TestIndirectedFoo.find('bar') }.should raise_error(Net::HTTPError)
373
- end
374
- end
375
- end
376
-
377
- describe "when searching for model instances over REST" do
378
- describe "when matching model instances can be found" do
379
- before :each do
380
- @model_instances = [ Puppet::TestIndirectedFoo.new(23), Puppet::TestIndirectedFoo.new(24) ]
381
-
382
- # Force yaml, because otherwise our mocks can't work correctly
383
- Puppet::TestIndirectedFoo.stubs(:supported_formats).returns %w{yaml}
384
-
385
- @mock_model.stubs(:search).returns @model_instances
386
- @mock_model.stubs(:render_multiple).returns @model_instances.to_yaml
387
- end
388
-
389
- it "should not fail" do
390
- lambda { Puppet::TestIndirectedFoo.search('bar') }.should_not raise_error
391
- end
392
-
393
- it 'should return all matching results' do
394
- Puppet::TestIndirectedFoo.search('bar').length.should == @model_instances.length
395
- end
396
-
397
- it "should pass options all the way through" do
398
- @mock_model.expects(:search).with { |key, args| args[:one] == "two" and args[:three] == "four" }.returns @model_instances
399
- Puppet::TestIndirectedFoo.search('bar', :one => "two", :three => "four")
400
- end
401
-
402
- it 'should return model instances' do
403
- Puppet::TestIndirectedFoo.search('bar').each do |result|
404
- result.class.should == Puppet::TestIndirectedFoo
405
- end
406
- end
407
-
408
- it 'should return the instance of the model class associated with the provided lookup key' do
409
- Puppet::TestIndirectedFoo.search('bar').collect { |i| i.value }.should == @model_instances.collect { |i| i.value }
410
- end
411
-
412
- it 'should set an expiration on model instances' do
413
- Puppet::TestIndirectedFoo.search('bar').each do |result|
414
- result.expiration.should_not be_nil
415
- end
416
- end
417
- end
418
-
419
- describe "when no matching model instance can be found" do
420
- before :each do
421
- @mock_model.stubs(:search).returns nil
422
- @mock_model.stubs(:render_multiple).returns nil.to_yaml
423
- end
424
-
425
- it "should return nil" do
426
- Puppet::TestIndirectedFoo.search('bar').should == []
427
- end
428
- end
429
-
430
- describe "when an exception is encountered in looking up a model instance" do
431
- before :each do
432
- @mock_model.stubs(:find).raises(RuntimeError)
433
- end
434
-
435
- it "should raise an exception" do
436
- lambda { Puppet::TestIndirectedFoo.find('bar') }.should raise_error(Net::HTTPError)
437
- end
438
- end
439
- end
440
-
441
- describe "when destroying a model instance over REST" do
442
- describe "when a matching model instance can be found" do
443
- before :each do
444
- @mock_model.stubs(:destroy).returns true
445
- end
446
-
447
- it "should not fail" do
448
- lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should_not raise_error
449
- end
450
-
451
- it 'should return success' do
452
- Puppet::TestIndirectedFoo.destroy('bar').should == true
453
- end
454
- end
455
-
456
- describe "when no matching model instance can be found" do
457
- before :each do
458
- @mock_model.stubs(:destroy).returns false
459
- end
460
-
461
- it "should return failure" do
462
- Puppet::TestIndirectedFoo.destroy('bar').should == false
463
- end
464
- end
465
-
466
- describe "when an exception is encountered in destroying a model instance" do
467
- before :each do
468
- @mock_model.stubs(:destroy).raises(RuntimeError)
469
- end
470
-
471
- it "should raise an exception" do
472
- lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should raise_error(Net::HTTPError)
473
- end
474
- end
475
- end
476
-
477
- describe "when saving a model instance over REST" do
478
- before :each do
479
- @instance = Puppet::TestIndirectedFoo.new(42)
480
- @mock_model.stubs(:convert_from).returns @instance
481
-
482
- # LAK:NOTE This stub is necessary to prevent the REST call from calling
483
- # REST.save again, thus producing painful infinite recursion.
484
- Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:save_object).returns(@instance)
485
- end
486
-
487
- describe "when a successful save can be performed" do
488
- before :each do
489
- end
490
-
491
- it "should not fail" do
492
- lambda { @instance.save }.should_not raise_error
493
- end
494
-
495
- it 'should return an instance of the model class' do
496
- @instance.save.class.should == Puppet::TestIndirectedFoo
497
- end
498
-
499
- it 'should return a matching instance of the model class' do
500
- @instance.save.value.should == @instance.value
501
- end
502
- end
503
-
504
- describe "when a save cannot be completed" do
505
- before :each do
506
- Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:save_object).returns(false)
507
- end
508
-
509
- it "should return failure" do
510
- @instance.save.should == false
511
- end
512
- end
513
-
514
- describe "when an exception is encountered in performing a save" do
515
- before :each do
516
- Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:save_object).raises(RuntimeError)
517
- end
518
-
519
- it "should raise an exception" do
520
- lambda { @instance.save }.should raise_error(Net::HTTPError)
521
- end
522
- end
523
- end
524
- end
525
- end