Skip to content

Commit

Permalink
Refs #36693 - address comments; remove some unused methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylenz committed Aug 31, 2023
1 parent f056db1 commit 55f149b
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 91 deletions.
14 changes: 3 additions & 11 deletions app/models/katello/concerns/host_managed_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -492,23 +492,15 @@ def rhel_lifecycle_status_label
end

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)
::Katello::RhelLifecycleStatus.full_support_end_dates[rhel_eos_schedule_index]
end

def maintenance_support_end_date
::Katello::RhelLifecycleStatus.maintenance_support_end_date(eos_schedule_index: rhel_eos_schedule_index)
::Katello::RhelLifecycleStatus.maintenance_support_end_dates[rhel_eos_schedule_index]
end

def extended_support_end_date
::Katello::RhelLifecycleStatus.extended_support_end_date(eos_schedule_index: rhel_eos_schedule_index)
end

def approaching_end_of_support_date
::Katello::RhelLifecycleStatus.warn_date(eos_schedule_index: rhel_eos_schedule_index)
::Katello::RhelLifecycleStatus.extended_support_end_dates[rhel_eos_schedule_index]
end

def end_of_support_date
Expand Down
93 changes: 44 additions & 49 deletions app/models/katello/rhel_lifecycle_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,33 +74,37 @@ def self.status_map
map
end

def self.approaching_end_of_category(eos_schedule_index:)
RHEL_EOS_SCHEDULE[eos_schedule_index].select { |k, v| (Time.now.utc .. Time.now.utc + EOS_WARNING_THRESHOLD).cover?(v) }
end

def self.to_status(rhel_eos_schedule_index: nil)
release = rhel_eos_schedule_index
return UNKNOWN unless release.present? && RHEL_EOS_SCHEDULE.key?(release)

# Full support
full_support_end_date = full_support_end_date(eos_schedule_index: release)
return FULL_SUPPORT if Date.today <= full_support_end_date

# Approach warnings
maintenance_approach_date = maintenance_warn_date(eos_schedule_index: release)
maintenance_end_of_support_date = maintenance_support_end_date(eos_schedule_index: release)
if between_dates?(maintenance_approach_date, maintenance_end_of_support_date)
return APPROACHING_END_OF_MAINTENANCE
approach = approaching_end_of_category(eos_schedule_index: release)
if approach.present?
case approach.keys.first
when last_support_category(eos_schedule_index: release)
return APPROACHING_END_OF_SUPPORT
when 'maintenance_support'
return APPROACHING_END_OF_MAINTENANCE
end
end
approach_date = warn_date(eos_schedule_index: release)
end_of_support_date = eos_date(eos_schedule_index: release)
if between_dates?(approach_date, end_of_support_date)
return APPROACHING_END_OF_SUPPORT

full_support_end_date = RHEL_EOS_SCHEDULE[release]['full_support']
maintenance_support_end_date = RHEL_EOS_SCHEDULE[release]['maintenance_support']
extended_support_end_date = RHEL_EOS_SCHEDULE[release]['extended_support']

case
when Date.today <= full_support_end_date
return FULL_SUPPORT
when Date.today <= maintenance_support_end_date
return MAINTENANCE_SUPPORT
when extended_support_end_date.present? && Date.today <= extended_support_end_date
return EXTENDED_SUPPORT
else
return SUPPORT_ENDED
end

# Maintenance support
return MAINTENANCE_SUPPORT if Date.today <= maintenance_end_of_support_date

# Extended support
return EXTENDED_SUPPORT if Date.today <= end_of_support_date

return SUPPORT_ENDED
end

def self.status_name
Expand All @@ -111,39 +115,34 @@ def self.humanized_name
'rhel_lifecycle'
end

def self.full_support_end_date(eos_schedule_index: nil)
return nil unless eos_schedule_index
RHEL_EOS_SCHEDULE[eos_schedule_index]&.[]('full_support')
# {"RHEL9"=>2035-05-31 23:59:59.999999999 UTC,
# "RHEL8"=>2032-05-31 23:59:59.999999999 UTC, ... }
def self.schedule_slice(support_category)
{}.merge(*RHEL_EOS_SCHEDULE.keys.map do |release|
{ release => RHEL_EOS_SCHEDULE[release]&.[](support_category) }
end)
end

def self.maintenance_support_end_date(eos_schedule_index: nil)
return nil unless eos_schedule_index
RHEL_EOS_SCHEDULE[eos_schedule_index]&.[]('maintenance_support')
def self.full_support_end_dates
schedule_slice('full_support')
end

def self.extended_support_end_date(eos_schedule_index: nil)
return nil unless eos_schedule_index
RHEL_EOS_SCHEDULE[eos_schedule_index]&.[]('extended_support')
def self.maintenance_support_end_dates
schedule_slice('maintenance_support')
end

def self.eos_date(eos_schedule_index: nil)
return nil unless eos_schedule_index
RHEL_EOS_SCHEDULE[eos_schedule_index]&.[]('extended_support') ||
RHEL_EOS_SCHEDULE[eos_schedule_index]&.[]('maintenance_support')
def self.extended_support_end_dates
schedule_slice('extended_support')
end

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
end_of_support_date - EOS_WARNING_THRESHOLD
def self.last_support_category(eos_schedule_index:)
RHEL_EOS_SCHEDULE[eos_schedule_index].keys.last
end

def self.maintenance_warn_date(eos_schedule_index: nil)
def self.eos_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
RHEL_EOS_SCHEDULE[eos_schedule_index]&.[]('extended_support') ||
RHEL_EOS_SCHEDULE[eos_schedule_index]&.[]('maintenance_support')
end

