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.
- data/CHANGELOG +225 -1
- data/CONTRIBUTING.md +299 -0
- data/README.md +0 -1
- data/conf/redhat/puppet.spec +132 -25
- data/conf/solaris/pkginfo +1 -1
- data/conf/suse/puppet.spec +5 -2
- data/ext/envpuppet +56 -3
- data/ext/vim/README +2 -1
- data/ext/vim/ftplugin/puppet.vim +94 -0
- data/ext/vim/indent/puppet.vim +76 -0
- data/lib/puppet.rb +2 -3
- data/lib/puppet/application/agent.rb +7 -7
- data/lib/puppet/application/apply.rb +20 -8
- data/lib/puppet/application/ca.rb +5 -0
- data/lib/puppet/application/cert.rb +2 -1
- data/lib/puppet/application/certificate.rb +0 -5
- data/lib/puppet/application/device.rb +4 -4
- data/lib/puppet/application/doc.rb +23 -12
- data/lib/puppet/application/face_base.rb +2 -1
- data/lib/puppet/application/inspect.rb +5 -2
- data/lib/puppet/configurer.rb +60 -56
- data/lib/puppet/configurer/fact_handler.rb +6 -1
- data/lib/puppet/defaults.rb +20 -1
- data/lib/puppet/face/ca.rb +233 -0
- data/lib/puppet/face/certificate.rb +15 -11
- data/lib/puppet/face/certificate_request.rb +9 -11
- data/lib/puppet/face/certificate_revocation_list.rb +5 -7
- data/lib/puppet/face/node/clean.rb +154 -0
- data/lib/puppet/face/status.rb +1 -0
- data/lib/puppet/file_serving/configuration/parser.rb +6 -13
- data/lib/puppet/indirector/exec.rb +3 -3
- data/lib/puppet/indirector/face.rb +17 -7
- data/lib/puppet/indirector/report/processor.rb +29 -16
- data/lib/puppet/indirector/rest.rb +42 -7
- data/lib/puppet/indirector/yaml.rb +5 -0
- data/lib/puppet/interface.rb +7 -2
- data/lib/puppet/interface/action.rb +57 -23
- data/lib/puppet/interface/action_manager.rb +10 -5
- data/lib/puppet/interface/face_collection.rb +43 -52
- data/lib/puppet/interface/option.rb +19 -0
- data/lib/puppet/interface/option_builder.rb +13 -0
- data/lib/puppet/interface/option_manager.rb +2 -1
- data/lib/puppet/metatype/manager.rb +7 -20
- data/lib/puppet/module.rb +4 -1
- data/lib/puppet/network/authconfig.rb +3 -1
- data/lib/puppet/network/authstore.rb +14 -5
- data/lib/puppet/network/handler/fileserver.rb +3 -0
- data/lib/puppet/network/http/webrick.rb +1 -1
- data/lib/puppet/network/rest_authconfig.rb +6 -1
- data/lib/puppet/network/rest_authorization.rb +1 -1
- data/lib/puppet/parser/compiler.rb +8 -11
- data/lib/puppet/parser/functions.rb +1 -6
- data/lib/puppet/parser/functions/create_resources.rb +6 -5
- data/lib/puppet/parser/functions/regsubst.rb +26 -0
- data/lib/puppet/parser/functions/shellquote.rb +26 -0
- data/lib/puppet/parser/functions/sprintf.rb +26 -0
- data/lib/puppet/parser/grammar.ra +34 -60
- data/lib/puppet/parser/lexer.rb +5 -5
- data/lib/puppet/parser/parser.rb +913 -1196
- data/lib/puppet/parser/resource.rb +18 -1
- data/lib/puppet/parser/scope.rb +2 -2
- data/lib/puppet/provider/augeas/augeas.rb +42 -17
- data/lib/puppet/provider/mount/parsed.rb +19 -1
- data/lib/puppet/provider/naginator.rb +9 -1
- data/lib/puppet/provider/nameservice/directoryservice.rb +11 -8
- data/lib/puppet/provider/network_device.rb +1 -1
- data/lib/puppet/provider/package/aptitude.rb +1 -0
- data/lib/puppet/provider/package/pacman.rb +94 -0
- data/lib/puppet/provider/ssh_authorized_key/parsed.rb +0 -6
- data/lib/puppet/rails/host.rb +7 -0
- data/lib/puppet/reports/store.rb +15 -0
- data/lib/puppet/resource/catalog.rb +15 -6
- data/lib/puppet/ssl/certificate.rb +6 -0
- data/lib/puppet/ssl/inventory.rb +2 -0
- data/lib/puppet/transaction.rb +9 -17
- data/lib/puppet/transaction/report.rb +3 -3
- data/lib/puppet/type.rb +13 -24
- data/lib/puppet/type/file.rb +8 -2
- data/lib/puppet/type/file/source.rb +2 -2
- data/lib/puppet/type/service.rb +20 -24
- data/lib/puppet/type/ssh_authorized_key.rb +12 -0
- data/lib/puppet/type/user.rb +8 -0
- data/lib/puppet/util.rb +0 -1
- data/lib/puppet/util/network_device.rb +3 -3
- data/lib/puppet/util/settings.rb +1 -1
- data/lib/puppet/util/settings/file_setting.rb +1 -0
- data/lib/semver.rb +65 -0
- data/spec/integration/defaults_spec.rb +23 -1
- data/spec/integration/network/rest_authconfig_spec.rb +145 -0
- data/spec/integration/node/facts_spec.rb +1 -1
- data/spec/integration/parser/functions_spec.rb +1 -1
- data/spec/integration/parser/parser_spec.rb +31 -0
- data/spec/integration/provider/ssh_authorized_key_spec.rb +207 -0
- data/spec/integration/type_spec.rb +11 -0
- data/spec/lib/puppet/face/1.0.0/huzzah.rb +8 -0
- data/spec/lib/puppet/face/huzzah.rb +1 -0
- data/spec/lib/puppet/face/huzzah/obsolete.rb +6 -0
- data/spec/shared_behaviours/things_that_declare_options.rb +115 -3
- data/spec/unit/application/agent_spec.rb +2 -2
- data/spec/unit/application/apply_spec.rb +74 -56
- data/spec/unit/application/cert_spec.rb +10 -0
- data/spec/unit/application/device_spec.rb +2 -3
- data/spec/unit/application/face_base_spec.rb +1 -0
- data/spec/unit/application/facts_spec.rb +1 -0
- data/spec/unit/application/inspect_spec.rb +5 -0
- data/spec/unit/configurer/fact_handler_spec.rb +45 -37
- data/spec/unit/configurer_spec.rb +405 -327
- data/spec/unit/face/ca_spec.rb +355 -0
- data/spec/unit/face/certificate_spec.rb +16 -4
- data/spec/unit/face/node_spec.rb +261 -1
- data/spec/unit/file_serving/configuration/parser_spec.rb +8 -0
- data/spec/unit/indirector/certificate/rest_spec.rb +1 -0
- data/spec/unit/indirector/certificate_status/file_spec.rb +4 -0
- data/spec/unit/indirector/exec_spec.rb +4 -4
- data/spec/unit/indirector/face_spec.rb +3 -1
- data/spec/unit/indirector/facts/couch_spec.rb +2 -2
- data/spec/unit/indirector/facts/network_device_spec.rb +2 -6
- data/spec/unit/indirector/node/exec_spec.rb +1 -1
- data/spec/unit/indirector/report/processor_spec.rb +31 -8
- data/spec/unit/indirector/rest_spec.rb +53 -5
- data/spec/unit/indirector/yaml_spec.rb +18 -0
- data/spec/unit/interface/action_spec.rb +112 -8
- data/spec/unit/interface/face_collection_spec.rb +46 -36
- data/spec/unit/interface/option_spec.rb +44 -0
- data/spec/unit/interface_spec.rb +11 -6
- data/spec/unit/module_spec.rb +38 -9
- data/spec/unit/network/authconfig_spec.rb +23 -0
- data/spec/unit/network/authstore_spec.rb +36 -4
- data/spec/unit/network/handler/fileserver_spec.rb +32 -0
- data/spec/unit/network/rest_authconfig_spec.rb +1 -1
- data/spec/unit/node_spec.rb +1 -0
- data/spec/unit/parser/compiler_spec.rb +8 -46
- data/spec/unit/parser/lexer_spec.rb +27 -17
- data/spec/unit/parser/resource_spec.rb +61 -3
- data/spec/unit/parser/scope_spec.rb +5 -1
- data/spec/unit/provider/augeas/augeas_spec.rb +106 -1
- data/spec/unit/provider/cisco_spec.rb +3 -4
- data/spec/unit/provider/interface/cisco_spec.rb +1 -2
- data/spec/unit/provider/mount/parsed_spec.rb +41 -0
- data/spec/unit/provider/nameservice/directoryservice_spec.rb +60 -0
- data/spec/unit/provider/network_device_spec.rb +1 -2
- data/spec/unit/provider/package/pacman_spec.rb +237 -0
- data/spec/unit/provider/package/pkgutil_spec.rb +2 -3
- data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +21 -32
- data/spec/unit/provider/vlan/cisco_spec.rb +1 -2
- data/spec/unit/rails/host_spec.rb +8 -0
- data/spec/unit/resource/catalog_spec.rb +55 -8
- data/spec/unit/semver_spec.rb +187 -0
- data/spec/unit/ssl/certificate_spec.rb +25 -0
- data/spec/unit/transaction/report_spec.rb +3 -3
- data/spec/unit/transaction_spec.rb +8 -2
- data/spec/unit/type/file_spec.rb +57 -0
- data/spec/unit/type/interface_spec.rb +1 -2
- data/spec/unit/type/schedule_spec.rb +73 -42
- data/spec/unit/type/ssh_authorized_key_spec.rb +180 -70
- data/spec/unit/type/user_spec.rb +8 -0
- data/spec/unit/type/vlan_spec.rb +1 -2
- data/spec/unit/type_spec.rb +66 -0
- data/spec/unit/util/network_device/cisco/device_spec.rb +1 -2
- data/spec/unit/util/network_device/cisco/facts_spec.rb +2 -3
- data/spec/unit/util/network_device/cisco/interface_spec.rb +1 -2
- data/spec/unit/util/network_device/config_spec.rb +3 -4
- data/spec/unit/util/network_device/ipcalc_spec.rb +1 -2
- data/spec/unit/util/network_device/transport/base_spec.rb +1 -2
- data/spec/unit/util/network_device/transport/ssh_spec.rb +1 -2
- data/spec/unit/util/network_device/transport/telnet_spec.rb +1 -2
- data/spec/unit/util/network_device_spec.rb +2 -2
- data/spec/unit/util/settings/file_setting_spec.rb +4 -0
- data/spec/unit/util/settings_spec.rb +11 -0
- data/test/lib/puppettest/railstesting.rb +0 -34
- 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
|
-
|
55
|
-
|
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
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
|
63
|
-
|
64
|
-
end
|
60
|
+
@facthandler.find_facts.should == bar_facts
|
61
|
+
end
|
65
62
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
74
|
-
|
68
|
+
@facthandler.find_facts.name.should == 'other_node_name'
|
69
|
+
end
|
75
70
|
|
76
|
-
|
77
|
-
|
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
|
-
|
80
|
-
end
|
76
|
+
@facthandler.find_facts
|
81
77
|
|
82
|
-
|
83
|
-
|
78
|
+
Puppet[:node_name_value].should == 'other_node_name'
|
79
|
+
end
|
84
80
|
|
85
|
-
|
86
|
-
|
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
|
-
|
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
|
93
|
-
|
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
|
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
|
49
|
+
Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
|
46
50
|
|
47
|
-
|
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
|
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
|
72
|
+
Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
|
69
73
|
|
70
|
-
|
74
|
+
@agent.execute_postrun_command.should be_false
|
71
75
|
end
|
72
76
|
end
|
73
|
-
end
|
74
77
|
|
75
|
-
describe
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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
|
-
|
89
|
-
|
96
|
+
it "should prepare for the run" do
|
97
|
+
@agent.expects(:prepare)
|
90
98
|
|
91
|
-
|
92
|
-
|
99
|
+
@agent.run
|
100
|
+
end
|
93
101
|
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
-
|
99
|
-
|
106
|
+
@agent.run
|
107
|
+
end
|
100
108
|
|
101
|
-
|
102
|
-
|
103
|
-
|
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
|
-
|
107
|
-
|
113
|
+
@agent.run.host.should == 'node_name_from_fact'
|
114
|
+
end
|
108
115
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
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
|
-
|
115
|
-
|
121
|
+
@agent.run
|
122
|
+
end
|
116
123
|
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
-
|
122
|
-
|
129
|
+
@agent.run(:report => report)
|
130
|
+
end
|
123
131
|
|
124
|
-
|
125
|
-
|
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
|
-
|
128
|
-
|
136
|
+
Puppet::Util::Log.expects(:newdestination).with(report)
|
137
|
+
Puppet::Util::Log.expects(:close).with(report)
|
129
138
|
|
130
|
-
|
131
|
-
|
139
|
+
@agent.run
|
140
|
+
end
|
132
141
|
|
133
|
-
|
134
|
-
|
142
|
+
it "should retrieve the catalog" do
|
143
|
+
@agent.expects(:retrieve_catalog)
|
135
144
|
|
136
|
-
|
145
|
+
@agent.run
|
146
|
+
end
|
137
147
|
|
138
|
-
|
139
|
-
|
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
|
-
|
142
|
-
@agent.expects(:retrieve_catalog).returns @catalog
|
151
|
+
Puppet.expects(:err).with "Could not retrieve catalog; skipping run"
|
143
152
|
|
144
|
-
|
145
|
-
|
146
|
-
end
|
153
|
+
@agent.run
|
154
|
+
end
|
147
155
|
|
148
|
-
|
149
|
-
|
156
|
+
it "should apply the catalog with all options to :run" do
|
157
|
+
@agent.expects(:retrieve_catalog).returns @catalog
|
150
158
|
|
151
|
-
|
152
|
-
|
153
|
-
|
159
|
+
@catalog.expects(:apply).with { |args| args[:one] == true }
|
160
|
+
@agent.run :one => true
|
161
|
+
end
|
154
162
|
|
155
|
-
|
156
|
-
|
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
|
-
|
166
|
+
@catalog.expects(:apply)
|
167
|
+
@agent.run :one => true, :catalog => @catalog
|
168
|
+
end
|
159
169
|
|
160
|
-
|
161
|
-
|
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
|
-
|
165
|
-
@agent.expects(:execute_postrun_command)
|
173
|
+
@agent.expects(:retrieve_catalog).returns @catalog
|
166
174
|
|
167
|
-
|
168
|
-
|
175
|
+
@catalog.expects(:apply).never # because we're not yielding
|
176
|
+
@agent.run
|
177
|
+
end
|
169
178
|
|
170
|
-
|
171
|
-
|
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
|
-
|
176
|
-
|
182
|
+
@agent.run
|
183
|
+
end
|
177
184
|
|
178
|
-
|
179
|
-
|
180
|
-
|
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
|
-
|
183
|
-
|
190
|
+
@agent.run
|
191
|
+
end
|
184
192
|
|
185
|
-
|
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
|
-
|
188
|
-
|
196
|
+
report = Puppet::Transaction::Report.new("apply")
|
197
|
+
Puppet::Transaction::Report.expects(:new).returns(report)
|
198
|
+
@agent.expects(:send_report)
|
189
199
|
|
190
|
-
|
191
|
-
|
200
|
+
@agent.run
|
201
|
+
end
|
192
202
|
|
193
|
-
report
|
194
|
-
|
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
|
-
|
198
|
-
|
206
|
+
report = Puppet::Transaction::Report.new("apply")
|
207
|
+
Puppet::Transaction::Report.expects(:new).returns(report)
|
208
|
+
@agent.expects(:send_report)
|
199
209
|
|
200
|
-
|
201
|
-
|
210
|
+
@agent.run.should be_nil
|
211
|
+
end
|
202
212
|
|
203
|
-
report
|
204
|
-
|
205
|
-
|
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
|
-
|
208
|
-
end
|
217
|
+
@agent.run
|
209
218
|
|
210
|
-
|
211
|
-
|
212
|
-
Puppet::Transaction::Report.expects(:new).returns(report)
|
219
|
+
Puppet::Util::Log.destinations.should_not include(report)
|
220
|
+
end
|
213
221
|
|
214
|
-
report
|
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
|
-
|
217
|
-
|
218
|
-
end
|
226
|
+
@agent.run.should equal(report)
|
227
|
+
end
|
219
228
|
|
220
|
-
|
221
|
-
|
222
|
-
|
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
|
-
|
225
|
-
|
226
|
-
|
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
|
-
|
229
|
-
|
237
|
+
@agent.run.should be_nil
|
238
|
+
end
|
230
239
|
|
231
|
-
|
232
|
-
|
233
|
-
|
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
|
-
|
237
|
-
|
238
|
-
end
|
244
|
+
Puppet.settings[:prerun_command] = "/my/command"
|
245
|
+
Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
|
239
246
|
|
240
|
-
|
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
|
-
|
246
|
-
|
249
|
+
@agent.run.should be_nil
|
250
|
+
end
|
247
251
|
|
248
|
-
|
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
|
-
|
251
|
-
|
252
|
-
|
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
|
-
|
255
|
-
|
260
|
+
@agent.run.should be_nil
|
261
|
+
end
|
256
262
|
|
257
|
-
|
258
|
-
|
259
|
-
|
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
|
-
|
262
|
-
|
267
|
+
Puppet.settings[:postrun_command] = "/my/command"
|
268
|
+
Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
|
263
269
|
|
264
|
-
|
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
|
-
|
269
|
-
|
272
|
+
@agent.run.should be_nil
|
273
|
+
end
|
270
274
|
|
271
|
-
|
272
|
-
|
273
|
-
|
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
|
-
|
276
|
-
|
281
|
+
@agent.run.should be_nil
|
282
|
+
end
|
277
283
|
|
278
|
-
|
279
|
-
|
280
|
-
|
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
|
-
|
283
|
-
|
288
|
+
report.expects(:finalize_report)
|
289
|
+
@agent.run
|
290
|
+
end
|
284
291
|
|
285
|
-
|
286
|
-
|
287
|
-
|
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
|
-
|
290
|
-
|
296
|
+
Puppet.settings[:prerun_command] = "/my/command"
|
297
|
+
Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
|
291
298
|
|
292
|
-
|
299
|
+
@catalog.expects(:apply).never()
|
300
|
+
@agent.expects(:send_report)
|
293
301
|
|
294
|
-
|
295
|
-
|
296
|
-
end
|
297
|
-
end
|
302
|
+
@agent.run.should be_nil
|
303
|
+
end
|
298
304
|
|
299
|
-
|
300
|
-
|
301
|
-
|
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
|
-
|
305
|
-
|
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
|
-
|
311
|
-
|
312
|
-
@configurer.save_last_run_summary(@report)
|
313
|
-
end
|
312
|
+
@catalog.expects(:apply)
|
313
|
+
@agent.expects(:send_report)
|
314
314
|
|
315
|
-
|
316
|
-
|
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
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
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
|
-
|
343
|
+
describe "when sending a report" do
|
344
|
+
include PuppetSpec::Files
|
328
345
|
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
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
|
-
|
351
|
+
@report = Puppet::Transaction::Report.new("apply")
|
352
|
+
end
|
336
353
|
|
337
|
-
|
338
|
-
|
354
|
+
it "should print a report summary if configured to do so" do
|
355
|
+
Puppet.settings[:summarize] = true
|
339
356
|
|
340
|
-
|
341
|
-
end
|
357
|
+
@report.expects(:summary).returns "stuff"
|
342
358
|
|
343
|
-
|
344
|
-
|
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
|
349
|
-
Puppet
|
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
|
-
@
|
366
|
+
@configurer.expects(:puts).never
|
367
|
+
@configurer.send_report(@report)
|
353
368
|
end
|
354
369
|
|
355
|
-
it "should
|
356
|
-
Puppet
|
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
|
-
|
373
|
+
Puppet::Transaction::Report.indirection.expects(:save).with(@report)
|
374
|
+
@configurer.send_report(@report)
|
360
375
|
end
|
361
|
-
end
|
362
376
|
|
363
|
-
|
364
|
-
|
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
|
-
@
|
380
|
+
Puppet::Transaction::Report.indirection.expects(:save).with(@report).never
|
381
|
+
@configurer.send_report(@report)
|
371
382
|
end
|
372
|
-
end
|
373
383
|
|
374
|
-
|
375
|
-
|
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
|
-
@
|
387
|
+
@configurer.expects(:save_last_run_summary).with(@report)
|
388
|
+
@configurer.send_report(@report)
|
382
389
|
end
|
383
|
-
end
|
384
390
|
|
385
|
-
|
386
|
-
|
391
|
+
it "should save the last run summary if reporting is disabled" do
|
392
|
+
Puppet.settings[:report] = false
|
387
393
|
|
388
|
-
|
389
|
-
|
394
|
+
@configurer.expects(:save_last_run_summary).with(@report)
|
395
|
+
@configurer.send_report(@report)
|
396
|
+
end
|
390
397
|
|
391
|
-
|
392
|
-
|
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
|
-
|
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
|
-
|
400
|
-
|
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
|
-
|
403
|
-
|
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
|
-
|
406
|
-
|
407
|
-
|
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
|
-
|
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
|
-
|
415
|
-
|
416
|
-
|
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
|
-
|
419
|
-
end
|
443
|
+
@catalog = Puppet::Resource::Catalog.new
|
420
444
|
|
421
|
-
|
422
|
-
|
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
|
-
|
426
|
-
|
448
|
+
@agent.stubs(:convert_catalog).returns @catalog
|
449
|
+
end
|
427
450
|
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
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
|
-
|
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
|
-
|
436
|
-
|
460
|
+
@agent.retrieve_catalog({}).should == @catalog
|
461
|
+
end
|
437
462
|
|
438
|
-
|
439
|
-
|
440
|
-
|
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
|
-
|
443
|
-
|
467
|
+
@agent.retrieve_catalog({}).should == @catalog
|
468
|
+
end
|
469
|
+
end
|
444
470
|
|
445
|
-
|
446
|
-
|
471
|
+
it "should use the Catalog class to get its catalog" do
|
472
|
+
Puppet::Resource::Catalog.indirection.expects(:find).returns @catalog
|
447
473
|
|
448
|
-
|
449
|
-
|
450
|
-
end
|
474
|
+
@agent.retrieve_catalog({})
|
475
|
+
end
|
451
476
|
|
452
|
-
|
453
|
-
|
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
|
-
|
456
|
-
|
457
|
-
end
|
482
|
+
@agent.retrieve_catalog({})
|
483
|
+
end
|
458
484
|
|
459
|
-
|
460
|
-
|
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
|
-
|
465
|
-
|
466
|
-
end
|
488
|
+
@agent.retrieve_catalog({}).should == @catalog
|
489
|
+
end
|
467
490
|
|
468
|
-
|
469
|
-
|
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
|
-
|
472
|
-
end
|
495
|
+
Puppet.expects(:notice)
|
473
496
|
|
474
|
-
|
475
|
-
|
497
|
+
@agent.retrieve_catalog({}).should == @catalog
|
498
|
+
end
|
476
499
|
|
477
|
-
|
478
|
-
|
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
|
-
|
481
|
-
|
504
|
+
@agent.retrieve_catalog({}).should == @catalog
|
505
|
+
end
|
482
506
|
|
483
|
-
|
484
|
-
|
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
|
-
|
487
|
-
|
511
|
+
@agent.retrieve_catalog({}).should == @catalog
|
512
|
+
end
|
488
513
|
|
489
|
-
|
490
|
-
|
491
|
-
|
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
|
-
|
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
|
-
|
505
|
-
|
506
|
-
@agent.expects(:dostorage)
|
507
|
-
@agent.prepare({})
|
508
|
-
end
|
521
|
+
@agent.retrieve_catalog({}).should be_nil
|
522
|
+
end
|
509
523
|
|
510
|
-
|
511
|
-
|
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
|
-
|
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
|
-
|
517
|
-
|
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
|
-
|
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
|
-
|
523
|
-
|
524
|
-
|
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
|