puppet 6.18.0-x86-mingw32 → 6.19.0-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.

Files changed (144) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +8 -10
  3. data/README.md +1 -2
  4. data/Rakefile +4 -12
  5. data/lib/puppet/agent/locker.rb +0 -7
  6. data/lib/puppet/application/agent.rb +8 -3
  7. data/lib/puppet/application/doc.rb +1 -1
  8. data/lib/puppet/application/lookup.rb +5 -5
  9. data/lib/puppet/configurer.rb +39 -7
  10. data/lib/puppet/defaults.rb +55 -29
  11. data/lib/puppet/environments.rb +51 -10
  12. data/lib/puppet/face/catalog.rb +1 -1
  13. data/lib/puppet/face/config.rb +46 -16
  14. data/lib/puppet/face/node.rb +3 -3
  15. data/lib/puppet/face/node/clean.rb +2 -2
  16. data/lib/puppet/face/status.rb +1 -1
  17. data/lib/puppet/file_bucket/dipper.rb +1 -1
  18. data/lib/puppet/functions/new.rb +8 -3
  19. data/lib/puppet/http.rb +1 -0
  20. data/lib/puppet/http/client.rb +1 -1
  21. data/lib/puppet/http/resolver.rb +5 -8
  22. data/lib/puppet/http/resolver/server_list.rb +18 -36
  23. data/lib/puppet/http/resolver/settings.rb +4 -4
  24. data/lib/puppet/http/resolver/srv.rb +5 -5
  25. data/lib/puppet/http/service.rb +3 -1
  26. data/lib/puppet/http/service/compiler.rb +1 -1
  27. data/lib/puppet/http/service/file_server.rb +1 -1
  28. data/lib/puppet/http/service/puppetserver.rb +39 -0
  29. data/lib/puppet/http/session.rb +5 -4
  30. data/lib/puppet/indirector/catalog/compiler.rb +1 -1
  31. data/lib/puppet/indirector/facts/yaml.rb +1 -1
  32. data/lib/puppet/indirector/json.rb +1 -1
  33. data/lib/puppet/indirector/msgpack.rb +1 -1
  34. data/lib/puppet/indirector/request.rb +4 -4
  35. data/lib/puppet/indirector/yaml.rb +1 -1
  36. data/lib/puppet/network/http/api/master/v3/environments.rb +0 -1
  37. data/lib/puppet/node/facts.rb +17 -0
  38. data/lib/puppet/pops/evaluator/collectors/abstract_collector.rb +1 -3
  39. data/lib/puppet/pops/evaluator/runtime3_converter.rb +2 -2
  40. data/lib/puppet/pops/types/p_meta_type.rb +1 -1
  41. data/lib/puppet/pops/types/p_type_set_type.rb +4 -0
  42. data/lib/puppet/provider/package/dpkg.rb +1 -1
  43. data/lib/puppet/provider/package/pip2.rb +17 -0
  44. data/lib/puppet/provider/package/puppetserver_gem.rb +180 -0
  45. data/lib/puppet/provider/package/yum.rb +1 -0
  46. data/lib/puppet/resource/type.rb +2 -1
  47. data/lib/puppet/rest/route.rb +2 -2
  48. data/lib/puppet/settings.rb +19 -5
  49. data/lib/puppet/transaction/report.rb +11 -7
  50. data/lib/puppet/type/file/source.rb +1 -1
  51. data/lib/puppet/type/filebucket.rb +1 -1
  52. data/lib/puppet/util/connection.rb +8 -8
  53. data/lib/puppet/util/run_mode.rb +5 -1
  54. data/lib/puppet/version.rb +1 -1
  55. data/locales/puppet.pot +153 -156
  56. data/man/man5/puppet.conf.5 +29 -13
  57. data/man/man8/puppet-agent.8 +6 -3
  58. data/man/man8/puppet-apply.8 +1 -1
  59. data/man/man8/puppet-catalog.8 +1 -1
  60. data/man/man8/puppet-config.8 +6 -6
  61. data/man/man8/puppet-describe.8 +1 -1
  62. data/man/man8/puppet-device.8 +1 -1
  63. data/man/man8/puppet-doc.8 +1 -1
  64. data/man/man8/puppet-epp.8 +1 -1
  65. data/man/man8/puppet-facts.8 +1 -1
  66. data/man/man8/puppet-filebucket.8 +1 -1
  67. data/man/man8/puppet-generate.8 +1 -1
  68. data/man/man8/puppet-help.8 +1 -1
  69. data/man/man8/puppet-key.8 +1 -1
  70. data/man/man8/puppet-lookup.8 +1 -1
  71. data/man/man8/puppet-man.8 +1 -1
  72. data/man/man8/puppet-module.8 +1 -1
  73. data/man/man8/puppet-node.8 +4 -4
  74. data/man/man8/puppet-parser.8 +1 -1
  75. data/man/man8/puppet-plugin.8 +1 -1
  76. data/man/man8/puppet-report.8 +1 -1
  77. data/man/man8/puppet-resource.8 +1 -1
  78. data/man/man8/puppet-script.8 +1 -1
  79. data/man/man8/puppet-ssl.8 +1 -1
  80. data/man/man8/puppet-status.8 +2 -2
  81. data/man/man8/puppet.8 +2 -2
  82. data/spec/fixtures/unit/provider/package/puppetserver_gem/gem-list-local-packages +30 -0
  83. data/spec/integration/application/agent_spec.rb +23 -19
  84. data/spec/integration/application/filebucket_spec.rb +7 -7
  85. data/spec/integration/application/plugin_spec.rb +3 -3
  86. data/spec/integration/configurer_spec.rb +14 -0
  87. data/spec/integration/defaults_spec.rb +26 -1
  88. data/spec/integration/util/windows/adsi_spec.rb +2 -2
  89. data/spec/shared_contexts/types_setup.rb +2 -0
  90. data/spec/unit/application/doc_spec.rb +2 -2
  91. data/spec/unit/application/facts_spec.rb +3 -1
  92. data/spec/unit/application_spec.rb +9 -4
  93. data/spec/unit/configurer_spec.rb +39 -6
  94. data/spec/unit/environments_spec.rb +99 -32
  95. data/spec/unit/face/config_spec.rb +56 -0
  96. data/spec/unit/face/node_spec.rb +2 -2
  97. data/spec/unit/file_system_spec.rb +1 -2
  98. data/spec/unit/http/resolver_spec.rb +24 -4
  99. data/spec/unit/http/service/ca_spec.rb +2 -2
  100. data/spec/unit/http/service/compiler_spec.rb +2 -2
  101. data/spec/unit/http/service/file_server_spec.rb +2 -2
  102. data/spec/unit/http/service/puppetserver_spec.rb +82 -0
  103. data/spec/unit/http/service/report_spec.rb +2 -2
  104. data/spec/unit/http/session_spec.rb +8 -20
  105. data/spec/unit/indirector/catalog/json_spec.rb +1 -1
  106. data/spec/unit/indirector/catalog/rest_spec.rb +1 -1
  107. data/spec/unit/indirector/facts/rest_spec.rb +1 -1
  108. data/spec/unit/indirector/json_spec.rb +8 -8
  109. data/spec/unit/indirector/msgpack_spec.rb +8 -8
  110. data/spec/unit/indirector/node/rest_spec.rb +1 -1
  111. data/spec/unit/indirector/request_spec.rb +4 -4
  112. data/spec/unit/indirector/rest_spec.rb +1 -1
  113. data/spec/unit/indirector/status/rest_spec.rb +1 -1
  114. data/spec/unit/indirector/yaml_spec.rb +7 -7
  115. data/spec/unit/network/http/api/master/v3/environments_spec.rb +12 -23
  116. data/spec/unit/provider/exec_spec.rb +4 -3
  117. data/spec/unit/provider/package/dpkg_spec.rb +22 -7
  118. data/spec/unit/provider/package/openbsd_spec.rb +2 -0
  119. data/spec/unit/provider/package/pip2_spec.rb +36 -0
  120. data/spec/unit/provider/package/puppetserver_gem_spec.rb +137 -0
  121. data/spec/unit/provider/package/yum_spec.rb +31 -0
  122. data/spec/unit/provider/service/base_spec.rb +2 -4
  123. data/spec/unit/provider/service/bsd_spec.rb +5 -1
  124. data/spec/unit/provider/service/daemontools_spec.rb +1 -1
  125. data/spec/unit/provider/service/debian_spec.rb +3 -5
  126. data/spec/unit/provider/service/freebsd_spec.rb +1 -1
  127. data/spec/unit/provider/service/gentoo_spec.rb +4 -5
  128. data/spec/unit/provider/service/init_spec.rb +4 -5
  129. data/spec/unit/provider/service/launchd_spec.rb +5 -6
  130. data/spec/unit/provider/service/openrc_spec.rb +4 -5
  131. data/spec/unit/provider/service/openwrt_spec.rb +1 -1
  132. data/spec/unit/provider/service/redhat_spec.rb +1 -1
  133. data/spec/unit/provider/service/runit_spec.rb +2 -1
  134. data/spec/unit/provider/service/smf_spec.rb +1 -1
  135. data/spec/unit/provider/service/src_spec.rb +3 -5
  136. data/spec/unit/provider/service/systemd_spec.rb +3 -1
  137. data/spec/unit/provider/service/upstart_spec.rb +4 -5
  138. data/spec/unit/rest/route_spec.rb +4 -4
  139. data/spec/unit/settings_spec.rb +44 -22
  140. data/spec/unit/transaction/report_spec.rb +2 -0
  141. data/spec/unit/type/file/source_spec.rb +1 -1
  142. data/spec/unit/type/filebucket_spec.rb +1 -1
  143. data/spec/unit/util/run_mode_spec.rb +6 -6
  144. metadata +13 -2
