aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_cdp.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_cdp.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_cdp.py')
-rw-r--r--test/test_cdp.py53
1 files changed, 30 insertions, 23 deletions
diff --git a/test/test_cdp.py b/test/test_cdp.py
index 46751e81d86..da378dbebe3 100644
--- a/test/test_cdp.py
+++ b/test/test_cdp.py
@@ -4,8 +4,13 @@
from scapy.packet import Packet
from scapy.all import ShortField, StrField
from scapy.layers.l2 import Dot3, LLC, SNAP
-from scapy.contrib.cdp import CDPMsgDeviceID, CDPMsgSoftwareVersion, \
- CDPMsgPlatform, CDPMsgPortID, CDPv2_HDR
+from scapy.contrib.cdp import (
+ CDPMsgDeviceID,
+ CDPMsgSoftwareVersion,
+ CDPMsgPlatform,
+ CDPMsgPortID,
+ CDPv2_HDR,
+)
from framework import VppTestCase
from scapy.all import raw
@@ -25,18 +30,17 @@ CDP test.
class CustomTLV(Packet):
- """ Custom TLV protocol layer for scapy """
+ """Custom TLV protocol layer for scapy"""
fields_desc = [
ShortField("type", 0),
ShortField("length", 4),
- StrField("value", "")
-
+ StrField("value", ""),
]
class TestCDP(VppTestCase):
- """ CDP Test Case """
+ """CDP Test Case"""
nen_ptr = compile(r"not enabled")
cdp_ptr = compile(r"^([-\.\w]+)\s+([-\.\w]+)\s+([-\.\w]+)\s+([-\.\w]+)$")
@@ -95,8 +99,9 @@ class TestCDP(VppTestCase):
length = min(len(system), len(self.device_id))
self.assert_equal(port, self.port_id, "CDP received invalid port id")
- self.assert_equal(system[:length], self.device_id[:length],
- "CDP received invalid device id")
+ self.assert_equal(
+ system[:length], self.device_id[:length], "CDP received invalid device id"
+ )
def test_cdp_underflow_tlv(self):
self.send_bad_packet(3, ".")
@@ -109,7 +114,8 @@ class TestCDP(VppTestCase):
self.send_packet(self.create_bad_packet(l, v))
err = self.statistics.get_err_counter(
- '/err/cdp-input/cdp packets with bad TLVs')
+ "/err/cdp-input/cdp packets with bad TLVs"
+ )
self.assertTrue(err >= 1, "CDP didn't drop bad packet")
def send_packet(self, packet):
@@ -118,29 +124,30 @@ class TestCDP(VppTestCase):
self.pg_start()
def create_base_packet(self):
- packet = (Dot3(src=self.interface.remote_mac,
- dst="01:00:0c:cc:cc:cc") /
- LLC(dsap=0xaa, ssap=0xaa, ctrl=0x03) /
- SNAP()/CDPv2_HDR())
+ packet = (
+ Dot3(src=self.interface.remote_mac, dst="01:00:0c:cc:cc:cc")
+ / LLC(dsap=0xAA, ssap=0xAA, ctrl=0x03)
+ / SNAP()
+ / CDPv2_HDR()
+ )
return packet
def create_packet(self):
- packet = (self.create_base_packet() /
- CDPMsgDeviceID(val=self.device_id) /
- CDPMsgSoftwareVersion(val=self.version) /
- CDPMsgPortID(iface=self.port_id) /
- CDPMsgPlatform(val=self.platform))
+ packet = (
+ self.create_base_packet()
+ / CDPMsgDeviceID(val=self.device_id)
+ / CDPMsgSoftwareVersion(val=self.version)
+ / CDPMsgPortID(iface=self.port_id)
+ / CDPMsgPlatform(val=self.platform)
+ )
return packet
def create_bad_packet(self, tl=4, tv=""):
- packet = (self.create_base_packet() /
- CustomTLV(type=1,
- length=tl,
- value=tv))
+ packet = self.create_base_packet() / CustomTLV(type=1, length=tl, value=tv)
return packet
def process_cli(self, exp, ptr):
- for line in self.vapi.cli(exp).split('\n')[1:]:
+ for line in self.vapi.cli(exp).split("\n")[1:]:
m = ptr.match(line.strip())
if m:
yield m.groups()