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
|
|
|
|
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>
|
2018-10-19 17:06:52 +02:00
|
|
|
#include <ssh/sftpchannel.h>
|
2012-05-18 10:49:35 +02:00
|
|
|
#include <ssh/sshremoteprocess.h>
|
|
|
|
|
#include <ssh/sshconnection.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-10-19 17:06:52 +02:00
|
|
|
enum State { Inactive, Connecting, RunningUname, TestingPorts, TestingSftp };
|
2011-12-21 20:14:42 +01:00
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
|
|
class GenericLinuxDeviceTesterPrivate
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2012-07-25 17:41:01 +02:00
|
|
|
IDevice::ConstPtr deviceConfiguration;
|
2017-11-09 17:19:49 +01:00
|
|
|
SshConnection *connection = nullptr;
|
2011-12-21 20:14:42 +01:00
|
|
|
SshRemoteProcess::Ptr process;
|
2012-07-26 23:29:00 +02:00
|
|
|
DeviceUsedPortsGatherer portsGatherer;
|
2018-10-19 17:06:52 +02:00
|
|
|
SftpChannel::Ptr sftpChannel;
|
2017-11-09 17:19:49 +01:00
|
|
|
State state = Inactive;
|
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
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-21 20:14:42 +01:00
|
|
|
GenericLinuxDeviceTester::~GenericLinuxDeviceTester()
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2011-12-21 20:14:42 +01:00
|
|
|
delete d;
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2012-07-25 17:41:01 +02:00
|
|
|
void GenericLinuxDeviceTester::testDevice(const IDevice::ConstPtr &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;
|
2012-06-08 08:48:03 +02:00
|
|
|
d->connection = new SshConnection(deviceConfiguration->sshParameters(), this);
|
2015-01-30 11:02:24 +01:00
|
|
|
connect(d->connection, &SshConnection::connected,
|
|
|
|
|
this, &GenericLinuxDeviceTester::handleConnected);
|
|
|
|
|
connect(d->connection, &SshConnection::error,
|
|
|
|
|
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:
|
|
|
|
|
d->sftpChannel->closeChannel();
|
|
|
|
|
break;
|
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");
|
2016-06-30 23:04:57 +03:00
|
|
|
connect(d->process.data(), &SshRemoteProcess::closed,
|
|
|
|
|
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);
|
|
|
|
|
|
2013-10-17 13:48:04 +02:00
|
|
|
emit errorMessage(tr("SSH connection failure: %1").arg(d->connection->errorString()) + 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::handleProcessFinished(int exitStatus)
|
2011-07-21 11:30:56 +02:00
|
|
|
{
|
2011-12-21 20:14:42 +01:00
|
|
|
QTC_ASSERT(d->state == RunningUname, return);
|
|
|
|
|
|
2012-06-08 08:23:32 +02:00
|
|
|
if (exitStatus != SshRemoteProcess::NormalExit || 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
|
|
|
|
|
|
|
|
emit progressMessage(tr("Checking if an SFTP channel can be set up..."));
|
|
|
|
|
d->sftpChannel = d->connection->createSftpChannel();
|
|
|
|
|
connect(d->sftpChannel.data(), &SftpChannel::initialized,
|
|
|
|
|
this, &GenericLinuxDeviceTester::handleSftpInitialized);
|
|
|
|
|
connect(d->sftpChannel.data(), &SftpChannel::channelError,
|
|
|
|
|
this, &GenericLinuxDeviceTester::handleSftpError);
|
|
|
|
|
d->state = TestingSftp;
|
|
|
|
|
d->sftpChannel->initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GenericLinuxDeviceTester::handleSftpInitialized()
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(d->state == TestingSftp, return);
|
|
|
|
|
emit progressMessage(tr("SFTP channel successfully initialized.\n"));
|
2011-12-21 20:14:42 +01:00
|
|
|
setFinished(TestSuccess);
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-19 17:06:52 +02:00
|
|
|
void GenericLinuxDeviceTester::handleSftpError(const QString &message)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(d->state == TestingSftp, return);
|
|
|
|
|
emit errorMessage(tr("Error setting up SFTP channel: %1\n").arg(message));
|
|
|
|
|
setFinished(TestFailure);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
disconnect(&d->portsGatherer, 0, this, 0);
|
2012-06-05 15:18:55 +02:00
|
|
|
if (d->connection) {
|
|
|
|
|
disconnect(d->connection, 0, this, 0);
|
|
|
|
|
d->connection->deleteLater();
|
|
|
|
|
d->connection = 0;
|
|
|
|
|
}
|
2011-12-21 20:14:42 +01:00
|
|
|
emit finished(result);
|
2011-07-21 11:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace RemoteLinux
|