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
@@ -12,6 +12,11 @@ describe Puppet::Application::Inspect do
12
12
 
13
13
  before :each do
14
14
  @inspect = Puppet::Application[:inspect]
15
+ @inspect.preinit
16
+ end
17
+
18
+ it "should operate in agent run_mode" do
19
+ @inspect.class.run_mode.name.should == :agent
15
20
  end
16
21
 
17
22
  describe "during setup" do
@@ -12,14 +12,6 @@ describe Puppet::Configurer::FactHandler do
12
12
  @facthandler = FactHandlerTester.new
13
13
  end
14
14
 
15
- it "should have a method for downloading fact plugins" do
16
- @facthandler.should respond_to(:download_fact_plugins)
17
- end
18
-
19
- it "should have a boolean method for determining whether fact plugins should be downloaded" do
20
- @facthandler.should respond_to(:download_fact_plugins?)
21
- end
22
-
23
15
  it "should download fact plugins when :factsync is true" do
24
16
  Puppet.settings.expects(:value).with(:factsync).returns true
25
17
  @facthandler.should be_download_fact_plugins
@@ -51,46 +43,62 @@ describe Puppet::Configurer::FactHandler do
51
43
  @facthandler.download_fact_plugins
52
44
  end
53
45
 
54
- it "should warn about factsync deprecation when factsync is enabled" do
55
- Puppet::Configurer::Downloader.stubs(:new).returns mock("downloader", :evaluate => nil)
46
+ describe "when finding facts" do
47
+ before :each do
48
+ @facthandler.stubs(:reload_facter)
49
+ Puppet::Node::Facts.indirection.terminus_class = :memory
50
+ end
56
51
 
57
- @facthandler.expects(:download_fact_plugins?).returns true
58
- Puppet.expects(:warning)
59
- @facthandler.download_fact_plugins
60
- end
52
+ it "should use the node name value to retrieve the facts" do
53
+ foo_facts = Puppet::Node::Facts.new('foo')
54
+ bar_facts = Puppet::Node::Facts.new('bar')
55
+ Puppet::Node::Facts.indirection.save(foo_facts)
56
+ Puppet::Node::Facts.indirection.save(bar_facts)
57
+ Puppet[:certname] = 'foo'
58
+ Puppet[:node_name_value] = 'bar'
61
59
 
62
- it "should have a method for retrieving facts" do
63
- @facthandler.should respond_to(:find_facts)
64
- end
60
+ @facthandler.find_facts.should == bar_facts
61
+ end
65
62
 
66
- it "should use the Facts class with the :certname to find the facts" do
67
- Puppet.settings.expects(:value).with(:certname).returns "foo"
68
- Puppet::Node::Facts.indirection.expects(:find).with("foo").returns "myfacts"
69
- @facthandler.stubs(:reload_facter)
70
- @facthandler.find_facts.should == "myfacts"
71
- end
63
+ it "should set the facts name based on the node_name_fact" do
64
+ facts = Puppet::Node::Facts.new(Puppet[:node_name_value], 'my_name_fact' => 'other_node_name')
65
+ Puppet::Node::Facts.indirection.save(facts)
66
+ Puppet[:node_name_fact] = 'my_name_fact'
72
67
 
73
- it "should reload Facter and find local facts when asked to find facts" do
74
- @facthandler.expects(:reload_facter)
68
+ @facthandler.find_facts.name.should == 'other_node_name'
69
+ end
75
70
 
76
- Puppet.settings.expects(:value).with(:certname).returns "myhost"
77
- Puppet::Node::Facts.indirection.expects(:find).with("myhost")
71
+ it "should set the node_name_value based on the node_name_fact" do
72
+ facts = Puppet::Node::Facts.new(Puppet[:node_name_value], 'my_name_fact' => 'other_node_name')
73
+ Puppet::Node::Facts.indirection.save(facts)
74
+ Puppet[:node_name_fact] = 'my_name_fact'
78
75
 
79
- @facthandler.find_facts
80
- end
76
+ @facthandler.find_facts
81
77
 
82
- it "should fail if finding facts fails" do
83
- @facthandler.stubs(:reload_facter)
78
+ Puppet[:node_name_value].should == 'other_node_name'
79
+ end
84
80
 
85
- Puppet.settings.stubs(:value).with(:trace).returns false
86
- Puppet.settings.stubs(:value).with(:certname).returns "myhost"
87
- Puppet::Node::Facts.indirection.expects(:find).raises RuntimeError
81
+ it "should reload Facter before finding facts" do
82
+ @facthandler.expects(:reload_facter)
88
83
 
89
- lambda { @facthandler.find_facts }.should raise_error(Puppet::Error)
84
+ @facthandler.find_facts
85
+ end
86
+
87
+ it "should fail if finding facts fails" do
88
+ Puppet[:trace] = false
89
+ Puppet[:certname] = "myhost"
90
+ Puppet::Node::Facts.indirection.expects(:find).raises RuntimeError
91
+
92
+ lambda { @facthandler.find_facts }.should raise_error(Puppet::Error)
93
+ end
90
94
  end
91
95
 
92
- it "should have a method to prepare the facts for uploading" do
93
- @facthandler.should respond_to(:facts_for_uploading)
96
+ it "should warn about factsync deprecation when factsync is enabled" do
97
+ Puppet::Configurer::Downloader.stubs(:new).returns mock("downloader", :evaluate => nil)
98
+
99
+ @facthandler.expects(:download_fact_plugins?).returns true
100
+ Puppet.expects(:warning)
101
+ @facthandler.download_fact_plugins
94
102
  end
