puppet 2.7.1 → 2.7.3

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 (171) hide show
  1. data/CHANGELOG +225 -1
  2. data/CONTRIBUTING.md +299 -0
  3. data/README.md +0 -1
  4. data/conf/redhat/puppet.spec +132 -25
  5. data/conf/solaris/pkginfo +1 -1
  6. data/conf/suse/puppet.spec +5 -2
  7. data/ext/envpuppet +56 -3
  8. data/ext/vim/README +2 -1
  9. data/ext/vim/ftplugin/puppet.vim +94 -0
  10. data/ext/vim/indent/puppet.vim +76 -0
  11. data/lib/puppet.rb +2 -3
  12. data/lib/puppet/application/agent.rb +7 -7
  13. data/lib/puppet/application/apply.rb +20 -8
  14. data/lib/puppet/application/ca.rb +5 -0
  15. data/lib/puppet/application/cert.rb +2 -1
  16. data/lib/puppet/application/certificate.rb +0 -5
  17. data/lib/puppet/application/device.rb +4 -4
  18. data/lib/puppet/application/doc.rb +23 -12
  19. data/lib/puppet/application/face_base.rb +2 -1
  20. data/lib/puppet/application/inspect.rb +5 -2
  21. data/lib/puppet/configurer.rb +60 -56
  22. data/lib/puppet/configurer/fact_handler.rb +6 -1
  23. data/lib/puppet/defaults.rb +20 -1
  24. data/lib/puppet/face/ca.rb +233 -0
  25. data/lib/puppet/face/certificate.rb +15 -11
  26. data/lib/puppet/face/certificate_request.rb +9 -11
  27. data/lib/puppet/face/certificate_revocation_list.rb +5 -7
  28. data/lib/puppet/face/node/clean.rb +154 -0
  29. data/lib/puppet/face/status.rb +1 -0
  30. data/lib/puppet/file_serving/configuration/parser.rb +6 -13
  31. data/lib/puppet/indirector/exec.rb +3 -3
  32. data/lib/puppet/indirector/face.rb +17 -7
  33. data/lib/puppet/indirector/report/processor.rb +29 -16
  34. data/lib/puppet/indirector/rest.rb +42 -7
  35. data/lib/puppet/indirector/yaml.rb +5 -0
  36. data/lib/puppet/interface.rb +7 -2
  37. data/lib/puppet/interface/action.rb +57 -23
  38. data/lib/puppet/interface/action_manager.rb +10 -5
  39. data/lib/puppet/interface/face_collection.rb +43 -52
  40. data/lib/puppet/interface/option.rb +19 -0
  41. data/lib/puppet/interface/option_builder.rb +13 -0
  42. data/lib/puppet/interface/option_manager.rb +2 -1
  43. data/lib/puppet/metatype/manager.rb +7 -20
  44. data/lib/puppet/module.rb +4 -1
  45. data/lib/puppet/network/authconfig.rb +3 -1
  46. data/lib/puppet/network/authstore.rb +14 -5
  47. data/lib/puppet/network/handler/fileserver.rb +3 -0
  48. data/lib/puppet/network/http/webrick.rb +1 -1
  49. data/lib/puppet/network/rest_authconfig.rb +6 -1
  50. data/lib/puppet/network/rest_authorization.rb +1 -1
  51. data/lib/puppet/parser/compiler.rb +8 -11
  52. data/lib/puppet/parser/functions.rb +1 -6
  53. data/lib/puppet/parser/functions/create_resources.rb +6 -5
  54. data/lib/puppet/parser/functions/regsubst.rb +26 -0
  55. data/lib/puppet/parser/functions/shellquote.rb +26 -0
  56. data/lib/puppet/parser/functions/sprintf.rb +26 -0
  57. data/lib/puppet/parser/grammar.ra +34 -60
  58. data/lib/puppet/parser/lexer.rb +5 -5
  59. data/lib/puppet/parser/parser.rb +913 -1196
  60. data/lib/puppet/parser/resource.rb +18 -1
  61. data/lib/puppet/parser/scope.rb +2 -2
  62. data/lib/puppet/provider/augeas/augeas.rb +42 -17
  63. data/lib/puppet/provider/mount/parsed.rb +19 -1
  64. data/lib/puppet/provider/naginator.rb +9 -1
  65. data/lib/puppet/provider/nameservice/directoryservice.rb +11 -8
  66. data/lib/puppet/provider/network_device.rb +1 -1
  67. data/lib/puppet/provider/package/aptitude.rb +1 -0
  68. data/lib/puppet/provider/package/pacman.rb +94 -0
  69. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +0 -6
  70. data/lib/puppet/rails/host.rb +7 -0
  71. data/lib/puppet/reports/store.rb +15 -0
  72. data/lib/puppet/resource/catalog.rb +15 -6
  73. data/lib/puppet/ssl/certificate.rb +6 -0
  74. data/lib/puppet/ssl/inventory.rb +2 -0
  75. data/lib/puppet/transaction.rb +9 -17
  76. data/lib/puppet/transaction/report.rb +3 -3
  77. data/lib/puppet/type.rb +13 -24
  78. data/lib/puppet/type/file.rb +8 -2
  79. data/lib/puppet/type/file/source.rb +2 -2
  80. data/lib/puppet/type/service.rb +20 -24
  81. data/lib/puppet/type/ssh_authorized_key.rb +12 -0
  82. data/lib/puppet/type/user.rb +8 -0
  83. data/lib/puppet/util.rb +0 -1
  84. data/lib/puppet/util/network_device.rb +3 -3
  85. data/lib/puppet/util/settings.rb +1 -1
  86. data/lib/puppet/util/settings/file_setting.rb +1 -0
  87. data/lib/semver.rb +65 -0
  88. data/spec/integration/defaults_spec.rb +23 -1
  89. data/spec/integration/network/rest_authconfig_spec.rb +145 -0
  90. data/spec/integration/node/facts_spec.rb +1 -1
  91. data/spec/integration/parser/functions_spec.rb +1 -1
  92. data/spec/integration/parser/parser_spec.rb +31 -0
  93. data/spec/integration/provider/ssh_authorized_key_spec.rb +207 -0
  94. data/spec/integration/type_spec.rb +11 -0
  95. data/spec/lib/puppet/face/1.0.0/huzzah.rb +8 -0
  96. data/spec/lib/puppet/face/huzzah.rb +1 -0
  97. data/spec/lib/puppet/face/huzzah/obsolete.rb +6 -0
  98. data/spec/shared_behaviours/things_that_declare_options.rb +115 -3
  99. data/spec/unit/application/agent_spec.rb +2 -2
  100. data/spec/unit/application/apply_spec.rb +74 -56
  101. data/spec/unit/application/cert_spec.rb +10 -0
  102. data/spec/unit/application/device_spec.rb +2 -3
  103. data/spec/unit/application/face_base_spec.rb +1 -0
  104. data/spec/unit/application/facts_spec.rb +1 -0
  105. data/spec/unit/application/inspect_spec.rb +5 -0
  106. data/spec/unit/configurer/fact_handler_spec.rb +45 -37
  107. data/spec/unit/configurer_spec.rb +405 -327
  108. data/spec/unit/face/ca_spec.rb +355 -0
  109. data/spec/unit/face/certificate_spec.rb +16 -4
  110. data/spec/unit/face/node_spec.rb +261 -1
  111. data/spec/unit/file_serving/configuration/parser_spec.rb +8 -0
  112. data/spec/unit/indirector/certificate/rest_spec.rb +1 -0
  113. data/spec/unit/indirector/certificate_status/file_spec.rb +4 -0
  114. data/spec/unit/indirector/exec_spec.rb +4 -4
  115. data/spec/unit/indirector/face_spec.rb +3 -1
  116. data/spec/unit/indirector/facts/couch_spec.rb +2 -2
  117. data/spec/unit/indirector/facts/network_device_spec.rb +2 -6
  118. data/spec/unit/indirector/node/exec_spec.rb +1 -1
  119. data/spec/unit/indirector/report/processor_spec.rb +31 -8
  120. data/spec/unit/indirector/rest_spec.rb +53 -5
  121. data/spec/unit/indirector/yaml_spec.rb +18 -0
  122. data/spec/unit/interface/action_spec.rb +112 -8
  123. data/spec/unit/interface/face_collection_spec.rb +46 -36
  124. data/spec/unit/interface/option_spec.rb +44 -0
  125. data/spec/unit/interface_spec.rb +11 -6
  126. data/spec/unit/module_spec.rb +38 -9
  127. data/spec/unit/network/authconfig_spec.rb +23 -0
  128. data/spec/unit/network/authstore_spec.rb +36 -4
  129. data/spec/unit/network/handler/fileserver_spec.rb +32 -0
  130. data/spec/unit/network/rest_authconfig_spec.rb +1 -1
  131. data/spec/unit/node_spec.rb +1 -0
  132. data/spec/unit/parser/compiler_spec.rb +8 -46
  133. data/spec/unit/parser/lexer_spec.rb +27 -17
  134. data/spec/unit/parser/resource_spec.rb +61 -3
  135. data/spec/unit/parser/scope_spec.rb +5 -1
  136. data/spec/unit/provider/augeas/augeas_spec.rb +106 -1
  137. data/spec/unit/provider/cisco_spec.rb +3 -4
  138. data/spec/unit/provider/interface/cisco_spec.rb +1 -2
  139. data/spec/unit/provider/mount/parsed_spec.rb +41 -0
  140. data/spec/unit/provider/nameservice/directoryservice_spec.rb +60 -0
  141. data/spec/unit/provider/network_device_spec.rb +1 -2
  142. data/spec/unit/provider/package/pacman_spec.rb +237 -0
  143. data/spec/unit/provider/package/pkgutil_spec.rb +2 -3
  144. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +21 -32
  145. data/spec/unit/provider/vlan/cisco_spec.rb +1 -2
  146. data/spec/unit/rails/host_spec.rb +8 -0
  147. data/spec/unit/resource/catalog_spec.rb +55 -8
  148. data/spec/unit/semver_spec.rb +187 -0
  149. data/spec/unit/ssl/certificate_spec.rb +25 -0
  150. data/spec/unit/transaction/report_spec.rb +3 -3
  151. data/spec/unit/transaction_spec.rb +8 -2
  152. data/spec/unit/type/file_spec.rb +57 -0
  153. data/spec/unit/type/interface_spec.rb +1 -2
  154. data/spec/unit/type/schedule_spec.rb +73 -42
  155. data/spec/unit/type/ssh_authorized_key_spec.rb +180 -70
  156. data/spec/unit/type/user_spec.rb +8 -0
  157. data/spec/unit/type/vlan_spec.rb +1 -2
  158. data/spec/unit/type_spec.rb +66 -0
  159. data/spec/unit/util/network_device/cisco/device_spec.rb +1 -2
  160. data/spec/unit/util/network_device/cisco/facts_spec.rb +2 -3
  161. data/spec/unit/util/network_device/cisco/interface_spec.rb +1 -2
  162. data/spec/unit/util/network_device/config_spec.rb +3 -4
  163. data/spec/unit/util/network_device/ipcalc_spec.rb +1 -2
  164. data/spec/unit/util/network_device/transport/base_spec.rb +1 -2
  165. data/spec/unit/util/network_device/transport/ssh_spec.rb +1 -2
  166. data/spec/unit/util/network_device/transport/telnet_spec.rb +1 -2
  167. data/spec/unit/util/network_device_spec.rb +2 -2
  168. data/spec/unit/util/settings/file_setting_spec.rb +4 -0
  169. data/spec/unit/util/settings_spec.rb +11 -0
  170. data/test/lib/puppettest/railstesting.rb +0 -34
  171. metadata +19 -4
