mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-05-28 06:32:32 +02:00
2025-04-29 Fred Gleason <fredg@paravelsystems.com>
* Modified regex code in ' RDConfig::provisioningHostShortName()' and 'RDConfig::provisioningServiceName()' to use the QRegularExpression class rather than QRegExp. * Added a 'test_provisioning' test harness in 'tests/'. Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
parent
632739f59a
commit
77b1dde5c1
1
.gitignore
vendored
1
.gitignore
vendored
@ -155,6 +155,7 @@ tests/mcast_recv_test
|
||||
tests/metadata_wildcard_test
|
||||
tests/meterstrip_test
|
||||
tests/notification_test
|
||||
tests/provisioning_test
|
||||
tests/rdwavefile_test
|
||||
tests/rdxml_parse_test
|
||||
tests/readcd_test
|
||||
|
@ -25058,3 +25058,8 @@
|
||||
2025-04-28 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Added a '--dump-config' switch to the set of common options
|
||||
in 'RDCoreApplications'.
|
||||
2025-04-29 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Modified regex code in ' RDConfig::provisioningHostShortName()' and
|
||||
'RDConfig::provisioningServiceName()' to use the QRegularExpression
|
||||
class rather than QRegExp.
|
||||
* Added a 'test_provisioning' test harness in 'tests/'.
|
||||
|
@ -117,7 +117,7 @@ XportHostname=
|
||||
CreateHost=No
|
||||
NewHostTemplate=some_host_entry
|
||||
NewHostIpAddress=lo
|
||||
NewHostShortNameRegex=[^*]*
|
||||
NewHostShortNameRegex=(\w+)-(\w+)
|
||||
NewHostShortNameGroup=0
|
||||
|
||||
; If CreateService=Yes, a Service entry will be automatically created in the DB
|
||||
@ -128,7 +128,7 @@ NewHostShortNameGroup=0
|
||||
; captured group from the regex specified in 'NewServiceNameGroup='.
|
||||
CreateService=No
|
||||
NewServiceTemplate=some_service_entry
|
||||
NewServiceNameRegex=[^*]*
|
||||
NewServiceNameRegex=(\w+)-(\w+)
|
||||
NewServiceNameGroup=0
|
||||
|
||||
[Logs]
|
||||
|
16
configure.ac
16
configure.ac
@ -89,21 +89,6 @@ AC_ARG_ENABLE(rdxport-debug,[ --enable-rdxport-debug enable DEBUG support for
|
||||
AC_ARG_ENABLE(i18n-updates,[ --enable-i18n-updates enable I18N metadata updates],
|
||||
[I18N_ENABLED=yes],[])
|
||||
|
||||
|
||||
#
|
||||
# Check for Qt5 (Mandatory)
|
||||
#
|
||||
#PKG_CHECK_MODULES(QT5,Qt5Core Qt5Widgets Qt5Gui Qt5Network Qt5Sql Qt5Xml Qt5WebKitWidgets,,[AC_MSG_ERROR([*** Qt5 not found ***])])
|
||||
#PKG_CHECK_MODULES(QT5_CLI,Qt5Core Qt5Network Qt5Sql Qt5Xml,,[AC_MSG_ERROR([*** Qt5 not found ***])])
|
||||
#AC_CHECK_PROG(MOC_NAME,moc-qt5,[moc-qt5],[moc])
|
||||
#AC_SUBST(QT_MOC,$MOC_NAME)
|
||||
|
||||
#AC_CHECK_PROG(LUPDATE_NAME,lupdate-qt5,[lupdate-qt5],[lupdate])
|
||||
#AC_SUBST(QT_LUPDATE,$LUPDATE_NAME)
|
||||
|
||||
#AC_CHECK_PROG(LRELEASE_NAME,lrelease-qt5,[lrelease-qt5],[lrelease])
|
||||
#AC_SUBST(QT_LRELEASE,$LRELEASE_NAME)
|
||||
|
||||
#
|
||||
# Check for Qt6 (Mandatory)
|
||||
#
|
||||
@ -115,7 +100,6 @@ AC_SUBST(QT_LUPDATE,$LUPDATE_NAME)
|
||||
AC_CHECK_PROG(LRELEASE_NAME,lrelease-qt6,[lrelease-qt6],[lrelease])
|
||||
AC_SUBST(QT_LRELEASE,$LRELEASE_NAME)
|
||||
|
||||
|
||||
#
|
||||
# Determine the target architecture
|
||||
#
|
||||
|
@ -536,7 +536,8 @@
|
||||
<listitem>
|
||||
<para>
|
||||
The name of an existing network interface from which to
|
||||
extract the IP address of a newly provisioned Host.
|
||||
extract the IP address to be assigned to a newly provisioned
|
||||
Host entry.
|
||||
</para>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
@ -546,7 +547,7 @@
|
||||
</term>
|
||||
<listitem>
|
||||
<para>
|
||||
A regular express to use when setting the Short Name of a
|
||||
A regular expression to use when setting the Short Name of a
|
||||
newly provisioned Host from the system host name.
|
||||
</para>
|
||||
</listitem>
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QObject>
|
||||
#include <QRegExp>
|
||||
#include <QRegularExpression>
|
||||
#include <QSettings>
|
||||
#include <QStringList>
|
||||
|
||||
@ -255,17 +255,10 @@ QHostAddress RDConfig::provisioningHostIpAddress() const
|
||||
|
||||
QString RDConfig::provisioningHostShortName(const QString &hostname) const
|
||||
{
|
||||
/*
|
||||
* FIXME: Reimplement using QRegularExpression
|
||||
*/
|
||||
QRegExp exp(conf_provisioning_host_short_name_regex);
|
||||
QRegularExpression regex(conf_provisioning_host_short_name_regex);
|
||||
QRegularExpressionMatch match=regex.match(hostname);
|
||||
|
||||
exp.indexIn(hostname);
|
||||
QStringList texts=exp.capturedTexts();
|
||||
if((unsigned)texts.size()<conf_provisioning_host_short_name_group) {
|
||||
return QString();
|
||||
}
|
||||
return texts[conf_provisioning_host_short_name_group];
|
||||
return match.captured(conf_provisioning_host_short_name_group);
|
||||
}
|
||||
|
||||
|
||||
@ -283,19 +276,10 @@ QString RDConfig::provisioningServiceTemplate() const
|
||||
|
||||
QString RDConfig::provisioningServiceName(const QString &hostname) const
|
||||
{
|
||||
/*
|
||||
* FIXME: Reimplement using QRegularExpression
|
||||
*
|
||||
QRegExp exp(conf_provisioning_service_name_regex);
|
||||
QRegularExpression regex(conf_provisioning_service_name_regex);
|
||||
QRegularExpressionMatch match=regex.match(hostname);
|
||||
|
||||
exp.indexIn(hostname);
|
||||
QStringList texts=exp.capturedTexts();
|
||||
if((unsigned)texts.size()<conf_provisioning_service_name_group) {
|
||||
return QString();
|
||||
}
|
||||
return texts[conf_provisioning_service_name_group];
|
||||
*/
|
||||
return QString();
|
||||
return match.captured(conf_provisioning_service_name_group);
|
||||
}
|
||||
|
||||
|
||||
|
@ -46,6 +46,7 @@ noinst_PROGRAMS = audio_convert_test\
|
||||
metadata_wildcard_test\
|
||||
meterstrip_test\
|
||||
notification_test\
|
||||
provisioning_test\
|
||||
rdwavefile_test\
|
||||
rdxml_parse_test\
|
||||
readcd_test\
|
||||
@ -130,6 +131,10 @@ dist_notification_test_SOURCES = notification_test.cpp notification_test.h
|
||||
nodist_notification_test_SOURCES = moc_notification_test.cpp
|
||||
notification_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT6_LIBS@ @MUSICBRAINZ_LIBS@ @IMAGEMAGICK_LIBS@
|
||||
|
||||
dist_provisioning_test_SOURCES = provisioning_test.cpp provisioning_test.h
|
||||
nodist_provisioning_test_SOURCES = moc_provisioning_test.cpp
|
||||
provisioning_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT6_LIBS@ @MUSICBRAINZ_LIBS@ @IMAGEMAGICK_LIBS@
|
||||
|
||||
dist_rdwavefile_test_SOURCES = rdwavefile_test.cpp rdwavefile_test.h
|
||||
nodist_rdwavefile_test_SOURCES = moc_rdwavefile_test.cpp
|
||||
rdwavefile_test_LDADD = @LIB_RDLIBS@ @LIBVORBIS@ @QT6_LIBS@ @MUSICBRAINZ_LIBS@ @IMAGEMAGICK_LIBS@
|
||||
|
92
tests/provisioning_test.cpp
Normal file
92
tests/provisioning_test.cpp
Normal file
@ -0,0 +1,92 @@
|
||||
// provisioning_test.cpp
|
||||
//
|
||||
// Test Rivendell provisioning methods in RDConfig.
|
||||
//
|
||||
// (C) Copyright 2025 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public
|
||||
// License along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
||||
#include <rd.h>
|
||||
#include <rdcmd_switch.h>
|
||||
#include <rdconfig.h>
|
||||
|
||||
#include "provisioning_test.h"
|
||||
|
||||
MainObject::MainObject(QObject *parent)
|
||||
:QObject(parent)
|
||||
{
|
||||
QString config_filename=RD_CONF_FILE;
|
||||
QString test_host_name;
|
||||
|
||||
//
|
||||
// Read Command Line
|
||||
//
|
||||
RDCmdSwitch *cmd=new RDCmdSwitch("provisioning_test",PROVISIONING_TEST_USAGE);
|
||||
for(unsigned i=0;i<cmd->keys();i++) {
|
||||
if(cmd->key(i)=="--config-file") {
|
||||
config_filename=cmd->value(i);
|
||||
cmd->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--test-host-name") {
|
||||
test_host_name=cmd->value(i);
|
||||
cmd->setProcessed(i,true);
|
||||
}
|
||||
if(!cmd->processed(i)) {
|
||||
fprintf(stderr,"provisioning_test: unknown option\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if(test_host_name.isEmpty()) {
|
||||
char name[HOST_NAME_MAX];
|
||||
if(gethostname(name,HOST_NAME_MAX)<0) {
|
||||
fprintf(stderr,"provisioning_test: %s\n",strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
test_host_name=QString::fromUtf8(name);
|
||||
}
|
||||
|
||||
//
|
||||
// Run Test
|
||||
//
|
||||
RDConfig *config=new RDConfig(config_filename);
|
||||
if(!config->load()) {
|
||||
fprintf(stderr,"provisioning_test: failed to load config file\n");
|
||||
exit(1);
|
||||
}
|
||||
printf(" Config File: %s\n",config_filename.toUtf8().constData());
|
||||
printf("Test Hostname: %s\n",test_host_name.toUtf8().constData());
|
||||
printf("\n");
|
||||
printf("provisiongHostShortName: %s\n",
|
||||
config->provisioningHostShortName(test_host_name).toUtf8().constData());
|
||||
printf("provisioningServiceName: %s\n",
|
||||
config->provisioningServiceName(test_host_name).toUtf8().constData());
|
||||
printf("provisioningHostIpAddress: %s\n",
|
||||
config->provisioningHostIpAddress().toString().toUtf8().constData());
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
QCoreApplication a(argc,argv,false);
|
||||
new MainObject();
|
||||
return a.exec();
|
||||
}
|
36
tests/provisioning_test.h
Normal file
36
tests/provisioning_test.h
Normal file
@ -0,0 +1,36 @@
|
||||
// provisioning_test.h
|
||||
//
|
||||
// Test Rivendell provisioning methods in RDConfig.
|
||||
//
|
||||
// (C) Copyright 2025 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public
|
||||
// License along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#ifndef PROVISIONING_TEST_H
|
||||
#define PROVISIONING_TEST_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#define PROVISIONING_TEST_USAGE "--config-file=<filename> --test-host-name=<hostname>"
|
||||
|
||||
class MainObject : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MainObject(QObject *parent=0);
|
||||
};
|
||||
|
||||
|
||||
#endif // PROVISIONING_TEST_H
|
Loading…
x
Reference in New Issue
Block a user