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]
|
retconfig[k] = v[0]
|
||||||
else:
|
else:
|
||||||
retconfig[k] = v
|
retconfig[k] = v
|
||||||
|
|
||||||
return OrderedDict({'name' : o.name,
|
return OrderedDict({'name' : o.name,
|
||||||
'addr_method' : o.addr_method,
|
'addr_method' : o.addr_method,
|
||||||
'addr_family' : o.addr_family,
|
'addr_family' : o.addr_family,
|
||||||
|
@ -278,6 +278,7 @@ class ifupdownMain(ifupdownBase):
|
|||||||
# Get dependents for interface by querying respective modules
|
# Get dependents for interface by querying respective modules
|
||||||
for mname, module in self.modules.items():
|
for mname, module in self.modules.items():
|
||||||
module = self.modules.get(mname)
|
module = self.modules.get(mname)
|
||||||
|
try:
|
||||||
if ops[0] == 'query-running':
|
if ops[0] == 'query-running':
|
||||||
if (not hasattr(module,
|
if (not hasattr(module,
|
||||||
'get_dependent_ifacenames_running')):
|
'get_dependent_ifacenames_running')):
|
||||||
@ -288,6 +289,11 @@ class ifupdownMain(ifupdownBase):
|
|||||||
continue
|
continue
|
||||||
dlist = module.get_dependent_ifacenames(ifaceobj,
|
dlist = module.get_dependent_ifacenames(ifaceobj,
|
||||||
self.ifaceobjdict.keys())
|
self.ifaceobjdict.keys())
|
||||||
|
except Exception, e:
|
||||||
|
self.logger.warn('%s: error getting dependent interfaces (%s)'
|
||||||
|
%(ifaceobj.name, str(e)))
|
||||||
|
dlist = None
|
||||||
|
pass
|
||||||
if dlist:
|
if dlist:
|
||||||
self.logger.debug('%s: ' %ifaceobj.name +
|
self.logger.debug('%s: ' %ifaceobj.name +
|
||||||
'lowerifaces/dependents: %s' %str(dlist))
|
'lowerifaces/dependents: %s' %str(dlist))
|
||||||
@ -336,9 +342,14 @@ class ifupdownMain(ifupdownBase):
|
|||||||
|
|
||||||
def _module_syntax_checker(self, attrname, attrval):
|
def _module_syntax_checker(self, attrname, attrval):
|
||||||
for m, mdict in self.module_attrs.items():
|
for m, mdict in self.module_attrs.items():
|
||||||
|
if not mdict:
|
||||||
|
continue
|
||||||
attrsdict = mdict.get('attrs')
|
attrsdict = mdict.get('attrs')
|
||||||
if attrsdict and attrname in attrsdict.keys():
|
try:
|
||||||
|
if attrsdict.get(attrname):
|
||||||
return True
|
return True
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def read_default_iface_config(self):
|
def read_default_iface_config(self):
|
||||||
@ -435,8 +446,8 @@ class ifupdownMain(ifupdownBase):
|
|||||||
|
|
||||||
validrange = attrvaldict.get('validrange')
|
validrange = attrvaldict.get('validrange')
|
||||||
if validrange:
|
if validrange:
|
||||||
print('%svalidrange: %s'
|
print('%svalidrange: %d-%d'
|
||||||
%(indent + ' ', '-'.join(validrange)))
|
%(indent + ' ', validrange[0], validrange[1]))
|
||||||
|
|
||||||
validvals = attrvaldict.get('validvals')
|
validvals = attrvaldict.get('validvals')
|
||||||
if validvals:
|
if validvals:
|
||||||
|
@ -95,8 +95,15 @@ class networkInterfaces():
|
|||||||
[self.auto_ifaces.append(a) for a in auto_ifaces]
|
[self.auto_ifaces.append(a) for a in auto_ifaces]
|
||||||
return 0
|
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("_", "-")
|
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, [])
|
attrvallist = iface_config.get(newattrname, [])
|
||||||
if newattrname in ['scope', 'netmask', 'broadcast', 'preferred-lifetime']:
|
if newattrname in ['scope', 'netmask', 'broadcast', 'preferred-lifetime']:
|
||||||
# For attributes that are related and that can have multiple
|
# For attributes that are related and that can have multiple
|
||||||
@ -149,13 +156,8 @@ class networkInterfaces():
|
|||||||
continue
|
continue
|
||||||
attrname = attrs[0]
|
attrname = attrs[0]
|
||||||
attrval = attrs[1].strip(' ')
|
attrval = attrs[1].strip(' ')
|
||||||
try:
|
self._add_to_iface_config(iface_config, attrname, attrval,
|
||||||
if not self.callbacks.get('validate')(attrname, attrval):
|
line_idx+1)
|
||||||
self._parse_error(self._currentfile, line_idx + 1,
|
|
||||||
'unsupported keyword (%s)' %l)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
self._add_to_iface_config(iface_config, attrname, attrval)
|
|
||||||
lines_consumed = line_idx - cur_idx
|
lines_consumed = line_idx - cur_idx
|
||||||
|
|
||||||
# Create iface object
|
# Create iface object
|
||||||
|
Reference in New Issue
Block a user