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>
|
2019-09-30 14:32:49 +02:00
|
|
|
#include <ssh/sftptransfer.h>
|
2012-05-18 10:49:35 +02:00
|
|
|
#include <ssh/sshconnection.h>
|
2018-12-12 17:16:49 +01:00
|
|
|
#include <ssh/sshconnectionmanager.h>
|
2022-05-06 02:16:54 +02:00
|
|
|
#include <utils/port.h>
|
|
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
#include <utils/qtcprocess.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;
|
2022-04-04 13:17:36 +02:00
|
|
|
using namespace Utils;
|
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:
|
2022-05-10 23:17:13 +02:00
|
|
|
IDevice::Ptr device;
|
2017-11-09 17:19:49 +01:00
|
|
|
SshConnection *connection = nullptr;
|
2022-05-03 09:35:20 +02:00
|
|
|
QtcProcess unameProcess;
|
2012-07-26 23:29:00 +02:00
|
|
|
DeviceUsedPortsGatherer portsGatherer;
|
2019-09-30 14:32:49 +02:00
|
|
|
SftpTransferPtr sftpTransfer;
|
2022-04-04 13:17:36 +02:00
|
|
|
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-05-03 09:35:20 +02:00
|
|
|
connect(&d->unameProcess, &QtcProcess::done, this,
|
2022-05-10 23:17:13 +02:00
|
|
|
&GenericLinuxDeviceTester::handleUnameDone);
|
|
|
|
|
connect(&d->portsGatherer, &DeviceUsedPortsGatherer::error,
|
|
|
|
|
this, &GenericLinuxDeviceTester::handlePortsGathererError);
|
|
|
|
|
connect(&d->portsGatherer, &DeviceUsedPortsGatherer::portListReady,
|
|
|
|
|
this, &GenericLinuxDeviceTester::handlePortsGathererDone);
|
2022-05-03 09:35:20 +02:00
|
|
|
connect(&d->rsyncProcess, &QtcProcess::done, this,
|
2022-05-10 23:17:13 +02:00
|
|
|
&GenericLinuxDeviceTester::handleRsyncDone);
|
2022-05-06 02:16:54 +02:00
|
|
|
SshConnectionParameters::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-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);
|
|
|
|
|
|
2022-05-10 23:17:13 +02:00
|
|
|
d->device = 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
|
|
|
|
2022-05-10 23:17:13 +02:00
|
|
|
emit progressMessage(tr("Connecting to device..."));
|
2011-12-21 20:14:42 +01:00
|
|
|
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:
|
2022-05-03 09:35:20 +02:00
|
|
|
d->unameProcess.close();
|
2011-12-21 20:14:42 +01:00
|
|
|
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:
|
2022-05-03 09:35:20 +02:00
|
|
|
d->rsyncProcess.close();
|
2022-05-10 23:17:13 +02:00
|
|
|
break;
|
2011-12-21 20:14:42 +01:00
|
|
|
case Inactive:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setFinished(TestFailure);
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-10 23:17:13 +02:00
|
|
|
void GenericLinuxDeviceTester::handleConnectionFailure()
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2022-05-10 23:17:13 +02:00
|
|
|
QTC_ASSERT(d->state != Inactive, return);
|
2011-12-21 20:14:42 +01:00
|
|
|
|
2022-05-10 23:17:13 +02:00
|
|
|
emit errorMessage(d->connection->errorString() + QLatin1Char('\n'));
|
2011-12-21 20:14:42 +01:00
|
|
|
|
2022-05-10 23:17:13 +02:00
|
|
|
setFinished(TestFailure);
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-10 23:17:13 +02:00
|
|
|
void GenericLinuxDeviceTester::handleConnected()
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2022-05-10 23:17:13 +02:00
|
|
|
QTC_ASSERT(d->state == Connecting, return);
|
|
|
|
|
emit progressMessage(tr("Connection to device established.") + QLatin1Char('\n'));
|
2011-12-21 20:14:42 +01:00
|
|
|
|
2022-05-10 23:17:13 +02:00
|
|
|
testUname();
|
|
|
|
|
}
|
2018-11-23 11:07:57 +01:00
|
|
|
|
2022-05-10 23:17:13 +02:00
|
|
|
void GenericLinuxDeviceTester::testUname()
|
|
|
|
|
{
|
|
|
|
|
d->state = RunningUname;
|
|
|
|
|
emit progressMessage(tr("Checking kernel version..."));
|
|
|
|
|
|
|
|
|
|
d->unameProcess.setCommand({d->device->filePath("uname"), {"-rsm"}});
|
|
|
|
|
d->unameProcess.start();
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-10 23:17:13 +02:00
|
|
|
void GenericLinuxDeviceTester::handleUnameDone()
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2011-12-21 20:14:42 +01:00
|
|
|
QTC_ASSERT(d->state == RunningUname, return);
|
|
|
|
|
|
2022-05-03 09:35:20 +02:00
|
|
|
if (!d->unameProcess.errorString().isEmpty() || d->unameProcess.exitCode() != 0) {
|
|
|
|
|
const QByteArray stderrOutput = d->unameProcess.readAllStandardError();
|
2011-12-21 20:14:42 +01:00
|
|
|
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 {
|
2022-05-03 09:35:20 +02:00
|
|
|
emit progressMessage(QString::fromUtf8(d->unameProcess.readAllStandardOutput()));
|
2011-12-21 20:14:42 +01:00
|
|
|
}
|
|
|
|
|
|
2022-05-10 23:17:13 +02:00
|
|
|
testPortsGatherer();
|
|
|
|
|
}
|
2011-12-21 20:14:42 +01:00
|
|
|
|
2022-05-10 23:17:13 +02:00
|
|
|
void GenericLinuxDeviceTester::testPortsGatherer()
|
|
|
|
|
{
|
2011-12-21 20:14:42 +01:00
|
|
|
d->state = TestingPorts;
|
2022-05-10 23:17:13 +02:00
|
|
|
emit progressMessage(tr("Checking if specified ports are available..."));
|
|
|
|
|
|
|
|
|
|
d->portsGatherer.start(d->device);
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-10 23:17:13 +02:00
|
|
|
void GenericLinuxDeviceTester::handlePortsGathererError(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
|
|
|
}
|
|
|
|
|
|
2022-05-10 23:17:13 +02:00
|
|
|
void GenericLinuxDeviceTester::handlePortsGathererDone()
|
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 {
|
2022-05-10 23:17:13 +02:00
|
|
|
const QString portList = transform(d->portsGatherer.usedPorts(), [](const Port &port) {
|
|
|
|
|
return QString::number(port.number());
|
|
|
|
|
}).join(", ");
|
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
|
|
|
|
2022-05-10 23:17:13 +02:00
|
|
|
testSftp();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GenericLinuxDeviceTester::testSftp()
|
|
|
|
|
{
|
|
|
|
|
d->state = TestingSftp;
|
2018-11-23 11:07:57 +01:00
|
|
|
emit progressMessage(tr("Checking whether an SFTP connection can be set up..."));
|
2022-05-10 23:17:13 +02:00
|
|
|
|
2022-05-10 08:43:06 +02:00
|
|
|
d->sftpTransfer = d->connection->createDownload(FilesToTransfer());
|
2019-09-30 14:32:49 +02:00
|
|
|
connect(d->sftpTransfer.get(), &SftpTransfer::done,
|
2022-05-10 23:17:13 +02:00
|
|
|
this, &GenericLinuxDeviceTester::handleSftpDone);
|
2019-09-30 14:32:49 +02:00
|
|
|
d->sftpTransfer->start();
|
2018-12-19 16:18:04 +01:00
|
|
|
}
|
|
|
|
|
|
2022-05-10 23:17:13 +02:00
|
|
|
void GenericLinuxDeviceTester::handleSftpDone(const QString &error)
|
2018-12-19 16:18:04 +01:00
|
|
|
{
|
|
|
|
|
QTC_ASSERT(d->state == TestingSftp, return);
|
2011-07-21 11:30:56 +02:00
|
|
|
|
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);
|
2022-05-10 23:17:13 +02:00
|
|
|
|
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()
|
|
|
|
|
{
|
2022-05-10 23:17:13 +02:00
|
|
|
d->state = TestingRsync;
|
2018-12-14 15:41:59 +01:00
|
|
|
emit progressMessage(tr("Checking whether rsync works..."));
|
2022-05-10 23:17:13 +02:00
|
|
|
|
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");
|
2022-04-04 13:17:36 +02:00
|
|
|
d->rsyncProcess.setCommand(CommandLine("rsync", args));
|
2021-06-25 14:54:27 +02:00
|
|
|
d->rsyncProcess.start();
|
2018-12-14 15:41:59 +01:00
|
|
|
}
|
|
|
|
|
|
2022-05-10 23:17:13 +02:00
|
|
|
void GenericLinuxDeviceTester::handleRsyncDone()
|
2018-12-14 15:41:59 +01:00
|
|
|
{
|
2022-05-10 23:17:13 +02:00
|
|
|
QTC_ASSERT(d->state == TestingRsync, return);
|
|
|
|
|
|
2018-12-14 15:41:59 +01:00
|
|
|
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"));
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-10 23:17:13 +02:00
|
|
|
d->device->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;
|
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
|