@@ -230,22 +230,6 @@ describe Puppet::Parser::Lexer::TOKENS do
230
230
  end
231
231
  end
232
232
 
233
- describe Puppet::Parser::Lexer::TOKENS[:CLASSNAME] do
234
- before { @token = Puppet::Parser::Lexer::TOKENS[:CLASSNAME] }
235
-
236
- it "should match against lower-case alpha-numeric terms separated by double colons" do
237
- @token.regex.should =~ "one::two"
238
- end
239
-
240
- it "should match against many lower-case alpha-numeric terms separated by double colons" do
241
- @token.regex.should =~ "one::two::three::four::five"
242
- end
243
-
244
- it "should match against lower-case alpha-numeric terms prefixed by double colons" do
245
- @token.regex.should =~ "::one"
246
- end
247
- end
248
-
249
233
  describe Puppet::Parser::Lexer::TOKENS[:CLASSREF] do
250
234
  before { @token = Puppet::Parser::Lexer::TOKENS[:CLASSREF] }
251
235
 
@@ -295,6 +279,22 @@ describe Puppet::Parser::Lexer::TOKENS[:NAME] do
295
279
  Puppet::Parser::Lexer::KEYWORDS.expects(:lookup).returns(keyword)
296
280
  @token.convert(stub('lexer'), "false").should == [Puppet::Parser::Lexer::TOKENS[:BOOLEAN], false]
