1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-03-03 14:52:21 +02:00

Document generator improvements.

* Build containers from scratch for more accurate testing.
* Allow environment load to be skipped.
* Allow bash wrapping to be skipped.
* Allow forcing a command to run as a user without sudo.
This commit is contained in:
David Steele 2018-06-10 14:13:56 -04:00
parent 5c0099781d
commit 835396751f
7 changed files with 519 additions and 191 deletions

View File

@ -154,9 +154,10 @@ sub executeKey
);
# Add user to command
my $bUserForce = $oCommand->paramTest('user-force', 'y') ? true : false;
my $strCommand = $self->{oManifest}->variableReplace(trim($oCommand->fieldGet('exe-cmd')));
my $strUser = $self->{oManifest}->variableReplace($oCommand->paramGet('user', false, 'postgres'));
$strCommand = ($strUser eq DOC_USER ? '' : ('sudo ' . ($strUser eq 'root' ? '' : "-u $strUser "))) . $strCommand;
my $strUser = $self->{oManifest}->variableReplace($oCommand->paramGet('user', false, DOC_USER));
$strCommand = ($strUser eq DOC_USER || $bUserForce ? '' : ('sudo ' . ($strUser eq 'root' ? '' : "-u $strUser "))) . $strCommand;
# Format and split command
$strCommand =~ s/[ ]*\n[ ]*/ \\\n /smg;
@ -170,6 +171,8 @@ sub executeKey
output => JSON::PP::false,
};
$$hCacheKey{'run-as-user'} = $bUserForce ? $strUser : undef;
if (defined($oCommand->fieldGet('exe-cmd-extra', false)))
{
$$hCacheKey{'cmd-extra'} = $oCommand->fieldGet('exe-cmd-extra');
@ -185,6 +188,9 @@ sub executeKey
$$hCacheKey{'output'} = JSON::PP::true;
}
$$hCacheKey{'load-env'} = $oCommand->paramTest('load-env', 'n') ? JSON::PP::false : JSON::PP::true;
$$hCacheKey{'bash-wrap'} = $oCommand->paramTest('bash-wrap', 'n') ? JSON::PP::false : JSON::PP::true;
if (defined($oCommand->fieldGet('exe-highlight', false)))
{
$$hCacheKey{'output'} = JSON::PP::true;
@ -276,7 +282,8 @@ sub execute
$strCommand . (defined($$hCacheKey{'cmd-extra'}) ? ' ' . $$hCacheKey{'cmd-extra'} : ''),
{iExpectedExitStatus => $$hCacheKey{'err-expect'},
bSuppressError => $oCommand->paramTest('err-suppress', 'y'),
iRetrySeconds => $oCommand->paramGet('retry', false)});
iRetrySeconds => $oCommand->paramGet('retry', false)}, $hCacheKey->{'run-as-user'},
{bLoadEnv => $hCacheKey->{'load-env'}, bBashWrap => $hCacheKey->{'bash-wrap'}});
$oExec->begin();
$oExec->end();

View File

@ -63,6 +63,9 @@
<!ATTLIST execute user CDATA "">
<!ATTLIST execute filter CDATA "">
<!ATTLIST execute filter-context CDATA "">
<!ATTLIST execute user-force CDATA "">
<!ATTLIST execute bash-wrap CDATA "">
<!ATTLIST execute load-env CDATA "">
<!ATTLIST execute skip CDATA "">
<!ATTLIST execute show CDATA "">
<!ATTLIST execute output CDATA "">

View File

@ -38,7 +38,11 @@
<release-doc-list>
<release-development-list>
<release-item>
<p>Document generator improvements. Allow parameters to be passed when a container is created. Allow <file>/etc/hosts</file> update to be skipped (for containers without bash).</p>
<p>Build containers from scratch for more accurate testing.</p>
</release-item>
<release-item>
<p>Document generator improvements. Allow parameters to be passed when a container is created. Allow <file>/etc/hosts</file> update to be skipped (for containers without bash). Allow environment load to be skipped. Allow bash wrapping to be skipped. Allow forcing a command to run as a user without sudo.</p>
</release-item>
</release-development-list>
</release-doc-list>

File diff suppressed because it is too large Load Diff

View File

@ -73,8 +73,8 @@ sub hostAdd
if ($bUpdateHosts)
{
$oHost->executeSimple("echo \"\" >> /etc/hosts", undef, 'root');
$oHost->executeSimple("echo \"# Test Hosts\" >> /etc/hosts", undef, 'root');
$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}) : '');
@ -87,12 +87,13 @@ sub hostAdd
if ($strOtherHostName ne $oHost->{strName})
{
# Add this host IP to all hosts
$oOtherHost->executeSimple("echo \"$oHost->{strIP} ${strHostList}\" >> /etc/hosts", undef, 'root');
$oOtherHost->executeSimple("echo \"$oHost->{strIP} ${strHostList}\" >> /etc/hosts", undef, 'root', {bLoadEnv => false});
# Add all other host IPs to this host
if ($bUpdateHosts)
{
$oHost->executeSimple("echo \"$oOtherHost->{strIP} ${strOtherHostName}\" >> /etc/hosts", undef, 'root');
$oHost->executeSimple(
"echo \"$oOtherHost->{strIP} ${strOtherHostName}\" >> /etc/hosts", undef, 'root', {bLoadEnv => false});
}
}
}

View File

@ -109,14 +109,18 @@ sub execute
$strOperation,
$strCommand,
$oParam,
$strUser
$strUser,
$bLoadEnv,
$bBashWrap,
) =
logDebugParam
(
__PACKAGE__ . '->execute', \@_,
{name => 'strCommand'},
{name => 'oParam', required=> false},
{name => 'strUser', required => false}
{name => 'oParam', required => false},
{name => 'strUser', required => false},
{name => 'bLoadEnv', optional => true, default => true},
{name => 'bBashWrap', optional => true, default => true},
);
# Set the user
@ -128,7 +132,8 @@ sub execute
$strCommand =~ s/'/'\\''/g;
my $oExec = new pgBackRestTest::Common::ExecuteTest(
"docker exec -u ${strUser} $self->{strContainer} bash -l -c '${strCommand}'" , $oParam);
"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
@ -151,17 +156,21 @@ sub executeSimple
$strOperation,
$strCommand,
$oParam,
$strUser
$strUser,
$bLoadEnv,
$bBashWrap,
) =
logDebugParam
(
__PACKAGE__ . '->executeSimple', \@_,
{name => 'strCommand', trace => true},
{name => 'oParam', required=> false, trace => true},
{name => 'strUser', 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);
my $oExec = $self->execute($strCommand, $oParam, $strUser, {bLoadEnv => $bLoadEnv});
$oExec->begin();
$oExec->end();

View File

@ -118,14 +118,6 @@ eval
executeTest('sudo apt-get install -y texlive-font-utils latex-xcolor', {bSuppressStdErr => true});
processEnd();
processBegin(VM_CO6 . ' build');
executeTest("${strTestExe} --vm-build --vm=" . VM_CO6, {bShowOutputAsync => true});
processEnd();
processBegin(VM_U16 . ' build');
executeTest("${strTestExe} --vm-build --vm=" . VM_U16, {bShowOutputAsync => true});
processEnd();
processBegin('release documentation doc');
executeTest("${strReleaseExe} --build", {bShowOutputAsync => true});
processEnd();