diff --git a/test/lib/pgBackRestTest/Common/LogTest.pm b/test/lib/pgBackRestTest/Common/LogTest.pm index 122406e6f..26309575d 100644 --- a/test/lib/pgBackRestTest/Common/LogTest.pm +++ b/test/lib/pgBackRestTest/Common/LogTest.pm @@ -222,7 +222,7 @@ sub logWrite if (!-e $strTestLogPath) { - mkdir($strTestLogPath) or + mkdir($strTestLogPath, 0750) or confess "unable to create expect log path ${strTestLogPath}"; } diff --git a/test/lib/pgBackRestTest/CommonTest.pm b/test/lib/pgBackRestTest/CommonTest.pm index d91309fa3..ac537a4f0 100755 --- a/test/lib/pgBackRestTest/CommonTest.pm +++ b/test/lib/pgBackRestTest/CommonTest.pm @@ -143,8 +143,8 @@ sub BackRestTestCommon_Drop # Remove the backrest private directory BackRestTestCommon_DropRepo(); - # Remove the test directory - BackRestTestCommon_PathRemove(BackRestTestCommon_TestPathGet()); + # Remove contents of the test directory + executeTest('rm -rf ' . BackRestTestCommon_TestPathGet() . '/*'); } #################################################################################################################################### @@ -152,8 +152,8 @@ sub BackRestTestCommon_Drop #################################################################################################################################### sub BackRestTestCommon_Create { - # Create the test directory - BackRestTestCommon_PathCreate(BackRestTestCommon_TestPathGet(), '0770'); + # Test directory is now created in parent VM so nothing to do here. Leaving as a place holder for a while in case any other + # test init needs to be done when refactoring. } #################################################################################################################################### diff --git a/test/lib/pgBackRestTest/Docker/ContainerTest.pm b/test/lib/pgBackRestTest/Docker/ContainerTest.pm index e9a458450..9513ec7cb 100755 --- a/test/lib/pgBackRestTest/Docker/ContainerTest.pm +++ b/test/lib/pgBackRestTest/Docker/ContainerTest.pm @@ -19,6 +19,7 @@ use Scalar::Util qw(blessed); use pgBackRest::Common::Ini; use pgBackRest::Common::Log; +use pgBackRest::Common::String; use pgBackRest::FileCommon; use pgBackRestTest::Common::ExecuteTest; @@ -120,7 +121,7 @@ sub containerWrite my $bForce = shift; # Write the image - fileStringWrite("${strTempPath}/${strImageName}", "$strImage\n", false); + fileStringWrite("${strTempPath}/${strImageName}", trim($strImage) . "\n", false); executeTest('docker build' . (defined($bForce) && $bForce ? ' --no-cache' : '') . " -f ${strTempPath}/${strImageName} -t backrest/${strImageName} ${strTempPath}", {bSuppressStdErr => true}); @@ -500,7 +501,7 @@ sub containerBuild # Install Perl packages $strImage .= - "\n\n" . perlInstall($strOS) . "\n"; + "\n\n" . perlInstall($strOS); # Make PostgreSQL home group readable $strImage .= diff --git a/test/lib/pgBackRestTest/FileTest.pm b/test/lib/pgBackRestTest/FileTest.pm index 8ab66e949..e2b5d599e 100755 --- a/test/lib/pgBackRestTest/FileTest.pm +++ b/test/lib/pgBackRestTest/FileTest.pm @@ -47,14 +47,11 @@ sub BackRestTestFile_Setup system("ssh ${strUserBackRest}\@${strHost} 'rm -rf ${strTestPath}/private'"); } - # Remove the test directory - system("rm -rf ${strTestPath}") == 0 or die 'unable to drop test path'; + # Remove contents of the test directory + system("rm -rf ${strTestPath}/*") == 0 or die 'unable to drop test path'; if (!defined($bDropOnly) || !$bDropOnly) { - # Create the test directory - mkdir($strTestPath, oct('0770')) or confess 'Unable to create test directory'; - # Create the backrest private directory if (defined($bPrivate) && $bPrivate) { @@ -102,8 +99,7 @@ sub BackRestTestFile_Test #------------------------------------------------------------------------------------------------------------------------------- # Create remotes #------------------------------------------------------------------------------------------------------------------------------- - mkdir($strTestPath, oct('0770')) or confess 'Unable to create test directory'; - mkdir($strTestPath . '/backrest', oct('0770')) or confess 'Unable to create test directory'; + mkdir($strTestPath . '/backrest', oct('0770')) or confess 'Unable to create backrest directory'; my $oRemote = new pgBackRest::Protocol::RemoteMaster ( diff --git a/test/test.pl b/test/test.pl index e3a55b39f..4bbfd6c6a 100755 --- a/test/test.pl +++ b/test/test.pl @@ -27,6 +27,7 @@ use pgBackRest::Common::Log; use pgBackRest::Common::String; use pgBackRest::Common::Wait; use pgBackRest::Db; +use pgBackRest::FileCommon; use pgBackRest::Version; use lib dirname($0) . '/lib'; @@ -190,6 +191,12 @@ if (defined($iThreadMax) && ($iThreadMax < 1 || $iThreadMax > 32)) confess 'thread-max must be between 1 and 32'; } +# Set test path if not expicitly set +if (!defined($strTestPath)) +{ + $strTestPath = cwd() . '/test'; +} + #################################################################################################################################### # Build Docker containers #################################################################################################################################### @@ -485,6 +492,9 @@ eval push(@{$oyProcess}, undef); executeTest("docker rm -f test-${iProcessIdx}", {bSuppressError => true}); } + + executeTest("sudo rm -rf ${strTestPath}/*"); + filePathCreate($strTestPath); } if ($bDryRun) @@ -539,7 +549,11 @@ eval if (!$bNoCleanup) { - executeTest("docker rm -f test-${iProcessIdx}"); + my $strImage = 'test-' . $iProcessIdx; + my $strHostTestPath = "${strTestPath}/${strImage}"; + + executeTest("docker rm -f ${strImage}"); + executeTest("sudo rm -rf ${strHostTestPath}"); } $$oyProcess[$iProcessIdx] = undef; @@ -579,12 +593,22 @@ eval &log($bDryRun && !$bVmOut || $bShowOutputAsync ? INFO : DEBUG, "${strTest}" . ($bVmOut || $bShowOutputAsync ? "\n" : '')); + my $strVmTestPath = "/home/vagrant/test/${strImage}"; + my $strHostTestPath = "${strTestPath}/${strImage}"; + + # Don't create the container if this is a dry run unless output from the VM is required. Ouput can be requested + # to get more information about the specific tests that will be run. if (!$bDryRun || $bVmOut) { + # Create host test directory + filePathCreate($strHostTestPath, '0770'); + executeTest("docker run -itd -h $$oTest{os}-test --name=${strImage}" . + " -v ${strHostTestPath}:${strVmTestPath}" . " -v /backrest:/backrest backrest/$$oTest{os}-test-${strDbVersion}"); } + # Build up command line for the individual test $strCommandLine =~ s/\-\-os\=\S*//g; $strCommandLine =~ s/\-\-test-path\=\S*//g; $strCommandLine =~ s/\-\-module\=\S*//g; @@ -592,19 +616,25 @@ eval $strCommandLine =~ s/\-\-run\=\S*//g; $strCommandLine =~ s/\-\-db\-version\=\S*//g; - my $strCommand = "docker exec -i -u vagrant ${strImage} $0 ${strCommandLine} --test-path=/home/vagrant/test" . - " --vm=none --module=$$oTest{module} --test=$$oTest{test}" . - (defined($$oTest{run}) ? " --run=$$oTest{run}" : '') . - (defined($$oTest{thread}) ? " --thread-max=$$oTest{thread}" : '') . - (defined($$oTest{db}) ? " --db-version=$$oTest{db}" : '') . - ($bDryRun ? " --dry-run" : '') . - " --no-cleanup --vm-out"; + my $strCommand = + "docker exec -i -u vagrant ${strImage} $0 ${strCommandLine} --test-path=${strVmTestPath}" . + " --vm=none --module=$$oTest{module} --test=$$oTest{test}" . + (defined($$oTest{run}) ? " --run=$$oTest{run}" : '') . + (defined($$oTest{thread}) ? " --thread-max=$$oTest{thread}" : '') . + (defined($$oTest{db}) ? " --db-version=$$oTest{db}" : '') . + ($bDryRun ? " --dry-run" : '') . + " --no-cleanup --vm-out"; &log(DEBUG, $strCommand); if (!$bDryRun || $bVmOut) { my $fTestStartTime = gettimeofday(); + + # Set permissions on the Docker test directory. This can be removed once users/groups are sync'd between + # Docker and the host VM. + executeTest("docker exec ${strImage} chown vagrant:postgres -R ${strVmTestPath}"); + my $oExec = new pgBackRestTest::Common::ExecuteTest( $strCommand, {bSuppressError => true, bShowOutputAsync => $bShowOutputAsync});