297
281
  end
282
+
283
+ it "should match against lower-case alpha-numeric terms separated by double colons" do
284
+ @token.regex.should =~ "one::two"
285
+ end
286
+
287
+ it "should match against many lower-case alpha-numeric terms separated by double colons" do
288
+ @token.regex.should =~ "one::two::three::four::five"
289
+ end
290
+
291
+ it "should match against lower-case alpha-numeric terms prefixed by double colons" do
292
+ @token.regex.should =~ "::one"
293
+ end
294
+
295
+ it "should match against nested terms starting with numbers" do
296
+ @token.regex.should =~ "::1one::2two::3three"
297
+ end
298
298
  end
299
299
 
300
300
  describe Puppet::Parser::Lexer::TOKENS[:NUMBER] do
@@ -445,6 +445,9 @@ describe Puppet::Parser::Lexer,"when lexing strings" do
445
445
  %q["foo$bar$"] => [[:DQPRE,"foo"],[:VARIABLE,"bar"],[:DQPOST,"$"]],
446
446
  %q["foo$$bar"] => [[:DQPRE,"foo$"],[:VARIABLE,"bar"],[:DQPOST,""]],
447
447
  %q[""] => [[:STRING,""]],
448
+ %q["123 456 789 0"] => [[:STRING,"123 456 789 0"]],
449
+ %q["${123} 456 $0"] => [[:DQPRE,""],[:VARIABLE,"123"],[:DQMID," 456 "],[:VARIABLE,"0"],[:DQPOST,""]],
450
+ %q["$foo::::bar"] => [[:DQPRE,""],[:VARIABLE,"foo"],[:DQPOST,"::::bar"]]
448
451
  }.each { |src,expected_result|
449
452
  it "should handle #{src} correctly" do
450
453
  tokens_scanned_from(src).should be_like(*expected_result)
@@ -660,10 +663,17 @@ describe "Puppet::Parser::Lexer in the old tests" do
660
663
  end
661
664
 
662
665
  it "should correctly lex variables" do
663
- ["$variable", "$::variable", "$qualified::variable", "$further::qualified::variable"].each do |string|
666
+ ["$variable", "$::variable", "$qualified::variable", "$further::qualified::variable", "$hyphenated-variable", "$-variable-with-leading-dash"].each do |string|
664
667
  tokens_scanned_from(string).should be_like([:VARIABLE,string.sub(/^\$/,'')])
665
668
  end
666
669
  end
670
+
671
+ it "should not include whitespace in a variable" do
672
+ tokens_scanned_from("$foo bar").should_not be_like([:VARIABLE, "foo bar"])
673
+ end
674
+ it "should not include excess colons in a variable" do
675
+ tokens_scanned_from("$foo::::bar").should_not be_like([:VARIABLE, "foo::::bar"])
676
+ end
667
677
  end
668
678
 
669
679
  describe "Puppet::Parser::Lexer in the old tests when lexing example files" do
@@ -131,9 +131,19 @@ describe Puppet::Parser::Resource do
131
131
  end
132
132
 
133
133
  describe "when evaluating" do
134
+ before do
135
+ @node = Puppet::Node.new "test-node"
136
+ @compiler = Puppet::Parser::Compiler.new @node
137
+ @catalog = Puppet::Resource::Catalog.new
138
+ source = stub('source')
139
+ source.stubs(:module_name)
140
+ @scope = Puppet::Parser::Scope.new(:compiler => @compiler, :source => source)
141
+ @catalog.add_resource(Puppet::Parser::Resource.new("stage", :main, :scope => @scope))
142
+ end
143
+
134
144
  it "should evaluate the associated AST definition" do
135
145
  definition = newdefine "mydefine"
136
- res = Puppet::Parser::Resource.new("mydefine", "whatever", :scope => @scope, :source => @source)
146
+ res = Puppet::Parser::Resource.new("mydefine", "whatever", :scope => @scope, :source => @source, :catalog => @catalog)
137
147
  definition.expects(:evaluate_code).with(res)
138
148
 
139
149
  res.evaluate
@@ -141,17 +151,65 @@ describe Puppet::Parser::Resource do
141
151
 
142
152
  it "should evaluate the associated AST class" do
143
153
  @class = newclass "myclass"
144
- res = Puppet::Parser::Resource.new("class", "myclass", :scope => @scope, :source => @source)
154
+ res = Puppet::Parser::Resource.new("class", "myclass", :scope => @scope, :source => @source, :catalog => @catalog)
145
155
  @class.expects(:evaluate_code).with(res)
146
156
  res.evaluate
147
157
  end
148
158
 
149
159
  it "should evaluate the associated AST node" do
150
160
  nodedef = newnode("mynode")
151
- res = Puppet::Parser::Resource.new("node", "mynode", :scope => @scope, :source => @source)
161
+ res = Puppet::Parser::Resource.new("node", "mynode", :scope => @scope, :source => @source, :catalog => @catalog)
152
162
  nodedef.expects(:evaluate_code).with(res)
153
163
  res.evaluate
154
164
  end
165
+
166
+ it "should add an edge to any specified stage for class resources", :'fails_on_ruby_1.9.2' => true do
167
+ @compiler.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "foo", '')
168
+
169
+ other_stage = Puppet::Parser::Resource.new(:stage, "other", :scope => @scope, :catalog => @catalog)
170
+ @compiler.add_resource(@scope, other_stage)
171
+ resource = Puppet::Parser::Resource.new(:class, "foo", :scope => @scope, :catalog => @catalog)
172
+ resource[:stage] = 'other'
173
+ @compiler.add_resource(@scope, resource)
174
+
175
+ resource.evaluate
176
+
177
+ @compiler.catalog.edge?(other_stage, resource).should be_true
178
+ end
179
+
180
+ it "should fail if an unknown stage is specified", :'fails_on_ruby_1.9.2' => true do
181
+ @compiler.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "foo", '')
182
+
183
+ resource = Puppet::Parser::Resource.new(:class, "foo", :scope => @scope, :catalog => @catalog)
184
+ resource[:stage] = 'other'
185
+
186
+ lambda { resource.evaluate }.should raise_error(ArgumentError, /Could not find stage other specified by/)
187
+ end
188
+
189
+ it "should add edges from the class resources to the parent's stage if no stage is specified", :'fails_on_ruby_1.9.2' => true do
190
+ main = @compiler.catalog.resource(:stage, :main)
191
+ foo_stage = Puppet::Parser::Resource.new(:stage, :foo_stage, :scope => @scope, :catalog => @catalog)
192
+ @compiler.add_resource(@scope, foo_stage)
193
+ @compiler.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "foo", '')
194
+ resource = Puppet::Parser::Resource.new(:class, "foo", :scope => @scope, :catalog => @catalog)
195
+ resource[:stage] = 'foo_stage'
196
+ @compiler.add_resource(@scope, resource)
197
+
198
+ resource.evaluate
199
+
200
+ @compiler.catalog.should be_edge(foo_stage, resource)
201
+ end
202
+
203
+ it "should add edges from top-level class resources to the main stage if no stage is specified", :'fails_on_ruby_1.9.2' => true do
204
+ main = @compiler.catalog.resource(:stage, :main)
205
+ @compiler.known_resource_types.add Puppet::Resource::Type.new(:hostclass, "foo", '')
206
+ resource = Puppet::Parser::Resource.new(:class, "foo", :scope => @scope, :catalog => @catalog)
207
+ @compiler.add_resource(@scope, resource)
208
+
209
+ resource.evaluate
210
+
211
+ @compiler.catalog.should be_edge(main, resource)
212
+ end
155
213
  end
