Skip to content

Commit

Permalink
Merge pull request #403 from toddr/beta
Browse files Browse the repository at this point in the history
Add command line arg to use the leapp beta repos
  • Loading branch information
toddr authored Mar 29, 2024
2 parents 88e35d0 + 7a91334 commit 7574ece
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 10 deletions.
31 changes: 26 additions & 5 deletions elevate-cpanel
Original file line number Diff line number Diff line change
Expand Up @@ -4584,6 +4584,8 @@ EOS
'disable_mysql_yum_repos', # This is a list of mysql repo files to disable
'ea_alias', # This is the value for the --target-os flag used when backing up an EA4 profile
'elevate_rpm_url', # This is the URL used to install the leapp RPM/repo
'leapp_repo_prod', # This is the repo name for the production repo.
'leapp_repo_beta', # This is the repo name for the beta repo. The OS might not provide a beta repo in which case it'll be blank.
'is_experimental', # This is used to determine if the OS is experimental or not
'is_supported', # This is used to determine if the OS is supported or not
'leapp_can_handle_epel', # This is used to determine if we can skip removing the EPEL repo pre_leapp or not
Expand Down Expand Up @@ -4667,6 +4669,7 @@ EOS
use constant default_upgrade_to => 'AlmaLinux';
use constant ea_alias => 'CentOS_8';
use constant elevate_rpm_url => 'https://repo.almalinux.org/elevate/elevate-release-latest-el7.noarch.rpm';
use constant leapp_repo_prod => 'elevate';
use constant name => 'CentOS7';
use constant pretty_name => 'CentOS 7';

Expand Down Expand Up @@ -4700,6 +4703,8 @@ EOS
use constant default_upgrade_to => 'CloudLinux';
use constant ea_alias => 'CloudLinux_8';
use constant elevate_rpm_url => 'https://repo.cloudlinux.com/elevate/elevate-release-latest-el7.noarch.rpm';
use constant leapp_repo_prod => 'elevate';
use constant leapp_repo_beta => 'elevate-updates-testing';
use constant is_experimental => 1;
use constant leapp_can_handle_epel => 1;
use constant leapp_can_handle_imunify => 1;
Expand Down Expand Up @@ -4806,6 +4811,7 @@ EOS
use constant pretty_name => 'RHEL';
use constant provides_mysql_governor => 0;
use constant should_check_cloudlinux_license => 0;
use constant leapp_repo_beta => ''; # Unavailable by default.

1;

Expand Down Expand Up @@ -4926,8 +4932,9 @@ EOS

use cPstrict;

use Cpanel::JSON ();
use Cpanel::Pkgr ();
use Cpanel::Binaries ();
use Cpanel::JSON ();
use Cpanel::Pkgr ();

use Elevate::OS ();
use Elevate::YUM ();
Expand Down Expand Up @@ -4958,6 +4965,7 @@ EOS
unless ( Cpanel::Pkgr::is_installed('elevate-release') ) {
my $elevate_rpm_url = Elevate::OS::elevate_rpm_url();
$self->yum->install_rpm_via_url($elevate_rpm_url);
$self->beta_if_enabled; # If --leappbeta was passed, then enable it.
}

my $leapp_data_pkg = Elevate::OS::leapp_data_pkg();
Expand All @@ -4969,6 +4977,15 @@ EOS
return;
}

sub beta_if_enabled ($self) {
return unless $self->cpev->getopt('leappbeta');
my $yum_config = Cpanel::Binaries::path('yum-config-manager');
$self->cpev->ssystem_and_die( $yum_config, '--disable', Elevate::OS::leapp_repo_prod() );
$self->cpev->ssystem_and_die( $yum_config, '--enable', Elevate::OS::leapp_repo_beta() );

return 1;
}

sub remove_kernel_devel ($self) {

if ( Cpanel::Pkgr::is_installed('kernel-devel') ) {
Expand Down Expand Up @@ -5949,6 +5966,7 @@ EOS
upgrade-to=s
no-leapp
non-interactive
leappbeta
);
}

Expand All @@ -5958,7 +5976,7 @@ EOS
clean continue help log service status update version
);
my @start_only_options = qw(
manual-reboots non-interactive
manual-reboots non-interactive leappbeta
);

