From 86fc62e20c830014e49a3ec3d794bbdc7fe818ff Mon Sep 17 00:00:00 2001 From: roopa Date: Fri, 9 May 2014 09:10:49 -0700 Subject: [PATCH] make a few things configurable (check output err/success string + warnings on ifupdown) Ticket: CM-1438 Reviewed By: Testing Done: Tested ifupdown2 sanity Some of the above mentioned configurable items can be specified in ifupdown2.conf --- config/ifupdown2.conf | 8 ++++++-- pkg/iface.py | 30 ++++++++++++------------------ pkg/ifupdownmain.py | 11 ++++++++++- pkg/scheduler.py | 18 ++++++++++++------ sbin/ifupdown | 4 ++-- 5 files changed, 42 insertions(+), 29 deletions(-) diff --git a/config/ifupdown2.conf b/config/ifupdown2.conf index b20bd42..bcd1401 100644 --- a/config/ifupdown2.conf +++ b/config/ifupdown2.conf @@ -1,7 +1,11 @@ # +# ifupdown2 configuration file # +# This file contains default settings for ifupdown # -TEMPLATE_ENGINE=mako -TEMPLATE_LOOKUPPATH=/etc/network/ifupdown2/templates +# default template engine (only mako is currently supported) +template_engine=mako +# default template lookup path during template rendering +template_lookuppath=/etc/network/ifupdown2/templates diff --git a/pkg/iface.py b/pkg/iface.py index 731ba84..3e1b50b 100644 --- a/pkg/iface.py +++ b/pkg/iface.py @@ -29,11 +29,6 @@ from collections import OrderedDict import logging import json -_tickmark = ' (' + u'\u2713' + ')' -_crossmark = ' (' + u'\u2717' + ')' -_success_sym = _tickmark -_error_sym = _crossmark - class ifaceStatus(): """Enumerates iface status """ @@ -292,13 +287,6 @@ class iface(): def get_config_attr_status(self, attr_name, idx=0): return self._config_status.get(attr_name, [])[idx] - def get_config_attr_status_str(self, attr_name, idx=0): - ret = self.get_config_attr_status(attr_name, idx) - if ret: - return _error_sym - else: - return _success_sym - def compare(self, dstiface): """ Compares two objects @@ -376,7 +364,8 @@ class iface(): logger.info(indent + indent + str(config)) logger.info('}') - def dump_pretty(self, with_status=False): + def dump_pretty(self, with_status=False, + successstr='success', errorstr='error'): indent = '\t' outbuf = '' if self.auto: @@ -389,9 +378,9 @@ class iface(): if with_status: if (self.status == ifaceStatus.NOTFOUND or self.status == ifaceStatus.ERROR): - outbuf += ' %s' %_error_sym - else: - outbuf += ' %s' %_success_sym + outbuf += ' (%s)' %errorstr + elif self.status == ifaceStatus.SUCCESS: + outbuf += ' (%s)' %successstr if self.status == ifaceStatus.NOTFOUND: if with_status: outbuf = (outbuf.encode('utf8') @@ -406,8 +395,13 @@ class iface(): for cv in cvaluelist: if not cv: continue if with_status: - outbuf += indent + '%s %s %s\n' %(cname, cv, - self.get_config_attr_status_str(cname, idx)) + s = self.get_config_attr_status(cname, idx) + if s: + outbuf += (indent + '%s %s (%s)\n' + %(cname, cv, errorstr)) + elif s == 0: + outbuf += (indent + '%s %s (%s)\n' + %(cname, cv, successstr)) else: outbuf += indent + '%s %s\n' %(cname, cv) idx += 1 diff --git a/pkg/ifupdownmain.py b/pkg/ifupdownmain.py index 36532bf..ee5666e 100644 --- a/pkg/ifupdownmain.py +++ b/pkg/ifupdownmain.py @@ -24,6 +24,11 @@ from collections import OrderedDict from graph import * from sets import Set +_tickmark = u'\u2713' +_crossmark = u'\u2717' +_success_sym = _tickmark +_error_sym = _crossmark + class ifupdownMain(ifupdownBase): """ ifupdown2 main class """ @@ -963,7 +968,11 @@ class ifupdownMain(ifupdownBase): print json.dumps(ifaceobjs, cls=ifaceJsonEncoder, indent=2, separators=(',', ': ')) else: - map(lambda i: i.dump_pretty(with_status=True), ifaceobjs) + map(lambda i: i.dump_pretty(with_status=True, + successstr=self.config.get('check_success_str', + _success_sym), + errorstr=self.config.get('check_error_str', _error_sym)), + ifaceobjs) return ret def print_ifaceobjsrunning_pretty(self, ifacenames, format='native'): diff --git a/pkg/scheduler.py b/pkg/scheduler.py index 9bdaf24..8865ec4 100644 --- a/pkg/scheduler.py +++ b/pkg/scheduler.py @@ -134,14 +134,16 @@ class ifaceScheduler(): Returns True or False indicating the caller to proceed with the operation. """ + # proceed only for down operation + if 'down' not in ops[0]: + return True + if (ifupdownobj.FORCE or not ifupdownobj.ADDONS_ENABLE or - not ifupdownobj.is_ifaceobj_noconfig(ifaceobj)): + (not ifupdownobj.is_ifaceobj_noconfig(ifaceobj) and + ifupdownobj.config.get('warn_on_ifdown', '0') == '0')): return True - # proceed only for down operation - if 'down' not in ops[0]: - return True ulist = ifaceobj.upperifaces if not ulist: return True @@ -156,8 +158,12 @@ class ifaceScheduler(): for u in tmpulist: if ifupdownobj.link_exists(u): if not ifupdownobj.ALL: - ifupdownobj.logger.info('%s: skipping interface down,' - %ifaceobj.name + ' upperiface %s still around ' %u) + if ifupdownobj.is_ifaceobj_noconfig(ifaceobj): + ifupdownobj.logger.info('%s: skipping interface down,' + %ifaceobj.name + ' upperiface %s still around ' %u) + else: + ifupdownobj.logger.warn('%s: skipping interface down,' + %ifaceobj.name + ' upperiface %s still around ' %u) return False return True diff --git a/sbin/ifupdown b/sbin/ifupdown index 336f552..b49f283 100755 --- a/sbin/ifupdown +++ b/sbin/ifupdown @@ -391,8 +391,8 @@ def main(argv): logger.error(str(e)) else: print str(e) - if args and not args.debug: - print '\nrerun the command with \'-d\' for a detailed errormsg' + #if args and not args.debug: + # print '\nrerun the command with \'-d\' for a detailed errormsg' exit(1) finally: deinit() -- 2.39.5