@@ -436,25 +436,6 @@ config_version=$vardir/random/scripts
436
436
  end
437
437
  end
438
438
  end
439
-
440
- context "custom cache expiration service" do
441
- it "consults the custom service to expire the cache" do
442
- loader_from(:filesystem => [directory_tree],
443
- :directory => directory_tree.children.first) do |loader|
444
- service = ReplayExpirationService.new([true])
445
- using_expiration_service(service) do
446
-
447
- cached = Puppet::Environments::Cached.new(loader)
448
- cached.get(:an_environment)
449
- cached.get(:an_environment)
450
-
451
- expect(service.created_envs).to include(:an_environment)
452
- expect(service.expired_envs).to include(:an_environment)
453
- expect(service.evicted_envs).to include(:an_environment)
454
- end
455
- end
456
- end
457
- end
458
439
  end
459
440
  end
460
441
 
@@ -645,6 +626,102 @@ config_version=$vardir/random/scripts
645
626
  end
646
627
  end
647
628
 
629
+ context "expiration policies" do
630
+ let(:service) { ReplayExpirationService.new }
631
+
632
+ # The environment named `:an_environment` will already be loaded when the
633
+ # block is yielded to
634
+ def with_environment_loaded(service, &block)
635
+ loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
636
+ using_expiration_service(service) do
637
+ cached = Puppet::Environments::Cached.new(loader)
638
+ cached.get!(:an_environment)
639
+
640
+ yield cached if block_given?
641
+ end
642
+ end
643
+ end
644
+
645
+ it "notifies when the environment is first created" do
646
+ with_environment_loaded(service)
647
+
648
+ expect(service.created_envs).to eq([:an_environment])
649
+ end
650
+
651
+ it "does not evict an unexpired environment" do
652
+ Puppet[:environment_timeout] = 'unlimited'
653
+
654
+ with_environment_loaded(service) do |cached|
655
+ cached.get!(:an_environment)
656
+ end
657
+
658
+ expect(service.created_envs).to eq([:an_environment])
659
+ expect(service.evicted_envs).to eq([])
660
+ end
661
+
662
+ it "evicts an expired environment" do
663
+ service = ReplayExpirationService.new
664
+
665
+ # The `Cached#clear_all_expired` method tries to optimize the case where
666
+ # no entries are expired. But if `Time.now < @next_expiration` and there is
667
+ # an expired entry, then the `service#expired?` method is called twice.
668
+ expect(service).to receive(:expired?).twice.and_return(true)
669
+
670
+ with_environment_loaded(service) do |cached|
671
+ cached.get!(:an_environment)
672
+ end
673
+
674
+ expect(service.created_envs).to eq([:an_environment, :an_environment])
675
+ expect(service.evicted_envs).to eq([:an_environment])
676
+ end
677
+
678
+ it "evicts an environment that hasn't been recently touched" do
679
+ Puppet[:environment_timeout] = 1
680
+ Puppet[:environment_timeout_mode] = :from_last_used
681
+
682
+ with_environment_loaded(service) do |cached|
683
+ future = Time.now + 60
684
+ expect(Time).to receive(:now).and_return(future).at_least(:once)
685
+
686
+ # this should cause the cached environment to be evicted and a new one created
687
+ cached.get!(:an_environment)
688
+ end
689
+
690
+ expect(service.created_envs).to eq([:an_environment, :an_environment])
691
+ expect(service.evicted_envs).to eq([:an_environment])
692
+
693
+ end
694
+
695
+ it "reuses an environment that was recently touched" do
696
+ Puppet[:environment_timeout] = 60
697
+ Puppet[:environment_timeout_mode] = :from_last_used
698
+
699
+ with_environment_loaded(service) do |cached|
700
+ # reuse the already cached environment
701
+ cached.get!(:an_environment)
702
+ end
703
+
704
+ expect(service.created_envs).to eq([:an_environment])
705
+ expect(service.evicted_envs).to eq([])
706
+ end
707
+
708
+ it "evicts a recently touched environment" do
709
+ Puppet[:environment_timeout] = 60
710
+ Puppet[:environment_timeout_mode] = :from_last_used
711
+
712
+ # see note above about "twice"
713
+ expect(service).to receive(:expired?).twice.and_return(true)
714
+
715
+ with_environment_loaded(service) do |cached|
716
+ # even though the environment was recently touched, it's been expired
717
+ cached.get!(:an_environment)
718
+ end
719
+
720
+ expect(service.created_envs).to eq([:an_environment, :an_environment])
721
+ expect(service.evicted_envs).to eq([:an_environment])
722
+ end
723
+ end
724
+
648
725
  it "gets an environment.conf" do
