puppet 2.6.4 → 2.6.5

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 (221) hide show
  1. data/CHANGELOG +147 -0
  2. data/LICENSE +2 -2
  3. data/Rakefile +3 -4
  4. data/lib/puppet.rb +1 -1
  5. data/lib/puppet/application.rb +22 -5
  6. data/lib/puppet/application/apply.rb +2 -18
  7. data/lib/puppet/application/doc.rb +1 -4
  8. data/lib/puppet/application/inspect.rb +178 -0
  9. data/lib/puppet/configurer.rb +9 -11
  10. data/lib/puppet/configurer/plugin_handler.rb +0 -2
  11. data/lib/puppet/defaults.rb +12 -3
  12. data/lib/puppet/external/pson/pure/generator.rb +1 -22
  13. data/lib/puppet/file_bucket/dipper.rb +9 -3
  14. data/lib/puppet/file_bucket/file.rb +14 -94
  15. data/lib/puppet/indirector.rb +4 -0
  16. data/lib/puppet/indirector/catalog/active_record.rb +1 -1
  17. data/lib/puppet/indirector/file_bucket_file/file.rb +64 -75
  18. data/lib/puppet/indirector/indirection.rb +18 -8
  19. data/lib/puppet/indirector/resource/ral.rb +7 -2
  20. data/lib/puppet/indirector/rest.rb +19 -2
  21. data/lib/puppet/network/http/api/v1.rb +3 -0
  22. data/lib/puppet/network/http/handler.rb +16 -1
  23. data/lib/puppet/network/http/rack/rest.rb +1 -3
  24. data/lib/puppet/network/rest_authconfig.rb +4 -12
  25. data/lib/puppet/network/rights.rb +28 -14
  26. data/lib/puppet/parser/ast.rb +4 -0
  27. data/lib/puppet/parser/compiler.rb +18 -3
  28. data/lib/puppet/parser/functions/defined.rb +28 -6
  29. data/lib/puppet/parser/functions/fqdn_rand.rb +6 -3
  30. data/lib/puppet/parser/templatewrapper.rb +1 -0
  31. data/lib/puppet/property.rb +16 -1
  32. data/lib/puppet/property/keyvalue.rb +0 -2
  33. data/lib/puppet/property/list.rb +0 -2
  34. data/lib/puppet/provider/file/posix.rb +1 -3
  35. data/lib/puppet/provider/file/win32.rb +1 -3
  36. data/lib/puppet/provider/maillist/mailman.rb +3 -5
  37. data/lib/puppet/provider/mount.rb +2 -0
  38. data/lib/puppet/provider/nameservice/directoryservice.rb +2 -2
  39. data/lib/puppet/provider/package/freebsd.rb +2 -2
  40. data/lib/puppet/provider/zone/solaris.rb +1 -1
  41. data/lib/puppet/reference/configuration.rb +2 -2
  42. data/lib/puppet/reference/function.rb +4 -0
  43. data/lib/puppet/relationship.rb +4 -0
  44. data/lib/puppet/reports/store.rb +1 -19
  45. data/lib/puppet/resource.rb +11 -2
  46. data/lib/puppet/resource/status.rb +24 -3
  47. data/lib/puppet/resource/type.rb +24 -16
  48. data/lib/puppet/resource/type_collection.rb +4 -1
  49. data/lib/puppet/simple_graph.rb +4 -0
  50. data/lib/puppet/transaction.rb +1 -28
  51. data/lib/puppet/transaction/event.rb +9 -4
  52. data/lib/puppet/transaction/report.rb +42 -22
  53. data/lib/puppet/transaction/resource_harness.rb +99 -71
  54. data/lib/puppet/type.rb +22 -9
  55. data/lib/puppet/type/cron.rb +1 -5
  56. data/lib/puppet/type/exec.rb +4 -34
  57. data/lib/puppet/type/file.rb +19 -26
  58. data/lib/puppet/type/file/checksum.rb +1 -1
  59. data/lib/puppet/type/file/content.rb +2 -1
  60. data/lib/puppet/type/file/ctime.rb +18 -0
  61. data/lib/puppet/type/file/ensure.rb +1 -1
  62. data/lib/puppet/type/file/mode.rb +10 -44
  63. data/lib/puppet/type/file/mtime.rb +17 -0
  64. data/lib/puppet/type/file/owner.rb +1 -1
  65. data/lib/puppet/type/file/source.rb +0 -1
  66. data/lib/puppet/type/file/target.rb +1 -1
  67. data/lib/puppet/type/file/type.rb +5 -12
  68. data/lib/puppet/type/host.rb +1 -1
  69. data/lib/puppet/type/mount.rb +2 -2
  70. data/lib/puppet/type/package.rb +0 -2
  71. data/lib/puppet/type/service.rb +11 -5
  72. data/lib/puppet/type/user.rb +7 -9
  73. data/lib/puppet/type/yumrepo.rb +2 -2
  74. data/lib/puppet/type/zpool.rb +0 -4
  75. data/lib/puppet/util/checksums.rb +24 -1
  76. data/lib/puppet/util/command_line.rb +6 -2
  77. data/lib/puppet/util/command_line/puppet +5 -1
  78. data/lib/puppet/util/command_line/puppetca +2 -2
  79. data/lib/puppet/util/command_line/puppetd +11 -9
  80. data/lib/puppet/util/command_line/puppetdoc +2 -2
  81. data/lib/puppet/util/command_line/puppetmasterd +5 -0
  82. data/lib/puppet/util/log.rb +15 -8
  83. data/lib/puppet/util/log/destinations.rb +2 -0
  84. data/lib/puppet/util/log_paths.rb +1 -1
  85. data/lib/puppet/util/logging.rb +1 -1
  86. data/lib/puppet/util/metric.rb +1 -0
  87. data/lib/puppet/util/reference.rb +1 -10
  88. data/lib/puppet/util/settings.rb +1 -1
  89. data/lib/puppet/util/zaml.rb +30 -31
  90. data/spec/fixtures/unit/provider/mount/mount-output.aix.txt +7 -0
  91. data/spec/integration/application/apply_spec.rb +1 -2
  92. data/spec/integration/defaults_spec.rb +1 -0
  93. data/spec/integration/indirector/catalog/queue_spec.rb +1 -4
  94. data/spec/integration/indirector/report/rest_spec.rb +13 -17
  95. data/spec/integration/network/formats_spec.rb +2 -5
  96. data/spec/integration/network/server/mongrel_spec.rb +1 -2
  97. data/spec/integration/provider/mailalias/aliases_spec.rb +0 -1
  98. data/spec/integration/provider/package_spec.rb +1 -3
  99. data/spec/integration/provider/service/init_spec.rb +3 -9
  100. data/spec/integration/reference/providers_spec.rb +2 -2
  101. data/spec/integration/resource/catalog_spec.rb +1 -2
  102. data/spec/integration/transaction/report_spec.rb +1 -1
  103. data/spec/monkey_patches/alias_should_to_must.rb +2 -0
  104. data/spec/shared_behaviours/file_server_terminus.rb +1 -1
  105. data/spec/shared_behaviours/file_serving.rb +1 -1
  106. data/spec/shared_behaviours/memory_terminus.rb +1 -1
  107. data/spec/spec_helper.rb +8 -6
  108. data/spec/unit/application/agent_spec.rb +1 -0
  109. data/spec/unit/application/apply_spec.rb +7 -7
  110. data/spec/unit/application/doc_spec.rb +2 -2
  111. data/spec/unit/application/filebucket_spec.rb +1 -0
  112. data/spec/unit/application/inspect_spec.rb +278 -0
  113. data/spec/unit/application/kick_spec.rb +1 -3
  114. data/spec/unit/application/master_spec.rb +1 -3
  115. data/spec/unit/application/queue_spec.rb +1 -0
  116. data/spec/unit/application_spec.rb +63 -5
  117. data/spec/unit/configurer/plugin_handler_spec.rb +5 -1
  118. data/spec/unit/configurer_spec.rb +33 -49
  119. data/spec/unit/file_bucket/dipper_spec.rb +69 -77
  120. data/spec/unit/file_bucket/file_spec.rb +12 -127
  121. data/spec/unit/file_serving/fileset_spec.rb +1 -0
  122. data/spec/unit/file_serving/metadata_spec.rb +4 -4
  123. data/spec/unit/indirector/active_record_spec.rb +1 -0
  124. data/spec/unit/indirector/catalog/active_record_spec.rb +29 -13
  125. data/spec/unit/indirector/facts/active_record_spec.rb +2 -3
  126. data/spec/unit/indirector/facts/couch_spec.rb +1 -2
  127. data/spec/unit/indirector/file_bucket_file/file_spec.rb +202 -218
  128. data/spec/unit/indirector/file_server_spec.rb +6 -7
  129. data/spec/unit/indirector/indirection_spec.rb +71 -2
  130. data/spec/unit/indirector/ldap_spec.rb +2 -6
  131. data/spec/unit/indirector/node/active_record_spec.rb +1 -3
  132. data/spec/unit/indirector/queue_spec.rb +1 -3
  133. data/spec/unit/indirector/rest_spec.rb +37 -1
  134. data/spec/unit/indirector/ssl_file_spec.rb +5 -5
  135. data/spec/unit/indirector_spec.rb +6 -1
  136. data/spec/unit/module_spec.rb +1 -3
  137. data/spec/unit/network/formats_spec.rb +2 -5
  138. data/spec/unit/network/http/api/v1_spec.rb +4 -0
  139. data/spec/unit/network/http/compression_spec.rb +1 -3
  140. data/spec/unit/network/http/handler_spec.rb +39 -0
  141. data/spec/unit/network/http/mongrel/rest_spec.rb +1 -2
  142. data/spec/unit/network/http/mongrel_spec.rb +3 -9
  143. data/spec/unit/network/http/rack/rest_spec.rb +1 -3
  144. data/spec/unit/network/http/rack/xmlrpc_spec.rb +2 -3
  145. data/spec/unit/network/http/rack_spec.rb +2 -3
  146. data/spec/unit/network/http/webrick_spec.rb +1 -0
  147. data/spec/unit/network/rest_authconfig_spec.rb +1 -1
  148. data/spec/unit/network/rights_spec.rb +43 -23
  149. data/spec/unit/network/xmlrpc/client_spec.rb +1 -0
  150. data/spec/unit/parameter_spec.rb +1 -2
  151. data/spec/unit/parser/collector_spec.rb +3 -6
  152. data/spec/unit/parser/compiler_spec.rb +90 -5
  153. data/spec/unit/parser/lexer_spec.rb +3 -2
  154. data/spec/unit/parser/templatewrapper_spec.rb +1 -0
  155. data/spec/unit/property/keyvalue_spec.rb +5 -5
  156. data/spec/unit/property/list_spec.rb +7 -7
  157. data/spec/unit/provider/mount/parsed_spec.rb +1 -2
  158. data/spec/unit/provider/mount_spec.rb +8 -0
  159. data/spec/unit/provider/nameservice/directoryservice_spec.rb +38 -0
  160. data/spec/unit/provider/package/freebsd_spec.rb +55 -0
  161. data/spec/unit/provider/service/init_spec.rb +2 -0
  162. data/spec/unit/rails/host_spec.rb +1 -3
  163. data/spec/unit/rails/param_value_spec.rb +2 -3
  164. data/spec/unit/rails/resource_spec.rb +2 -3
  165. data/spec/unit/rails_spec.rb +5 -15
  166. data/spec/unit/relationship_spec.rb +2 -6
  167. data/spec/unit/reports/http_spec.rb +1 -1
  168. data/spec/unit/reports/store_spec.rb +31 -0
  169. data/spec/unit/reports/tagmail_spec.rb +1 -1
  170. data/spec/unit/resource/catalog_spec.rb +2 -6
  171. data/spec/unit/resource/status_spec.rb +53 -3
  172. data/spec/unit/resource/type_collection_spec.rb +0 -8
  173. data/spec/unit/resource/type_spec.rb +50 -4
  174. data/spec/unit/resource_spec.rb +10 -6
  175. data/spec/unit/ssl/certificate_authority/interface_spec.rb +1 -1
  176. data/spec/unit/transaction/event_spec.rb +21 -2
  177. data/spec/unit/transaction/report_spec.rb +91 -35
  178. data/spec/unit/transaction/resource_harness_spec.rb +289 -208
  179. data/spec/unit/transaction_spec.rb +1 -6
  180. data/spec/unit/type/augeas_spec.rb +1 -3
  181. data/spec/unit/type/file/content_spec.rb +63 -10
  182. data/spec/unit/type/file/ctime.rb +35 -0
  183. data/spec/unit/type/file/ensure_spec.rb +8 -7
  184. data/spec/unit/type/file/group_spec.rb +5 -5
  185. data/spec/unit/type/file/mtime.rb +35 -0
  186. data/spec/unit/type/file/owner_spec.rb +7 -7
  187. data/spec/unit/type/file/selinux_spec.rb +2 -2
  188. data/spec/unit/type/file/source_spec.rb +3 -3
  189. data/spec/unit/type/file/type.rb +20 -0
  190. data/spec/unit/type/file_spec.rb +131 -8
  191. data/spec/unit/type/mount_spec.rb +4 -4
  192. data/spec/unit/type/package_spec.rb +3 -3
  193. data/spec/unit/type/ssh_authorized_key_spec.rb +1 -1
  194. data/spec/unit/type/user_spec.rb +31 -3
  195. data/spec/unit/type/zpool_spec.rb +12 -12
  196. data/spec/unit/type_spec.rb +2 -2
  197. data/spec/unit/util/checksums_spec.rb +9 -1
  198. data/spec/unit/util/command_line_spec.rb +29 -0
  199. data/spec/unit/util/log/destinations_spec.rb +13 -0
  200. data/spec/unit/util/log_spec.rb +24 -12
  201. data/spec/unit/util/logging_spec.rb +1 -1
  202. data/spec/unit/util/metric_spec.rb +7 -7
  203. data/spec/unit/util/pson_spec.rb +15 -0
  204. data/spec/unit/util/queue/stomp_spec.rb +2 -6
  205. data/spec/unit/util/settings/file_setting_spec.rb +1 -3
  206. data/spec/unit/util/zaml_spec.rb +51 -0
  207. data/test/language/snippets.rb +3 -0
  208. data/test/lib/puppettest/fileparsing.rb +2 -0
  209. data/test/lib/puppettest/reporttesting.rb +1 -1
  210. data/test/lib/puppettest/support/utils.rb +1 -1
  211. data/test/network/server/mongrel_test.rb +0 -6
  212. data/test/other/report.rb +1 -1
  213. data/test/ral/providers/cron/crontab.rb +4 -1
  214. data/test/ral/type/file.rb +1 -1
  215. data/test/ral/type/filesources.rb +1 -4
  216. metadata +1119 -1113
  217. data/lib/puppet/transaction/change.rb +0 -87
  218. data/spec/Rakefile +0 -91
  219. data/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb +0 -46
  220. data/spec/spec_specs/runnable_spec.rb +0 -95
  221. data/spec/unit/transaction/change_spec.rb +0 -193