156
214
 
157
215
  describe "when finishing" do
@@ -121,7 +121,11 @@ describe Puppet::Parser::Scope do
121
121
 
122
122
  def create_class_scope(name)
123
123
  klass = newclass(name)
124
- Puppet::Parser::Resource.new("class", name, :scope => @scope, :source => mock('source')).evaluate
124
+
125
+ catalog = Puppet::Resource::Catalog.new
126
+ catalog.add_resource(Puppet::Parser::Resource.new("stage", :main, :scope => Puppet::Parser::Scope.new))
127
+
128
+ Puppet::Parser::Resource.new("class", name, :scope => @scope, :source => mock('source'), :catalog => catalog).evaluate
125
129
 
126
130
  @scope.class_scope(klass)
127
131
  end
@@ -4,7 +4,6 @@ require 'spec_helper'
4
4
  provider_class = Puppet::Type.type(:augeas).provider(:augeas)
5
5
 
6
6
  describe provider_class do
7
-
8
7
  describe "command parsing" do
9
8
  before do
10
9
  @resource = stub("resource")
@@ -252,6 +251,7 @@ describe provider_class do
252
251
  it "should handle no filters" do
253
252
  resource = stub("resource")
254
253
  resource.stubs(:[]).returns(false).then.returns("").then.returns("")
