mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
Fix splits everywhere to include space and tabs. Use regex split
Ticket: CM-3121 Reviewed By: Testing Done: Ran precommit Conflicts: packages/ifupdown2-addons/pkg/modulebase.py
This commit is contained in:
@@ -17,10 +17,8 @@ auto vlan-${v}
|
|||||||
iface vlan-${v} inet static
|
iface vlan-${v} inet static
|
||||||
bridge-ports glob swp1-6.${v}
|
bridge-ports glob swp1-6.${v}
|
||||||
bridge-stp on
|
bridge-stp on
|
||||||
bridge-treeprio 32768
|
|
||||||
bridge-ageing 200
|
bridge-ageing 200
|
||||||
bridge-maxhops 10
|
|
||||||
bridge-maxage 10
|
bridge-maxage 10
|
||||||
bridge-fdelay 10
|
bridge-fd 10
|
||||||
%endfor
|
%endfor
|
||||||
|
|
||||||
|
@@ -42,6 +42,7 @@ class networkInterfaces():
|
|||||||
self._template_engine = templateEngine(template_engine,
|
self._template_engine = templateEngine(template_engine,
|
||||||
template_lookuppath)
|
template_lookuppath)
|
||||||
self._currentfile_has_template = False
|
self._currentfile_has_template = False
|
||||||
|
self._ws_split_regex = re.compile(r'[\s\t]\s*')
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _currentfile(self):
|
def _currentfile(self):
|
||||||
@@ -90,7 +91,7 @@ class networkInterfaces():
|
|||||||
def process_allow(self, lines, cur_idx, lineno):
|
def process_allow(self, lines, cur_idx, lineno):
|
||||||
allow_line = lines[cur_idx]
|
allow_line = lines[cur_idx]
|
||||||
|
|
||||||
words = allow_line.split()
|
words = re.split(self._ws_split_regex, allow_line)
|
||||||
if len(words) <= 1:
|
if len(words) <= 1:
|
||||||
raise Exception('invalid allow line \'%s\' at line %d'
|
raise Exception('invalid allow line \'%s\' at line %d'
|
||||||
%(allow_line, lineno))
|
%(allow_line, lineno))
|
||||||
@@ -108,7 +109,7 @@ class networkInterfaces():
|
|||||||
def process_source(self, lines, cur_idx, lineno):
|
def process_source(self, lines, cur_idx, lineno):
|
||||||
# Support regex
|
# Support regex
|
||||||
self.logger.debug('processing sourced line ..\'%s\'' %lines[cur_idx])
|
self.logger.debug('processing sourced line ..\'%s\'' %lines[cur_idx])
|
||||||
sourced_file = lines[cur_idx].split(' ', 2)[1]
|
sourced_file = re.split(self._ws_split_regex, lines[cur_idx], 2)[1]
|
||||||
if sourced_file:
|
if sourced_file:
|
||||||
for f in glob.glob(sourced_file):
|
for f in glob.glob(sourced_file):
|
||||||
self.read_file(f)
|
self.read_file(f)
|
||||||
@@ -118,7 +119,7 @@ class networkInterfaces():
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
def process_auto(self, lines, cur_idx, lineno):
|
def process_auto(self, lines, cur_idx, lineno):
|
||||||
auto_ifaces = lines[cur_idx].split()[1:]
|
auto_ifaces = re.split(self._ws_split_regex, lines[cur_idx])[1:]
|
||||||
if not auto_ifaces:
|
if not auto_ifaces:
|
||||||
self._parse_error(self._currentfile, lineno,
|
self._parse_error(self._currentfile, lineno,
|
||||||
'invalid auto line \'%s\''%lines[cur_idx])
|
'invalid auto line \'%s\''%lines[cur_idx])
|
||||||
@@ -166,7 +167,7 @@ class networkInterfaces():
|
|||||||
|
|
||||||
ifaceobj = iface()
|
ifaceobj = iface()
|
||||||
iface_line = lines[cur_idx].strip(whitespaces)
|
iface_line = lines[cur_idx].strip(whitespaces)
|
||||||
iface_attrs = iface_line.split()
|
iface_attrs = re.split(self._ws_split_regex, iface_line)
|
||||||
ifacename = iface_attrs[1]
|
ifacename = iface_attrs[1]
|
||||||
|
|
||||||
ifaceobj.raw_config.append(iface_line)
|
ifaceobj.raw_config.append(iface_line)
|
||||||
@@ -176,19 +177,19 @@ class networkInterfaces():
|
|||||||
l = lines[line_idx].strip(whitespaces)
|
l = lines[line_idx].strip(whitespaces)
|
||||||
if self.ignore_line(l) == 1:
|
if self.ignore_line(l) == 1:
|
||||||
continue
|
continue
|
||||||
if self._is_keyword(l.split()[0]):
|
attrs = re.split(self._ws_split_regex, l, 1)
|
||||||
|
if self._is_keyword(attrs[0]):
|
||||||
line_idx -= 1
|
line_idx -= 1
|
||||||
break
|
break
|
||||||
ifaceobj.raw_config.append(l)
|
# if not a keyword, every line must have at least a key and value
|
||||||
# preprocess vars (XXX: only preprocesses $IFACE for now)
|
|
||||||
l = re.sub(r'\$IFACE', ifacename, l)
|
|
||||||
attrs = l.split(' ', 1)
|
|
||||||
if len(attrs) < 2:
|
if len(attrs) < 2:
|
||||||
self._parse_error(self._currentfile, line_idx,
|
self._parse_error(self._currentfile, line_idx,
|
||||||
'iface %s: invalid syntax \'%s\'' %(ifacename, l))
|
'iface %s: invalid syntax \'%s\'' %(ifacename, l))
|
||||||
continue
|
continue
|
||||||
|
ifaceobj.raw_config.append(l)
|
||||||
attrname = attrs[0]
|
attrname = attrs[0]
|
||||||
attrval = attrs[1].strip(' ')
|
# preprocess vars (XXX: only preprocesses $IFACE for now)
|
||||||
|
attrval = re.sub(r'\$IFACE', ifacename, attrs[1])
|
||||||
self._add_to_iface_config(ifacename, iface_config, attrname,
|
self._add_to_iface_config(ifacename, iface_config, attrname,
|
||||||
attrval, line_idx+1)
|
attrval, line_idx+1)
|
||||||
lines_consumed = line_idx - cur_idx
|
lines_consumed = line_idx - cur_idx
|
||||||
@@ -254,7 +255,7 @@ class networkInterfaces():
|
|||||||
if self.ignore_line(lines[line_idx]):
|
if self.ignore_line(lines[line_idx]):
|
||||||
line_idx += 1
|
line_idx += 1
|
||||||
continue
|
continue
|
||||||
words = lines[line_idx].split()
|
words = re.split(self._ws_split_regex, lines[line_idx])
|
||||||
if not words:
|
if not words:
|
||||||
line_idx += 1
|
line_idx += 1
|
||||||
continue
|
continue
|
||||||
|
Reference in New Issue
Block a user