Lancelot: Add configurable client filtering to baseline server
(cherry picked from commit d499f7ca995e40f7a75f913ff0f07d9a73fa3559)
This commit is contained in:
parent
c3ce002a54
commit
c890bf88a7
@ -60,6 +60,7 @@ const QString PI_CreationDate(QLS("CreationDate"));
|
||||
|
||||
QString BaselineServer::storage;
|
||||
QString BaselineServer::url;
|
||||
QString BaselineServer::settingsFile;
|
||||
|
||||
BaselineServer::BaselineServer(QObject *parent)
|
||||
: QTcpServer(parent), lastRunIdIdx(0)
|
||||
@ -91,6 +92,15 @@ QString BaselineServer::baseUrl()
|
||||
return url;
|
||||
}
|
||||
|
||||
QString BaselineServer::settingsFilePath()
|
||||
{
|
||||
if (settingsFile.isEmpty()) {
|
||||
QString exeName = QCoreApplication::applicationFilePath().section(QLC('/'), -1);
|
||||
settingsFile = storagePath() + QLC('/') + exeName + QLS(".ini");
|
||||
}
|
||||
return settingsFile;
|
||||
}
|
||||
|
||||
void BaselineServer::incomingConnection(int socketDescriptor)
|
||||
{
|
||||
QString runId = QDateTime::currentDateTime().toString(QLS("MMMdd-hhmmss"));
|
||||
@ -144,6 +154,8 @@ void BaselineThread::run()
|
||||
BaselineHandler::BaselineHandler(const QString &runId, int socketDescriptor)
|
||||
: QObject(), runId(runId), connectionEstablished(false)
|
||||
{
|
||||
settings = new QSettings(BaselineServer::settingsFilePath(), QSettings::IniFormat, this);
|
||||
|
||||
if (socketDescriptor == -1)
|
||||
return;
|
||||
|
||||
@ -174,17 +186,23 @@ bool BaselineHandler::establishConnection()
|
||||
qDebug() << runId << logtime() << "Connection established with" << plat.value(PI_HostName)
|
||||
<< "[" << qPrintable(plat.value(PI_HostAddress)) << "]" << logMsg;
|
||||
|
||||
// Filter on branch
|
||||
QString branch = plat.value(PI_PulseGitBranch);
|
||||
if (branch.isEmpty()) {
|
||||
// Not run by Pulse, i.e. ad hoc run: Ok.
|
||||
}
|
||||
else if (branch != QLS("master-integration") || !plat.value(PI_GitCommit).contains(QLS("Merge branch 'master' of scm.dev.nokia.troll.no:qt/qt-fire-staging into master-integration"))) {
|
||||
qDebug() << runId << logtime() << "Did not pass branch/staging repo filter, disconnecting.";
|
||||
proto.sendBlock(BaselineProtocol::Abort, QByteArray("This branch/staging repo is not assigned to be tested."));
|
||||
settings->beginGroup("ClientFilters");
|
||||
if (!settings->childKeys().isEmpty()) {
|
||||
// Abort if client does not match the filters
|
||||
foreach(QString filterKey, settings->childKeys()) {
|
||||
QString filter = settings->value(filterKey).toString();
|
||||
QString platVal = plat.value(filterKey);
|
||||
if (filter.isEmpty() || platVal.isEmpty())
|
||||
continue; // tbd: add a syntax for specifying a "value-must-be-present" filter
|
||||
if (!platVal.contains(filter)) {
|
||||
qDebug() << runId << logtime() << "Did not pass client filter on" << filterKey << "; disconnecting.";
|
||||
proto.sendBlock(BaselineProtocol::Abort, QByteArray("Configured to not do testing for this client or repo, ref. ") + BaselineServer::settingsFilePath().toLatin1());
|
||||
proto.socket.disconnectFromHost();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
settings->endGroup();
|
||||
|
||||
proto.sendBlock(BaselineProtocol::Ack, QByteArray());
|
||||
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include <QScopedPointer>
|
||||
#include <QTimer>
|
||||
#include <QDateTime>
|
||||
#include <QSettings>
|
||||
|
||||
#include "baselineprotocol.h"
|
||||
#include "report.h"
|
||||
@ -65,6 +66,7 @@ public:
|
||||
|
||||
static QString storagePath();
|
||||
static QString baseUrl();
|
||||
static QString settingsFilePath();
|
||||
|
||||
protected:
|
||||
void incomingConnection(int socketDescriptor);
|
||||
@ -79,6 +81,7 @@ private:
|
||||
int lastRunIdIdx;
|
||||
static QString storage;
|
||||
static QString url;
|
||||
static QString settingsFile;
|
||||
};
|
||||
|
||||
|
||||
@ -132,6 +135,7 @@ private:
|
||||
QString runId;
|
||||
bool connectionEstablished;
|
||||
Report report;
|
||||
QSettings *settings;
|
||||
};
|
||||
|
||||
#endif // BASELINESERVER_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user