]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Stop logging STDOUT and STDERR on every shell out
authorMatthew Treinish <mtreinish@kortar.org>
Mon, 24 Aug 2015 17:28:22 +0000 (13:28 -0400)
committerMatthew Treinish <mtreinish@kortar.org>
Mon, 24 Aug 2015 17:28:22 +0000 (13:28 -0400)
Sometimes you can log too much. For example, logging a complete
iptables dump on every security group operation, OMG TMI. Doing this
during DSVM run results in a log file >7M compressed. To mitigate this
issue this commit switches the execute method to only log the command
and it's exit code on the success case. If there is a failure the
entire stdin, stdout and stderr are logged.

Change-Id: Iaf17297306dc752e666612033c805a528f078f2f

neutron/agent/linux/utils.py

index 95c47a0607bc0080b6c0efd431366889250df66a..ff1ef7b0204bfca4725bbb6245d195e05a78641f 100644 (file)
@@ -134,19 +134,20 @@ def execute(cmd, process_input=None, addl_env=None,
                 except UnicodeError:
                     pass
 
-        m = _("\nCommand: {cmd}\nExit code: {code}\nStdin: {stdin}\n"
-              "Stdout: {stdout}\nStderr: {stderr}").format(
+        m = _("\nCommand: {cmd}\nExit code: {code}\n").format(
                   cmd=cmd,
-                  code=returncode,
-                  stdin=process_input or '',
-                  stdout=_stdout,
-                  stderr=_stderr)
+                  code=returncode)
 
         extra_ok_codes = extra_ok_codes or []
         if returncode and returncode in extra_ok_codes:
             returncode = None
 
         if returncode and log_fail_as_error:
+            m += ("Stdin: {stdin}\n"
+                  "Stdout: {stdout}\nStderr: {stderr}").format(
+                stdin=process_input or '',
+                stdout=_stdout,
+                stderr=_stderr)
             LOG.error(m)
         else:
             LOG.debug(m)