95
103
 
96
104
  # I couldn't get marshal to work for this, only yaml, so we hard-code yaml.
@@ -10,6 +10,10 @@ describe Puppet::Configurer do
10
10
  before do
11
11
  Puppet.settings.stubs(:use).returns(true)
12
12
  @agent = Puppet::Configurer.new
13
+ @agent.stubs(:dostorage)
14
+ Puppet::Util::Storage.stubs(:store)
15
+ Puppet[:server] = "puppetmaster"
16
+ Puppet[:report] = true
13
17
  end
14
18
 
15
19
  it "should include the Plugin Handler module" do
@@ -35,16 +39,16 @@ describe Puppet::Configurer do
35
39
 
36
40
  it "should execute any pre-run command provided via the 'prerun_command' setting" do
37
41
  Puppet.settings[:prerun_command] = "/my/command"
38
- Puppet::Util.expects(:execute).with { |args| args[0] == "/my/command" }
42
+ Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
39
43
 
40
44
  @agent.execute_prerun_command
41
45
  end
42
46
 
43
47
  it "should fail if the command fails" do
44
48
  Puppet.settings[:prerun_command] = "/my/command"
45
- Puppet::Util.expects(:execute).raises Puppet::ExecutionFailure
49
+ Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
46
50
 
47
- lambda { @agent.execute_prerun_command }.should raise_error(Puppet::Configurer::CommandHookError)
51
+ @agent.execute_prerun_command.should be_false
48
52
  end
49
53
  end
50
54
 
@@ -58,469 +62,543 @@ describe Puppet::Configurer do
58
62
 
59
63
  it "should execute any post-run command provided via the 'postrun_command' setting" do
60
64
  Puppet.settings[:postrun_command] = "/my/command"
61
- Puppet::Util.expects(:execute).with { |args| args[0] == "/my/command" }
65
+ Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
62
66
 
63
67
  @agent.execute_postrun_command
64
68
  end
65
69
 
66
70
  it "should fail if the command fails" do
67
71
  Puppet.settings[:postrun_command] = "/my/command"
68
- Puppet::Util.expects(:execute).raises Puppet::ExecutionFailure
72
+ Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
69
73
 
70
- lambda { @agent.execute_postrun_command }.should raise_error(Puppet::Configurer::CommandHookError)
74
+ @agent.execute_postrun_command.should be_false
71
75
  end
72
76
  end
73
- end
74
77
 
75
- describe Puppet::Configurer, "when executing a catalog run" do
76
- before do
77
- Puppet.settings.stubs(:use).returns(true)
78
- @agent = Puppet::Configurer.new
79
- @agent.stubs(:prepare)
80
- @agent.stubs(:facts_for_uploading).returns({})
81
- @catalog = Puppet::Resource::Catalog.new
82
- @catalog.stubs(:apply)
83
- @agent.stubs(:retrieve_catalog).returns @catalog
84
- @agent.stubs(:save_last_run_summary)
85
- Puppet::Transaction::Report.indirection.stubs(:save)
86
- end
78
+ describe "when executing a catalog run" do
79
+ before do
80
+ Puppet.settings.stubs(:use).returns(true)
81
+ @agent.stubs(:prepare)
82
+ Puppet::Node::Facts.indirection.terminus_class = :memory
83
+ @facts = Puppet::Node::Facts.new(Puppet[:node_name_value])
84
+ Puppet::Node::Facts.indirection.save(@facts)
85
+
86
+ @catalog = Puppet::Resource::Catalog.new
87
+ @catalog.stubs(:to_ral).returns(@catalog)
88
+ Puppet::Resource::Catalog.indirection.terminus_class = :rest
89
+ Puppet::Resource::Catalog.indirection.stubs(:find).returns(@catalog)
90
+ @agent.stubs(:send_report)
91
+ @agent.stubs(:save_last_run_summary)
92
+
93
+ Puppet::Util::Log.stubs(:close_all)
94
+ end
87
95
 
88
- it "should prepare for the run" do
89
- @agent.expects(:prepare)
96
+ it "should prepare for the run" do
97
+ @agent.expects(:prepare)
90
98
 
91
- @agent.run
92
- end
99
+ @agent.run
100
+ end
93
101
 
94
- it "should initialize a transaction report if one is not provided" do
95
- report = Puppet::Transaction::Report.new("apply")
96
- Puppet::Transaction::Report.expects(:new).at_least_once.returns report
102
+ it "should initialize a transaction report if one is not provided" do
103
+ report = Puppet::Transaction::Report.new("apply")
104
+ Puppet::Transaction::Report.expects(:new).returns report
97
105
 
98
- @agent.run
99
- end
106
+ @agent.run
107
+ end
100
108
 
101
- it "should pass the new report to the catalog" do
102
- report = Puppet::Transaction::Report.new("apply")
103
- Puppet::Transaction::Report.stubs(:new).returns report
104
- @catalog.expects(:apply).with{|options| options[:report] == report}
109
+ it "should respect node_name_fact when setting the host on a report" do
110
+ Puppet[:node_name_fact] = 'my_name_fact'
111
+ @facts.values = {'my_name_fact' => 'node_name_from_fact'}
105
112
 