def self.to_label(status, eos_date: nil, maintenance_support_end_date: nil)
Expand Down Expand Up @@ -182,11 +181,7 @@ def eos_date
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)
self.class.maintenance_support_end_dates[rhel_eos_schedule_index]
end

def rhel_eos_schedule_index
Expand Down
26 changes: 7 additions & 19 deletions test/models/concerns/host_managed_extensions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -423,37 +423,25 @@ def test_search_known_traces
class HostRhelEosSchedulesTest < ActiveSupport::TestCase
let(:host) { FactoryBot.create(:host, :with_subscription) }

def test_full_support_end_date
def test_full_support_end_dates
host.expects(:rhel_eos_schedule_index).returns('RHEL9')
expected_date = ::Katello::RhelLifecycleStatus.full_support_end_date(eos_schedule_index: 'RHEL9')
expected_date = ::Katello::RhelLifecycleStatus.full_support_end_dates['RHEL9']
assert_equal expected_date, host.full_support_end_date
end

def test_maintenance_support_end_date
def test_maintenance_support_end_dates
host.expects(:rhel_eos_schedule_index).returns('RHEL9')
expected_date = ::Katello::RhelLifecycleStatus.maintenance_support_end_date(eos_schedule_index: 'RHEL9')
expected_date = ::Katello::RhelLifecycleStatus.maintenance_support_end_dates['RHEL9']
assert_equal expected_date, host.maintenance_support_end_date
end

def test_approaching_end_of_maintenance_date
def test_extended_support_end_dates
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')
expected_date = ::Katello::RhelLifecycleStatus.extended_support_end_dates['RHEL9']
assert_equal expected_date, host.extended_support_end_date
end

def test_approaching_end_of_support_date
host.expects(:rhel_eos_schedule_index).returns('RHEL9')
expected_date = ::Katello::RhelLifecycleStatus.warn_date(eos_schedule_index: 'RHEL9')
assert_equal expected_date, host.approaching_end_of_support_date
end

def test_end_of_support_date
def test_end_of_support_dates
host.expects(:rhel_eos_schedule_index).returns('RHEL9')
expected_date = ::Katello::RhelLifecycleStatus.eos_date(eos_schedule_index: 'RHEL9')
assert_equal expected_date, host.end_of_support_date
Expand Down
31 changes: 19 additions & 12 deletions test/models/rhel_lifecycle_status_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ def test_to_status_full_support
os.hosts << host
host.operatingsystem.update(:name => "RedHat", :major => "9", :minor => "0")
host.operatingsystem.expects(:rhel_eos_schedule_index).returns(release)
Katello::RhelLifecycleStatus.expects(:approaching_end_of_category).returns({})
fake_full_support_end_date(Date.today + 2.years)
fake_maintenance_support_end_date(Date.today + 10.years)
fake_extended_support_end_date(Date.today + 20.years)
assert_equal Katello::RhelLifecycleStatus::FULL_SUPPORT, status.to_status
end

Expand All @@ -89,9 +92,7 @@ def test_to_status_approaching_end_of_support
os.hosts << host
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 - 5.years)
fake_maintenance_support_end_date(Date.today - 3.years)
fake_extended_support_end_date(Date.today + 10.days)
Katello::RhelLifecycleStatus.expects(:approaching_end_of_category).returns({ 'extended_support' => Date.today + 2.days })
assert_equal Katello::RhelLifecycleStatus::APPROACHING_END_OF_SUPPORT, status.to_status
end

Expand All @@ -115,19 +116,25 @@ def test_to_status_support_ended
assert_equal Katello::RhelLifecycleStatus::SUPPORT_ENDED, status.to_status
end

def test_full_support_end_date
fake_full_support_end_date(Date.today + 2.years)
assert_equal Date.today + 2.years, Katello::RhelLifecycleStatus.full_support_end_date(eos_schedule_index: release)
def test_full_support_end_dates
assert_equal_arrays Katello::RhelLifecycleStatus::RHEL_EOS_SCHEDULE.keys, Katello::RhelLifecycleStatus.full_support_end_dates.keys
Katello::RhelLifecycleStatus::RHEL_EOS_SCHEDULE.each do |release, schedule|
assert_equal schedule['full_support'], Katello::RhelLifecycleStatus.full_support_end_dates[release]
end
end

def test_maintenance_support_end_date
fake_maintenance_support_end_date(Date.today + 2.years)
assert_equal Date.today + 2.years, Katello::RhelLifecycleStatus.maintenance_support_end_date(eos_schedule_index: release)
def test_maintenance_support_end_dates
assert_equal_arrays Katello::RhelLifecycleStatus::RHEL_EOS_SCHEDULE.keys, Katello::RhelLifecycleStatus.maintenance_support_end_dates.keys
Katello::RhelLifecycleStatus::RHEL_EOS_SCHEDULE.each do |release, schedule|
assert_equal schedule['maintenance_support'], Katello::RhelLifecycleStatus.maintenance_support_end_dates[release]
end
end

def test_extended_support_end_date
fake_extended_support_end_date(Date.today + 2.years)
assert_equal Date.today + 2.years, Katello::RhelLifecycleStatus.extended_support_end_date(eos_schedule_index: release)
def test_extended_support_end_dates
assert_equal_arrays Katello::RhelLifecycleStatus::RHEL_EOS_SCHEDULE.keys, Katello::RhelLifecycleStatus.extended_support_end_dates.keys
Katello::RhelLifecycleStatus::RHEL_EOS_SCHEDULE.each do |release, schedule|
assert_equal schedule['extended_support'], Katello::RhelLifecycleStatus.extended_support_end_dates[release]
end
end

def test_eos_date
Expand Down

0 comments on commit 55f149b

Please sign in to comment.