Move to f-strings

Used:
$ flynt -a -tc . vppcfg

Execution time:                            0.216s
Files checked:                             24
Files modified:                            13
Character count reduction:                 632 (0.36%)

Per expression type:
Old style (`%`) expressions attempted:     209/211 (99.1%)
No `.format(...)` calls attempted.
No concatenations attempted.
F-string expressions created:              205

Ran an integration test before and after. No diffs.
This commit is contained in:
Pim van Pelt
2022-04-22 10:58:41 +00:00
parent 13cdba1e1d
commit e13694a566
13 changed files with 205 additions and 205 deletions

View File

@ -87,17 +87,17 @@ class Validator(object):
validators[IPInterfaceWithPrefixLength.tag] = IPInterfaceWithPrefixLength
if self.schema:
fn = self.schema
self.logger.debug("Validating against --schema %s" % fn)
self.logger.debug(f"Validating against --schema {fn}")
elif hasattr(sys, "_MEIPASS"):
## See vppcfg.spec data_files that includes schema.yaml into the bundle
self.logger.debug("Validating against built-in schema")
fn = os.path.join(sys._MEIPASS, "schema.yaml")
else:
fn = "./schema.yaml"
self.logger.debug("Validating against fallthrough default schema %s" % fn)
self.logger.debug(f"Validating against fallthrough default schema {fn}")
if not os.path.isfile(fn):
self.logger.error("Cannot file schema file: %s" % fn)
self.logger.error(f"Cannot file schema file: {fn}")
return False, ret_msgs
try:
@ -109,7 +109,7 @@ class Validator(object):
ret_rv = False
for result in e.results:
for error in result.errors:
ret_msgs.extend(['yamale: %s' % error])
ret_msgs.extend([f'yamale: {error}'])
return ret_rv, ret_msgs
self.logger.debug("Validating Semantics...")

View File

@ -30,7 +30,7 @@ def get_all_addresses_except_ifname(yaml, except_ifname):
ret.append(ipaddress.ip_interface(a))
if 'sub-interfaces' in iface:
for subid, sub_iface in iface['sub-interfaces'].items():
sub_ifname = "%s.%d" % (ifname, subid)
sub_ifname = f"{ifname}.{int(subid)}"
if sub_ifname == except_ifname:
continue

View File

@ -156,23 +156,23 @@ def validate_bondethernets(yaml):
return result, msgs
for ifname, iface in yaml['bondethernets'].items():
logger.debug("bondethernet %s: %s" % (ifname, iface))
logger.debug(f"bondethernet {ifname}: {iface}")
bond_ifname, bond_iface = interface.get_by_name(yaml, ifname)
bond_mtu = 1500
if not bond_iface:
msgs.append("bondethernet %s does not exist in interfaces" % (ifname))
msgs.append(f"bondethernet {ifname} does not exist in interfaces")
result = False
else:
bond_mtu = interface.get_mtu(yaml, bond_ifname)
instance = int(ifname[12:])
if instance > 4294967294:
msgs.append("bondethernet %s has instance %d which is too large" % (ifname, instance))
msgs.append(f"bondethernet {ifname} has instance {int(instance)} which is too large")
result = False
if not get_mode(yaml, bond_ifname) in ['xor','lacp'] and 'load-balance' in iface:
msgs.append("bondethernet %s can only have load-balance if in mode XOR or LACP" % (ifname))
msgs.append(f"bondethernet {ifname} can only have load-balance if in mode XOR or LACP")
result = False
if 'mac' in iface and mac.is_multicast(iface['mac']):
msgs.append("bondethernet %s MAC address %s cannot be multicast" % (ifname, iface['mac']))
msgs.append(f"bondethernet {ifname} MAC address {iface['mac']} cannot be multicast")
result = False
if not 'interfaces' in iface:
@ -180,21 +180,21 @@ def validate_bondethernets(yaml):
for member in iface['interfaces']:
if (None, None) == interface.get_by_name(yaml, member):
msgs.append("bondethernet %s member %s does not exist" % (ifname, member))
msgs.append(f"bondethernet {ifname} member {member} does not exist")
result = False
continue
if interface.has_sub(yaml, member):
msgs.append("bondethernet %s member %s has sub-interface(s)" % (ifname, member))
msgs.append(f"bondethernet {ifname} member {member} has sub-interface(s)")
result = False
if interface.has_lcp(yaml, member):
msgs.append("bondethernet %s member %s has an LCP" % (ifname, member))
msgs.append(f"bondethernet {ifname} member {member} has an LCP")
result = False
if interface.has_address(yaml, member):
msgs.append("bondethernet %s member %s has an address" % (ifname, member))
msgs.append(f"bondethernet {ifname} member {member} has an address")
result = False
member_mtu = interface.get_mtu(yaml, member)
if member_mtu != bond_mtu:
msgs.append("bondethernet %s member %s MTU %d does not match BondEthernet MTU %d" % (ifname, member, member_mtu, bond_mtu))
msgs.append(f"bondethernet {ifname} member {member} MTU {int(member_mtu)} does not match BondEthernet MTU {int(bond_mtu)}")
result = False
return result, msgs

View File

@ -123,26 +123,26 @@ def validate_bridgedomains(yaml):
return result, msgs
for ifname, iface in yaml['bridgedomains'].items():
logger.debug("bridgedomain %s" % iface)
logger.debug(f"bridgedomain {iface}")
bd_mtu = 1500
if 'mtu' in iface:
bd_mtu = iface['mtu']
instance = int(ifname[2:])
if instance == 0:
msgs.append("bridgedomain %s is reserved" % ifname)
msgs.append(f"bridgedomain {ifname} is reserved")
result = False
elif instance > 16777215:
msgs.append("bridgedomain %s has instance %d which is too large" % (ifname, instance))
msgs.append(f"bridgedomain {ifname} has instance {int(instance)} which is too large")
result = False
if 'bvi' in iface:
bviname = iface['bvi']
bvi_ifname, bvi_iface = loopback.get_by_name(yaml,iface['bvi'])
if not bvi_unique(yaml, bvi_ifname):
msgs.append("bridgedomain %s BVI %s is not unique" % (ifname, bvi_ifname))
msgs.append(f"bridgedomain {ifname} BVI {bvi_ifname} is not unique")
result = False
if not bvi_iface:
msgs.append("bridgedomain %s BVI %s does not exist" % (ifname, bvi_ifname))
msgs.append(f"bridgedomain {ifname} BVI {bvi_ifname} does not exist")
result = False
continue
@ -150,28 +150,28 @@ def validate_bridgedomains(yaml):
if 'mtu' in bvi_iface:
bvi_mtu = bvi_iface['mtu']
if bvi_mtu != bd_mtu:
msgs.append("bridgedomain %s BVI %s has MTU %d, while bridge has %d" % (ifname, bvi_ifname, bvi_mtu, bd_mtu))
msgs.append(f"bridgedomain {ifname} BVI {bvi_ifname} has MTU {int(bvi_mtu)}, while bridge has {int(bd_mtu)}")
result = False
if 'interfaces' in iface:
for member in iface['interfaces']:
if (None, None) == interface.get_by_name(yaml, member):
msgs.append("bridgedomain %s member %s does not exist" % (ifname, member))
msgs.append(f"bridgedomain {ifname} member {member} does not exist")
result = False
continue
if not is_bridge_interface_unique(yaml, member):
msgs.append("bridgedomain %s member %s is not unique" % (ifname, member))
msgs.append(f"bridgedomain {ifname} member {member} is not unique")
result = False
if interface.has_lcp(yaml, member):
msgs.append("bridgedomain %s member %s has an LCP" % (ifname, member))
msgs.append(f"bridgedomain {ifname} member {member} has an LCP")
result = False
if interface.has_address(yaml, member):
msgs.append("bridgedomain %s member %s has an address" % (ifname, member))
msgs.append(f"bridgedomain {ifname} member {member} has an address")
result = False
member_mtu = interface.get_mtu(yaml, member)
if member_mtu != bd_mtu:
msgs.append("bridgedomain %s member %s has MTU %d, while bridge has %d" % (ifname, member, member_mtu, bd_mtu))
msgs.append(f"bridgedomain {ifname} member {member} has MTU {int(member_mtu)}, while bridge has {int(bd_mtu)}")
result = False

