mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
Fix a few syntax checker bugs
Ticket: CM-2302 Reviewed By: Testing Done: Tested ifupdown syntax checker + sanity Also includes fixes to some of the sytax checker problems mentioned in CM-2509
This commit is contained in:
@ -131,7 +131,6 @@ class ifaceJsonEncoder(json.JSONEncoder):
|
||||
retconfig[k] = v[0]
|
||||
else:
|
||||
retconfig[k] = v
|
||||
|
||||
return OrderedDict({'name' : o.name,
|
||||
'addr_method' : o.addr_method,
|
||||
'addr_family' : o.addr_family,
|
||||
|
@ -278,6 +278,7 @@ class ifupdownMain(ifupdownBase):
|
||||
# Get dependents for interface by querying respective modules
|
||||
for mname, module in self.modules.items():
|
||||
module = self.modules.get(mname)
|
||||
try:
|
||||
if ops[0] == 'query-running':
|
||||
if (not hasattr(module,
|
||||
'get_dependent_ifacenames_running')):
|
||||
@ -288,6 +289,11 @@ class ifupdownMain(ifupdownBase):
|
||||
continue
|
||||
dlist = module.get_dependent_ifacenames(ifaceobj,
|
||||
self.ifaceobjdict.keys())
|
||||
except Exception, e:
|
||||
self.logger.warn('%s: error getting dependent interfaces (%s)'
|
||||
%(ifaceobj.name, str(e)))
|
||||
dlist = None
|
||||
pass
|
||||
if dlist:
|
||||
self.logger.debug('%s: ' %ifaceobj.name +
|
||||
'lowerifaces/dependents: %s' %str(dlist))
|
||||
@ -336,9 +342,14 @@ class ifupdownMain(ifupdownBase):
|
||||
|
||||
def _module_syntax_checker(self, attrname, attrval):
|
||||
for m, mdict in self.module_attrs.items():
|
||||
if not mdict:
|
||||
continue
|
||||
attrsdict = mdict.get('attrs')
|
||||
if attrsdict and attrname in attrsdict.keys():
|
||||
try:
|
||||
if attrsdict.get(attrname):
|
||||
return True
|
||||
except AttributeError:
|
||||
pass
|
||||
return False
|
||||
|
||||
def read_default_iface_config(self):
|
||||
@ -435,8 +446,8 @@ class ifupdownMain(ifupdownBase):
|
||||
|
||||
validrange = attrvaldict.get('validrange')
|
||||
if validrange:
|
||||
print('%svalidrange: %s'
|
||||
%(indent + ' ', '-'.join(validrange)))
|
||||
print('%svalidrange: %d-%d'
|
||||
%(indent + ' ', validrange[0], validrange[1]))
|
||||
|
||||
validvals = attrvaldict.get('validvals')
|
||||
if validvals:
|
||||
|
@ -95,8 +95,15 @@ class networkInterfaces():
|
||||
[self.auto_ifaces.append(a) for a in auto_ifaces]
|
||||
return 0
|
||||
|
||||
def _add_to_iface_config(self, iface_config, attrname, attrval):
|
||||
def _add_to_iface_config(self, iface_config, attrname, attrval, lineno):
|
||||
newattrname = attrname.replace("_", "-")
|
||||
try:
|
||||
if not self.callbacks.get('validate')(newattrname, attrval):
|
||||
self._parse_error(self._currentfile, lineno,
|
||||
'unsupported keyword (%s)' %attrname)
|
||||
return
|
||||
except:
|
||||
pass
|
||||
attrvallist = iface_config.get(newattrname, [])
|
||||
if newattrname in ['scope', 'netmask', 'broadcast', 'preferred-lifetime']:
|
||||
# For attributes that are related and that can have multiple
|
||||
@ -149,13 +156,8 @@ class networkInterfaces():
|
||||
continue
|
||||
attrname = attrs[0]
|
||||
attrval = attrs[1].strip(' ')
|
||||
try:
|
||||
if not self.callbacks.get('validate')(attrname, attrval):
|
||||
self._parse_error(self._currentfile, line_idx + 1,
|
||||
'unsupported keyword (%s)' %l)
|
||||
except:
|
||||
pass
|
||||
self._add_to_iface_config(iface_config, attrname, attrval)
|
||||
self._add_to_iface_config(iface_config, attrname, attrval,
|
||||
line_idx+1)
|
||||
lines_consumed = line_idx - cur_idx
|
||||
|
||||
# Create iface object
|
||||
|
Reference in New Issue
Block a user