106
- @agent.run
107
- end
113
+ @agent.run.host.should == 'node_name_from_fact'
114
+ end
108
115
 
109
- it "should use the provided report if it was passed one" do
110
- report = Puppet::Transaction::Report.new("apply")
111
- Puppet::Transaction::Report.expects(:new).never
112
- @catalog.expects(:apply).with{|options| options[:report] == report}
116
+ it "should pass the new report to the catalog" do
117
+ report = Puppet::Transaction::Report.new("apply")
118
+ Puppet::Transaction::Report.stubs(:new).returns report
119
+ @catalog.expects(:apply).with{|options| options[:report] == report}
113
120
 
114
- @agent.run(:report => report)
115
- end
121
+ @agent.run
122
+ end
116
123
 
117
- it "should set the report as a log destination" do
118
- report = Puppet::Transaction::Report.new("apply")
119
- Puppet::Transaction::Report.expects(:new).returns report
124
+ it "should use the provided report if it was passed one" do
125
+ report = Puppet::Transaction::Report.new("apply")
126
+ Puppet::Transaction::Report.expects(:new).never
127
+ @catalog.expects(:apply).with{|options| options[:report] == report}
120
128
 
121
- @agent.stubs(:send_report)
122
- Puppet::Util::Log.expects(:newdestination).with(report)
129
+ @agent.run(:report => report)
130
+ end
123
131
 
124
- @agent.run
125
- end
132
+ it "should set the report as a log destination" do
133
+ report = Puppet::Transaction::Report.new("apply")
134
+ Puppet::Transaction::Report.expects(:new).returns report
126
135
 
127
- it "should retrieve the catalog" do
128
- @agent.expects(:retrieve_catalog)
136
+ Puppet::Util::Log.expects(:newdestination).with(report)
137
+ Puppet::Util::Log.expects(:close).with(report)
129
138
 
130
- @agent.run
131
- end
139
+ @agent.run
140
+ end
132
141
 
133
- it "should log a failure and do nothing if no catalog can be retrieved" do
134
- @agent.expects(:retrieve_catalog).returns nil
142
+ it "should retrieve the catalog" do
143
+ @agent.expects(:retrieve_catalog)
135
144
 
136
- Puppet.expects(:err).with "Could not retrieve catalog; skipping run"
145
+ @agent.run
146
+ end
137
147
 
138
- @agent.run
139
- end
148
+ it "should log a failure and do nothing if no catalog can be retrieved" do
149
+ @agent.expects(:retrieve_catalog).returns nil
140
150
 
141
- it "should apply the catalog with all options to :run" do
142
- @agent.expects(:retrieve_catalog).returns @catalog
151
+ Puppet.expects(:err).with "Could not retrieve catalog; skipping run"
143
152
 
144
- @catalog.expects(:apply).with { |args| args[:one] == true }
145
- @agent.run :one => true
146
- end
153
+ @agent.run
154
+ end
147
155
 
148
- it "should accept a catalog and use it instead of retrieving a different one" do
149
- @agent.expects(:retrieve_catalog).never
156
+ it "should apply the catalog with all options to :run" do
157
+ @agent.expects(:retrieve_catalog).returns @catalog
150
158
 
151
- @catalog.expects(:apply)
152
- @agent.run :one => true, :catalog => @catalog
153
- end
159
+ @catalog.expects(:apply).with { |args| args[:one] == true }
160
+ @agent.run :one => true
161
+ end
154
162
 
155
- it "should benchmark how long it takes to apply the catalog" do
156
- @agent.expects(:benchmark).with(:notice, "Finished catalog run")
163
+ it "should accept a catalog and use it instead of retrieving a different one" do
164
+ @agent.expects(:retrieve_catalog).never
157
165
 
158
- @agent.expects(:retrieve_catalog).returns @catalog
166
+ @catalog.expects(:apply)
167
+ @agent.run :one => true, :catalog => @catalog
168
+ end
159
169
 
160
- @catalog.expects(:apply).never # because we're not yielding
161
- @agent.run
162
- end
170
+ it "should benchmark how long it takes to apply the catalog" do
171
+ @agent.expects(:benchmark).with(:notice, "Finished catalog run")
163
172
 
164
- it "should execute post-run hooks after the run" do
165
- @agent.expects(:execute_postrun_command)
173
+ @agent.expects(:retrieve_catalog).returns @catalog
166
174
 
167
- @agent.run
168
- end
175
+ @catalog.expects(:apply).never # because we're not yielding
176
+ @agent.run
177
+ end
169
178
 
170
- it "should send the report" do
171
- report = Puppet::Transaction::Report.new("apply")
172
- Puppet::Transaction::Report.expects(:new).returns(report)
173
- @agent.expects(:send_report).with { |r, trans| r == report }
179
+ it "should execute post-run hooks after the run" do
180
+ @agent.expects(:execute_postrun_command)
174
181
 
175
- @agent.run
176
- end
182
+ @agent.run
183
+ end
177
184
 
178
- it "should send the transaction report with a reference to the transaction if a run was actually made" do
179
- report = Puppet::Transaction::Report.new("apply")
180
- Puppet::Transaction::Report.expects(:new).returns(report)
185
+ it "should send the report" do
186
+ report = Puppet::Transaction::Report.new("apply")
187
+ Puppet::Transaction::Report.expects(:new).returns(report)
188
+ @agent.expects(:send_report).with(report)
181
189
 
