mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
Fixes for some corner cases + cleanup
Ticket: CM-1438 Reviewed By: Testing Done: Also includes fix for CM-2307 and some other fixes for primary/secondary address handling.
This commit is contained in:
52
pkg/iface.py
52
pkg/iface.py
@@ -34,7 +34,7 @@ class ifaceStatus():
|
||||
elif state == cls.ERROR:
|
||||
return 'error'
|
||||
elif state == cls.NOTFOUND:
|
||||
return 'not found'
|
||||
return 'notfound'
|
||||
|
||||
@classmethod
|
||||
def from_str(cls, state_str):
|
||||
@@ -136,6 +136,7 @@ class iface():
|
||||
self.addr_family = None
|
||||
self.addr_method = None
|
||||
self.config = OrderedDict()
|
||||
self.config_status = {}
|
||||
self.state = ifaceState.NEW
|
||||
self.status = ifaceStatus.UNKNOWN
|
||||
self.errstr = ''
|
||||
@@ -231,6 +232,12 @@ class iface():
|
||||
|
||||
return False
|
||||
|
||||
def set_priv_flags(self, priv_flags):
|
||||
self.priv_flags = priv_flags
|
||||
|
||||
def get_priv_flags(self):
|
||||
return self.priv_flags
|
||||
|
||||
def get_state(self):
|
||||
return self.state
|
||||
|
||||
@@ -336,19 +343,32 @@ class iface():
|
||||
self.config.update(attrdict)
|
||||
|
||||
def update_config_with_status(self, attr_name, attr_value, attr_status=0):
|
||||
if attr_value is None:
|
||||
if not attr_value:
|
||||
attr_value = ''
|
||||
|
||||
if self.config.get(attr_name):
|
||||
self.config[attr_name].append(attr_value)
|
||||
self.config_status[attr_name].append(attr_status)
|
||||
else:
|
||||
self.config[attr_name] = [attr_value]
|
||||
self.config_status[attr_name] = [attr_status]
|
||||
|
||||
# set global iface state
|
||||
if attr_status:
|
||||
self.set_status(ifaceStatus.ERROR)
|
||||
new_attr_value = '%s (%s)' %(attr_value, crossmark)
|
||||
elif self.get_status() != ifaceStatus.ERROR:
|
||||
# Not already error, mark success
|
||||
self.set_status(ifaceStatus.SUCCESS)
|
||||
|
||||
def get_config_attr_status(self, attr_name, idx=0):
|
||||
self.config_status.get(attr_name, [])[idx]
|
||||
|
||||
def get_config_attr_status_str(self, attr_name, idx=0):
|
||||
ret = self.config_status.get(attr_name, [])[idx]
|
||||
if ret:
|
||||
return crossmark
|
||||
else:
|
||||
new_attr_value = '%s (%s)' %(attr_value, tickmark)
|
||||
if self.get_status() != ifaceStatus.ERROR:
|
||||
self.set_status(ifaceStatus.SUCCESS)
|
||||
if self.config.get(attr_name) is not None:
|
||||
self.config[attr_name].append(new_attr_value)
|
||||
else:
|
||||
self.config[attr_name] = [new_attr_value]
|
||||
return tickmark
|
||||
|
||||
def is_different(self, dstiface):
|
||||
if self.name != dstiface.name: return True
|
||||
@@ -410,7 +430,7 @@ class iface():
|
||||
logger.info(indent + indent + str(config))
|
||||
logger.info('}')
|
||||
|
||||
def dump_pretty(self):
|
||||
def dump_pretty(self, with_status=False):
|
||||
indent = '\t'
|
||||
outbuf = ''
|
||||
if self.get_auto():
|
||||
@@ -427,10 +447,16 @@ class iface():
|
||||
config = self.get_config()
|
||||
if config is not None:
|
||||
for cname, cvaluelist in config.items():
|
||||
idx = 0
|
||||
for cv in cvaluelist:
|
||||
outbuf += indent + '%s' %cname + ' %s\n' %cv
|
||||
if with_status:
|
||||
outbuf += indent + '%s %s %s\n' %(cname, cv,
|
||||
self.get_config_attr_status_str(cname, idx))
|
||||
else:
|
||||
outbuf += indent + '%s %s\n' %(cname, cv)
|
||||
idx += 1
|
||||
|
||||
print outbuf
|
||||
|
||||
def dump_json(self):
|
||||
def dump_json(self, with_status=False):
|
||||
print json.dumps(self, cls=ifaceJsonEncoder, indent=4)
|
||||
|
@@ -206,12 +206,13 @@ class ifupdownMain(ifupdownBase):
|
||||
def create_n_save_ifaceobjcurr(self, ifaceobj):
|
||||
ifacename = ifaceobj.get_name()
|
||||
ifaceobjcurr = self.get_ifaceobjcurr(ifacename)
|
||||
if ifaceobjcurr is not None:
|
||||
if ifaceobjcurr:
|
||||
return ifaceobjcurr
|
||||
|
||||
ifaceobjcurr = iface()
|
||||
ifaceobjcurr.set_name(ifacename)
|
||||
ifaceobjcurr.set_lowerifaces(ifaceobj.get_lowerifaces())
|
||||
ifaceobjcurr.set_priv_flags(ifaceobj.get_priv_flags())
|
||||
self.ifaceobjcurrdict[ifacename] = ifaceobjcurr
|
||||
|
||||
return ifaceobjcurr
|
||||
@@ -1033,7 +1034,8 @@ class ifupdownMain(ifupdownBase):
|
||||
ifaceobj = self.get_ifaceobjcurr(i)
|
||||
if not ifaceobj: continue
|
||||
if ifaceobj.get_status() == ifaceStatus.NOTFOUND:
|
||||
print 'iface %s' %ifaceobj.get_name() + ' (not found)\n'
|
||||
print 'iface %s %s\n' %(ifaceobj.get_name(),
|
||||
ifaceStatus.to_str(ifaceStatus.NOTFOUND))
|
||||
ret = 1
|
||||
continue
|
||||
elif ifaceobj.get_status() == ifaceStatus.ERROR:
|
||||
@@ -1043,15 +1045,14 @@ class ifupdownMain(ifupdownBase):
|
||||
continue
|
||||
|
||||
if format == 'json':
|
||||
ifaceobj.dump_json()
|
||||
ifaceobj.dump_json(with_status=True)
|
||||
else:
|
||||
ifaceobj.dump_pretty()
|
||||
ifaceobj.dump_pretty(with_status=True)
|
||||
|
||||
if self.WITH_DEPENDS:
|
||||
dlist = ifaceobj.get_lowerifaces()
|
||||
if not dlist or not len(dlist): continue
|
||||
self.print_ifaceobjscurr_pretty(dlist, format)
|
||||
|
||||
return ret
|
||||
|
||||
def print_ifaceobjsrunning_pretty(self, ifacenames, format='native'):
|
||||
|
@@ -14,6 +14,7 @@ from collections import deque
|
||||
from collections import OrderedDict
|
||||
import logging
|
||||
import traceback
|
||||
import sys
|
||||
from graph import *
|
||||
from collections import deque
|
||||
from threading import *
|
||||
@@ -198,6 +199,8 @@ class ifaceScheduler():
|
||||
order, followdependents)
|
||||
except Exception, e:
|
||||
if continueonfailure:
|
||||
if ifupdownobj.logger.isEnabledFor(logging.DEBUG):
|
||||
traceback.print_tb(sys.exc_info()[2])
|
||||
ifupdownobj.logger.error('%s : %s' %(ifacename, str(e)))
|
||||
pass
|
||||
else:
|
||||
|
Reference in New Issue
Block a user