Skip to content

Commit

Permalink
Merge pull request #505 from cpanel/RE-217
Browse files Browse the repository at this point in the history
Rework Elevate::Leapp to reuse code
  • Loading branch information
toddr authored Sep 5, 2024
2 parents 8dcfd78 + 20a1368 commit e41ede3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 60 deletions.
43 changes: 13 additions & 30 deletions elevate-cpanel
Original file line number Diff line number Diff line change
Expand Up @@ -7157,40 +7157,23 @@ Please investigate, resolve then re-run the following command to continue the up
EOS

my $leapp_json_report = LEAPP_REPORT_JSON;
if ( -e $leapp_json_report ) {
my $report = eval { Cpanel::JSON::LoadFile($leapp_json_report) } // {};

my $entries = $report->{entries};
if ( ref $entries eq 'ARRAY' ) {
foreach my $e (@$entries) {
next unless ref $e && $e->{title} =~ qr{Missing.*answer}i;

$msg .= $e->{summary} if $e->{summary};

if ( ref $e->{detail} ) {
my $d = $e->{detail};

if ( ref $d->{remediations} ) {
foreach my $remed ( $d->{remediations}->@* ) {
next unless $remed->{type} && $remed->{type} eq 'command';
next unless ref $remed->{context};
my @hint = $remed->{context}->@*;
next unless scalar @hint;
$hint[0] = q[/usr/bin/leapp] if $hint[0] && $hint[0] eq 'leapp';
my $cmd = join( ' ', @hint );

$msg .= "\n\n";
$msg .= <<"EOS";
my $entries = $self->search_report_file_for_inhibitors;
if ( ref $entries eq 'ARRAY' ) {
foreach my $e (@$entries) {
$msg .= "\n$e->{summary}" if $e->{summary};

if ( $e->{command} ) {

my $cmd = $e->{command};
$cmd =~ s[^leapp][/usr/bin/leapp];

$msg .= "\n\n";
$msg .= <<"EOS";
Consider running this command:
$cmd
EOS
}
}

}
EOS
}
}
}
Expand Down
43 changes: 13 additions & 30 deletions lib/Elevate/Leapp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -308,40 +308,23 @@ Please investigate, resolve then re-run the following command to continue the up
EOS

my $leapp_json_report = LEAPP_REPORT_JSON;
if ( -e $leapp_json_report ) {
my $report = eval { Cpanel::JSON::LoadFile($leapp_json_report) } // {};

my $entries = $report->{entries};
if ( ref $entries eq 'ARRAY' ) {
foreach my $e (@$entries) {
next unless ref $e && $e->{title} =~ qr{Missing.*answer}i;

$msg .= $e->{summary} if $e->{summary};

if ( ref $e->{detail} ) {
my $d = $e->{detail};

if ( ref $d->{remediations} ) {
foreach my $remed ( $d->{remediations}->@* ) {
next unless $remed->{type} && $remed->{type} eq 'command';
next unless ref $remed->{context};
my @hint = $remed->{context}->@*;
next unless scalar @hint;
$hint[0] = q[/usr/bin/leapp] if $hint[0] && $hint[0] eq 'leapp';
my $cmd = join( ' ', @hint );

$msg .= "\n\n";
$msg .= <<"EOS";
my $entries = $self->search_report_file_for_inhibitors;
if ( ref $entries eq 'ARRAY' ) {
foreach my $e (@$entries) {
$msg .= "\n$e->{summary}" if $e->{summary};

if ( $e->{command} ) {

my $cmd = $e->{command};
$cmd =~ s[^leapp][/usr/bin/leapp];

$msg .= "\n\n";
$msg .= <<"EOS";
Consider running this command:
$cmd
EOS
}
}

}
EOS
}
}
}
Expand Down

0 comments on commit e41ede3

Please sign in to comment.