puppet 5.5.17-x86-mingw32 → 5.5.18-x86-mingw32
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.
- checksums.yaml +4 -4
- data/CODEOWNERS +1 -1
- data/Gemfile +2 -3
- data/Gemfile.lock +35 -31
- data/ext/build_defaults.yaml +1 -0
- data/ext/cert_inspector +3 -3
- data/ext/puppet-test +2 -2
- data/ext/regexp_nodes/regexp_nodes.rb +4 -4
- data/ext/windows/service/daemon.rb +54 -8
- data/install.rb +6 -6
- data/lib/puppet/application.rb +1 -1
- data/lib/puppet/application/apply.rb +2 -2
- data/lib/puppet/application/describe.rb +3 -9
- data/lib/puppet/application/doc.rb +1 -1
- data/lib/puppet/application/lookup.rb +1 -1
- data/lib/puppet/application/script.rb +2 -2
- data/lib/puppet/configurer.rb +86 -28
- data/lib/puppet/configurer/downloader.rb +2 -6
- data/lib/puppet/defaults.rb +17 -4
- data/lib/puppet/error.rb +9 -1
- data/lib/puppet/external/nagios/base.rb +1 -1
- data/lib/puppet/face/ca.rb +1 -1
- data/lib/puppet/face/module/list.rb +5 -5
- data/lib/puppet/face/module/search.rb +1 -1
- data/lib/puppet/face/module/uninstall.rb +1 -1
- data/lib/puppet/face/module/upgrade.rb +1 -1
- data/lib/puppet/file_serving/http_metadata.rb +1 -1
- data/lib/puppet/file_system.rb +0 -8
- data/lib/puppet/file_system/memory_file.rb +1 -1
- data/lib/puppet/file_system/posix.rb +3 -2
- data/lib/puppet/forge.rb +3 -3
- data/lib/puppet/functions/epp.rb +4 -4
- data/lib/puppet/functions/inline_epp.rb +5 -5
- data/lib/puppet/gettext/module_translations.rb +1 -1
- data/lib/puppet/graph/rb_tree_map.rb +2 -2
- data/lib/puppet/graph/simple_graph.rb +6 -5
- data/lib/puppet/indirector/file_bucket_file/file.rb +1 -1
- data/lib/puppet/indirector/hiera.rb +2 -0
- data/lib/puppet/indirector/resource/ral.rb +1 -3
- data/lib/puppet/indirector/resource/validator.rb +1 -1
- data/lib/puppet/interface.rb +2 -1
- data/lib/puppet/loaders.rb +0 -1
- data/lib/puppet/metatype/manager.rb +1 -1
- data/lib/puppet/module.rb +1 -1
- data/lib/puppet/module_tool/applications/builder.rb +1 -1
- data/lib/puppet/module_tool/applications/installer.rb +1 -1
- data/lib/puppet/module_tool/applications/uninstaller.rb +3 -3
- data/lib/puppet/module_tool/metadata.rb +1 -1
- data/lib/puppet/module_tool/shared_behaviors.rb +4 -4
- data/lib/puppet/module_tool/tar/mini.rb +1 -1
- data/lib/puppet/network/http/api/indirected_routes.rb +12 -11
- data/lib/puppet/network/http/connection.rb +10 -12
- data/lib/puppet/network/http/pool.rb +2 -0
- data/lib/puppet/network/http/rack/rest.rb +2 -2
- data/lib/puppet/network/http/site.rb +1 -1
- data/lib/puppet/network/resolver.rb +2 -2
- data/lib/puppet/node/environment.rb +4 -2
- data/lib/puppet/parser/ast.rb +1 -1
- data/lib/puppet/parser/ast/resourceparam.rb +1 -1
- data/lib/puppet/parser/functions.rb +1 -1
- data/lib/puppet/parser/functions/epp.rb +3 -3
- data/lib/puppet/parser/functions/inline_epp.rb +5 -5
- data/lib/puppet/pops/evaluator/collectors/catalog_collector.rb +1 -1
- data/lib/puppet/pops/evaluator/collectors/exported_collector.rb +1 -1
- data/lib/puppet/pops/evaluator/external_syntax_support.rb +3 -2
- data/lib/puppet/pops/evaluator/runtime3_support.rb +4 -4
- data/lib/puppet/pops/loaders.rb +1 -1
- data/lib/puppet/pops/lookup/hiera_config.rb +1 -0
- data/lib/puppet/pops/lookup/sub_lookup.rb +1 -1
- data/lib/puppet/pops/merge_strategy.rb +22 -18
- data/lib/puppet/pops/parser/heredoc_support.rb +1 -1
- data/lib/puppet/pops/parser/interpolation_support.rb +4 -4
- data/lib/puppet/pops/parser/locator.rb +1 -1
- data/lib/puppet/pops/parser/pn_parser.rb +17 -16
- data/lib/puppet/pops/puppet_stack.rb +51 -48
- data/lib/puppet/pops/types/p_sensitive_type.rb +1 -1
- data/lib/puppet/pops/types/string_converter.rb +10 -10
- data/lib/puppet/pops/types/types.rb +3 -3
- data/lib/puppet/property.rb +1 -1
- data/lib/puppet/property/ensure.rb +1 -1
- data/lib/puppet/provider/augeas/augeas.rb +1 -1
- data/lib/puppet/provider/cron/crontab.rb +1 -1
- data/lib/puppet/provider/exec.rb +6 -2
- data/lib/puppet/provider/mount.rb +1 -1
- data/lib/puppet/provider/mount/parsed.rb +8 -8
- data/lib/puppet/provider/nameservice/directoryservice.rb +1 -1
- data/lib/puppet/provider/nameservice/pw.rb +2 -2
- data/lib/puppet/provider/package/dnfmodule.rb +87 -0
- data/lib/puppet/provider/package/dpkg.rb +3 -12
- data/lib/puppet/provider/package/openbsd.rb +1 -1
- data/lib/puppet/provider/package/pip.rb +34 -9
- data/lib/puppet/provider/package/portage.rb +4 -4
- data/lib/puppet/provider/package/rpm.rb +6 -6
- data/lib/puppet/provider/package/windows/package.rb +1 -1
- data/lib/puppet/provider/package/yum.rb +1 -1
- data/lib/puppet/provider/package_targetable.rb +5 -4
- data/lib/puppet/provider/parsedfile.rb +1 -1
- data/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +3 -3
- data/lib/puppet/provider/service/daemontools.rb +9 -9
- data/lib/puppet/provider/service/openbsd.rb +1 -1
- data/lib/puppet/provider/service/rcng.rb +2 -2
- data/lib/puppet/provider/service/runit.rb +2 -8
- data/lib/puppet/provider/service/systemd.rb +8 -8
- data/lib/puppet/provider/user/directoryservice.rb +1 -1
- data/lib/puppet/provider/user/hpux.rb +1 -1
- data/lib/puppet/provider/user/user_role_add.rb +1 -1
- data/lib/puppet/provider/user/useradd.rb +22 -13
- data/lib/puppet/provider/user/windows_adsi.rb +4 -5
- data/lib/puppet/provider/yumrepo/inifile.rb +2 -2
- data/lib/puppet/reference/indirection.rb +2 -2
- data/lib/puppet/reference/metaparameter.rb +1 -3
- data/lib/puppet/reference/providers.rb +1 -1
- data/lib/puppet/reference/type.rb +3 -9
- data/lib/puppet/reports.rb +1 -1
- data/lib/puppet/resource.rb +1 -1
- data/lib/puppet/resource/catalog.rb +1 -1
- data/lib/puppet/settings.rb +3 -3
- data/lib/puppet/settings/environment_conf.rb +1 -0
- data/lib/puppet/ssl/certificate_authority/interface.rb +1 -1
- data/lib/puppet/ssl/certificate_factory.rb +2 -2
- data/lib/puppet/ssl/host.rb +3 -3
- data/lib/puppet/ssl/oids.rb +1 -1
- data/lib/puppet/transaction/report.rb +1 -1
- data/lib/puppet/type.rb +2 -4
- data/lib/puppet/type/cron.rb +1 -1
- data/lib/puppet/type/exec.rb +7 -3
- data/lib/puppet/type/file.rb +1 -2
- data/lib/puppet/type/file/data_sync.rb +5 -1
- data/lib/puppet/type/group.rb +4 -2
- data/lib/puppet/type/interface.rb +1 -1
- data/lib/puppet/type/notify.rb +3 -2
- data/lib/puppet/type/package.rb +2 -2
- data/lib/puppet/type/schedule.rb +1 -1
- data/lib/puppet/type/selboolean.rb +17 -3
- data/lib/puppet/type/service.rb +1 -1
- data/lib/puppet/type/user.rb +4 -2
- data/lib/puppet/util.rb +35 -12
- data/lib/puppet/util/command_line/trollop.rb +1 -1
- data/lib/puppet/util/http_proxy.rb +8 -14
- data/lib/puppet/util/instance_loader.rb +1 -1
- data/lib/puppet/util/log.rb +1 -1
- data/lib/puppet/util/log/destinations.rb +2 -2
- data/lib/puppet/util/logging.rb +30 -18
- data/lib/puppet/util/metric.rb +2 -2
- data/lib/puppet/util/monkey_patches.rb +1 -1
- data/lib/puppet/util/nagios_maker.rb +2 -2
- data/lib/puppet/util/network_device/cisco/device.rb +1 -1
- data/lib/puppet/util/network_device/cisco/interface.rb +2 -2
- data/lib/puppet/util/network_device/transport/ssh.rb +1 -1
- data/lib/puppet/util/provider_features.rb +2 -4
- data/lib/puppet/util/rdoc.rb +1 -1
- data/lib/puppet/util/reference.rb +1 -1
- data/lib/puppet/util/resource_template.rb +1 -1
- data/lib/puppet/util/selinux.rb +3 -1
- data/lib/puppet/util/windows/adsi.rb +58 -28
- data/lib/puppet/util/windows/registry.rb +7 -5
- data/lib/puppet/vendor.rb +1 -1
- data/lib/puppet/version.rb +1 -1
- data/lib/puppet_pal.rb +2 -2
- data/locales/puppet.pot +115 -95
- data/man/man5/puppet.conf.5 +21 -5
- data/man/man8/puppet-agent.8 +1 -1
- data/man/man8/puppet-apply.8 +1 -1
- data/man/man8/puppet-ca.8 +1 -1
- data/man/man8/puppet-catalog.8 +1 -1
- data/man/man8/puppet-cert.8 +1 -1
- data/man/man8/puppet-certificate.8 +1 -1
- data/man/man8/puppet-certificate_request.8 +1 -1
- data/man/man8/puppet-certificate_revocation_list.8 +1 -1
- data/man/man8/puppet-config.8 +1 -1
- data/man/man8/puppet-describe.8 +1 -1
- data/man/man8/puppet-device.8 +1 -1
- data/man/man8/puppet-doc.8 +1 -1
- data/man/man8/puppet-epp.8 +1 -1
- data/man/man8/puppet-facts.8 +1 -1
- data/man/man8/puppet-filebucket.8 +1 -1
- data/man/man8/puppet-generate.8 +1 -1
- data/man/man8/puppet-help.8 +1 -1
- data/man/man8/puppet-key.8 +1 -1
- data/man/man8/puppet-lookup.8 +1 -1
- data/man/man8/puppet-man.8 +1 -1
- data/man/man8/puppet-master.8 +1 -1
- data/man/man8/puppet-module.8 +1 -1
- data/man/man8/puppet-node.8 +1 -1
- data/man/man8/puppet-parser.8 +1 -1
- data/man/man8/puppet-plugin.8 +1 -1
- data/man/man8/puppet-report.8 +1 -1
- data/man/man8/puppet-resource.8 +1 -1
- data/man/man8/puppet-script.8 +1 -1
- data/man/man8/puppet-status.8 +1 -1
- data/man/man8/puppet.8 +2 -2
- data/spec/fixtures/unit/provider/package/dnfmodule/dnf-module-list-installed.txt +11 -0
- data/spec/integration/configurer_spec.rb +52 -0
- data/spec/integration/type/notify_spec.rb +46 -0
- data/spec/unit/configurer_spec.rb +380 -397
- data/spec/unit/forge/forge_spec.rb +1 -3
- data/spec/unit/forge/repository_spec.rb +1 -3
- data/spec/unit/indirector/resource/ral_spec.rb +4 -4
- data/spec/unit/network/http/connection_spec.rb +26 -0
- data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +8 -3
- data/spec/unit/provider/exec_spec.rb +209 -0
- data/spec/unit/provider/package/dnfmodule_spec.rb +186 -0
- data/spec/unit/provider/package/dpkg_spec.rb +15 -3
- data/spec/unit/provider/package/pip_spec.rb +51 -6
- data/spec/unit/provider/package/portage_spec.rb +4 -4
- data/spec/unit/provider/package_targetable_spec.rb +60 -0
- data/spec/unit/provider/service/daemontools_spec.rb +24 -0
- data/spec/unit/provider/service/runit_spec.rb +24 -0
- data/spec/unit/provider/service/systemd_spec.rb +22 -22
- data/spec/unit/provider/user/hpux_spec.rb +2 -2
- data/spec/unit/provider/user/useradd_spec.rb +46 -0
- data/spec/unit/type/exec_spec.rb +6 -12
- data/spec/unit/type/file/content_spec.rb +9 -3
- data/spec/unit/type/file_spec.rb +9 -4
- data/spec/unit/type/selboolean_spec.rb +4 -6
- data/spec/unit/util/execution_spec.rb +16 -0
- data/spec/unit/util/http_proxy_spec.rb +97 -0
- data/spec/unit/util/log/destinations_spec.rb +7 -3
- data/spec/unit/util/log_spec.rb +0 -138
- data/spec/unit/util/logging_spec.rb +200 -0
- data/spec/unit/util/windows/adsi_spec.rb +51 -0
- data/tasks/manpages.rake +1 -0
- metadata +12 -5
- data/lib/puppet/pops/loader/null_loader.rb +0 -60
- data/locales/ja/puppet.po +0 -12114
@@ -1,108 +1,92 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'puppet/configurer'
|
3
|
+
require 'webmock/rspec'
|
3
4
|
|
4
5
|
describe Puppet::Configurer do
|
5
6
|
before do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
allow(Puppet::Util::Storage).to receive(:store)
|
7
|
+
Puppet::Node::Facts.indirection.terminus_class = :memory
|
8
|
+
Puppet::Node::Facts.indirection.save(facts)
|
9
|
+
|
10
10
|
Puppet[:server] = "puppetmaster"
|
11
11
|
Puppet[:report] = true
|
12
|
-
end
|
13
12
|
|
14
|
-
|
15
|
-
|
13
|
+
catalog.add_resource(resource)
|
14
|
+
|
15
|
+
allow(Puppet::SSL::Host).to receive(:localhost).and_return(double('host'))
|
16
16
|
end
|
17
17
|
|
18
|
+
let(:configurer) { Puppet::Configurer.new }
|
19
|
+
let(:report) { Puppet::Transaction::Report.new }
|
20
|
+
let(:catalog) { Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote(Puppet[:environment].to_sym)) }
|
21
|
+
let(:resource) { Puppet::Resource.new(:notice, 'a') }
|
22
|
+
let(:facts) { Puppet::Node::Facts.new(Puppet[:node_name_value]) }
|
23
|
+
|
18
24
|
describe "when executing a pre-run hook" do
|
19
25
|
it "should do nothing if the hook is set to an empty string" do
|
20
26
|
Puppet.settings[:prerun_command] = ""
|
21
|
-
expect(Puppet::Util).not_to receive(:
|
27
|
+
expect(Puppet::Util::Execution).not_to receive(:execute)
|
22
28
|
|
23
|
-
|
29
|
+
configurer.execute_prerun_command
|
24
30
|
end
|
25
31
|
|
26
32
|
it "should execute any pre-run command provided via the 'prerun_command' setting" do
|
27
33
|
Puppet.settings[:prerun_command] = "/my/command"
|
28
34
|
expect(Puppet::Util::Execution).to receive(:execute).with(["/my/command"]).and_raise(Puppet::ExecutionFailure, "Failed")
|
29
35
|
|
30
|
-
|
36
|
+
configurer.execute_prerun_command
|
31
37
|
end
|
32
38
|
|
33
39
|
it "should fail if the command fails" do
|
34
40
|
Puppet.settings[:prerun_command] = "/my/command"
|
35
41
|
expect(Puppet::Util::Execution).to receive(:execute).with(["/my/command"]).and_raise(Puppet::ExecutionFailure, "Failed")
|
36
42
|
|
37
|
-
expect(
|
43
|
+
expect(configurer.execute_prerun_command).to be_falsey
|
38
44
|
end
|
39
45
|
end
|
40
46
|
|
41
47
|
describe "when executing a post-run hook" do
|
42
48
|
it "should do nothing if the hook is set to an empty string" do
|
43
49
|
Puppet.settings[:postrun_command] = ""
|
44
|
-
expect(Puppet::Util).not_to receive(:
|
50
|
+
expect(Puppet::Util::Execution).not_to receive(:execute)
|
45
51
|
|
46
|
-
|
52
|
+
configurer.execute_postrun_command
|
47
53
|
end
|
48
54
|
|
49
55
|
it "should execute any post-run command provided via the 'postrun_command' setting" do
|
50
56
|
Puppet.settings[:postrun_command] = "/my/command"
|
51
57
|
expect(Puppet::Util::Execution).to receive(:execute).with(["/my/command"]).and_raise(Puppet::ExecutionFailure, "Failed")
|
52
58
|
|
53
|
-
|
59
|
+
configurer.execute_postrun_command
|
54
60
|
end
|
55
61
|
|
56
62
|
it "should fail if the command fails" do
|
57
63
|
Puppet.settings[:postrun_command] = "/my/command"
|
58
64
|
expect(Puppet::Util::Execution).to receive(:execute).with(["/my/command"]).and_raise(Puppet::ExecutionFailure, "Failed")
|
59
65
|
|
60
|
-
expect(
|
66
|
+
expect(configurer.execute_postrun_command).to be_falsey
|
61
67
|
end
|
62
68
|
end
|
63
69
|
|
64
70
|
describe "when executing a catalog run" do
|
65
71
|
before do
|
66
|
-
allow(Puppet.settings).to receive(:use).and_return(true)
|
67
|
-
allow(@agent).to receive(:download_plugins)
|
68
|
-
Puppet::Node::Facts.indirection.terminus_class = :memory
|
69
|
-
@facts = Puppet::Node::Facts.new(Puppet[:node_name_value])
|
70
|
-
Puppet::Node::Facts.indirection.save(@facts)
|
71
|
-
|
72
|
-
@catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote(Puppet[:environment].to_sym))
|
73
|
-
allow(@catalog).to receive(:to_ral).and_return(@catalog)
|
74
72
|
Puppet::Resource::Catalog.indirection.terminus_class = :rest
|
75
|
-
allow(Puppet::Resource::Catalog.indirection).to receive(:find).and_return(
|
76
|
-
allow(@agent).to receive(:send_report)
|
77
|
-
allow(@agent).to receive(:save_last_run_summary)
|
78
|
-
|
79
|
-
allow(Puppet::Util::Log).to receive(:close_all)
|
80
|
-
end
|
81
|
-
|
82
|
-
after :all do
|
83
|
-
Puppet::Node::Facts.indirection.reset_terminus_class
|
84
|
-
Puppet::Resource::Catalog.indirection.reset_terminus_class
|
85
|
-
end
|
86
|
-
|
87
|
-
it "should initialize storage" do
|
88
|
-
expect(Puppet::Util::Storage).to receive(:load)
|
89
|
-
@agent.run
|
73
|
+
allow(Puppet::Resource::Catalog.indirection).to receive(:find).and_return(catalog)
|
90
74
|
end
|
91
75
|
|
92
76
|
it "downloads plugins when told" do
|
93
|
-
expect(
|
94
|
-
|
77
|
+
expect(configurer).to receive(:download_plugins)
|
78
|
+
configurer.run(:pluginsync => true)
|
95
79
|
end
|
96
80
|
|
97
81
|
it "does not download plugins when told" do
|
98
|
-
expect(
|
99
|
-
|
82
|
+
expect(configurer).not_to receive(:download_plugins)
|
83
|
+
configurer.run(:pluginsync => false)
|
100
84
|
end
|
101
85
|
|
102
86
|
it "should carry on when it can't fetch its node definition" do
|
103
87
|
error = Net::HTTPError.new(400, 'dummy server communication error')
|
104
88
|
expect(Puppet::Node.indirection).to receive(:find).and_raise(error)
|
105
|
-
expect(
|
89
|
+
expect(configurer.run).to eq(0)
|
106
90
|
end
|
107
91
|
|
108
92
|
it "applies a cached catalog when it can't connect to the master" do
|
@@ -110,200 +94,157 @@ describe Puppet::Configurer do
|
|
110
94
|
|
111
95
|
expect(Puppet::Node.indirection).to receive(:find).and_raise(error)
|
112
96
|
expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(:ignore_cache => true)).and_raise(error)
|
113
|
-
expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(:ignore_terminus => true)).and_return(
|
97
|
+
expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(:ignore_terminus => true)).and_return(catalog)
|
114
98
|
|
115
|
-
expect(
|
99
|
+
expect(configurer.run).to eq(0)
|
116
100
|
end
|
117
101
|
|
118
102
|
it "should initialize a transaction report if one is not provided" do
|
119
|
-
report = Puppet::Transaction::Report.new
|
120
103
|
expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
|
121
104
|
|
122
|
-
|
105
|
+
configurer.run
|
123
106
|
end
|
124
107
|
|
125
108
|
it "should respect node_name_fact when setting the host on a report" do
|
126
109
|
Puppet[:node_name_fact] = 'my_name_fact'
|
127
|
-
|
128
|
-
|
129
|
-
report = Puppet::Transaction::Report.new
|
110
|
+
facts.values = {'my_name_fact' => 'node_name_from_fact'}
|
111
|
+
Puppet::Node::Facts.indirection.save(facts)
|
130
112
|
|
131
|
-
|
113
|
+
configurer.run(:report => report)
|
132
114
|
expect(report.host).to eq('node_name_from_fact')
|
133
115
|
end
|
134
116
|
|
135
|
-
it "
|
136
|
-
|
137
|
-
|
138
|
-
expect(@catalog).to receive(:apply).with(hash_including(report: report))
|
139
|
-
|
140
|
-
@agent.run
|
141
|
-
end
|
142
|
-
|
143
|
-
it "should use the provided report if it was passed one" do
|
144
|
-
report = Puppet::Transaction::Report.new
|
145
|
-
expect(@catalog).to receive(:apply).with(hash_including(report: report))
|
146
|
-
|
147
|
-
@agent.run(:report => report)
|
148
|
-
end
|
149
|
-
|
150
|
-
it "should set the report as a log destination" do
|
151
|
-
report = Puppet::Transaction::Report.new
|
152
|
-
|
153
|
-
expect(report).to receive(:<<).with(instance_of(Puppet::Util::Log)).at_least(:once)
|
117
|
+
it "creates a new report when applying the catalog" do
|
118
|
+
options = {}
|
119
|
+
configurer.run(options)
|
154
120
|
|
155
|
-
|
121
|
+
expect(options[:report].metrics['time']['catalog_application']).to be_an_instance_of(Float)
|
156
122
|
end
|
157
123
|
|
158
|
-
it "
|
159
|
-
|
124
|
+
it "uses the provided report when applying the catalog" do
|
125
|
+
configurer.run(:report => report)
|
160
126
|
|
161
|
-
|
127
|
+
expect(report.metrics['time']['catalog_application']).to be_an_instance_of(Float)
|
162
128
|
end
|
163
129
|
|
164
130
|
it "should log a failure and do nothing if no catalog can be retrieved" do
|
165
|
-
expect(
|
131
|
+
expect(configurer).to receive(:retrieve_catalog).and_return(nil)
|
166
132
|
|
167
133
|
expect(Puppet).to receive(:err).with("Could not retrieve catalog; skipping run")
|
168
134
|
|
169
|
-
|
170
|
-
end
|
171
|
-
|
172
|
-
it "should apply the catalog with all options to :run" do
|
173
|
-
expect(@agent).to receive(:retrieve_catalog).and_return(@catalog)
|
174
|
-
|
175
|
-
expect(@catalog).to receive(:apply).with(hash_including(one: true))
|
176
|
-
@agent.run :one => true
|
135
|
+
configurer.run
|
177
136
|
end
|
178
137
|
|
179
|
-
it "
|
180
|
-
expect(
|
138
|
+
it "passes arbitrary options when applying the catalog" do
|
139
|
+
expect(catalog).to receive(:apply).with(hash_including(one: true))
|
181
140
|
|
182
|
-
|
183
|
-
@agent.run :one => true, :catalog => @catalog
|
141
|
+
configurer.run(catalog: catalog, one: true)
|
184
142
|
end
|
185
143
|
|
186
144
|
it "should benchmark how long it takes to apply the catalog" do
|
187
|
-
|
188
|
-
|
189
|
-
expect(@agent).to receive(:retrieve_catalog).and_return(@catalog)
|
190
|
-
|
191
|
-
expect(@catalog).not_to receive(:apply) # because we're not yielding
|
192
|
-
@agent.run
|
193
|
-
end
|
145
|
+
configurer.run(report: report)
|
194
146
|
|
195
|
-
|
196
|
-
expect(@agent).to receive(:execute_postrun_command)
|
197
|
-
|
198
|
-
@agent.run
|
147
|
+
expect(report.logs).to include(an_object_having_attributes(level: :notice, message: /Applied catalog in .* seconds/))
|
199
148
|
end
|
200
149
|
|
201
150
|
it "should create report with passed transaction_uuid and job_id" do
|
202
|
-
|
203
|
-
allow(@agent).to receive(:init_storage)
|
151
|
+
configurer = Puppet::Configurer.new("test_tuuid", "test_jid")
|
204
152
|
|
205
153
|
report = Puppet::Transaction::Report.new(nil, "test", "aaaa")
|
206
154
|
expect(Puppet::Transaction::Report).to receive(:new).with(anything, anything, 'test_tuuid', 'test_jid').and_return(report)
|
207
|
-
expect(
|
155
|
+
expect(configurer).to receive(:send_report).with(report)
|
208
156
|
|
209
|
-
|
157
|
+
configurer.run
|
210
158
|
end
|
211
159
|
|
212
160
|
it "should send the report" do
|
213
161
|
report = Puppet::Transaction::Report.new(nil, "test", "aaaa")
|
214
162
|
expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
|
215
|
-
expect(
|
163
|
+
expect(configurer).to receive(:send_report).with(report)
|
216
164
|
|
217
165
|
expect(report.environment).to eq("test")
|
218
166
|
expect(report.transaction_uuid).to eq("aaaa")
|
219
167
|
|
220
|
-
|
168
|
+
configurer.run
|
221
169
|
end
|
222
170
|
|
223
171
|
it "should send the transaction report even if the catalog could not be retrieved" do
|
224
|
-
expect(
|
172
|
+
expect(configurer).to receive(:retrieve_catalog).and_return(nil)
|
225
173
|
|
226
174
|
report = Puppet::Transaction::Report.new(nil, "test", "aaaa")
|
227
175
|
expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
|
228
|
-
expect(
|
176
|
+
expect(configurer).to receive(:send_report).with(report)
|
229
177
|
|
230
178
|
expect(report.environment).to eq("test")
|
231
179
|
expect(report.transaction_uuid).to eq("aaaa")
|
232
180
|
|
233
|
-
|
181
|
+
configurer.run
|
234
182
|
end
|
235
183
|
|
236
184
|
it "should send the transaction report even if there is a failure" do
|
237
|
-
expect(
|
185
|
+
expect(configurer).to receive(:retrieve_catalog).and_raise("whatever")
|
238
186
|
|
239
187
|
report = Puppet::Transaction::Report.new(nil, "test", "aaaa")
|
240
188
|
expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
|
241
|
-
expect(
|
189
|
+
expect(configurer).to receive(:send_report).with(report)
|
242
190
|
|
243
191
|
expect(report.environment).to eq("test")
|
244
192
|
expect(report.transaction_uuid).to eq("aaaa")
|
245
193
|
|
246
|
-
expect(
|
194
|
+
expect(configurer.run).to be_nil
|
247
195
|
end
|
248
196
|
|
249
197
|
it "should remove the report as a log destination when the run is finished" do
|
250
|
-
report = Puppet::Transaction::Report.new
|
251
198
|
expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
|
252
199
|
|
253
|
-
|
200
|
+
configurer.run
|
254
201
|
|
255
202
|
expect(Puppet::Util::Log.destinations).not_to include(report)
|
256
203
|
end
|
257
204
|
|
258
205
|
it "should return the report exit_status as the result of the run" do
|
259
|
-
report = Puppet::Transaction::Report.new
|
260
206
|
expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
|
261
207
|
expect(report).to receive(:exit_status).and_return(1234)
|
262
208
|
|
263
|
-
expect(
|
209
|
+
expect(configurer.run).to eq(1234)
|
264
210
|
end
|
265
211
|
|
266
212
|
it "should return nil if catalog application fails" do
|
267
|
-
|
268
|
-
report
|
269
|
-
expect(@agent.run(catalog: @catalog, report: report)).to be_nil
|
213
|
+
expect_any_instance_of(Puppet::Resource::Catalog).to receive(:apply).and_raise(Puppet::Error, 'One or more resource dependency cycles detected in graph')
|
214
|
+
expect(configurer.run(catalog: catalog, report: report)).to be_nil
|
270
215
|
end
|
271
216
|
|
272
217
|
it "should send the transaction report even if the pre-run command fails" do
|
273
|
-
report = Puppet::Transaction::Report.new
|
274
218
|
expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
|
275
219
|
|
276
220
|
Puppet.settings[:prerun_command] = "/my/command"
|
277
221
|
expect(Puppet::Util::Execution).to receive(:execute).with(["/my/command"]).and_raise(Puppet::ExecutionFailure, "Failed")
|
278
|
-
expect(
|
222
|
+
expect(configurer).to receive(:send_report).with(report)
|
279
223
|
|
280
|
-
expect(
|
224
|
+
expect(configurer.run).to be_nil
|
281
225
|
end
|
282
226
|
|
283
227
|
it "should include the pre-run command failure in the report" do
|
284
|
-
report = Puppet::Transaction::Report.new
|
285
228
|
expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
|
286
229
|
|
287
230
|
Puppet.settings[:prerun_command] = "/my/command"
|
288
231
|
expect(Puppet::Util::Execution).to receive(:execute).with(["/my/command"]).and_raise(Puppet::ExecutionFailure, "Failed")
|
289
232
|
|
290
|
-
expect(
|
233
|
+
expect(configurer.run).to be_nil
|
291
234
|
expect(report.logs.find { |x| x.message =~ /Could not run command from prerun_command/ }).to be
|
292
235
|
end
|
293
236
|
|
294
237
|
it "should send the transaction report even if the post-run command fails" do
|
295
|
-
report = Puppet::Transaction::Report.new
|
296
238
|
expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
|
297
239
|
|
298
240
|
Puppet.settings[:postrun_command] = "/my/command"
|
299
241
|
expect(Puppet::Util::Execution).to receive(:execute).with(["/my/command"]).and_raise(Puppet::ExecutionFailure, "Failed")
|
300
|
-
expect(
|
242
|
+
expect(configurer).to receive(:send_report).with(report)
|
301
243
|
|
302
|
-
expect(
|
244
|
+
expect(configurer.run).to be_nil
|
303
245
|
end
|
304
246
|
|
305
247
|
it "should include the post-run command failure in the report" do
|
306
|
-
report = Puppet::Transaction::Report.new
|
307
248
|
expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
|
308
249
|
|
309
250
|
Puppet.settings[:postrun_command] = "/my/command"
|
@@ -311,7 +252,7 @@ describe Puppet::Configurer do
|
|
311
252
|
|
312
253
|
expect(report).to receive(:<<) { |log, _| expect(log.message).to match(/Could not run command from postrun_command/) }.at_least(:once)
|
313
254
|
|
314
|
-
expect(
|
255
|
+
expect(configurer.run).to be_nil
|
315
256
|
end
|
316
257
|
|
317
258
|
it "should execute post-run command even if the pre-run command fails" do
|
@@ -320,47 +261,42 @@ describe Puppet::Configurer do
|
|
320
261
|
expect(Puppet::Util::Execution).to receive(:execute).with(["/my/precommand"]).and_raise(Puppet::ExecutionFailure, "Failed")
|
321
262
|
expect(Puppet::Util::Execution).to receive(:execute).with(["/my/postcommand"])
|
322
263
|
|
323
|
-
expect(
|
264
|
+
expect(configurer.run).to be_nil
|
324
265
|
end
|
325
266
|
|
326
267
|
it "should finalize the report" do
|
327
|
-
report = Puppet::Transaction::Report.new
|
328
268
|
expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
|
329
269
|
|
330
270
|
expect(report).to receive(:finalize_report)
|
331
|
-
|
271
|
+
configurer.run
|
332
272
|
end
|
333
273
|
|
334
274
|
it "should not apply the catalog if the pre-run command fails" do
|
335
|
-
report = Puppet::Transaction::Report.new
|
336
275
|
expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
|
337
276
|
|
338
277
|
Puppet.settings[:prerun_command] = "/my/command"
|
339
278
|
expect(Puppet::Util::Execution).to receive(:execute).with(["/my/command"]).and_raise(Puppet::ExecutionFailure, "Failed")
|
340
279
|
|
341
|
-
|
342
|
-
expect(
|
280
|
+
expect_any_instance_of(Puppet::Resource::Catalog).not_to receive(:apply)
|
281
|
+
expect(configurer).to receive(:send_report)
|
343
282
|
|
344
|
-
expect(
|
283
|
+
expect(configurer.run).to be_nil
|
345
284
|
end
|
346
285
|
|
347
286
|
it "should apply the catalog, send the report, and return nil if the post-run command fails" do
|
348
|
-
report = Puppet::Transaction::Report.new
|
349
287
|
expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
|
350
288
|
|
351
289
|
Puppet.settings[:postrun_command] = "/my/command"
|
352
290
|
expect(Puppet::Util::Execution).to receive(:execute).with(["/my/command"]).and_raise(Puppet::ExecutionFailure, "Failed")
|
353
291
|
|
354
|
-
|
355
|
-
expect(
|
292
|
+
expect_any_instance_of(Puppet::Resource::Catalog).to receive(:apply)
|
293
|
+
expect(configurer).to receive(:send_report)
|
356
294
|
|
357
|
-
expect(
|
295
|
+
expect(configurer.run).to be_nil
|
358
296
|
end
|
359
297
|
|
360
298
|
it 'includes total time metrics in the report after successfully applying the catalog' do
|
361
|
-
report
|
362
|
-
allow(@catalog).to receive(:apply).with(:report => report)
|
363
|
-
@agent.run(report: report)
|
299
|
+
configurer.run(report: report)
|
364
300
|
|
365
301
|
expect(report.metrics['time']).to be
|
366
302
|
expect(report.metrics['time']['total']).to be_a_kind_of(Numeric)
|
@@ -370,17 +306,15 @@ describe Puppet::Configurer do
|
|
370
306
|
Puppet.settings[:prerun_command] = "/my/command"
|
371
307
|
expect(Puppet::Util::Execution).to receive(:execute).with(["/my/command"]).and_raise(Puppet::ExecutionFailure, "Failed")
|
372
308
|
|
373
|
-
report
|
374
|
-
@agent.run(report: report)
|
309
|
+
configurer.run(report: report)
|
375
310
|
|
376
311
|
expect(report.metrics['time']).to be
|
377
312
|
expect(report.metrics['time']['total']).to be_a_kind_of(Numeric)
|
378
313
|
end
|
379
314
|
|
380
315
|
it 'includes total time metrics in the report even if catalog retrieval fails' do
|
381
|
-
|
382
|
-
|
383
|
-
@agent.run(:report => report)
|
316
|
+
allow(configurer).to receive(:prepare_and_retrieve_catalog_from_cache).and_raise
|
317
|
+
configurer.run(:report => report)
|
384
318
|
|
385
319
|
expect(report.metrics['time']).to be
|
386
320
|
expect(report.metrics['time']['total']).to be_a_kind_of(Numeric)
|
@@ -388,96 +322,93 @@ describe Puppet::Configurer do
|
|
388
322
|
|
389
323
|
it "should refetch the catalog if the server specifies a new environment in the catalog" do
|
390
324
|
catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote('second_env'))
|
391
|
-
expect(
|
325
|
+
expect(configurer).to receive(:retrieve_catalog).and_return(catalog).twice
|
392
326
|
|
393
|
-
|
327
|
+
configurer.run
|
394
328
|
end
|
395
329
|
|
396
|
-
it "
|
397
|
-
|
330
|
+
it "changes the configurer's environment if the server specifies a new environment in the catalog" do
|
331
|
+
allow_any_instance_of(Puppet::Resource::Catalog).to receive(:environment).and_return("second_env")
|
398
332
|
|
399
|
-
|
333
|
+
configurer.run
|
400
334
|
|
401
|
-
expect(
|
335
|
+
expect(configurer.environment).to eq("second_env")
|
402
336
|
end
|
403
337
|
|
404
|
-
it "
|
405
|
-
|
406
|
-
expect(Puppet::Transaction::Report).to receive(:new).and_return(report)
|
407
|
-
expect(@agent).to receive(:send_report).with(report)
|
408
|
-
|
409
|
-
allow(@catalog).to receive(:environment).and_return("second_env")
|
410
|
-
allow(@agent).to receive(:retrieve_catalog).and_return(@catalog)
|
338
|
+
it "changes the report's environment if the server specifies a new environment in the catalog" do
|
339
|
+
allow_any_instance_of(Puppet::Resource::Catalog).to receive(:environment).and_return("second_env")
|
411
340
|
|
412
|
-
|
341
|
+
configurer.run(report: report)
|
413
342
|
|
414
343
|
expect(report.environment).to eq("second_env")
|
415
344
|
end
|
416
345
|
|
417
346
|
it "sends the transaction uuid in a catalog request" do
|
418
|
-
|
347
|
+
configurer = Puppet::Configurer.new('aaa')
|
419
348
|
expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(transaction_uuid: 'aaa'))
|
420
|
-
|
349
|
+
configurer.run
|
421
350
|
end
|
422
351
|
|
423
352
|
it "sends the transaction uuid in a catalog request" do
|
424
|
-
|
353
|
+
configurer = Puppet::Configurer.new('b', 'aaa')
|
425
354
|
expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(job_id: 'aaa'))
|
426
|
-
|
355
|
+
configurer.run
|
427
356
|
end
|
428
357
|
|
429
358
|
it "sets the static_catalog query param to true in a catalog request" do
|
430
359
|
expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(static_catalog: true))
|
431
|
-
|
360
|
+
configurer.run
|
432
361
|
end
|
433
362
|
|
434
363
|
it "sets the checksum_type query param to the default supported_checksum_types in a catalog request" do
|
435
364
|
expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything,
|
436
365
|
hash_including(checksum_type: 'md5.sha256.sha384.sha512.sha224'))
|
437
|
-
|
366
|
+
configurer.run
|
438
367
|
end
|
439
368
|
|
440
369
|
it "sets the checksum_type query param to the supported_checksum_types setting in a catalog request" do
|
441
|
-
# Regenerate the agent to pick up the new setting
|
442
370
|
Puppet[:supported_checksum_types] = ['sha256']
|
443
|
-
|
444
|
-
|
445
|
-
allow(@agent).to receive(:download_plugins)
|
446
|
-
allow(@agent).to receive(:send_report)
|
447
|
-
allow(@agent).to receive(:save_last_run_summary)
|
371
|
+
# Regenerate the agent to pick up the new setting
|
372
|
+
configurer = Puppet::Configurer.new
|
448
373
|
|
449
374
|
expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(checksum_type: 'sha256'))
|
450
|
-
|
375
|
+
configurer.run
|
451
376
|
end
|
452
377
|
|
453
378
|
describe "when not using a REST terminus for catalogs" do
|
454
379
|
it "should not pass any facts when retrieving the catalog" do
|
380
|
+
# This is weird, we collect facts when constructing the node,
|
381
|
+
# but we don't send them in the indirector request. Then the compiler
|
382
|
+
# looks up the node, and collects its facts, which we could have sent
|
383
|
+
# in the first place. This seems like a bug.
|
455
384
|
Puppet::Resource::Catalog.indirection.terminus_class = :compiler
|
456
|
-
|
385
|
+
|
457
386
|
expect(Puppet::Resource::Catalog.indirection).to receive(:find) do |name, options|
|
458
|
-
options[:facts].
|
459
|
-
end.and_return(
|
387
|
+
expect(options[:facts]).to be_nil
|
388
|
+
end.and_return(catalog)
|
460
389
|
|
461
|
-
|
390
|
+
configurer.run
|
462
391
|
end
|
463
392
|
end
|
464
393
|
|
465
394
|
describe "when using a REST terminus for catalogs" do
|
466
|
-
it "should pass the
|
395
|
+
it "should pass the url encoded facts and facts format as arguments when retrieving the catalog" do
|
467
396
|
Puppet::Resource::Catalog.indirection.terminus_class = :rest
|
468
|
-
expect(@agent).to receive(:facts_for_uploading).and_return(:facts => "myfacts", :facts_format => :foo)
|
469
|
-
expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(facts: "myfacts", facts_format: :foo)).and_return(@catalog)
|
470
397
|
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
398
|
+
facts.values = { 'foo' => 'bar' }
|
399
|
+
Puppet::Node::Facts.indirection.save(facts)
|
400
|
+
|
401
|
+
expect(
|
402
|
+
Puppet::Resource::Catalog.indirection
|
403
|
+
).to receive(:find) do |_, options|
|
404
|
+
expect(options[:facts_format]).to eq("application/json")
|
405
|
+
|
406
|
+
unescaped = JSON.parse(CGI.unescape(options[:facts]))
|
407
|
+
expect(unescaped).to include("values" => {"foo" => "bar"})
|
408
|
+
end.and_return(catalog)
|
475
409
|
|
476
|
-
|
477
|
-
|
478
|
-
expect(SecureRandom).not_to receive(:uuid)
|
479
|
-
configurer = Puppet::Configurer.new('foo')
|
480
|
-
expect(configurer.instance_variable_get(:@transaction_uuid) == 'foo')
|
410
|
+
configurer.run
|
411
|
+
end
|
481
412
|
end
|
482
413
|
end
|
483
414
|
|
@@ -485,56 +416,52 @@ describe Puppet::Configurer do
|
|
485
416
|
include PuppetSpec::Files
|
486
417
|
|
487
418
|
before do
|
488
|
-
allow(Puppet.settings).to receive(:use).and_return(true)
|
489
|
-
@configurer = Puppet::Configurer.new
|
490
419
|
Puppet[:lastrunfile] = tmpfile('last_run_file')
|
491
|
-
|
492
|
-
@report = Puppet::Transaction::Report.new
|
493
420
|
Puppet[:reports] = "none"
|
494
421
|
end
|
495
422
|
|
496
423
|
it "should print a report summary if configured to do so" do
|
497
424
|
Puppet.settings[:summarize] = true
|
498
425
|
|
499
|
-
expect(
|
426
|
+
expect(report).to receive(:summary).and_return("stuff")
|
500
427
|
|
501
|
-
expect(
|
502
|
-
|
428
|
+
expect(configurer).to receive(:puts).with("stuff")
|
429
|
+
configurer.send_report(report)
|
503
430
|
end
|
504
431
|
|
505
432
|
it "should not print a report summary if not configured to do so" do
|
506
433
|
Puppet.settings[:summarize] = false
|
507
434
|
|
508
|
-
expect(
|
509
|
-
|
435
|
+
expect(configurer).not_to receive(:puts)
|
436
|
+
configurer.send_report(report)
|
510
437
|
end
|
511
438
|
|
512
439
|
it "should save the report if reporting is enabled" do
|
513
440
|
Puppet.settings[:report] = true
|
514
441
|
|
515
|
-
expect(Puppet::Transaction::Report.indirection).to receive(:save).with(
|
516
|
-
|
442
|
+
expect(Puppet::Transaction::Report.indirection).to receive(:save).with(report, nil, instance_of(Hash))
|
443
|
+
configurer.send_report(report)
|
517
444
|
end
|
518
445
|
|
519
446
|
it "should not save the report if reporting is disabled" do
|
520
447
|
Puppet.settings[:report] = false
|
521
448
|
|
522
|
-
expect(Puppet::Transaction::Report.indirection).not_to receive(:save).with(
|
523
|
-
|
449
|
+
expect(Puppet::Transaction::Report.indirection).not_to receive(:save).with(report, nil, instance_of(Hash))
|
450
|
+
configurer.send_report(report)
|
524
451
|
end
|
525
452
|
|
526
453
|
it "should save the last run summary if reporting is enabled" do
|
527
454
|
Puppet.settings[:report] = true
|
528
455
|
|
529
|
-
expect(
|
530
|
-
|
456
|
+
expect(configurer).to receive(:save_last_run_summary).with(report)
|
457
|
+
configurer.send_report(report)
|
531
458
|
end
|
532
459
|
|
533
460
|
it "should save the last run summary if reporting is disabled" do
|
534
461
|
Puppet.settings[:report] = false
|
535
462
|
|
536
|
-
expect(
|
537
|
-
|
463
|
+
expect(configurer).to receive(:save_last_run_summary).with(report)
|
464
|
+
configurer.send_report(report)
|
538
465
|
end
|
539
466
|
|
540
467
|
it "should log but not fail if saving the report fails" do
|
@@ -543,7 +470,7 @@ describe Puppet::Configurer do
|
|
543
470
|
expect(Puppet::Transaction::Report.indirection).to receive(:save).and_raise("whatever")
|
544
471
|
|
545
472
|
expect(Puppet).to receive(:err)
|
546
|
-
expect {
|
473
|
+
expect { configurer.send_report(report) }.not_to raise_error
|
547
474
|
end
|
548
475
|
end
|
549
476
|
|
@@ -551,22 +478,17 @@ describe Puppet::Configurer do
|
|
551
478
|
include PuppetSpec::Files
|
552
479
|
|
553
480
|
before do
|
554
|
-
allow(Puppet.settings).to receive(:use).and_return(true)
|
555
|
-
@configurer = Puppet::Configurer.new
|
556
|
-
|
557
|
-
@report = double('report', :raw_summary => {})
|
558
|
-
|
559
481
|
Puppet[:lastrunfile] = tmpfile('last_run_file')
|
560
482
|
end
|
561
483
|
|
562
484
|
it "should write the last run file" do
|
563
|
-
|
485
|
+
configurer.save_last_run_summary(report)
|
564
486
|
expect(Puppet::FileSystem.exist?(Puppet[:lastrunfile])).to be_truthy
|
565
487
|
end
|
566
488
|
|
567
489
|
it "should write the raw summary as yaml" do
|
568
|
-
expect(
|
569
|
-
|
490
|
+
expect(report).to receive(:raw_summary).and_return("summary")
|
491
|
+
configurer.save_last_run_summary(report)
|
570
492
|
expect(File.read(Puppet[:lastrunfile])).to eq(YAML.dump("summary"))
|
571
493
|
end
|
572
494
|
|
@@ -582,12 +504,12 @@ describe Puppet::Configurer do
|
|
582
504
|
expect(Puppet::Util).to receive(:replace_file).and_yield(fh)
|
583
505
|
|
584
506
|
expect(Puppet).to receive(:err)
|
585
|
-
expect {
|
507
|
+
expect { configurer.save_last_run_summary(report) }.to_not raise_error
|
586
508
|
end
|
587
509
|
|
588
510
|
it "should create the last run file with the correct mode" do
|
589
511
|
expect(Puppet.settings.setting(:lastrunfile)).to receive(:mode).and_return('664')
|
590
|
-
|
512
|
+
configurer.save_last_run_summary(report)
|
591
513
|
|
592
514
|
if Puppet::Util::Platform.windows?
|
593
515
|
require 'puppet/util/windows/security'
|
@@ -601,25 +523,25 @@ describe Puppet::Configurer do
|
|
601
523
|
it "should report invalid last run file permissions" do
|
602
524
|
expect(Puppet.settings.setting(:lastrunfile)).to receive(:mode).and_return('892')
|
603
525
|
expect(Puppet).to receive(:err).with(/Could not save last run local report.*892 is invalid/)
|
604
|
-
|
526
|
+
configurer.save_last_run_summary(report)
|
605
527
|
end
|
606
528
|
end
|
607
529
|
|
608
530
|
describe "when requesting a node" do
|
609
531
|
it "uses the transaction uuid in the request" do
|
610
532
|
expect(Puppet::Node.indirection).to receive(:find).with(anything, hash_including(transaction_uuid: anything)).twice
|
611
|
-
|
533
|
+
configurer.run
|
612
534
|
end
|
613
535
|
|
614
536
|
it "sends an explicitly configured environment request" do
|
615
537
|
expect(Puppet.settings).to receive(:set_by_config?).with(:environment).and_return(true)
|
616
538
|
expect(Puppet::Node.indirection).to receive(:find).with(anything, hash_including(configured_environment: Puppet[:environment])).twice
|
617
|
-
|
539
|
+
configurer.run
|
618
540
|
end
|
619
541
|
|
620
542
|
it "does not send a configured_environment when using the default" do
|
621
543
|
expect(Puppet::Node.indirection).to receive(:find).with(anything, hash_including(configured_environment: nil)).twice
|
622
|
-
|
544
|
+
configurer.run
|
623
545
|
end
|
624
546
|
end
|
625
547
|
|
@@ -650,14 +572,6 @@ describe Puppet::Configurer do
|
|
650
572
|
|
651
573
|
describe "when retrieving a catalog" do
|
652
574
|
before do
|
653
|
-
allow(Puppet.settings).to receive(:use).and_return(true)
|
654
|
-
allow(@agent).to receive(:facts_for_uploading).and_return({})
|
655
|
-
allow(@agent).to receive(:download_plugins)
|
656
|
-
|
657
|
-
# retrieve a catalog in the current environment, so we don't try to converge unexpectedly
|
658
|
-
@catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote(Puppet[:environment].to_sym))
|
659
|
-
|
660
|
-
# this is the default when using a Configurer instance
|
661
575
|
allow(Puppet::Resource::Catalog.indirection).to receive(:terminus_class).and_return(:rest)
|
662
576
|
end
|
663
577
|
|
@@ -667,100 +581,128 @@ describe Puppet::Configurer do
|
|
667
581
|
end
|
668
582
|
|
669
583
|
it "should first look in the cache for a catalog" do
|
670
|
-
expects_cached_catalog_only(
|
584
|
+
expects_cached_catalog_only(catalog)
|
671
585
|
|
672
|
-
|
586
|
+
configurer.run
|
673
587
|
end
|
674
588
|
|
675
589
|
it "should not make a node request or pluginsync when a cached catalog is successfully retrieved" do
|
676
590
|
expect(Puppet::Node.indirection).not_to receive(:find)
|
677
|
-
expects_cached_catalog_only(
|
678
|
-
expect(
|
591
|
+
expects_cached_catalog_only(catalog)
|
592
|
+
expect(configurer).not_to receive(:download_plugins)
|
679
593
|
|
680
|
-
|
594
|
+
configurer.run
|
681
595
|
end
|
682
596
|
|
683
597
|
it "should make a node request and pluginsync when a cached catalog cannot be retrieved" do
|
684
598
|
expect(Puppet::Node.indirection).to receive(:find).and_return(nil)
|
685
|
-
expects_fallback_to_new_catalog(
|
686
|
-
expect(
|
599
|
+
expects_fallback_to_new_catalog(catalog)
|
600
|
+
expect(configurer).to receive(:download_plugins)
|
687
601
|
|
688
|
-
|
602
|
+
configurer.run
|
689
603
|
end
|
690
604
|
|
691
605
|
it "should set its cached_catalog_status to 'explicitly_requested'" do
|
692
|
-
expects_cached_catalog_only(
|
606
|
+
expects_cached_catalog_only(catalog)
|
693
607
|
|
694
|
-
|
695
|
-
|
608
|
+
options = {}
|
609
|
+
configurer.run(options)
|
610
|
+
|
611
|
+
expect(options[:report].cached_catalog_status).to eq('explicitly_requested')
|
696
612
|
end
|
697
613
|
|
698
614
|
it "should set its cached_catalog_status to 'explicitly requested' if the cached catalog is from a different environment" do
|
699
615
|
cached_catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote('second_env'))
|
700
616
|
expects_cached_catalog_only(cached_catalog)
|
701
617
|
|
702
|
-
|
703
|
-
|
618
|
+
options = {}
|
619
|
+
configurer.run(options)
|
620
|
+
|
621
|
+
expect(options[:report].cached_catalog_status).to eq('explicitly_requested')
|
704
622
|
end
|
705
623
|
|
706
624
|
it "should compile a new catalog if none is found in the cache" do
|
707
|
-
expects_fallback_to_new_catalog(
|
625
|
+
expects_fallback_to_new_catalog(catalog)
|
708
626
|
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
it "should set its cached_catalog_status to 'not_used' if no catalog is found in the cache" do
|
713
|
-
expects_fallback_to_new_catalog(@catalog)
|
627
|
+
options = {}
|
628
|
+
configurer.run(options)
|
714
629
|
|
715
|
-
|
716
|
-
expect(@agent.instance_variable_get(:@cached_catalog_status)).to eq('not_used')
|
630
|
+
expect(options[:report].cached_catalog_status).to eq('not_used')
|
717
631
|
end
|
718
632
|
|
719
633
|
it "should not attempt to retrieve a cached catalog again if the first attempt failed" do
|
720
634
|
expect(Puppet::Node.indirection).to receive(:find).and_return(nil)
|
721
635
|
expects_neither_new_or_cached_catalog
|
722
636
|
|
723
|
-
|
637
|
+
configurer.run
|
724
638
|
end
|
725
639
|
|
726
640
|
it "should return the cached catalog when the environment doesn't match" do
|
727
641
|
cached_catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote('second_env'))
|
728
642
|
expects_cached_catalog_only(cached_catalog)
|
729
643
|
|
644
|
+
allow(Puppet).to receive(:info)
|
730
645
|
expect(Puppet).to receive(:info).with("Using cached catalog from environment 'second_env'")
|
731
|
-
|
646
|
+
|
647
|
+
configurer.run
|
648
|
+
end
|
649
|
+
|
650
|
+
it "applies the catalog passed as options when the catalog cache terminus is not set" do
|
651
|
+
stub_request(:get, %r{/puppet/v3/file_metadatas?/plugins}).to_return(:status => 404)
|
652
|
+
stub_request(:get, %r{/puppet/v3/file_metadatas?/pluginfacts}).to_return(:status => 404)
|
653
|
+
|
654
|
+
catalog.add_resource(Puppet::Resource.new('notify', 'from apply'))
|
655
|
+
configurer.run(catalog: catalog.to_ral)
|
656
|
+
|
657
|
+
# make sure cache class is not set to avoid surprises later
|
658
|
+
expect(Puppet::Resource::Catalog.indirection).to_not be_cache
|
659
|
+
expect(@logs).to include(an_object_having_attributes(level: :notice, message: /defined 'message' as 'from apply'/))
|
660
|
+
end
|
661
|
+
|
662
|
+
it "applies the cached catalog when the catalog cache terminus is set, ignoring the catalog passed as options" do
|
663
|
+
Puppet::Resource::Catalog.indirection.cache_class = :json
|
664
|
+
|
665
|
+
cached_catalog = Puppet::Resource::Catalog.new(Puppet[:node_name_value], Puppet[:environment])
|
666
|
+
cached_catalog.add_resource(Puppet::Resource.new('notify', 'from cache'))
|
667
|
+
|
668
|
+
# update cached catalog
|
669
|
+
Puppet.settings.use(:main, :agent)
|
670
|
+
path = Puppet::Resource::Catalog.indirection.cache.path(cached_catalog.name)
|
671
|
+
FileUtils.mkdir(File.dirname(path))
|
672
|
+
File.write(path, cached_catalog.render(:json))
|
673
|
+
|
674
|
+
configurer.run(catalog: catalog.to_ral)
|
675
|
+
|
676
|
+
expect(@logs).to include(an_object_having_attributes(level: :notice, message: /defined 'message' as 'from cache'/))
|
732
677
|
end
|
733
678
|
end
|
734
679
|
|
735
680
|
describe "and strict environment mode is set" do
|
736
681
|
before do
|
737
|
-
allow(@catalog).to receive(:to_ral).and_return(@catalog)
|
738
|
-
allow(@catalog).to receive(:write_class_file)
|
739
|
-
allow(@catalog).to receive(:write_resource_file)
|
740
|
-
allow(@agent).to receive(:send_report)
|
741
|
-
allow(@agent).to receive(:save_last_run_summary)
|
742
682
|
Puppet.settings[:strict_environment_mode] = true
|
743
683
|
end
|
744
684
|
|
745
685
|
it "should not make a node request" do
|
746
686
|
expect(Puppet::Node.indirection).not_to receive(:find)
|
747
687
|
|
748
|
-
|
688
|
+
configurer.run
|
749
689
|
end
|
750
690
|
|
751
691
|
it "should return nil when the catalog's environment doesn't match the agent specified environment" do
|
752
|
-
|
753
|
-
|
692
|
+
Puppet[:environment] = 'second_env'
|
693
|
+
configurer = Puppet::Configurer.new
|
694
|
+
|
695
|
+
catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote("production"))
|
696
|
+
expects_new_catalog_only(catalog)
|
754
697
|
|
755
698
|
expect(Puppet).to receive(:err).with("Not using catalog because its environment 'production' does not match agent specified environment 'second_env' and strict_environment_mode is set")
|
756
|
-
expect(
|
699
|
+
expect(configurer.run).to be_nil
|
757
700
|
end
|
758
701
|
|
759
|
-
it "should
|
760
|
-
|
761
|
-
expects_new_catalog_only(@catalog)
|
702
|
+
it "should return 0 when the catalog's environment matches the agent specified environment" do
|
703
|
+
expects_new_catalog_only(catalog)
|
762
704
|
|
763
|
-
expect(
|
705
|
+
expect(configurer.run).to eq(0)
|
764
706
|
end
|
765
707
|
|
766
708
|
describe "and a cached catalog is explicitly requested" do
|
@@ -769,83 +711,81 @@ describe Puppet::Configurer do
|
|
769
711
|
end
|
770
712
|
|
771
713
|
it "should return nil when the cached catalog's environment doesn't match the agent specified environment" do
|
772
|
-
|
773
|
-
|
714
|
+
Puppet[:environment] = 'second_env'
|
715
|
+
configurer = Puppet::Configurer.new
|
716
|
+
|
717
|
+
catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote("production"))
|
718
|
+
expects_cached_catalog_only(catalog)
|
774
719
|
|
775
720
|
expect(Puppet).to receive(:err).with("Not using catalog because its environment 'production' does not match agent specified environment 'second_env' and strict_environment_mode is set")
|
776
|
-
expect(
|
721
|
+
expect(configurer.run).to be_nil
|
777
722
|
end
|
778
723
|
|
779
724
|
it "should proceed with the cached catalog if its environment matchs the local environment" do
|
780
|
-
|
781
|
-
@agent.instance_variable_set(:@environment, 'production')
|
782
|
-
expects_cached_catalog_only(@catalog)
|
725
|
+
expects_cached_catalog_only(catalog)
|
783
726
|
|
784
|
-
expect(
|
727
|
+
expect(configurer.run).to eq(0)
|
785
728
|
end
|
786
729
|
end
|
787
730
|
end
|
788
731
|
|
789
|
-
it "should use the Catalog class to get its catalog" do
|
790
|
-
expect(Puppet::Resource::Catalog.indirection).to receive(:find).and_return(@catalog)
|
791
|
-
|
792
|
-
@agent.retrieve_catalog({})
|
793
|
-
end
|
794
|
-
|
795
732
|
it "should set its cached_catalog_status to 'not_used' when downloading a new catalog" do
|
796
|
-
expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_cache: true)).and_return(
|
733
|
+
expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_cache: true)).and_return(catalog)
|
797
734
|
|
798
|
-
|
799
|
-
|
735
|
+
options = {}
|
736
|
+
configurer.run(options)
|
737
|
+
|
738
|
+
expect(options[:report].cached_catalog_status).to eq('not_used')
|
800
739
|
end
|
801
740
|
|
802
741
|
it "should use its node_name_value to retrieve the catalog" do
|
803
|
-
|
804
|
-
Puppet.
|
805
|
-
expect(Puppet::Resource::Catalog.indirection).to receive(:find).with("myhost.domain.com", anything).and_return(@catalog)
|
806
|
-
|
807
|
-
@agent.retrieve_catalog({})
|
808
|
-
end
|
742
|
+
myhost_facts = Puppet::Node::Facts.new("myhost.domain.com")
|
743
|
+
Puppet::Node::Facts.indirection.save(myhost_facts)
|
809
744
|
|
810
|
-
|
811
|
-
expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(
|
745
|
+
Puppet.settings[:node_name_value] = "myhost.domain.com"
|
746
|
+
expect(Puppet::Resource::Catalog.indirection).to receive(:find).with("myhost.domain.com", anything).and_return(catalog)
|
812
747
|
|
813
|
-
|
748
|
+
configurer.run
|
814
749
|
end
|
815
750
|
|
816
|
-
it "should log
|
817
|
-
expects_fallback_to_cached_catalog(
|
751
|
+
it "should log when no catalog can be retrieved from the server" do
|
752
|
+
expects_fallback_to_cached_catalog(catalog)
|
818
753
|
|
754
|
+
allow(Puppet).to receive(:info)
|
819
755
|
expect(Puppet).to receive(:info).with("Using cached catalog from environment 'production'")
|
820
|
-
|
756
|
+
configurer.run
|
821
757
|
end
|
822
758
|
|
823
759
|
it "should set its cached_catalog_status to 'on_failure' when no catalog can be retrieved from the server" do
|
824
|
-
expects_fallback_to_cached_catalog(
|
760
|
+
expects_fallback_to_cached_catalog(catalog)
|
761
|
+
|
762
|
+
options = {}
|
763
|
+
configurer.run(options)
|
825
764
|
|
826
|
-
|
827
|
-
expect(@agent.instance_variable_get(:@cached_catalog_status)).to eq('on_failure')
|
765
|
+
expect(options[:report].cached_catalog_status).to eq('on_failure')
|
828
766
|
end
|
829
767
|
|
830
768
|
it "should not look in the cache for a catalog if one is returned from the server" do
|
831
|
-
expects_new_catalog_only(
|
769
|
+
expects_new_catalog_only(catalog)
|
832
770
|
|
833
|
-
|
771
|
+
configurer.run
|
834
772
|
end
|
835
773
|
|
836
774
|
it "should return the cached catalog when retrieving the remote catalog throws an exception" do
|
837
775
|
expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_cache: true)).and_raise("eh")
|
838
|
-
expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_terminus: true)).and_return(
|
776
|
+
expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_terminus: true)).and_return(catalog)
|
839
777
|
|
840
|
-
|
778
|
+
configurer.run
|
841
779
|
end
|
842
780
|
|
843
781
|
it "should set its cached_catalog_status to 'on_failure' when retrieving the remote catalog throws an exception" do
|
844
782
|
expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_cache: true)).and_raise("eh")
|
845
|
-
expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_terminus: true)).and_return(
|
783
|
+
expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_terminus: true)).and_return(catalog)
|
784
|
+
|
785
|
+
options = {}
|
786
|
+
configurer.run(options)
|
846
787
|
|
847
|
-
|
848
|
-
expect(@agent.instance_variable_get(:@cached_catalog_status)).to eq('on_failure')
|
788
|
+
expect(options[:report].cached_catalog_status).to eq('on_failure')
|
849
789
|
end
|
850
790
|
|
851
791
|
it "should log and return nil if no catalog can be retrieved from the server and :usecacheonfailure is disabled" do
|
@@ -854,120 +794,173 @@ describe Puppet::Configurer do
|
|
854
794
|
|
855
795
|
expect(Puppet).to receive(:warning).with('Not using cache on failed catalog')
|
856
796
|
|
857
|
-
expect(
|
797
|
+
expect(configurer.run).to be_nil
|
858
798
|
end
|
859
799
|
|
860
800
|
it "should set its cached_catalog_status to 'not_used' if no catalog can be retrieved from the server and :usecacheonfailure is disabled or fails to retrieve a catalog" do
|
861
801
|
Puppet[:usecacheonfailure] = false
|
862
802
|
expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_cache: true)).and_return(nil)
|
863
803
|
|
864
|
-
|
865
|
-
|
804
|
+
options = {}
|
805
|
+
configurer.run(options)
|
806
|
+
|
807
|
+
expect(options[:report].cached_catalog_status).to eq('not_used')
|
866
808
|
end
|
867
809
|
|
868
810
|
it "should return nil if no cached catalog is available and no catalog can be retrieved from the server" do
|
869
811
|
expects_neither_new_or_cached_catalog
|
870
812
|
|
871
|
-
expect(
|
813
|
+
expect(configurer.run).to be_nil
|
872
814
|
end
|
873
815
|
|
874
816
|
it "should return nil if its cached catalog environment doesn't match server-specified environment" do
|
875
817
|
cached_catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote('second_env'))
|
876
|
-
@agent.instance_variable_set(:@node_environment, 'production')
|
877
818
|
|
878
819
|
expects_fallback_to_cached_catalog(cached_catalog)
|
879
820
|
|
821
|
+
allow(Puppet).to receive(:err)
|
880
822
|
expect(Puppet).to receive(:err).with("Not using cached catalog because its environment 'second_env' does not match 'production'")
|
881
|
-
expect(
|
823
|
+
expect(configurer.run).to be_nil
|
882
824
|
end
|
883
825
|
|
884
826
|
it "should set its cached_catalog_status to 'not_used' if the cached catalog environment doesn't match server-specified environment" do
|
885
827
|
cached_catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote('second_env'))
|
886
|
-
@agent.instance_variable_set(:@node_environment, 'production')
|
887
|
-
|
888
|
-
expects_fallback_to_cached_catalog(cached_catalog)
|
889
|
-
|
890
|
-
@agent.retrieve_catalog({})
|
891
|
-
expect(@agent.instance_variable_get(:@cached_catalog_status)).to eq('not_used')
|
892
|
-
end
|
893
|
-
|
894
|
-
it "should return its cached catalog if the environment matches the server-specified environment" do
|
895
|
-
cached_catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote(Puppet[:environment]))
|
896
|
-
@agent.instance_variable_set(:@node_environment, cached_catalog.environment)
|
897
828
|
|
898
829
|
expects_fallback_to_cached_catalog(cached_catalog)
|
899
830
|
|
900
|
-
|
831
|
+
options = {}
|
832
|
+
configurer.run(options)
|
833
|
+
expect(options[:report].cached_catalog_status).to eq('not_used')
|
901
834
|
end
|
902
835
|
|
903
836
|
it "should set its cached_catalog_status to 'on_failure' if the cached catalog environment matches server-specified environment" do
|
904
|
-
|
905
|
-
@agent.instance_variable_set(:@node_environment, cached_catalog.environment)
|
906
|
-
|
907
|
-
expects_fallback_to_cached_catalog(cached_catalog)
|
837
|
+
expects_fallback_to_cached_catalog(catalog)
|
908
838
|
|
909
|
-
|
910
|
-
|
839
|
+
options = {}
|
840
|
+
configurer.run(options)
|
841
|
+
expect(options[:report].cached_catalog_status).to eq('on_failure')
|
911
842
|
end
|
912
843
|
|
913
844
|
it "should not update the cached catalog in noop mode" do
|
914
845
|
Puppet[:noop] = true
|
915
|
-
expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(ignore_cache: true, ignore_cache_save: true)).and_return(@catalog)
|
916
846
|
|
917
|
-
|
847
|
+
stub_request(:get, %r{/puppet/v3/catalog}).to_return(:status => 200, :body => catalog.render(:json), :headers => {'Content-Type' => 'application/json'})
|
848
|
+
|
849
|
+
Puppet::Resource::Catalog.indirection.cache_class = :json
|
850
|
+
path = Puppet::Resource::Catalog.indirection.cache.path(catalog.name)
|
851
|
+
|
852
|
+
expect(File).to_not be_exist(path)
|
853
|
+
configurer.run
|
854
|
+
expect(File).to_not be_exist(path)
|
918
855
|
end
|
919
856
|
|
920
857
|
it "should update the cached catalog when not in noop mode" do
|
921
858
|
Puppet[:noop] = false
|
922
|
-
|
859
|
+
Puppet[:log_level] = 'info'
|
860
|
+
|
861
|
+
stub_request(:get, %r{/puppet/v3/catalog}).to_return(:status => 200, :body => catalog.render(:json), :headers => {'Content-Type' => 'application/json'})
|
862
|
+
|
863
|
+
Puppet::Resource::Catalog.indirection.cache_class = :json
|
864
|
+
cache_path = Puppet::Resource::Catalog.indirection.cache.path(Puppet[:node_name_value])
|
865
|
+
|
866
|
+
expect(File).to_not be_exist(cache_path)
|
867
|
+
configurer.run
|
868
|
+
expect(File).to be_exist(cache_path)
|
869
|
+
|
870
|
+
expect(@logs).to include(an_object_having_attributes(level: :info, message: "Caching catalog for #{Puppet[:node_name_value]}"))
|
871
|
+
end
|
872
|
+
|
873
|
+
it "successfully applies the catalog without a cache" do
|
874
|
+
stub_request(:get, %r{/puppet/v3/catalog}).to_return(:status => 200, :body => catalog.render(:json), :headers => {'Content-Type' => 'application/json'})
|
875
|
+
|
876
|
+
Puppet::Resource::Catalog.indirection.cache_class = nil
|
877
|
+
|
878
|
+
expect(configurer.run).to eq(0)
|
879
|
+
end
|
880
|
+
|
881
|
+
it "should not update the cached catalog when running puppet apply" do
|
882
|
+
Puppet::Resource::Catalog.indirection.cache_class = :json
|
883
|
+
path = Puppet::Resource::Catalog.indirection.cache.path(catalog.name)
|
923
884
|
|
924
|
-
|
885
|
+
expect(File).to_not be_exist(path)
|
886
|
+
configurer.run(catalog: catalog)
|
887
|
+
expect(File).to_not be_exist(path)
|
925
888
|
end
|
926
889
|
end
|
927
890
|
|
928
|
-
describe "when
|
929
|
-
|
930
|
-
|
891
|
+
describe "when converging the environment" do
|
892
|
+
let(:apple) { Puppet::Resource::Catalog.new(Puppet[:node_name_value], Puppet::Node::Environment.remote('apple')) }
|
893
|
+
let(:banana) { Puppet::Resource::Catalog.new(Puppet[:node_name_value], Puppet::Node::Environment.remote('banana')) }
|
894
|
+
|
895
|
+
before :each do
|
896
|
+
apple.add_resource(resource)
|
897
|
+
banana.add_resource(resource)
|
898
|
+
end
|
931
899
|
|
932
|
-
|
900
|
+
it "converges after multiple attempts" do
|
901
|
+
expect(Puppet::Resource::Catalog.indirection).to receive(:find).and_return(apple, banana, banana)
|
902
|
+
|
903
|
+
allow(Puppet).to receive(:notice)
|
904
|
+
expect(Puppet).to receive(:notice).with("Local environment: 'production' doesn't match server specified environment 'apple', restarting agent run with environment 'apple'")
|
905
|
+
expect(Puppet).to receive(:notice).with("Local environment: 'apple' doesn't match server specified environment 'banana', restarting agent run with environment 'banana'")
|
906
|
+
|
907
|
+
configurer.run
|
933
908
|
end
|
934
909
|
|
935
|
-
|
936
|
-
|
910
|
+
it "raises if it can't converge after 4 tries after the initial catalog request" do
|
911
|
+
expect(Puppet::Resource::Catalog.indirection).to receive(:find).and_return(apple, banana, apple, banana, apple)
|
937
912
|
|
938
|
-
|
939
|
-
|
913
|
+
expect(Puppet).to receive(:err).with("Failed to apply catalog: Catalog environment didn't stabilize after 4 fetches, aborting run")
|
914
|
+
|
915
|
+
configurer.run
|
940
916
|
end
|
917
|
+
end
|
941
918
|
|
942
|
-
|
943
|
-
|
919
|
+
describe "when converting the catalog" do
|
920
|
+
it "converts Puppet::Resource into Puppet::Type::Notify" do
|
921
|
+
expect(configurer).to receive(:apply_catalog) do |ral, _|
|
922
|
+
expect(ral.resources).to contain(an_instance_of(Puppet::Type::Notify))
|
923
|
+
end
|
944
924
|
|
945
|
-
|
925
|
+
configurer.run(catalog: catalog)
|
946
926
|
end
|
947
927
|
|
948
|
-
it "
|
949
|
-
expect(
|
928
|
+
it "adds default schedules" do
|
929
|
+
expect(configurer).to receive(:apply_catalog) do |ral, _|
|
930
|
+
expect(ral.resources.map(&:to_ref)).to contain(%w{Schedule[puppet] Schedule[hourly] Schedule[daily] Schedule[weekly] Schedule[monthly] Schedule[never]})
|
931
|
+
end
|
950
932
|
|
951
|
-
|
933
|
+
configurer.run
|
952
934
|
end
|
953
935
|
|
954
|
-
it "
|
955
|
-
expect(
|
936
|
+
it "records the retrieval duration to the catalog" do
|
937
|
+
expect(configurer).to receive(:apply_catalog) do |ral, _|
|
938
|
+
expect(ral.retrieval_duration).to be_an_instance_of(Float)
|
939
|
+
end
|
956
940
|
|
957
|
-
|
941
|
+
configurer.run
|
958
942
|
end
|
959
943
|
|
960
|
-
it "
|
961
|
-
expect(
|
944
|
+
it "writes the class file containing applied settings classes" do
|
945
|
+
expect(File).to_not be_exist(Puppet[:classfile])
|
962
946
|
|
963
|
-
|
947
|
+
configurer.run
|
948
|
+
|
949
|
+
expect(File.read(Puppet[:classfile]).chomp).to eq('settings')
|
964
950
|
end
|
965
951
|
|
966
|
-
it "
|
967
|
-
|
952
|
+
it "writes an empty resource file since no resources are 'managed'" do
|
953
|
+
expect(File).to_not be_exist(Puppet[:resourcefile])
|
954
|
+
|
955
|
+
configurer.run
|
968
956
|
|
969
|
-
expect(
|
970
|
-
|
957
|
+
expect(File.read(Puppet[:resourcefile]).chomp).to eq("")
|
958
|
+
end
|
959
|
+
|
960
|
+
it "adds the conversion time to the report" do
|
961
|
+
configurer.run(report: report)
|
962
|
+
|
963
|
+
expect(report.metrics['time']['convert_catalog']).to be_an_instance_of(Float)
|
971
964
|
end
|
972
965
|
end
|
973
966
|
|
@@ -1002,80 +995,70 @@ describe Puppet::Configurer do
|
|
1002
995
|
describe "when attempting failover" do
|
1003
996
|
it "should not failover if server_list is not set" do
|
1004
997
|
Puppet.settings[:server_list] = []
|
1005
|
-
|
1006
|
-
@agent.run
|
998
|
+
configurer.run
|
1007
999
|
end
|
1008
1000
|
|
1009
1001
|
it "should not failover during an apply run" do
|
1010
1002
|
Puppet.settings[:server_list] = ["myserver:123"]
|
1011
|
-
expect(@agent).not_to receive(:find_functional_server)
|
1012
1003
|
catalog = Puppet::Resource::Catalog.new("tester", Puppet::Node::Environment.remote(Puppet[:environment].to_sym))
|
1013
|
-
|
1004
|
+
configurer.run(catalog: catalog)
|
1014
1005
|
end
|
1015
1006
|
|
1016
1007
|
it "should select a server when it receives 200 OK response" do
|
1017
1008
|
Puppet.settings[:server_list] = ["myserver:123"]
|
1018
|
-
|
1019
|
-
|
1020
|
-
allow(@agent).to receive(:run_internal)
|
1009
|
+
|
1010
|
+
stub_request(:get, 'https://myserver:123/status/v1/simple/master').to_return(status: 200)
|
1021
1011
|
|
1022
1012
|
options = {}
|
1023
|
-
|
1013
|
+
configurer.run(options)
|
1024
1014
|
expect(options[:report].master_used).to eq('myserver:123')
|
1025
1015
|
end
|
1026
1016
|
|
1027
1017
|
it "should select a server when it receives 403 Forbidden" do
|
1028
1018
|
Puppet.settings[:server_list] = ["myserver:123"]
|
1029
|
-
|
1030
|
-
|
1031
|
-
allow(@agent).to receive(:run_internal)
|
1019
|
+
|
1020
|
+
stub_request(:get, 'https://myserver:123/status/v1/simple/master').to_return(status: 403)
|
1032
1021
|
|
1033
1022
|
options = {}
|
1034
|
-
|
1023
|
+
configurer.run(options)
|
1035
1024
|
expect(options[:report].master_used).to eq('myserver:123')
|
1036
1025
|
end
|
1037
1026
|
|
1038
|
-
it "queries the simple status for the 'master' service" do
|
1039
|
-
Puppet.settings[:server_list] = ["myserver:123"]
|
1040
|
-
response = Net::HTTPOK.new(nil, 200, 'OK')
|
1041
|
-
http = double('request')
|
1042
|
-
expect(http).to receive(:get).with('/status/v1/simple/master').and_return(response)
|
1043
|
-
allow(Puppet::Network::HttpPool).to receive(:http_ssl_instance).with('myserver', '123').and_return(http)
|
1044
|
-
allow(@agent).to receive(:run_internal)
|
1045
|
-
|
1046
|
-
@agent.run
|
1047
|
-
end
|
1048
|
-
|
1049
1027
|
it "should report when a server is unavailable" do
|
1050
1028
|
Puppet.settings[:server_list] = ["myserver:123"]
|
1051
|
-
response = Net::HTTPInternalServerError.new(nil, 500, 'Internal Server Error')
|
1052
|
-
allow(Puppet::Network::HttpPool).to receive(:http_ssl_instance).with('myserver', '123').and_return(double('request', get: response))
|
1053
|
-
allow(@agent).to receive(:run_internal)
|
1054
1029
|
|
1030
|
+
stub_request(:get, 'https://myserver:123/status/v1/simple/master').to_return(status: [500, "Internal Server Error"])
|
1031
|
+
|
1032
|
+
allow(Puppet).to receive(:debug)
|
1055
1033
|
expect(Puppet).to receive(:debug).with("Puppet server myserver:123 is unavailable: 500 Internal Server Error")
|
1056
|
-
expect {
|
1034
|
+
expect {
|
1035
|
+
configurer.run
|
1036
|
+
}.to raise_error(Puppet::Error, /Could not select a functional puppet master from server_list:/)
|
1057
1037
|
end
|
1058
1038
|
|
1059
1039
|
it "should error when no servers in 'server_list' are reachable" do
|
1060
1040
|
Puppet.settings[:server_list] = "myserver:123,someotherservername"
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
expect{ @agent.run }.to raise_error(Puppet::Error, /Could not select a functional puppet master from server_list: 'myserver:123,someotherservername'/)
|
1041
|
+
|
1042
|
+
stub_request(:get, 'https://myserver/status/v1/simple/master').to_return(status: 400)
|
1043
|
+
stub_request(:get, 'https://someotherservername/status/v1/simple/master').to_return(status: 400)
|
1044
|
+
|
1045
|
+
expect{
|
1046
|
+
configurer.run
|
1047
|
+
}.to raise_error(Puppet::Error, /Could not select a functional puppet master from server_list: 'myserver:123,someotherservername'/)
|
1069
1048
|
end
|
1070
1049
|
|
1071
|
-
it "should not make multiple node
|
1072
|
-
response = Net::HTTPOK.new(nil, 200, 'OK')
|
1073
|
-
allow(Puppet::Network::HttpPool).to receive(:http_ssl_instance).with('myserver', '123').and_return(double('request', get: response))
|
1074
|
-
|
1050
|
+
it "should not make multiple node requests when the server is found" do
|
1075
1051
|
Puppet.settings[:server_list] = ["myserver:123"]
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1052
|
+
Puppet::Node.indirection.terminus_class = :rest
|
1053
|
+
Puppet::Resource::Catalog.indirection.terminus_class = :rest
|
1054
|
+
|
1055
|
+
stub_request(:get, 'https://myserver:123/status/v1/simple/master').to_return(status: 200)
|
1056
|
+
stub_request(:get, %r{https://myserver:123/puppet/v3/catalog}).to_return(status: 200)
|
1057
|
+
node_request = stub_request(:get, %r{https://myserver:123/puppet/v3/node/}).to_return(status: 200)
|
1058
|
+
|
1059
|
+
configurer.run
|
1060
|
+
|
1061
|
+
expect(node_request).to have_been_requested.once
|
1079
1062
|
end
|
1080
1063
|
end
|
1081
1064
|
end
|