@@ -6,9 +6,7 @@ describe "Package Provider" do
6
6
  Puppet::Type.type(:package).providers.each do |name|
7
7
  provider = Puppet::Type.type(:package).provider(name)
8
8
 
9
- describe name do
10
- confine "Provider #{name} is not suitable" => provider.suitable?
11
-
9
+ describe name, :if => provider.suitable? do
12
10
  it "should fail when asked to install an invalid package" do
13
11
  pending("This test hangs forever with recent versions of RubyGems") if provider.name == :gem
14
12
  pkg = Puppet::Type.newpackage :name => "nosuch#{provider.name}", :provider => provider.name
@@ -6,25 +6,19 @@ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f
6
6
  provider = Puppet::Type.type(:service).provider(:init)
7
7
 
8
8
  describe provider do
9
- describe "when running on FreeBSD" do
10
- confine "Not running on FreeBSD" => (Facter.value(:operatingsystem) == "FreeBSD")
11
-
9
+ describe "when running on FreeBSD", :if => (Facter.value(:operatingsystem) == "FreeBSD") do
12
10
  it "should set its default path to include /etc/init.d and /usr/local/etc/init.d" do
13
11
  provider.defpath.should == ["/etc/rc.d", "/usr/local/etc/rc.d"]
14
12
  end