182
- trans = stub 'transaction'
183
- @catalog.expects(:apply).returns trans
190
+ @agent.run
191
+ end
184
192
 
185
- @agent.expects(:send_report).with { |r, t| t == trans }
193
+ it "should send the transaction report even if the catalog could not be retrieved" do
194
+ @agent.expects(:retrieve_catalog).returns nil
186
195
 
187
- @agent.run :catalog => @catalog
188
- end
196
+ report = Puppet::Transaction::Report.new("apply")
197
+ Puppet::Transaction::Report.expects(:new).returns(report)
198
+ @agent.expects(:send_report)
189
199
 
190
- it "should send the transaction report even if the catalog could not be retrieved" do
191
- @agent.expects(:retrieve_catalog).returns nil
200
+ @agent.run
201
+ end
192
202
 
193
- report = Puppet::Transaction::Report.new("apply")
194
- Puppet::Transaction::Report.expects(:new).returns(report)
195
- @agent.expects(:send_report)
203
+ it "should send the transaction report even if there is a failure" do
204
+ @agent.expects(:retrieve_catalog).raises "whatever"
196
205
 
197
- @agent.run
198
- end
206
+ report = Puppet::Transaction::Report.new("apply")
207
+ Puppet::Transaction::Report.expects(:new).returns(report)
208
+ @agent.expects(:send_report)
199
209
 
200
- it "should send the transaction report even if there is a failure" do
201
- @agent.expects(:retrieve_catalog).raises "whatever"
210
+ @agent.run.should be_nil
211
+ end
202
212
 
203
- report = Puppet::Transaction::Report.new("apply")
204
- Puppet::Transaction::Report.expects(:new).returns(report)
205
- @agent.expects(:send_report)
213
+ it "should remove the report as a log destination when the run is finished" do
214
+ report = Puppet::Transaction::Report.new("apply")
215
+ Puppet::Transaction::Report.expects(:new).returns(report)
206
216
 
207
- lambda { @agent.run }.should raise_error
208
- end
217
+ @agent.run
209
218
 
210
- it "should remove the report as a log destination when the run is finished" do
211
- report = Puppet::Transaction::Report.new("apply")
212
- Puppet::Transaction::Report.expects(:new).returns(report)
219
+ Puppet::Util::Log.destinations.should_not include(report)
220
+ end
213
221
 
214
- report.expects(:<<).at_least_once
222
+ it "should return the report as the result of the run" do
223
+ report = Puppet::Transaction::Report.new("apply")
224
+ Puppet::Transaction::Report.expects(:new).returns(report)
215
225
 
216
- @agent.run
217
- Puppet::Util::Log.destinations.should_not include(report)
218
- end
226
+ @agent.run.should equal(report)
227
+ end
219
228
 
220
- it "should return the report as the result of the run" do
221
- report = Puppet::Transaction::Report.new("apply")
222
- Puppet::Transaction::Report.expects(:new).returns(report)
229
+ it "should send the transaction report even if the pre-run command fails" do
230
+ report = Puppet::Transaction::Report.new("apply")
231
+ Puppet::Transaction::Report.expects(:new).returns(report)
223
232
 
224
- @agent.run.should equal(report)
225
- end
226
- end
233
+ Puppet.settings[:prerun_command] = "/my/command"
234
+ Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
235
+ @agent.expects(:send_report)
227
236
 
228
- describe Puppet::Configurer, "when sending a report" do
229
- include PuppetSpec::Files
237
+ @agent.run.should be_nil
238
+ end
230
239
 
231
- before do
232
- Puppet.settings.stubs(:use).returns(true)
233
- @configurer = Puppet::Configurer.new
234
- Puppet[:lastrunfile] = tmpfile('last_run_file')
240
+ it "should include the pre-run command failure in the report" do
241
+ report = Puppet::Transaction::Report.new("apply")
242
+ Puppet::Transaction::Report.expects(:new).returns(report)
235
243
 
236
- @report = Puppet::Transaction::Report.new("apply")
237
- @trans = stub 'transaction'
238
- end
244
+ Puppet.settings[:prerun_command] = "/my/command"
245
+ Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
239
246
 
240
- it "should finalize the report" do
241
- @report.expects(:finalize_report)
242
- @configurer.send_report(@report, @trans)
243
- end
247
+ report.expects(:<<).with { |log| log.message =~ /^Could not run command from prerun_command/ }
244
248
 
245
- it "should print a report summary if configured to do so" do
246
- Puppet.settings[:summarize] = true
249
+ @agent.run.should be_nil
250
+ end
247
251
 
248
- @report.expects(:summary).returns "stuff"
252
+ it "should send the transaction report even if the post-run command fails" do
253
+ report = Puppet::Transaction::Report.new("apply")
254
+ Puppet::Transaction::Report.expects(:new).returns(report)
249
255
 
250
- @configurer.expects(:puts).with("stuff")
251
- @configurer.send_report(@report, nil)
252
- end
256
+ Puppet.settings[:postrun_command] = "/my/command"
257
+ Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
258
+ @agent.expects(:send_report)
253
259
 
254
- it "should not print a report summary if not configured to do so" do
255
- Puppet.settings[:summarize] = false
260
+ @agent.run.should be_nil
261
+ end
256
262
 
257
- @configurer.expects(:puts).never
258
- @configurer.send_report(@report, nil)
259
- end
263
+ it "should include the post-run command failure in the report" do
264
+ report = Puppet::Transaction::Report.new("apply")
265
+ Puppet::Transaction::Report.expects(:new).returns(report)
260
266
 
