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

Misc fixes. Add a --skip-upperifaces option to ifup (given the confusion

over ifup handling of upperifaces by default) + some fixes in the
reserved vlan check

Ticket: CM-3346
Reviewed By:
Testing Done: Tested ifupdown sanity.
This commit is contained in:
Roopa Prabhu
2014-11-25 10:19:35 -08:00
parent aa5751ba27
commit ad25e7bb98
5 changed files with 37 additions and 9 deletions

View File

@@ -336,6 +336,15 @@ class bridge(moduleBase):
b = list(b) b = list(b)
yield b[0][1], b[-1][1] yield b[0][1], b[-1][1]
def _handle_reserved_vlan(self, vlanid):
if vlanid in range(self._resv_vlan_range[0],
self._resv_vlan_range[1]):
self.logger.warn('skipping reserved vlan %d' %vlanid +
' (reserved vlan range %d-%d)' %(self._resv_vlan_range[0],
self._resv_vlan_range[1]))
return True
return False
def _ranges_to_ints(self, rangelist): def _ranges_to_ints(self, rangelist):
""" returns expanded list of integers given set of string ranges """ returns expanded list of integers given set of string ranges
example: ['1', '2-4', '6'] returns [1, 2, 3, 4, 6] example: ['1', '2-4', '6'] returns [1, 2, 3, 4, 6]
@@ -345,9 +354,14 @@ class bridge(moduleBase):
if '-' in part: if '-' in part:
a, b = part.split('-') a, b = part.split('-')
a, b = int(a), int(b) a, b = int(a), int(b)
if (self._handle_reserved_vlan(a) or
self._handle_reserved_vlan(b)):
continue
result.extend(range(a, b + 1)) result.extend(range(a, b + 1))
else: else:
a = int(part) a = int(part)
if self._handle_reserved_vlan(a):
continue
result.append(a) result.append(a)
return result return result

View File

@@ -625,7 +625,7 @@ class ifupdownMain(ifupdownBase):
# continue reading # continue reading
pass pass
def _sched_ifaces(self, ifacenames, ops): def _sched_ifaces(self, ifacenames, ops, skipupperifaces=False):
self.logger.debug('scheduling \'%s\' for %s' self.logger.debug('scheduling \'%s\' for %s'
%(str(ops), str(ifacenames))) %(str(ops), str(ifacenames)))
self._pretty_print_ordered_dict('dependency graph', self._pretty_print_ordered_dict('dependency graph',
@@ -635,7 +635,8 @@ class ifupdownMain(ifupdownBase):
order=ifaceSchedulerFlags.INORDER order=ifaceSchedulerFlags.INORDER
if 'down' in ops[0] if 'down' in ops[0]
else ifaceSchedulerFlags.POSTORDER, else ifaceSchedulerFlags.POSTORDER,
followdependents=True if self.WITH_DEPENDS else False) followdependents=True if self.WITH_DEPENDS else False,
skipupperifaces=skipupperifaces)
def _render_ifacename(self, ifacename): def _render_ifacename(self, ifacename):
new_ifacenames = [] new_ifacenames = []
@@ -753,7 +754,7 @@ class ifupdownMain(ifupdownBase):
def up(self, ops, auto=False, allow_classes=None, ifacenames=None, def up(self, ops, auto=False, allow_classes=None, ifacenames=None,
excludepats=None, printdependency=None, syntaxcheck=False, excludepats=None, printdependency=None, syntaxcheck=False,
type=None): type=None, skipupperifaces=False):
"""This brings the interface(s) up """This brings the interface(s) up
Args: Args:
@@ -806,7 +807,8 @@ class ifupdownMain(ifupdownBase):
self.populate_dependency_info(ops) self.populate_dependency_info(ops)
try: try:
self._sched_ifaces(filtered_ifacenames, ops) self._sched_ifaces(filtered_ifacenames, ops,
skipupperifaces=skipupperifaces)
finally: finally:
if not self.DRYRUN and self.ADDONS_ENABLE: if not self.DRYRUN and self.ADDONS_ENABLE:
self._save_state() self._save_state()

