mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
addons: vrf: vrf_slave: up vrf dev only when all interfaces are being
brought up Ticket: CM-10954, CM-10953 Reviewed By: julien Testing Done: ran ifupdown2 smoke and vrf ifup/ifdown testing - vrf master if not around is brought up when the first slave is brought up by design (because we want the slaves to be enslaved to a vrf master before addresses are configured). and master is not brought up by first because interfaces are brought up down to top in the dependency tree. - This patch makes sure a slave brings up a vrf master only when all interfaces are specified. When an individual interface is brought up, skip master bring up and throw an error. - Since the addon modules also need to use the ALL and WITH_DEPENDS flags, this patch moves them to the existing global ifupdownflags class - vrf module uses the ifupdownflags.ALL flag to not bring up the master when only the slave is being brought up example: ifup <vrf> # brings up the vrf device ifup <vrf> --with-depends # brings up the vrf dev and # its slaves ifup <vrf_slave> # if vrf master is not around, # an error is thrown ifup <vrf_slave> --with-depends # will still not bring up the vrf master ifdown <vrf> # deletes vrf dev and flushes the # addresses on vrf slaves ifup <vrf> # brings up vrf dev and does not # up the adresses on the slaves ifup <vrf> --with-depends # will bring up vrf and reapply config # on slaves (including addresses) Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
This commit is contained in:
@@ -351,15 +351,22 @@ class vrf(moduleBase):
|
|||||||
def _up_vrf_slave(self, ifacename, vrfname, ifaceobj=None,
|
def _up_vrf_slave(self, ifacename, vrfname, ifaceobj=None,
|
||||||
ifaceobj_getfunc=None, vrf_exists=False):
|
ifaceobj_getfunc=None, vrf_exists=False):
|
||||||
try:
|
try:
|
||||||
|
master_exists = True
|
||||||
if vrf_exists or self.ipcmd.link_exists(vrfname):
|
if vrf_exists or self.ipcmd.link_exists(vrfname):
|
||||||
upper = self.ipcmd.link_get_upper(ifacename)
|
upper = self.ipcmd.link_get_upper(ifacename)
|
||||||
if not upper or upper != vrfname:
|
if not upper or upper != vrfname:
|
||||||
self._handle_existing_connections(ifaceobj, vrfname)
|
self._handle_existing_connections(ifaceobj, vrfname)
|
||||||
self.ipcmd.link_set(ifacename, 'master', vrfname)
|
self.ipcmd.link_set(ifacename, 'master', vrfname)
|
||||||
elif ifaceobj:
|
elif ifupdownflags.flags.ALL and ifaceobj:
|
||||||
self._up_vrf_slave_without_master(ifacename, vrfname, ifaceobj,
|
self._up_vrf_slave_without_master(ifacename, vrfname, ifaceobj,
|
||||||
ifaceobj_getfunc)
|
ifaceobj_getfunc)
|
||||||
rtnetlink_api.rtnl_api.link_set(ifacename, "up")
|
else:
|
||||||
|
master_exists = False
|
||||||
|
if master_exists:
|
||||||
|
rtnetlink_api.rtnl_api.link_set(ifacename, "up")
|
||||||
|
else:
|
||||||
|
self.log_error('vrf %s not around, skipping vrf config'
|
||||||
|
%(vrfname))
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.log_error('%s: %s' %(ifacename, str(e)))
|
self.log_error('%s: %s' %(ifacename, str(e)))
|
||||||
|
|
||||||
@@ -455,6 +462,8 @@ class vrf(moduleBase):
|
|||||||
if add_slaves:
|
if add_slaves:
|
||||||
for s in add_slaves:
|
for s in add_slaves:
|
||||||
try:
|
try:
|
||||||
|
if not self.ipcmd.link_exists(s):
|
||||||
|
continue
|
||||||
sobj = None
|
sobj = None
|
||||||
if ifaceobj_getfunc:
|
if ifaceobj_getfunc:
|
||||||
sobj = ifaceobj_getfunc(s)
|
sobj = ifaceobj_getfunc(s)
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
class ifupdownFlags():
|
class ifupdownFlags():
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.ALL = False
|
||||||
self.FORCE = False
|
self.FORCE = False
|
||||||
self.DRYRUN = False
|
self.DRYRUN = False
|
||||||
self.NOWAIT = False
|
self.NOWAIT = False
|
||||||
|
@@ -40,8 +40,6 @@ _success_sym = '(%s)' %_tickmark
|
|||||||
_error_sym = '(%s)' %_crossmark
|
_error_sym = '(%s)' %_crossmark
|
||||||
|
|
||||||
class ifupdownMainFlags():
|
class ifupdownMainFlags():
|
||||||
WITH_DEPENDS = False
|
|
||||||
ALL = False
|
|
||||||
IFACE_CLASS = False
|
IFACE_CLASS = False
|
||||||
COMPAT_EXEC_SCRIPTS = False
|
COMPAT_EXEC_SCRIPTS = False
|
||||||
STATEMANAGER_ENABLE = True
|
STATEMANAGER_ENABLE = True
|
||||||
@@ -112,7 +110,8 @@ class ifupdownMain(ifupdownBase):
|
|||||||
# there is no real interface behind it
|
# there is no real interface behind it
|
||||||
if ifaceobj.type == ifaceType.BRIDGE_VLAN:
|
if ifaceobj.type == ifaceType.BRIDGE_VLAN:
|
||||||
return
|
return
|
||||||
if ifaceobj.link_kind & ifaceLinkKind.VRF:
|
if ((ifaceobj.link_kind & ifaceLinkKind.VRF) or
|
||||||
|
(ifaceobj.link_privflags & ifaceLinkPrivFlags.VRF_SLAVE)):
|
||||||
return
|
return
|
||||||
if (ifaceobj.addr_method and
|
if (ifaceobj.addr_method and
|
||||||
ifaceobj.addr_method == 'manual'):
|
ifaceobj.addr_method == 'manual'):
|
||||||
@@ -131,7 +130,8 @@ class ifupdownMain(ifupdownBase):
|
|||||||
self.link_up(ifaceobj.name)
|
self.link_up(ifaceobj.name)
|
||||||
|
|
||||||
def run_down(self, ifaceobj):
|
def run_down(self, ifaceobj):
|
||||||
if ifaceobj.link_kind & ifaceLinkKind.VRF:
|
if ((ifaceobj.link_kind & ifaceLinkKind.VRF) or
|
||||||
|
(ifaceobj.link_privflags & ifaceLinkPrivFlags.VRF_SLAVE)):
|
||||||
return
|
return
|
||||||
# Skip link sets on ifaceobjs of type 'vlan' (used for l2 attrs)
|
# Skip link sets on ifaceobjs of type 'vlan' (used for l2 attrs)
|
||||||
# there is no real interface behind it
|
# there is no real interface behind it
|
||||||
@@ -195,13 +195,13 @@ class ifupdownMain(ifupdownBase):
|
|||||||
ifupdownflags.flags.NOWAIT = nowait
|
ifupdownflags.flags.NOWAIT = nowait
|
||||||
ifupdownflags.flags.PERFMODE = perfmode
|
ifupdownflags.flags.PERFMODE = perfmode
|
||||||
ifupdownflags.flags.CACHE = cache
|
ifupdownflags.flags.CACHE = cache
|
||||||
|
ifupdownflags.flags.WITH_DEPENDS = withdepends
|
||||||
|
|
||||||
# Can be used to provide hints for caching
|
# Can be used to provide hints for caching
|
||||||
ifupdownflags.flags.CACHE_FLAGS = 0x0
|
ifupdownflags.flags.CACHE_FLAGS = 0x0
|
||||||
|
|
||||||
self.flags = ifupdownMainFlags()
|
self.flags = ifupdownMainFlags()
|
||||||
|
|
||||||
self.flags.WITH_DEPENDS = withdepends
|
|
||||||
self.flags.STATEMANAGER_ENABLE = statemanager_enable
|
self.flags.STATEMANAGER_ENABLE = statemanager_enable
|
||||||
self.interfacesfile = interfacesfile
|
self.interfacesfile = interfacesfile
|
||||||
self.interfacesfileiobuf = interfacesfileiobuf
|
self.interfacesfileiobuf = interfacesfileiobuf
|
||||||
@@ -1103,8 +1103,8 @@ class ifupdownMain(ifupdownBase):
|
|||||||
if not self.flags.ADDONS_ENABLE:
|
if not self.flags.ADDONS_ENABLE:
|
||||||
self.flags.STATEMANAGER_UPDATE = False
|
self.flags.STATEMANAGER_UPDATE = False
|
||||||
if auto:
|
if auto:
|
||||||
self.flags.ALL = True
|
ifupdownflags.flags.ALL = True
|
||||||
self.flags.WITH_DEPENDS = True
|
ifupdownflags.flags.WITH_DEPENDS = True
|
||||||
try:
|
try:
|
||||||
iface_read_ret = self.read_iface_config()
|
iface_read_ret = self.read_iface_config()
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -1143,7 +1143,8 @@ class ifupdownMain(ifupdownBase):
|
|||||||
ret = self._sched_ifaces(filtered_ifacenames, ops,
|
ret = self._sched_ifaces(filtered_ifacenames, ops,
|
||||||
skipupperifaces=skipupperifaces,
|
skipupperifaces=skipupperifaces,
|
||||||
followdependents=True
|
followdependents=True
|
||||||
if self.flags.WITH_DEPENDS else False)
|
if ifupdownflags.flags.WITH_DEPENDS
|
||||||
|
else False)
|
||||||
finally:
|
finally:
|
||||||
self._process_delay_admin_state_queue('up')
|
self._process_delay_admin_state_queue('up')
|
||||||
if not ifupdownflags.flags.DRYRUN and self.flags.ADDONS_ENABLE:
|
if not ifupdownflags.flags.DRYRUN and self.flags.ADDONS_ENABLE:
|
||||||
@@ -1164,8 +1165,8 @@ class ifupdownMain(ifupdownBase):
|
|||||||
if not self.flags.ADDONS_ENABLE:
|
if not self.flags.ADDONS_ENABLE:
|
||||||
self.flags.STATEMANAGER_UPDATE = False
|
self.flags.STATEMANAGER_UPDATE = False
|
||||||
if auto:
|
if auto:
|
||||||
self.flags.ALL = True
|
ifupdownflags.flags.ALL = True
|
||||||
self.flags.WITH_DEPENDS = True
|
ifupdownflags.flags.WITH_DEPENDS = True
|
||||||
# For down we need to look at old state, unless usecurrentconfig
|
# For down we need to look at old state, unless usecurrentconfig
|
||||||
# is set
|
# is set
|
||||||
if (not usecurrentconfig and self.flags.STATEMANAGER_ENABLE and
|
if (not usecurrentconfig and self.flags.STATEMANAGER_ENABLE and
|
||||||
@@ -1210,7 +1211,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
try:
|
try:
|
||||||
self._sched_ifaces(filtered_ifacenames, ops,
|
self._sched_ifaces(filtered_ifacenames, ops,
|
||||||
followdependents=True
|
followdependents=True
|
||||||
if self.flags.WITH_DEPENDS else False)
|
if ifupdownflags.flags.WITH_DEPENDS else False)
|
||||||
finally:
|
finally:
|
||||||
self._process_delay_admin_state_queue('down')
|
self._process_delay_admin_state_queue('down')
|
||||||
if not ifupdownflags.flags.DRYRUN and self.flags.ADDONS_ENABLE:
|
if not ifupdownflags.flags.DRYRUN and self.flags.ADDONS_ENABLE:
|
||||||
@@ -1236,8 +1237,8 @@ class ifupdownMain(ifupdownBase):
|
|||||||
self.flags.STATEMANAGER_UPDATE = False
|
self.flags.STATEMANAGER_UPDATE = False
|
||||||
if auto:
|
if auto:
|
||||||
self.logger.debug('setting flag ALL')
|
self.logger.debug('setting flag ALL')
|
||||||
self.flags.ALL = True
|
ifupdownflags.flags.ALL = True
|
||||||
self.flags.WITH_DEPENDS = True
|
ifupdownflags.flags.WITH_DEPENDS = True
|
||||||
|
|
||||||
if ops[0] == 'query-syntax':
|
if ops[0] == 'query-syntax':
|
||||||
self._modules_help()
|
self._modules_help()
|
||||||
@@ -1285,7 +1286,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
|
|
||||||
ret = self._sched_ifaces(filtered_ifacenames, ops,
|
ret = self._sched_ifaces(filtered_ifacenames, ops,
|
||||||
followdependents=True
|
followdependents=True
|
||||||
if self.flags.WITH_DEPENDS else False)
|
if ifupdownflags.flags.WITH_DEPENDS else False)
|
||||||
|
|
||||||
if ops[0] == 'query' and ifupdownflags.flags.WITHDEFAULTS:
|
if ops[0] == 'query' and ifupdownflags.flags.WITHDEFAULTS:
|
||||||
return self.print_ifaceobjs_pretty(filtered_ifacenames, format)
|
return self.print_ifaceobjs_pretty(filtered_ifacenames, format)
|
||||||
@@ -1371,8 +1372,8 @@ class ifupdownMain(ifupdownBase):
|
|||||||
# Now, run 'up' with new config dict
|
# Now, run 'up' with new config dict
|
||||||
# reset statemanager update flag to default
|
# reset statemanager update flag to default
|
||||||
if auto:
|
if auto:
|
||||||
self.flags.ALL = True
|
ifupdownflags.flags.ALL = True
|
||||||
self.flags.WITH_DEPENDS = True
|
ifupdownflags.flags.WITH_DEPENDS = True
|
||||||
if new_ifaceobjdict:
|
if new_ifaceobjdict:
|
||||||
# and now, ifaceobjdict is back to current config
|
# and now, ifaceobjdict is back to current config
|
||||||
self.ifaceobjdict = new_ifaceobjdict
|
self.ifaceobjdict = new_ifaceobjdict
|
||||||
@@ -1384,7 +1385,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
%str(interfaces_to_up))
|
%str(interfaces_to_up))
|
||||||
ret = self._sched_ifaces(interfaces_to_up, upops,
|
ret = self._sched_ifaces(interfaces_to_up, upops,
|
||||||
followdependents=True
|
followdependents=True
|
||||||
if self.flags.WITH_DEPENDS else False)
|
if ifupdownflags.flags.WITH_DEPENDS else False)
|
||||||
if ifupdownflags.flags.DRYRUN:
|
if ifupdownflags.flags.DRYRUN:
|
||||||
return
|
return
|
||||||
self._save_state()
|
self._save_state()
|
||||||
@@ -1557,8 +1558,8 @@ class ifupdownMain(ifupdownBase):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if auto:
|
if auto:
|
||||||
self.flags.ALL = True
|
ifupdownflags.flags.ALL = True
|
||||||
self.flags.WITH_DEPENDS = True
|
ifupdownflags.flags.WITH_DEPENDS = True
|
||||||
# and now, we are back to the current config in ifaceobjdict
|
# and now, we are back to the current config in ifaceobjdict
|
||||||
self.ifaceobjdict = new_ifaceobjdict
|
self.ifaceobjdict = new_ifaceobjdict
|
||||||
self.dependency_graph = new_dependency_graph
|
self.dependency_graph = new_dependency_graph
|
||||||
@@ -1569,7 +1570,8 @@ class ifupdownMain(ifupdownBase):
|
|||||||
try:
|
try:
|
||||||
ret = self._sched_ifaces(new_filtered_ifacenames, upops,
|
ret = self._sched_ifaces(new_filtered_ifacenames, upops,
|
||||||
followdependents=True
|
followdependents=True
|
||||||
if self.flags.WITH_DEPENDS else False)
|
if ifupdownflags.flags.WITH_DEPENDS
|
||||||
|
else False)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
ret = None
|
ret = None
|
||||||
self.logger.error(str(e))
|
self.logger.error(str(e))
|
||||||
@@ -1625,7 +1627,8 @@ class ifupdownMain(ifupdownBase):
|
|||||||
continue
|
continue
|
||||||
ifaceobj.dump_raw(self.logger)
|
ifaceobj.dump_raw(self.logger)
|
||||||
print '\n'
|
print '\n'
|
||||||
if self.flags.WITH_DEPENDS and not self.flags.ALL:
|
if (ifupdownflags.flags.WITH_DEPENDS and
|
||||||
|
not ifupdownflags.flags.ALL):
|
||||||
dlist = ifaceobj.lowerifaces
|
dlist = ifaceobj.lowerifaces
|
||||||
if not dlist: continue
|
if not dlist: continue
|
||||||
self.print_ifaceobjs_raw(dlist)
|
self.print_ifaceobjs_raw(dlist)
|
||||||
@@ -1639,7 +1642,8 @@ class ifupdownMain(ifupdownBase):
|
|||||||
(running and not ifaceobj.is_config_present())):
|
(running and not ifaceobj.is_config_present())):
|
||||||
continue
|
continue
|
||||||
ifaceobjs.append(ifaceobj)
|
ifaceobjs.append(ifaceobj)
|
||||||
if self.flags.WITH_DEPENDS and not self.flags.ALL:
|
if (ifupdownflags.flags.WITH_DEPENDS and
|
||||||
|
not ifupdownflags.flags.ALL):
|
||||||
dlist = ifaceobj.lowerifaces
|
dlist = ifaceobj.lowerifaces
|
||||||
if not dlist: continue
|
if not dlist: continue
|
||||||
self._get_ifaceobjs_pretty(dlist, ifaceobjs, running)
|
self._get_ifaceobjs_pretty(dlist, ifaceobjs, running)
|
||||||
@@ -1675,7 +1679,8 @@ class ifupdownMain(ifupdownBase):
|
|||||||
if self.is_ifaceobj_noconfig(ifaceobj):
|
if self.is_ifaceobj_noconfig(ifaceobj):
|
||||||
continue
|
continue
|
||||||
ifaceobjs.append(ifaceobj)
|
ifaceobjs.append(ifaceobj)
|
||||||
if self.flags.WITH_DEPENDS and not self.flags.ALL:
|
if (ifupdownflags.flags.WITH_DEPENDS and
|
||||||
|
not ifupdownflags.flags.ALL):
|
||||||
dlist = ifaceobj.lowerifaces
|
dlist = ifaceobj.lowerifaces
|
||||||
if not dlist: continue
|
if not dlist: continue
|
||||||
dret = self._get_ifaceobjscurr_pretty(dlist, ifaceobjs)
|
dret = self._get_ifaceobjscurr_pretty(dlist, ifaceobjs)
|
||||||
|
@@ -184,7 +184,7 @@ class ifaceScheduler():
|
|||||||
not ifupdownobj.flags.ADDONS_ENABLE or
|
not ifupdownobj.flags.ADDONS_ENABLE or
|
||||||
(not ifupdownobj.is_ifaceobj_noconfig(ifaceobj) and
|
(not ifupdownobj.is_ifaceobj_noconfig(ifaceobj) and
|
||||||
ifupdownobj.config.get('warn_on_ifdown', '0') == '0' and
|
ifupdownobj.config.get('warn_on_ifdown', '0') == '0' and
|
||||||
not ifupdownobj.flags.ALL)):
|
not ifupdownflags.flags.ALL)):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
ulist = ifaceobj.upperifaces
|
ulist = ifaceobj.upperifaces
|
||||||
@@ -201,7 +201,7 @@ class ifaceScheduler():
|
|||||||
# return false to the caller to skip this interface
|
# return false to the caller to skip this interface
|
||||||
for u in tmpulist:
|
for u in tmpulist:
|
||||||
if ifupdownobj.link_exists(u):
|
if ifupdownobj.link_exists(u):
|
||||||
if not ifupdownobj.flags.ALL:
|
if not ifupdownflags.flags.ALL:
|
||||||
if ifupdownobj.is_ifaceobj_noconfig(ifaceobj):
|
if ifupdownobj.is_ifaceobj_noconfig(ifaceobj):
|
||||||
ifupdownobj.logger.info('%s: skipping interface down,'
|
ifupdownobj.logger.info('%s: skipping interface down,'
|
||||||
%ifaceobj.name + ' upperiface %s still around ' %u)
|
%ifaceobj.name + ' upperiface %s still around ' %u)
|
||||||
@@ -423,7 +423,7 @@ class ifaceScheduler():
|
|||||||
ifacenames_all_sorted = graph.topological_sort_graphs_all(
|
ifacenames_all_sorted = graph.topological_sort_graphs_all(
|
||||||
dependency_graph, indegrees)
|
dependency_graph, indegrees)
|
||||||
# if ALL was set, return all interfaces
|
# if ALL was set, return all interfaces
|
||||||
if ifupdownobj.flags.ALL:
|
if ifupdownflags.flags.ALL:
|
||||||
return ifacenames_all_sorted
|
return ifacenames_all_sorted
|
||||||
|
|
||||||
# else return ifacenames passed as argument in sorted order
|
# else return ifacenames passed as argument in sorted order
|
||||||
@@ -480,7 +480,7 @@ class ifaceScheduler():
|
|||||||
for ifacename in dependency_graph.keys():
|
for ifacename in dependency_graph.keys():
|
||||||
indegrees[ifacename] = ifupdownobj.get_iface_refcnt(ifacename)
|
indegrees[ifacename] = ifupdownobj.get_iface_refcnt(ifacename)
|
||||||
|
|
||||||
if not ifupdownobj.flags.ALL:
|
if not ifupdownflags.flags.ALL:
|
||||||
if 'up' in ops[0]:
|
if 'up' in ops[0]:
|
||||||
# If there is any interface that does not exist, maybe it
|
# If there is any interface that does not exist, maybe it
|
||||||
# is a logical interface and we have to followupperifaces
|
# is a logical interface and we have to followupperifaces
|
||||||
@@ -537,7 +537,7 @@ class ifaceScheduler():
|
|||||||
|
|
||||||
if (not skipupperifaces and
|
if (not skipupperifaces and
|
||||||
ifupdownobj.config.get('skip_upperifaces', '0') == '0' and
|
ifupdownobj.config.get('skip_upperifaces', '0') == '0' and
|
||||||
((not ifupdownobj.flags.ALL and followdependents) or
|
((not ifupdownflags.flags.ALL and followdependents) or
|
||||||
followupperifaces) and
|
followupperifaces) and
|
||||||
'up' in ops[0]):
|
'up' in ops[0]):
|
||||||
# If user had given a set of interfaces to bring up
|
# If user had given a set of interfaces to bring up
|
||||||
|
Reference in New Issue
Block a user