254
+ resource.stubs(:noop?).returns(false)
255
255
  augeas_stub = stub("augeas", :match => ["set", "of", "values"])
256
256
  augeas_stub.stubs("close")
257
257
  provider = provider_class.new(resource)
@@ -263,6 +263,7 @@ describe provider_class do
263
263
  it "should return true when a get filter matches" do
264
264
  resource = stub("resource")
265
265
  resource.stubs(:[]).returns(false).then.returns("get path == value").then.returns("")
266
+ resource.stubs(:noop?).returns(false)
266
267
  provider = provider_class.new(resource)
267
268
  augeas_stub = stub("augeas", :get => "value")
268
269
  augeas_stub.stubs("close")
@@ -285,6 +286,7 @@ describe provider_class do
285
286
  it "should return true when a match filter matches" do
286
287
  resource = stub("resource")
287
288
  resource.stubs(:[]).returns(false).then.returns("match path size == 3").then.returns("")
289
+ resource.stubs(:noop?).returns(false)
288
290
  provider = provider_class.new(resource)
289
291
  augeas_stub = stub("augeas", :match => ["set", "of", "values"])
290
292
  augeas_stub.stubs("close")
@@ -320,6 +322,7 @@ describe provider_class do
320
322
  it "should return true when a size != the provided value" do
