Add unit tests for loopbacks; While here, fix a bug in get_by_name(), yaay

This commit is contained in:
Pim van Pelt
2022-03-22 18:02:35 +00:00
parent 36fbbf9b35
commit 5ecd1ef22c
3 changed files with 47 additions and 1 deletions

View File

@ -19,6 +19,14 @@ class NullHandler(logging.Handler):
def emit(self, record):
pass
def get_loopbacks(yaml):
""" Return a list of all loopbacks. """
ret = []
if 'loopbacks' in yaml:
for ifname, iface in yaml['loopbacks'].items():
ret.append(ifname)
return ret
def get_by_name(yaml, ifname):
""" Return the loopback by name, if it exists. Return None otherwise. """
try:
@ -26,7 +34,7 @@ def get_by_name(yaml, ifname):
return ifname, yaml['loopbacks'][ifname]
except:
pass
return None
return None, None
def validate_loopbacks(yaml):