2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-07-21 11:30:56 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-07-21 11:30:56 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-07-21 11:30:56 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2011-07-21 11:30:56 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-07-21 11:30:56 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-07-21 11:30:56 +02:00
|
|
|
|
2012-07-26 23:29:00 +02:00
|
|
|
#include "linuxdevicetester.h"
|
2011-07-21 11:30:56 +02:00
|
|
|
|
2019-01-21 13:36:50 +01:00
|
|
|
#include "remotelinux_constants.h"
|
2018-12-14 15:41:59 +01:00
|
|
|
#include "rsyncdeploystep.h"
|
|
|
|
|
|
2012-07-26 23:29:00 +02:00
|
|
|
#include <projectexplorer/devicesupport/deviceusedportsgatherer.h>
|
2016-04-19 16:43:30 +02:00
|
|
|
#include <utils/port.h>
|
2011-07-21 11:30:56 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2019-09-30 14:32:49 +02:00
|
|
|
#include <ssh/sftptransfer.h>
|
2012-05-18 10:49:35 +02:00
|
|
|
#include <ssh/sshremoteprocess.h>
|
|
|
|
|
#include <ssh/sshconnection.h>
|
2018-12-12 17:16:49 +01:00
|
|
|
#include <ssh/sshconnectionmanager.h>
|
2011-07-21 11:30:56 +02:00
|
|
|
|
2012-07-25 17:41:01 +02:00
|
|
|
using namespace ProjectExplorer;
|
2012-05-18 10:49:35 +02:00
|
|
|
using namespace QSsh;
|
2011-07-21 11:30:56 +02:00
|
|
|
|
|
|
|
|
namespace RemoteLinux {
|
|
|
|
|
namespace Internal {
|
2011-12-21 20:14:42 +01:00
|
|
|
namespace {
|
2011-07-21 11:30:56 +02:00
|
|
|
|
2018-12-14 15:41:59 +01:00
|
|
|
enum State { Inactive, Connecting, RunningUname, TestingPorts, TestingSftp, TestingRsync };
|
2011-12-21 20:14:42 +01:00
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
|
|
class GenericLinuxDeviceTesterPrivate
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2018-12-14 15:41:59 +01:00
|
|
|
IDevice::Ptr deviceConfiguration;
|
2017-11-09 17:19:49 +01:00
|
|
|
SshConnection *connection = nullptr;
|
2018-11-23 11:07:57 +01:00
|
|
|
SshRemoteProcessPtr process;
|
2012-07-26 23:29:00 +02:00
|
|
|
DeviceUsedPortsGatherer portsGatherer;
|
2019-09-30 14:32:49 +02:00
|
|
|
SftpTransferPtr sftpTransfer;
|
2022-02-18 12:31:19 +01:00
|
|
|
Utils::QtcProcess rsyncProcess;
|
2017-11-09 17:19:49 +01:00
|
|
|
State state = Inactive;
|
2018-12-14 15:41:59 +01:00
|
|
|
bool sftpWorks = false;
|
2011-07-21 11:30:56 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
|
|
|
|
|
using namespace Internal;
|
|
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
GenericLinuxDeviceTester::GenericLinuxDeviceTester(QObject *parent)
|
2013-06-27 17:12:08 +02:00
|
|
|
: DeviceTester(parent), d(new GenericLinuxDeviceTesterPrivate)
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2022-02-18 12:31:19 +01:00
|
|
|
SshRemoteProcess::setupSshEnvironment(&d->rsyncProcess);
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
GenericLinuxDeviceTester::~GenericLinuxDeviceTester()
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2018-12-12 17:16:49 +01:00
|
|
|
if (d->connection)
|
2021-09-09 15:29:28 +02:00
|
|
|
SshConnectionManager::releaseConnection(d->connection);
|
2011-12-21 20:14:42 +01:00
|
|
|
delete d;
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2018-12-14 15:41:59 +01:00
|
|
|
void GenericLinuxDeviceTester::testDevice(const IDevice::Ptr &deviceConfiguration)
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2011-12-21 20:14:42 +01:00
|
|
|
QTC_ASSERT(d->state == Inactive, return);
|
|
|
|
|
|
|
|
|
|
d->deviceConfiguration = deviceConfiguration;
|
2021-09-09 15:29:28 +02:00
|
|
|
SshConnectionManager::forceNewConnection(deviceConfiguration->sshParameters());
|
|
|
|
|
d->connection = SshConnectionManager::acquireConnection(deviceConfiguration->sshParameters());
|
2015-01-30 11:02:24 +01:00
|
|
|
connect(d->connection, &SshConnection::connected,
|
|
|
|
|
this, &GenericLinuxDeviceTester::handleConnected);
|
2018-11-23 11:07:57 +01:00
|
|
|
connect(d->connection, &SshConnection::errorOccurred,
|
2015-01-30 11:02:24 +01:00
|
|
|
this, &GenericLinuxDeviceTester::handleConnectionFailure);
|
2011-12-21 20:14:42 +01:00
|
|
|
|
|
|
|
|
emit progressMessage(tr("Connecting to host..."));
|
|
|
|
|
d->state = Connecting;
|
|
|
|
|
d->connection->connectToHost();
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
void GenericLinuxDeviceTester::stopTest()
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2011-12-21 20:14:42 +01:00
|
|
|
QTC_ASSERT(d->state != Inactive, return);
|
|
|
|
|
|
|
|
|
|
switch (d->state) {
|
|
|
|
|
case Connecting:
|
|
|
|
|
d->connection->disconnectFromHost();
|
|
|
|
|
break;
|
|
|
|
|
case TestingPorts:
|
|
|
|
|
d->portsGatherer.stop();
|
|
|
|
|
break;
|
|
|
|
|
case RunningUname:
|
|
|
|
|
d->process->close();
|
|
|
|
|
break;
|
2018-10-19 17:06:52 +02:00
|
|
|
case TestingSftp:
|
2019-09-30 14:32:49 +02:00
|
|
|
d->sftpTransfer->stop();
|
2018-10-19 17:06:52 +02:00
|
|
|
break;
|
2018-12-14 15:41:59 +01:00
|
|
|
case TestingRsync:
|
|
|
|
|
d->rsyncProcess.disconnect();
|
|
|
|
|
d->rsyncProcess.kill();
|
2011-12-21 20:14:42 +01:00
|
|
|
case Inactive:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setFinished(TestFailure);
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
void GenericLinuxDeviceTester::handleConnected()
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2011-12-21 20:14:42 +01:00
|
|
|
QTC_ASSERT(d->state == Connecting, return);
|
|
|
|
|
|
|
|
|
|
d->process = d->connection->createRemoteProcess("uname -rsm");
|
2018-11-23 11:07:57 +01:00
|
|
|
connect(d->process.get(), &SshRemoteProcess::done,
|
2016-06-30 23:04:57 +03:00
|
|
|
this, &GenericLinuxDeviceTester::handleProcessFinished);
|
2011-12-21 20:14:42 +01:00
|
|
|
|
2012-11-24 21:06:36 +02:00
|
|
|
emit progressMessage(tr("Checking kernel version..."));
|
2011-12-21 20:14:42 +01:00
|
|
|
d->state = RunningUname;
|
|
|
|
|
d->process->start();
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
void GenericLinuxDeviceTester::handleConnectionFailure()
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2011-12-21 20:14:42 +01:00
|
|
|
QTC_ASSERT(d->state != Inactive, return);
|
|
|
|
|
|
2018-11-23 11:07:57 +01:00
|
|
|
emit errorMessage(d->connection->errorString() + QLatin1Char('\n'));
|
|
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
setFinished(TestFailure);
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2022-02-28 14:11:49 +01:00
|
|
|
void GenericLinuxDeviceTester::handleProcessFinished()
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2011-12-21 20:14:42 +01:00
|
|
|
QTC_ASSERT(d->state == RunningUname, return);
|
|
|
|
|
|
2022-02-28 14:11:49 +01:00
|
|
|
if (!d->process->errorString().isEmpty() || d->process->exitCode() != 0) {
|
2011-12-21 20:14:42 +01:00
|
|
|
const QByteArray stderrOutput = d->process->readAllStandardError();
|
|
|
|
|
if (!stderrOutput.isEmpty())
|
2013-10-17 13:48:04 +02:00
|
|
|
emit errorMessage(tr("uname failed: %1").arg(QString::fromUtf8(stderrOutput)) + QLatin1Char('\n'));
|
2011-12-21 20:14:42 +01:00
|
|
|
else
|
2013-10-17 13:48:04 +02:00
|
|
|
emit errorMessage(tr("uname failed.") + QLatin1Char('\n'));
|
2011-12-21 20:14:42 +01:00
|
|
|
} else {
|
|
|
|
|
emit progressMessage(QString::fromUtf8(d->process->readAllStandardOutput()));
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-30 11:02:24 +01:00
|
|
|
connect(&d->portsGatherer, &DeviceUsedPortsGatherer::error,
|
|
|
|
|
this, &GenericLinuxDeviceTester::handlePortsGatheringError);
|
|
|
|
|
connect(&d->portsGatherer, &DeviceUsedPortsGatherer::portListReady,
|
|
|
|
|
this, &GenericLinuxDeviceTester::handlePortListReady);
|
2011-12-21 20:14:42 +01:00
|
|
|
|
|
|
|
|
emit progressMessage(tr("Checking if specified ports are available..."));
|
|
|
|
|
d->state = TestingPorts;
|
2012-04-03 10:23:59 +02:00
|
|
|
d->portsGatherer.start(d->deviceConfiguration);
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
void GenericLinuxDeviceTester::handlePortsGatheringError(const QString &message)
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2011-12-21 20:14:42 +01:00
|
|
|
QTC_ASSERT(d->state == TestingPorts, return);
|
|
|
|
|
|
2013-10-17 13:48:04 +02:00
|
|
|
emit errorMessage(tr("Error gathering ports: %1").arg(message) + QLatin1Char('\n'));
|
2011-12-21 20:14:42 +01:00
|
|
|
setFinished(TestFailure);
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
void GenericLinuxDeviceTester::handlePortListReady()
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2011-12-21 20:14:42 +01:00
|
|
|
QTC_ASSERT(d->state == TestingPorts, return);
|
|
|
|
|
|
|
|
|
|
if (d->portsGatherer.usedPorts().isEmpty()) {
|
2013-10-17 13:48:04 +02:00
|
|
|
emit progressMessage(tr("All specified ports are available.") + QLatin1Char('\n'));
|
2011-12-21 20:14:42 +01:00
|
|
|
} else {
|
|
|
|
|
QString portList;
|
2016-04-19 16:43:30 +02:00
|
|
|
foreach (const Utils::Port port, d->portsGatherer.usedPorts())
|
|
|
|
|
portList += QString::number(port.number()) + QLatin1String(", ");
|
2011-12-21 20:14:42 +01:00
|
|
|
portList.remove(portList.count() - 2, 2);
|
2013-10-17 13:48:04 +02:00
|
|
|
emit errorMessage(tr("The following specified ports are currently in use: %1")
|
|
|
|
|
.arg(portList) + QLatin1Char('\n'));
|
2011-12-21 20:14:42 +01:00
|
|
|
}
|
2018-10-19 17:06:52 +02:00
|
|
|
|
2018-11-23 11:07:57 +01:00
|
|
|
emit progressMessage(tr("Checking whether an SFTP connection can be set up..."));
|
2019-09-30 14:32:49 +02:00
|
|
|
d->sftpTransfer = d->connection->createDownload(FilesToTransfer(),
|
|
|
|
|
FileTransferErrorHandling::Abort);
|
|
|
|
|
connect(d->sftpTransfer.get(), &SftpTransfer::done,
|
2018-11-23 11:07:57 +01:00
|
|
|
this, &GenericLinuxDeviceTester::handleSftpFinished);
|
2018-10-19 17:06:52 +02:00
|
|
|
d->state = TestingSftp;
|
2019-09-30 14:32:49 +02:00
|
|
|
d->sftpTransfer->start();
|
2018-12-19 16:18:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GenericLinuxDeviceTester::handleSftpStarted()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(d->state == TestingSftp, return);
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2018-11-23 11:07:57 +01:00
|
|
|
void GenericLinuxDeviceTester::handleSftpFinished(const QString &error)
|
2018-10-19 17:06:52 +02:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(d->state == TestingSftp, return);
|
2019-09-30 14:32:49 +02:00
|
|
|
if (error.isEmpty()) {
|
|
|
|
|
d->sftpWorks = true;
|
|
|
|
|
emit progressMessage(tr("SFTP service available.\n"));
|
|
|
|
|
} else {
|
|
|
|
|
d->sftpWorks = false;
|
|
|
|
|
emit errorMessage(tr("Error setting up SFTP connection: %1\n").arg(error));
|
|
|
|
|
}
|
|
|
|
|
disconnect(d->sftpTransfer.get(), nullptr, this, nullptr);
|
2018-12-19 16:18:04 +01:00
|
|
|
testRsync();
|
|
|
|
|
}
|
2018-12-14 15:41:59 +01:00
|
|
|
|
2018-12-19 16:18:04 +01:00
|
|
|
void GenericLinuxDeviceTester::testRsync()
|
|
|
|
|
{
|
2018-12-14 15:41:59 +01:00
|
|
|
emit progressMessage(tr("Checking whether rsync works..."));
|
2021-06-25 14:54:27 +02:00
|
|
|
connect(&d->rsyncProcess, &Utils::QtcProcess::errorOccurred, [this] {
|
2018-12-14 15:41:59 +01:00
|
|
|
if (d->rsyncProcess.error() == QProcess::FailedToStart)
|
|
|
|
|
handleRsyncFinished();
|
|
|
|
|
});
|
2021-06-25 14:54:27 +02:00
|
|
|
connect(&d->rsyncProcess, &Utils::QtcProcess::finished, this, [this] {
|
2018-12-14 15:41:59 +01:00
|
|
|
handleRsyncFinished();
|
|
|
|
|
});
|
2019-04-23 15:57:54 +02:00
|
|
|
const RsyncCommandLine cmdLine = RsyncDeployStep::rsyncCommand(*d->connection,
|
|
|
|
|
RsyncDeployStep::defaultFlags());
|
2018-12-14 15:41:59 +01:00
|
|
|
const QStringList args = QStringList(cmdLine.options)
|
|
|
|
|
<< "-n" << "--exclude=*" << (cmdLine.remoteHostSpec + ":/tmp");
|
2021-06-25 14:54:27 +02:00
|
|
|
d->rsyncProcess.setCommand(Utils::CommandLine("rsync", args));
|
|
|
|
|
d->rsyncProcess.start();
|
2018-12-14 15:41:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GenericLinuxDeviceTester::handleRsyncFinished()
|
|
|
|
|
{
|
|
|
|
|
QString error;
|
|
|
|
|
if (d->rsyncProcess.error() == QProcess::FailedToStart) {
|
|
|
|
|
error = tr("Failed to start rsync: %1\n").arg(d->rsyncProcess.errorString());
|
|
|
|
|
} else if (d->rsyncProcess.exitStatus() == QProcess::CrashExit) {
|
|
|
|
|
error = tr("rsync crashed.\n");
|
|
|
|
|
} else if (d->rsyncProcess.exitCode() != 0) {
|
|
|
|
|
error = tr("rsync failed with exit code %1: %2\n")
|
|
|
|
|
.arg(d->rsyncProcess.exitCode())
|
|
|
|
|
.arg(QString::fromLocal8Bit(d->rsyncProcess.readAllStandardError()));
|
2018-11-23 11:07:57 +01:00
|
|
|
}
|
2018-12-14 15:41:59 +01:00
|
|
|
TestResult result = TestSuccess;
|
|
|
|
|
if (!error.isEmpty()) {
|
|
|
|
|
emit errorMessage(error);
|
2018-12-21 10:47:39 +01:00
|
|
|
if (d->sftpWorks) {
|
|
|
|
|
emit progressMessage(tr("SFTP will be used for deployment, because rsync "
|
|
|
|
|
"is not available.\n"));
|
|
|
|
|
} else {
|
2018-12-14 15:41:59 +01:00
|
|
|
emit errorMessage(tr("Deployment to this device will not work out of the box.\n"));
|
|
|
|
|
result = TestFailure;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
emit progressMessage(tr("rsync is functional.\n"));
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-21 13:36:50 +01:00
|
|
|
d->deviceConfiguration->setExtraData(Constants::SupportsRSync, error.isEmpty());
|
2018-12-14 15:41:59 +01:00
|
|
|
setFinished(result);
|
2018-10-19 17:06:52 +02:00
|
|
|
}
|
|
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
void GenericLinuxDeviceTester::setFinished(TestResult result)
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2011-12-21 20:14:42 +01:00
|
|
|
d->state = Inactive;
|
2018-11-24 17:06:01 +01:00
|
|
|
disconnect(&d->portsGatherer, nullptr, this, nullptr);
|
2019-09-30 14:32:49 +02:00
|
|
|
if (d->sftpTransfer) {
|
|
|
|
|
disconnect(d->sftpTransfer.get(), nullptr, this, nullptr);
|
|
|
|
|
d->sftpTransfer.release()->deleteLater();
|
2018-11-23 11:07:57 +01:00
|
|
|
}
|
2012-06-05 15:18:55 +02:00
|
|
|
if (d->connection) {
|
2018-11-24 17:06:01 +01:00
|
|
|
disconnect(d->connection, nullptr, this, nullptr);
|
2021-09-09 15:29:28 +02:00
|
|
|
SshConnectionManager::releaseConnection(d->connection);
|
2018-11-24 17:06:01 +01:00
|
|
|
d->connection = nullptr;
|
2012-06-05 15:18:55 +02:00
|
|
|
}
|
2011-12-21 20:14:42 +01:00
|
|
|
emit finished(result);
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace RemoteLinux
|