321
323
  resource = stub("resource")
322
324
  resource.stubs(:[]).returns(false).then.returns("match path size != 17").then.returns("")
325
+ resource.stubs(:noop?).returns(false)
323
326
  provider = provider_class.new(resource)
324
327
  augeas_stub = stub("augeas", :match => ["set", "of", "values"])
325
328
  augeas_stub.stubs("close")
@@ -339,6 +342,107 @@ describe provider_class do
339
342
  provider.stubs(:get_augeas_version).returns("0.3.5")
340
343
  provider.need_to_run?.should == false
341
344
  end
345
+
346
+ # Ticket 2728 (diff files)
347
+ describe "and Puppet[:show_diff] is set", :if => Puppet.features.augeas? do
348
+ before do
349
+ Puppet[:show_diff] = true
350
+
351
+ @resource = Puppet::Type.type(:augeas).new(:name => "test")
352
+ @provider = provider_class.new(@resource)
353
+ @augeas_stub = stub("augeas")
354
+ @provider.aug = @augeas_stub
355
+
356
+ @augeas_stub.stubs("get").with("/augeas/version").returns("0.7.2")
357
+ @augeas_stub.stubs(:set).returns(true)
358
+ @augeas_stub.stubs(:save).returns(true)
359
+ end
360
+
361
+ it "should call diff when a file is shown to have been changed" do
362
+ file = "/etc/hosts"
363
+
364
+ @resource[:context] = "/files"
365
+ @resource[:changes] = ["set #{file}/foo bar"]
366
+
367
+ @augeas_stub.stubs(:match).with("/augeas/events/saved").returns(["/augeas/events/saved"])
368
+ @augeas_stub.stubs(:get).with("/augeas/events/saved").returns(["/files#{file}"])
369
+ @augeas_stub.expects(:set).with("/augeas/save", "newfile")
370
+ @augeas_stub.expects(:close).never()
371
+
372
+ @provider.expects("diff").with("#{file}", "#{file}.augnew").returns("")
373
+ @provider.should be_need_to_run
374
+ end
375
+
376
+ it "should call diff for each file thats changed" do
377
+ file1 = "/etc/hosts"
378
+ file2 = "/etc/resolv.conf"
379
+
380
+ @resource[:context] = "/files"
381
+ @resource[:changes] = ["set #{file1}/foo bar", "set #{file2}/baz biz"]
382
+
383
+ @augeas_stub.stubs(:match).with("/augeas/events/saved").returns(["/augeas/events/saved[1]", "/augeas/events/saved[2]"])
384
+ @augeas_stub.stubs(:get).with("/augeas/events/saved[1]").returns(["/files#{file1}"])
385
+ @augeas_stub.stubs(:get).with("/augeas/events/saved[2]").returns(["/files#{file2}"])
386
+ @augeas_stub.expects(:set).with("/augeas/save", "newfile")
387
+ @augeas_stub.expects(:close).never()
388
+
389
+ @provider.expects(:diff).with("#{file1}", "#{file1}.augnew").returns("")
390
+ @provider.expects(:diff).with("#{file2}", "#{file2}.augnew").returns("")
391
+ @provider.should be_need_to_run
392
+ end
393
+
394
+ describe "and resource[:root] is set" do
395
+ it "should call diff when a file is shown to have been changed" do
396
+ root = "/tmp/foo"
397
+ file = "/etc/hosts"
398
+
399
+ @resource[:context] = "/files"
400
+ @resource[:changes] = ["set #{file}/foo bar"]
401
+ @resource[:root] = root
402
+
403
+ @augeas_stub.stubs(:match).with("/augeas/events/saved").returns(["/augeas/events/saved"])
404
+ @augeas_stub.stubs(:get).with("/augeas/events/saved").returns(["/files#{file}"])
405
+ @augeas_stub.expects(:set).with("/augeas/save", "newfile")
406
+ @augeas_stub.expects(:close).never()
407
+
408
+ @provider.expects(:diff).with("#{root}#{file}", "#{root}#{file}.augnew").returns("")
409
+ @provider.should be_need_to_run
410
+ end
411
+ end
412
+
413
+ it "should not call diff if no files change" do
414
+ file = "/etc/hosts"
415
+
416
+ @resource[:context] = "/files"
417
+ @resource[:changes] = ["set #{file}/foo bar"]
418
+
419
+ @augeas_stub.stubs(:match).with("/augeas/events/saved").returns([])
420
+ @augeas_stub.expects(:set).with("/augeas/save", "newfile")
421
+ @augeas_stub.expects(:get).with("/augeas/events/saved").never()
422
+ @augeas_stub.expects(:close)
423
+
424
+ @provider.expects(:diff).never()
425
+ @provider.should_not be_need_to_run
426
+ end
427
+
428
+ it "should cleanup when in noop mode" do
429
+ file = "/etc/hosts"
430
+
431
+ @resource[:noop] = true
432
+ @resource[:context] = "/files"
433
+ @resource[:changes] = ["set #{file}/foo bar"]
434
+
435
+ @augeas_stub.stubs(:match).with("/augeas/events/saved").returns(["/augeas/events/saved"])
436
+ @augeas_stub.stubs(:get).with("/augeas/events/saved").returns(["/files#{file}"])
437
+ @augeas_stub.expects(:set).with("/augeas/save", "newfile")
438
+ @augeas_stub.expects(:close)
439
+
440
+ File.expects(:delete).with(file + ".augnew")
441
+
442
+ @provider.expects(:diff).with("#{file}", "#{file}.augnew").returns("")
443
+ @provider.should be_need_to_run
444
+ end
445
+ end
342
446
  end