649
726
  loader_from(:filesystem => [directory_tree], :directory => directory_tree.children.first) do |loader|
650
727
  expect(Puppet::Environments::Cached.new(loader).get_conf(:an_environment)).to match_environment_conf(:an_environment).
@@ -746,31 +823,21 @@ config_version=$vardir/random/scripts
746
823
  end
747
824
  end
748
825
 
749
- class ReplayExpirationService
750
- attr_reader :created_envs, :expired_envs, :evicted_envs
826
+ class ReplayExpirationService < Puppet::Environments::Cached::DefaultCacheExpirationService
827
+ attr_reader :created_envs, :evicted_envs
751
828
 
752
- def initialize(expiration_sequence)
829
+ def initialize
753
830
  @created_envs = []
754
- @expired_envs = []
755
831
  @evicted_envs = []
756
- @expiration_sequence = expiration_sequence
757
832
  end
758
833
 
759
834
  def created(env)
760
835
  @created_envs << env.name
761
836
  end
762
837
 
763
- def expired?(env_name)
764
- # make expired? idempotent
765
- return true if @expired_envs.include? (env_name)
766
- @expired_envs << env_name
767
- @expiration_sequence.pop
768
- end
769
-
770
838
  def evicted(env_name)
771
839
  @evicted_envs << env_name
