]> xenbits.xensource.com Git - xcp/xen-api.git/commitdiff
[PATCH] xenserver: Add --no-syslog feature to interface-reconfigure.
authorBen Pfaff <blp@nicira.com>
Thu, 8 Jul 2010 13:25:51 +0000 (14:25 +0100)
committerBen Pfaff <blp@nicira.com>
Thu, 8 Jul 2010 13:25:51 +0000 (14:25 +0100)
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 <blp@nicira.com>
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
---
 .../opt_xensource_libexec_InterfaceReconfigure.py  |   16 +++++++++++++++-
 .../opt_xensource_libexec_interface-reconfigure    |    9 +++++++--
 2 files changed, 22 insertions(+), 3 deletions(-)

scripts/InterfaceReconfigure.py
scripts/interface-reconfigure

index 089283db9489ec4b44537c8c98c5e160686d8d9d..3c3a0195a6687fe8977f0094451fcb019a5489f7 100644 (file)
@@ -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.
index 49e24f58d95ebbd90e33bc001b66a97afd7cc633..f756bab7bc30350a26912766b071ca1eb667a5af 100755 (executable)
@@ -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 <action> not present")