343
447
 
344
448
  describe "augeas execution integration" do
@@ -349,6 +453,7 @@ describe provider_class do
349
453
  @augeas = stub("augeas")
350
454
  @provider.aug= @augeas
351
455
  @provider.stubs(:get_augeas_version).returns("0.3.5")
456
+ @augeas.stubs(:match).with("/augeas/events/saved")
352
457
  end
353
458
 
354
459
  it "should handle set commands" do
@@ -1,6 +1,5 @@
1
- #!/usr/bin/env ruby
2
-
3
- require File.dirname(__FILE__) + '/../../spec_helper'
1
+ #!/usr/bin/env rspec
2
+ require 'spec_helper'
4
3
 
5
4
  require 'puppet/provider/cisco'
6
5
 
@@ -13,4 +12,4 @@ describe Puppet::Provider::Cisco do
13
12
  Puppet::Util::NetworkDevice::Cisco::Device.expects(:new).returns :device
14
13
  Puppet::Provider::Cisco.device(:url).should == :device
15
14
  end
16
- end
15
+ end
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env rspec
2
-
3
- require File.dirname(__FILE__) + '/../../../spec_helper'
2
+ require 'spec_helper'
4
3
 
5
4
  require 'puppet/provider/interface/cisco'
6
5
 
@@ -193,6 +193,47 @@ FSTAB
193
193
 
194
194
  my_fixtures('*.fstab').each do |fstab|
195
195
  platform = File.basename(fstab, '.fstab')
196
+
197
+ describe "when calling instances on #{platform}" do
198
+ before :each do
199
+ if Facter[:operatingsystem] == "Solaris" then
200
+ platform == 'solaris' or
201
+ pending "We need to stub the operatingsystem fact at load time, but can't"
202
+ else
203
+ platform != 'solaris' or
204
+ pending "We need to stub the operatingsystem fact at load time, but can't"
205
+ end
206
+
207
+ # Stub the mount output to our fixture.
208
+ begin
209
+ mount = my_fixture(platform + '.mount')
210
+ @provider.stubs(:mountcmd).returns File.read(mount)
211
+ rescue
212
+ pending "is #{platform}.mount missing at this point?"
213
+ end
214
+
215
+ # Note: we have to stub default_target before creating resources
216
+ # because it is used by Puppet::Type::Mount.new to populate the
217
+ # :target property.
218
+ @provider.stubs(:default_target).returns fstab
219
+ @retrieve = @provider.instances.collect { |prov| {:name => prov.get(:name), :ensure => prov.get(:ensure)}}
220
+ end
221
+
222
+ # Following mountpoint are present in all fstabs/mountoutputs
223
+ it "should include unmounted resources" do
224
+ @retrieve.should include(:name => '/', :ensure => :mounted)
225
+ end
226
+
227
+ it "should include mounted resources" do
228
+ @retrieve.should include(:name => '/boot', :ensure => :unmounted)
229
+ end
230
+
231
+ it "should include ghost resources" do
232
+ @retrieve.should include(:name => '/ghost', :ensure => :ghost)
233
+ end
234
+
235
+ end
236
+
196
237
  describe "when prefetching on #{platform}" do
