Skip to content

Commit

Permalink
Merge pull request #502 from sloanebernstein/RE-492
Browse files Browse the repository at this point in the history
Mention "MariaDB" not "MySQL" when appropriate
  • Loading branch information
toddr authored Aug 28, 2024
2 parents 064c5fa + 3f7fb95 commit f63bb7b
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 52 deletions.
57 changes: 34 additions & 23 deletions elevate-cpanel
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,8 @@ BEGIN { # Suppress load of all of these at earliest point.
# use Log::Log4perl qw(:easy);
INIT { Log::Log4perl->import(qw{:easy}); }

my ( $db_type, $db_version );

sub check ($self) {
my $ok = 1;
$ok = 0 unless $self->_blocker_old_mysql;
Expand All @@ -632,65 +634,65 @@ BEGIN { # Suppress load of all of these at earliest point.
}

sub _blocker_old_cloudlinux_mysql ($self) {
my ( $db_type, $db_version ) = Elevate::Database::get_db_info_if_provided_by_cloudlinux();
( $db_type, $db_version ) = Elevate::Database::get_db_info_if_provided_by_cloudlinux();

return 0 if length $db_version && $db_version >= 55;

my $pretty_distro_name = $self->upgrade_to_pretty_name();
my $db_dot_version = $db_version;
$db_type = Elevate::Database::pretty_type_name($db_type);

$db_dot_version =~ s/([0-9])$/\.$1/;
$db_version =~ s/([0-9])$/\.$1/;

return $self->has_blocker( <<~"EOS");
You are using MySQL $db_dot_version server.
You are using $db_type $db_version server.
This version is not available for $pretty_distro_name.
You first need to update your MySQL server to 5.5 or later.
You first need to update your database server software to version 5.5 or later.
Please review the following documentation for instructions
on how to update to a newer MySQL Version with MySQL Governor:
on how to update to a newer version with MySQL Governor:
https://docs.cloudlinux.com/shared/cloudlinux_os_components/#upgrading-database-server
Once the MySQL upgrade is finished, you can then retry to elevate to $pretty_distro_name.
Once the upgrade is finished, you can then retry to ELevate to $pretty_distro_name.
EOS
}

sub _blocker_old_cpanel_mysql ($self) {

my $mysql_version = Elevate::Database::get_local_database_version();
$db_version = Elevate::Database::get_local_database_version();

if ( Elevate::Database::is_database_version_supported($mysql_version) ) {
if ( Elevate::Database::is_database_version_supported($db_version) ) {

Elevate::StageFile::update_stage_file( { 'mysql-version' => $mysql_version } );
Elevate::StageFile::update_stage_file( { 'mysql-version' => $db_version } );
return 0;
}

my $pretty_distro_name = $self->upgrade_to_pretty_name();
my $database_type_name = Elevate::Database::get_database_type_name_from_version($mysql_version);
my $pretty_distro_name = $self->upgrade_to_pretty_name();
$db_type = Elevate::Database::get_database_type_name_from_version($db_version);
my $upgrade_version = Elevate::Database::get_default_upgrade_version();
my $upgrade_dbtype_name = Elevate::Database::get_database_type_name_from_version($upgrade_version);

WARN( <<~"EOS" );
You have $database_type_name $mysql_version installed.
You have $db_type $db_version installed.
This version is not available for $pretty_distro_name.
EOS

if ( $self->is_check_mode() ) {
INFO( <<~"EOS" );
You can manually upgrade your installation of $database_type_name using the following command:
You can manually upgrade your installation of $db_type using the following command:
/usr/local/cpanel/bin/whmapi1 start_background_mysql_upgrade version=$upgrade_version
Once the MySQL upgrade is finished, you can then retry to elevate to $pretty_distro_name.
Once the $db_type upgrade is finished, you can then retry to elevate to $pretty_distro_name.
EOS
return 0;
}

WARN( <<~"EOS" );
Prior to elevating this system to $pretty_distro_name,
we will automatically upgrade your installation of $database_type_name
we will automatically upgrade your installation of $db_type
to $upgrade_dbtype_name $upgrade_version.
EOS
Expand All @@ -706,7 +708,7 @@ BEGIN { # Suppress load of all of these at earliest point.
)
) {
return $self->has_blocker( <<~"EOS" );
The system cannot be elevated to $pretty_distro_name until $database_type_name has been upgraded. To upgrade manually:
The system cannot be elevated to $pretty_distro_name until $db_type has been upgraded. To upgrade manually:
/usr/local/cpanel/bin/whmapi1 start_background_mysql_upgrade version=$upgrade_version
Expand All @@ -723,7 +725,7 @@ BEGIN { # Suppress load of all of these at earliest point.

sub _blocker_mysql_upgrade_in_progress ($self) {
if ( -e q[/var/cpanel/mysql_upgrade_in_progress] ) {
return $self->has_blocker(q[MySQL upgrade in progress. Please wait for the MySQL upgrade to finish.]);
return $self->has_blocker(q[MySQL/MariaDB upgrade in progress. Please wait for the upgrade to finish.]);
}

return 0;
Expand All @@ -734,7 +736,7 @@ BEGIN { # Suppress load of all of these at earliest point.
my $enabled = Cpanel::Services::Enabled::is_enabled('mysql');

Elevate::StageFile::update_stage_file( { 'mysql-enabled' => $enabled } );
WARN( "MySQL is disabled. This must be enabled for MySQL upgrade to succeed.\n" . "We temporarily will enable it when it is needed to be enabled,\n" . "but we reccomend starting the process with MySQL enabled." ) if !$enabled;
WARN( "$db_type is disabled. This must be enabled for the upgrade to succeed.\n" . "We temporarily will enable it when it is needed to be enabled,\n" . "but we recommend starting the process with $db_type enabled." ) if !$enabled;
return 0;
}

Expand Down Expand Up @@ -4356,7 +4358,8 @@ EOS
my $mysql_version = Elevate::StageFile::read_stage_file( 'mysql-version', '' );
return unless length $mysql_version;

INFO("# Cleanup MySQL packages ; using version $mysql_version");
my $db_type = Elevate::Database::get_database_type_name_from_version($mysql_version);
INFO("# Cleanup $db_type packages ; using version $mysql_version");

Elevate::StageFile::update_stage_file( { 'mysql-version' => $mysql_version } );

Expand Down Expand Up @@ -5900,7 +5903,7 @@ EOS
}

sub _set_local_mysql_root_password ( $self, $password ) {
INFO("Resetting password for local root MySQL user...");
INFO("Resetting password for local root database user...");

my $encoded_password = Cpanel::Encoder::URI::uri_encode_str($password);

Expand All @@ -5912,7 +5915,7 @@ EOS
my $errors = join qq{\n\n}, @{ $result->{'metadata'}{'errors'} };

die <<~"EOS";
Unable to set root password for the localhost MySQL server.
Unable to set root password for the localhost database server.
The following errors occurred:
Expand Down Expand Up @@ -5942,7 +5945,7 @@ EOS

if ( $stdout !~ m{MySQL profile activation done} ) {
die <<~"EOS";
Unable to activate a MySQL DB profile for "localhost":
Unable to activate a MySQL profile for "localhost":
$stdout
Expand Down Expand Up @@ -6585,6 +6588,14 @@ EOS
return;
}

sub pretty_type_name ($type) {
$type =~ s/^mysql$/MySQL/i;
$type =~ s/^mariadb$/MariaDB/i;
$type =~ s/^(?:pgsql|postgres(?:ql)?)$/PostgreSQL/i;
$type =~ s/^percona$/Percona/i; # yes, Percona is a valid type; see get_db_info_if_provided_by_cloudlinux
return $type;
}

1;

} # --- END lib/Elevate/Database.pm
Expand Down
40 changes: 21 additions & 19 deletions lib/Elevate/Blockers/Databases.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ use parent qw{Elevate::Blockers::Base};

use Log::Log4perl qw(:easy);

my ( $db_type, $db_version );

sub check ($self) {
my $ok = 1;
$ok = 0 unless $self->_blocker_old_mysql;
Expand All @@ -43,73 +45,73 @@ sub _blocker_old_mysql ($self) {
}

sub _blocker_old_cloudlinux_mysql ($self) {
my ( $db_type, $db_version ) = Elevate::Database::get_db_info_if_provided_by_cloudlinux();
( $db_type, $db_version ) = Elevate::Database::get_db_info_if_provided_by_cloudlinux();

# 5.5 gets stored as 55 and so on and so forth since there are no .'s
# for the version in the RPM package name
return 0 if length $db_version && $db_version >= 55;

my $pretty_distro_name = $self->upgrade_to_pretty_name();
my $db_dot_version = $db_version;
$db_type = Elevate::Database::pretty_type_name($db_type);

# Shift decimal one place to the left
# 80 becomes 8.0
# 102 becomes 10.2
$db_dot_version =~ s/([0-9])$/\.$1/;
$db_version =~ s/([0-9])$/\.$1/;

return $self->has_blocker( <<~"EOS");
You are using MySQL $db_dot_version server.
You are using $db_type $db_version server.
This version is not available for $pretty_distro_name.
You first need to update your MySQL server to 5.5 or later.
You first need to update your database server software to version 5.5 or later.
Please review the following documentation for instructions
on how to update to a newer MySQL Version with MySQL Governor:
on how to update to a newer version with MySQL Governor:
https://docs.cloudlinux.com/shared/cloudlinux_os_components/#upgrading-database-server
Once the MySQL upgrade is finished, you can then retry to elevate to $pretty_distro_name.
Once the upgrade is finished, you can then retry to ELevate to $pretty_distro_name.
EOS
}

sub _blocker_old_cpanel_mysql ($self) {

my $mysql_version = Elevate::Database::get_local_database_version();
$db_version = Elevate::Database::get_local_database_version();

# If we are running a local version of MySQL/MariaDB that will be
# supported by the new OS version, we leave it as it is.
if ( Elevate::Database::is_database_version_supported($mysql_version) ) {
if ( Elevate::Database::is_database_version_supported($db_version) ) {

# store the MySQL version we started from
Elevate::StageFile::update_stage_file( { 'mysql-version' => $mysql_version } );
Elevate::StageFile::update_stage_file( { 'mysql-version' => $db_version } );
return 0;
}

my $pretty_distro_name = $self->upgrade_to_pretty_name();
my $database_type_name = Elevate::Database::get_database_type_name_from_version($mysql_version);
my $pretty_distro_name = $self->upgrade_to_pretty_name();
$db_type = Elevate::Database::get_database_type_name_from_version($db_version);
my $upgrade_version = Elevate::Database::get_default_upgrade_version();
my $upgrade_dbtype_name = Elevate::Database::get_database_type_name_from_version($upgrade_version);

WARN( <<~"EOS" );
You have $database_type_name $mysql_version installed.
You have $db_type $db_version installed.
This version is not available for $pretty_distro_name.
EOS

if ( $self->is_check_mode() ) {
INFO( <<~"EOS" );
You can manually upgrade your installation of $database_type_name using the following command:
You can manually upgrade your installation of $db_type using the following command:
/usr/local/cpanel/bin/whmapi1 start_background_mysql_upgrade version=$upgrade_version
Once the MySQL upgrade is finished, you can then retry to elevate to $pretty_distro_name.
Once the $db_type upgrade is finished, you can then retry to elevate to $pretty_distro_name.
EOS
return 0;
}

WARN( <<~"EOS" );
Prior to elevating this system to $pretty_distro_name,
we will automatically upgrade your installation of $database_type_name
we will automatically upgrade your installation of $db_type
to $upgrade_dbtype_name $upgrade_version.
EOS
Expand All @@ -125,7 +127,7 @@ sub _blocker_old_cpanel_mysql ($self) {
)
) {
return $self->has_blocker( <<~"EOS" );
The system cannot be elevated to $pretty_distro_name until $database_type_name has been upgraded. To upgrade manually:
The system cannot be elevated to $pretty_distro_name until $db_type has been upgraded. To upgrade manually:
/usr/local/cpanel/bin/whmapi1 start_background_mysql_upgrade version=$upgrade_version
Expand All @@ -143,7 +145,7 @@ sub _blocker_old_cpanel_mysql ($self) {

sub _blocker_mysql_upgrade_in_progress ($self) {
if ( -e q[/var/cpanel/mysql_upgrade_in_progress] ) {
return $self->has_blocker(q[MySQL upgrade in progress. Please wait for the MySQL upgrade to finish.]);
return $self->has_blocker(q[MySQL/MariaDB upgrade in progress. Please wait for the upgrade to finish.]);
}

return 0;
Expand All @@ -154,7 +156,7 @@ sub _warning_mysql_not_enabled ($self) {
my $enabled = Cpanel::Services::Enabled::is_enabled('mysql');

Elevate::StageFile::update_stage_file( { 'mysql-enabled' => $enabled } );
WARN( "MySQL is disabled. This must be enabled for MySQL upgrade to succeed.\n" . "We temporarily will enable it when it is needed to be enabled,\n" . "but we reccomend starting the process with MySQL enabled." ) if !$enabled;
WARN( "$db_type is disabled. This must be enabled for the upgrade to succeed.\n" . "We temporarily will enable it when it is needed to be enabled,\n" . "but we recommend starting the process with $db_type enabled." ) if !$enabled;
return 0;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Elevate/Components/DatabaseUpgrade.pm
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ sub _create_new_localhost_profile ( $self, $profile_manager ) {
}

sub _set_local_mysql_root_password ( $self, $password ) {
INFO("Resetting password for local root MySQL user...");
INFO("Resetting password for local root database user...");

my $encoded_password = Cpanel::Encoder::URI::uri_encode_str($password);

Expand All @@ -153,7 +153,7 @@ sub _set_local_mysql_root_password ( $self, $password ) {
my $errors = join qq{\n\n}, @{ $result->{'metadata'}{'errors'} };

die <<~"EOS";
Unable to set root password for the localhost MySQL server.
Unable to set root password for the localhost database server.
The following errors occurred:
Expand Down Expand Up @@ -183,7 +183,7 @@ sub _activate_localhost_profile {

if ( $stdout !~ m{MySQL profile activation done} ) {
die <<~"EOS";
Unable to activate a MySQL DB profile for "localhost":
Unable to activate a MySQL profile for "localhost":
$stdout
Expand Down
3 changes: 2 additions & 1 deletion lib/Elevate/Components/MySQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ sub _cleanup_mysql_packages ($self) {
my $mysql_version = Elevate::StageFile::read_stage_file( 'mysql-version', '' );
return unless length $mysql_version;

INFO("# Cleanup MySQL packages ; using version $mysql_version");
my $db_type = Elevate::Database::get_database_type_name_from_version($mysql_version);
INFO("# Cleanup $db_type packages ; using version $mysql_version");

Elevate::StageFile::update_stage_file( { 'mysql-version' => $mysql_version } );

Expand Down
8 changes: 8 additions & 0 deletions lib/Elevate/Database.pm
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,12 @@ sub upgrade_database_server () {
return;
}

sub pretty_type_name ($type) {
$type =~ s/^mysql$/MySQL/i;
$type =~ s/^mariadb$/MariaDB/i;
$type =~ s/^(?:pgsql|postgres(?:ql)?)$/PostgreSQL/i;
$type =~ s/^percona$/Percona/i; # yes, Percona is a valid type; see get_db_info_if_provided_by_cloudlinux
return $type;
}

1;
10 changes: 5 additions & 5 deletions t/blocker-Databases.t
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ my $mock_elevate = Test::MockFile->file('/var/cpanel/elevate');
$db->_blocker_mysql_upgrade_in_progress(),
{
id => q[Elevate::Blockers::Databases::_blocker_mysql_upgrade_in_progress],
msg => "MySQL upgrade in progress. Please wait for the MySQL upgrade to finish.",
msg => "MySQL/MariaDB upgrade in progress. Please wait for the upgrade to finish.",
},
q{Block if mysql is upgrading.}
);
Expand Down Expand Up @@ -171,16 +171,16 @@ my $mock_elevate = Test::MockFile->file('/var/cpanel/elevate');
{
id => q[Elevate::Blockers::Databases::_blocker_old_cloudlinux_mysql],
msg => <<~'EOS',
You are using MySQL 5.1 server.
You are using foo 5.1 server.
This version is not available for CloudLinux 8.
You first need to update your MySQL server to 5.5 or later.
You first need to update your database server software to version 5.5 or later.
Please review the following documentation for instructions
on how to update to a newer MySQL Version with MySQL Governor:
on how to update to a newer version with MySQL Governor:
https://docs.cloudlinux.com/shared/cloudlinux_os_components/#upgrading-database-server
Once the MySQL upgrade is finished, you can then retry to elevate to CloudLinux 8.
Once the upgrade is finished, you can then retry to ELevate to CloudLinux 8.
EOS
},
'5.1 is a blocker for CL',
Expand Down
2 changes: 1 addition & 1 deletion t/components-DatabaseUpgrade.t
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ my $db_upgrade = bless {}, 'Elevate::Components::DatabaseUpgrade';
$mock_saferun->redefine( 'saferunnoerror', sub { push @cmds, \@_; return $stdout } );

ok lives { $db_upgrade->_set_local_mysql_root_password('F00b4r!@#%$%') }, '_set_local_mysql_root_password with successful api call lives';
message_seen( 'INFO', qr/Resetting password for local root MySQL user/ );
message_seen( 'INFO', qr/Resetting password for local root database user/ );

is \@cmds, [
[
Expand Down

0 comments on commit f63bb7b

Please sign in to comment.