View File

@ -40,7 +40,7 @@ def get_qinx_parent_by_name(yaml, ifname):
return None,None
for subid, sub_iface in parent_iface['sub-interfaces'].items():
sub_ifname = "%s.%d" % (parent_ifname, subid)
sub_ifname = f"{parent_ifname}.{int(subid)}"
sub_encap = get_encapsulation(yaml, sub_ifname)
if not sub_encap:
continue
@ -73,7 +73,7 @@ def get_by_lcp_name(yaml, lcpname):
if not 'sub-interfaces' in iface:
continue
for subid, sub_iface in yaml['interfaces'][ifname]['sub-interfaces'].items():
sub_ifname = "%s.%d" % (ifname, subid)
sub_ifname = f"{ifname}.{int(subid)}"
if 'lcp' in sub_iface and sub_iface['lcp'] == lcpname:
return sub_ifname, sub_iface
return None,None
@ -135,7 +135,7 @@ def get_l2xc_interfaces(yaml):
ret.append(ifname)
if 'sub-interfaces' in iface:
for subid, sub_iface in iface['sub-interfaces'].items():
sub_ifname = "%s.%d" % (ifname, subid)
sub_ifname = f"{ifname}.{int(subid)}"
if 'l2xc' in sub_iface:
ret.append(sub_ifname)
@ -296,7 +296,7 @@ def get_interfaces(yaml):
if not 'sub-interfaces' in iface:
continue
for subid, sub_iface in iface['sub-interfaces'].items():
ret.append("%s.%d" % (ifname, subid))
ret.append(f"{ifname}.{int(subid)}")
return ret
@ -346,7 +346,7 @@ def unique_encapsulation(yaml, sub_ifname):
ncount = 0
for subid, sibling_iface in parent_iface['sub-interfaces'].items():
sibling_ifname = "%s.%d" % (parent_ifname, subid)
sibling_ifname = f"{parent_ifname}.{int(subid)}"
sibling_encap = get_encapsulation(yaml, sibling_ifname)
if sub_encap == sibling_encap and new_ifname != sibling_ifname:
ncount = ncount + 1
@ -418,18 +418,18 @@ def validate_interfaces(yaml):
return result, msgs
for ifname, iface in yaml['interfaces'].items():
logger.debug("interface %s" % iface)
logger.debug(f"interface {iface}")
if ifname.startswith("BondEthernet") and (None,None) == bondethernet.get_by_name(yaml, ifname):
msgs.append("interface %s does not exist in bondethernets" % ifname)
msgs.append(f"interface {ifname} does not exist in bondethernets")
result = False
if ifname.startswith("BondEthernet") and 'mac' in iface:
msgs.append("interface %s is a member of bondethernet, cannot set MAC" % ifname)
msgs.append(f"interface {ifname} is a member of bondethernet, cannot set MAC")
result = False
if not 'state' in iface:
iface['state'] = 'up'
if 'mac' in iface and mac.is_multicast(iface['mac']):
msgs.append("interface %s MAC address %s cannot be multicast" % (ifname, iface['mac']))
msgs.append(f"interface {ifname} MAC address {iface['mac']} cannot be multicast")
result = False
iface_mtu = get_mtu(yaml, ifname)
@ -439,167 +439,167 @@ def validate_interfaces(yaml):
if ifname.startswith('tap'):
tap_ifname, tap_iface = tap.get_by_name(yaml, ifname)
if not tap_iface:
msgs.append("interface %s is a TAP but does not exist in taps" % (ifname))
msgs.append(f"interface {ifname} is a TAP but does not exist in taps")
result = False
elif 'mtu' in tap_iface['host']:
host_mtu = tap_iface['host']['mtu']
if host_mtu != iface_mtu:
msgs.append("interface %s is a TAP so its MTU %d must match host MTU %d" % (ifname, iface_mtu, host_mtu))
msgs.append(f"interface {ifname} is a TAP so its MTU {int(iface_mtu)} must match host MTU {int(host_mtu)}")
result = False
if iface_address:
msgs.append("interface %s is a TAP so it cannot have an address" % (ifname))
msgs.append(f"interface {ifname} is a TAP so it cannot have an address")
result = False
if iface_lcp:
msgs.append("interface %s is a TAP so it cannot have an LCP" % (ifname))
msgs.append(f"interface {ifname} is a TAP so it cannot have an LCP")
result = False
if has_sub(yaml, ifname):
msgs.append("interface %s is a TAP so it cannot have sub-interfaces" % (ifname))
msgs.append(f"interface {ifname} is a TAP so it cannot have sub-interfaces")
result = False
if is_l2(yaml, ifname) and iface_lcp:
msgs.append("interface %s is in L2 mode but has LCP name %s" % (ifname, iface_lcp))
msgs.append(f"interface {ifname} is in L2 mode but has LCP name {iface_lcp}")
result = False
if is_l2(yaml, ifname) and iface_address:
msgs.append("interface %s is in L2 mode but has an address" % ifname)
msgs.append(f"interface {ifname} is in L2 mode but has an address")
result = False
if iface_lcp and not lcp.is_unique(yaml, iface_lcp):
msgs.append("interface %s does not have a unique LCP name %s" % (ifname, iface_lcp))
msgs.append(f"interface {ifname} does not have a unique LCP name {iface_lcp}")
result = False
if 'addresses' in iface:
for a in iface['addresses']:
if not address.is_allowed(yaml, ifname, iface['addresses'], a):
msgs.append("interface %s IP address %s conflicts with another" % (ifname, a))
msgs.append(f"interface {ifname} IP address {a} conflicts with another")
result = False
if 'l2xc' in iface:
if has_sub(yaml, ifname):
msgs.append("interface %s has l2xc so it cannot have sub-interfaces" % (ifname))
msgs.append(f"interface {ifname} has l2xc so it cannot have sub-interfaces")
result = False
if iface_lcp:
msgs.append("interface %s has l2xc so it cannot have an LCP" % (ifname))
msgs.append(f"interface {ifname} has l2xc so it cannot have an LCP")
result = False
if iface_address:
msgs.append("interface %s has l2xc so it cannot have an address" % (ifname))
msgs.append(f"interface {ifname} has l2xc so it cannot have an address")
result = False
if (None,None) == get_by_name(yaml, iface['l2xc']):
msgs.append("interface %s l2xc target %s does not exist" % (ifname, iface['l2xc']))
msgs.append(f"interface {ifname} l2xc target {iface['l2xc']} does not exist")
result = False
if iface['l2xc'] == ifname:
msgs.append("interface %s l2xc target cannot be itself" % (ifname))
msgs.append(f"interface {ifname} l2xc target cannot be itself")
result = False
target_mtu = get_mtu(yaml, iface['l2xc'])
if target_mtu != iface_mtu:
msgs.append("interface %s l2xc target MTU %d does not match source MTU %d" % (ifname, target_mtu, iface_mtu))
msgs.append(f"interface {ifname} l2xc target MTU {int(target_mtu)} does not match source MTU {int(iface_mtu)}")
result = False
if not is_l2xc_target_interface_unique(yaml, iface['l2xc']):
msgs.append("interface %s l2xc target %s is not unique" % (ifname, iface['l2xc']))
msgs.append(f"interface {ifname} l2xc target {iface['l2xc']} is not unique")
result = False
if bridgedomain.is_bridge_interface(yaml, iface['l2xc']):
msgs.append("interface %s l2xc target %s is in a bridgedomain" % (ifname, iface['l2xc']))
msgs.append(f"interface {ifname} l2xc target {iface['l2xc']} is in a bridgedomain")
result = False
if has_lcp(yaml, iface['l2xc']):
msgs.append("interface %s l2xc target %s cannot have an LCP" % (ifname, iface['l2xc']))
msgs.append(f"interface {ifname} l2xc target {iface['l2xc']} cannot have an LCP")
result = False
if has_address(yaml, iface['l2xc']):
msgs.append("interface %s l2xc target %s cannot have an address" % (ifname, iface['l2xc']))
msgs.append(f"interface {ifname} l2xc target {iface['l2xc']} cannot have an address")
result = False
if has_sub(yaml, ifname):
for sub_id, sub_iface in yaml['interfaces'][ifname]['sub-interfaces'].items():
logger.debug("sub-interface %s" % sub_iface)
sub_ifname = "%s.%d" % (ifname, sub_id)
logger.debug(f"sub-interface {sub_iface}")
sub_ifname = f"{ifname}.{int(sub_id)}"
if not sub_iface:
msgs.append("sub-interface %s has no config" % (sub_ifname))
msgs.append(f"sub-interface {sub_ifname} has no config")
result = False
continue
if not 'state' in sub_iface:
sub_iface['state'] = 'up'
if sub_iface['state'] == 'up' and iface['state'] == 'down':
msgs.append("sub-interface %s cannot be up if parent %s is down" % (sub_ifname, ifname))
msgs.append(f"sub-interface {sub_ifname} cannot be up if parent {ifname} is down")
result = False
sub_mtu = get_mtu(yaml, sub_ifname)
if sub_mtu > iface_mtu:
msgs.append("sub-interface %s has MTU %d higher than parent %s MTU %d" % (sub_ifname, sub_iface['mtu'], ifname, iface_mtu))
msgs.append(f"sub-interface {sub_ifname} has MTU {int(sub_iface['mtu'])} higher than parent {ifname} MTU {int(iface_mtu)}")
result = False
if is_qinx(yaml, sub_ifname):
mid_ifname, mid_iface = get_qinx_parent_by_name(yaml, sub_ifname)
mid_mtu = get_mtu(yaml, mid_ifname)
if sub_mtu > mid_mtu:
msgs.append("sub-interface %s has MTU %d higher than parent %s MTU %d" % (sub_ifname, sub_iface['mtu'], mid_ifname, mid_mtu))
msgs.append(f"sub-interface {sub_ifname} has MTU {int(sub_iface['mtu'])} higher than parent {mid_ifname} MTU {int(mid_mtu)}")
result = False
sub_lcp = get_lcp(yaml, sub_ifname)
if is_l2(yaml, sub_ifname) and sub_lcp:
msgs.append("sub-interface %s is in L2 mode but has LCP name %s" % (sub_ifname, sub_lcp))
msgs.append(f"sub-interface {sub_ifname} is in L2 mode but has LCP name {sub_lcp}")
result = False
if sub_lcp and not lcp.is_unique(yaml, sub_lcp):
msgs.append("sub-interface %s does not have a unique LCP name %s" % (sub_ifname, sub_lcp))
msgs.append(f"sub-interface {sub_ifname} does not have a unique LCP name {sub_lcp}")
result = False
if sub_lcp and not iface_lcp:
msgs.append("sub-interface %s has LCP name %s but %s does not have an LCP" % (sub_ifname, sub_lcp, ifname))
msgs.append(f"sub-interface {sub_ifname} has LCP name {sub_lcp} but {ifname} does not have an LCP")
result = False
if sub_lcp and is_qinx(yaml, sub_ifname):
mid_ifname, mid_iface = get_qinx_parent_by_name(yaml, sub_ifname)
if not mid_iface:
msgs.append("sub-interface %s is QinX and has LCP name %s which requires a parent" % (sub_ifname, sub_lcp))
msgs.append(f"sub-interface {sub_ifname} is QinX and has LCP name {sub_lcp} which requires a parent")
result = False
elif not get_lcp(yaml, mid_ifname):
msgs.append("sub-interface %s is QinX and has LCP name %s but %s does not have an LCP" % (sub_ifname, sub_lcp, mid_ifname))
msgs.append(f"sub-interface {sub_ifname} is QinX and has LCP name {sub_lcp} but {mid_ifname} does not have an LCP")
result = False
encap = get_encapsulation(yaml, sub_ifname)
if sub_lcp and (not encap or not encap['exact-match']):
msgs.append("sub-interface %s has LCP name %s but its encapsulation is not exact-match" % (sub_ifname, sub_lcp))
msgs.append(f"sub-interface {sub_ifname} has LCP name {sub_lcp} but its encapsulation is not exact-match")
result = False
if has_address(yaml, sub_ifname):
if not encap or not encap['exact-match']:
msgs.append("sub-interface %s has an address but its encapsulation is not exact-match" % (sub_ifname))
msgs.append(f"sub-interface {sub_ifname} has an address but its encapsulation is not exact-match")
result = False
if is_l2(yaml, sub_ifname):
msgs.append("sub-interface %s is in L2 mode but has an address" % sub_ifname)
msgs.append(f"sub-interface {sub_ifname} is in L2 mode but has an address")
result = False
for a in sub_iface['addresses']:
if not address.is_allowed(yaml, sub_ifname, sub_iface['addresses'], a):
msgs.append("sub-interface %s IP address %s conflicts with another" % (sub_ifname, a))
msgs.append(f"sub-interface {sub_ifname} IP address {a} conflicts with another")
result = False
if not valid_encapsulation(yaml, sub_ifname):
msgs.append("sub-interface %s has invalid encapsulation" % (sub_ifname))
msgs.append(f"sub-interface {sub_ifname} has invalid encapsulation")
result = False
elif not unique_encapsulation(yaml, sub_ifname):
msgs.append("sub-interface %s does not have unique encapsulation" % (sub_ifname))
msgs.append(f"sub-interface {sub_ifname} does not have unique encapsulation")
result = False
if 'l2xc' in sub_iface:
if has_lcp(yaml, sub_ifname):
msgs.append("sub-interface %s has l2xc so it cannot have an LCP" % (sub_ifname))
msgs.append(f"sub-interface {sub_ifname} has l2xc so it cannot have an LCP")
result = False
if has_address(yaml, sub_ifname):
msgs.append("sub-interface %s has l2xc so it cannot have an address" % (sub_ifname))
msgs.append(f"sub-interface {sub_ifname} has l2xc so it cannot have an address")
result = False
if (None, None) == get_by_name(yaml, sub_iface['l2xc']):
msgs.append("sub-interface %s l2xc target %s does not exist" % (sub_ifname, sub_iface['l2xc']))
msgs.append(f"sub-interface {sub_ifname} l2xc target {sub_iface['l2xc']} does not exist")
result = False
if sub_iface['l2xc'] == sub_ifname:
msgs.append("sub-interface %s l2xc target cannot be itself" % (sub_ifname))
msgs.append(f"sub-interface {sub_ifname} l2xc target cannot be itself")
result = False
target_mtu = get_mtu(yaml, sub_iface['l2xc'])
if target_mtu != sub_mtu:
msgs.append("sub-interface %s l2xc target MTU %d does not match source MTU %d" % (ifname, target_mtu, sub_mtu))
msgs.append(f"sub-interface {ifname} l2xc target MTU {int(target_mtu)} does not match source MTU {int(sub_mtu)}")
result = False
if not is_l2xc_target_interface_unique(yaml, sub_iface['l2xc']):
msgs.append("sub-interface %s l2xc target %s is not unique" % (sub_ifname, sub_iface['l2xc']))
msgs.append(f"sub-interface {sub_ifname} l2xc target {sub_iface['l2xc']} is not unique")
result = False
if bridgedomain.is_bridge_interface(yaml, sub_iface['l2xc']):
msgs.append("sub-interface %s l2xc target %s is in a bridgedomain" % (sub_ifname, sub_iface['l2xc']))
msgs.append(f"sub-interface {sub_ifname} l2xc target {sub_iface['l2xc']} is in a bridgedomain")
result = False
if has_lcp(yaml, sub_iface['l2xc']):
msgs.append("sub-interface %s l2xc target %s cannot have an LCP" % (sub_ifname, sub_iface['l2xc']))
msgs.append(f"sub-interface {sub_ifname} l2xc target {sub_iface['l2xc']} cannot have an LCP")
result = False
if has_address(yaml, sub_iface['l2xc']):
msgs.append("sub-interface %s l2xc target %s cannot have an address" % (sub_ifname, sub_iface['l2xc']))
msgs.append(f"sub-interface {sub_ifname} l2xc target {sub_iface['l2xc']} cannot have an address")
result = False