197
238
  before :each do
198
239
  if Facter[:operatingsystem] == "Solaris" then
@@ -35,3 +35,63 @@ require 'spec_helper'
35
35
  end
36
36
  end
37
37
  end
38
+
39
+ describe 'DirectoryService.single_report' do
40
+ it 'should fail on OS X < 10.4' do
41
+ Puppet::Provider::NameService::DirectoryService.stubs(:get_macosx_version_major).returns("10.3")
42
+
43
+ lambda {
44
+ Puppet::Provider::NameService::DirectoryService.single_report('resource_name')
45
+ }.should raise_error(RuntimeError, "Puppet does not support OS X versions < 10.4")
46
+ end
47
+
48
+ it 'should use url data on 10.4' do
49
+ Puppet::Provider::NameService::DirectoryService.stubs(:get_macosx_version_major).returns("10.4")
50
+ Puppet::Provider::NameService::DirectoryService.stubs(:get_ds_path).returns('Users')
51
+ Puppet::Provider::NameService::DirectoryService.stubs(:list_all_present).returns(
52
+ ['root', 'user1', 'user2', 'resource_name']
53
+ )
54
+ Puppet::Provider::NameService::DirectoryService.stubs(:generate_attribute_hash)
55
+ Puppet::Provider::NameService::DirectoryService.stubs(:execute)
56
+ Puppet::Provider::NameService::DirectoryService.expects(:parse_dscl_url_data)
57
+
58
+ Puppet::Provider::NameService::DirectoryService.single_report('resource_name')
59
+ end
60
+
61
+ it 'should use plist data on > 10.4' do
62
+ Puppet::Provider::NameService::DirectoryService.stubs(:get_macosx_version_major).returns("10.5")
63
+ Puppet::Provider::NameService::DirectoryService.stubs(:get_ds_path).returns('Users')
64
+ Puppet::Provider::NameService::DirectoryService.stubs(:list_all_present).returns(
65
+ ['root', 'user1', 'user2', 'resource_name']
66
+ )
67
+ Puppet::Provider::NameService::DirectoryService.stubs(:generate_attribute_hash)
68
+ Puppet::Provider::NameService::DirectoryService.stubs(:execute)
69
+ Puppet::Provider::NameService::DirectoryService.expects(:parse_dscl_plist_data)
70
+
71
+ Puppet::Provider::NameService::DirectoryService.single_report('resource_name')
72
+ end
73
+ end
74
+
75
+ describe 'DirectoryService.get_exec_preamble' do
76
+ it 'should fail on OS X < 10.4' do
77
+ Puppet::Provider::NameService::DirectoryService.stubs(:get_macosx_version_major).returns("10.3")
78
+
79
+ lambda {
80
+ Puppet::Provider::NameService::DirectoryService.get_exec_preamble('-list')
81
+ }.should raise_error(RuntimeError, "Puppet does not support OS X versions < 10.4")
82
+ end
83
+
84
+ it 'should use url data on 10.4' do
85
+ Puppet::Provider::NameService::DirectoryService.stubs(:get_macosx_version_major).returns("10.4")
86
+ Puppet::Provider::NameService::DirectoryService.stubs(:get_ds_path).returns('Users')
87
+
88
+ Puppet::Provider::NameService::DirectoryService.get_exec_preamble('-list').should include("-url")
89
+ end
90
+
91
+ it 'should use plist data on > 10.4' do
92
+ Puppet::Provider::NameService::DirectoryService.stubs(:get_macosx_version_major).returns("10.5")
93
+ Puppet::Provider::NameService::DirectoryService.stubs(:get_ds_path).returns('Users')
94
+
95
+ Puppet::Provider::NameService::DirectoryService.get_exec_preamble('-list').should include("-plist")
96
+ end
97
+ end