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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
atlas-tdaq-software
CastorScript
Commits
136b3737
Commit
136b3737
authored
6 years ago
by
Jonas
Browse files
Options
Downloads
Patches
Plain Diff
Added: Try, Except and comments in krb_tokenexpiration()
parent
a6a3002f
No related branches found
No related tags found
1 merge request
!23
Resolve "Logging implementation cleanup"
Pipeline
#751058
passed
6 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Script/CastorScript.py
+48
-18
48 additions, 18 deletions
Script/CastorScript.py
with
48 additions
and
18 deletions
Script/CastorScript.py
+
48
−
18
View file @
136b3737
...
...
@@ -363,38 +363,68 @@ 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
'
klist
=
subprocess
.
Popen
([
'
klist
'
,],
env
=
envm
,
stdout
=
subprocess
.
PIPE
,
# 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
ret
:
logger
.
critical
(
'
klist failed: retcode=%s, output=%s
'
,
str
(
ret
),
out
)
return
datetime
.
datetime
(
1970
,
1
,
1
)
# 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
# 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
out
=
out
.
split
(
'
\n
'
)
for
idx
,
l
in
enumerate
(
out
):
output
=
output
.
split
(
'
\n
'
)
for
idx
,
l
in
enumerate
(
output
):
#found the line with "Valid" in it..
if
'
Valid
'
in
l
:
ticket
=
out
[
idx
+
1
]
#and we get the line after!
ticket
=
output
[
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
)
return
datetime
.
d
ate
t
ime
(
1970
,
1
,
1
)
logger
.
critical
(
'
error parsing klist output: output=%s
'
,
out
put
)
return
expirationD
ate
T
ime
# 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
:
expiration_date
=
datetime
.
datetime
.
strptime
(
'
'
.
join
(
ticket
[
2
:
4
]),
'
%m/%d/%y %H:%M:%S
'
)
expirationDateTime
=
datetime
.
datetime
.
strptime
(
dateString
,
'
%m/%d/%y %H:%M:%S
'
)
except
ValueError
as
exc
:
logger
.
critical
(
'
error converting string to date: ticket=
"
{}
"
, date_string=
"
{}
"'
,
ticket
,
'
'
.
join
(
ticket
[
2
:
4
])
)
ticket
,
dateString
)
raise
exc
return
expiration_date
return
expirationDateTime
if
__name__
==
'
__main__
'
:
main
(
config
)
This diff is collapsed.
Click to expand it.
Jonas Ladefoged Holm
@jholm
mentioned in commit
a7c2a1db
·
6 years ago
mentioned in commit
a7c2a1db
mentioned in commit a7c2a1db0aa148ea6e4e358cfb094c71145d9cdf
Toggle commit list
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
register
or
sign in
to comment