View File

@ -61,21 +61,21 @@ def validate_loopbacks(yaml):
return result, msgs
for ifname, iface in yaml['loopbacks'].items():
logger.debug("loopback %s" % iface)
logger.debug(f"loopback {iface}")
instance = int(ifname[4:])
if instance > 4095:
msgs.append("loopback %s has instance %d which is too large" % (ifname, instance))
msgs.append(f"loopback {ifname} has instance {int(instance)} which is too large")
result = False
if 'lcp' in iface and not lcp.is_unique(yaml, iface['lcp']):
msgs.append("loopback %s does not have a unique LCP name %s" % (ifname, iface['lcp']))
msgs.append(f"loopback {ifname} does not have a unique LCP name {iface['lcp']}")
result = False
if 'addresses' in iface:
for a in iface['addresses']:
if not address.is_allowed(yaml, ifname, iface['addresses'], a):
msgs.append("loopback %s IP address %s conflicts with another" % (ifname, a))
msgs.append(f"loopback {ifname} IP address {a} conflicts with another")
result = False
if 'mac' in iface and mac.is_multicast(iface['mac']):
msgs.append("loopback %s MAC address %s cannot be multicast" % (ifname, iface['mac']))
msgs.append(f"loopback {ifname} MAC address {iface['mac']} cannot be multicast")
result = False
return result, msgs

