_healthCheckCounter = 0
_answerUnexpected = True
_checkConfigExpectedOutput = None
+ _checkConfigExpectedOutputPrefix = None
_verboseMode = False
_sudoMode = False
_skipListeningOnCL = False
output = subprocess.check_output(testcmd, stderr=subprocess.STDOUT, close_fds=True)
except subprocess.CalledProcessError as exc:
raise AssertionError('dnsdist --check-config failed (%d): %s' % (exc.returncode, exc.output))
- if cls._checkConfigExpectedOutput is not None:
- expectedOutput = cls._checkConfigExpectedOutput
+
+ if cls._checkConfigExpectedOutputPrefix is not None:
+ if not output.startswith(cls._checkConfigExpectedOutputPrefix):
+ raise AssertionError('dnsdist --check-config failed: %s (expected prefix %s)' % (output, cls._checkConfigExpectedOutputPrefix))
else:
- expectedOutput = ('Configuration \'%s\' OK!\n' % (confFile)).encode()
- if not cls._verboseMode and output != expectedOutput:
- raise AssertionError('dnsdist --check-config failed: %s (expected %s)' % (output, expectedOutput))
+ if cls._checkConfigExpectedOutput is not None:
+ expectedOutput = cls._checkConfigExpectedOutput
+ else:
+ expectedOutput = ('Configuration \'%s\' OK!\n' % (confFile)).encode()
+
+ if not cls._verboseMode and output != expectedOutput:
+ raise AssertionError('dnsdist --check-config failed: %s (expected %s)' % (output, expectedOutput))
logFile = os.path.join('configs', 'dnsdist_%s.log' % (cls.__name__))
with open(logFile, 'w') as fdLog:
--- /dev/null
+#!/usr/bin/env python
+from dnsdisttests import DNSDistTest, pickAvailablePort
+
+class TestStructuredLoggingDefaultBackendFromYaml(DNSDistTest):
+
+ _yaml_config_template = """---
+binds:
+ - listen_address: "127.0.0.1:%d"
+ protocol: Do53
+
+backends:
+ - address: "127.0.0.1:%d"
+ protocol: Do53
+
+logging:
+ structured:
+ enabled: true
+"""
+ _dnsDistPort = pickAvailablePort()
+ _testServerPort = pickAvailablePort()
+ _yaml_config_params = ['_dnsDistPort', '_testServerPort']
+ _config_params = []
+ _checkConfigExpectedOutput = None
+ _checkConfigExpectedOutputPrefix = b'msg="Configuration OK" subsystem="setup"'
+
+ def testOK(self):
+ pass
+
+class TestStructuredLoggingJSONBackendFromYaml(DNSDistTest):
+
+ _yaml_config_template = """---
+binds:
+ - listen_address: "127.0.0.1:%d"
+ protocol: Do53
+
+backends:
+ - address: "127.0.0.1:%d"
+ protocol: Do53
+
+logging:
+ structured:
+ enabled: true
+ backend: "json"
+"""
+ _dnsDistPort = pickAvailablePort()
+ _testServerPort = pickAvailablePort()
+ _yaml_config_params = ['_dnsDistPort', '_testServerPort']
+ _config_params = []
+ _checkConfigExpectedOutput = None
+ _checkConfigExpectedOutputPrefix = b'{"level": "0", "msg": "Configuration OK", "path":'
+
+ def testOK(self):
+ pass
+
+class TestStructuredLoggingDefaultBackendFromLua(DNSDistTest):
+
+ _config_template = """
+setStructuredLogging(true)
+
+newServer{address="127.0.0.1:%d"}
+"""
+ _testServerPort = pickAvailablePort()
+ _checkConfigExpectedOutput = None
+ _checkConfigExpectedOutputPrefix = b'msg="Configuration OK" subsystem="setup"'
+
+ def testOK(self):
+ pass
+
+class TestStructuredLoggingJSONBackendFromLua(DNSDistTest):
+
+ _config_template = """
+setStructuredLogging(true, {backend="json"})
+
+newServer{address="127.0.0.1:%d"}
+"""
+ _testServerPort = pickAvailablePort()
+ _checkConfigExpectedOutput = None
+ _checkConfigExpectedOutputPrefix = b'{"level": "0", "msg": "Configuration OK", "path":'
+
+ def testOK(self):
+ pass