|
78 | 78 | configurer.run(:pluginsync => false)
|
79 | 79 | end
|
80 | 80 |
|
| 81 | + it "should carry on when it can't fetch its node definition" do |
| 82 | + error = Net::HTTPError.new(400, 'dummy server communication error') |
| 83 | + expect(Puppet::Node.indirection).to receive(:find).and_raise(error) |
| 84 | + expect(configurer.run).to eq(0) |
| 85 | + end |
| 86 | + |
81 | 87 | it "fails the run if pluginsync fails when usecacheonfailure is false" do
|
82 | 88 | Puppet[:ignore_plugin_errors] = false
|
83 | 89 |
|
|
119 | 125 | it "applies a cached catalog when it can't connect to the master" do
|
120 | 126 | error = Errno::ECONNREFUSED.new('Connection refused - connect(2)')
|
121 | 127 |
|
| 128 | + expect(Puppet::Node.indirection).to receive(:find).and_raise(error) |
122 | 129 | expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(:ignore_cache => true)).and_raise(error)
|
123 | 130 | expect(Puppet::Resource::Catalog.indirection).to receive(:find).with(anything, hash_including(:ignore_terminus => true)).and_return(catalog)
|
124 | 131 |
|
@@ -546,6 +553,24 @@ def method_missing(*args)
|
546 | 553 | end
|
547 | 554 | end
|
548 | 555 |
|
| 556 | + describe "when requesting a node" do |
| 557 | + it "uses the transaction uuid in the request" do |
| 558 | + expect(Puppet::Node.indirection).to receive(:find).with(anything, hash_including(transaction_uuid: anything)).twice |
| 559 | + configurer.run |
| 560 | + end |
| 561 | + |
| 562 | + it "sends an explicitly configured environment request" do |
| 563 | + expect(Puppet.settings).to receive(:set_by_config?).with(:environment).and_return(true) |
| 564 | + expect(Puppet::Node.indirection).to receive(:find).with(anything, hash_including(configured_environment: Puppet[:environment])).twice |
| 565 | + configurer.run |
| 566 | + end |
| 567 | + |
| 568 | + it "does not send a configured_environment when using the default" do |
| 569 | + expect(Puppet::Node.indirection).to receive(:find).with(anything, hash_including(configured_environment: nil)).twice |
| 570 | + configurer.run |
| 571 | + end |
| 572 | + end |
| 573 | + |
549 | 574 | def expects_pluginsync
|
550 | 575 | metadata = "[{\"path\":\"/etc/puppetlabs/code\",\"relative_path\":\".\",\"links\":\"follow\",\"owner\":0,\"group\":0,\"mode\":420,\"checksum\":{\"type\":\"ctime\",\"value\":\"{ctime}2020-07-10 14:00:00 -0700\"},\"type\":\"directory\",\"destination\":null}]"
|
551 | 576 | stub_request(:get, %r{/puppet/v3/file_metadatas/(plugins|locales)}).to_return(status: 200, body: metadata, headers: {'Content-Type' => 'application/json'})
|
@@ -597,13 +622,21 @@ def expects_neither_new_or_cached_catalog
|
597 | 622 | configurer.run
|
598 | 623 | end
|
599 | 624 |
|
600 |
| - it "should not pluginsync when a cached catalog is successfully retrieved" do |
| 625 | + it "should not make a node request or pluginsync when a cached catalog is successfully retrieved" do |
| 626 | + expect(Puppet::Node.indirection).not_to receive(:find) |
601 | 627 | expects_cached_catalog_only(catalog)
|
602 | 628 | expect(configurer).not_to receive(:download_plugins)
|
603 | 629 |
|
604 | 630 | configurer.run
|
605 | 631 | end
|
606 | 632 |
|
| 633 | + it "should make a node request and pluginsync when a cached catalog cannot be retrieved" do |
| 634 | + expect(Puppet::Node.indirection).to receive(:find).and_return(nil) |
| 635 | + expects_fallback_to_new_catalog(catalog) |
| 636 | + |
| 637 | + configurer.run |
| 638 | + end |
| 639 | + |
607 | 640 | it "should set its cached_catalog_status to 'explicitly_requested'" do
|
608 | 641 | expects_cached_catalog_only(catalog)
|
609 | 642 |
|
@@ -635,6 +668,7 @@ def expects_neither_new_or_cached_catalog
|
635 | 668 | end
|
636 | 669 |
|
637 | 670 | it "should not attempt to retrieve a cached catalog again if the first attempt failed" do
|
| 671 | + expect(Puppet::Node.indirection).to receive(:find).and_return(nil) |
638 | 672 | expects_neither_new_or_cached_catalog
|
639 | 673 | expects_pluginsync
|
640 | 674 |
|
@@ -690,6 +724,16 @@ def expects_neither_new_or_cached_catalog
|
690 | 724 | Puppet.settings[:strict_environment_mode] = true
|
691 | 725 | end
|
692 | 726 |
|
| 727 | + it "should not make a node request" do |
| 728 | + stub_request(:get, %r{/puppet/v3/file_metadatas?/plugins}).to_return(:status => 404) |
| 729 | + stub_request(:get, %r{/puppet/v3/file_metadatas?/pluginfacts}).to_return(:status => 404) |
| 730 | + expects_new_catalog_only(catalog) |
| 731 | + |
| 732 | + expect(Puppet::Node.indirection).not_to receive(:find) |
| 733 | + |
| 734 | + configurer.run |
| 735 | + end |
| 736 | + |
693 | 737 | it "should return nil when the catalog's environment doesn't match the agent specified environment" do
|
694 | 738 | Puppet[:environment] = 'second_env'
|
695 | 739 | configurer = Puppet::Configurer.new
|
@@ -1063,105 +1107,20 @@ def expects_neither_new_or_cached_catalog
|
1063 | 1107 | expect(configurer.run(options)).to eq(0)
|
1064 | 1108 | expect(options[:report].server_used).to be_nil
|
1065 | 1109 | end
|
1066 |
| - end |
1067 |
| - |
1068 |
| - describe "when selecting an environment" do |
1069 |
| - include PuppetSpec::Files |
1070 |
| - include PuppetSpec::Settings |
1071 |
| - |
1072 |
| - describe "when the last used environment is available" do |
1073 |
| - let(:last_used_environment) { 'development' } |
1074 |
| - let(:default_environment) { 'production' } |
1075 |
| - |
1076 |
| - before do |
1077 |
| - Puppet[:lastrunreport] = my_fixture('last_run_report.yaml') |
1078 |
| - Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY) |
1079 |
| - --- |
1080 |
| - version: |
1081 |
| - config: 1624882680 |
1082 |
| - environment: development |
1083 |
| - puppet: 6.24.0 |
1084 |
| - SUMMARY |
1085 |
| - end |
1086 | 1110 |
|
1087 |
| - it "prefers the environment set via cli" do |
1088 |
| - Puppet.settings.handlearg('--environment', 'usethis') |
1089 |
| - configurer.run |
1090 |
| - |
1091 |
| - expect(configurer.environment).to eq('usethis') |
1092 |
| - end |
1093 |
| - |
1094 |
| - it "prefers the environment set via config" do |
1095 |
| - FileUtils.mkdir_p(Puppet[:confdir]) |
1096 |
| - set_puppet_conf(Puppet[:confdir], <<~CONF) |
1097 |
| - [main] |
1098 |
| - environment = usethis |
1099 |
| - CONF |
1100 |
| - |
1101 |
| - Puppet.initialize_settings |
1102 |
| - configurer.run |
1103 |
| - |
1104 |
| - expect(configurer.environment).to eq('usethis') |
1105 |
| - end |
1106 |
| - |
1107 |
| - it "uses the default environment if given a catalog" do |
1108 |
| - configurer.run(catalog: catalog) |
1109 |
| - |
1110 |
| - expect(configurer.environment).to eq(default_environment) |
1111 |
| - end |
1112 |
| - |
1113 |
| - it "uses the default environment if use_cached_catalog = true" do |
1114 |
| - Puppet[:use_cached_catalog] = true |
1115 |
| - expects_cached_catalog_only(catalog) |
1116 |
| - configurer.run |
1117 |
| - |
1118 |
| - expect(configurer.environment).to eq(default_environment) |
1119 |
| - end |
1120 |
| - |
1121 |
| - describe "when the environment is not configured" do |
1122 |
| - it "uses the environment found in lastrunfile if the key exists" do |
1123 |
| - configurer.run |
1124 |
| - |
1125 |
| - expect(configurer.environment).to eq(last_used_environment) |
1126 |
| - end |
1127 |
| - |
1128 |
| - it "falls back to the environment from lastrunreport if lastrunfile does not contain the environment" do |
1129 |
| - Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY) |
1130 |
| - --- |
1131 |
| - version: |
1132 |
| - config: 1624882680 |
1133 |
| - puppet: 6.24.0 |
1134 |
| - SUMMARY |
1135 |
| - configurer.run |
1136 |
| - |
1137 |
| - expect(configurer.environment).to eq(last_used_environment) |
1138 |
| - end |
1139 |
| - |
1140 |
| - it "falls back to the environment from lastrunreport if lastrunfile is invalid YAML" do |
1141 |
| - Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', <<~SUMMARY) |
1142 |
| - Key: 'this is my very very very ' + |
1143 |
| - 'long string' |
1144 |
| - SUMMARY |
1145 |
| - configurer.run |
1146 |
| - |
1147 |
| - expect(configurer.environment).to eq(last_used_environment) |
1148 |
| - end |
| 1111 | + it "should not make multiple node requests when the server is found" do |
| 1112 | + Puppet.settings[:server_list] = ["myserver:123"] |
1149 | 1113 |
|
1150 |
| - it "falls back to the environment from lastrunreport if lastrunfile exists but is empty" do |
1151 |
| - Puppet[:lastrunfile] = file_containing('last_run_summary.yaml', '') |
1152 |
| - configurer.run |
| 1114 | + Puppet::Node.indirection.terminus_class = :rest |
| 1115 | + Puppet::Resource::Catalog.indirection.terminus_class = :rest |
1153 | 1116 |
|
1154 |
| - expect(configurer.environment).to eq(last_used_environment) |
1155 |
| - end |
| 1117 | + stub_request(:get, 'https://myserver:123/status/v1/simple/master').to_return(status: 200) |
| 1118 | + stub_request(:post, %r{https://myserver:123/puppet/v3/catalog}).to_return(status: 200) |
| 1119 | + node_request = stub_request(:get, %r{https://myserver:123/puppet/v3/node/}).to_return(status: 200) |
1156 | 1120 |
|
1157 |
| - it "uses the default environment if the last used one cannot be found" do |
1158 |
| - Puppet[:lastrunfile] = tmpfile('last_run_summary.yaml') |
1159 |
| - Puppet[:lastrunreport] = tmpfile('last_run_report.yaml') |
1160 |
| - configurer.run |
| 1121 | + configurer.run |
1161 | 1122 |
|
1162 |
| - expect(configurer.environment).to eq(default_environment) |
1163 |
| - end |
1164 |
| - end |
| 1123 | + expect(node_request).to have_been_requested.once |
1165 | 1124 | end
|
1166 | 1125 | end
|
1167 | 1126 | end
|
0 commit comments