15
13
  end
16
14
 
17
- describe "when running on HP-UX" do
18
- confine "Not running on HP-UX" => (Facter.value(:operatingsystem) == "HP-UX")
19
-
15
+ describe "when running on HP-UX", :if => (Facter.value(:operatingsystem) == "HP-UX")do
20
16
  it "should set its default path to include /sbin/init.d" do
21
17
  provider.defpath.should == "/sbin/init.d"
22
18
  end
23
19
  end
24
20
 
25
- describe "when not running on FreeBSD or HP-UX" do
26
- confine "Running on HP-UX or FreeBSD" => (! %w{HP-UX FreeBSD}.include?(Facter.value(:operatingsystem)))
27
-
21
+ describe "when not running on FreeBSD or HP-UX", :if => (! %w{HP-UX FreeBSD}.include?(Facter.value(:operatingsystem))) do
28
22
  it "should set its default path to include /etc/init.d" do
29
23
  provider.defpath.should == "/etc/init.d"
30
24
  end
@@ -11,7 +11,7 @@ describe reference do
11
11
  reference.should_not be_nil
12
12
  end
13
13
 
14
- it "should be able to be rendered as text" do
15
- lambda { reference.to_text }.should_not raise_error
14
+ it "should be able to be rendered as markdown" do
15
+ lambda { reference.to_markdown }.should_not raise_error
16
16
  end
