1
0
mirror of https://github.com/CumulusNetworks/ifupdown2.git synced 2024-05-06 15:54:50 +00:00

Fix upperiface check to not barf when --force is used

Ticket: CM-2366
Reviewed By: trivial
Testing Done: Tested ifup/ifdown with bonds and bridges

Also refactored some code.
This commit is contained in:
roopa
2014-03-06 14:37:28 -08:00
parent 5c72192578
commit 21c7daa773
2 changed files with 38 additions and 28 deletions

View File

@@ -386,7 +386,6 @@ class iface():
del odict['config_status']
del odict['flags']
del odict['priv_flags']
del odict['upperifaces']
del odict['raw_lines']
del odict['linkstate']
del odict['env']
@@ -400,7 +399,6 @@ class iface():
self.refcnt = 0
self.flags = 0
self.lowerifaces = None
self.upperifaces = None
self.linkstate = None
self.env = None
self.priv_flags = 0

View File

@@ -109,36 +109,33 @@ class ifaceScheduler():
if posthookfunc:
posthookfunc(ifupdownobj, ifaceobj)
@classmethod
def run_iface_graph(cls, ifupdownobj, ifacename, ops, parent=None,
order=ifaceSchedulerFlags.POSTORDER,
followdependents=True):
""" runs interface by traversing all nodes rooted at itself """
def _check_upperifaces(cls, ifupdownobj, ifaceobj, ops, parent):
""" Check if conflicting upper ifaces are around and warn if required
Returns False if this interface needs to be skipped, else return True """
# Each ifacename can have a list of iface objects
ifaceobjs = ifupdownobj.get_ifaceobjs(ifacename)
if not ifaceobjs:
raise Exception('%s: not found' %ifacename)
for ifaceobj in ifaceobjs:
ifacename = ifaceobj.get_name()
# Deal with upperdevs first
ulist = ifaceobj.get_upperifaces()
if ulist:
tmpulist = ([u for u in ulist if u != parent] if parent
else ulist)
if tmpulist:
if not tmpulist:
ifupdownobj.logger.info('Roopa: tmpulist = %s' %str(tmpulist))
return True
if 'down' in ops[0]:
# XXX: This is expensive. Find a cheaper way to do this
# if any of the upperdevs are present,
# dont down this interface
for u in tmpulist:
if ifupdownobj.link_exists(u):
if not ifupdownobj.ALL:
if not ifupdownobj.FORCE and not ifupdownobj.ALL:
ifupdownobj.logger.warn('%s: ' %ifacename +
' skip interface down,' +
' upperiface %s still around' %u)
return
return False
elif 'up' in ops[0] and not ifupdownobj.ALL:
# For 'up', just warn that there is an upperdev which is
# probably not up
@@ -146,7 +143,22 @@ class ifaceScheduler():
if not ifupdownobj.link_exists(u):
ifupdownobj.logger.warn('%s: upper iface %s '
%(ifacename, u) + 'does not exist')
return True
@classmethod
def run_iface_graph(cls, ifupdownobj, ifacename, ops, parent=None,
order=ifaceSchedulerFlags.POSTORDER,
followdependents=True):
""" runs interface by traversing all nodes rooted at itself """
# Each ifacename can have a list of iface objects
ifaceobjs = ifupdownobj.get_ifaceobjs(ifacename)
if not ifaceobjs:
raise Exception('%s: not found' %ifacename)
for ifaceobj in ifaceobjs:
if not cls._check_upperifaces(ifupdownobj, ifaceobj, ops, parent):
return
if order == ifaceSchedulerFlags.INORDER:
# If inorder, run the iface first and then its dependents
cls.run_iface_ops(ifupdownobj, ifaceobj, ops)