From 0f88943b7b2e142d86d3a03755a41a1b31754338 Mon Sep 17 00:00:00 2001 From: David Steele Date: Sun, 10 Jan 2016 19:30:51 -0500 Subject: [PATCH] Database versions are now run as separate tests. --- test/lib/BackRestTest/Common/VmTest.pm | 65 ++++++++++ .../Docker/{Container.pm => ContainerTest.pm} | 100 +++++--------- test/test.pl | 122 +++++++++++------- 3 files changed, 170 insertions(+), 117 deletions(-) create mode 100644 test/lib/BackRestTest/Common/VmTest.pm rename test/lib/BackRestTest/Docker/{Container.pm => ContainerTest.pm} (83%) diff --git a/test/lib/BackRestTest/Common/VmTest.pm b/test/lib/BackRestTest/Common/VmTest.pm new file mode 100644 index 000000000..a36bece38 --- /dev/null +++ b/test/lib/BackRestTest/Common/VmTest.pm @@ -0,0 +1,65 @@ +#################################################################################################################################### +# VmTest.pm - Vm constants and data +#################################################################################################################################### +package BackRestTest::Common::VmTest; + +#################################################################################################################################### +# Perl includes +#################################################################################################################################### +use strict; +use warnings FATAL => qw(all); +use Carp qw(confess); + +use Exporter qw(import); + our @EXPORT = qw(); + +#################################################################################################################################### +# Valid OS list +#################################################################################################################################### +use constant OS_CO6 => 'co6'; + push @EXPORT, qw(OS_CO6); +use constant OS_CO7 => 'co7'; + push @EXPORT, qw(OS_CO7); +use constant OS_U12 => 'u12'; + push @EXPORT, qw(OS_U12); +use constant OS_U14 => 'u14'; + push @EXPORT, qw(OS_U14); + +my $oyVm = +{ + # CentOS 6 + &OS_CO6 => + { + db => ['9.0', '9.1', '9.2', '9.3', '9.4', '9.5'] + }, + + # CentOS 7 + &OS_CO7 => + { + db => ['9.3', '9.4', '9.5'] + }, + + # Ubuntu 12.04 + &OS_U12 => + { + db => ['8.4', '9.0', '9.1', '9.2', '9.3', '9.4', '9.5'] + }, + + # Ubuntu 14.04 + &OS_U14 => + { + db => ['9.0', '9.1', '9.2', '9.3', '9.4', '9.5'] + } +}; + +#################################################################################################################################### +# vmGet +#################################################################################################################################### +sub vmGet +{ + return $oyVm; +} + +push @EXPORT, qw(vmGet); + +1; diff --git a/test/lib/BackRestTest/Docker/Container.pm b/test/lib/BackRestTest/Docker/ContainerTest.pm similarity index 83% rename from test/lib/BackRestTest/Docker/Container.pm rename to test/lib/BackRestTest/Docker/ContainerTest.pm index a47b7b4c9..1942ac09d 100755 --- a/test/lib/BackRestTest/Docker/Container.pm +++ b/test/lib/BackRestTest/Docker/ContainerTest.pm @@ -1,7 +1,7 @@ #################################################################################################################################### -# Container.pm - Build docker containers for testing and documentation +# ContainerTest.pm - Build docker containers for testing and documentation #################################################################################################################################### -package BackRestTest::Docker::Container; +package BackRestTest::Docker::ContainerTest; #################################################################################################################################### # Perl includes @@ -22,22 +22,7 @@ use BackRest::Common::Log; use BackRest::FileCommon; use BackRestTest::Common::ExecuteTest; - -#################################################################################################################################### -# Valid OS list -#################################################################################################################################### -use constant OS_CO6 => 'co6'; -use constant OS_CO7 => 'co7'; -use constant OS_U12 => 'u12'; -use constant OS_U14 => 'u14'; - -my @stryOS = -( - OS_CO6, # CentOS 6 - OS_CO7, # CentOS 7 - OS_U12, # Ubuntu 12.04 - OS_U14 # Ubuntu 14.04 -); +use BackRestTest::Common::VmTest; use constant TEST_GROUP => 'admin'; use constant TEST_GROUP_ID => 1000; @@ -214,8 +199,11 @@ sub containerBuild executeTest("ssh-keygen -f ${strTempPath}/id_rsa -t rsa -b 768 -N ''", {bSuppressStdErr => true}); } - foreach my $strOS (@stryOS) + my $oyVm = vmGet(); + + foreach my $strOS (sort(keys(%$oyVm))) { + my $oOS = $$oyVm{$strOS}; my $strImage; my $strImageName; @@ -378,58 +366,31 @@ sub containerBuild # Install PostgreSQL $strImage .= - "\n\n# Install PostgreSQL\n"; + "\n\n# Install PostgreSQL"; - if ($strOS eq OS_CO6) + foreach my $strDbVersion (@{$$oOS{db}}) { - $strImage .= - "RUN yum -y install postgresql90-server\n" . - "RUN yum -y install postgresql91-server\n" . - "RUN yum -y install postgresql92-server\n" . - "RUN yum -y install postgresql93-server\n" . - "RUN yum -y install postgresql94-server\n" . - "RUN yum -y install postgresql95-server"; - } - elsif ($strOS eq OS_CO7) - { - $strImage .= - "RUN yum -y install postgresql93-server\n" . - "RUN yum -y install postgresql94-server\n" . - "RUN yum -y install postgresql95-server"; - } - elsif ($strOS eq OS_U12) - { - $strImage .= - "RUN apt-get install -y postgresql-9.5\n" . - "RUN pg_dropcluster --stop 9.5 main\n" . - "RUN apt-get install -y postgresql-9.4\n" . - "RUN pg_dropcluster --stop 9.4 main\n" . - "RUN apt-get install -y postgresql-9.3\n" . - "RUN pg_dropcluster --stop 9.3 main\n" . - "RUN apt-get install -y postgresql-9.2\n" . - "RUN pg_dropcluster --stop 9.2 main\n" . - "RUN apt-get install -y postgresql-9.1\n" . - "RUN pg_dropcluster --stop 9.1 main\n" . - "RUN apt-get install -y postgresql-9.0\n" . - "RUN pg_dropcluster --stop 9.0 main\n" . - "RUN apt-get install -y postgresql-8.4\n" . - "RUN pg_dropcluster --stop 8.4 main"; - } - elsif ($strOS eq OS_U14) - { - $strImage .= - "RUN apt-get install -y postgresql-9.5\n" . - "RUN pg_dropcluster --stop 9.5 main\n" . - "RUN apt-get install -y postgresql-9.4\n" . - "RUN pg_dropcluster --stop 9.4 main\n" . - "RUN apt-get install -y postgresql-9.3\n" . - "RUN pg_dropcluster --stop 9.3 main\n" . - "RUN apt-get install -y postgresql-9.2\n" . - "RUN pg_dropcluster --stop 9.2 main\n" . - "RUN apt-get install -y postgresql-9.1\n" . - "RUN pg_dropcluster --stop 9.1 main\n" . - "RUN apt-get install -y postgresql-9.0\n" . - "RUN pg_dropcluster --stop 9.0 main"; + if ($strOS eq OS_CO6 || $strOS eq OS_CO7) + { + $strDbVersion =~ s/\.//; + } + + if ($strOS eq OS_CO6) + { + $strImage .= + "\nRUN yum -y install postgresql${strDbVersion}-server"; + } + elsif ($strOS eq OS_CO7) + { + $strImage .= + "\nRUN yum -y install postgresql${strDbVersion}-server"; + } + elsif ($strOS eq OS_U12 || $strOS eq OS_U14) + { + $strImage .= + "\nRUN apt-get install -y postgresql-${strDbVersion}" . + "\nRUN pg_dropcluster --stop ${strDbVersion} main"; + } } # Write the image @@ -437,7 +398,6 @@ sub containerBuild executeTest("docker build -f ${strTempPath}/${strImageName} -t backrest/${strImageName} ${strTempPath}", {bSuppressStdErr => true}); - # Db Doc image ########################################################################################################################### $strImageName = "${strOS}-db-doc"; diff --git a/test/test.pl b/test/test.pl index 537db9fa5..cf8ff2588 100755 --- a/test/test.pl +++ b/test/test.pl @@ -31,10 +31,11 @@ use BackRest::Db; use lib dirname($0) . '/lib'; use BackRestTest::BackupTest; use BackRestTest::Common::ExecuteTest; +use BackRestTest::Common::VmTest; use BackRestTest::CommonTest; use BackRestTest::CompareTest; use BackRestTest::ConfigTest; -use BackRestTest::Docker::Container; +use BackRestTest::Docker::ContainerTest; use BackRestTest::FileTest; use BackRestTest::HelpTest; @@ -316,7 +317,8 @@ eval { name => 'full', total => 8, - thread => true + thread => true, + db => true } ] } @@ -330,66 +332,89 @@ eval ################################################################################################################################ if ($strOS ne 'none') { + my $oyVm = vmGet(); + + if ($strOS ne 'all' && !defined($${oyVm}{$strOS})) + { + confess &log(ERROR, "${strOS} is not a valid VM"); + } + # Determine which tests to run my $iTestsToRun = 0; - foreach my $oModule (@{$$oTestDefinition{module}}) + my $stryTestOS = []; + + if ($strOS eq 'all') { - if ($strModule eq $$oModule{name} || $strModule eq 'all') + $stryTestOS = ['co6', 'u12', 'co7', 'u14']; + } + else + { + $stryTestOS = [$strOS]; + } + + foreach my $strTestOS (@{$stryTestOS}) + { + foreach my $oModule (@{$$oTestDefinition{module}}) { - &log(DEBUG, "Select Module $$oModule{name}"); - - foreach my $oTest (@{$$oModule{test}}) + if ($strModule eq $$oModule{name} || $strModule eq 'all') { - if ($strModuleTest eq $$oTest{name} || $strModuleTest eq 'all') + foreach my $oTest (@{$$oModule{test}}) { - &log(DEBUG, " Select Test $$oTest{name}"); - - my $iTestRunMin = defined($iModuleTestRun) ? $iModuleTestRun : (defined($$oTest{total}) ? 1 : -1); - my $iTestRunMax = defined($iModuleTestRun) ? $iModuleTestRun : (defined($$oTest{total}) ? $$oTest{total} : -1); - - if (defined($$oTest{total}) && $iTestRunMax > $$oTest{total}) + if ($strModuleTest eq $$oTest{name} || $strModuleTest eq 'all') { - confess &log(ERROR, "invalid run - must be >= 1 and <= $$oTest{total}") - } + my $iDbVersionMin = -1; + my $iDbVersionMax = -1; - for (my $iTestRunIdx = $iTestRunMin; $iTestRunIdx <= $iTestRunMax; $iTestRunIdx++) - { - &log(DEBUG, " Select Run $iTestRunIdx"); - - my $stryTestOS = []; - - if ($strOS eq 'all') + if (defined($$oTest{db}) && $$oTest{db}) { - $stryTestOS = ['u12', 'u14', 'co6', 'co7']; - } - else - { - $stryTestOS = [$strOS]; + $iDbVersionMin = 0; + $iDbVersionMax = @{$$oyVm{$strTestOS}{db}} - 1; } - my $iyThreadMax = [defined($iThreadMax) ? $iThreadMax : 1]; + my $bFirstDbVersion = true; - if (defined($$oTest{thread}) && $$oTest{thread} && !defined($iThreadMax)) + for (my $iDbVersionIdx = $iDbVersionMax; $iDbVersionIdx >= $iDbVersionMin; $iDbVersionIdx--) { - $iyThreadMax = [1, 4]; - } - - foreach my $iThreadTestMax (@{$iyThreadMax}) - { - foreach my $strTestOS (@{$stryTestOS}) + if ($iDbVersionIdx == -1 || $strDbVersion eq 'all' || + ($strDbVersion ne 'all' && $strDbVersion eq ${$$oyVm{$strTestOS}{db}}[$iDbVersionIdx])) { - my $oTestRun = - { - os => $strTestOS, - module => $$oModule{name}, - test => $$oTest{name}, - run => $iTestRunIdx == -1 ? undef : $iTestRunIdx, - thread => $iThreadTestMax - }; + my $iTestRunMin = defined($iModuleTestRun) ? $iModuleTestRun : (defined($$oTest{total}) ? 1 : -1); + my $iTestRunMax = defined($iModuleTestRun) ? $iModuleTestRun : (defined($$oTest{total}) ? $$oTest{total} : -1); - push(@{$oyTestRun}, $oTestRun); - $iTestsToRun++; + if (defined($$oTest{total}) && $iTestRunMax > $$oTest{total}) + { + confess &log(ERROR, "invalid run - must be >= 1 and <= $$oTest{total}") + } + + for (my $iTestRunIdx = $iTestRunMin; $iTestRunIdx <= $iTestRunMax; $iTestRunIdx++) + { + my $iyThreadMax = [defined($iThreadMax) ? $iThreadMax : 1]; + + if (defined($$oTest{thread}) && $$oTest{thread} && + !defined($iThreadMax) && $bFirstDbVersion) + { + $iyThreadMax = [1, 4]; + } + + foreach my $iThreadTestMax (@{$iyThreadMax}) + { + my $oTestRun = + { + os => $strTestOS, + module => $$oModule{name}, + test => $$oTest{name}, + run => $iTestRunIdx == -1 ? undef : $iTestRunIdx, + thread => $iThreadTestMax, + db => $iDbVersionIdx == -1 ? undef : ${$$oyVm{$strTestOS}{db}}[$iDbVersionIdx] + }; + + push(@{$oyTestRun}, $oTestRun); + $iTestsToRun++; + } + } + + $bFirstDbVersion = false; } } } @@ -487,7 +512,8 @@ eval length($iTestMax) . "d - ", $iProcessIdx, $iTestIdx, $iTestMax) . "vm=$$oTest{os}, module=$$oTest{module}, test=$$oTest{test}" . (defined($$oTest{run}) ? ", run=$$oTest{run}" : '') . - (defined($$oTest{thread}) ? ", thread-max=$$oTest{thread}" : ''); + (defined($$oTest{thread}) ? ", thread-max=$$oTest{thread}" : '') . + (defined($$oTest{db}) ? ", db=$$oTest{db}" : ''); my $strImage = 'test-' . $iProcessIdx; @@ -504,11 +530,13 @@ eval $strCommandLine =~ s/\-\-module\=\S*//g; $strCommandLine =~ s/\-\-test\=\S*//g; $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}" : '') . " --no-cleanup"; &log(DEBUG, $strCommand);