261
- it "should save the report if reporting is enabled" do
262
- Puppet.settings[:report] = true
267
+ Puppet.settings[:postrun_command] = "/my/command"
268
+ Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
263
269
 
264
- Puppet::Transaction::Report.indirection.expects(:save).with(@report)
265
- @configurer.send_report(@report, nil)
266
- end
270
+ report.expects(:<<).with { |log| log.message =~ /^Could not run command from postrun_command/ }
267
271
 
268
- it "should not save the report if reporting is disabled" do
269
- Puppet.settings[:report] = false
272
+ @agent.run.should be_nil
273
+ end
270
274
 
271
- Puppet::Transaction::Report.indirection.expects(:save).never
272
- @configurer.send_report(@report, nil)
273
- end
275
+ it "should execute post-run command even if the pre-run command fails" do
276
+ Puppet.settings[:prerun_command] = "/my/precommand"
277
+ Puppet.settings[:postrun_command] = "/my/postcommand"
278
+ Puppet::Util.expects(:execute).with(["/my/precommand"]).raises(Puppet::ExecutionFailure, "Failed")
279
+ Puppet::Util.expects(:execute).with(["/my/postcommand"])
274
280
 
275
- it "should save the last run summary if reporting is enabled" do
276
- Puppet.settings[:report] = true
281
+ @agent.run.should be_nil
282
+ end
277
283
 
278
- @configurer.expects(:save_last_run_summary).with(@report)
279
- @configurer.send_report(@report, nil)
280
- end
284
+ it "should finalize the report" do
285
+ report = Puppet::Transaction::Report.new("apply")
286
+ Puppet::Transaction::Report.expects(:new).returns(report)
281
287
 
282
- it "should save the last run summary if reporting is disabled" do
283
- Puppet.settings[:report] = false
288
+ report.expects(:finalize_report)
289
+ @agent.run
290
+ end
284
291
 
285
- @configurer.expects(:save_last_run_summary).with(@report)
286
- @configurer.send_report(@report, nil)
287
- end
292
+ it "should not apply the catalog if the pre-run command fails" do
293
+ report = Puppet::Transaction::Report.new("apply")
294
+ Puppet::Transaction::Report.expects(:new).returns(report)
288
295
 
289
- it "should log but not fail if saving the report fails" do
290
- Puppet.settings[:report] = true
296
+ Puppet.settings[:prerun_command] = "/my/command"
297
+ Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
291
298
 
292
- Puppet::Transaction::Report.indirection.expects(:save).with(@report).raises "whatever"
299
+ @catalog.expects(:apply).never()
300
+ @agent.expects(:send_report)
293
301
 
294
- Puppet.expects(:err)
295
- lambda { @configurer.send_report(@report, nil) }.should_not raise_error
296
- end
297
- end
302
+ @agent.run.should be_nil
303
+ end
298
304
 
299
- describe Puppet::Configurer, "when saving the summary report file" do
300
- before do
301
- Puppet.settings.stubs(:use).returns(true)
302
- @configurer = Puppet::Configurer.new
305
+ it "should apply the catalog, send the report, and return nil if the post-run command fails" do
306
+ report = Puppet::Transaction::Report.new("apply")
307
+ Puppet::Transaction::Report.expects(:new).returns(report)
303
308
 
304
- @report = stub 'report'
305
- @trans = stub 'transaction'
306
- @lastrunfd = stub 'lastrunfd'
307
- Puppet::Util::FileLocking.stubs(:writelock).yields(@lastrunfd)
308
- end
309
+ Puppet.settings[:postrun_command] = "/my/command"
310
+ Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
309
311
 
310
- it "should write the raw summary to the lastrunfile setting value" do
311
- Puppet::Util::FileLocking.expects(:writelock).with(Puppet[:lastrunfile], 0660)
312
- @configurer.save_last_run_summary(@report)
313
- end
312
+ @catalog.expects(:apply)
313
+ @agent.expects(:send_report)
314
314
 
315
- it "should write the raw summary as yaml" do
316
- @report.expects(:raw_summary).returns("summary")
317
- @lastrunfd.expects(:print).with(YAML.dump("summary"))
318
- @configurer.save_last_run_summary(@report)
319
- end
315
+ @agent.run.should be_nil
316
+ end
320
317
 
321
- it "should log but not fail if saving the last run summary fails" do
322
- Puppet::Util::FileLocking.expects(:writelock).raises "exception"
323
- Puppet.expects(:err)
324
- lambda { @configurer.save_last_run_summary(@report) }.should_not raise_error
318
+ describe "when not using a REST terminus for catalogs" do
319
+ it "should not pass any facts when retrieving the catalog" do
320
+ Puppet::Resource::Catalog.indirection.terminus_class = :compiler
321
+ @agent.expects(:facts_for_uploading).never
322
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options|
323
+ options[:facts].nil?
324
+ }.returns @catalog
325
+
326
+ @agent.run
327
+ end
328
+ end
329
+
330
+ describe "when using a REST terminus for catalogs" do
331
+ it "should pass the prepared facts and the facts format as arguments when retrieving the catalog" do
332
+ Puppet::Resource::Catalog.indirection.terminus_class = :rest
333
+ @agent.expects(:facts_for_uploading).returns(:facts => "myfacts", :facts_format => :foo)
334
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options|
335
+ options[:facts] == "myfacts" and options[:facts_format] == :foo
336
+ }.returns @catalog
337
+
338
+ @agent.run
339
+ end
340
+ end
325
341
  end