17
17
  end
@@ -6,8 +6,7 @@
6
6
  require File.dirname(__FILE__) + '/../../spec_helper'
7
7
 
8
8
  describe Puppet::Resource::Catalog do
9
- describe "when pson is available" do
10
- confine "PSON library is missing" => Puppet.features.pson?
9
+ describe "when pson is available", :if => Puppet.features.pson? do
11
10
  it "should support pson" do
12
11
  Puppet::Resource::Catalog.supported_formats.should be_include(:pson)
13
12
  end
@@ -19,7 +19,7 @@ describe Puppet::Transaction::Report do
19
19
 
20
20
  Facter.stubs(:value).returns "host.domain.com"
21
21
 
22
- report = Puppet::Transaction::Report.new
22
+ report = Puppet::Transaction::Report.new("apply")
23
23
 
24
24
  terminus.expects(:process).with(report)
25
25
 
@@ -1,3 +1,5 @@
1
+ require 'rspec'
2
+
1
3
  class Object
2
4
  # This is necessary because the RAL has a 'should'
3
5
  # method.
@@ -3,7 +3,7 @@
3
3
  # Created by Luke Kanies on 2007-10-18.
4
4
  # Copyright (c) 2007. All rights reserved.
5
5
 
6
- describe "Puppet::Indirector::FileServerTerminus", :shared => true do
6
+ shared_examples_for "Puppet::Indirector::FileServerTerminus" do
7
7
  # This only works if the shared behaviour is included before
