-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support elevate for systems with Acronis backup agent
Case RE-575: For Acronis, we must remove the Acronis backup agent package before the distro upgrade and re-install it after the distro upgrade. Changelog: Support running elevate on systems that have the Acronis backup agent installed.
- Loading branch information
Tim Mullin
committed
Oct 16, 2024
1 parent
19ffe6c
commit bc1f04f
Showing
7 changed files
with
239 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package Elevate::Components::Acronis; | ||
|
||
=encoding utf-8 | ||
=head1 NAME | ||
Elevate::Components::Acronis | ||
=head2 check | ||
noop | ||
=head2 pre_distro_upgrade | ||
Find out if Acronis is installed. | ||
If it is, uninstall it & make a note in the stage file. | ||
(We'll need to reinstall it after the OS upgrade.) | ||
=head2 post_distro_upgrade | ||
If the agent had been installed: | ||
Re-install the agent. | ||
=cut | ||
|
||
use cPstrict; | ||
|
||
use Elevate::Constants (); | ||
use Elevate::StageFile (); | ||
|
||
use Cpanel::Pkgr (); | ||
|
||
use parent qw{Elevate::Components::Base}; | ||
|
||
sub pre_distro_upgrade ($self) { | ||
|
||
return unless Cpanel::Pkgr::is_installed(Elevate::Constants::ACRONIS_BACKUP_PACKAGE); | ||
|
||
$self->yum->remove( | ||
Elevate::Constants::ACRONIS_BACKUP_PACKAGE, | ||
Elevate::Constants::ACRONIS_OTHER_PACKAGES | ||
); | ||
|
||
Elevate::StageFile::update_stage_file( { 'reinstall' => { 'acronis' => 1 } } ); | ||
|
||
return; | ||
} | ||
|
||
sub post_distro_upgrade ($self) { | ||
|
||
return unless Elevate::StageFile::read_stage_file('reinstall')->{'acronis'}; | ||
|
||
$self->dnf->install(Elevate::Constants::ACRONIS_BACKUP_PACKAGE); | ||
|
||
return; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#!/usr/local/cpanel/3rdparty/bin/perl | ||
|
||
# Copyright 2024 WebPros International, LLC | ||
# All rights reserved. | ||
# copyright@cpanel.net http://cpanel.net | ||
# This code is subject to the cPanel license. Unauthorized copying is prohibited. | ||
|
||
package test::cpev::components; | ||
|
||
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; | ||
|
||
my $acronis = cpev->new->get_component('Acronis'); | ||
|
||
{ | ||
note "Checking pre_distro_upgrade"; | ||
|
||
my $is_installed; | ||
my $yum_remove_called; | ||
my $stage_file_data; | ||
|
||
my $mock_pkgr = Test::MockModule->new('Cpanel::Pkgr'); | ||
$mock_pkgr->redefine( | ||
is_installed => sub { return $is_installed; }, | ||
); | ||
|
||
my $mock_yum = Test::MockModule->new('Elevate::YUM'); | ||
$mock_yum->redefine( | ||
remove => sub { $yum_remove_called = 1; }, | ||
); | ||
|
||
my $mock_upsf = Test::MockModule->new('Elevate::StageFile'); | ||
$mock_upsf->redefine( | ||
update_stage_file => sub { $stage_file_data = shift; }, | ||
); | ||
|
||
# Test when Acronis is not installed | ||
$is_installed = 0; | ||
$yum_remove_called = 0; | ||
$stage_file_data = {}; | ||
|
||
$acronis->pre_distro_upgrade(); | ||
is( $yum_remove_called, 0, 'When package not installed: did not uninstall package' ); | ||
is( $stage_file_data, {}, 'When package not installed: did not update the stage file' ); | ||
|
||
# Test when Acronis is installed | ||
$is_installed = 1; | ||
$yum_remove_called = 0; | ||
$stage_file_data = {}; | ||
|
||
$acronis->pre_distro_upgrade(); | ||
is( $yum_remove_called, 1, 'When package is installed: uninstalled package' ); | ||
is( | ||
$stage_file_data, | ||
{ | ||
'reinstall' => { | ||
'acronis' => 1, | ||
}, | ||
}, | ||
'When package is installed: updated the stage file' | ||
); | ||
} | ||
|
||
{ | ||
note "Checking post_distro_upgrade"; | ||
|
||
my $stage_file_data; | ||
my $dnf_install_called; | ||
|
||
my $mock_upsf = Test::MockModule->new('Elevate::StageFile'); | ||
$mock_upsf->redefine( | ||
read_stage_file => sub { return $stage_file_data; }, | ||
); | ||
|
||
my $mock_dnf = Test::MockModule->new('Elevate::DNF'); | ||
$mock_dnf->redefine( | ||
install => sub { $dnf_install_called = 1; }, | ||
); | ||
|
||
# Test when had not been installed | ||
$stage_file_data = {}; | ||
$dnf_install_called = 0; | ||
|
||
$acronis->post_distro_upgrade(); | ||
is( $dnf_install_called, 0, 'When package was never installed: did not reinstall' ); | ||
|
||
# Test when had been installed | ||
$stage_file_data = { 'acronis' => 1 }; | ||
$dnf_install_called = 1; | ||
|
||
$acronis->post_distro_upgrade(); | ||
is( $dnf_install_called, 1, 'When package had been installed: reinstalled package' ); | ||
} | ||
|
||
done_testing(); |