]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
orchestra: introduce quiet mode for remote.run 1584/head
authorKyr Shatskyy <kyrylo.shatskyy@suse.com>
Mon, 30 Nov 2020 15:27:10 +0000 (16:27 +0100)
committerKyr Shatskyy <kyrylo.shatskyy@suse.com>
Mon, 30 Nov 2020 17:54:39 +0000 (18:54 +0100)
Applied changes:

- Add quiet option to remote.run and subsidiary function calls
- Logging commands now directed to DEBUG instead of INFO logger

This is usefull when we want suppress logs for some kind of commmands like
reading binary files or logging useless data to stdout/stderr as well as
dumping some vulnarable information.

Signed-off-by: Kyr Shatskyy <kyrylo.shatskyy@suse.com>
teuthology/orchestra/remote.py
teuthology/orchestra/run.py

index acafef3a6632131e8610e2342623c5acbae7f20e..a9c4c0fd1d780924b35646a9969c7a2291cbdb61 100644 (file)
@@ -550,7 +550,7 @@ class Remote(object):
         if iflags:
             args += ' iflag=' + ','.join(iflags)
         args = 'set -ex' + '\n' + args
-        proc = self.run(args=args, stdout=stdout, stderr=StringIO(), check_status=False)
+        proc = self.run(args=args, stdout=stdout, stderr=StringIO(), check_status=False, quiet=True)
         if proc.returncode:
             if 'No such file or directory' in proc.stderr.getvalue():
                 raise FileNotFoundError(errno.ENOENT,
@@ -591,7 +591,7 @@ class Remote(object):
             chown = 'sudo chown' if sudo else 'chown'
             args += '\n' + chown + ' ' + owner + ' ' + path
         args = 'set -ex' + '\n' + args
-        self.run(args=args, stdin=data)
+        self.run(args=args, stdin=data, quiet=True)
 
     def sudo_write_file(self, path, data, **kwargs):
         """
index 3bd0be8313f5d1e25a775e12dfbaa2a9bdcea8e0..f31dfd0d7fc1db89feab1f67abdc95c809a9731d 100644 (file)
@@ -90,7 +90,7 @@ class RemoteProcess(object):
         Execute remote command
         """
         for line in self.command.split('\n'):
-            log.getChild(self.hostname).info('%s> %s' % (self.label or '', line))
+            log.getChild(self.hostname).debug('%s> %s' % (self.label or '', line))
 
         if hasattr(self, 'timeout'):
             (self._stdin_buf, self._stdout_buf, self._stderr_buf) = \
@@ -114,7 +114,7 @@ class RemoteProcess(object):
             # FIXME: Is this actually true?
             raise RuntimeError(self.deadlock_warning % 'stdin')
 
-    def setup_output_stream(self, stream_obj, stream_name):
+    def setup_output_stream(self, stream_obj, stream_name, quiet=False):
         if stream_obj is not PIPE:
             # Log the stream
             host_log = self.logger.getChild(self.hostname)
@@ -125,6 +125,7 @@ class RemoteProcess(object):
                     getattr(self, stream_name),
                     stream_log,
                     stream_obj,
+                    quiet,
                 )
             )
             setattr(self, stream_name, stream_obj)
@@ -258,7 +259,7 @@ def quote(args):
         return args
 
 
-def copy_to_log(f, logger, loglevel=logging.INFO, capture=None):
+def copy_to_log(f, logger, loglevel=logging.INFO, capture=None, quiet=False):
     """
     Copy line by line from file in f to the log from logger
 
@@ -266,6 +267,8 @@ def copy_to_log(f, logger, loglevel=logging.INFO, capture=None):
     :param logger: the destination logger object
     :param loglevel: the level of logging data
     :param capture: an optional stream object for data copy
+    :param quiet: suppress `logger` usage if True, this is useful only
+                  in combination with `capture`, defaults False
     """
     # Work-around for http://tracker.ceph.com/issues/8313
     if isinstance(f, ChannelFile):
@@ -284,6 +287,8 @@ def copy_to_log(f, logger, loglevel=logging.INFO, capture=None):
                     capture.write(line)
         line = line.rstrip()
         # Second part of work-around for http://tracker.ceph.com/issues/8313
+        if quiet:
+            continue
         try:
             if isinstance(line, bytes):
                 line = line.decode('utf-8', 'replace')
@@ -305,15 +310,17 @@ def copy_and_close(src, fdst):
     fdst.close()
 
 
-def copy_file_to(src, logger, stream=None):
+def copy_file_to(src, logger, stream=None, quiet=False):
     """
     Copy file
     :param src: file to be copied.
     :param logger: the logger object
-    :param stream: an optional file-like object which will receive a copy of
-                   src.
+    :param stream: an optional file-like object which will receive
+                   a copy of src.
+    :param quiet: disable logger usage if True, useful in combination
+                  with `stream` parameter, defaults False.
     """
-    copy_to_log(src, logger, capture=stream)
+    copy_to_log(src, logger, capture=stream, quiet=quiet)
 
 def spawn_asyncresult(fn, *args, **kwargs):
     """
@@ -384,6 +391,7 @@ def run(
     wait=True,
     name=None,
     label=None,
+    quiet=False,
     timeout=None,
     cwd=None,
     # omit_sudo is used by vstart_runner.py
@@ -417,6 +425,7 @@ def run(
     :param name: Human readable name (probably hostname) of the destination
                  host
     :param label: Can be used to label or describe what the command is doing.
+    :param quiet: Do not log command's stdout and stderr, defaults False.
     :param timeout: timeout value for args to complete on remote channel of
                     paramiko
     :param cwd: Directory in which the command should be executed.
@@ -440,8 +449,8 @@ def run(
                       cwd=cwd)
     r.execute()
     r.setup_stdin(stdin)
-    r.setup_output_stream(stderr, 'stderr')
-    r.setup_output_stream(stdout, 'stdout')
+    r.setup_output_stream(stderr, 'stderr', quiet)
+    r.setup_output_stream(stdout, 'stdout', quiet)
     if wait:
         r.wait()
     return r