diff options
author | John <john.mccrae@progress.com> | 2023-05-15 21:32:39 +0000 |
---|---|---|
committer | John <john.mccrae@progress.com> | 2023-05-15 21:32:39 +0000 |
commit | bc995775bf86e73f454a9779370d8aab2ae6d71b (patch) | |
tree | eb7d0b12c916d86f6e0754cef3b88902b979448c | |
parent | 4a0d3b475ab74ccc4b7e7354453e191ff892d604 (diff) | |
download | chef-bc995775bf86e73f454a9779370d8aab2ae6d71b.tar.gz |
[chef-17] 26 of X - Updating EOL Support
Signed-off-by: John <john.mccrae@progress.com>
-rw-r--r-- | lib/chef/client.rb | 19 | ||||
-rw-r--r-- | spec/unit/client_spec.rb | 44 |
2 files changed, 20 insertions, 43 deletions
diff --git a/lib/chef/client.rb b/lib/chef/client.rb index 1543c7cf85..4c690b230f 100644 --- a/lib/chef/client.rb +++ b/lib/chef/client.rb @@ -326,25 +326,20 @@ class Chef def warn_if_eol require_relative "version" - # New Date format is YYYY-MM-DD - new_date = eol_override? + # New Date format is YYYY-MM-DD or false + new_date = eol_override # We make a release every year so take the version you're on + 2006 and you get # the year it goes EOL eol_year = 2006 + Gem::Version.new(Chef::VERSION).segments.first + cut_off_date = !!new_date ? Time.parse(new_date) : Time.new(eol_year, 5, 01) - if !!new_date - new_eol_date = new_date.split("-") - year = new_eol_date[0] - month = Date::MONTHNAMES[new_eol_date[1].to_i] - day = new_eol_date[2] - logger.warn("This release of #{ChefUtils::Dist::Infra::PRODUCT} became end of life (EOL) on #{month} #{day} #{year}. Please update to a supported release to receive new features, bug fixes, and security updates.") - else Time.now > Time.new(eol_year, 5, 01) - logger.warn("This release of #{ChefUtils::Dist::Infra::PRODUCT} became end of life (EOL) on May 1st #{eol_year}. Please update to a supported release to receive new features, bug fixes, and security updates.") - end + return if Time.now < cut_off_date + + logger.warn("This release of #{ChefUtils::Dist::Infra::PRODUCT} became end of life (EOL) on #{cut_off_date.strftime('%b %d, %Y')}. Please update to a supported release to receive new features, bug fixes, and security updates.") end - def eol_override? + def eol_override # If you want to override the exisitn EOL date, add a file in the root of Chef # put a date in it in the form of YYYY-DD-MM. override_file = "EOL_override" diff --git a/spec/unit/client_spec.rb b/spec/unit/client_spec.rb index 78e485cf0c..ea0e72d83b 100644 --- a/spec/unit/client_spec.rb +++ b/spec/unit/client_spec.rb @@ -309,40 +309,22 @@ describe Chef::Client do end describe "eol release warning" do - before do - @local_client = Chef::Client.new - # allow_any_instance_of(client).to receive(:eol_override?).and_return(false) - # require "pry" - # binding.pry + it "warns when running an EOL release" do + stub_const("Chef::VERSION", 15) + # added a call to client because Time.now gets invoked multiple times during instantiation. Don't mock Time until after client initialized + client + expect(Time).to receive(:now).and_return(Time.new(2021, 5, 1, 5)) + allow(client).to receive(:eol_override).and_return(false) + expect(logger).to receive(:warn).with("This release of Chef Infra Client became end of life (EOL) on May 01, 2021. Please update to a supported release to receive new features, bug fixes, and security updates.") + client.warn_if_eol end - subject { @local_client } - it "warns when running an EOL release" do - - # = Net::HTTPClientException.new('404 "Not Found"', response) + it "does not warn when running an non-EOL release" do stub_const("Chef::VERSION", 15) - allow(Time).to receive(:now).and_return(Time.new(2021, 5, 1, 5)) - # allow(@local_client).to receive(:eol_override?).and_return(false) - # allow(@local_client).to receive(:logger).and_return(logger) - require "pry" - binding.pry - # @local_client.warn_if_eol - # expect(@local_client).to receive(:warn).with(/This release of.*became end of life \(EOL\) on May 1st 2021/) - end - - # it "warns when running an EOL release" do - # stub_const("Chef::VERSION", 15) - # allow(Time).to receive(:now).and_return(Time.new(2021, 5, 1, 5)) - # expect(logger).to receive(:warn).with(/This release of.*became end of life \(EOL\) on May 1st 2021/) - # client.warn_if_eol - # end - - # it "does not warn when running an non-EOL release" do - # stub_const("Chef::VERSION", 15) - # allow(Time).to receive(:now).and_return(Time.new(2021, 4, 31)) - # expect(logger).to_not receive(:warn).with(/became end of life/) - # client.warn_if_eol - # end + allow(Time).to receive(:now).and_return(Time.new(2021, 4, 31)) + expect(logger).to_not receive(:warn).with(/became end of life/) + client.warn_if_eol + end end describe "authentication protocol selection" do |