Skip to content

Commit

Permalink
Refs #36693 - add maintenance warn date
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz committed Aug 30, 2023
1 parent d88b59c commit c31d1fb
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
4 changes: 4 additions & 0 deletions app/models/katello/concerns/host_managed_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,10 @@ def full_support_end_date
::Katello::RhelLifecycleStatus.full_support_end_date(eos_schedule_index: rhel_eos_schedule_index)
end

def approaching_end_of_maintenance_date
::Katello::RhelLifecycleStatus.maintenance_warn_date(eos_schedule_index: rhel_eos_schedule_index)
end

def maintenance_support_end_date
::Katello::RhelLifecycleStatus.maintenance_support_end_date(eos_schedule_index: rhel_eos_schedule_index)
end
Expand Down
47 changes: 39 additions & 8 deletions app/models/katello/rhel_lifecycle_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ class RhelLifecycleStatus < HostStatus::Status
UNKNOWN = 0
FULL_SUPPORT = 1
MAINTENANCE_SUPPORT = 2
EXTENDED_SUPPORT = 3
APPROACHING_END_OF_SUPPORT = 4
SUPPORT_ENDED = 5
APPROACHING_END_OF_MAINTENANCE = 3
EXTENDED_SUPPORT = 4
APPROACHING_END_OF_SUPPORT = 5
SUPPORT_ENDED = 6

def self.end_of_day(date)
DateTime.parse(date.to_s).end_of_day.utc
Expand Down Expand Up @@ -51,12 +52,19 @@ def self.end_of_day(date)
}
}.freeze

def self.between_dates?(date1, date2)
return nil unless date1.present? && date2.present?
today = Date.today.beginning_of_day.utc
date1.present? && today >= date1.beginning_of_day.utc && today <= date2.end_of_day.utc
end

EOS_WARNING_THRESHOLD = 1.year