return 1 if !%{ $self->{_getopt} };
Expand Down Expand Up @@ -6219,6 +6237,7 @@ CloudLinux 7 => CloudLinux 8 (Experimental)
--log Show the current elevation log
--status Check the current elevation status
--clean Cleanup scripts and files created by elevate-cpanel
--leappbeta Use the special beta repo from leapp. Do this only if instructed to by cPanel
--upgrade-to=[rocky|almalinux|cloudlinux] Update to AlmaLinux 8 or Rocky Linux 8
[Servers running CentOS 7 will default to 'almalinux']
[Servers running CloudLinux 7 will default to 'cloudlinux']
Expand Down Expand Up @@ -6579,8 +6598,10 @@ sub run ( $pkg, @args ) {
}

if ( $self->getopt('start') ) {
die qq[Unsupported option with --start\n] if $self->getopt('continue') || $self->getopt('service');
return 1 if $self->start();
die qq[Unsupported option with --start\n] if $self->getopt('continue') || $self->getopt('service');
die qq[BETA is unavailable for this leapp repo.] if $self->getopt('leappbeta') && !length Elevate::OS::leapp_repo_beta();

return 1 if $self->start();
}
elsif ( $self->getopt('status') ) {
return $self->check_status();
Expand Down
15 changes: 13 additions & 2 deletions lib/Elevate/Leapp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ Object to install and execute the leapp script

use cPstrict;

use Cpanel::JSON ();
use Cpanel::Pkgr ();
use Cpanel::Binaries ();
use Cpanel::JSON ();
use Cpanel::Pkgr ();

use Elevate::OS ();
use Elevate::YUM ();
Expand Down Expand Up @@ -43,6 +44,7 @@ sub install ($self) {
unless ( Cpanel::Pkgr::is_installed('elevate-release') ) {
my $elevate_rpm_url = Elevate::OS::elevate_rpm_url();
$self->yum->install_rpm_via_url($elevate_rpm_url);
$self->beta_if_enabled; # If --leappbeta was passed, then enable it.
}

my $leapp_data_pkg = Elevate::OS::leapp_data_pkg();
Expand All @@ -54,6 +56,15 @@ sub install ($self) {
return;
}

sub beta_if_enabled ($self) {
return unless $self->cpev->getopt('leappbeta');
my $yum_config = Cpanel::Binaries::path('yum-config-manager');
$self->cpev->ssystem_and_die( $yum_config, '--disable', Elevate::OS::leapp_repo_prod() );
$self->cpev->ssystem_and_die( $yum_config, '--enable', Elevate::OS::leapp_repo_beta() );

return 1;
}

sub remove_kernel_devel ($self) {

if ( Cpanel::Pkgr::is_installed('kernel-devel') ) {
Expand Down
2 changes: 2 additions & 0 deletions lib/Elevate/OS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ BEGIN {
'disable_mysql_yum_repos', # This is a list of mysql repo files to disable
'ea_alias', # This is the value for the --target-os flag used when backing up an EA4 profile
'elevate_rpm_url', # This is the URL used to install the leapp RPM/repo
'leapp_repo_prod', # This is the repo name for the production repo.
'leapp_repo_beta', # This is the repo name for the beta repo. The OS might not provide a beta repo in which case it'll be blank.
'is_experimental', # This is used to determine if the OS is experimental or not
'is_supported', # This is used to determine if the OS is supported or not
'leapp_can_handle_epel', # This is used to determine if we can skip removing the EPEL repo pre_leapp or not
Expand Down
1 change: 1 addition & 0 deletions lib/Elevate/OS/CentOS7.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use constant available_upgrade_paths => (
use constant default_upgrade_to => 'AlmaLinux';
use constant ea_alias => 'CentOS_8';
use constant elevate_rpm_url => 'https://repo.almalinux.org/elevate/elevate-release-latest-el7.noarch.rpm';
use constant leapp_repo_prod => 'elevate';
use constant name => 'CentOS7';
use constant pretty_name => 'CentOS 7';

Expand Down
2 changes: 2 additions & 0 deletions lib/Elevate/OS/CloudLinux7.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use constant available_upgrade_paths => (
use constant default_upgrade_to => 'CloudLinux';
use constant ea_alias => 'CloudLinux_8';
use constant elevate_rpm_url => 'https://repo.cloudlinux.com/elevate/elevate-release-latest-el7.noarch.rpm';
use constant leapp_repo_prod => 'elevate';
use constant leapp_repo_beta => 'elevate-updates-testing';
use constant is_experimental => 1;
use constant leapp_can_handle_epel => 1;
use constant leapp_can_handle_imunify => 1;
Expand Down
1 change: 1 addition & 0 deletions lib/Elevate/OS/RHEL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@ use constant name => 'RHEL';
use constant pretty_name => 'RHEL';
use constant provides_mysql_governor => 0;
use constant should_check_cloudlinux_license => 0;
use constant leapp_repo_beta => ''; # Unavailable by default.

1;
3 changes: 2 additions & 1 deletion lib/Elevate/Usage.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ sub _OPTIONS {
upgrade-to=s
no-leapp
non-interactive
leappbeta
);
}

Expand All @@ -32,7 +33,7 @@ sub _validate_option_combos ($self) {
clean continue help log service status update version
);
my @start_only_options = qw(
manual-reboots non-interactive
manual-reboots non-interactive leappbeta
);

# Invoking with no options is permissible
Expand Down
7 changes: 5 additions & 2 deletions script/elevate-cpanel.PL
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ CloudLinux 7 => CloudLinux 8 (Experimental)
--log Show the current elevation log
--status Check the current elevation status
--clean Cleanup scripts and files created by elevate-cpanel
--leappbeta Use the special beta repo from leapp. Do this only if instructed to by cPanel
--upgrade-to=[rocky|almalinux|cloudlinux] Update to AlmaLinux 8 or Rocky Linux 8
[Servers running CentOS 7 will default to 'almalinux']
[Servers running CloudLinux 7 will default to 'cloudlinux']
Expand Down Expand Up @@ -415,8 +416,10 @@ sub run ( $pkg, @args ) {
}

if ( $self->getopt('start') ) {
die qq[Unsupported option with --start\n] if $self->getopt('continue') || $self->getopt('service');
return 1 if $self->start();
die qq[Unsupported option with --start\n] if $self->getopt('continue') || $self->getopt('service');
die qq[BETA is unavailable for this leapp repo.] if $self->getopt('leappbeta') && !length Elevate::OS::leapp_repo_beta();

return 1 if $self->start();
}
elsif ( $self->getopt('status') ) {
return $self->check_status();
Expand Down
49 changes: 49 additions & 0 deletions t/leapp_beta.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/local/cpanel/3rdparty/bin/perl

# HARNESS-NO-STREAM

use cPstrict;
use FindBin;

use Test2::V0;
use Test2::Tools::Explain;
use Test2::Plugin::NoWarnings;
use Test2::Tools::Exception;

use Test::MockModule qw/strict/;

use lib $FindBin::Bin . "/lib";
use Test::Elevate;

use cPstrict;

$INC{'scripts/ElevateCpanel.pm'} = '__TEST__';

my @ssystem_cmds;
my $leappbeta = 1;
my $mock_elevate = Test::MockModule->new('cpev');
$mock_elevate->redefine(
ssystem_and_die => sub ( $, @args ) {

push @ssystem_cmds, [@args];
note "run: " . join( " ", @args );

return;
},
getopt => sub ( $, $opt ) { return $leappbeta if $opt && $opt eq 'leappbeta' },
);

my $cpev = bless( {}, 'cpev' );
my $self = Elevate::Leapp->new( 'cpev' => $cpev );

set_os_to_cloudlinux_7();
is( $self->beta_if_enabled, 1, "beta_if_enabled when enabled" );
is( \@ssystem_cmds, [ [qw{/usr/bin/yum-config-manager --disable elevate}], [qw{/usr/bin/yum-config-manager --enable elevate-updates-testing}] ], "Expected commands are run to setup the repos." )
or diag explain \@ssystem_cmds;

$leappbeta = 0;
@ssystem_cmds = ();
is( $self->beta_if_enabled, undef, "beta_if_enabled when disabled" );
is( \@ssystem_cmds, [], "No commands are run to setup the repos." );

done_testing;

0 comments on commit 7574ece

Please sign in to comment.