8
8
  # the 'before' block in the including context.
9
9
  before do
@@ -3,7 +3,7 @@
3
3
  # Created by Luke Kanies on 2007-10-18.
4
4
  # Copyright (c) 2007. All rights reserved.
5
5
 
6
- describe "Puppet::FileServing::Files", :shared => true do
6
+ shared_examples_for "Puppet::FileServing::Files" do
7
7
  it "should use the rest terminus when the 'puppet' URI scheme is used and a host name is present" do
8
8
  uri = "puppet://myhost/fakemod/my/file"
9
9
 
@@ -2,7 +2,7 @@
2
2
  # Created by Luke Kanies on 2008-4-8.
3
3
  # Copyright (c) 2008. All rights reserved.
4
4
 
5
- describe "A Memory Terminus", :shared => true do
5
+ shared_examples_for "A Memory Terminus" do
6
6
  it "should find no instances by default" do
7
7
  @searcher.find(@request).should be_nil
8
8
  end
@@ -6,29 +6,31 @@ dir = File.expand_path(File.dirname(__FILE__))
6
6
  $LOAD_PATH.unshift("#{dir}/")
7
7
  $LOAD_PATH.unshift("#{dir}/lib") # a spec-specific test lib dir
8
8
  $LOAD_PATH.unshift("#{dir}/../lib")
9
+ $LOAD_PATH.unshift("#{dir}/../test/lib")
9
10
 
10
11
  # Don't want puppet getting the command line arguments for rake or autotest
11
12
  ARGV.clear
12
13
 
13
14
  require 'puppet'
14
15
  require 'mocha'
15
- gem 'rspec', '>=1.2.9'
16
- require 'spec/autorun'
16
+ gem 'rspec', '>=2.0.0'
17
17
 
18
18
  # So everyone else doesn't have to include this base constant.
19
19
  module PuppetSpec
20
20
  FIXTURE_DIR = File.join(dir = File.expand_path(File.dirname(__FILE__)), "fixtures") unless defined?(FIXTURE_DIR)
21
21
  end
22
22
 
23
+ module PuppetTest
24
+ end
25
+
23
26
  require 'lib/puppet_spec/files'
24
27
  require 'monkey_patches/alias_should_to_must'
25
- require 'monkey_patches/add_confine_and_runnable_to_rspec_dsl'
26
28
  require 'monkey_patches/publicize_methods'
27
29
 
28
- Spec::Runner.configure do |config|
30
+ RSpec.configure do |config|
29
31
  config.mock_with :mocha
30
32
 
31
- config.prepend_after :each do
33
+ config.after :each do
32
34
  Puppet.settings.clear
33
35
  Puppet::Node::Environment.clear
34
36
  Puppet::Util::Storage.clear
@@ -58,7 +60,7 @@ Spec::Runner.configure do |config|
58
60
  Puppet::Util::Log.close_all
59
61
  end
60
62
 
61
- config.prepend_before :each do
63
+ config.before :each do
62
64
  # these globals are set by Application
63
65
  $puppet_application_mode = nil
64
66
  $puppet_application_name = nil
@@ -5,6 +5,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
5
5
  require 'puppet/agent'
6
6
  require 'puppet/application/agent'
7
7
  require 'puppet/network/server'
8
+ require 'puppet/network/handler'
8
9
  require 'puppet/daemon'
9
10
 
10
11
  describe Puppet::Application::Agent do
@@ -4,6 +4,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
4
4
 
5
5
  require 'puppet/application/apply'
6
6
  require 'puppet/file_bucket/dipper'
