summaryrefslogtreecommitdiffstats
path: root/test/test_syslog.py
diff options
context:
space:
mode:
authorKlement Sekera <klement.sekera@gmail.com>2022-04-26 19:02:15 +0200
committerOle Tr�an <otroan@employees.org>2022-05-10 18:52:08 +0000
commitd9b0c6fbf7aa5bd9af84264105b39c82028a4a29 (patch)
tree4f786cfd8ebc2443cb11e11b74c8657204068898 /test/test_syslog.py
parentf90348bcb4afd0af2611cefc43b17ef3042b511c (diff)
tests: replace pycodestyle with black
Drop pycodestyle for code style checking in favor of black. Black is much faster, stable PEP8 compliant code style checker offering also automatic formatting. It aims to be very stable and produce smallest diffs. It's used by many small and big projects. Running checkstyle with black takes a few seconds with a terse output. Thus, test-checkstyle-diff is no longer necessary. Expand scope of checkstyle to all python files in the repo, replacing test-checkstyle with checkstyle-python. Also, fixstyle-python is now available for automatic style formatting. Note: python virtualenv has been consolidated in test/Makefile, test/requirements*.txt which will eventually be moved to a central location. This is required to simply the automated generation of docker executor images in the CI. Type: improvement Change-Id: I022a326603485f58585e879ac0f697fceefbc9c8 Signed-off-by: Klement Sekera <klement.sekera@gmail.com> Signed-off-by: Dave Wallace <dwallacelf@gmail.com>
Diffstat (limited to 'test/test_syslog.py')
-rw-r--r--test/test_syslog.py206
1 files changed, 114 insertions, 92 deletions
diff --git a/test/test_syslog.py b/test/test_syslog.py
index b084a1d1846..b84c89c57d0 100644
--- a/test/test_syslog.py
+++ b/test/test_syslog.py
@@ -11,7 +11,7 @@ from vpp_papi import VppEnum
class TestSyslog(VppTestCase):
- """ Syslog Protocol Test Cases """
+ """Syslog Protocol Test Cases"""
@property
def SYSLOG_SEVERITY(self):
@@ -22,7 +22,7 @@ class TestSyslog(VppTestCase):
super(TestSyslog, cls).setUpClass()
try:
- cls.pg0, = cls.create_pg_interfaces(range(1))
+ (cls.pg0,) = cls.create_pg_interfaces(range(1))
cls.pg0.admin_up()
cls.pg0.config_ip4()
cls.pg0.resolve_arp()
@@ -35,8 +35,7 @@ class TestSyslog(VppTestCase):
def tearDownClass(cls):
super(TestSyslog, cls).tearDownClass()
- def syslog_generate(self, facility, severity, appname, msgid, sd=None,
- msg=None):
+ def syslog_generate(self, facility, severity, appname, msgid, sd=None, msg=None):
"""
Generate syslog message
@@ -47,20 +46,50 @@ class TestSyslog(VppTestCase):
:param sd: structured data (optional)
:param msg: free-form message (optional)
"""
- facility_str = ['kernel', 'user-level', 'mail-system',
- 'system-daemons', 'security-authorization', 'syslogd',
- 'line-printer', 'network-news', 'uucp', 'clock-daemon',
- '', 'ftp-daemon', 'ntp-subsystem', 'log-audit',
- 'log-alert', '', 'local0', 'local1', 'local2',
- 'local3', 'local4', 'local5', 'local6', 'local7']
-
- severity_str = ['emergency', 'alert', 'critical', 'error', 'warning',
- 'notice', 'informational', 'debug']
-
- cli_str = "test syslog %s %s %s %s" % (facility_str[facility],
- severity_str[severity],
- appname,
- msgid)
+ facility_str = [
+ "kernel",
+ "user-level",
+ "mail-system",
+ "system-daemons",
+ "security-authorization",
+ "syslogd",
+ "line-printer",
+ "network-news",
+ "uucp",
+ "clock-daemon",
+ "",
+ "ftp-daemon",
+ "ntp-subsystem",
+ "log-audit",
+ "log-alert",
+ "",
+ "local0",
+ "local1",
+ "local2",
+ "local3",
+ "local4",
+ "local5",
+ "local6",
+ "local7",
+ ]
+
+ severity_str = [
+ "emergency",
+ "alert",
+ "critical",
+ "error",
+ "warning",
+ "notice",
+ "informational",
+ "debug",
+ ]
+
+ cli_str = "test syslog %s %s %s %s" % (
+ facility_str[facility],
+ severity_str[severity],
+ appname,
+ msgid,
+ )
if sd is not None:
for sd_id, sd_params in sd.items():
cli_str += " sd-id %s" % (sd_id)
@@ -70,8 +99,9 @@ class TestSyslog(VppTestCase):
cli_str += " %s" % (msg)
self.vapi.cli(cli_str)
- def syslog_verify(self, data, facility, severity, appname, msgid, sd=None,
- msg=None):
+ def syslog_verify(
+ self, data, facility, severity, appname, msgid, sd=None, msg=None
+ ):
"""
Verify syslog message
@@ -83,7 +113,7 @@ class TestSyslog(VppTestCase):
:param sd: structured data (optional)
:param msg: free-form message (optional)
"""
- message = data.decode('utf-8')
+ message = data.decode("utf-8")
if sd is None:
sd = {}
try:
@@ -102,35 +132,32 @@ class TestSyslog(VppTestCase):
self.assertEqual(message.hostname, self.pg0.local_ip4)
def test_syslog(self):
- """ Syslog Protocol test """
- self.vapi.syslog_set_sender(src_address=self.pg0.local_ip4,
- collector_address=self.pg0.remote_ip4)
+ """Syslog Protocol test"""
+ self.vapi.syslog_set_sender(
+ src_address=self.pg0.local_ip4, collector_address=self.pg0.remote_ip4
+ )
config = self.vapi.syslog_get_sender()
- self.assertEqual(str(config.collector_address),
- self.pg0.remote_ip4)
+ self.assertEqual(str(config.collector_address), self.pg0.remote_ip4)
self.assertEqual(config.collector_port, 514)
self.assertEqual(str(config.src_address), self.pg0.local_ip4)
self.assertEqual(config.vrf_id, 0)
self.assertEqual(config.max_msg_size, 480)
- appname = 'test'
- msgid = 'testMsg'
- msg = 'this is message'
- sd1 = {'exampleSDID@32473': {'iut': '3',
- 'eventSource': 'App',
- 'eventID': '1011'}}
- sd2 = {'exampleSDID@32473': {'iut': '3',
- 'eventSource': 'App',
- 'eventID': '1011'},
- 'examplePriority@32473': {'class': 'high'}}
+ appname = "test"
+ msgid = "testMsg"
+ msg = "this is message"
+ sd1 = {
+ "exampleSDID@32473": {"iut": "3", "eventSource": "App", "eventID": "1011"}
+ }
+ sd2 = {
+ "exampleSDID@32473": {"iut": "3", "eventSource": "App", "eventID": "1011"},
+ "examplePriority@32473": {"class": "high"},
+ }
self.pg_enable_capture(self.pg_interfaces)
- self.syslog_generate(SyslogFacility.local7,
- SyslogSeverity.info,
- appname,
- msgid,
- None,
- msg)
+ self.syslog_generate(
+ SyslogFacility.local7, SyslogSeverity.info, appname, msgid, None, msg
+ )
capture = self.pg0.get_capture(1)
try:
self.assertEqual(capture[0][IP].src, self.pg0.local_ip4)
@@ -140,71 +167,66 @@ class TestSyslog(VppTestCase):
except:
self.logger.error(ppp("invalid packet:", capture[0]))
raise
- self.syslog_verify(capture[0][Raw].load,
- SyslogFacility.local7,
- SyslogSeverity.info,
- appname,
- msgid,
- None,
- msg)
+ self.syslog_verify(
+ capture[0][Raw].load,
+ SyslogFacility.local7,
+ SyslogSeverity.info,
+ appname,
+ msgid,
+ None,
+ msg,
+ )
self.pg_enable_capture(self.pg_interfaces)
- self.vapi.syslog_set_filter(
- self.SYSLOG_SEVERITY.SYSLOG_API_SEVERITY_WARN)
+ self.vapi.syslog_set_filter(self.SYSLOG_SEVERITY.SYSLOG_API_SEVERITY_WARN)
filter = self.vapi.syslog_get_filter()
- self.assertEqual(filter.severity,
- self.SYSLOG_SEVERITY.SYSLOG_API_SEVERITY_WARN)
- self.syslog_generate(SyslogFacility.local7,
- SyslogSeverity.info,
- appname,
- msgid,
- None,
- msg)
+ self.assertEqual(filter.severity, self.SYSLOG_SEVERITY.SYSLOG_API_SEVERITY_WARN)
+ self.syslog_generate(
+ SyslogFacility.local7, SyslogSeverity.info, appname, msgid, None, msg
+ )
self.pg0.assert_nothing_captured()
self.pg_enable_capture(self.pg_interfaces)
- self.syslog_generate(SyslogFacility.local6,
- SyslogSeverity.warning,
- appname,
- msgid,
- sd1,
- msg)
+ self.syslog_generate(
+ SyslogFacility.local6, SyslogSeverity.warning, appname, msgid, sd1, msg
+ )
capture = self.pg0.get_capture(1)
- self.syslog_verify(capture[0][Raw].load,
- SyslogFacility.local6,
- SyslogSeverity.warning,
- appname,
- msgid,
- sd1,
- msg)
-
- self.vapi.syslog_set_sender(self.pg0.local_ip4,
- self.pg0.remote_ip4,
- collector_port=12345)
+ self.syslog_verify(
+ capture[0][Raw].load,
+ SyslogFacility.local6,
+ SyslogSeverity.warning,
+ appname,
+ msgid,
+ sd1,
+ msg,
+ )
+
+ self.vapi.syslog_set_sender(
+ self.pg0.local_ip4, self.pg0.remote_ip4, collector_port=12345
+ )
config = self.vapi.syslog_get_sender()
self.assertEqual(config.collector_port, 12345)
self.pg_enable_capture(self.pg_interfaces)
- self.syslog_generate(SyslogFacility.local5,
- SyslogSeverity.err,
- appname,
- msgid,
- sd2,
- None)
+ self.syslog_generate(
+ SyslogFacility.local5, SyslogSeverity.err, appname, msgid, sd2, None
+ )
capture = self.pg0.get_capture(1)
try:
self.assertEqual(capture[0][UDP].dport, 12345)
except:
self.logger.error(ppp("invalid packet:", capture[0]))
raise
- self.syslog_verify(capture[0][Raw].load,
- SyslogFacility.local5,
- SyslogSeverity.err,
- appname,
- msgid,
- sd2,
- None)
-
-
-if __name__ == '__main__':
+ self.syslog_verify(
+ capture[0][Raw].load,
+ SyslogFacility.local5,
+ SyslogSeverity.err,
+ appname,
+ msgid,
+ sd2,
+ None,
+ )
+
+
+if __name__ == "__main__":
unittest.main(testRunner=VppTestRunner)