diff --git a/tests/os_release.pm b/tests/os_release.pm index bd2d0f5a..6922b9bb 100644 --- a/tests/os_release.pm +++ b/tests/os_release.pm @@ -31,6 +31,14 @@ sub date_to_epoch { return $epoch; } +sub epoch_to_date { + # This will convert the epoch integer into YYYY-MM-DD. + my $epoch = shift; + my $time = localtime($epoch); + my $date = $time->strftime('%Y-%m-%d'); + return $date; +} + sub get_bodhi_eol { # This reads the Bodhi info file (downloaded in collect_web_data.pm), # parses it and returns the EOL date from that file. @@ -68,13 +76,13 @@ sub get_schedule_eol { } sub get_current_date { - # This returns the current date in as the epoch + # This returns the current date in as the epoch and YYYY-MM-DD. # which we need to see if the EOL is correctly set in the future. my $time = localtime; - my %dates; - $dates{'date'} = $time->strftime('%Y-%m-%d'); - $dates{'epoch'} = date_to_epoch($date); - return \%dates; + my $dates = {}; + $dates->{date} = $time->strftime('%Y-%m-%d'); + $dates->{epoch} = date_to_epoch($dates{date}); + return $dates; } sub check_eol_in_year { @@ -85,7 +93,7 @@ sub check_eol_in_year { my $tested = shift; $tested = date_to_epoch($tested); my $dates = get_current_date(); - my $current = $dates->{'epoch'} + my $current = $dates->{epoch}; # The EOL in the os-release.pm must be at least a year # in the future, so we calculate the epoch difference # between $tested and $current. @@ -100,6 +108,49 @@ sub check_eol_in_year { return $bool; } +sub check_eols_match { + # This will take the EOL dates from the /etc/os-release + # file and it will compare the value with those from + # Bodhi and Fedora Schedule and will succeed when they + # match each other. + my $tested = shift; + my $version = get_release_number(); + my $bodhi = get_bodhi_eol($version); + $bodhi = epoch_to_date($bodhi); + my $schedule = get_schedule_eol($version); + $schedule = epoch_to_date($schedule); + # The resulting code will be 0 if the local SUPPORT_END cannot be validated + # against Bodhi or Schedule and os-release is the only source. + my $rcode = 0; + my $overall = 1; + # Change the exit code based on the resulting condition. We are only + # interested in the first condition really, but we want to know what + # the situation is exactly, so we will test all options. + if ($bodhi eq $schedule and $bodhi eq $tested) { + $rcode = 1; + } + elsif ($bodhi eq $schedule) { + $rcode = 2; + } + elsif ($tested eq $bodhi) { + $rcode = 3; + } + elsif ($tested eq $schedule) { + $rcode = 4; + } + $overall = 0 if ($rcode != 1); + my $return_codes = { + 0 => "No EOL dates do match:\n\tos-release: $tested\n\tBodhi: $bodhi\n\tSchedule: $schedule", + 2 => "The os-release doesn't match Bodhi or Schedule, but they match each other:\n\tos-release: $tested\n\tBodhi: $bodhi\n\tSchedule: $schedule" + 3 => "The os-release file matches Bodhi but Schedule differs:\n\tos-release: $tested\n\tBodhi: $bodhi\n\tSchedule: $schedule", + 4 => "The os-release file matches Schedule but Bodhi differs:\n\tos-release: $tested\n\tBodhi: $bodhi\n\tSchedule: $schedule", + 1 => "All EOL dates match:\n\tos-release: $tested\n\tBodhi: $bodhi\n\tSchedule: $schedule" + }; + + my $result = [$overall, $return_codes->{$rcode}]; + return $result; +} + sub run { # First, let us define some variables needed to run the program. my $self = shift; @@ -274,7 +325,11 @@ sub run { my $os_release_eol = $content{'SUPPORT_END'}; my $result = check_eol_in_year($os_release_eol); my $current = get_current_date(); - rec_log("The SUPPORT_END date is $current->{epoch} which is at least a year ahead in time", $result == 1, $failref); + rec_log("The SUPPORT_END date is $os_release_eol which is at least a year ahead in time (now is $current->{date})", $result == 1, $failref); + + # Test for EOL dates match each other. + $result = check_eols_match($os_release_eol); + rec_log($result->[1], $result->[0] == 1, $failref); # Check for fails, count them, collect their messages and die if something was found. my $failcount = scalar @fails;