change cfg file format

config file format change:

The section names no longer contain a space, the are either
bare module names or 'NODE' or 'INTERFACE' (capitalized in order to
distingish from module names).

The present code still accepts the old form.

Moving to the 'toml' format was considered too, but this needs some
more investigations. The necessary code changes would be limited
to the method Server.loadCfgFile.

Change-Id: I6020058c9dcc4c1cbf38f5b9e8f67e9aad670183
Reviewed-on: https://forge.frm2.tum.de/review/c/sine2020/secop/playground/+/23031
Reviewed-by: Enrico Faulhaber <enrico.faulhaber@frm2.tum.de>
Reviewed-by: Markus Zolliker <markus.zolliker@psi.ch>
Tested-by: JenkinsCodeReview <bjoern_pedersen@frm2.tum.de>
This commit is contained in:
2020-05-01 15:02:41 +02:00
parent bdb754976f
commit 64a3bf534b
4 changed files with 145 additions and 167 deletions

View File

@ -26,11 +26,11 @@ import socket
import collections
import socketserver
from secop.datatypes import StringType, IntRange, BoolType
from secop.datatypes import StringType, BoolType
from secop.errors import SECoPError
from secop.lib import formatException, \
formatExtendedStack, formatExtendedTraceback
from secop.properties import HasProperties, Property
from secop.properties import Property
from secop.protocol.interface import decode_msg, encode_msg_frame, get_msg
from secop.protocol.messages import ERRORPREFIX, \
HELPREPLY, HELPREQUEST, HelpMessage
@ -187,42 +187,27 @@ class TCPRequestHandler(socketserver.BaseRequestHandler):
self.request.close()
class TCPServer(HasProperties, socketserver.ThreadingTCPServer):
class TCPServer(socketserver.ThreadingTCPServer):
daemon_threads = True
allow_reuse_address = True
properties = {
'bindto': Property('hostname or ip address for binding', StringType(),
default='localhost:%d' % DEF_PORT, export=False),
'bindport': Property('port number to bind', IntRange(1, 65535),
default=DEF_PORT, export=False),
# for cfg-editor
configurables = {
'uri': Property('hostname or ip address for binding', StringType(),
default='tcp://%d' % DEF_PORT, export=False),
'detailed_errors': Property('Flag to enable detailed Errorreporting.', BoolType(),
default=False, export=False),
}
# XXX: create configurables from Metaclass!
configurables = properties
def __init__(self, name, logger, options, srv): # pylint: disable=super-init-not-called
self.dispatcher = srv.dispatcher
self.name = name
self.log = logger
# do not call HasProperties.__init__, as this will supercall ThreadingTCPServer
self.initProperties()
bindto = options.pop('bindto', 'localhost')
bindport = int(options.pop('bindport', DEF_PORT))
detailed_errors = options.pop('detailed_errors', False)
if ':' in bindto:
bindto, _port = bindto.rsplit(':')
bindport = int(_port)
self.setProperty('bindto', bindto)
self.setProperty('bindport', bindport)
self.setProperty('detailed_errors', detailed_errors)
self.checkProperties()
port = int(options.pop('uri').split('://', 1)[-1])
self.detailed_errors = options.pop('detailed_errors', False)
self.allow_reuse_address = True
self.log.info("TCPServer %s binding to %s:%d" % (name, self.bindto, self.bindport))
self.log.info("TCPServer %s binding to port %d" % (name, port))
socketserver.ThreadingTCPServer.__init__(
self, (self.bindto, self.bindport), TCPRequestHandler, bind_and_activate=True)
self, ('0.0.0.0', port), TCPRequestHandler, bind_and_activate=True)
self.log.info("TCPServer initiated")