Skip to content

Commit

Permalink
fix: modify login in dirac_pilot.py and fix the test
Browse files Browse the repository at this point in the history
  • Loading branch information
martynia committed Nov 7, 2023
1 parent ca28397 commit e07604f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
7 changes: 4 additions & 3 deletions Pilot/dirac-pilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
# print the buffer, so we have a "classic' logger back in sync.
sys.stdout.write(bufContent)
# now the remote logger.
if pilotParams.pilotLogging:
remote = pilotParams.pilotLogging and (pilotParams.loggerURL is not None)
if remote:
# In a remote logger enabled Dirac version we would have some classic logger content from a wrapper,
# which we passed in:
receivedContent = ""
Expand Down Expand Up @@ -97,7 +98,7 @@

log.info("Executing commands: %s" % str(pilotParams.commands))

if pilotParams.pilotLogging:
if remote:
# It's safer to cancel the timer here. Each command has got its own logger object with a timer cancelled by the
# finaliser. No need for a timer in the "else" code segment below.
try:
Expand All @@ -114,6 +115,6 @@
else:
log.error("Command %s could not be instantiated" % commandName)
# send the last message and abandon ship.
if pilotParams.pilotLogging:
if remote:
log.buffer.flush()
sys.exit(-1)
19 changes: 9 additions & 10 deletions Pilot/tests/Test_simplePilotLogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import tempfile

try:
from Pilot.pilotTools import CommandBase, PilotParams, RemoteLogger
from Pilot.pilotTools import CommandBase, PilotParams, Logger, RemoteLogger
except ImportError:
from pilotTools import CommandBase, PilotParams, RemoteLogger
from pilotTools import CommandBase, PilotParams, Logger, RemoteLogger

import unittest

Expand Down Expand Up @@ -122,14 +122,17 @@ def tearDown(self):
@patch(("sys.argv"))
@patch("subprocess.Popen")
def test_executeAndGetOutput(self, popenMock, argvmock):

argvmock.__getitem__.return_value = [
"-d",
"-g",
"dummyURL",
"-F",
"tests/pilot.json",
]

import os
cwd = os.getcwd()
print("cwd", cwd)
for size in [1000, 1024, 1025, 2005]:
random_str = "".join(random.choice(string.ascii_letters + "\n") for i in range(size))
if sys.version_info.major == 3:
Expand All @@ -144,14 +147,10 @@ def test_executeAndGetOutput(self, popenMock, argvmock):
self.stderr_mock.write("Errare humanum est!")
self.stderr_mock.seek(0)
pp = PilotParams()
try:
cBase = CommandBase(pp)
# we have a logger URL set, so:
assert isinstance(cBase.log, RemoteLogger)
finally:
# and cancel the timer !
cBase.log.buffer.cancelTimer()

cBase = CommandBase(pp)

assert isinstance(cBase.log, Logger)
popenMock.return_value.stdout = self.stdout_mock
popenMock.return_value.stderr = self.stderr_mock
outData = cBase.executeAndGetOutput("dummy")
Expand Down

0 comments on commit e07604f

Please sign in to comment.