Modules: chase API change, use std::chrono::seconds

main
Adriaan de Groot 6 years ago
parent e2504627aa
commit a0854a999e

@ -170,7 +170,7 @@ ContextualProcessJob::setConfigurationMap( const QVariantMap& configurationMap )
continue;
}
CalamaresUtils::CommandList* commands = new CalamaresUtils::CommandList( valueiter.value(), !dontChroot, timeout );
CalamaresUtils::CommandList* commands = new CalamaresUtils::CommandList( valueiter.value(), !dontChroot, std::chrono::seconds( timeout ) );
binding->append( valueString, commands );
}

@ -74,8 +74,8 @@ InitcpioJob::exec()
cDebug() << "Updating initramfs with kernel" << m_kernel;
auto r = CalamaresUtils::System::instance()->targetEnvCommand(
{ "mkinitcpio", "-p", m_kernel }, QString(), QString(), 0 );
return r.explainProcess( "mkinitcpio", 10 );
{ "mkinitcpio", "-p", m_kernel }, QString(), QString() /* no timeout , 0 */ );
return r.explainProcess( "mkinitcpio", std::chrono::seconds( 10 ) /* fake timeout */ );
}
void
@ -89,7 +89,7 @@ InitcpioJob::setConfigurationMap( const QVariantMap& configurationMap )
else if ( m_kernel == "$uname" )
{
auto r = CalamaresUtils::System::runCommand(
CalamaresUtils::System::RunLocation::RunInHost, { "/bin/uname", "-r" }, QString(), QString(), 3 );
CalamaresUtils::System::RunLocation::RunInHost, { "/bin/uname", "-r" }, QString(), QString(), std::chrono::seconds( 3 ) );
if ( r.getExitCode() == 0 )
{
m_kernel = r.getOutput();

@ -63,8 +63,8 @@ InitramfsJob::exec()
// And then do the ACTUAL work.
auto r = CalamaresUtils::System::instance()->targetEnvCommand(
{ "update-initramfs", "-k", m_kernel, "-c", "-t" }, QString(), QString(), 0 );
return r.explainProcess( "update-initramfs", 10 );
{ "update-initramfs", "-k", m_kernel, "-c", "-t" }, QString(), QString() /* no timeout, 0 */ );
return r.explainProcess( "update-initramfs", std::chrono::seconds( 10 ) /* fake timeout */ );
}
@ -79,7 +79,7 @@ InitramfsJob::setConfigurationMap( const QVariantMap& configurationMap )
else if ( m_kernel == "$uname" )
{
auto r = CalamaresUtils::System::runCommand(
CalamaresUtils::System::RunLocation::RunInHost, { "/bin/uname", "-r" }, QString(), QString(), 3 );
CalamaresUtils::System::RunLocation::RunInHost, { "/bin/uname", "-r" }, QString(), QString(), std::chrono::seconds( 3 ) );
if ( r.getExitCode() == 0 )
{
m_kernel = r.getOutput();

@ -71,7 +71,7 @@ struct LuksDevice
* Given a list of partitions (as set up by the partitioning module,
* so there's maps with keys inside), returns just the list of
* luks passphrases for each device.
*/
*/
static QList< LuksDevice >
getLuksDevices( const QVariantList& list )
{
@ -130,7 +130,7 @@ static bool
setupLuks( const LuksDevice& d )
{
auto r = CalamaresUtils::System::instance()->targetEnvCommand(
{ "cryptsetup", "luksAddKey", d.device, keyfile }, QString(), d.passphrase, 15 );
{ "cryptsetup", "luksAddKey", d.device, keyfile }, QString(), d.passphrase, std::chrono::seconds( 15 ) );
if ( r.getExitCode() != 0 )
{
cWarning() << "Could not configure LUKS keyfile on" << d.device << ':' << r.getOutput() << "(exit code"

@ -75,7 +75,7 @@ ShellProcessJob::setConfigurationMap( const QVariantMap& configurationMap )
if ( configurationMap.contains( "script" ) )
{
m_commands = new CalamaresUtils::CommandList( configurationMap.value( "script" ), !dontChroot, timeout );
m_commands = new CalamaresUtils::CommandList( configurationMap.value( "script" ), !dontChroot, std::chrono::seconds( timeout ) );
if ( m_commands->isEmpty() )
cDebug() << "ShellProcessJob: \"script\" contains no commands for" << moduleInstanceKey();
}

@ -34,6 +34,8 @@
QTEST_GUILESS_MAIN( ShellProcessTests )
using CommandList = CalamaresUtils::CommandList;
using std::operator""s;
ShellProcessTests::ShellProcessTests()
{
@ -68,8 +70,9 @@ ShellProcessTests::testProcessListSampleConfig()
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
QVERIFY( !cl.isEmpty() );
QCOMPARE( cl.count(), 3 );
QCOMPARE( cl.at(0).timeout(), -1 );
QCOMPARE( cl.at(2).timeout(), 3600 ); // slowloris
QCOMPARE( cl.at(0).timeout(), CalamaresUtils::CommandLine::TimeoutNotSet() );
QCOMPARE( cl.at(2).timeout(), 3600s ); // slowloris
}
void ShellProcessTests::testProcessListFromList()
@ -105,9 +108,10 @@ script: "ls /tmp"
)" );
CommandList cl(
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
QVERIFY( !cl.isEmpty() );
QCOMPARE( cl.count(), 1 );
QCOMPARE( cl.at(0).timeout(), 10 );
QCOMPARE( cl.at(0).timeout(), 10s );
QCOMPARE( cl.at(0).command(), QStringLiteral( "ls /tmp" ) );
// Not a string
@ -118,7 +122,6 @@ script: false
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
QVERIFY( cl1.isEmpty() );
QCOMPARE( cl1.count(), 0 );
}
void ShellProcessTests::testProcessFromObject()
@ -130,9 +133,10 @@ script:
)" );
CommandList cl(
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
QVERIFY( !cl.isEmpty() );
QCOMPARE( cl.count(), 1 );
QCOMPARE( cl.at(0).timeout(), 20 );
QCOMPARE( cl.at(0).timeout(), 20s );
QCOMPARE( cl.at(0).command(), QStringLiteral( "ls /tmp" ) );
}
@ -148,9 +152,9 @@ script:
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
QVERIFY( !cl.isEmpty() );
QCOMPARE( cl.count(), 2 );
QCOMPARE( cl.at(0).timeout(), 12 );
QCOMPARE( cl.at(0).timeout(), 12s );
QCOMPARE( cl.at(0).command(), QStringLiteral( "ls /tmp" ) );
QCOMPARE( cl.at(1).timeout(), -1 ); // not set
QCOMPARE( cl.at(1).timeout(), CalamaresUtils::CommandLine::TimeoutNotSet() ); // not set
}
void ShellProcessTests::testRootSubstitution()
@ -182,30 +186,31 @@ script:
QVERIFY( gs != nullptr );
qDebug() << "Expect WARNING, ERROR, WARNING";
// Doesn't use @@ROOT@@, so no failures
QVERIFY( bool(CommandList(plainScript, false, 10 ).run()) );
QVERIFY( bool(CommandList(plainScript, false, 10s ).run()) );
// Doesn't use @@ROOT@@, but does chroot, so fails
QVERIFY( !bool(CommandList(plainScript, true, 10 ).run()) );
QVERIFY( !bool(CommandList(plainScript, true, 10s ).run()) );
// Does use @@ROOT@@, which is not set, so fails
QVERIFY( !bool(CommandList(rootScript, false, 10 ).run()) );
QVERIFY( !bool(CommandList(rootScript, false, 10s ).run()) );
// .. fails for two reasons
QVERIFY( !bool(CommandList(rootScript, true, 10 ).run()) );
QVERIFY( !bool(CommandList(rootScript, true, 10s ).run()) );
gs->insert( "rootMountPoint", "/tmp" );
// Now that the root is set, two variants work .. still can't
// chroot, unless the rootMountPoint contains a full system,
// *and* we're allowed to chroot (ie. running tests as root).
qDebug() << "Expect no output.";
QVERIFY( bool(CommandList(plainScript, false, 10 ).run()) );
QVERIFY( bool(CommandList(rootScript, false, 10 ).run()) );
QVERIFY( bool(CommandList(plainScript, false, 10s ).run()) );
QVERIFY( bool(CommandList(rootScript, false, 10s ).run()) );
qDebug() << "Expect ERROR";
// But no user set yet
QVERIFY( !bool(CommandList(userScript, false, 10 ).run()) );
QVERIFY( !bool(CommandList(userScript, false, 10s ).run()) );
// Now play dangerous games with shell expansion
gs->insert( "username", "`id -u`" );
QVERIFY( bool(CommandList(userScript, false, 10 ).run()) );
QVERIFY( bool(CommandList(userScript, false, 10s ).run()) );
}

