mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
ifupdown2: fix a few regex parsing error messages
Ticket: Reviewed By: CCR-3804 Testing Done: Tested regex parsing failures This is mostly a cosmetic fix. we were failing with weird/unclear errors on unable to parse regex expressions correctly. This patch mainly adds the interface name to the message and plus adds an info message showing the actual regex being used in searches. example config: {noformat} auto br-roopa iface br-roopa bridge-vlan-aware yes bridge-ports regex '(\\Aswp3\\Z|\\Aswp4\\Z)' bridge-pvid 20 {noformat} before the patch: warning: br-roopa: error getting dependent interfaces (unbalanced parenthesis) after the patch (not pretty but easier to debug) info: br-roopa: evaluating port expr '['regex', "'(", 'Aswp3', 'Z|', 'Aswp4', "Z)'"]' warning: br-roopa: error getting dependent interfaces (br-roopa: error searching regex ''(' in swp38 (unbalanced parenthesis)) (cherry picked from commit bcca6f753a25494666d53f1f2f3c855ffa41d7f0)
This commit is contained in:
committed by
Sam Tannous
parent
2722bb1972
commit
0c8332bc5e
@ -122,7 +122,8 @@ class bond(moduleBase):
|
||||
|
||||
if not self._is_bond(ifaceobj):
|
||||
return None
|
||||
slave_list = self.parse_port_list(ifaceobj.get_attr_value_first(
|
||||
slave_list = self.parse_port_list(ifaceobj.name,
|
||||
ifaceobj.get_attr_value_first(
|
||||
'bond-slaves'), ifacenames_all)
|
||||
ifaceobj.dependency_type = ifaceDependencyType.MASTER_SLAVE
|
||||
# Also save a copy for future use
|
||||
@ -146,7 +147,7 @@ class bond(moduleBase):
|
||||
return ifaceobj.priv_data
|
||||
slaves = ifaceobj.get_attr_value_first('bond-slaves')
|
||||
if slaves:
|
||||
return self.parse_port_list(slaves)
|
||||
return self.parse_port_list(ifaceobj.name, slaves)
|
||||
else:
|
||||
return None
|
||||
|
||||
@ -273,7 +274,7 @@ class bond(moduleBase):
|
||||
attrval = ifaceobj.get_attrs_value_first(['bond-lacp-bypass-priority',
|
||||
'bond-lacp-fallback-priority'])
|
||||
if attrval:
|
||||
portlist = self.parse_port_list(attrval)
|
||||
portlist = self.parse_port_list(ifaceobj.name, attrval)
|
||||
if not portlist:
|
||||
self.log_warn('%s: could not parse \'%s %s\''
|
||||
%(ifaceobj.name, attrname, attrval))
|
||||
|
@ -233,7 +233,8 @@ class bridge(moduleBase):
|
||||
ifaceobj.link_kind |= ifaceLinkKind.BRIDGE_VLAN_AWARE
|
||||
ifaceobj.role |= ifaceRole.MASTER
|
||||
ifaceobj.dependency_type = ifaceDependencyType.MASTER_SLAVE
|
||||
return self.parse_port_list(ifaceobj.get_attr_value_first(
|
||||
return self.parse_port_list(ifaceobj.name,
|
||||
ifaceobj.get_attr_value_first(
|
||||
'bridge-ports'), ifacenames_all)
|
||||
|
||||
def get_dependent_ifacenames_running(self, ifaceobj):
|
||||
@ -252,7 +253,7 @@ class bridge(moduleBase):
|
||||
return port_list
|
||||
ports = ifaceobj.get_attr_value_first('bridge-ports')
|
||||
if ports:
|
||||
return self.parse_port_list(ports)
|
||||
return self.parse_port_list(ifaceobj.name, ports)
|
||||
else:
|
||||
return None
|
||||
|
||||
@ -270,7 +271,8 @@ class bridge(moduleBase):
|
||||
return
|
||||
if waitporttime <= 0: return
|
||||
try:
|
||||
waitportlist = self.parse_port_list(waitportvals[1])
|
||||
waitportlist = self.parse_port_list(ifaceobj.name,
|
||||
waitportvals[1])
|
||||
except IndexError, e:
|
||||
# ignore error and use all bridge ports
|
||||
waitportlist = portlist
|
||||
@ -474,7 +476,7 @@ class bridge(moduleBase):
|
||||
# Install pvids
|
||||
attrval = ifaceobj.get_attr_value_first('bridge-port-pvids')
|
||||
if attrval:
|
||||
portlist = self.parse_port_list(attrval)
|
||||
portlist = self.parse_port_list(ifaceobj.name, attrval)
|
||||
if not portlist:
|
||||
self.log_warn('%s: could not parse \'%s %s\''
|
||||
%(ifaceobj.name, attrname, attrval))
|
||||
@ -496,7 +498,7 @@ class bridge(moduleBase):
|
||||
# install port vids
|
||||
attrval = ifaceobj.get_attr_value_first('bridge-port-vids')
|
||||
if attrval:
|
||||
portlist = self.parse_port_list(attrval)
|
||||
portlist = self.parse_port_list(ifaceobj.name, attrval)
|
||||
if not portlist:
|
||||
self.log_warn('%s: could not parse \'%s %s\''
|
||||
%(ifaceobj.name, attrname, attrval))
|
||||
@ -637,7 +639,7 @@ class bridge(moduleBase):
|
||||
attrval = ifaceobj.get_attr_value_first(attrname)
|
||||
if not attrval:
|
||||
continue
|
||||
portlist = self.parse_port_list(attrval)
|
||||
portlist = self.parse_port_list(ifaceobj.name, attrval)
|
||||
if not portlist:
|
||||
self.log_warn('%s: could not parse \'%s %s\''
|
||||
%(ifaceobj.name, attrname, attrval))
|
||||
@ -1229,7 +1231,7 @@ class bridge(moduleBase):
|
||||
attrval = ifaceobj.get_attr_value_first('bridge-port-vids')
|
||||
if attrval:
|
||||
running_bridge_port_vids = ''
|
||||
portlist = self.parse_port_list(attrval)
|
||||
portlist = self.parse_port_list(ifaceobj.name, attrval)
|
||||
if not portlist:
|
||||
self.log_warn('%s: could not parse \'%s %s\''
|
||||
%(ifaceobj.name, attrname, attrval))
|
||||
@ -1261,7 +1263,7 @@ class bridge(moduleBase):
|
||||
|
||||
attrval = ifaceobj.get_attr_value_first('bridge-port-pvids')
|
||||
if attrval:
|
||||
portlist = self.parse_port_list(attrval)
|
||||
portlist = self.parse_port_list(ifaceobj.name, attrval)
|
||||
if not portlist:
|
||||
self.log_warn('%s: could not parse \'%s %s\''
|
||||
%(ifaceobj.name, attrname, attrval))
|
||||
@ -1383,7 +1385,7 @@ class bridge(moduleBase):
|
||||
# <portname>=<portattrvalue>
|
||||
status = 0
|
||||
currstr = ''
|
||||
vlist = self.parse_port_list(v)
|
||||
vlist = self.parse_port_list(ifaceobj.name, v)
|
||||
if not vlist:
|
||||
continue
|
||||
for vlistitem in vlist:
|
||||
|
@ -186,7 +186,8 @@ class mstpctl(moduleBase):
|
||||
def get_dependent_ifacenames(self, ifaceobj, ifacenames_all=None):
|
||||
if not self._is_bridge(ifaceobj):
|
||||
return None
|
||||
return self.parse_port_list(ifaceobj.get_attr_value_first(
|
||||
return self.parse_port_list(ifaceobj.name,
|
||||
ifaceobj.get_attr_value_first(
|
||||
'mstpctl-ports'), ifacenames_all)
|
||||
|
||||
def get_dependent_ifacenames_running(self, ifaceobj):
|
||||
@ -206,7 +207,7 @@ class mstpctl(moduleBase):
|
||||
return port_list
|
||||
ports = ifaceobj.get_attr_value_first('mstpctl-ports')
|
||||
if ports:
|
||||
return self.parse_port_list(ports)
|
||||
return self.parse_port_list(ifaceobj.name, ports)
|
||||
else:
|
||||
return None
|
||||
|
||||
@ -274,7 +275,7 @@ class mstpctl(moduleBase):
|
||||
attrval = ifaceobj.get_attr_value_first(attrname)
|
||||
if not attrval:
|
||||
continue
|
||||
portlist = self.parse_port_list(attrval)
|
||||
portlist = self.parse_port_list(ifaceobj.name, attrval)
|
||||
if not portlist:
|
||||
self.log_warn('%s: error parsing \'%s %s\''
|
||||
%(ifaceobj.name, attrname, attrval))
|
||||
@ -588,7 +589,7 @@ class mstpctl(moduleBase):
|
||||
# <portname>=<portattrvalue>
|
||||
status = 0
|
||||
currstr = ''
|
||||
vlist = self.parse_port_list(v)
|
||||
vlist = self.parse_port_list(ifaceobj.name, v)
|
||||
if not vlist:
|
||||
continue
|
||||
for vlistitem in vlist:
|
||||
|
@ -126,27 +126,36 @@ class moduleBase(object):
|
||||
with open('/proc/net/dev') as f:
|
||||
try:
|
||||
lines = f.readlines()
|
||||
for line in lines:
|
||||
for line in lines[2:]:
|
||||
ifacenames.append(line.split()[0].strip(': '))
|
||||
except:
|
||||
raise
|
||||
return ifacenames
|
||||
|
||||
def parse_regex(self, expr, ifacenames=None):
|
||||
def parse_regex(self, ifacename, expr, ifacenames=None):
|
||||
try:
|
||||
proc_ifacenames = self.get_ifaces_from_proc()
|
||||
except:
|
||||
self.logger.warn('error reading ifaces from proc')
|
||||
self.logger.warn('%s: error reading ifaces from proc' %ifacename)
|
||||
|
||||
for proc_ifacename in proc_ifacenames:
|
||||
if re.search(expr + '$', proc_ifacename):
|
||||
yield proc_ifacename
|
||||
try:
|
||||
if re.search(expr + '$', proc_ifacename):
|
||||
yield proc_ifacename
|
||||
except Exception, e:
|
||||
raise Exception('%s: error searching regex \'%s\' in %s (%s)'
|
||||
%(ifacename, expr, proc_ifacename, str(e)))
|
||||
if not ifacenames:
|
||||
return
|
||||
for ifacename in ifacenames:
|
||||
if re.search(expr + '$', ifacename):
|
||||
yield ifacename
|
||||
try:
|
||||
if re.search(expr + '$', ifacename):
|
||||
yield ifacename
|
||||
except Exception, e:
|
||||
raise Exception('%s: error searching regex \'%s\' in %s (%s)'
|
||||
%(ifacename, expr, ifacename, str(e)))
|
||||
|
||||
def parse_glob(self, expr):
|
||||
def parse_glob(self, ifacename, expr):
|
||||
errmsg = ('error parsing glob expression \'%s\'' %expr +
|
||||
' (supported glob syntax: swp1-10.300 or swp[1-10].300' +
|
||||
' or swp[1-10]sub[0-4].300')
|
||||
@ -163,7 +172,7 @@ class moduleBase(object):
|
||||
mlist = m.groups()
|
||||
if len(mlist) < 7:
|
||||
# we have problems and should not continue
|
||||
raise Exception('Error: unhandled glob expression %s\n%s' % (expr,errmsg))
|
||||
raise Exception('%s: error: unhandled glob expression %s\n%s' % (ifacename, expr,errmsg))
|
||||
|
||||
prefix = mlist[0]
|
||||
suffix = mlist[6]
|
||||
@ -187,7 +196,7 @@ class moduleBase(object):
|
||||
m = regexs[2].match(expr)
|
||||
mlist = m.groups()
|
||||
if len(mlist) != 4:
|
||||
raise Exception(errmsg + '(unexpected len)')
|
||||
raise Exception('%s: ' %ifacename + errmsg + '(unexpected len)')
|
||||
prefix = mlist[0]
|
||||
suffix = mlist[3]
|
||||
start_index = int(mlist[1])
|
||||
@ -197,10 +206,10 @@ class moduleBase(object):
|
||||
|
||||
else:
|
||||
# Could not match anything.
|
||||
self.logger.warn('%s' %(errmsg))
|
||||
self.logger.warn('%s: %s' %(ifacename, errmsg))
|
||||
yield expr
|
||||
|
||||
def parse_port_list(self, port_expr, ifacenames=None):
|
||||
def parse_port_list(self, ifacename, port_expr, ifacenames=None):
|
||||
""" parse port list containing glob and regex
|
||||
|
||||
Args:
|
||||
@ -213,7 +222,10 @@ class moduleBase(object):
|
||||
|
||||
if not port_expr:
|
||||
return None
|
||||
for expr in re.split(r'[\s\t]\s*', port_expr):
|
||||
exprs = re.split(r'[\s\t]\s*', port_expr)
|
||||
self.logger.info('%s: evaluating port expr \'%s\''
|
||||
%(ifacename, str(exprs)))
|
||||
for expr in exprs:
|
||||
if expr == 'noregex':
|
||||
regex = 0
|
||||
elif expr == 'noglob':
|
||||
@ -223,7 +235,7 @@ class moduleBase(object):
|
||||
elif expr == 'glob':
|
||||
glob = 1
|
||||
elif regex:
|
||||
for port in self.parse_regex(expr, ifacenames):
|
||||
for port in self.parse_regex(ifacename, expr, ifacenames):
|
||||
if port not in portlist:
|
||||
portlist.append(port)
|
||||
regex = 0
|
||||
|
Reference in New Issue
Block a user