[shellprocess] Apply current coding style
This commit is contained in:
parent
d363732302
commit
a0430f76b7
@ -18,13 +18,13 @@
|
|||||||
|
|
||||||
#include "ShellProcessJob.h"
|
#include "ShellProcessJob.h"
|
||||||
|
|
||||||
#include <QProcess>
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QProcess>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
#include "CalamaresVersion.h"
|
#include "CalamaresVersion.h"
|
||||||
#include "JobQueue.h"
|
|
||||||
#include "GlobalStorage.h"
|
#include "GlobalStorage.h"
|
||||||
|
#include "JobQueue.h"
|
||||||
|
|
||||||
#include "utils/CommandList.h"
|
#include "utils/CommandList.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
@ -71,16 +71,23 @@ ShellProcessJob::setConfigurationMap( const QVariantMap& configurationMap )
|
|||||||
bool dontChroot = CalamaresUtils::getBool( configurationMap, "dontChroot", false );
|
bool dontChroot = CalamaresUtils::getBool( configurationMap, "dontChroot", false );
|
||||||
int timeout = CalamaresUtils::getInteger( configurationMap, "timeout", 10 );
|
int timeout = CalamaresUtils::getInteger( configurationMap, "timeout", 10 );
|
||||||
if ( timeout < 1 )
|
if ( timeout < 1 )
|
||||||
|
{
|
||||||
timeout = 10;
|
timeout = 10;
|
||||||
|
}
|
||||||
|
|
||||||
if ( configurationMap.contains( "script" ) )
|
if ( configurationMap.contains( "script" ) )
|
||||||
{
|
{
|
||||||
m_commands = new CalamaresUtils::CommandList( configurationMap.value( "script" ), !dontChroot, std::chrono::seconds( timeout ) );
|
m_commands = new CalamaresUtils::CommandList(
|
||||||
|
configurationMap.value( "script" ), !dontChroot, std::chrono::seconds( timeout ) );
|
||||||
if ( m_commands->isEmpty() )
|
if ( m_commands->isEmpty() )
|
||||||
|
{
|
||||||
cDebug() << "ShellProcessJob: \"script\" contains no commands for" << moduleInstanceKey();
|
cDebug() << "ShellProcessJob: \"script\" contains no commands for" << moduleInstanceKey();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
cWarning() << "No script given for ShellProcessJob" << moduleInstanceKey();
|
cWarning() << "No script given for ShellProcessJob" << moduleInstanceKey();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CALAMARES_PLUGIN_FACTORY_DEFINITION( ShellProcessJobFactory, registerPlugin< ShellProcessJob >(); )
|
CALAMARES_PLUGIN_FACTORY_DEFINITION( ShellProcessJobFactory, registerPlugin< ShellProcessJob >(); )
|
||||||
|
@ -37,13 +37,9 @@ using CommandList = CalamaresUtils::CommandList;
|
|||||||
using std::operator""s;
|
using std::operator""s;
|
||||||
|
|
||||||
|
|
||||||
ShellProcessTests::ShellProcessTests()
|
ShellProcessTests::ShellProcessTests() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
ShellProcessTests::~ShellProcessTests()
|
ShellProcessTests::~ShellProcessTests() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ShellProcessTests::initTestCase()
|
ShellProcessTests::initTestCase()
|
||||||
@ -66,8 +62,7 @@ ShellProcessTests::testProcessListSampleConfig()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandList cl(
|
CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
||||||
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
|
||||||
QVERIFY( !cl.isEmpty() );
|
QVERIFY( !cl.isEmpty() );
|
||||||
QCOMPARE( cl.count(), 3 );
|
QCOMPARE( cl.count(), 3 );
|
||||||
|
|
||||||
@ -75,7 +70,8 @@ ShellProcessTests::testProcessListSampleConfig()
|
|||||||
QCOMPARE( cl.at( 2 ).timeout(), 3600s ); // slowloris
|
QCOMPARE( cl.at( 2 ).timeout(), 3600s ); // slowloris
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShellProcessTests::testProcessListFromList()
|
void
|
||||||
|
ShellProcessTests::testProcessListFromList()
|
||||||
{
|
{
|
||||||
YAML::Node doc = YAML::Load( R"(---
|
YAML::Node doc = YAML::Load( R"(---
|
||||||
script:
|
script:
|
||||||
@ -83,8 +79,7 @@ script:
|
|||||||
- "ls /nonexistent"
|
- "ls /nonexistent"
|
||||||
- "/bin/false"
|
- "/bin/false"
|
||||||
)" );
|
)" );
|
||||||
CommandList cl(
|
CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
||||||
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
|
||||||
QVERIFY( !cl.isEmpty() );
|
QVERIFY( !cl.isEmpty() );
|
||||||
QCOMPARE( cl.count(), 3 );
|
QCOMPARE( cl.count(), 3 );
|
||||||
|
|
||||||
@ -95,19 +90,18 @@ script:
|
|||||||
- false
|
- false
|
||||||
- "ls /nonexistent"
|
- "ls /nonexistent"
|
||||||
)" );
|
)" );
|
||||||
CommandList cl1(
|
CommandList cl1( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
||||||
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
|
||||||
QVERIFY( !cl1.isEmpty() );
|
QVERIFY( !cl1.isEmpty() );
|
||||||
QCOMPARE( cl1.count(), 2 ); // One element ignored
|
QCOMPARE( cl1.count(), 2 ); // One element ignored
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShellProcessTests::testProcessListFromString()
|
void
|
||||||
|
ShellProcessTests::testProcessListFromString()
|
||||||
{
|
{
|
||||||
YAML::Node doc = YAML::Load( R"(---
|
YAML::Node doc = YAML::Load( R"(---
|
||||||
script: "ls /tmp"
|
script: "ls /tmp"
|
||||||
)" );
|
)" );
|
||||||
CommandList cl(
|
CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
||||||
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
|
||||||
|
|
||||||
QVERIFY( !cl.isEmpty() );
|
QVERIFY( !cl.isEmpty() );
|
||||||
QCOMPARE( cl.count(), 1 );
|
QCOMPARE( cl.count(), 1 );
|
||||||
@ -118,21 +112,20 @@ script: "ls /tmp"
|
|||||||
doc = YAML::Load( R"(---
|
doc = YAML::Load( R"(---
|
||||||
script: false
|
script: false
|
||||||
)" );
|
)" );
|
||||||
CommandList cl1(
|
CommandList cl1( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
||||||
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
|
||||||
QVERIFY( cl1.isEmpty() );
|
QVERIFY( cl1.isEmpty() );
|
||||||
QCOMPARE( cl1.count(), 0 );
|
QCOMPARE( cl1.count(), 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShellProcessTests::testProcessFromObject()
|
void
|
||||||
|
ShellProcessTests::testProcessFromObject()
|
||||||
{
|
{
|
||||||
YAML::Node doc = YAML::Load( R"(---
|
YAML::Node doc = YAML::Load( R"(---
|
||||||
script:
|
script:
|
||||||
command: "ls /tmp"
|
command: "ls /tmp"
|
||||||
timeout: 20
|
timeout: 20
|
||||||
)" );
|
)" );
|
||||||
CommandList cl(
|
CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
||||||
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
|
||||||
|
|
||||||
QVERIFY( !cl.isEmpty() );
|
QVERIFY( !cl.isEmpty() );
|
||||||
QCOMPARE( cl.count(), 1 );
|
QCOMPARE( cl.count(), 1 );
|
||||||
@ -140,7 +133,8 @@ script:
|
|||||||
QCOMPARE( cl.at( 0 ).command(), QStringLiteral( "ls /tmp" ) );
|
QCOMPARE( cl.at( 0 ).command(), QStringLiteral( "ls /tmp" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShellProcessTests::testProcessListFromObject()
|
void
|
||||||
|
ShellProcessTests::testProcessListFromObject()
|
||||||
{
|
{
|
||||||
YAML::Node doc = YAML::Load( R"(---
|
YAML::Node doc = YAML::Load( R"(---
|
||||||
script:
|
script:
|
||||||
@ -148,8 +142,7 @@ script:
|
|||||||
timeout: 12
|
timeout: 12
|
||||||
- "-/bin/false"
|
- "-/bin/false"
|
||||||
)" );
|
)" );
|
||||||
CommandList cl(
|
CommandList cl( CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
||||||
CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" ) );
|
|
||||||
QVERIFY( !cl.isEmpty() );
|
QVERIFY( !cl.isEmpty() );
|
||||||
QCOMPARE( cl.count(), 2 );
|
QCOMPARE( cl.count(), 2 );
|
||||||
QCOMPARE( cl.at( 0 ).timeout(), 12s );
|
QCOMPARE( cl.at( 0 ).timeout(), 12s );
|
||||||
@ -157,25 +150,28 @@ script:
|
|||||||
QCOMPARE( cl.at( 1 ).timeout(), CalamaresUtils::CommandLine::TimeoutNotSet() ); // not set
|
QCOMPARE( cl.at( 1 ).timeout(), CalamaresUtils::CommandLine::TimeoutNotSet() ); // not set
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShellProcessTests::testRootSubstitution()
|
void
|
||||||
|
ShellProcessTests::testRootSubstitution()
|
||||||
{
|
{
|
||||||
YAML::Node doc = YAML::Load( R"(---
|
YAML::Node doc = YAML::Load( R"(---
|
||||||
script:
|
script:
|
||||||
- "ls /tmp"
|
- "ls /tmp"
|
||||||
)" );
|
)" );
|
||||||
QVariant plainScript = CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" );
|
QVariant plainScript = CalamaresUtils::yamlMapToVariant( doc ).toMap().value( "script" );
|
||||||
QVariant rootScript = CalamaresUtils::yamlMapToVariant(
|
QVariant rootScript = CalamaresUtils::yamlMapToVariant( YAML::Load( R"(---
|
||||||
YAML::Load( R"(---
|
|
||||||
script:
|
script:
|
||||||
- "ls @@ROOT@@"
|
- "ls @@ROOT@@"
|
||||||
)" ) ).toMap().value( "script" );
|
)" ) )
|
||||||
QVariant userScript = CalamaresUtils::yamlMapToVariant(
|
.toMap()
|
||||||
YAML::Load( R"(---
|
.value( "script" );
|
||||||
|
QVariant userScript = CalamaresUtils::yamlMapToVariant( YAML::Load( R"(---
|
||||||
script:
|
script:
|
||||||
- mktemp -d @@ROOT@@/calatestXXXXXXXX
|
- mktemp -d @@ROOT@@/calatestXXXXXXXX
|
||||||
- "chown @@USER@@ @@ROOT@@/calatest*"
|
- "chown @@USER@@ @@ROOT@@/calatest*"
|
||||||
- rm -rf @@ROOT@@/calatest*
|
- rm -rf @@ROOT@@/calatest*
|
||||||
)" ) ).toMap().value( "script" );
|
)" ) )
|
||||||
|
.toMap()
|
||||||
|
.value( "script" );
|
||||||
|
|
||||||
if ( !Calamares::JobQueue::instance() )
|
if ( !Calamares::JobQueue::instance() )
|
||||||
(void)new Calamares::JobQueue( nullptr );
|
(void)new Calamares::JobQueue( nullptr );
|
||||||
|
Loading…
Reference in New Issue
Block a user