[partition] Remove initKPMCore() from KPMHelpers

- This is a job for KPMManager, from the partition service.
 - In tests, needs to be a little hackish.
This commit is contained in:
Adriaan de Groot 2019-06-13 22:33:41 +02:00
parent a01539b664
commit d039f9bbb8
6 changed files with 16 additions and 34 deletions

View File

@ -37,25 +37,6 @@ using CalamaresUtils::Partition::PartitionIterator;
namespace KPMHelpers
{
static bool s_KPMcoreInited = false;
bool
initKPMcore()
{
if ( s_KPMcoreInited )
return true;
QByteArray backendName = qgetenv( "KPMCORE_BACKEND" );
if ( !CoreBackendManager::self()->load( backendName.isEmpty() ? CoreBackendManager::defaultBackendName() : backendName ) )
{
cWarning() << "Failed to load backend plugin" << backendName;
return false;
}
s_KPMcoreInited = true;
return true;
}
Partition*
findPartitionByMountPoint( const QList< Device* >& devices, const QString& mountPoint )
{

View File

@ -50,19 +50,6 @@ class PartitionRole;
namespace KPMHelpers
{
/**
* Thin wrapper on top of CoreBackendManager. Hides things like initializing the
* Config instance or instantiating the backend.
*
* Initialize PartitionManager Config object and load a PartitionManager
* backend. It loads the "libparted" plugin by default, but this can be
* overloaded by settings the environment variable KPMCORE_BACKEND. Setting it to
* "dummy" will load the dummy plugin instead.
*
* @return true if initialization was successful.
*/
bool initKPMcore();
/**
* Iterates on all devices and return the first partition which is associated
* with mountPoint. This uses PartitionInfo::mountPoint(), not Partition::mountPoint()

View File

@ -147,7 +147,7 @@ PartitionCoreModule::PartitionCoreModule( QObject* parent )
, m_deviceModel( new DeviceModel( this ) )
, m_bootLoaderModel( new BootLoaderModel( this ) )
{
if ( !KPMHelpers::initKPMcore() )
if ( !m_kpmcore )
qFatal( "Failed to initialize KPMcore backend" );
}

View File

@ -26,6 +26,7 @@
#include "core/PartitionModel.h"
#include "Job.h"
#include "partition/KPMManager.h"
// KPMcore
#include <kpmcore/core/lvmdevice.h>
@ -235,6 +236,8 @@ Q_SIGNALS:
void deviceReverted( Device* device );
private:
CalamaresUtils::Partition::KPMManager m_kpmcore;
void refreshAfterModelChange();
/**

View File

@ -19,7 +19,9 @@
#include <PartitionJobTests.h>
#include "partition/KPMManager.h"
#include "partition/PartitionQuery.h"
#include "utils/Logger.h"
#include "utils/Units.h"
#include <jobs/CreatePartitionJob.h>
@ -163,6 +165,8 @@ QueueRunner::onFailed( const QString& message, const QString& details )
QFAIL( qPrintable( msg ) );
}
CalamaresUtils::Partition::KPMManager* kpmcore = nullptr;
//- PartitionJobTests ------------------------------------------------------------------
PartitionJobTests::PartitionJobTests()
: m_runner( &m_queue )
@ -178,12 +182,18 @@ PartitionJobTests::initTestCase()
QSKIP( "Skipping test, CALAMARES_TEST_DISK is not set. It should point to a disk which can be safely formatted", 0 );
}
QVERIFY( KPMHelpers::initKPMcore() );
kpmcore = new CalamaresUtils::Partition::KPMManager();
FileSystemFactory::init();
refreshDevice();
}
void
PartitionJobTests::cleanupTestCase()
{
delete kpmcore;
}
void
PartitionJobTests::refreshDevice()
{

View File

@ -59,6 +59,7 @@ public:
private Q_SLOTS:
void initTestCase();
void cleanupTestCase();
void testPartitionTable();
void testCreatePartition();
void testCreatePartitionExtended();