View File

@ -62,40 +62,40 @@ def validate_taps(yaml):
return result, msgs
for ifname, iface in yaml['taps'].items():
logger.debug("tap %s" % iface)
logger.debug(f"tap {iface}")
instance = int(ifname[3:])
## NOTE(pim): 1024 is not off-by-one, tap1024 is precisely the highest permissible id
if instance > 1024:
msgs.append("tap %s has instance %d which is too large" % (ifname, instance))
msgs.append(f"tap {ifname} has instance {int(instance)} which is too large")
result = False
if not is_host_name_unique(yaml, iface['host']['name']):
msgs.append("tap %s does not have a unique host name %s" % (ifname, iface['host']['name']))
msgs.append(f"tap {ifname} does not have a unique host name {iface['host']['name']}")
result = False
if 'rx-ring-size' in iface:
n = iface['rx-ring-size']
if n & (n-1) != 0:
msgs.append("tap %s rx-ring-size must be a power of two" % (ifname))
msgs.append(f"tap {ifname} rx-ring-size must be a power of two")
result = False
if 'tx-ring-size' in iface:
n = iface['tx-ring-size']
if n & (n-1) != 0:
msgs.append("tap %s tx-ring-size must be a power of two" % (ifname))
msgs.append(f"tap {ifname} tx-ring-size must be a power of two")
result = False
if 'namespace-create' in iface['host'] and iface['host']['namespace-create'] and not 'namespace' in iface['host']:
msgs.append("tap %s namespace-create can only be set if namespace is set" % (ifname))
msgs.append(f"tap {ifname} namespace-create can only be set if namespace is set")
result = False
if 'bridge-create' in iface['host'] and iface['host']['bridge-create'] and not 'bridge' in iface['host']:
msgs.append("tap %s bridge-create can only be set if bridge is set" % (ifname))
msgs.append(f"tap {ifname} bridge-create can only be set if bridge is set")
result = False
if 'mac' in iface['host'] and mac.is_multicast(iface['host']['mac']):
msgs.append("tap %s host MAC address %s cannot be multicast" % (ifname, iface['host']['mac']))
msgs.append(f"tap {ifname} host MAC address {iface['host']['mac']} cannot be multicast")
result = False
return result, msgs

View File

@ -65,20 +65,20 @@ def validate_vxlan_tunnels(yaml):
return result, msgs
for ifname, iface in yaml['vxlan_tunnels'].items():
logger.debug("vxlan_tunnel %s: %s" % (ifname, iface))
logger.debug(f"vxlan_tunnel {ifname}: {iface}")
instance = int(ifname[12:])
if instance > 2147483647:
msgs.append("vxlan_tunnel %s has instance %d which is too large" % (ifname, instance))
msgs.append(f"vxlan_tunnel {ifname} has instance {int(instance)} which is too large")
result = False
vni = iface['vni']
if not vni_unique(yaml, vni):
msgs.append("vxlan_tunnel %s VNI %d is not unique" % (ifname, vni))
msgs.append(f"vxlan_tunnel {ifname} VNI {int(vni)} is not unique")
result = False
local = ipaddress.ip_address(iface['local'])
remote = ipaddress.ip_address(iface['remote'])
if local.version != remote.version:
msgs.append("vxlan_tunnel %s local and remote are not the same address family" % (ifname))
msgs.append(f"vxlan_tunnel {ifname} local and remote are not the same address family")
result = False
return result, msgs

View File

@ -79,7 +79,7 @@ class YAMLTest(unittest.TestCase):
this_msg_expected = True
break
if not this_msg_expected:
print("%s: Unexpected message: %s" % (self.yaml_filename, m), file=sys.stderr)
print(f"{self.yaml_filename}: Unexpected message: {m}", file=sys.stderr)
fail = True
count = 0
@ -87,7 +87,7 @@ class YAMLTest(unittest.TestCase):
count = unittest['test']['errors']['count']
if len(msgs) != count:
print("%s: Unexpected error count %d (expecting %d)" % (self.yaml_filename, len(msgs), count), file=sys.stderr)
print(f"{self.yaml_filename}: Unexpected error count {len(msgs)} (expecting {int(count)})", file=sys.stderr)
self.assertEqual(len(msgs), count)
self.assertFalse(fail)

View File

@ -25,7 +25,7 @@ class Dumper(VPPApi):
if fh is not sys.stdout:
fh.close()
self.logger.info("Wrote YAML config to %s" % (outfile))
self.logger.info(f"Wrote YAML config to {outfile}")
def cache_to_config(self):
config = {"loopbacks": {}, "bondethernets": {}, "interfaces": {}, "bridgedomains": {}, "vxlan_tunnels": {}, "taps": {} }
@ -51,7 +51,7 @@ class Dumper(VPPApi):
if iface.interface_dev_type=='Loopback':
if iface.sub_id > 0:
self.logger.warning("Refusing to export sub-interfaces of loopback devices (%s)" % iface.interface_name)
self.logger.warning(f"Refusing to export sub-interfaces of loopback devices ({iface.interface_name})")
continue
loop = {"description": ""}
loop['mtu'] = iface.mtu[0]
@ -136,7 +136,7 @@ class Dumper(VPPApi):
for idx, iface in self.cache['bridgedomains'].items():
# self.logger.info("%d: %s" % (idx, iface))
bridge_name = "bd%d" % idx
bridge_name = f"bd{int(idx)}"
mtu = 1500
bridge = {"description": ""}
settings = {}

View File

