Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CastorScript
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
atlas-tdaq-software
CastorScript
Commits
a7c2a1db
Commit
a7c2a1db
authored
Mar 7, 2019
by
Jonas
Browse files
Options
Downloads
Patches
Plain Diff
Revert "Added: Try, Except and comments in krb_tokenexpiration()"
This reverts commit
136b3737
.
parent
42c09c08
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!23
Resolve "Logging implementation cleanup"
Pipeline
#752886
failed
Mar 14, 2019
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Script/CastorScript.py
+18
-48
18 additions, 48 deletions
Script/CastorScript.py
with
18 additions
and
48 deletions
Script/CastorScript.py
+
18
−
48
View file @
a7c2a1db
...
...
@@ -357,68 +357,38 @@ def krb_tokenexpiration(logger):
# So it's safer to always set LC_ALL to a 'default' constant
envm
=
os
.
environ
.
copy
()
envm
[
'
LC_ALL
'
]
=
'
C
'
# Define klist_output and returncode for the klist process
# (klist, lists kerberos tokens and their expiration date)
output
=
None
returnCode
=
None
#set a default expiration date to the start of UNIX time
#This is a way to signal that something went wrong
expirationDateTime
=
datetime
.
datetime
(
1970
,
1
,
1
)
#try to run the klist process (kerberos list)
#catch the exception if it fails and return datetime(1970,1,1)
try
:
klist
=
subprocess
.
Popen
([
'
klist
'
,],
env
=
envm
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
STDOUT
)
ret
=
klist
.
wait
()
out
=
klist
.
stdout
.
read
()
logger
.
debug
(
'
klist done. Return code: %d Output: %s
'
%
(
ret
,
out
))
#we wait for the process to finish
returnCode
=
klist
.
wait
()
output
=
klist
.
stdout
.
read
()
logger
.
debug
(
'
klist done. Return code: %d Output: %s
'
%
(
returnCode
,
output
))
except
Exception
as
ex
:
logger
.
critical
(
'
klist failed: Return code=%s, Output=%s, with exception= %s
'
,
str
(
returnCode
),
output
,
str
(
ex
))
return
expirationDateTime
# if the returncode from the klist process is not 0, something went wrong
if
returnCode
!=
0
or
returnCode
is
None
:
logger
.
critical
(
'
klist failed: Return code=%s, Output=%s
'
,
str
(
returnCode
),
output
)
return
expirationDateTime
if
ret
:
logger
.
critical
(
'
klist failed: retcode=%s, output=%s
'
,
str
(
ret
),
out
)
return
datetime
.
datetime
(
1970
,
1
,
1
)
# From the output of klist, we extract the line with the token expiration date
# it is the next line after a line with "Valid" in it.
ticket
=
None
output
=
output
.
split
(
'
\n
'
)
for
idx
,
l
in
enumerate
(
output
):
#found the line with "Valid" in it..
out
=
out
.
split
(
'
\n
'
)
for
idx
,
l
in
enumerate
(
out
):
if
'
Valid
'
in
l
:
#and we get the line after!
ticket
=
output
[
idx
+
1
]
ticket
=
out
[
idx
+
1
]
break
# If we didn't find a line, we return datetime(1970, 1, 1)
if
ticket
is
None
:
logger
.
critical
(
'
error parsing klist output: output=%s
'
,
out
put
)
return
expirationD
ate
T
ime
logger
.
critical
(
'
error parsing klist output: output=%s
'
,
out
)
return
datetime
.
d
ate
t
ime
(
1970
,
1
,
1
)
# we found the line with the date
ticket
=
ticket
.
split
()
logger
.
debug
(
'
Ticket expiration: %s
'
%
ticket
)
# and extract only the date into a string
dateString
=
'
'
.
join
(
ticket
[
2
:
4
])
# try to pass it as a datetime object, catch exception
# (but raise it afterwards anyhow, to crash the script (for the .watchdog.sh))
try
:
expirationDateTime
=
datetime
.
datetime
.
strptime
(
dateString
,
'
%m/%d/%y %H:%M:%S
'
)
expiration_date
=
datetime
.
datetime
.
strptime
(
'
'
.
join
(
ticket
[
2
:
4
]),
'
%m/%d/%y %H:%M:%S
'
)
except
ValueError
as
exc
:
logger
.
critical
(
'
error converting string to date: ticket=
"
{}
"
, date_string=
"
{}
"'
,
ticket
,
dateString
)
ticket
,
'
'
.
join
(
ticket
[
2
:
4
])
)
raise
exc
return
expirationDateTime
return
expiration_date
if
__name__
==
'
__main__
'
:
main
(
config
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment