Skip to content

Commit 3b4878a

Browse files
feat: Add pilot auth, pilot logging and refresh
1 parent 9c7d387 commit 3b4878a

File tree

5 files changed

+629
-91
lines changed

5 files changed

+629
-91
lines changed

.github/workflows/basic.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
strategy:
2424
matrix:
2525
python:
26-
- 2.7.18
26+
# - 2.7.18
2727
- 3.6.15
2828
- 3.9.17
2929

@@ -53,7 +53,7 @@ jobs:
5353
strategy:
5454
matrix:
5555
python:
56-
- 2.7.18
56+
# - 2.7.18
5757
- 3.6.15
5858
- 3.9.17
5959

@@ -77,7 +77,7 @@ jobs:
7777
strategy:
7878
matrix:
7979
python:
80-
- 2.7.18
80+
# - 2.7.18
8181
- 3.6.15
8282
- 3.9.17
8383

Pilot/dirac-pilot.py

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@
4949
getCommand,
5050
pythonPathCheck,
5151
)
52+
53+
try:
54+
from Pilot.proxyTools import revokePilotToken
55+
except ImportError:
56+
from proxyTools import revokePilotToken
57+
5258
############################
5359

5460
if __name__ == "__main__":
@@ -63,25 +69,34 @@
6369
# print the buffer, so we have a "classic' logger back in sync.
6470
sys.stdout.write(bufContent)
6571
# now the remote logger.
66-
remote = pilotParams.pilotLogging and (pilotParams.loggerURL is not None)
67-
if remote:
72+
remote = pilotParams.pilotLogging and pilotParams.diracXServer
73+
if remote and pilotParams.jwt != {}:
6874
# In a remote logger enabled Dirac version we would have some classic logger content from a wrapper,
6975
# which we passed in:
7076
receivedContent = ""
7177
if not sys.stdin.isatty():
7278
receivedContent = sys.stdin.read()
79+
7380
log = RemoteLogger(
74-
pilotParams.loggerURL,
81+
pilotParams.diracXServer,
7582
"Pilot",
7683
bufsize=pilotParams.loggerBufsize,
7784
pilotUUID=pilotParams.pilotUUID,
7885
debugFlag=pilotParams.debugFlag,
79-
wnVO=pilotParams.wnVO,
86+
jwt=pilotParams.jwt,
87+
legacy_logging=pilotParams.isLegacyLogging,
88+
clientID=pilotParams.clientID
8089
)
8190
log.info("Remote logger activated")
82-
log.buffer.write(receivedContent)
91+
log.buffer.write(log.format_to_json(
92+
"INFO",
93+
receivedContent,
94+
))
8395
log.buffer.flush()
84-
log.buffer.write(bufContent)
96+
log.buffer.write(log.format_to_json(
97+
"INFO",
98+
bufContent,
99+
))
85100
else:
86101
log = Logger("Pilot", debugFlag=pilotParams.debugFlag)
87102

@@ -104,7 +119,7 @@
104119

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

107-
if remote:
122+
if remote and pilotParams.jwt:
108123
# It's safer to cancel the timer here. Each command has got its own logger object with a timer cancelled by the
109124
# finaliser. No need for a timer in the "else" code segment below.
110125
try:
@@ -122,5 +137,22 @@
122137
log.error("Command %s could not be instantiated" % commandName)
123138
# send the last message and abandon ship.
124139
if remote:
125-
log.buffer.flush()
140+
log.buffer.flush(force=True)
126141
sys.exit(-1)
142+
143+
log.info("Pilot tasks finished.")
144+
145+
if not remote:
146+
log.buffer.flush()
147+
148+
if pilotParams.jwt:
149+
if remote:
150+
log.buffer.flush(force=True)
151+
152+
log.info("Revoking pilot token.")
153+
revokePilotToken(
154+
pilotParams.diracXServer,
155+
pilotParams.pilotUUID,
156+
pilotParams.jwt,
157+
pilotParams.clientID
158+
)

Pilot/pilotCommands.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def __init__(self, pilotParams):
2828
import sys
2929
import time
3030
import traceback
31-
import subprocess
3231
from collections import Counter
3332

3433
############################
@@ -44,7 +43,6 @@ def __init__(self, pilotParams):
4443
from shlex import quote
4544
except ImportError:
4645
from pipes import quote
47-
4846
try:
4947
from Pilot.pilotTools import (
5048
CommandBase,
@@ -92,16 +90,20 @@ def wrapper(self):
9290
self.log.info(
9391
"Flushing the remote logger buffer for pilot on sys.exit(): %s (exit code:%s)" % (pRef, str(exCode))
9492
)
95-
self.log.buffer.flush() # flush the buffer unconditionally (on sys.exit()).
93+
9694
try:
97-
sendMessage(self.log.url, self.log.pilotUUID, self.log.wnVO, "finaliseLogs", {"retCode": str(exCode)})
95+
self.log.error(str(exCode))
96+
self.log.error(traceback.format_exc())
97+
self.log.buffer.flush(force=True)
9898
except Exception as exc:
9999
self.log.error("Remote logger couldn't be finalised %s " % str(exc))
100+
100101
raise
101102
except Exception as exc:
102103
# unexpected exit: document it and bail out.
103104
self.log.error(str(exc))
104105
self.log.error(traceback.format_exc())
106+
self.log.buffer.flush(force=True)
105107
raise
106108
finally:
107109
self.log.buffer.cancelTimer()
@@ -132,7 +134,6 @@ def __init__(self, pilotParams):
132134
@logFinalizer
133135
def execute(self):
134136
"""Get host and local user info, and other basic checks, e.g. space available"""
135-
136137
self.log.info("Uname = %s" % " ".join(os.uname()))
137138
self.log.info("Host Name = %s" % socket.gethostname())
138139
self.log.info("Host FQDN = %s" % socket.getfqdn())
@@ -549,7 +550,13 @@ def __init__(self, pilotParams):
549550

550551
@logFinalizer
551552
def execute(self):
552-
"""Calls dirac-admin-add-pilot"""
553+
"""Calls dirac-admin-add-pilot
554+
555+
Deprecated with DIRAC V9 and DiracX."""
556+
557+
if self.pp.jwt:
558+
self.log.warn("Skipping module, normally it is already done via DiracX secret-exchange.")
559+
return
553560

554561
if not self.pp.pilotReference:
555562
self.log.warn("Skipping module, no pilot reference found")
@@ -1113,8 +1120,6 @@ def execute(self):
11131120
self.__setInnerCEOpts()
11141121
self.__startJobAgent()
11151122

1116-
sys.exit(0)
1117-
11181123

11191124
class NagiosProbes(CommandBase):
11201125
"""Run one or more Nagios probe scripts that follow the Nagios Plugin API:
@@ -1231,4 +1236,4 @@ def _runNagiosProbes(self):
12311236
def execute(self):
12321237
"""Standard entry point to a pilot command"""
12331238
self._setNagiosOptions()
1234-
self._runNagiosProbes()
1239+
self._runNagiosProbes()

0 commit comments

Comments
 (0)