@ -52,7 +52,7 @@ class Reconciler():
ret = True
for ifname in interface.get_phys(self.cfg):
if not ifname in self.vpp.cache['interface_names']:
self.logger.warning("Interface %s does not exist in VPP" % ifname)
self.logger.warning(f"Interface {ifname} does not exist in VPP")
ret = False
return ret
@ -63,7 +63,7 @@ class Reconciler():
ret = True
for ifname in self.vpp.get_phys():
if not ifname in interface.get_interfaces(self.cfg):
self.logger.warning("Interface %s does not exist in the config" % ifname)
self.logger.warning(f"Interface {ifname} does not exist in the config")
ret = False
return ret
@ -118,11 +118,11 @@ class Reconciler():
removed_addresses = []
for a in self.vpp.cache['interface_addresses'][idx]:
if not a in address_list:
cli="set interface ip address del %s %s" % (ifname, a)
cli=f"set interface ip address del {ifname} {a}"
self.cli['prune'].append(cli);
removed_addresses.append(a)
else:
self.logger.debug("Address OK: %s %s" % (ifname, a))
self.logger.debug(f"Address OK: {ifname} {a}")
for a in removed_addresses:
self.vpp.cache['interface_addresses'][idx].remove(a)
@ -139,15 +139,15 @@ class Reconciler():
if not config_iface:
self.prune_addresses(vpp_iface.interface_name, [])
if numtags == 0:
cli="delete loopback interface intfc %s" % (vpp_iface.interface_name)
cli=f"delete loopback interface intfc {vpp_iface.interface_name}"
self.cli['prune'].append(cli);
removed_interfaces.append(vpp_iface.interface_name)
else:
cli="delete sub %s" % (vpp_iface.interface_name)
cli=f"delete sub {vpp_iface.interface_name}"
self.cli['prune'].append(cli);
removed_interfaces.append(vpp_iface.interface_name)
continue
self.logger.debug("Loopback OK: %s" % (vpp_iface.interface_name))
self.logger.debug(f"Loopback OK: {vpp_iface.interface_name}")
addresses = []
if 'addresses' in config_iface:
addresses = config_iface['addresses']
@ -163,7 +163,7 @@ class Reconciler():
""" Remove bridge-domains from VPP, if they do not occur in the config. If any interfaces are
found in to-be removed bridge-domains, they are returned to L3 mode, and tag-rewrites removed. """
for idx, bridge in self.vpp.cache['bridgedomains'].items():
bridgename = "bd%d" % idx
bridgename = f"bd{int(idx)}"
config_ifname, config_iface = bridgedomain.get_by_name(self.cfg, bridgename)
members = []
if not config_iface:
@ -173,30 +173,30 @@ class Reconciler():
member_iface = self.vpp.cache['interfaces'][member.sw_if_index]
member_ifname = member_iface.interface_name
if member_iface.sub_id > 0:
cli="set interface l2 tag-rewrite %s disable" % (member_ifname)
cli=f"set interface l2 tag-rewrite {member_ifname} disable"
self.cli['prune'].append(cli);
cli="set interface l3 %s" % (member_ifname)
cli=f"set interface l3 {member_ifname}"
self.cli['prune'].append(cli);
if bridge.bvi_sw_if_index in self.vpp.cache['interfaces']:
bviname = self.vpp.cache['interfaces'][bridge.bvi_sw_if_index].interface_name
cli="set interface l3 %s" % (bviname)
cli=f"set interface l3 {bviname}"
self.cli['prune'].append(cli);
cli="create bridge-domain %d del" % (idx)
cli=f"create bridge-domain {int(idx)} del"
self.cli['prune'].append(cli);
else:
self.logger.debug("BridgeDomain OK: %s" % (bridgename))
self.logger.debug(f"BridgeDomain OK: {bridgename}")
for member in bridge.sw_if_details:
member_ifname = self.vpp.cache['interfaces'][member.sw_if_index].interface_name
if 'members' in config_iface and member_ifname in config_iface['members']:
if interface.is_sub(self.cfg, member_ifname):
cli="set interface l2 tag-rewrite %s disable" % (member_ifname)
cli=f"set interface l2 tag-rewrite {member_ifname} disable"
self.cli['prune'].append(cli);
cli="set interface l3 %s" % (member_ifname)
cli=f"set interface l3 {member_ifname}"
self.cli['prune'].append(cli);
if 'bvi' in config_iface and bridge.bvi_sw_if_index in self.vpp.cache['interfaces']:
bviname = self.vpp.cache['interfaces'][bridge.bvi_sw_if_index].interface_name
if bviname != config_iface['bvi']:
cli="set interface l3 %s" % (bviname)
cli=f"set interface l3 {bviname}"
self.cli['prune'].append(cli);
return True
@ -211,31 +211,31 @@ class Reconciler():
config_rx_ifname, config_rx_iface = interface.get_by_name(self.cfg, vpp_rx_ifname)
if not config_rx_ifname:
if self.vpp.cache['interfaces'][l2xc.rx_sw_if_index].sub_id > 0:
cli="set interface l2 tag-rewrite %s disable" % (vpp_rx_ifname)
cli=f"set interface l2 tag-rewrite {vpp_rx_ifname} disable"
self.cli['prune'].append(cli);
cli="set interface l3 %s" % (vpp_rx_ifname)
cli=f"set interface l3 {vpp_rx_ifname}"
self.cli['prune'].append(cli);
removed_l2xcs.append(vpp_rx_ifname)
continue
if not interface.is_l2xc_interface(self.cfg, config_rx_ifname):
if interface.is_sub(self.cfg, config_rx_ifname):
cli="set interface l2 tag-rewrite %s disable" % (vpp_rx_ifname)
cli=f"set interface l2 tag-rewrite {vpp_rx_ifname} disable"
self.cli['prune'].append(cli);
cli="set interface l3 %s" % (vpp_rx_ifname)
cli=f"set interface l3 {vpp_rx_ifname}"
self.cli['prune'].append(cli);
removed_l2xcs.append(vpp_rx_ifname)
continue
vpp_tx_ifname = self.vpp.cache['interfaces'][l2xc.tx_sw_if_index].interface_name
if vpp_tx_ifname != config_rx_iface['l2xc']:
if interface.is_sub(self.cfg, config_rx_ifname):
cli="set interface l2 tag-rewrite %s disable" % (vpp_rx_ifname)
cli=f"set interface l2 tag-rewrite {vpp_rx_ifname} disable"
self.cli['prune'].append(cli);
cli="set interface l3 %s" % (vpp_rx_ifname)
cli=f"set interface l3 {vpp_rx_ifname}"
self.cli['prune'].append(cli);
removed_l2xcs.append(vpp_rx_ifname)
continue
self.logger.debug("L2XC OK: %s -> %s" % (vpp_rx_ifname, vpp_tx_ifname))
self.logger.debug(f"L2XC OK: {vpp_rx_ifname} -> {vpp_tx_ifname}")
for l2xc in removed_l2xcs:
self.vpp.cache_remove_l2xc(l2xc)
return True
@ -337,10 +337,10 @@ class Reconciler():
if self.__tap_has_diff(vpp_ifname):
removed_taps.append(vpp_ifname)
continue
self.logger.debug("TAP OK: %s" % (vpp_ifname))
self.logger.debug(f"TAP OK: {vpp_ifname}")
for ifname in removed_taps:
cli="delete tap %s" % ifname
cli=f"delete tap {ifname}"
self.cli['prune'].append(cli)
self.vpp.cache_remove_interface(ifname)
return True
@ -358,10 +358,10 @@ class Reconciler():
self.prune_addresses(vpp_ifname, [])
for member in self.vpp.cache['bondethernet_members'][idx]:
member_ifname = self.vpp.cache['interfaces'][member].interface_name
cli="bond del %s" % (member_ifname)
cli=f"bond del {member_ifname}"
self.cli['prune'].append(cli);
removed_bondethernet_members.append(member_ifname)
cli="delete bond %s" % (vpp_ifname)
cli=f"delete bond {vpp_ifname}"
self.cli['prune'].append(cli);
removed_interfaces.append(vpp_ifname)
continue
@ -369,14 +369,14 @@ class Reconciler():
for member in self.vpp.cache['bondethernet_members'][idx]:
member_ifname = self.vpp.cache['interfaces'][member].interface_name
if 'interfaces' in config_iface and not member_ifname in config_iface['interfaces']:
cli="bond del %s" % (member_ifname)
cli=f"bond del {member_ifname}"
self.cli['prune'].append(cli);
removed_bondethernet_members.append(member_ifname)
addresses = []
if 'addresses' in config_iface:
addresses = config_iface['addresses']
self.prune_addresses(vpp_ifname, addresses)
self.logger.debug("BondEthernet OK: %s" % (vpp_ifname))
self.logger.debug(f"BondEthernet OK: {vpp_ifname}")
for ifname in removed_bondethernet_members:
self.vpp.cache_remove_bondethernet_member(ifname)
@ -412,7 +412,7 @@ class Reconciler():
if 'addresses' in config_iface:
addresses = config_iface['addresses']
self.prune_addresses(vpp_ifname, addresses)
self.logger.debug("VXLAN Tunnel OK: %s" % (vpp_ifname))
self.logger.debug(f"VXLAN Tunnel OK: {vpp_ifname}")
for ifname in removed_interfaces:
self.vpp.cache_remove_vxlan_tunnel(ifname)
@ -450,7 +450,7 @@ class Reconciler():
if prune:
self.prune_addresses(vpp_ifname, [])
cli="delete sub %s" % (vpp_ifname)
cli=f"delete sub {vpp_ifname}"
self.cli['prune'].append(cli);
removed_interfaces.append(vpp_ifname)
continue
@ -459,7 +459,7 @@ class Reconciler():
if 'addresses' in config_iface:
addresses = config_iface['addresses']
self.prune_addresses(vpp_ifname, addresses)
self.logger.debug("Sub Interface OK: %s" % (vpp_ifname))
self.logger.debug(f"Sub Interface OK: {vpp_ifname}")
for ifname in removed_interfaces:
self.vpp.cache_remove_interface(ifname)
@ -475,14 +475,14 @@ class Reconciler():
## Interfaces were sent DOWN in the prune_admin_state() step previously
self.prune_addresses(vpp_ifname, [])
if vpp_iface.link_mtu != 9000:
cli="set interface mtu 9000 %s" % (vpp_ifname)
cli=f"set interface mtu 9000 {vpp_ifname}"
self.cli['prune'].append(cli);
continue
addresses = []
if 'addresses' in config_iface:
addresses = config_iface['addresses']
self.prune_addresses(vpp_ifname, addresses)
self.logger.debug("Interface OK: %s" % (vpp_ifname))
self.logger.debug(f"Interface OK: {vpp_ifname}")
return True
def __parent_iface_by_encap(self, sup_sw_if_index, outer, dot1ad=True):
@ -495,10 +495,10 @@ class Reconciler():
if iface.sub_inner_vlan_id > 0:
continue
if dot1ad and (iface.sub_if_flags&8) and iface.sub_outer_vlan_id == outer:
self.logger.debug("match: %s (dot1ad)" % iface.interface_name)
self.logger.debug(f"match: {iface.interface_name} (dot1ad)")
return idx
if not dot1ad and not (iface.sub_if_flags&8) and iface.sub_outer_vlan_id == outer:
self.logger.debug("match: %s (dot1q)" % iface.interface_name)
self.logger.debug(f"match: {iface.interface_name} (dot1q)")
return idx
return None
@ -605,11 +605,11 @@ class Reconciler():
removed_lcps.append(lcp)
continue
self.logger.debug("LCP OK: %s -> (vpp=%s, config=%s)" % (lcp.host_if_name, vpp_iface.interface_name, config_ifname))
self.logger.debug(f"LCP OK: {lcp.host_if_name} -> (vpp={vpp_iface.interface_name}, config={config_ifname})")
for lcp in removed_lcps:
vpp_ifname = self.vpp.cache['interfaces'][lcp.phy_sw_if_index].interface_name
cli="lcp delete %s" % (vpp_ifname)
cli=f"lcp delete {vpp_ifname}"
self.cli['prune'].append(cli);
self.vpp.cache_remove_lcp(lcp.host_if_name)
return True
@ -624,7 +624,7 @@ class Reconciler():
continue
if vpp_iface.flags & 1: # IF_STATUS_API_FLAG_ADMIN_UP
cli="set interface state %s down" % (ifname)
cli=f"set interface state {ifname} down"
self.cli['prune'].append(cli);
return True
@ -662,10 +662,10 @@ class Reconciler():
if ifname in self.vpp.cache['interface_names']:
continue
instance = int(ifname[4:])
cli="create loopback interface instance %d" % (instance)
cli=f"create loopback interface instance {int(instance)}"
ifname, iface = loopback.get_by_name(self.cfg, ifname)
if 'mac' in iface:
cli += " mac %s" % iface['mac']
cli += f" mac {iface['mac']}"
self.cli['create'].append(cli);
return True
@ -676,12 +676,12 @@ class Reconciler():
ifname, iface = bondethernet.get_by_name(self.cfg, ifname)
instance = int(ifname[12:])
mode = bondethernet.get_mode(self.cfg, ifname)
cli="create bond id %d mode %s" % (instance, mode)
cli=f"create bond id {int(instance)} mode {mode}"
lb = bondethernet.get_lb(self.cfg, ifname)
if lb:
cli += " load-balance %s" % lb
cli += f" load-balance {lb}"
if 'mac' in iface:
cli += " hw-addr %s" % iface['mac']
cli += f" hw-addr {iface['mac']}"
self.cli['create'].append(cli);
return True
@ -710,15 +710,15 @@ class Reconciler():
## Assemble the encapsulation string
encap = interface.get_encapsulation(self.cfg, ifname)
if encap['dot1ad'] > 0:
encapstr = "dot1ad %d" % encap['dot1ad']
encapstr = f"dot1ad {int(encap['dot1ad'])}"
else:
encapstr = "dot1q %d" % encap['dot1q']
encapstr = f"dot1q {int(encap['dot1q'])}"
if do_qinx:
encapstr += " inner-dot1q %d" % encap['inner-dot1q']
encapstr += f" inner-dot1q {int(encap['inner-dot1q'])}"
if encap['exact-match'] == True:
encapstr += " exact-match"
parent, subid = ifname.split('.')
cli="create sub %s %d %s" % (parent, int(subid), encapstr)
cli=f"create sub {parent} {int(int(subid))} {encapstr}"
self.cli['create'].append(cli);
return True
@ -728,19 +728,19 @@ class Reconciler():
if ifname in self.vpp.cache['interface_names']:
continue
instance=int(ifname[3:])
cli="create tap id %d host-if-name %s" % (instance, iface['host']['name'])
cli=f"create tap id {int(instance)} host-if-name {iface['host']['name']}"
if 'mac' in iface['host']:
cli+=" host-mac-addr %s" % iface['host']['mac']
cli+=f" host-mac-addr {iface['host']['mac']}"
if 'namespace' in iface['host']:
cli+=" host-ns %d" % iface['host']['namespace']
cli+=f" host-ns {int(iface['host']['namespace'])}"
if 'bridge' in iface['host']:
cli+=" host-bridge %s" % iface['host']['bridge']
cli+=f" host-bridge {iface['host']['bridge']}"
if 'mtu' in iface['host']:
cli+=" host-mtu-size %d" % iface['host']['mtu']
cli+=f" host-mtu-size {int(iface['host']['mtu'])}"
if 'rx-ring-size' in iface:
cli+=" rx-ring-size %d" % iface['rx-ring-size']
cli+=f" rx-ring-size {int(iface['rx-ring-size'])}"
if 'tx-ring-size' in iface:
cli+=" tx-ring-size %d" % iface['tx-ring-size']
cli+=f" tx-ring-size {int(iface['tx-ring-size'])}"
self.cli['create'].append(cli)
return True
@ -752,7 +752,7 @@ class Reconciler():
settings = bridgedomain.get_settings(self.cfg, ifname)
if instance in self.vpp.cache['bridgedomains']:
continue
cli="create bridge-domain %s" % (instance)
cli=f"create bridge-domain {instance}"
if not settings['learn']:
cli += " learn 0"
if not settings['unicast-flood']:
@ -766,7 +766,7 @@ class Reconciler():
if settings['arp-unicast-forward']:
cli += " arp-ufwd 1"
if settings['mac-age-minutes'] > 0:
cli += " mac-age %d" % settings['mac-age-minutes']
cli += f" mac-age {int(settings['mac-age-minutes'])}"
self.cli['create'].append(cli);
return True
@ -786,7 +786,7 @@ class Reconciler():
continue
if iface['lcp'] in lcpnames:
continue
cli="lcp create %s host-if %s" % (ifname, iface['lcp'])
cli=f"lcp create {ifname} host-if {iface['lcp']}"
self.cli['create'].append(cli);
## ... then 1-tag (Dot1Q/Dot1AD), and then create 2-tag (Qin*) LCPs
@ -799,7 +799,7 @@ class Reconciler():
continue
if iface['lcp'] in lcpnames:
continue
cli="lcp create %s host-if %s" % (ifname, iface['lcp'])
cli=f"lcp create {ifname} host-if {iface['lcp']}"
self.cli['create'].append(cli);
return True
@ -839,7 +839,7 @@ class Reconciler():
vpp_iface = self.vpp.cache['interface_names'][ifname]
config_ifname, config_iface = loopback.get_by_name(self.cfg, ifname)
if 'mac' in config_iface and config_iface['mac'] != str(vpp_iface.l2_address):
cli="set interface mac address %s %s" % (config_ifname, config_iface['mac'])
cli=f"set interface mac address {config_ifname} {config_iface['mac']}"
self.cli['sync'].append(cli)
return True
@ -851,7 +851,7 @@ class Reconciler():
vpp_iface = self.vpp.cache['interface_names'][ifname]
config_ifname, config_iface = interface.get_by_name(self.cfg, ifname)
if 'mac' in config_iface and config_iface['mac'] != str(vpp_iface.l2_address):
cli="set interface mac address %s %s" % (config_ifname, config_iface['mac'])
cli=f"set interface mac address {config_ifname} {config_iface['mac']}"
self.cli['sync'].append(cli)
return True
@ -876,10 +876,10 @@ class Reconciler():
if not member_ifname in vpp_members:
if len(vpp_members) == 0:
bondmac = member_iface.l2_address
cli="bond add %s %s" % (config_bond_ifname, member_iface.interface_name)
cli=f"bond add {config_bond_ifname} {member_iface.interface_name}"
self.cli['sync'].append(cli);
if vpp_iface and 'mac' in config_iface and str(vpp_iface.l2_address) != config_iface['mac']:
cli="set interface mac address %s %s" % (config_ifname, config_iface['mac'])
cli=f"set interface mac address {config_ifname} {config_iface['mac']}"
self.cli['sync'].append(cli);
elif bondmac and 'lcp' in config_iface:
## TODO(pim) - Ensure LCP has the same MAC as the BondEthernet
@ -906,49 +906,49 @@ class Reconciler():
bvi_sw_if_index = -1
bridge_members = []
config_bridge_ifname, config_bridge_iface = bridgedomain.get_by_name(self.cfg, "bd%d"%instance)
config_bridge_ifname, config_bridge_iface = bridgedomain.get_by_name(self.cfg, f"bd{int(instance)}")
if vpp_bridge:
# Sync settings on existing bridge. create_bridgedomain() will have set them for new bridges.
settings = bridgedomain.get_settings(self.cfg, config_bridge_ifname)
if settings['learn'] != vpp_bridge.learn:
cli="set bridge-domain learn %d" % (instance)
cli=f"set bridge-domain learn {int(instance)}"
if not settings['learn']:
cli += " disable"
self.cli['sync'].append(cli);
if settings['unicast-forward'] != vpp_bridge.forward:
cli="set bridge-domain forward %d" % (instance)
cli=f"set bridge-domain forward {int(instance)}"
if not settings['unicast-forward']:
cli += " disable"
self.cli['sync'].append(cli);
if settings['unicast-flood'] != vpp_bridge.flood:
cli="set bridge-domain flood %d" % (instance)
cli=f"set bridge-domain flood {int(instance)}"
if not settings['unicast-flood']:
cli += " disable"
self.cli['sync'].append(cli);
if settings['unknown-unicast-flood'] != vpp_bridge.uu_flood:
cli="set bridge-domain uu-flood %d" % (instance)
cli=f"set bridge-domain uu-flood {int(instance)}"
if not settings['unknown-unicast-flood']:
cli += " disable"
self.cli['sync'].append(cli);
if settings['arp-termination'] != vpp_bridge.arp_term:
cli="set bridge-domain arp term %d" % (instance)
cli=f"set bridge-domain arp term {int(instance)}"
if not settings['arp-termination']:
cli += " disable"
self.cli['sync'].append(cli);
if settings['arp-unicast-forward'] != vpp_bridge.arp_ufwd:
cli="set bridge-domain arp-ufwd %d" % (instance)
cli=f"set bridge-domain arp-ufwd {int(instance)}"
if not settings['arp-unicast-forward']:
cli += " disable"
self.cli['sync'].append(cli);
if settings['mac-age-minutes'] != vpp_bridge.mac_age:
cli="set bridge-domain mac-age %d %d" % (instance, settings['mac-age-minutes'])
cli=f"set bridge-domain mac-age {int(instance)} {int(settings['mac-age-minutes'])}"
self.cli['sync'].append(cli);
if 'bvi' in config_bridge_iface:
bviname = config_bridge_iface['bvi']
if bviname in self.vpp.cache['interface_names'] and self.vpp.cache['interface_names'][bviname].sw_if_index == bvi_sw_if_index:
continue
cli="set interface l2 bridge %s %d bvi" % (bviname, instance)
cli=f"set interface l2 bridge {bviname} {int(instance)} bvi"
self.cli['sync'].append(cli);
if not 'interfaces' in config_bridge_iface:
@ -956,14 +956,14 @@ class Reconciler():
for member_ifname in config_bridge_iface['interfaces']:
member_ifname, member_iface = interface.get_by_name(self.cfg, member_ifname)
if not member_ifname in bridge_members:
cli="set interface l2 bridge %s %d" % (member_ifname, instance)
cli=f"set interface l2 bridge {member_ifname} {int(instance)}"
self.cli['sync'].append(cli);
operation="disable"
if interface.is_qinx(self.cfg, member_ifname):
operation="pop 2"
elif interface.is_sub(self.cfg, member_ifname):
operation="pop 1"
cli="set interface l2 tag-rewrite %s %s" % (member_ifname, operation)
cli=f"set interface l2 tag-rewrite {member_ifname} {operation}"
self.cli['sync'].append(cli);
return True
@ -987,7 +987,7 @@ class Reconciler():
l2xc_changed = True
if l2xc_changed:
cli="set interface l2 xconnect %s %s" % (config_rx_ifname, config_tx_ifname)
cli=f"set interface l2 xconnect {config_rx_ifname} {config_tx_ifname}"
self.cli['sync'].append(cli);
operation="disable"
@ -995,7 +995,7 @@ class Reconciler():
operation="pop 2"
elif interface.is_sub(self.cfg, config_rx_ifname):
operation="pop 1"
cli="set interface l2 tag-rewrite %s %s" % (config_rx_ifname, operation)
cli=f"set interface l2 tag-rewrite {config_rx_ifname} {operation}"
self.cli['sync'].append(cli);
return True
@ -1032,10 +1032,10 @@ class Reconciler():
config_mtu = interface.get_mtu(self.cfg, ifname)
if shrink and config_mtu < vpp_mtu:
cli="set interface mtu packet %d %s" % (config_mtu, vpp_ifname)
cli=f"set interface mtu packet {int(config_mtu)} {vpp_ifname}"
self.cli['sync'].append(cli);
elif not shrink and config_mtu > vpp_mtu:
cli="set interface mtu packet %d %s" % (config_mtu, vpp_ifname)
cli=f"set interface mtu packet {int(config_mtu)} {vpp_ifname}"
self.cli['sync'].append(cli);
return True
@ -1048,7 +1048,7 @@ class Reconciler():
config_ifname, config_iface = interface.get_by_name(self.cfg, vpp_iface.interface_name)
if not config_iface:
self.logger.warning("Interface %s exists in VPP but not in config, this is dangerous" % vpp_iface.interface_name)
self.logger.warning(f"Interface {vpp_iface.interface_name} exists in VPP but not in config, this is dangerous")
continue
if not interface.is_phy(self.cfg, vpp_iface.interface_name):
continue
@ -1062,26 +1062,26 @@ class Reconciler():
if shrink and config_mtu < vpp_iface.link_mtu:
## If the interface is up, temporarily down it in order to change the Max Frame Size
if vpp_iface.flags & 1: # IF_STATUS_API_FLAG_ADMIN_UP
cli="set interface state %s down" % (vpp_iface.interface_name)
cli=f"set interface state {vpp_iface.interface_name} down"
self.cli['sync'].append(cli);
cli="set interface mtu %d %s" % (config_mtu, vpp_iface.interface_name)
cli=f"set interface mtu {int(config_mtu)} {vpp_iface.interface_name}"
self.cli['sync'].append(cli);
if vpp_iface.flags & 1: # IF_STATUS_API_FLAG_ADMIN_UP
cli="set interface state %s up" % (vpp_iface.interface_name)
cli=f"set interface state {vpp_iface.interface_name} up"
self.cli['sync'].append(cli);
elif not shrink and config_mtu > vpp_iface.link_mtu:
## If the interface is up, temporarily down it in order to change the Max Frame Size
if vpp_iface.flags & 1: # IF_STATUS_API_FLAG_ADMIN_UP
cli="set interface state %s down" % (vpp_iface.interface_name)
cli=f"set interface state {vpp_iface.interface_name} down"
self.cli['sync'].append(cli);
cli="set interface mtu %d %s" % (config_mtu, vpp_iface.interface_name)
cli=f"set interface mtu {int(config_mtu)} {vpp_iface.interface_name}"
self.cli['sync'].append(cli);
if vpp_iface.flags & 1: # IF_STATUS_API_FLAG_ADMIN_UP
cli="set interface state %s up" % (vpp_iface.interface_name)
cli=f"set interface state {vpp_iface.interface_name} up"
self.cli['sync'].append(cli);
return True
@ -1120,7 +1120,7 @@ class Reconciler():
for a in config_addresses:
if a in vpp_addresses:
continue
cli="set interface ip address %s %s" % (vpp_ifname, a)
cli=f"set interface ip address {vpp_ifname} {a}"
self.cli['sync'].append(cli);
return True
@ -1141,7 +1141,7 @@ class Reconciler():
state="up"
if config_admin_state == 0:
state="down"
cli="set interface state %s %s" % (vpp_ifname, state)
cli=f"set interface state {vpp_ifname} {state}"
self.cli['sync'].append(cli);
return True
@ -1174,4 +1174,4 @@ class Reconciler():
if fh is not sys.stdout:
fh.close()
self.logger.info("Wrote %d lines to %s" % (len(output), outfile))
self.logger.info(f"Wrote {len(output)} lines to {outfile}")