326
342
 
327
- end
343
+ describe "when sending a report" do
344
+ include PuppetSpec::Files
328
345
 
329
- describe Puppet::Configurer, "when retrieving a catalog" do
330
- before do
331
- Puppet.settings.stubs(:use).returns(true)
332
- @agent = Puppet::Configurer.new
333
- @agent.stubs(:facts_for_uploading).returns({})
346
+ before do
347
+ Puppet.settings.stubs(:use).returns(true)
348
+ @configurer = Puppet::Configurer.new
349
+ Puppet[:lastrunfile] = tmpfile('last_run_file')
334
350
 
335
- @catalog = Puppet::Resource::Catalog.new
351
+ @report = Puppet::Transaction::Report.new("apply")
352
+ end
336
353
 
337
- # this is the default when using a Configurer instance
338
- Puppet::Resource::Catalog.indirection.stubs(:terminus_class).returns :rest
354
+ it "should print a report summary if configured to do so" do
355
+ Puppet.settings[:summarize] = true
339
356
 
340
- @agent.stubs(:convert_catalog).returns @catalog
341
- end
357
+ @report.expects(:summary).returns "stuff"
342
358
 
343
- describe "and configured to only retrieve a catalog from the cache" do
344
- before do
345
- Puppet.settings[:use_cached_catalog] = true
359
+ @configurer.expects(:puts).with("stuff")
360
+ @configurer.send_report(@report)
346
361
  end
347
362
 
348
- it "should first look in the cache for a catalog" do
349
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
350
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.never
363
+ it "should not print a report summary if not configured to do so" do
364
+ Puppet.settings[:summarize] = false
351
365
 
352
- @agent.retrieve_catalog.should == @catalog
366
+ @configurer.expects(:puts).never
367
+ @configurer.send_report(@report)
353
368
  end
354
369
 
355
- it "should compile a new catalog if none is found in the cache" do
356
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil
357
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
370
+ it "should save the report if reporting is enabled" do
371
+ Puppet.settings[:report] = true
358
372
 
359
- @agent.retrieve_catalog.should == @catalog
373
+ Puppet::Transaction::Report.indirection.expects(:save).with(@report)
374
+ @configurer.send_report(@report)
360
375
  end
361
- end
362
376
 
363
- describe "when not using a REST terminus for catalogs" do
364
- it "should not pass any facts when retrieving the catalog" do
365
- @agent.expects(:facts_for_uploading).never
366
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options|
367
- options[:facts].nil?
368
- }.returns @catalog
377
+ it "should not save the report if reporting is disabled" do
378
+ Puppet.settings[:report] = false
369
379
 
370
- @agent.retrieve_catalog
380
+ Puppet::Transaction::Report.indirection.expects(:save).with(@report).never
381
+ @configurer.send_report(@report)
371
382
  end
372
- end
373
383
 
374
- describe "when using a REST terminus for catalogs" do
375
- it "should pass the prepared facts and the facts format as arguments when retrieving the catalog" do
376
- @agent.expects(:facts_for_uploading).returns(:facts => "myfacts", :facts_format => :foo)
377
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options|
378
- options[:facts] == "myfacts" and options[:facts_format] == :foo
379
- }.returns @catalog
384
+ it "should save the last run summary if reporting is enabled" do
385
+ Puppet.settings[:report] = true
380
386
 
381
- @agent.retrieve_catalog
387
+ @configurer.expects(:save_last_run_summary).with(@report)
388
+ @configurer.send_report(@report)
382
389
  end
383
- end
384
390
 
385
- it "should use the Catalog class to get its catalog" do
386
- Puppet::Resource::Catalog.indirection.expects(:find).returns @catalog
391
+ it "should save the last run summary if reporting is disabled" do
392
+ Puppet.settings[:report] = false
387
393
 
388
- @agent.retrieve_catalog
389
- end
394
+ @configurer.expects(:save_last_run_summary).with(@report)
395
+ @configurer.send_report(@report)
396
+ end
390
397
 
391
- it "should use its certname to retrieve the catalog" do
392
- Facter.stubs(:value).returns "eh"
393
- Puppet.settings[:certname] = "myhost.domain.com"
394
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| name == "myhost.domain.com" }.returns @catalog
398
+ it "should log but not fail if saving the report fails" do
399
+ Puppet.settings[:report] = true
395
400
 
396
- @agent.retrieve_catalog
401
+ Puppet::Transaction::Report.indirection.expects(:save).raises("whatever")
402
+
403
+ Puppet.expects(:err)
404
+ lambda { @configurer.send_report(@report) }.should_not raise_error
405
+ end
397
406
  end
398
407
 
399
- it "should default to returning a catalog retrieved directly from the server, skipping the cache" do
400
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
408
+ describe "when saving the summary report file" do
409
+ before do
410
+ Puppet.settings.stubs(:use).returns(true)
411
+ @configurer = Puppet::Configurer.new
401
412
 
402
- @agent.retrieve_catalog.should == @catalog
403
- end
413
+ @report = stub 'report'
414
+ @trans = stub 'transaction'
415
+ @lastrunfd = stub 'lastrunfd'
416
+ Puppet::Util::FileLocking.stubs(:writelock).yields(@lastrunfd)
417
+ end
404
418
 
