Skip to content

Commit

Permalink
Un-invert logic of upgrade_distro_manually
Browse files Browse the repository at this point in the history
During resolution of RE-670, it was discovered that PR #554, which
changed `should_run_distro_upgrade` to `upgrade_distro_manually`, failed
to account for the fact that this change of name inverts the sense of
the logic. Since none of the users of this method embed it in a
logically complicated way, and since there aren't too many users, modify
the method and its users to restore correct semantics.
  • Loading branch information
Sloane Bernstein committed Dec 11, 2024
1 parent 8832300 commit 1c7553f
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 32 deletions.
24 changes: 12 additions & 12 deletions elevate-cpanel
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ BEGIN { # Suppress load of all of these at earliest point.

sub check ($self) {

return 1 unless $self->upgrade_distro_manually; # skip when --upgrade-distro-manually is provided
return 1 if $self->upgrade_distro_manually; # skip when --upgrade-distro-manually is provided

my $ok = 0;
try {
Expand Down Expand Up @@ -2312,7 +2312,7 @@ EOS

sub verify_cmdline ($self) {
return unless _check_command_exists();
if ( $self->cpev->upgrade_distro_manually() ) {
if ( !$self->cpev->upgrade_distro_manually() ) {
my $arg = "elevate-" . _persistent_id;
INFO("Checking for \"$arg\" in booted kernel's command line...");

Expand Down Expand Up @@ -2536,7 +2536,7 @@ EOS
sub check ($self) {

return 1 unless Elevate::OS::needs_leapp();
return 1 unless $self->upgrade_distro_manually; # skip when --upgrade-distro-manually is provided
return 1 if $self->upgrade_distro_manually; # skip when --upgrade-distro-manually is provided

my $ok = 1;
$ok = 0 unless $self->_blocker_grub2_workaround;
Expand Down Expand Up @@ -3094,7 +3094,7 @@ EOS

sub check ($self) { # $self is a cpev object here

return 0 unless $self->upgrade_distro_manually;
return 0 if $self->upgrade_distro_manually;

if ( _is_container_envtype() ) {
return $self->has_blocker( <<~'EOS');
Expand Down Expand Up @@ -3416,7 +3416,7 @@ EOS

return unless Elevate::OS::needs_leapp();

return unless $self->upgrade_distro_manually; # skip when --upgrade-distro-manually is provided
return if $self->upgrade_distro_manually; # skip when --upgrade-distro-manually is provided

return if ( $self->components->num_blockers_found() > 0 ); # skip if any blockers have already been found

Expand Down Expand Up @@ -4252,7 +4252,7 @@ EOS
sub check ($self) {

return 1 unless Elevate::OS::needs_leapp();
return 1 unless $self->upgrade_distro_manually;
return 1 if $self->upgrade_distro_manually;

return $self->_blocker_bad_nics_naming;
}
Expand Down Expand Up @@ -6418,7 +6418,7 @@ EOS
use constant UFW => '/usr/sbin/ufw';

sub pre_distro_upgrade ($self) {
return unless $self->upgrade_distro_manually(); # skip when --upgrade-distro-manually is provided
return if $self->upgrade_distro_manually(); # skip when --upgrade-distro-manually is provided
return unless Elevate::OS::needs_do_release_upgrade();

if ( !-x UFW ) {
Expand Down Expand Up @@ -8724,7 +8724,7 @@ deb https://wp-toolkit.plesk.com/cPanel/Ubuntu-22.04-x86_64/latest/thirdparty/ .

sub upgrade ($self) {

return unless $self->cpev->upgrade_distro_manually();
return if $self->cpev->upgrade_distro_manually();

$self->cpev->run_once(
setup_answer_file => sub {
Expand Down Expand Up @@ -8853,7 +8853,7 @@ deb https://wp-toolkit.plesk.com/cPanel/Ubuntu-22.04-x86_64/latest/thirdparty/ .
sub wait_for_leapp_completion ($self) {
return 1 unless Elevate::OS::needs_leapp();

return 1 unless $self->cpev->upgrade_distro_manually();
return 1 if $self->cpev->upgrade_distro_manually();

my $upgrade_log = LEAPP_UPGRADE_LOG;

Expand Down Expand Up @@ -10938,7 +10938,7 @@ sub run_stage_1 ($self) {

Elevate::Motd->setup();

if ( !$self->upgrade_distro_manually() ) {
if ( $self->upgrade_distro_manually() ) {
Elevate::Stages::bump_stage();
return ACTION_CONTINUE;
}
Expand Down Expand Up @@ -11021,7 +11021,7 @@ sub run_stage_3 ($self) {
# and executing do-release-upgrade
$self->run_component_once( 'Ufw' => 'pre_distro_upgrade' );

if ( !$self->upgrade_distro_manually() ) {
if ( $self->upgrade_distro_manually() ) {
return $self->_request_to_upgrade_distro_manually();
}

Expand Down Expand Up @@ -11475,7 +11475,7 @@ sub upgrade_distro_manually ($self) {
# we need to check to see if the CLI option is passed here too in order
# to allow users to run this script with the '--check --upgrade-distro-manually', etc. options
my $manual_distro_upgrade = scalar grep { $self->getopt($_) || Elevate::StageFile::read_stage_file( tr/-/_/r, 0 ) } qw/upgrade-distro-manually no-leapp/;
return !$manual_distro_upgrade;
return $manual_distro_upgrade;
}

sub get_current_status ($self) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Elevate/Components/BootKernel.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use Try::Tiny;

sub check ($self) {

return 1 unless $self->upgrade_distro_manually; # skip when --upgrade-distro-manually is provided
return 1 if $self->upgrade_distro_manually; # skip when --upgrade-distro-manually is provided

my $ok = 0;
try {
Expand Down
2 changes: 1 addition & 1 deletion lib/Elevate/Components/Grub2ChecksWorkarounds.pm
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ sub post_distro_upgrade ($self) {
sub check ($self) {

return 1 unless Elevate::OS::needs_leapp();
return 1 unless $self->upgrade_distro_manually; # skip when --upgrade-distro-manually is provided
return 1 if $self->upgrade_distro_manually; # skip when --upgrade-distro-manually is provided

my $ok = 1;
$ok = 0 unless $self->_blocker_grub2_workaround;
Expand Down
2 changes: 1 addition & 1 deletion lib/Elevate/Components/Grub2ControlTest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ sub _remove_kernel_arg ( $self, $arg ) {

sub verify_cmdline ($self) {
return unless _check_command_exists();
if ( $self->cpev->upgrade_distro_manually() ) {
if ( !$self->cpev->upgrade_distro_manually() ) {
my $arg = "elevate-" . _persistent_id;
INFO("Checking for \"$arg\" in booted kernel's command line...");

Expand Down
2 changes: 1 addition & 1 deletion lib/Elevate/Components/IsContainer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use Log::Log4perl qw(:easy);

sub check ($self) { # $self is a cpev object here

return 0 unless $self->upgrade_distro_manually;
return 0 if $self->upgrade_distro_manually;

if ( _is_container_envtype() ) {
return $self->has_blocker( <<~'EOS');
Expand Down
2 changes: 1 addition & 1 deletion lib/Elevate/Components/Leapp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ sub check ($self) {

return unless Elevate::OS::needs_leapp();

return unless $self->upgrade_distro_manually; # skip when --upgrade-distro-manually is provided
return if $self->upgrade_distro_manually; # skip when --upgrade-distro-manually is provided

return if ( $self->components->num_blockers_found() > 0 ); # skip if any blockers have already been found

Expand Down
2 changes: 1 addition & 1 deletion lib/Elevate/Components/NICs.pm
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ sub check ($self) {

# This only matters for upgrades performed with the leapp utility
return 1 unless Elevate::OS::needs_leapp();
return 1 unless $self->upgrade_distro_manually;
return 1 if $self->upgrade_distro_manually;

return $self->_blocker_bad_nics_naming;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Elevate/Components/Ufw.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use parent qw{Elevate::Components::Base};
use constant UFW => '/usr/sbin/ufw';

sub pre_distro_upgrade ($self) {
return unless $self->upgrade_distro_manually(); # skip when --upgrade-distro-manually is provided
return if $self->upgrade_distro_manually(); # skip when --upgrade-distro-manually is provided
return unless Elevate::OS::needs_do_release_upgrade();

if ( !-x UFW ) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Elevate/Leapp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ sub preupgrade ($self) {

sub upgrade ($self) {

return unless $self->cpev->upgrade_distro_manually();
return if $self->cpev->upgrade_distro_manually();

$self->cpev->run_once(
setup_answer_file => sub {
Expand Down Expand Up @@ -240,7 +240,7 @@ sub wait_for_leapp_completion ($self) {
return 1 unless Elevate::OS::needs_leapp();

# No use waiting for leapp to complete if we did not run leapp
return 1 unless $self->cpev->upgrade_distro_manually();
return 1 if $self->cpev->upgrade_distro_manually();

my $upgrade_log = LEAPP_UPGRADE_LOG;

Expand Down
6 changes: 3 additions & 3 deletions script/elevate-cpanel.PL
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ sub run_stage_1 ($self) {

Elevate::Motd->setup();

if ( !$self->upgrade_distro_manually() ) {
if ( $self->upgrade_distro_manually() ) {
Elevate::Stages::bump_stage();
return ACTION_CONTINUE;
}
Expand Down Expand Up @@ -1027,7 +1027,7 @@ sub run_stage_3 ($self) {
# and executing do-release-upgrade
$self->run_component_once( 'Ufw' => 'pre_distro_upgrade' );

if ( !$self->upgrade_distro_manually() ) {
if ( $self->upgrade_distro_manually() ) {
return $self->_request_to_upgrade_distro_manually();
}

Expand Down Expand Up @@ -1481,7 +1481,7 @@ sub upgrade_distro_manually ($self) {
# we need to check to see if the CLI option is passed here too in order
# to allow users to run this script with the '--check --upgrade-distro-manually', etc. options
my $manual_distro_upgrade = scalar grep { $self->getopt($_) || Elevate::StageFile::read_stage_file( tr/-/_/r, 0 ) } qw/upgrade-distro-manually no-leapp/;
return !$manual_distro_upgrade;
return $manual_distro_upgrade;
}

sub get_current_status ($self) {
Expand Down
4 changes: 2 additions & 2 deletions t/components-BootKernel.t
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ my $comp = cpev->new->get_component('BootKernel');
reboot_status => sub { die "should not be called here\n"; },
);

$mock_cpev->redefine( upgrade_distro_manually => 0 );
$mock_cpev->redefine( upgrade_distro_manually => 1 );
is( $comp->check(), 1, 'Should skip when upgrade-distro-manually is passed' );
}

{
note 'Test BootKernel behavior';

$mock_cpev->redefine( upgrade_distro_manually => 1 );
$mock_cpev->redefine( upgrade_distro_manually => 0 );

my $rv;
my $bv;
Expand Down
4 changes: 2 additions & 2 deletions t/components-Grub2ControlTest.t
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ $mock_stage_file->redefine( _save_stage_file => sub { $stage_data = $_[0]; retur
my $cmdline;
$mock_slurp->redefine( read_binary => sub { return $cmdline } );

$mock_cpev->redefine( upgrade_distro_manually => 1 );
$mock_cpev->redefine( upgrade_distro_manually => 0 );
$mock_cpev->redefine( do_cleanup => sub { $stage_data = undef; return; } );

my $mock_comp = Test::MockModule->new('Elevate::Components::Grub2ControlTest');
Expand Down Expand Up @@ -136,7 +136,7 @@ $mock_stage_file->redefine( _save_stage_file => sub { $stage_data = $_[0]; retur
my $cmdline;
$mock_slurp->redefine( read_binary => sub { return $cmdline } );

$mock_cpev->redefine( upgrade_distro_manually => 1 );
$mock_cpev->redefine( upgrade_distro_manually => 0 );
$mock_cpev->redefine( do_cleanup => sub { $stage_data = undef; return; } );

my $mock_comp = Test::MockModule->new('Elevate::Components::Grub2ControlTest');
Expand Down
4 changes: 2 additions & 2 deletions t/components-Ufw.t
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ $mock_stagefile->redefine(
set_os_to('ubuntu');

$mock_ufw->redefine(
upgrade_distro_manually => 0,
upgrade_distro_manually => 1,
);

is( $ufw->pre_distro_upgrade(), undef, 'Returns early if the user is updating the OS' );
is( $ssystem_and_die_params, [], 'No system commands were called' );
no_messages_seen();

$mock_ufw->redefine(
upgrade_distro_manually => 1,
upgrade_distro_manually => 0,
);

set_os_to('cent');
Expand Down
4 changes: 2 additions & 2 deletions t/leapp_upgrade.t
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,13 @@ note 'LEAPP upgrade log failure checks';
$mock_leapp_upgrade_log->unlink;

$mock_elevate->redefine(
upgrade_distro_manually => 0,
upgrade_distro_manually => 1,
);

is( cpev->leapp->wait_for_leapp_completion, 1, 'wait_for_leapp_completion returns early when it should NOT run leapp' );

$mock_elevate->redefine(
upgrade_distro_manually => 1,
upgrade_distro_manually => 0,
);

is( cpev->leapp->wait_for_leapp_completion, 0, "wait_for_leapp_completion fails when the upgrade log is missing." );
Expand Down

0 comments on commit 1c7553f

Please sign in to comment.