View File

@@ -336,7 +336,7 @@ class ifaceScheduler():
def sched_ifaces(cls, ifupdownobj, ifacenames, ops, def sched_ifaces(cls, ifupdownobj, ifacenames, ops,
dependency_graph=None, indegrees=None, dependency_graph=None, indegrees=None,
order=ifaceSchedulerFlags.POSTORDER, order=ifaceSchedulerFlags.POSTORDER,
followdependents=True): followdependents=True, skipupperifaces=False):
""" runs interface configuration modules on interfaces passed as """ runs interface configuration modules on interfaces passed as
argument. Runs topological sort on interface dependency graph. argument. Runs topological sort on interface dependency graph.
@@ -426,7 +426,8 @@ class ifaceScheduler():
if not cls._SCHED_RETVAL: if not cls._SCHED_RETVAL:
raise Exception() raise Exception()
if (ifupdownobj.config.get('skip_upperifaces', '0') == '0' and if (not skipupperifaces and
ifupdownobj.config.get('skip_upperifaces', '0') == '0' and
((not ifupdownobj.ALL and followdependents) or ((not ifupdownobj.ALL and followdependents) or
followupperifaces) and followupperifaces) and
'up' in ops[0]): 'up' in ops[0]):

View File

@@ -325,7 +325,9 @@ class moduleBase(object):
start = end = 0 start = end = 0
get_resvvlan = '/usr/share/python-ifupdown2/get_reserved_vlan_range.sh' get_resvvlan = '/usr/share/python-ifupdown2/get_reserved_vlan_range.sh'
try: try:
(start, end) = self.exec_command(get_resvvlan).split('-') (s, e) = self.exec_command(get_resvvlan).strip('\n').split('-')
start = int(s)
end = int(e)
except: except:
# ignore errors # ignore errors
pass pass

View File

@@ -51,13 +51,15 @@ def run_up(args):
ifupdown_handle.up(['up'], args.all, args.CLASS, iflist, ifupdown_handle.up(['up'], args.all, args.CLASS, iflist,
excludepats=args.excludepats, excludepats=args.excludepats,
printdependency=args.printdependency, printdependency=args.printdependency,
syntaxcheck=args.syntaxcheck, type=args.type) syntaxcheck=args.syntaxcheck, type=args.type,
skipupperifaces=args.skipupperifaces)
else: else:
ifupdown_handle.up(['pre-up', 'up', 'post-up'], ifupdown_handle.up(['pre-up', 'up', 'post-up'],
args.all, args.CLASS, iflist, args.all, args.CLASS, iflist,
excludepats=args.excludepats, excludepats=args.excludepats,
printdependency=args.printdependency, printdependency=args.printdependency,
syntaxcheck=args.syntaxcheck, type=args.type) syntaxcheck=args.syntaxcheck, type=args.type,
skipupperifaces=args.skipupperifaces)
except: except:
raise raise
@@ -260,6 +262,13 @@ def update_ifup_argparser(argparser):
argparser.add_argument('-s', '--syntax-check', dest='syntaxcheck', argparser.add_argument('-s', '--syntax-check', dest='syntaxcheck',
action='store_true', action='store_true',
help='Only run the interfaces file parser') help='Only run the interfaces file parser')
argparser.add_argument('-k', '--skip-upperifaces', dest='skipupperifaces',
action='store_true',
help='ifup by default tries to add newly created interfaces' +
' into its upper/parent interfaces. Eg. if a bridge port is' +
' created as a result of ifup on the port, ifup automatically' +
' adds the port to the bridge. This option can be used to ' +
'disable this default behaviour')
update_ifupdown_argparser(argparser) update_ifupdown_argparser(argparser)
def update_ifdown_argparser(argparser): def update_ifdown_argparser(argparser):