7
+ require 'puppet/configurer'
7
8
 
8
9
  describe Puppet::Application::Apply do
9
10
  before :each do
@@ -194,6 +195,9 @@ describe Puppet::Application::Apply do
194
195
  @catalog.stubs(:apply).returns(@transaction)
195
196
 
196
197
  @apply.stubs(:exit)
198
+
199
+ Puppet::Util::Storage.stubs(:load)
200
+ Puppet::Configurer.any_instance.stubs(:save_last_run_summary) # to prevent it from trying to write files
197
201
  end
198
202
 
199
203
  it "should set the code to run from --code" do
@@ -302,11 +306,8 @@ describe Puppet::Application::Apply do
302
306
  end
303
307
 
304
308
  it "should call the prerun and postrun commands on a Configurer instance" do
305
- configurer = stub 'configurer'
306
-
307
- Puppet::Configurer.expects(:new).returns configurer
308
- configurer.expects(:execute_prerun_command)
309
- configurer.expects(:execute_postrun_command)
309
+ Puppet::Configurer.any_instance.expects(:execute_prerun_command)
310
+ Puppet::Configurer.any_instance.expects(:execute_postrun_command)
310
311
 
311
312
  @apply.main
312
313
  end
@@ -321,8 +322,7 @@ describe Puppet::Application::Apply do
321
322
  it "should exit with report's computed exit status" do
322
323
  Puppet.stubs(:[]).with(:noop).returns(false)
323
324
  @apply.options.stubs(:[]).with(:detailed_exitcodes).returns(true)
324
- report = stub 'report', :exit_status => 666
325
- @transaction.stubs(:report).returns(report)
325
+ Puppet::Transaction::Report.any_instance.stubs(:exit_status).returns(666)
326
326
  @apply.expects(:exit).with(666)
327
327
 
328
328
  @apply.main
@@ -48,10 +48,10 @@ describe Puppet::Application::Doc do
48
48
  @doc.options[:mode].should == :text
49
49
  end
50
50
 
51
- it "should init format to to_rest" do
51
+ it "should init format to to_markdown" do
52
52
  @doc.preinit
53
53
 
54
- @doc.options[:format].should == :to_rest
54
+ @doc.options[:format].should == :to_markdown
55
55
  end
56
56
  end
57
57
 
@@ -3,6 +3,7 @@
3
3
  require File.dirname(__FILE__) + '/../../spec_helper'
4
4
 
5
5
  require 'puppet/application/filebucket'
6
+ require 'puppet/file_bucket/dipper'
6
7
 
7
8
  describe Puppet::Application::Filebucket do
8
9
  before :each do