772
840
  end
773
841
  end
774
-
775
842
  end
776
843
  end
@@ -200,6 +200,44 @@ trace = true
200
200
  expect(Puppet::FileSystem).to receive(:open).with(path, nil, 'r+:UTF-8')
201
201
  subject.set('foo', 'bar')
202
202
  end
203
+
204
+ it "sets settings into the [server] section when setting [master] section settings" do
205
+ initial_contents = <<-CONFIG
206
+ [master]
207
+ setting = old_setting_value
208
+ untouched_setting = value
209
+ CONFIG
210
+
211
+ myinitialfile = StringIO.new(initial_contents)
212
+ allow(Puppet::FileSystem).to receive(:open).with(path, anything, anything).and_yield(myinitialfile)
213
+
214
+ expect {
215
+ subject.set('setting', 'new_setting_value', {:section => 'master'})
216
+ }.to output("Deleted setting from 'master': 'setting = old_setting_value', and adding it to 'server' section\n").to_stdout
217
+ modified_content = <<-CONFIG
218
+ [master]
219
+ untouched_setting = value
220
+ [server]
221
+ setting = new_setting_value
222
+ CONFIG
223
+
224
+ mymodifiedfile = StringIO.new(modified_content)
225
+ expect(myinitialfile.string).to match(mymodifiedfile.string)
226
+ end
227
+
228
+ it "setting [master] section settings, sets settings into [server] section instead" do
229
+ myinitialfile = StringIO.new("")
230
+ allow(Puppet::FileSystem).to receive(:open).with(path, anything, anything).and_yield(myinitialfile)
231
+ subject.set('setting_name', 'value', {:section => 'master'})
232
+
233
+ expected_content = <<-CONFIG
234
+ [server]
235
+ setting_name = value
236
+ CONFIG
237
+
238
+ myexpectedfile = StringIO.new(expected_content)
239
+ expect(myinitialfile.string).to match(myexpectedfile.string)
240
+ end
203
241
  end
