Changeset 3be92d3 in mod_gnutls


Ignore:
Timestamp:
Dec 18, 2019, 5:42:58 PM (12 months ago)
Author:
Fiona Klute <fiona.klute@…>
Branches:
asyncio, master, proxy-ticket
Children:
d5c572b
Parents:
779406c
Message:

Optionally log gnutls-cli stderr output to another stream/file

Location:
test/mgstest
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • test/mgstest/http.py

    r779406c r3be92d3  
    3232    def __init__(self, command, host, port=None,
    3333                 output_filter=None,
     34                 stderr_log=None,
    3435                 timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
    3536                 blocksize=8192):
     
    5152        # and the socket back to the HTTP connection (write-only).
    5253        self._output_filter = output_filter
     54        # If not None, write a copy of the subprocess' stderr to here.
     55        self._stderr_log = stderr_log
    5356        # output filter thread
    5457        self._fthread = None
     
    7780                                           bufsize=0)
    7881        self._ethread = Thread(target=_stderr_writer,
    79                                args=(self._sproc.stderr,))
     82                               args=(self._sproc.stderr, self._stderr_log))
    8083        self._ethread.start()
    8184        self.sock = s_local
     
    112115
    113116
    114 def _stderr_writer(stream):
    115     """Flush incoming data to sys.stderr.
     117def _stderr_writer(stream, copy=None):
     118    """Flush incoming data to sys.stderr, and optionally to "copy".
    116119
    117120    This is a workaround to prevent output from gnutls-cli and the
     
    119122    logs. Forcing gnutls-cli stderr through Python ensures
    120123    synchronization (via global interpreter lock).
     124
    121125    """
    122126    for line in stream:
    123127        print(line.decode(), file=sys.stderr, end='', flush=True)
     128        if copy:
     129            print(line.decode(), file=copy, end='')
  • test/mgstest/tests.py

    r779406c r3be92d3  
    7777                f'description={self.description!r})')
    7878
    79     def run(self, timeout=5.0):
     79    def run(self, timeout=5.0, conn_log=None):
    8080        # note: "--logfile" option requires GnuTLS version >= 3.6.7
    8181        command = ['gnutls-cli', '--logfile=/dev/stderr']
     
    8787            conn = HTTPSubprocessConnection(command, self.host, self.port,
    8888                                            output_filter=filter_cert_log,
     89                                            stderr_log=conn_log,
    8990                                            timeout=timeout)
    9091        elif self.transport == Transports.PLAIN:
     
    370371
    371372
    372 def run_test_conf(test_config, timeout=5.0):
     373def run_test_conf(test_config, timeout=5.0, conn_log=None):
    373374    conns = None
    374375
     
    390391            print(f'Running test connection {i}.')
    391392        sys.stdout.flush()
    392         test_conn.run(timeout=timeout)
     393        test_conn.run(timeout=timeout, conn_log=conn_log)
Note: See TracChangeset for help on using the changeset viewer.