@@ -0,0 +1,278 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../../spec_helper'
4
+
5
+ require 'puppet/application/inspect'
6
+ require 'puppet/resource/catalog'
7
+ require 'puppet/indirector/catalog/yaml'
8
+ require 'puppet/indirector/report/rest'
9
+ require 'puppet/indirector/file_bucket_file/rest'
10
+
11
+ describe Puppet::Application::Inspect do
12
+ include PuppetSpec::Files
13
+
14
+ before :each do
15
+ @inspect = Puppet::Application[:inspect]
16
+ end
17
+
18
+ describe "during setup" do
19
+ it "should print its configuration if asked" do
20
+ Puppet[:configprint] = "all"
21
+
22
+ Puppet.settings.expects(:print_configs).returns(true)
23
+ lambda { @inspect.setup }.should raise_error(SystemExit)
24
+ end
25
+
26
+ it "should fail if reporting is turned off" do
27
+ Puppet[:report] = false
28
+ lambda { @inspect.setup }.should raise_error(/report=true/)
29
+ end
30
+ end
31
+
32
+ describe "when executing" do
33
+ before :each do
34
+ Puppet[:report] = true
35
+ @inspect.options[:logset] = true
36
+ Puppet::Transaction::Report::Rest.any_instance.stubs(:save)
37
+ @inspect.setup
38
+ end
39
+
40
+ it "should retrieve the local catalog" do
41
+ Puppet::Resource::Catalog::Yaml.any_instance.expects(:find).with {|request| request.key == Puppet[:certname] }.returns(Puppet::Resource::Catalog.new)
42
+
43
+ @inspect.run_command
44
+ end
45
+
46
+ it "should save the report to REST" do
47
+ Puppet::Resource::Catalog::Yaml.any_instance.stubs(:find).returns(Puppet::Resource::Catalog.new)
48
+ Puppet::Transaction::Report::Rest.any_instance.expects(:save).with {|request| request.instance.host == Puppet[:certname] }
49
+
50
+ @inspect.run_command
51
+ end
52
+
53
+ it "should audit the specified properties" do
54
+ catalog = Puppet::Resource::Catalog.new
55
+ file = Tempfile.new("foo")
56
+ file.puts("file contents")
57
+ file.close
58
+ resource = Puppet::Resource.new(:file, file.path, :parameters => {:audit => "all"})
59
+ catalog.add_resource(resource)
60
+ Puppet::Resource::Catalog::Yaml.any_instance.stubs(:find).returns(catalog)
61
+
62
+ events = nil
63
+
64
+ Puppet::Transaction::Report::Rest.any_instance.expects(:save).with do |request|
65
+ events = request.instance.resource_statuses.values.first.events
66
+ end
67
+
68
+ @inspect.run_command
69
+
70
+ properties = events.inject({}) do |property_values, event|
71
+ property_values.merge(event.property => event.previous_value)
72
+ end
73
+ properties["ensure"].should == :file
74
+ properties["content"].should == "{md5}#{Digest::MD5.hexdigest("file contents\n")}"
75
+ properties.has_key?("target").should == false
76
+ end
77
+
78
+ it "should set audited to true for all events" do
79
+ catalog = Puppet::Resource::Catalog.new
80
+ file = Tempfile.new("foo")
81
+ resource = Puppet::Resource.new(:file, file.path, :parameters => {:audit => "all"})
82
+ catalog.add_resource(resource)
83
+ Puppet::Resource::Catalog::Yaml.any_instance.stubs(:find).returns(catalog)
84
+
85
+ events = nil
86
+
87
+ Puppet::Transaction::Report::Rest.any_instance.expects(:save).with do |request|
88
+ events = request.instance.resource_statuses.values.first.events
89
+ end
90
+
91
+ @inspect.run_command
92
+
93
+ events.each do |event|
94
+ event.audited.should == true
95
+ end
96
+ end
97
+
98
+ it "should not report irrelevent attributes if the resource is absent" do
99
+ catalog = Puppet::Resource::Catalog.new
100
+ file = Tempfile.new("foo")
101
+ resource = Puppet::Resource.new(:file, file.path, :parameters => {:audit => "all"})
102
+ file.delete
103
+ catalog.add_resource(resource)
104
+ Puppet::Resource::Catalog::Yaml.any_instance.stubs(:find).returns(catalog)
105
+
106
+ events = nil
107
+
108
+ Puppet::Transaction::Report::Rest.any_instance.expects(:save).with do |request|
109
+ events = request.instance.resource_statuses.values.first.events
110
+ end
111
+
112
+ @inspect.run_command
113
+
114
+ properties = events.inject({}) do |property_values, event|
115
+ property_values.merge(event.property => event.previous_value)
116
+ end
117
+ properties.should == {"ensure" => :absent}
118
+ end
119
+
120
+ describe "when archiving to a bucket" do
121
+ before :each do
122
+ Puppet[:archive_files] = true
123
+ Puppet[:archive_file_server] = "filebucketserver"
124
+ @catalog = Puppet::Resource::Catalog.new
125
+ Puppet::Resource::Catalog::Yaml.any_instance.stubs(:find).returns(@catalog)
126
+ end
127
+
128
+ describe "when auditing files" do
129
+ before :each do
130
+ @file = tmpfile("foo")
131
+ @resource = Puppet::Resource.new(:file, @file, :parameters => {:audit => "content"})
132
+ @catalog.add_resource(@resource)
133
+ end
134
+
135
+ it "should send an existing file to the file bucket" do
136
+ File.open(@file, 'w') { |f| f.write('stuff') }
137
+ Puppet::FileBucketFile::Rest.any_instance.expects(:head).with do |request|
138
+ request.server == Puppet[:archive_file_server]
139
+ end.returns(false)
140
+ Puppet::FileBucketFile::Rest.any_instance.expects(:save).with do |request|
141
+ request.server == Puppet[:archive_file_server] and request.instance.contents == 'stuff'
142
+ end
143
+ @inspect.run_command
144
+ end
145
+
146
+ it "should not send unreadable files" do
147
+ File.open(@file, 'w') { |f| f.write('stuff') }
148
+ File.chmod(0, @file)
149
+ Puppet::FileBucketFile::Rest.any_instance.expects(:head).never
150
+ Puppet::FileBucketFile::Rest.any_instance.expects(:save).never
151
+ @inspect.run_command
152
+ end
153
+
154
+ it "should not try to send non-existent files" do
155
+ Puppet::FileBucketFile::Rest.any_instance.expects(:head).never
156
+ Puppet::FileBucketFile::Rest.any_instance.expects(:save).never
157
+ @inspect.run_command
158
+ end
159
+
160
+ it "should not try to send files whose content we are not auditing" do
161
+ @resource[:audit] = "group"
162
+ Puppet::FileBucketFile::Rest.any_instance.expects(:head).never
163
+ Puppet::FileBucketFile::Rest.any_instance.expects(:save).never
164
+ @inspect.run_command
165
+ end
166
+
167
+ it "should continue if bucketing a file fails" do
168
+ File.open(@file, 'w') { |f| f.write('stuff') }
169
+ Puppet::FileBucketFile::Rest.any_instance.stubs(:head).returns false
170
+ Puppet::FileBucketFile::Rest.any_instance.stubs(:save).raises "failure"
171
+ Puppet::Transaction::Report::Rest.any_instance.expects(:save).with do |request|
172
+ @report = request.instance
173
+ end
174
+
175
+ @inspect.run_command
176
+
177
+ @report.logs.first.should_not == nil
178
+ @report.logs.first.message.should =~ /Could not back up/
179
+ end
180
+ end
181
+
182
+ describe "when auditing non-files" do
183
+ before :each do
184
+ Puppet::Type.newtype(:stub_type) do
185
+ newparam(:name) do
186
+ desc "The name var"
187
+ isnamevar
188
+ end
189
+
190
+ newproperty(:content) do
191
+ desc "content"
192
+ def retrieve
193
+ :whatever
194
+ end
195
+ end
196
+ end
197
+
198
+ @resource = Puppet::Resource.new(:stub_type, 'foo', :parameters => {:audit => "all"})
199
+ @catalog.add_resource(@resource)
200
+ end
201
+
202
+ after :each do
203
+ Puppet::Type.rmtype(:stub_type)
204
+ end
205
+
206
+ it "should not try to send non-files" do
207
+ Puppet::FileBucketFile::Rest.any_instance.expects(:head).never
208
+ Puppet::FileBucketFile::Rest.any_instance.expects(:save).never
209
+ @inspect.run_command
210
+ end
211
+ end
212
+ end
213
+
214
+ describe "when there are failures" do
215
+ before :each do
216
+ Puppet::Type.newtype(:stub_type) do
217
+ newparam(:name) do
218
+ desc "The name var"
219
+ isnamevar
220
+ end
221
+
222
+ newproperty(:content) do
223
+ desc "content"
224
+ def retrieve
225
+ raise "failed"
226
+ end
227
+ end
228
+ end
229
+
230
+ @catalog = Puppet::Resource::Catalog.new
231
+ Puppet::Resource::Catalog::Yaml.any_instance.stubs(:find).returns(@catalog)
232
+
233
+ Puppet::Transaction::Report::Rest.any_instance.expects(:save).with do |request|
234
+ @report = request.instance
235
+ end
236
+ end
237
+
238
+ after :each do
239
+ Puppet::Type.rmtype(:stub_type)
240
+ end
241
+
242
+ it "should mark the report failed and create failed events for each property" do
243
+ @resource = Puppet::Resource.new(:stub_type, 'foo', :parameters => {:audit => "all"})
244
+ @catalog.add_resource(@resource)
245
+
246
+ @inspect.run_command
247
+
248
+ @report.status.should == "failed"
249
+ @report.logs.select{|log| log.message =~ /Could not inspect/}.count.should == 1
250
+ @report.resource_statuses.count.should == 1
251
+ @report.resource_statuses['Stub_type[foo]'].events.count.should == 1
252
+
253
+ event = @report.resource_statuses['Stub_type[foo]'].events.first
254
+ event.property.should == "content"
255
+ event.status.should == "failure"
256
+ event.audited.should == true
257
+ event.instance_variables.should_not include("@previous_value")
258
+ end
259
+
260
+ it "should continue to the next resource" do
261
+ @resource = Puppet::Resource.new(:stub_type, 'foo', :parameters => {:audit => "all"})
262
+ @other_resource = Puppet::Resource.new(:stub_type, 'bar', :parameters => {:audit => "all"})
263
+ @catalog.add_resource(@resource)
264
+ @catalog.add_resource(@other_resource)
265
+
266
+ @inspect.run_command
267
+
268
+ @report.resource_statuses.count.should == 2
269
+ @report.resource_statuses.keys.should =~ ['Stub_type[foo]', 'Stub_type[bar]']
270
+ end
271
+ end
272
+ end
273
+
274
+ after :all do
275
+ Puppet::Resource::Catalog.indirection.reset_terminus_class
276
+ Puppet::Transaction::Report.indirection.terminus_class = :processor
277
+ end
278
+ end