View File

@ -48,7 +48,7 @@ class VPPApi():
return False
v = self.vpp.api.show_version()
self.logger.info('VPP version is %s' % v.version)
self.logger.info(f'VPP version is {v.version}')
self.connected = True
return True
@ -76,7 +76,7 @@ class VPPApi():
found = True
break
if not found:
self.logger.warning("Trying to remove an LCP which is not in the config: %s" % lcpname)
self.logger.warning(f"Trying to remove an LCP which is not in the config: {lcpname}")
return False
ifname = self.cache['interfaces'][lcp.host_sw_if_index].interface_name
@ -88,7 +88,7 @@ class VPPApi():
def cache_remove_bondethernet_member(self, ifname):
""" Removes the bonderthernet member interface, identified by name, from the config. """
if not ifname in self.cache['interface_names']:
self.logger.warning("Trying to remove a bondethernet member interface which is not in the config: %s" % ifname)
self.logger.warning(f"Trying to remove a bondethernet member interface which is not in the config: {ifname}")
return False
iface = self.cache['interface_names'][ifname]
@ -100,7 +100,7 @@ class VPPApi():
def cache_remove_l2xc(self, ifname):
if not ifname in self.cache['interface_names']:
self.logger.warning("Trying to remove an L2XC which is not in the config: %s" % ifname)
self.logger.warning(f"Trying to remove an L2XC which is not in the config: {ifname}")
return False
iface = self.cache['interface_names'][ifname]
self.cache['l2xcs'].pop(iface.sw_if_index, None)
@ -108,7 +108,7 @@ class VPPApi():
def cache_remove_vxlan_tunnel(self, ifname):
if not ifname in self.cache['interface_names']:
self.logger.warning("Trying to remove a VXLAN Tunnel which is not in the config: %s" % ifname)
self.logger.warning(f"Trying to remove a VXLAN Tunnel which is not in the config: {ifname}")
return False
iface = self.cache['interface_names'][ifname]
@ -118,20 +118,20 @@ class VPPApi():
def cache_remove_interface(self, ifname):
""" Removes the interface, identified by name, from the config. """
if not ifname in self.cache['interface_names']:
self.logger.warning("Trying to remove an interface which is not in the config: %s" % ifname)
self.logger.warning(f"Trying to remove an interface which is not in the config: {ifname}")
return False
iface = self.cache['interface_names'][ifname]
del self.cache['interfaces'][iface.sw_if_index]
if len(self.cache['interface_addresses'][iface.sw_if_index]) > 0:
self.logger.warning("Not all addresses were removed on %s" % ifname)
self.logger.warning(f"Not all addresses were removed on {ifname}")
del self.cache['interface_addresses'][iface.sw_if_index]
del self.cache['interface_names'][ifname]
## Use my_dict.pop('key', None), as it allows 'key' to be absent
if iface.sw_if_index in self.cache['bondethernet_members']:
if len(self.cache['bondethernet_members'][iface.sw_if_index]) != 0:
self.logger.warning("When removing BondEthernet %s, its members are not empty: %s" % (ifname, self.cache['bondethernet_members'][iface.sw_if_index]))
self.logger.warning(f"When removing BondEthernet {ifname}, its members are not empty: {self.cache['bondethernet_members'][iface.sw_if_index]}")
else:
del self.cache['bondethernet_members'][iface.sw_if_index]
self.cache['bondethernets'].pop(iface.sw_if_index, None)
@ -158,7 +158,7 @@ class VPPApi():
lcp = lcp._replace(phy_sw_if_index=socket.ntohl(lcp.phy_sw_if_index))
lcp = lcp._replace(host_sw_if_index=socket.ntohl(lcp.host_sw_if_index))
lcp = lcp._replace(vif_index=socket.ntohl(lcp.vif_index))
self.logger.warning("LCP workaround for endianness issue on %s" % lcp.host_if_name)
self.logger.warning(f"LCP workaround for endianness issue on {lcp.host_if_name}")
self.cache['lcps'][lcp.phy_sw_if_index] = lcp
self.lcp_enabled = True
except:
@ -170,11 +170,11 @@ class VPPApi():
self.cache['interfaces'][iface.sw_if_index] = iface
self.cache['interface_names'][iface.interface_name] = iface
self.cache['interface_addresses'][iface.sw_if_index] = []
self.logger.debug("Retrieving IPv4 addresses for %s" % iface.interface_name)
self.logger.debug(f"Retrieving IPv4 addresses for {iface.interface_name}")
ipr = self.vpp.api.ip_address_dump(sw_if_index=iface.sw_if_index, is_ipv6=False)
for ip in ipr:
self.cache['interface_addresses'][iface.sw_if_index].append(str(ip.prefix))
self.logger.debug("Retrieving IPv6 addresses for %s" % iface.interface_name)
self.logger.debug(f"Retrieving IPv6 addresses for {iface.interface_name}")
ipr = self.vpp.api.ip_address_dump(sw_if_index=iface.sw_if_index, is_ipv6=True)
for ip in ipr:
self.cache['interface_addresses'][iface.sw_if_index].append(str(ip.prefix))
@ -216,7 +216,7 @@ class VPPApi():
ret = True
for ifname in ifname_list:
if not ifname in self.cache['interface_names']:
self.logger.warning("Interface %s does not exist in VPP" % ifname)
self.logger.warning(f"Interface {ifname} does not exist in VPP")
ret = False
return ret

6
vppcfg
View File

@ -74,11 +74,11 @@ def main():
try:
with open(args.config, "r") as f:
logging.info("Loading configfile %s" % args.config)
logging.info(f"Loading configfile {args.config}")
cfg = yaml.load(f, Loader = yaml.FullLoader)
logging.debug("Config: %s" % cfg)
logging.debug(f"Config: {cfg}")
except:
logging.error("Couldn't read config from %s" % args.config)
logging.error(f"Couldn't read config from {args.config}")
sys.exit(-1)
v = Validator(schema=args.schema)