204
242
 
205
243
  context 'when the puppet.conf file does not exist' do
@@ -249,6 +287,24 @@ trace = true
249
287
  expect(Puppet).to receive(:warning).with("No setting found in configuration file for section 'main' setting name 'setting'")
250
288
  subject.delete('setting', {:section => 'main'})
251
289
  end
290
+
291
+ ['master', 'server'].each do |section|
292
+ describe "when deleting from [#{section}] section" do
293
+ it "deletes section values from both [server] and [master] sections" do
294
+ allow(Puppet::FileSystem).to receive(:open).with(path, anything, anything).and_yield(StringIO.new)
295
+ config = Puppet::Settings::IniFile.new([Puppet::Settings::IniFile::DefaultSection.new])
296
+ manipulator = Puppet::Settings::IniFile::Manipulator.new(config)
297
+ allow(Puppet::Settings::IniFile::Manipulator).to receive(:new).and_return(manipulator)
298
+
299
+ expect(manipulator).to receive(:delete).with('master', 'setting').and_return('setting=value')
300
+ expect(manipulator).to receive(:delete).with('server', 'setting').and_return('setting=value')
301
+ expect {
302
+ subject.delete('setting', {:section => section})
303
+ }.to output(/Deleted setting from 'master': 'setting'\nDeleted setting from 'server': 'setting'\n/).to_stdout
304
+ end
305
+ end
306
+ end
307
+
252
308
  end
253
309
 
254
310
  shared_examples_for :config_printing_a_section do |section|
@@ -74,9 +74,9 @@ describe Puppet::Face[:node, '0.0.1'] do
74
74
  subject.clean('hostname')
75
75
  end
76
76
 
77
- it "should run in master mode" do
77
+ it "should run in server mode" do
78
78
  subject.clean('hostname')
79
- expect(Puppet.run_mode).to be_master
79
+ expect(Puppet.run_mode).to be_server
80
80
  end
81
81
 
82
82
  it "should set node cache as yaml" do
@@ -872,8 +872,7 @@ describe "Puppet::FileSystem" do
872
872
 
873
873
  # regardless of slash direction, return value is drive letter
874
874
  expanded = Puppet::FileSystem.expand_path(slash)
875
- expect(expanded).to eq(ENV['SystemDrive'] + File::SEPARATOR)
876
- expect(expanded).to eq(File.expand_path(slash))
875
+ expect(expanded).to match(/^[a-z]:/i)
877
876
  end
878
877
  end
879
878
 
@@ -43,9 +43,25 @@ describe Puppet::HTTP::Resolver do
43
43
  expect(service.url.to_s).to eq("https://ca.example.com:8141/puppet-ca/v1")
44
44
  end
45
45
 
46
- it 'logs unsuccessful HTTP 500 responses' do
47
- Puppet[:log_level] = "debug"
46
+ it 'includes extra http headers' do
47
+ Puppet[:http_extra_headers] = 'region:us-west'
48
+
49
+ stub_request(:get, "https://ca.example.com:8141/status/v1/simple/master")
50
+ .with(headers: {'Region' => 'us-west'})
51
+
52
+ subject.resolve(session, :ca)
53
+ end
54
+
55
+ it 'uses the provided ssl context during resolution' do
56
+ stub_request(:get, "https://ca.example.com:8141/status/v1/simple/master").to_return(status: 200)
57
+
58
+ other_ctx = Puppet::SSL::SSLContext.new
59
+ expect(client).to receive(:connect).with(URI("https://ca.example.com:8141/status/v1/simple/master"), options: {ssl_context: other_ctx}).and_call_original
60
+
61
+ subject.resolve(session, :ca, ssl_context: other_ctx)
62
+ end
48
63
 
