Formatting w/ black

This commit is contained in:
Pim van Pelt
2022-04-24 10:41:35 +00:00
parent 1a1760d45c
commit 71ea1823f4
6 changed files with 14 additions and 8 deletions

View File

@ -76,6 +76,7 @@ class Validator:
The purpose is to ensure that the YAML file is both syntactically correct, The purpose is to ensure that the YAML file is both syntactically correct,
which is ensured by Yamale, and semantically correct, which is ensured by a set which is ensured by Yamale, and semantically correct, which is ensured by a set
of built-in validators, and user-added validators (see the add_validator() method).""" of built-in validators, and user-added validators (see the add_validator() method)."""
def __init__(self, schema): def __init__(self, schema):
self.logger = logging.getLogger("vppcfg.config") self.logger = logging.getLogger("vppcfg.config")
self.logger.addHandler(logging.NullHandler()) self.logger.addHandler(logging.NullHandler())

View File

@ -39,6 +39,7 @@ def example_validator(_yaml):
class YAMLTest(unittest.TestCase): class YAMLTest(unittest.TestCase):
"""This test suite takes a YAML configuration file and holds it against the syntax """This test suite takes a YAML configuration file and holds it against the syntax
(Yamale) and semantic validators, returning errors in case of validation failures.""" (Yamale) and semantic validators, returning errors in case of validation failures."""
def __init__(self, testName, yaml_filename, yaml_schema): def __init__(self, testName, yaml_filename, yaml_schema):
# calling the super class init varies for different python versions. This works for 2.7 # calling the super class init varies for different python versions. This works for 2.7
super().__init__(testName) super().__init__(testName)
@ -46,7 +47,7 @@ class YAMLTest(unittest.TestCase):
self.yaml_schema = yaml_schema self.yaml_schema = yaml_schema
def test_yaml(self): def test_yaml(self):
""" The test executor """ """The test executor"""
test = None test = None
cfg = None cfg = None
ncount = 0 ncount = 0

View File

@ -45,7 +45,9 @@ class Applier(VPPApi):
"""Delete a sub-int identified by name (ie GigabitEthernet3/0/0.100)""" """Delete a sub-int identified by name (ie GigabitEthernet3/0/0.100)"""
pass pass
def set_interface_l2_tag_rewrite(self, ifname, vtr_op, vtr_push_dot1q, vtr_tag1, vtr_tag2): def set_interface_l2_tag_rewrite(
self, ifname, vtr_op, vtr_push_dot1q, vtr_tag1, vtr_tag2
):
"""Set l2 tag rewrite on an interface identified by name (ie GigabitEthernet3/0/0.100) """Set l2 tag rewrite on an interface identified by name (ie GigabitEthernet3/0/0.100)
into a certain operational mode. TODO(pim) clarify the vtr_* arguments.""" into a certain operational mode. TODO(pim) clarify the vtr_* arguments."""
## somewhere in interface.api see vtr_* fields ## somewhere in interface.api see vtr_* fields
@ -141,7 +143,7 @@ class Applier(VPPApi):
pass pass
def set_interface_l2_bridge(self, bd_id, ifname): def set_interface_l2_bridge(self, bd_id, ifname):
"""Set an interface given by name (ie 'GigabitEthernet3/0/0') into a bridge """Set an interface given by name (ie 'GigabitEthernet3/0/0') into a bridge
domain identified by bd_id (ie 100)""" domain identified by bd_id (ie 100)"""
pass pass

View File

@ -30,11 +30,12 @@ class Dumper(VPPApi):
Note that not all running VPP configs are "valid" in vppcfg's eyes. It is not Note that not all running VPP configs are "valid" in vppcfg's eyes. It is not
guaranteed that the output of the Dumper() will stand validation.""" guaranteed that the output of the Dumper() will stand validation."""
def __init__(self, address="/run/vpp/api.sock", clientname="vppcfg"): def __init__(self, address="/run/vpp/api.sock", clientname="vppcfg"):
VPPApi.__init__(self, address, clientname) VPPApi.__init__(self, address, clientname)
def write(self, outfile): def write(self, outfile):
""" Emit the configuration to either stdout (outfile=='-') or a filename """ """Emit the configuration to either stdout (outfile=='-') or a filename"""
if outfile and outfile == "-": if outfile and outfile == "-":
file = sys.stdout file = sys.stdout
outfile = "(stdout)" outfile = "(stdout)"
@ -50,7 +51,7 @@ class Dumper(VPPApi):
self.logger.info(f"Wrote YAML config to {outfile}") self.logger.info(f"Wrote YAML config to {outfile}")
def cache_to_config(self): def cache_to_config(self):
""" Convert the VPP configuration cache (previously read by readconfig() into """Convert the VPP configuration cache (previously read by readconfig() into
a YAML representation.""" a YAML representation."""
config = { config = {
"loopbacks": {}, "loopbacks": {},

View File

@ -27,6 +27,7 @@ from vpp_papi import VPPApiClient
class VPPApi: class VPPApi:
"""The VPPApi class is a base class that abstracts the vpp_papi.""" """The VPPApi class is a base class that abstracts the vpp_papi."""
def __init__(self, address="/run/vpp/api.sock", clientname="vppcfg"): def __init__(self, address="/run/vpp/api.sock", clientname="vppcfg"):
self.logger = logging.getLogger("vppcfg.vppapi") self.logger = logging.getLogger("vppcfg.vppapi")
self.logger.addHandler(logging.NullHandler()) self.logger.addHandler(logging.NullHandler())
@ -40,7 +41,7 @@ class VPPApi:
self.lcp_enabled = False self.lcp_enabled = False
def connect(self): def connect(self):
""" Connect to the VPP Dataplane, if we're not already connected """ """Connect to the VPP Dataplane, if we're not already connected"""
if self.connected: if self.connected:
return True return True
@ -81,7 +82,7 @@ class VPPApi:
return True return True
def cache_clear(self): def cache_clear(self):
""" Remove the cached VPP configuration elements and return an empty dictionary""" """Remove the cached VPP configuration elements and return an empty dictionary"""
self.cache_read = False self.cache_read = False
return { return {
"lcps": {}, "lcps": {},

2
vppcfg
View File

@ -30,7 +30,7 @@ except ImportError:
def main(): def main():
""" The main vppcfg program """ """The main vppcfg program"""
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter) parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument( parser.add_argument(
"-d", "-d",