405
- it "should log and return the cached catalog when no catalog can be retrieved from the server" do
406
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
407
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
419
+ it "should write the raw summary to the lastrunfile setting value" do
420
+ Puppet::Util::FileLocking.expects(:writelock).with(Puppet[:lastrunfile], 0660)
421
+ @configurer.save_last_run_summary(@report)
422
+ end
408
423
 
409
- Puppet.expects(:notice)
424
+ it "should write the raw summary as yaml" do
425
+ @report.expects(:raw_summary).returns("summary")
426
+ @lastrunfd.expects(:print).with(YAML.dump("summary"))
427
+ @configurer.save_last_run_summary(@report)
428
+ end
429
+
430
+ it "should log but not fail if saving the last run summary fails" do
431
+ Puppet::Util::FileLocking.expects(:writelock).raises "exception"
432
+ Puppet.expects(:err)
433
+ lambda { @configurer.save_last_run_summary(@report) }.should_not raise_error
434
+ end
410
435
 
411
- @agent.retrieve_catalog.should == @catalog
412
436
  end
413
437
 
414
- it "should not look in the cache for a catalog if one is returned from the server" do
415
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
416
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.never
438
+ describe "when retrieving a catalog" do
439
+ before do
440
+ Puppet.settings.stubs(:use).returns(true)
441
+ @agent.stubs(:facts_for_uploading).returns({})
417
442
 
418
- @agent.retrieve_catalog.should == @catalog
419
- end
443
+ @catalog = Puppet::Resource::Catalog.new
420
444
 
421
- it "should return the cached catalog when retrieving the remote catalog throws an exception" do
422
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.raises "eh"
423
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
445
+ # this is the default when using a Configurer instance
446
+ Puppet::Resource::Catalog.indirection.stubs(:terminus_class).returns :rest
424
447
 
425
- @agent.retrieve_catalog.should == @catalog
426
- end
448
+ @agent.stubs(:convert_catalog).returns @catalog
449
+ end
427
450
 
428
- it "should log and return nil if no catalog can be retrieved from the server and :usecacheonfailure is disabled" do
429
- Puppet.stubs(:[])
430
- Puppet.expects(:[]).with(:usecacheonfailure).returns false
431
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
451
+ describe "and configured to only retrieve a catalog from the cache" do
452
+ before do
453
+ Puppet.settings[:use_cached_catalog] = true
454
+ end
432
455
 
433
- Puppet.expects(:warning)
456
+ it "should first look in the cache for a catalog" do
457
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
458
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.never
434
459
 
435
- @agent.retrieve_catalog.should be_nil
436
- end
460
+ @agent.retrieve_catalog({}).should == @catalog
461
+ end
437
462
 
438
- it "should return nil if no cached catalog is available and no catalog can be retrieved from the server" do
439
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
440
- Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil
463
+ it "should compile a new catalog if none is found in the cache" do
464
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil
465
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
441
466
 
442
- @agent.retrieve_catalog.should be_nil
443
- end
467
+ @agent.retrieve_catalog({}).should == @catalog
468
+ end
469
+ end
444
470
 
445
- it "should convert the catalog before returning" do
446
- Puppet::Resource::Catalog.indirection.stubs(:find).returns @catalog
471
+ it "should use the Catalog class to get its catalog" do
472
+ Puppet::Resource::Catalog.indirection.expects(:find).returns @catalog
447
473
 
448
- @agent.expects(:convert_catalog).with { |cat, dur| cat == @catalog }.returns "converted catalog"
449
- @agent.retrieve_catalog.should == "converted catalog"
450
- end
474
+ @agent.retrieve_catalog({})
475
+ end
451
476
 
452
- it "should return nil if there is an error while retrieving the catalog" do
453
- Puppet::Resource::Catalog.indirection.expects(:find).at_least_once.raises "eh"
477
+ it "should use its node_name_value to retrieve the catalog" do
478
+ Facter.stubs(:value).returns "eh"
479
+ Puppet.settings[:node_name_value] = "myhost.domain.com"
480
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| name == "myhost.domain.com" }.returns @catalog
454
481
 
455
- @agent.retrieve_catalog.should be_nil
456
- end
457
- end
482
+ @agent.retrieve_catalog({})
483
+ end
458
484
 
459
- describe Puppet::Configurer, "when converting the catalog" do
460
- before do
461
- Puppet.settings.stubs(:use).returns(true)
462
- @agent = Puppet::Configurer.new
485
+ it "should default to returning a catalog retrieved directly from the server, skipping the cache" do
486
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
463
487
 
464
- @catalog = Puppet::Resource::Catalog.new
465
- @oldcatalog = stub 'old_catalog', :to_ral => @catalog
466
- end
488
+ @agent.retrieve_catalog({}).should == @catalog
489
+ end
467
490
 
468
- it "should convert the catalog to a RAL-formed catalog" do
469
- @oldcatalog.expects(:to_ral).returns @catalog
491
+ it "should log and return the cached catalog when no catalog can be retrieved from the server" do
492
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
493
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
470
494
 
471
- @agent.convert_catalog(@oldcatalog, 10).should equal(@catalog)
472
- end
495
+ Puppet.expects(:notice)
473
496
 
474
- it "should finalize the catalog" do
475
- @catalog.expects(:finalize)
497
+ @agent.retrieve_catalog({}).should == @catalog
498
+ end
476
499
 
