1
0
mirror of https://github.com/CumulusNetworks/ifupdown2.git synced 2024-05-06 15:54:50 +00:00

cleanup + fix some reload caching issues

Ticket: CM-2508
Reviewed By:
Testing Done: ifreload and ifupdown sanity testing
This commit is contained in:
roopa
2014-04-04 15:00:59 -07:00
parent 7538dc77f5
commit 525f0a30ef
5 changed files with 22 additions and 27 deletions

View File

@@ -22,24 +22,22 @@ class ifupdownBase(object):
def exec_command(self, cmd, cmdenv=None, nowait=False):
cmd_returncode = 0
cmdout = ''
try:
self.logger.info('Executing ' + cmd)
if self.DRYRUN:
return cmdout
ch = subprocess.Popen(cmd.split(),
stdout=subprocess.PIPE,
shell=False, env=cmdenv,
stderr=subprocess.STDOUT)
cmdout = ch.communicate()[0]
cmd_returncode = ch.wait()
except OSError, e:
raise Exception('could not execute ' + cmd +
'(' + str(e) + ')')
if cmd_returncode != 0:
raise Exception('error executing cmd \'%s\'' %cmd +
'\n(' + cmdout.strip('\n ') + ')')
return cmdout
def ignore_error(self, errmsg):

View File

@@ -118,6 +118,8 @@ class ifupdownMain(ifupdownBase):
self.STATEMANAGER_ENABLE = statemanager_enable
self.CACHE = cache
self.logger.debug("Roopa: DRYRUN = %s" %self.DRYRUN)
# Can be used to provide hints for caching
self.CACHE_FLAGS = 0x0
self._DELETE_DEPENDENT_IFACES_WITH_NOCONFIG = False
@@ -290,7 +292,7 @@ class ifupdownMain(ifupdownBase):
self.ifaceobjdict.keys())
if dlist:
self.logger.debug('%s: ' %ifaceobj.name +
'got lowerifaces/dependents: %s' %str(dlist))
'lowerifaces/dependents: %s' %str(dlist))
break
return dlist
@@ -614,12 +616,11 @@ class ifupdownMain(ifupdownBase):
else:
self.populate_dependency_info(ops)
self._sched_ifaces(filtered_ifacenames, ops)
if self.DRYRUN and self.ADDONS_ENABLE:
return
self._save_state()
try:
self._sched_ifaces(filtered_ifacenames, ops)
finally:
if not self.DRYRUN and self.ADDONS_ENABLE:
self._save_state()
def down(self, ops, auto=False, allow_classes=None, ifacenames=None,
excludepats=None, printdependency=None, usecurrentconfig=False):
@@ -664,10 +665,12 @@ class ifupdownMain(ifupdownBase):
return
else:
self.populate_dependency_info(ops)
self._sched_ifaces(filtered_ifacenames, ops)
if self.DRYRUN and self.ADDONS_ENABLE:
return
self._save_state()
try:
self._sched_ifaces(filtered_ifacenames, ops)
finally:
if not self.DRYRUN and self.ADDONS_ENABLE:
self._save_state()
def query(self, ops, auto=False, allow_classes=None, ifacenames=None,
excludepats=None, printdependency=None,
@@ -835,9 +838,9 @@ class ifupdownMain(ifupdownBase):
self._save_state()
def _pretty_print_ordered_dict(self, prefix, argdict):
outbuf = prefix + ' {'
outbuf = prefix + ' {\n'
for k, vlist in argdict.items():
outbuf += '%s : %s\n' %(k, str(vlist))
outbuf += '\t%s : %s\n' %(k, str(vlist))
self.logger.debug(outbuf + '}')
def print_dependency(self, ifacenames, format):

View File

@@ -100,7 +100,7 @@ class ifaceScheduler():
# minor optimization. If operation is 'down', proceed only
# if interface exists in the system
if 'down' in ops[0] and not ifupdownobj.link_exists(ifacename):
ifupdownobj.logger.info('%s: does not exist' %ifacename)
ifupdownobj.logger.debug('%s: does not exist' %ifacename)
return
cenv=None
if ifupdownobj.COMPAT_EXEC_SCRIPTS:

View File

@@ -108,8 +108,9 @@ class stateManager():
try:
with open(self.state_file, 'w') as f:
if not len(self.ifaceobjdict):
os.remove(self.state_file)
f.truncate(0)
return
self.logger.debug('saving state ..')
for ifaceobjs in self.ifaceobjdict.values():
[pickling.save_obj(f, i) for i in ifaceobjs]
except:

View File

@@ -52,15 +52,11 @@ def run_down(args):
try:
iflist = args.iflist
logger.debug('creating ifupdown object ..')
cachearg=(False if (iflist or args.nocache or
args.perfmode or args.noact)
else True)
ifupdown_handle = ifupdownMain(force=args.force,
withdepends=args.withdepends,
perfmode=args.perfmode,
njobs=args.jobs,
dryrun=args.noact,
cache=cachearg,
addons_enable=not args.noaddons,
statemanager_enable=not args.noaddons)
@@ -116,12 +112,9 @@ def run_reload(args):
try:
logger.debug('creating ifupdown object ..')
cachearg=(False if (args.nocache or
args.perfmode or args.noact) else True)
ifupdown_handle = ifupdownMain(withdepends=args.withdepends,
perfmode=args.perfmode,
njobs=args.jobs,
cache=cachearg)
njobs=args.jobs)
ifupdown_handle.reload(['pre-up', 'up', 'post-up'],
['pre-down', 'down', 'post-down'],
args.all, None, None,