From 0d1268cd573121c44c453de162201d37bad7cbfb Mon Sep 17 00:00:00 2001 From: Lukas Ruzicka Date: Fri, 29 Nov 2024 15:01:16 +0100 Subject: [PATCH] Save progress, might be working. --- tests/collect_web_data.pm | 4 ++-- tests/os_release.pm | 29 ++++++++++++++--------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/tests/collect_web_data.pm b/tests/collect_web_data.pm index a8d7dc34..880524fb 100644 --- a/tests/collect_web_data.pm +++ b/tests/collect_web_data.pm @@ -20,11 +20,11 @@ sub run { # We will fetch the version data from various locations. # Download data from Bodhi for - assert_script_run("curl -o bodhi-$current.json https://bodhi.fedoraproject.org/releases/F$current"); assert_script_run("curl -o bodhi-$target.json https://bodhi.fedoraproject.org/releases/F$target"); # Download data from Fedora Schedule - assert_script_run("curl -o schedule-$current.json https://fedorapeople.org/groups/schedule/f-$current/f-$current-key.json"); assert_script_run("curl -o schedule-$target.json https://fedorapeople.org/groups/schedule/f-$target/f-$target-key.json"); + # Install jq to modify the downloaded jsons and make sure, they will be correctly formed. + assert_script_run("dnf install -y jq", timeout => 60); } sub test_flags { diff --git a/tests/os_release.pm b/tests/os_release.pm index 10042201..a3db343f 100644 --- a/tests/os_release.pm +++ b/tests/os_release.pm @@ -1,6 +1,6 @@ use base "installedtest"; use strict; -use JSON::PP; +use JSON; use Time::Piece; use testapi; use utils; @@ -18,10 +18,10 @@ sub json_to_hash { # This will convert a Json string into a valid # Perl hash for further processing. my $json = shift; - my $hash; - eval { - my $hash = JSON::PP->new->utf8->decode($json); - }; + # The file is transferred via openQA methods and it basically + # is a string with \n symbols in it, which does not + # make it a valid json file. First, we need to remove these. + my $hash = decode_json($json); die("Failed to parse JSON: $@") if ($@); return $hash; } @@ -50,7 +50,7 @@ sub get_bodhi_eol { # date should be returned. my $ver = shift; # The content of the downloaded file is a JSON string. - my $json = script_output("cat ~/version_data/bodhi-$ver.json"); + my $json = script_output("cat ~/version_data/bodhi-$ver.json | jq -c"); my $bodhi = json_to_hash($json); my $eol = $bodhi->{"eol"}; $eol = date_to_epoch($eol); @@ -63,22 +63,21 @@ sub get_schedule_eol { # the EOL date from that file. As argument, it takes the version # number from which the EOL date should be returned. my $ver = shift; - my $json = script_output("cat ~/version_data/schedule-$ver.json"); + my $json = script_output("cat ~/version_data/schedule-$ver.json | jq -c"); my $schedule = json_to_hash($json); my $eol; - # The format of the json is quite complicated, so we need to do - # quite a lot of magic to arrive at the correct date, so let's - # hope the format stays the same in the future. - # FIXME parsing the tasks - my $tasks = $json->{tasks}[0]{tasks}[0]{tasks}; + # The format of the json is quite complicated, so a lot of magic is necessary to come onto the EOL date inside, especially + # when some parts are placed in a list and Perl complains about incorrect HASH reference. + # However, I realized that it also has a field "end" just at the top structure which has the same value. + my $tasks = $schedule->{'tasks'}[0]{'tasks'}[0]{'tasks'}; my $eol; - foreach my $task (@$tasks) { - if ($task->{name} && $task->{name} =~ /End of Life/) { - $eol = $task->{end}; + if ($task->{'name'} and $task->{'name'} =~ /End of Life/) { + $eol = $task->{'end'}; last; } } + # The EOL date is provided as an epoch, so just return it. return $eol; }