mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2026-06-20 01:17:49 +02:00
Regression tests can now be run as any properly-configured user, not just vagrant.
This commit is contained in:
@@ -41,6 +41,7 @@ use pgBackRestTest::Backup::Common::HostBackupTest;
|
||||
use pgBackRestTest::Backup::Common::HostBaseTest;
|
||||
use pgBackRestTest::Backup::Common::HostDbTest;
|
||||
use pgBackRestTest::Backup::Common::HostDbSyntheticTest;
|
||||
use pgBackRestTest::Common::ContainerTest;
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
use pgBackRestTest::Common::FileTest;
|
||||
use pgBackRestTest::Common::HostGroupTest;
|
||||
@@ -1105,7 +1106,7 @@ sub backupTestRun
|
||||
# Fix permissions on the restore log & remove lock files
|
||||
if ($bNeutralTest && !$bRemote)
|
||||
{
|
||||
executeTest('sudo chown -R vagrant:postgres ' . $oHostBackup->logPath());
|
||||
executeTest('sudo chown -R ' . TEST_USER . ':' . POSTGRES_GROUP . ' ' . $oHostBackup->logPath());
|
||||
executeTest('sudo rm -rf ' . $oHostDbMaster->lockPath() . '/*');
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ use pgBackRest::Manifest;
|
||||
use pgBackRest::Version;
|
||||
|
||||
use pgBackRestTest::Backup::Common::HostBaseTest;
|
||||
use pgBackRestTest::Common::ContainerTest;
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
use pgBackRestTest::Common::HostGroupTest;
|
||||
use pgBackRestTest::CommonTest;
|
||||
@@ -103,7 +104,7 @@ sub new
|
||||
if (!defined($$oParam{strName}) || $$oParam{strName} eq HOST_BACKUP)
|
||||
{
|
||||
$strName = HOST_BACKUP;
|
||||
$strImage = 'backrest/' . $oHostGroup->paramGet(HOST_PARAM_VM) . '-backup-test-pre';
|
||||
$strImage = containerNamespace() . '/' . $oHostGroup->paramGet(HOST_PARAM_VM) . '-backup-test-pre';
|
||||
$strUser = $oHostGroup->paramGet(HOST_BACKUP_USER);
|
||||
$strVm = $oHostGroup->paramGet(HOST_PARAM_VM);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ use pgBackRest::Common::Log;
|
||||
use pgBackRest::FileCommon;
|
||||
use pgBackRest::Version;
|
||||
|
||||
use pgBackRestTest::Common::ContainerTest;
|
||||
use pgBackRestTest::Common::HostGroupTest;
|
||||
|
||||
####################################################################################################################################
|
||||
@@ -83,7 +84,7 @@ sub new
|
||||
$self->paramSet(HOST_PARAM_TEST_PATH, $strTestPath);
|
||||
|
||||
# Set permissions on the test path
|
||||
$self->executeSimple('chown -R ' . $self->userGet() . ':postgres ' . $self->testPath(), undef, 'root');
|
||||
$self->executeSimple('chown -R ' . $self->userGet() . ':'. POSTGRES_GROUP . ' ' . $self->testPath(), undef, 'root');
|
||||
|
||||
# Return from function and log return values if any
|
||||
return logDebugReturn
|
||||
|
||||
@@ -30,6 +30,7 @@ use pgBackRest::Version;
|
||||
use pgBackRestTest::Backup::Common::HostBackupTest;
|
||||
use pgBackRestTest::Backup::Common::HostBaseTest;
|
||||
use pgBackRestTest::Backup::Common::HostDbCommonTest;
|
||||
use pgBackRestTest::Common::ContainerTest;
|
||||
use pgBackRestTest::Common::FileTest;
|
||||
use pgBackRestTest::Common::HostGroupTest;
|
||||
use pgBackRestTest::CommonTest;
|
||||
@@ -58,7 +59,7 @@ sub new
|
||||
|
||||
my $self = $class->SUPER::new(
|
||||
{
|
||||
strImage => 'backrest/' . $oHostGroup->paramGet(HOST_PARAM_VM) . "-db-test-pre",
|
||||
strImage => containerNamespace() . '/' . $oHostGroup->paramGet(HOST_PARAM_VM) . "-db-test-pre",
|
||||
strBackupDestination => $$oParam{strBackupDestination},
|
||||
oLogTest => $$oParam{oLogTest},
|
||||
bSynthetic => true,
|
||||
|
||||
@@ -28,6 +28,7 @@ use pgBackRest::Version;
|
||||
use pgBackRestTest::Backup::Common::HostBackupTest;
|
||||
use pgBackRestTest::Backup::Common::HostBaseTest;
|
||||
use pgBackRestTest::Backup::Common::HostDbCommonTest;
|
||||
use pgBackRestTest::Common::ContainerTest;
|
||||
use pgBackRestTest::Common::HostGroupTest;
|
||||
|
||||
####################################################################################################################################
|
||||
@@ -81,7 +82,7 @@ sub new
|
||||
|
||||
my $self = $class->SUPER::new(
|
||||
{
|
||||
strImage => 'backrest/' . $oHostGroup->paramGet(HOST_PARAM_VM) . "-db-${strDbVersion}-test-pre",
|
||||
strImage => containerNamespace() . '/' . $oHostGroup->paramGet(HOST_PARAM_VM) . "-db-${strDbVersion}-test-pre",
|
||||
strBackupDestination => $$oParam{strBackupDestination},
|
||||
oLogTest => $$oParam{oLogTest},
|
||||
bStandby => $$oParam{bStandby},
|
||||
|
||||
@@ -9,6 +9,7 @@ package pgBackRestTest::Common::ContainerTest;
|
||||
use strict;
|
||||
use warnings FATAL => qw(all);
|
||||
use Carp qw(confess longmess);
|
||||
use English '-no_match_vars';
|
||||
|
||||
use Cwd qw(abs_path);
|
||||
use Exporter qw(import);
|
||||
@@ -20,6 +21,7 @@ use pgBackRest::Common::Ini;
|
||||
use pgBackRest::Common::Log;
|
||||
use pgBackRest::Common::String;
|
||||
use pgBackRest::FileCommon;
|
||||
use pgBackRest::Version;
|
||||
|
||||
use pgBackRestTest::Common::ExecuteTest;
|
||||
use pgBackRestTest::Common::VmTest;
|
||||
@@ -28,20 +30,32 @@ use pgBackRestTest::Common::VmTest;
|
||||
# User/group definitions
|
||||
####################################################################################################################################
|
||||
use constant POSTGRES_GROUP => 'postgres';
|
||||
push @EXPORT, qw(POSTGRES_GROUP);
|
||||
use constant POSTGRES_GROUP_ID => getgrnam(POSTGRES_GROUP) . '';
|
||||
use constant POSTGRES_USER => POSTGRES_GROUP;
|
||||
use constant POSTGRES_USER_ID => POSTGRES_GROUP_ID;
|
||||
|
||||
use constant TEST_GROUP => POSTGRES_GROUP;
|
||||
use constant TEST_GROUP_ID => POSTGRES_GROUP_ID;
|
||||
use constant TEST_USER => 'vagrant';
|
||||
use constant TEST_USER_ID => getpwnam(TEST_USER) . '';
|
||||
use constant TEST_USER => getpwuid($UID) . '';
|
||||
push @EXPORT, qw(TEST_USER);
|
||||
use constant TEST_USER_ID => $UID;
|
||||
|
||||
use constant BACKREST_GROUP => POSTGRES_GROUP;
|
||||
use constant BACKREST_GROUP_ID => POSTGRES_GROUP_ID;
|
||||
use constant BACKREST_USER => 'backrest';
|
||||
use constant BACKREST_USER_ID => getpwnam(BACKREST_USER) . '';
|
||||
|
||||
####################################################################################################################################
|
||||
# Container namespace
|
||||
####################################################################################################################################
|
||||
sub containerNamespace
|
||||
{
|
||||
return BACKREST_EXE . qw(/) . TEST_USER;
|
||||
}
|
||||
|
||||
push @EXPORT, qw(containerNamespace);
|
||||
|
||||
####################################################################################################################################
|
||||
# User/group creation
|
||||
####################################################################################################################################
|
||||
@@ -155,7 +169,7 @@ sub containerWrite
|
||||
# Write the image
|
||||
fileStringWrite("${strTempPath}/${strImage}", trim($strScript) . "\n", false);
|
||||
executeTest('docker build' . (defined($bForce) && $bForce ? ' --no-cache' : '') .
|
||||
" -f ${strTempPath}/${strImage} -t backrest/${strImage} ${strTempPath}",
|
||||
" -f ${strTempPath}/${strImage} -t " . containerNamespace() . "/${strImage} ${strTempPath}",
|
||||
{bSuppressStdErr => true});
|
||||
}
|
||||
|
||||
@@ -291,7 +305,7 @@ sub containerBuild
|
||||
# Remove old images on force
|
||||
if ($bVmForce)
|
||||
{
|
||||
my $strRegExp = '^backrest\/';
|
||||
my $strRegExp = '^' . containerNamespace() . '/';
|
||||
|
||||
if ($strVm ne 'all')
|
||||
{
|
||||
@@ -433,7 +447,7 @@ sub containerBuild
|
||||
|
||||
# Base pre image
|
||||
###########################################################################################################################
|
||||
$strImageParent = "backrest/${strOS}-base";
|
||||
$strImageParent = containerNamespace() . "/${strOS}-base";
|
||||
$strImage = "${strOS}-base-pre";
|
||||
|
||||
# Install Perl packages
|
||||
@@ -477,7 +491,7 @@ sub containerBuild
|
||||
|
||||
my $bDocBuildVersion = ($bDocBuild && grep(/^$strDbVersion$/, @{$$oOS{&VM_DB_DOC}}));
|
||||
|
||||
$strImageParent = "backrest/${strOS}-base";
|
||||
$strImageParent = containerNamespace() . "/${strOS}-base";
|
||||
$strImage = "${strOS}-db-${strDbVersion}";
|
||||
|
||||
# Create PostgreSQL User
|
||||
@@ -507,7 +521,7 @@ sub containerBuild
|
||||
########################################################################################################################
|
||||
if ($bDocBuildVersion)
|
||||
{
|
||||
$strImageParent = "backrest/${strOS}-db-${strDbVersion}";
|
||||
$strImageParent = containerNamespace() . "/${strOS}-db-${strDbVersion}";
|
||||
$strImage = "${strOS}-db-${strDbVersion}-doc";
|
||||
|
||||
# Install SSH key
|
||||
@@ -522,7 +536,7 @@ sub containerBuild
|
||||
|
||||
# Db test image
|
||||
########################################################################################################################
|
||||
$strImageParent = "backrest/${strOS}-db-${strDbVersion}";
|
||||
$strImageParent = containerNamespace() . "/${strOS}-db-${strDbVersion}";
|
||||
$strImage = "${strOS}-db-${strDbVersion}-test";
|
||||
|
||||
# Install SSH key
|
||||
@@ -534,7 +548,7 @@ sub containerBuild
|
||||
|
||||
# Db test image (for sythetic tests)
|
||||
########################################################################################################################
|
||||
$strImageParent = "backrest/${strOS}-base";
|
||||
$strImageParent = containerNamespace() . "/${strOS}-base";
|
||||
$strImage = "${strOS}-db-test";
|
||||
|
||||
# Install SSH key
|
||||
@@ -545,7 +559,7 @@ sub containerBuild
|
||||
|
||||
# Loop test image
|
||||
########################################################################################################################
|
||||
$strImageParent = "backrest/${strOS}-base";
|
||||
$strImageParent = containerNamespace() . "/${strOS}-base";
|
||||
$strImage = "${strOS}-loop-test";
|
||||
|
||||
# Create BackRest User
|
||||
@@ -569,7 +583,7 @@ sub containerBuild
|
||||
|
||||
# Backup image
|
||||
###########################################################################################################################
|
||||
$strImageParent = "backrest/${strOS}-base";
|
||||
$strImageParent = containerNamespace() . "/${strOS}-base";
|
||||
$strImage = "${strOS}-backup";
|
||||
my $strTitle = "Backup";
|
||||
|
||||
@@ -588,7 +602,7 @@ sub containerBuild
|
||||
###########################################################################################################################
|
||||
if ($bDocBuild)
|
||||
{
|
||||
$strImageParent = "backrest/${strOS}-backup";
|
||||
$strImageParent = containerNamespace() . "/${strOS}-backup";
|
||||
$strImage = "${strOS}-backup-doc";
|
||||
|
||||
# Create configuration file
|
||||
@@ -607,7 +621,7 @@ sub containerBuild
|
||||
|
||||
# Backup Test image
|
||||
###########################################################################################################################
|
||||
$strImageParent = "backrest/${strOS}-backup";
|
||||
$strImageParent = containerNamespace() . "/${strOS}-backup";
|
||||
$strImage = "${strOS}-backup-test";
|
||||
|
||||
# Make test user home readable
|
||||
@@ -640,6 +654,8 @@ sub containerRemove
|
||||
}
|
||||
}
|
||||
|
||||
push @EXPORT, qw(containerRemove);
|
||||
|
||||
####################################################################################################################################
|
||||
# imageRemove
|
||||
#
|
||||
@@ -659,6 +675,4 @@ sub imageRemove
|
||||
}
|
||||
}
|
||||
|
||||
push @EXPORT, qw(containerRemove);
|
||||
|
||||
1;
|
||||
|
||||
@@ -348,9 +348,16 @@ sub regExpReplaceAll
|
||||
|
||||
$strLine = $self->regExpReplace($strLine, 'GROUP', 'strGroup = [^ \n,\[\]]+', '[^ \n,\[\]]+$');
|
||||
$strLine = $self->regExpReplace($strLine, 'GROUP', 'group"[ ]{0,1}:[ ]{0,1}"[^"]+', '[^"]+$');
|
||||
|
||||
$strLine = $self->regExpReplace($strLine, 'USER', 'strUser = [^ \n,\[\]]+', '[^ \n,\[\]]+$');
|
||||
$strLine = $self->regExpReplace($strLine, 'USER', 'user"[ ]{0,1}:[ ]{0,1}"[^"]+', '[^"]+$');
|
||||
$strLine = $self->regExpReplace($strLine, 'USER', 'user=\"[^"]+', '[^"]+$');
|
||||
$strLine = $self->regExpReplace($strLine, 'USER', '^db-user=.+$', '[^=]+$');
|
||||
$strLine = $self->regExpReplace($strLine, 'USER', 'was not mapped to a name\, set to .+$', '[^ ]+$');
|
||||
$strLine = $self->regExpReplace($strLine, 'USER', 'set ownership [^\:]+', '[^ ]+$');
|
||||
$strLine = $self->regExpReplace($strLine, 'USER', 'cannot be used for restore\, set to .+$', '[^ ]+$');
|
||||
$strLine = $self->regExpReplace($strLine, 'USER', '-user=[a-z0-9_]+', '[^=]+$');
|
||||
$strLine = $self->regExpReplace($strLine, 'USER', '[^ ]+\@db\-master', '^[^\@]+');
|
||||
|
||||
$strLine = $self->regExpReplace($strLine, 'PORT', 'db-port=[0-9]+', '[0-9]+$');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user