@ -125,7 +125,7 @@ sed -i "s,URI =.*,URI = http://releases.neon.kde.org/meta-release/${MACHINE_ID},
sed -i "s,URI_LTS =.*,URI_LTS = http://releases.neon.kde.org/meta-release-lts/${MACHINE_ID}," /etc/update-manager/meta-release
true
)x"),
1);
std::chrono::seconds( 1 ) );
if ( r == 0 )
return Calamares::JobResult::ok();

@ -158,7 +158,7 @@ CreateUserJob::exec()
if ( commandResult.getExitCode() )
{
cError() << "useradd failed" << commandResult.getExitCode();
return commandResult.explainProcess( useradd, 10 /* bogus timeout */ );
return commandResult.explainProcess( useradd, std::chrono::seconds( 10 ) /* bogus timeout */ );
}
commandResult = CalamaresUtils::System::instance()->targetEnvCommand(
@ -166,7 +166,7 @@ CreateUserJob::exec()
if ( commandResult.getExitCode() )
{
cError() << "usermod failed" << commandResult.getExitCode();
return commandResult.explainProcess( "usermod", 10 );
return commandResult.explainProcess( "usermod", std::chrono::seconds( 10 ) /* bogus timeout */ );
}
QString userGroup = QString( "%1:%2" ).arg( m_userName ).arg( m_userName );
@ -176,7 +176,7 @@ CreateUserJob::exec()
if ( commandResult.getExitCode() )
{
cError() << "chown failed" << commandResult.getExitCode();
return commandResult.explainProcess( "chown", 10 );
return commandResult.explainProcess( "chown", std::chrono::seconds( 10 ) /* bogus timeout */ );
}
return Calamares::JobResult::ok();

Loading…
Cancel
Save