Add MTU value checking and log messages

Ensures that if a specified MTU is more than the maximum it is set to
the maximum instead, and adds warning messages for both situations.
This commit is contained in:
Joshua Boniface 2021-10-09 18:48:56 -04:00
parent 87cda72ca9
commit 6ce28c43af
1 changed files with 39 additions and 1 deletions

View File

@ -83,9 +83,28 @@ class VXNetworkInstance(object):
except Exception: except Exception:
self.vx_mtu = None self.vx_mtu = None
update_mtu = False
# Explicitly set the MTU to max_mtu if unset (in Zookeeper too assuming the key exists) # Explicitly set the MTU to max_mtu if unset (in Zookeeper too assuming the key exists)
if self.vx_mtu == '' or self.vx_mtu is None: if self.vx_mtu == '' or self.vx_mtu is None:
self.logger.out(
'MTU not specified; setting to maximum MTU {} instead'.format(self.max_mtu),
prefix='VNI {}'.format(self.vni),
state='w'
)
self.vx_mtu = self.max_mtu self.vx_mtu = self.max_mtu
update_mtu = True
# Ensure the MTU is valid
if self.vx_mtu > self.max_mtu:
self.logger.out(
'MTU {} is larger than maximum MTU {}; setting to maximum MTU instead'.format(self.vx_mtu, self.max_mtu),
prefix='VNI {}'.format(self.vni),
state='w'
)
self.vx_mtu = self.max_mtu
update_mtu = True
if update_mtu:
# Try block for migration purposes # Try block for migration purposes
try: try:
self.zkhandler.write([ self.zkhandler.write([
@ -145,11 +164,30 @@ class VXNetworkInstance(object):
except Exception: except Exception:
self.vx_mtu = None self.vx_mtu = None
update_mtu = False
# Explicitly set the MTU to max_mtu if unset (in Zookeeper too assuming the key exists) # Explicitly set the MTU to max_mtu if unset (in Zookeeper too assuming the key exists)
if self.vx_mtu == '' or self.vx_mtu is None: if self.vx_mtu == '' or self.vx_mtu is None:
self.logger.out(
'MTU not specified; setting to maximum MTU {} instead'.format(self.max_mtu),
prefix='VNI {}'.format(self.vni),
state='w'
)
self.vx_mtu = self.max_mtu self.vx_mtu = self.max_mtu
update_mtu = True
# Ensure the MTU is valid
if self.vx_mtu > self.max_mtu:
self.logger.out(
'MTU {} is larger than maximum MTU {}; setting to maximum MTU instead'.format(self.vx_mtu, self.max_mtu),
prefix='VNI {}'.format(self.vni),
state='w'
)
self.vx_mtu = self.max_mtu
update_mtu = True
if update_mtu:
# Try block for migration purposes
try: try:
# Try block for migration purposes
self.zkhandler.write([ self.zkhandler.write([
(('network.mtu', self.vni), self.vx_mtu) (('network.mtu', self.vni), self.vx_mtu)
]) ])