def self.status_map
map = {
full_support: FULL_SUPPORT,
maintenance_support: MAINTENANCE_SUPPORT,
approaching_end_of_maintenance: APPROACHING_END_OF_MAINTENANCE,
extended_support: EXTENDED_SUPPORT,
approaching_end_of_support: APPROACHING_END_OF_SUPPORT,
support_ended: SUPPORT_ENDED
Expand All @@ -71,11 +79,17 @@ def self.to_status(operatingsystem: nil)
release = operatingsystem.rhel_eos_schedule_index
approach_date = warn_date(eos_schedule_index: release)
end_of_support_date = eos_date(eos_schedule_index: release)
maintenance_approach_date = maintenance_warn_date(eos_schedule_index: release)
maintenance_end_of_support_date = maintenance_support_end_date(eos_schedule_index: release)
return UNKNOWN unless release
return UNKNOWN if RHEL_EOS_SCHEDULE[release].nil?

return FULL_SUPPORT if Date.today <= RHEL_EOS_SCHEDULE[release]['full_support']
return MAINTENANCE_SUPPORT if Date.today <= RHEL_EOS_SCHEDULE[release]['maintenance_support']
if approach_date.present? && Date.today >= approach_date && Date.today <= end_of_support_date
if between_dates?(maintenance_approach_date, maintenance_end_of_support_date)
return APPROACHING_END_OF_MAINTENANCE
end
return MAINTENANCE_SUPPORT if Date.today <= maintenance_end_of_support_date
if between_dates?(approach_date, end_of_support_date)
return APPROACHING_END_OF_SUPPORT
end
return EXTENDED_SUPPORT if Date.today <= end_of_support_date
Expand Down Expand Up @@ -115,15 +129,28 @@ def self.warn_date(eos_schedule_index: nil)
return nil unless eos_schedule_index
end_of_support_date = eos_date(eos_schedule_index: eos_schedule_index)
return nil unless end_of_support_date
eos_date(eos_schedule_index: eos_schedule_index) - EOS_WARNING_THRESHOLD
end_of_support_date - EOS_WARNING_THRESHOLD
end

def self.to_label(status, eos_date: nil)
def self.maintenance_warn_date(eos_schedule_index: nil)
return nil unless eos_schedule_index
end_of_maintenance_support_date = maintenance_support_end_date(eos_schedule_index: eos_schedule_index)
return nil unless end_of_maintenance_support_date
end_of_maintenance_support_date - EOS_WARNING_THRESHOLD
end

def self.to_label(status, eos_date: nil, maintenance_support_end_date: nil)
case status
when FULL_SUPPORT
N_('Full support')
when MAINTENANCE_SUPPORT
N_('Maintenance support')
when APPROACHING_END_OF_MAINTENANCE
if maintenance_support_end_date.present?
N_('Approaching end of maintenance support (%s)') % maintenance_support_end_date.strftime('%Y-%m-%d')
else
N_('Approaching end of maintenance support')
end
when EXTENDED_SUPPORT
N_('Extended support')
when APPROACHING_END_OF_SUPPORT
Expand All @@ -140,13 +167,17 @@ def self.to_label(status, eos_date: nil)
end

def to_label(_options = {})
self.class.to_label(status, eos_date: eos_date)
self.class.to_label(status, eos_date: eos_date, maintenance_support_end_date: maintenance_support_end_date)
end

def eos_date
self.class.eos_date(eos_schedule_index: rhel_eos_schedule_index)
end

def maintenance_support_end_date
self.class.maintenance_support_end_date(eos_schedule_index: rhel_eos_schedule_index)
end

def warn_date
self.class.warn_date(eos_schedule_index: rhel_eos_schedule_index)
end
Expand Down
6 changes: 6 additions & 0 deletions test/models/concerns/host_managed_extensions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,12 @@ def test_maintenance_support_end_date
assert_equal expected_date, host.maintenance_support_end_date
end

def test_approaching_end_of_maintenance_date
host.expects(:rhel_eos_schedule_index).returns('RHEL9')
expected_date = ::Katello::RhelLifecycleStatus.maintenance_warn_date(eos_schedule_index: 'RHEL9')
assert_equal expected_date, host.approaching_end_of_maintenance_date
end

def test_extended_support_end_date
host.expects(:rhel_eos_schedule_index).returns('RHEL9')
expected_date = ::Katello::RhelLifecycleStatus.extended_support_end_date(eos_schedule_index: 'RHEL9')
Expand Down
3 changes: 2 additions & 1 deletion test/models/rhel_lifecycle_status_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def test_to_status_full_support
host.operatingsystem.update(:name => "RedHat", :major => "9", :minor => "0")
host.operatingsystem.expects(:rhel_eos_schedule_index).returns(release)
fake_full_support_end_date(Date.today + 2.years)
fake_maintenance_support_end_date(Date.today + 5.years)
fake_extended_support_end_date(Date.today + 10.years)
assert_equal Katello::RhelLifecycleStatus::FULL_SUPPORT, status.to_status
end
Expand All @@ -81,7 +82,7 @@ def test_to_status_maintenance_support
host.operatingsystem.update(:name => "RedHat", :major => "9", :minor => "0")
host.operatingsystem.expects(:rhel_eos_schedule_index).returns(release)
fake_full_support_end_date(Date.today - 1.year)
fake_maintenance_support_end_date(Date.today + 1.year)
fake_maintenance_support_end_date(Date.today + 2.years)
fake_extended_support_end_date(Date.today + 10.years)
assert_equal Katello::RhelLifecycleStatus::MAINTENANCE_SUPPORT, status.to_status
end
Expand Down
1 change: 0 additions & 1 deletion test/services/katello/registration_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ def test_registration_existing_host
def test_unregister_host
@host = FactoryBot.create(:host, :with_content, :with_subscription, :content_view => @content_view,
:lifecycle_environment => @library, :organization => @content_view.organization)
@host.content_facet.expects(:cves_changed?).returns(false)
::Host::Managed.any_instance.stubs(:refresh_statuses)
::Katello::Resources::Candlepin::Consumer.expects(:destroy)
::Katello::EventQueue.expects(:push_event).never
Expand Down

0 comments on commit c31d1fb

Please sign in to comment.