You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-29 08:21:11 +03:00
Migrate integration tests to C.
The Perl integration tests were migrated as faithfully as possible, but there was some cruft and a few unit tests that it did not make sense to migrate. Also remove all Perl code made obsolete by this migration. All unit, performance, and integration tests are now written in C but significant parts of the test harness remain to be migrated.
This commit is contained in:
@ -16,11 +16,11 @@ use File::Basename qw(dirname);
|
||||
use Storable qw(dclone);
|
||||
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
use pgBackRestTest::Common::HostTest;
|
||||
use pgBackRestTest::Common::HostGroupTest;
|
||||
|
||||
use pgBackRestDoc::Common::DocManifest;
|
||||
use pgBackRestDoc::Common::Exception;
|
||||
use pgBackRestDoc::Common::Host;
|
||||
use pgBackRestDoc::Common::HostGroup;
|
||||
use pgBackRestDoc::Common::Ini;
|
||||
use pgBackRestDoc::Common::Log;
|
||||
use pgBackRestDoc::Common::String;
|
||||
@ -1050,7 +1050,7 @@ sub sectionChildProcess
|
||||
$strOption =~ s/\{\[host\-repo\-path\]\}/${strHostRepoPath}/g;
|
||||
}
|
||||
|
||||
my $oHost = new pgBackRestTest::Common::HostTest(
|
||||
my $oHost = new pgBackRestDoc::Common::Host(
|
||||
$$hCacheKey{name}, "doc-$$hCacheKey{name}", $strImage, $strHostUser,
|
||||
defined($strMount) ? [$strMount] : undef, $strOption, $$hCacheKey{param}, $$hCacheKey{'update-hosts'});
|
||||
|
||||
|
312
doc/lib/pgBackRestDoc/Common/Host.pm
Normal file
312
doc/lib/pgBackRestDoc/Common/Host.pm
Normal file
@ -0,0 +1,312 @@
|
||||
####################################################################################################################################
|
||||
# HostTest.pm - Encapsulate a docker host
|
||||
####################################################################################################################################
|
||||
package pgBackRestDoc::Common::Host;
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
####################################################################################################################################
|
||||
use strict;
|
||||
use warnings FATAL => qw(all);
|
||||
use Carp qw(confess);
|
||||
|
||||
use Cwd qw(abs_path);
|
||||
use Exporter qw(import);
|
||||
our @EXPORT = qw();
|
||||
|
||||
use pgBackRestDoc::Common::Log;
|
||||
use pgBackRestDoc::Common::String;
|
||||
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# new
|
||||
####################################################################################################################################
|
||||
sub new
|
||||
{
|
||||
my $class = shift; # Class name
|
||||
|
||||
# Create the class hash
|
||||
my $self = {};
|
||||
bless $self, $class;
|
||||
|
||||
# Assign function parameters, defaults, and log debug info
|
||||
(
|
||||
my $strOperation,
|
||||
$self->{strName},
|
||||
$self->{strContainer},
|
||||
$self->{strImage},
|
||||
$self->{strUser},
|
||||
$self->{stryMount},
|
||||
$self->{strOption},
|
||||
$self->{strParam},
|
||||
$self->{bHostUpdate},
|
||||
$self->{strEntryPoint},
|
||||
) =
|
||||
logDebugParam
|
||||
(
|
||||
__PACKAGE__ . '->new', \@_,
|
||||
{name => 'strName', trace => true},
|
||||
{name => 'strContainer', trace => true},
|
||||
{name => 'strImage', trace => true},
|
||||
{name => 'strUser', trace => true},
|
||||
{name => 'stryMount', required => false, trace => true},
|
||||
{name => 'strOption', required => false, trace => true},
|
||||
{name => 'strParam', required => false, trace => true},
|
||||
{name => 'bHostUpdate', required => false, trace => true, default => true},
|
||||
{name => 'strEntryPoint', required => false, trace => true},
|
||||
);
|
||||
|
||||
executeTest("docker rm -f $self->{strContainer}", {bSuppressError => true});
|
||||
|
||||
executeTest("docker run -itd -h $self->{strName} --name=$self->{strContainer}" .
|
||||
(defined($self->{strOption}) ? ' ' . $self->{strOption} : '') .
|
||||
(defined($self->{stryMount}) ? ' -v ' . join(' -v ', @{$self->{stryMount}}) : '') .
|
||||
(defined($self->{strEntryPoint}) ? " --entrypoint=$self->{strEntryPoint} --user=$self->{strUser}" : '') .
|
||||
" $self->{strImage} " . (defined($self->{strParam}) ? ' ' . $self->{strParam} : ''),
|
||||
{bSuppressStdErr => true});
|
||||
|
||||
# Get IP Address
|
||||
$self->{strIP} = trim(executeTest("docker inspect --format '\{\{ .NetworkSettings.IPAddress \}\}' $self->{strContainer}"));
|
||||
$self->{bActive} = true;
|
||||
|
||||
# Return from function and log return values if any
|
||||
return logDebugReturn
|
||||
(
|
||||
$strOperation,
|
||||
{name => 'self', value => $self, trace => true}
|
||||
);
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# remove
|
||||
####################################################################################################################################
|
||||
sub remove
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Assign function parameters, defaults, and log debug info
|
||||
my ($strOperation) = logDebugParam(__PACKAGE__ . '->remove');
|
||||
|
||||
if ($self->{bActive})
|
||||
{
|
||||
executeTest("docker rm -f $self->{strContainer}", {bSuppressError => true});
|
||||
$self->{bActive} = false;
|
||||
}
|
||||
|
||||
# Return from function and log return values if any
|
||||
return logDebugReturn($strOperation);
|
||||
}
|
||||
|
||||
|
||||
####################################################################################################################################
|
||||
# execute
|
||||
####################################################################################################################################
|
||||
sub execute
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Assign function parameters, defaults, and log debug info
|
||||
my
|
||||
(
|
||||
$strOperation,
|
||||
$strCommand,
|
||||
$oParam,
|
||||
$strUser,
|
||||
$bLoadEnv,
|
||||
$bBashWrap,
|
||||
) =
|
||||
logDebugParam
|
||||
(
|
||||
__PACKAGE__ . '->execute', \@_,
|
||||
{name => 'strCommand'},
|
||||
{name => 'oParam', required => false},
|
||||
{name => 'strUser', required => false},
|
||||
{name => 'bLoadEnv', optional => true, default => true},
|
||||
{name => 'bBashWrap', optional => true, default => true},
|
||||
);
|
||||
|
||||
# Set the user
|
||||
if (!defined($strUser))
|
||||
{
|
||||
$strUser = $self->{strUser};
|
||||
}
|
||||
|
||||
$strCommand =~ s/'/'\\''/g;
|
||||
|
||||
my $oExec = new pgBackRestTest::Common::ExecuteTest(
|
||||
"docker exec -u ${strUser} $self->{strContainer}" .
|
||||
($bBashWrap ? " bash" . ($bLoadEnv ? ' -l' : '') . " -c '${strCommand}'" : " ${strCommand}"), $oParam);
|
||||
|
||||
# Return from function and log return values if any
|
||||
return logDebugReturn
|
||||
(
|
||||
$strOperation,
|
||||
{name => 'oExec', value => $oExec, trace => true}
|
||||
);
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# executeSimple
|
||||
####################################################################################################################################
|
||||
sub executeSimple
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Assign function parameters, defaults, and log debug info
|
||||
my
|
||||
(
|
||||
$strOperation,
|
||||
$strCommand,
|
||||
$oParam,
|
||||
$strUser,
|
||||
$bLoadEnv,
|
||||
$bBashWrap,
|
||||
) =
|
||||
logDebugParam
|
||||
(
|
||||
__PACKAGE__ . '->executeSimple', \@_,
|
||||
{name => 'strCommand', trace => true},
|
||||
{name => 'oParam', required=> false, trace => true},
|
||||
{name => 'strUser', required => false, trace => true},
|
||||
{name => 'bLoadEnv', optional => true, default => true, trace => true},
|
||||
{name => 'bBashWrap', optional => true, default => true},
|
||||
);
|
||||
|
||||
my $oExec = $self->execute($strCommand, $oParam, $strUser, {bLoadEnv => $bLoadEnv});
|
||||
$oExec->begin();
|
||||
$oExec->end();
|
||||
|
||||
# Return from function and log return values if any
|
||||
return logDebugReturn
|
||||
(
|
||||
$strOperation,
|
||||
{name => 'strOutLog', value => $oExec->{strOutLog}, trace => true}
|
||||
);
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# copyTo
|
||||
####################################################################################################################################
|
||||
sub copyTo
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Assign function parameters, defaults, and log debug info
|
||||
my
|
||||
(
|
||||
$strOperation,
|
||||
$strSource,
|
||||
$strDestination,
|
||||
$strOwner,
|
||||
$strMode
|
||||
) =
|
||||
logDebugParam
|
||||
(
|
||||
__PACKAGE__ . '->copyTo', \@_,
|
||||
{name => 'strSource'},
|
||||
{name => 'strDestination'},
|
||||
{name => 'strOwner', required => false},
|
||||
{name => 'strMode', required => false}
|
||||
);
|
||||
|
||||
executeTest("docker cp ${strSource} $self->{strContainer}:${strDestination}");
|
||||
|
||||
if (defined($strOwner))
|
||||
{
|
||||
$self->executeSimple("chown ${strOwner} ${strDestination}", undef, 'root');
|
||||
}
|
||||
|
||||
if (defined($strMode))
|
||||
{
|
||||
$self->executeSimple("chmod ${strMode} ${strDestination}", undef, 'root');
|
||||
}
|
||||
|
||||
# Return from function and log return values if any
|
||||
return logDebugReturn($strOperation);
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# copyFrom
|
||||
####################################################################################################################################
|
||||
sub copyFrom
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Assign function parameters, defaults, and log debug info
|
||||
my
|
||||
(
|
||||
$strOperation,
|
||||
$strSource,
|
||||
$strDestination
|
||||
) =
|
||||
logDebugParam
|
||||
(
|
||||
__PACKAGE__ . '->copyFrom', \@_,
|
||||
{name => 'strSource'},
|
||||
{name => 'strDestination'}
|
||||
);
|
||||
|
||||
executeTest("docker cp $self->{strContainer}:${strSource} ${strDestination}");
|
||||
|
||||
# Return from function and log return values if any
|
||||
return logDebugReturn($strOperation);
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# hostUpdateGet
|
||||
####################################################################################################################################
|
||||
sub hostUpdateGet
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
return $self->{bHostUpdate};
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# ipGet
|
||||
####################################################################################################################################
|
||||
sub ipGet
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
return $self->{strIP};
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# nameGet
|
||||
####################################################################################################################################
|
||||
sub nameGet
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
return $self->{strName};
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# nameTest
|
||||
####################################################################################################################################
|
||||
sub nameTest
|
||||
{
|
||||
my $self = shift;
|
||||
my $strName = shift;
|
||||
|
||||
return $self->{strName} eq $strName;
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# userGet
|
||||
####################################################################################################################################
|
||||
sub userGet
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
return $self->{strUser};
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# Getters
|
||||
####################################################################################################################################
|
||||
sub container {shift->{strContainer}}
|
||||
|
||||
1;
|
188
doc/lib/pgBackRestDoc/Common/HostGroup.pm
Normal file
188
doc/lib/pgBackRestDoc/Common/HostGroup.pm
Normal file
@ -0,0 +1,188 @@
|
||||
####################################################################################################################################
|
||||
# HostGroupTest.pm - Encapsulate a group of docker containers
|
||||
####################################################################################################################################
|
||||
package pgBackRestDoc::Common::HostGroup;
|
||||
|
||||
####################################################################################################################################
|
||||
# Perl includes
|
||||
####################################################################################################################################
|
||||
use strict;
|
||||
use warnings FATAL => qw(all);
|
||||
use Carp qw(confess);
|
||||
|
||||
use Cwd qw(abs_path);
|
||||
use Exporter qw(import);
|
||||
our @EXPORT = qw();
|
||||
|
||||
use pgBackRestDoc::Common::Log;
|
||||
use pgBackRestDoc::Common::String;
|
||||
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
|
||||
####################################################################################################################################
|
||||
# Global host group variable
|
||||
####################################################################################################################################
|
||||
my $oHostGroup;
|
||||
|
||||
####################################################################################################################################
|
||||
# new
|
||||
####################################################################################################################################
|
||||
sub new
|
||||
{
|
||||
my $class = shift; # Class name
|
||||
|
||||
# Create the class hash
|
||||
my $self = {};
|
||||
bless $self, $class;
|
||||
|
||||
# Assign function parameters, defaults, and log debug info
|
||||
my ($strOperation) = logDebugParam(__PACKAGE__ . '->new');
|
||||
|
||||
# Return from function and log return values if any
|
||||
return logDebugReturn
|
||||
(
|
||||
$strOperation,
|
||||
{name => 'self', value => $self, trace => true}
|
||||
);
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# hostAdd
|
||||
####################################################################################################################################
|
||||
sub hostAdd
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Assign function parameters, defaults, and log debug info
|
||||
my
|
||||
(
|
||||
$strOperation,
|
||||
$oHost,
|
||||
$rstryHostName,
|
||||
) =
|
||||
logDebugParam
|
||||
(
|
||||
__PACKAGE__ . '->hostAdd', \@_,
|
||||
{name => 'oHost'},
|
||||
{name => 'rstryHostName', optional => true},
|
||||
);
|
||||
|
||||
$self->{host}{$oHost->{strName}} = $oHost;
|
||||
|
||||
if ($oHost->hostUpdateGet())
|
||||
{
|
||||
$oHost->executeSimple("echo \"\" >> /etc/hosts", undef, 'root', {bLoadEnv => false});
|
||||
$oHost->executeSimple("echo \"# Test Hosts\" >> /etc/hosts", undef, 'root', {bLoadEnv => false});
|
||||
}
|
||||
|
||||
my $strHostList = $oHost->{strName} . (defined($rstryHostName) ? ' ' . join(' ', @{$rstryHostName}) : '');
|
||||
|
||||
# Iterate hosts to add IP mappings
|
||||
foreach my $strOtherHostName (sort(keys(%{$self->{host}})))
|
||||
{
|
||||
my $oOtherHost = $self->{host}{$strOtherHostName};
|
||||
|
||||
if ($strOtherHostName ne $oHost->{strName})
|
||||
{
|
||||
# Add this host IP to all hosts
|
||||
if ($oOtherHost->hostUpdateGet())
|
||||
{
|
||||
$oOtherHost->executeSimple(
|
||||
"echo \"$oHost->{strIP} ${strHostList}\" >> /etc/hosts", undef, 'root', {bLoadEnv => false});
|
||||
}
|
||||
|
||||
# Add all other host IPs to this host
|
||||
if ($oHost->hostUpdateGet())
|
||||
{
|
||||
$oHost->executeSimple(
|
||||
"echo \"$oOtherHost->{strIP} ${strOtherHostName}\" >> /etc/hosts", undef, 'root', {bLoadEnv => false});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Return from function and log return values if any
|
||||
return logDebugReturn($strOperation);
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# hostGet
|
||||
####################################################################################################################################
|
||||
sub hostGet
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Assign function parameters, defaults, and log debug info
|
||||
my
|
||||
(
|
||||
$strOperation,
|
||||
$strName,
|
||||
$bIgnoreMissing,
|
||||
) =
|
||||
logDebugParam
|
||||
(
|
||||
__PACKAGE__ . '->hostGet', \@_,
|
||||
{name => 'strName', trace => true},
|
||||
{name => 'bIgnoreMissing', default => false, trace => true},
|
||||
);
|
||||
|
||||
my $oHost = $self->{host}{$strName};
|
||||
|
||||
if (!defined($oHost) && !$bIgnoreMissing)
|
||||
{
|
||||
confess &log(ERROR, "host ${strName} does not exist");
|
||||
}
|
||||
|
||||
# Return from function and log return values if any
|
||||
return logDebugReturn
|
||||
(
|
||||
$strOperation,
|
||||
{name => 'oHost', value => $oHost}
|
||||
);
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# removeAll
|
||||
####################################################################################################################################
|
||||
sub removeAll
|
||||
{
|
||||
my $self = shift;
|
||||
|
||||
# Assign function parameters, defaults, and log debug info
|
||||
my ($strOperation) = logDebugParam(__PACKAGE__ . '->removeAll');
|
||||
|
||||
my $iTotal = 0;
|
||||
|
||||
foreach my $strHostName (sort(keys(%{$self->{host}})))
|
||||
{
|
||||
${$self->{host}}{$strHostName}->remove();
|
||||
delete($self->{host}{$strHostName});
|
||||
|
||||
$iTotal++;
|
||||
}
|
||||
|
||||
# Return from function and log return values if any
|
||||
return logDebugReturn
|
||||
(
|
||||
$strOperation,
|
||||
{name => 'iTotal', value => $iTotal}
|
||||
);
|
||||
}
|
||||
|
||||
####################################################################################################################################
|
||||
# hostGroupGet
|
||||
#
|
||||
# Get the global host group object.
|
||||
####################################################################################################################################
|
||||
sub hostGroupGet
|
||||
{
|
||||
if (!defined($oHostGroup))
|
||||
{
|
||||
$oHostGroup = new pgBackRestDoc::Common::HostGroup();
|
||||
}
|
||||
|
||||
return $oHostGroup;
|
||||
}
|
||||
|
||||
push @EXPORT, qw(hostGroupGet);
|
||||
|
||||
1;
|
Reference in New Issue
Block a user