Include node name in the logging output from subprocesses.

This commit is contained in:
Itamar Turner-Trauring 2023-04-27 10:23:06 -04:00
parent 6d961eada9
commit 8f1d1cc1a0
3 changed files with 11 additions and 10 deletions

View File

@ -161,7 +161,7 @@ def flog_gatherer(reactor, temp_dir, flog_binary, request):
) )
pytest_twisted.blockon(out_protocol.done) pytest_twisted.blockon(out_protocol.done)
twistd_protocol = _MagicTextProtocol("Gatherer waiting at") twistd_protocol = _MagicTextProtocol("Gatherer waiting at", "gatherer")
twistd_process = reactor.spawnProcess( twistd_process = reactor.spawnProcess(
twistd_protocol, twistd_protocol,
which('twistd')[0], which('twistd')[0],
@ -244,7 +244,7 @@ log_gatherer.furl = {log_furl}
# "tahoe run" is consistent across Linux/macOS/Windows, unlike the old # "tahoe run" is consistent across Linux/macOS/Windows, unlike the old
# "start" command. # "start" command.
protocol = _MagicTextProtocol('introducer running') protocol = _MagicTextProtocol('introducer running', "introducer")
transport = _tahoe_runner_optional_coverage( transport = _tahoe_runner_optional_coverage(
protocol, protocol,
reactor, reactor,
@ -320,7 +320,7 @@ log_gatherer.furl = {log_furl}
# "tahoe run" is consistent across Linux/macOS/Windows, unlike the old # "tahoe run" is consistent across Linux/macOS/Windows, unlike the old
# "start" command. # "start" command.
protocol = _MagicTextProtocol('introducer running') protocol = _MagicTextProtocol('introducer running', "tor_introducer")
transport = _tahoe_runner_optional_coverage( transport = _tahoe_runner_optional_coverage(
protocol, protocol,
reactor, reactor,

View File

@ -35,7 +35,7 @@ if sys.platform.startswith('win'):
@pytest.fixture @pytest.fixture
def i2p_network(reactor, temp_dir, request): def i2p_network(reactor, temp_dir, request):
"""Fixture to start up local i2pd.""" """Fixture to start up local i2pd."""
proto = util._MagicTextProtocol("ephemeral keys") proto = util._MagicTextProtocol("ephemeral keys", "i2pd")
reactor.spawnProcess( reactor.spawnProcess(
proto, proto,
which("docker"), which("docker"),
@ -99,7 +99,7 @@ log_gatherer.furl = {log_furl}
# "tahoe run" is consistent across Linux/macOS/Windows, unlike the old # "tahoe run" is consistent across Linux/macOS/Windows, unlike the old
# "start" command. # "start" command.
protocol = util._MagicTextProtocol('introducer running') protocol = util._MagicTextProtocol('introducer running', "introducer")
transport = util._tahoe_runner_optional_coverage( transport = util._tahoe_runner_optional_coverage(
protocol, protocol,
reactor, reactor,

View File

@ -12,7 +12,7 @@ import sys
import time import time
import json import json
from os import mkdir, environ from os import mkdir, environ
from os.path import exists, join from os.path import exists, join, basename
from io import StringIO, BytesIO from io import StringIO, BytesIO
from subprocess import check_output from subprocess import check_output
@ -129,8 +129,9 @@ class _MagicTextProtocol(ProcessProtocol):
and then .callback()s on self.done and .errback's if the process exits and then .callback()s on self.done and .errback's if the process exits
""" """
def __init__(self, magic_text): def __init__(self, magic_text: str, name: str) -> None:
self.magic_seen = Deferred() self.magic_seen = Deferred()
self.name = f"{name}: "
self.exited = Deferred() self.exited = Deferred()
self._magic_text = magic_text self._magic_text = magic_text
self._output = StringIO() self._output = StringIO()
@ -140,7 +141,7 @@ class _MagicTextProtocol(ProcessProtocol):
def outReceived(self, data): def outReceived(self, data):
data = str(data, sys.stdout.encoding) data = str(data, sys.stdout.encoding)
sys.stdout.write(data) sys.stdout.write(self.name + data)
self._output.write(data) self._output.write(data)
if not self.magic_seen.called and self._magic_text in self._output.getvalue(): if not self.magic_seen.called and self._magic_text in self._output.getvalue():
print("Saw '{}' in the logs".format(self._magic_text)) print("Saw '{}' in the logs".format(self._magic_text))
@ -148,7 +149,7 @@ class _MagicTextProtocol(ProcessProtocol):
def errReceived(self, data): def errReceived(self, data):
data = str(data, sys.stderr.encoding) data = str(data, sys.stderr.encoding)
sys.stdout.write(data) sys.stdout.write(self.name + data)
def _cleanup_process_async(transport: IProcessTransport, allow_missing: bool) -> None: def _cleanup_process_async(transport: IProcessTransport, allow_missing: bool) -> None:
@ -282,7 +283,7 @@ def _run_node(reactor, node_dir, request, magic_text, finalize=True):
""" """
if magic_text is None: if magic_text is None:
magic_text = "client running" magic_text = "client running"
protocol = _MagicTextProtocol(magic_text) protocol = _MagicTextProtocol(magic_text, basename(node_dir))
# "tahoe run" is consistent across Linux/macOS/Windows, unlike the old # "tahoe run" is consistent across Linux/macOS/Windows, unlike the old
# "start" command. # "start" command.