477
- @agent.convert_catalog(@oldcatalog, 10)
478
- end
500
+ it "should not look in the cache for a catalog if one is returned from the server" do
501
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
502
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.never
479
503
 
480
- it "should record the passed retrieval time with the RAL catalog" do
481
- @catalog.expects(:retrieval_duration=).with 10
504
+ @agent.retrieve_catalog({}).should == @catalog
505
+ end
482
506
 
483
- @agent.convert_catalog(@oldcatalog, 10)
484
- end
507
+ it "should return the cached catalog when retrieving the remote catalog throws an exception" do
508
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.raises "eh"
509
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
485
510
 
486
- it "should write the RAL catalog's class file" do
487
- @catalog.expects(:write_class_file)
511
+ @agent.retrieve_catalog({}).should == @catalog
512
+ end
488
513
 
489
- @agent.convert_catalog(@oldcatalog, 10)
490
- end
491
- end
514
+ it "should log and return nil if no catalog can be retrieved from the server and :usecacheonfailure is disabled" do
515
+ Puppet.stubs(:[])
516
+ Puppet.expects(:[]).with(:usecacheonfailure).returns false
517
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
492
518
 
493
- describe Puppet::Configurer, "when preparing for a run" do
494
- before do
495
- Puppet.settings.stubs(:use).returns(true)
496
- @agent = Puppet::Configurer.new
497
- @agent.stubs(:dostorage)
498
- @agent.stubs(:download_fact_plugins)
499
- @agent.stubs(:download_plugins)
500
- @agent.stubs(:execute_prerun_command)
501
- @facts = {"one" => "two", "three" => "four"}
502
- end
519
+ Puppet.expects(:warning)
503
520
 
504
- it "should initialize the metadata store" do
505
- @agent.class.stubs(:facts).returns(@facts)
506
- @agent.expects(:dostorage)
507
- @agent.prepare({})
508
- end
521
+ @agent.retrieve_catalog({}).should be_nil
522
+ end
509
523
 
510
- it "should download fact plugins" do
511
- @agent.expects(:download_fact_plugins)
524
+ it "should return nil if no cached catalog is available and no catalog can be retrieved from the server" do
525
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
526
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil
527
+
528
+ @agent.retrieve_catalog({}).should be_nil
529
+ end
530
+
531
+ it "should convert the catalog before returning" do
532
+ Puppet::Resource::Catalog.indirection.stubs(:find).returns @catalog
533
+
534
+ @agent.expects(:convert_catalog).with { |cat, dur| cat == @catalog }.returns "converted catalog"
535
+ @agent.retrieve_catalog({}).should == "converted catalog"
536
+ end
512
537
 
513
- @agent.prepare({})
538
+ it "should return nil if there is an error while retrieving the catalog" do
539
+ Puppet::Resource::Catalog.indirection.expects(:find).at_least_once.raises "eh"
540
+
541
+ @agent.retrieve_catalog({}).should be_nil
542
+ end
514
543
  end
515
544
 
516
- it "should download plugins" do
517
- @agent.expects(:download_plugins)
545
+ describe "when converting the catalog" do
546
+ before do
547
+ Puppet.settings.stubs(:use).returns(true)
548
+
549
+ @catalog = Puppet::Resource::Catalog.new
550
+ @oldcatalog = stub 'old_catalog', :to_ral => @catalog
551
+ end
518
552
 
519
- @agent.prepare({})
553
+ it "should convert the catalog to a RAL-formed catalog" do
554
+ @oldcatalog.expects(:to_ral).returns @catalog
555
+
556
+ @agent.convert_catalog(@oldcatalog, 10).should equal(@catalog)
557
+ end
558
+
559
+ it "should finalize the catalog" do
560
+ @catalog.expects(:finalize)
561
+
562
+ @agent.convert_catalog(@oldcatalog, 10)
563
+ end
564
+
565
+ it "should record the passed retrieval time with the RAL catalog" do
566
+ @catalog.expects(:retrieval_duration=).with 10
567
+
568
+ @agent.convert_catalog(@oldcatalog, 10)
569
+ end
570
+
571
+ it "should write the RAL catalog's class file" do
572
+ @catalog.expects(:write_class_file)
573
+
574
+ @agent.convert_catalog(@oldcatalog, 10)
575
+ end
520
576
  end
521
577
 
522
- it "should perform the pre-run commands" do
523
- @agent.expects(:execute_prerun_command)
524
- @agent.prepare({})
578
+ describe "when preparing for a run" do
579
+ before do
580
+ Puppet.settings.stubs(:use).returns(true)
581
+ @agent.stubs(:download_fact_plugins)
582
+ @agent.stubs(:download_plugins)
583
+ @facts = {"one" => "two", "three" => "four"}
584
+ end
585
+
586
+ it "should initialize the metadata store" do
587
+ @agent.class.stubs(:facts).returns(@facts)
588
+ @agent.expects(:dostorage)
589
+ @agent.prepare({})
590
+ end
591
+
592
+ it "should download fact plugins" do
593
+ @agent.expects(:download_fact_plugins)
594
+
595
+ @agent.prepare({})
596
+ end
597
+
598
+ it "should download plugins" do
599
+ @agent.expects(:download_plugins)
600
+
601
+ @agent.prepare({})
602
+ end
525
603
  end
526
604
  end