1
0
mirror of https://github.com/CumulusNetworks/ifupdown2.git synced 2024-05-06 15:54:50 +00:00
CumulusNetworks-ifupdown2/pkg/ifupdownbase.py
roopa f321512771 Fix l3 lag test failure
Ticket: CM-1438
Reviewed By:
Testing Done: l3 lag test with help from purna

- THe down sequence in the new ifupdown was causing switchd some grief
  (wilson is looking at it). readded the topological sort which i had
removed in favor of only walking the tree. With the fix,i dont see the
switchd problem anymore.
- And another down bug was causing the bond to go away prematurely (only
  with the all depends option). Added a upperdevice list to track upperdev references
2014-02-12 22:29:41 -08:00

67 lines
1.8 KiB
Python

#!/usr/bin/python
#
# Copyright 2013. Cumulus Networks, Inc.
# Author: Roopa Prabhu, roopa@cumulusnetworks.com
#
# ifupdownBase --
# base object for various ifupdown objects
#
import logging
import subprocess
import re
import os
from ifupdown.iface import *
class ifupdownBase(object):
def __init__(self):
modulename = self.__class__.__name__
self.logger = logging.getLogger('ifupdown.' + modulename)
def exec_command(self, cmd, cmdenv=None, nowait=False):
cmd_returncode = 0
cmdout = ''
try:
self.logger.debug('Executing ' + cmd)
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):
if (self.FORCE == True or re.search(r'exists', errmsg,
re.IGNORECASE | re.MULTILINE) is not None):
return True
return False
def log_warn(self, str):
if self.ignore_error(str) == False:
if self.logger.getEffectiveLevel() == logging.DEBUG:
traceback.print_stack()
self.logger.warn(str)
pass
def log_error(self, str):
if self.ignore_error(str) == False:
raise
#raise Exception(str)
else:
pass
def link_exists(self, ifacename):
return os.path.exists('/sys/class/net/%s' %ifacename)