]> git.proxmox.com Git - ovs.git/commitdiff
tests: Don't log to syslog during tests.
authorBen Pfaff <blp@ovn.org>
Wed, 8 Aug 2018 23:04:56 +0000 (16:04 -0700)
committerBen Pfaff <blp@ovn.org>
Thu, 9 Aug 2018 22:40:09 +0000 (15:40 -0700)
Until now, "make check" generated a huge amount of output to syslog.  This
commit suppresses it.

Acked-by: Ilya Maximets <i.maximets@samsung.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
NEWS
lib/automake.mk
lib/syslog-null.c [new file with mode: 0644]
lib/syslog-null.h [new file with mode: 0644]
lib/vlog.c
lib/vlog.man
lib/vlog.xml
python/ovs/vlog.py
tests/atlocal.in

diff --git a/NEWS b/NEWS
index 7875f6673e345e27594cf5e78c1744f4e7620204..ae21340e904671021bfdadc2ea41c3294e1fbc30 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,7 @@
 Post-v2.10.0
 ---------------------
+   - The environment variable OVS_SYSLOG_METHOD, if set, is now used
+     as the default syslog method.
 
 
 v2.10.0 - xx xxx xxxx
index fb43aa1413b27106c0a5fc75b8f5f6e27e3cab67..63e9d72ac18a6b9b128f702c19acd60a3a2f9c45 100644 (file)
@@ -280,6 +280,8 @@ lib_libopenvswitch_la_SOURCES = \
        lib/syslog-direct.h \
        lib/syslog-libc.c \
        lib/syslog-libc.h \
+       lib/syslog-null.c \
+       lib/syslog-null.h \
        lib/syslog-provider.h \
        lib/table.c \
        lib/table.h \
diff --git a/lib/syslog-null.c b/lib/syslog-null.c
new file mode 100644 (file)
index 0000000..9dbd139
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2015, 2016 Nicira, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "syslog-null.h"
+
+#include <config.h>
+
+#include "compiler.h"
+#include "syslog-provider.h"
+#include "util.h"
+
+static void syslog_null_open(struct syslogger *this, int facility);
+static void syslog_null_log(struct syslogger *this, int pri, const char *msg);
+
+static struct syslog_class syslog_null_class = {
+    syslog_null_open,
+    syslog_null_log,
+};
+
+struct syslog_null {
+    struct syslogger parent;
+};
+
+/* This function  creates object that delegate all logging to null's
+ * syslog implementation. */
+struct syslogger *
+syslog_null_create(void)
+{
+    struct syslog_null *this = xmalloc(sizeof *this);
+
+    this->parent.class = &syslog_null_class;
+    this->parent.prefix = "";
+
+    return &this->parent;
+}
+
+static void
+syslog_null_open(struct syslogger *this OVS_UNUSED, int facility OVS_UNUSED)
+{
+    /* Nothing to do. */
+}
+
+static void
+syslog_null_log(struct syslogger *this OVS_UNUSED, int pri OVS_UNUSED,
+                const char *msg OVS_UNUSED)
+{
+    /* Nothing to do. */
+}
diff --git a/lib/syslog-null.h b/lib/syslog-null.h
new file mode 100644 (file)
index 0000000..0f7731d
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2015 Nicira, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SYSLOG_NULL_H
+#define SYSLOG_NULL_H 1
+
+struct syslogger *syslog_null_create(void);
+
+#endif /* syslog-null.h */
index bf5fd88ba9e8c45b7d497f6977e9bfd6e488e209..01cfdc5d3d2d70307113acd1e498acf46de48518 100644 (file)
@@ -39,6 +39,7 @@
 #include "svec.h"
 #include "syslog-direct.h"
 #include "syslog-libc.h"
+#include "syslog-null.h"
 #include "syslog-provider.h"
 #include "timeval.h"
 #include "unixctl.h"
@@ -584,7 +585,9 @@ vlog_set_syslog_method(const char *method)
         return;
     }
 
