From: Ben Pfaff Date: Thu, 8 Jul 2010 13:25:51 +0000 (+0100) Subject: [PATCH] xenserver: Add --no-syslog feature to interface-reconfigure. X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=9ec5072b4c6072722be64f14c667e14cf1727866;p=xcp%2Fxen-api.git [PATCH] xenserver: Add --no-syslog feature to interface-reconfigure. From b63fadcfdc8a96ddb5e944b60733edf21999a1ad Mon Sep 17 00:00:00 2001 Date: Mon, 22 Feb 2010 16:26:50 -0800 This makes it easier to do unit tests (some of which will be added in an upcoming commit) by allowing messages to be read from stderr instead of having to somehow intercept syslog calls. Signed-off-by: Ben Pfaff Signed-off-by: Ian Campbell --- .../opt_xensource_libexec_InterfaceReconfigure.py | 16 +++++++++++++++- .../opt_xensource_libexec_interface-reconfigure | 9 +++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) --- diff --git a/scripts/InterfaceReconfigure.py b/scripts/InterfaceReconfigure.py index 089283db..3c3a0195 100644 --- a/scripts/InterfaceReconfigure.py +++ b/scripts/InterfaceReconfigure.py @@ -10,6 +10,7 @@ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # +import sys import syslog import os @@ -25,12 +26,25 @@ def set_root_prefix(prefix): global the_root_prefix the_root_prefix = prefix +log_destination = "syslog" +def get_log_destination(): + """Returns the current log destination. + 'syslog' means "log to syslog". + 'stderr' means "log to stderr".""" + return log_destination +def set_log_destination(dest): + global log_destination + log_destination = dest + # # Logging. # def log(s): - syslog.syslog(s) + if get_log_destination() == 'syslog': + syslog.syslog(s) + else: + print >>sys.stderr, s # # Exceptions. diff --git a/scripts/interface-reconfigure b/scripts/interface-reconfigure index 49e24f58..f756bab7 100755 --- a/scripts/interface-reconfigure +++ b/scripts/interface-reconfigure @@ -34,6 +34,7 @@ --pif-uuid The UUID of a PIF. --force An interface name. --root-prefix=DIR Use DIR as alternate root directory (for testing). + --no-syslog Write log messages to stderr instead of system log. """ # Notes: @@ -584,6 +585,7 @@ def main(argv=None): "management", "mac=", "device=", "mode=", "ip=", "netmask=", "gateway=", "root-prefix=", + "no-syslog", "help" ] arglist, args = getopt.gnu_getopt(argv[1:], shortops, longops) except getopt.GetoptError, msg: @@ -606,12 +608,15 @@ def main(argv=None): force_rewrite_config[o[2:]] = a elif o == "--root-prefix": set_root_prefix(a) + elif o == "--no-syslog": + set_log_destination("stderr") elif o == "-h" or o == "--help": print __doc__ % {'command-name': os.path.basename(argv[0])} return 0 - syslog.openlog(os.path.basename(argv[0])) - log("Called as " + str.join(" ", argv)) + if get_log_destination() == "syslog": + syslog.openlog(os.path.basename(argv[0])) + log("Called as " + str.join(" ", argv)) if len(args) < 1: raise Usage("Required option not present")