64
+ it 'logs unsuccessful HTTP 500 responses' do
49
65
  stub_request(:get, "https://ca.example.com:8141/status/v1/simple/master").to_return(status: [500, 'Internal Server Error'])
50
66
  stub_request(:get, "https://apple.example.com:8142/status/v1/simple/master").to_return(status: 200)
51
67
 
@@ -54,11 +70,15 @@ describe Puppet::HTTP::Resolver do
54
70
  expect(@logs.map(&:message)).to include(/Puppet server ca.example.com:8141 is unavailable: 500 Internal Server Error/)
55
71
  end
56
72
 
57
- it 'fails if no servers in server_list are accessible' do
73
+ it 'cancels resolution if no servers in server_list are accessible' do
58
74
  stub_request(:get, "https://ca.example.com:8141/status/v1/simple/master").to_return(status: 503)
59
75
  stub_request(:get, "https://apple.example.com:8142/status/v1/simple/master").to_return(status: 503)
60
76
 
61
- expect { subject.resolve(session, :ca) }.to raise_error(Puppet::Error, /^Could not select a functional puppet master from server_list:/)
77
+ canceled = false
78
+ canceled_handler = lambda { |cancel| canceled = cancel }
79
+
80
+ expect(subject.resolve(session, :ca, canceled_handler: canceled_handler)).to eq(nil)
81
+ expect(canceled).to eq(true)
62
82
  end
63
83
 
64
84
  it 'cycles through server_list until a valid server is found' do
@@ -38,11 +38,11 @@ describe Puppet::HTTP::Service::Ca do
38
38
  subject.get_certificate('ca')
39
39
  end
40
40
 
41
- it 'fallbacks to server and masterport' do
41
+ it 'fallbacks to server and serverport' do
42
42
  Puppet[:ca_server] = nil
43
43
  Puppet[:ca_port] = nil
44
44
  Puppet[:server] = 'ca2.example.com'
45
- Puppet[:masterport] = 8142
45
+ Puppet[:serverport] = 8142
46
46
 
47
47
  stub_request(:get, "https://ca2.example.com:8142/puppet-ca/v1/certificate/ca").to_return(body: pem)
48
48
 
@@ -16,7 +16,7 @@ describe Puppet::HTTP::Service::Compiler do
16
16
 
17
17
  before :each do
18
18
  Puppet[:server] = 'compiler.example.com'
19
- Puppet[:masterport] = 8140
19
+ Puppet[:serverport] = 8140
20
20
 
21
21
  Puppet::Node::Facts.indirection.terminus_class = :memory
22
22
  end
@@ -37,7 +37,7 @@ describe Puppet::HTTP::Service::Compiler do
37
37
  context 'when routing to the compiler service' do
38
38
  it 'defaults the server and port based on settings' do
39
39
  Puppet[:server] = 'compiler2.example.com'
40
- Puppet[:masterport] = 8141
40
+ Puppet[:serverport] = 8141
41
41
 
42
42
  stub_request(:post, "https://compiler2.example.com:8141/puppet/v3/catalog/ziggy?environment=testing")
43
43
  .to_return(body: formatter.render(catalog), headers: {'Content-Type' => formatter.mime })
@@ -12,7 +12,7 @@ describe Puppet::HTTP::Service::FileServer do
12
12
 
13
13
  before :each do
14
14
  Puppet[:server] = 'www.example.com'
15
- Puppet[:masterport] = 443
15
+ Puppet[:serverport] = 443
16
16
  end
17
17
 
18
18
  context 'when making requests' do
@@ -31,7 +31,7 @@ describe Puppet::HTTP::Service::FileServer do
31
31
  context 'when routing to the file service' do
32
32
  it 'defaults the server and port based on settings' do
33
33
  Puppet[:server] = 'file.example.com'
34
- Puppet[:masterport] = 8141
34
+ Puppet[:serverport] = 8141
35
35
 
36
36
  stub_request(:get, "https://file.example.com:8141/puppet/v3/file_content/:mount/:path?environment=testing")