-    if (!strcmp(method, "libc")) {
+    if (!strcmp(method, "null")) {
+        syslogger = syslog_null_create();
+    } else if (!strcmp(method, "libc")) {
         syslogger = syslog_libc_create();
     } else if (!strncmp(method, "udp:", 4) || !strncmp(method, "unix:", 5)) {
         syslogger = syslog_direct_create(method);
@@ -778,7 +781,12 @@ vlog_init(void)
          * log anything before calling ovsthread_once_done() will deadlock. */
         atomic_read_explicit(&log_facility, &facility, memory_order_relaxed);
         if (!syslogger) {
-            syslogger = syslog_libc_create();
+            char *env = getenv("OVS_SYSLOG_METHOD");
+            if (env && env[0]) {
+                vlog_set_syslog_method(env);
+            } else {
+                syslogger = syslog_libc_create();
+            }
         }
         syslogger->class->openlog(syslogger, facility ? facility : LOG_DAEMON);
         ovsthread_once_done(&once);
index 674528d79aaed43bef7f0eb2c7ae4a3b10b75d9a..bad80e3d277131196042fdb10b5a7af9b5558301 100644 (file)
@@ -83,7 +83,7 @@ Specify \fImethod\fR how syslog messages should be sent to syslog daemon.
 Following forms are supported:
 .RS
 .IP \(bu
-\fBlibc\fR, use libc \fBsyslog()\fR function.  This is the default behavior.
+\fBlibc\fR, use libc \fBsyslog()\fR function.
 Downside of using this options is that libc adds fixed prefix to every
 message before it is actually sent to the syslog daemon over \fB/dev/log\fR
 UNIX domain socket.
@@ -103,4 +103,9 @@ to listen on the specified UDP port, accidental iptables rules could be
 interfering with local syslog traffic and there are some security
 considerations that apply to UDP sockets, but do not apply to UNIX domain
 sockets.
+.IP \(bu
+\fBnull\fR, discards all messages logged to syslog.
 .RE
+.IP
+The default is taken from the \fBOVS_SYSLOG_METHOD\fR environment
+variable; if it is unset, the default is \fBlibc\fR.
index 70f88b3a6652394557297f22d84971205cf7e355..c3afc0492314d98fac65439f537171bf77a46a0c 100644 (file)
     <ul>
       <li>
         <code>libc</code>, to use the libc <code>syslog()</code> function.
-        This is the default behavior.  Downside of using this options is that
+        Downside of using this options is that
         libc adds fixed prefix to every message before it is actually sent to
         the syslog daemon over <code>/dev/log</code> UNIX domain socket.
       </li>
         local syslog traffic and there are some security considerations that
         apply to UDP sockets, but do not apply to UNIX domain sockets.
       </li>
+
+      <li>
+        <code>null</code>, to discard all messages logged to syslog.
+      </li>
     </ul>
+
+    <p>
+      The default is taken from the <code>OVS_SYSLOG_METHOD</code> environment
+      variable; if it is unset, the default is <code>libc</code>.
+    </p>
   </dd>
 </dl>
index d7a84d8274462b88b3fa85f158e429065755b920..e3cf76dcd9e25d630febc65eb9ad055c51224a17 100644 (file)
@@ -305,9 +305,11 @@ class Vlog(object):
             return
 
         logger = logging.getLogger('syslog')
-        # If there is no infrastructure to support python syslog, disable
-        # the logger to avoid repeated errors.
-        if not os.path.exists("/dev/log"):
+        # Disable the logger if there is no infrastructure to support python
+        # syslog (to avoid repeated errors) or if the "null" syslog method
+        # requested by environment.
+        if (not os.path.exists("/dev/log")
+            or os.environ.get('OVS_SYSLOG_METHOD') == "null"):
             logger.disabled = True
             return
 
index 0f4a6ca33758546e20df266de04080d0133c41fd..a86de8bc1b90d868fc102f28e4570dddfad298b3 100644 (file)
@@ -212,3 +212,7 @@ unset NO_PROXY
 # Avoid OVN environment variables leaking in from external environment.
 unset OVN_NB_DB
 unset OVN_SB_DB
+
+# Prevent logging to syslog during tests.
+OVS_SYSLOG_METHOD=null
+export OVS_SYSLOG_METHOD