37
37
 
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+ require 'puppet/http'
3
+
4
+ describe Puppet::HTTP::Service::Puppetserver do
5
+ let(:ssl_context) { Puppet::SSL::SSLContext.new }
6
+ let(:client) { Puppet::HTTP::Client.new(ssl_context: ssl_context) }
7
+ let(:subject) { client.create_session.route_to(:puppetserver) }
8
+
9
+ before :each do
10
+ Puppet[:server] = 'puppetserver.example.com'
11
+ end
12
+
13
+ context 'when making requests' do
14
+ it 'includes default HTTP headers' do
15
+ stub_request(:get, "https://puppetserver.example.com:8140/status/v1/simple/master").with do |request|
16
+ expect(request.headers).to include({'X-Puppet-Version' => /./, 'User-Agent' => /./})
17
+ expect(request.headers).to_not include('X-Puppet-Profiling')
18
+ end.to_return(body: "running", headers: {'Content-Type' => 'text/plain;charset=utf-8'})
19
+
20
+ subject.get_simple_status
21
+ end
22
+
23
+ it 'includes extra headers' do
24
+ Puppet[:http_extra_headers] = 'region:us-west'
25
+
26
+ stub_request(:get, "https://puppetserver.example.com:8140/status/v1/simple/master")
27
+ .with(headers: {'Region' => 'us-west'})
28
+ .to_return(body: "running", headers: {'Content-Type' => 'text/plain;charset=utf-8'})
29
+
30
+ subject.get_simple_status
31
+ end
32
+ end
33
+
34
+ context 'when routing to the puppetserver service' do
35
+ it 'defaults the server and port based on settings' do
36
+ Puppet[:server] = 'compiler2.example.com'
37
+ Puppet[:serverport] = 8141
38
+
39
+ stub_request(:get, "https://compiler2.example.com:8141/status/v1/simple/master")
40
+ .to_return(body: "running", headers: {'Content-Type' => 'text/plain;charset=utf-8'})
41
+
42
+ subject.get_simple_status
43
+ end
44
+ end
45
+
46
+ context 'when getting puppetserver status' do
47
+ let(:url) { "https://puppetserver.example.com:8140/status/v1/simple/master" }
48
+
49
+ it 'returns the request response and status' do
50
+ stub_request(:get, url)
51
+ .to_return(body: "running", headers: {'Content-Type' => 'text/plain;charset=utf-8'})
52
+
53
+ resp, status = subject.get_simple_status
54
+ expect(resp).to be_a(Puppet::HTTP::Response)
55
+ expect(status).to eq('running')
56
+ end
57
+
58
+ it 'raises a response error if unsuccessful' do
59
+ stub_request(:get, url).to_return(status: [500, 'Internal Server Error'])
60
+
61
+ expect {
62
+ subject.get_simple_status
63
+ }.to raise_error do |err|
64
+ expect(err).to be_an_instance_of(Puppet::HTTP::ResponseError)
65
+ expect(err.message).to eq("Internal Server Error")
66
+ expect(err.response.code).to eq(500)
67
+ end
68
+ end
69
+
70
+ it 'accepts an ssl context' do
71
+ stub_request(:get, url)
72
+ .to_return(body: "running", headers: {'Content-Type' => 'text/plain;charset=utf-8'})
73
+
74
+ other_ctx = Puppet::SSL::SSLContext.new
75
+ expect(client).to receive(:connect).with(URI(url), options: {ssl_context: other_ctx}).and_call_original
76
+
77
+ session = client.create_session
78
+ service = Puppet::HTTP::Service.create_service(client, session, :puppetserver, 'puppetserver.example.com', 8140)
79
+ service.get_simple_status(ssl_context: other_ctx)
80
+ end
81
+ end
82
+ end
@@ -36,11 +36,11 @@ describe Puppet::HTTP::Service::Report do
36
36
  subject.put_report('report', report, environment: environment)
37
37
  end
38
38
 
39
- it 'fallbacks to server and masterport' do
39
+ it 'fallbacks to server and serverport' do
40
40
  Puppet[:report_server] = nil
41
41
  Puppet[:report_port] = nil
42
42
  Puppet[:server] = 'report2.example.com'
43
- Puppet[:masterport] = 8142
43
+ Puppet[:serverport] = 8142
44
44
 
45
45
  stub_request(:put, "https://report2.example.com:8142/puppet/v3/report/report?environment=testing")
46
46