Skip to content

Commit

Permalink
Created uuidgen_t() to replace call to external command
Browse files Browse the repository at this point in the history
  • Loading branch information
PalNilsson committed Oct 16, 2024
1 parent e61c0da commit 8c383c9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
10 changes: 10 additions & 0 deletions pilot/util/auxiliary.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from numbers import Number
from time import sleep
from typing import Any
from uuid import uuid4

from pilot.util.constants import (
SUCCESS,
Expand Down Expand Up @@ -802,3 +803,12 @@ def is_kubernetes_resource() -> bool:
return True
else:
return False


def uuidgen_t() -> str:
"""
Generate a UUID string in the same format as "uuidgen -t".
:return: A UUID in the format "00000000-0000-0000-0000-000000000000" (str).
"""
return str(uuid4())
16 changes: 9 additions & 7 deletions pilot/util/tracereport.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,25 @@
# Authors:
# - Alexey Anisenkov, [email protected], 2017
# - Pavlo Svirin, [email protected], 2018
# - Paul Nilsson, [email protected], 2018-23
# - Paul Nilsson, [email protected], 2018-24

import hashlib
import os
import socket
import time

from sys import exc_info
from json import dumps, loads
from os import environ, getuid

from pilot.common.exception import FileHandlingFailure
from pilot.util.auxiliary import correct_none_types
from pilot.util.auxiliary import (
correct_none_types,
uuidgen_t
)
from pilot.util.config import config
from pilot.util.constants import get_pilot_version, get_rucio_client_version
from pilot.util.container import execute, execute2
from pilot.util.container import execute2
from pilot.util.filehandling import append_to_file, write_file
from pilot.util.https import request2

Expand Down Expand Up @@ -130,10 +134,8 @@ def init(self, job):
s = 'ppilot_%s' % job.jobdefinitionid
self['uuid'] = hashlib.md5(s.encode('utf-8')).hexdigest() # hash_pilotid, Python 2/3
else:
#self['uuid'] = commands.getoutput('uuidgen -t 2> /dev/null').replace('-', '') # all LFNs of one request have the same uuid
cmd = 'uuidgen -t 2> /dev/null'
exit_code, stdout, stderr = execute(cmd, timeout=10)
self['uuid'] = stdout.replace('-', '')
_uuid = uuidgen_t() # 'uuidgen -t 2> /dev/null'
self['uuid'] = _uuid.replace('-', '')

def get_value(self, key):
"""
Expand Down

0 comments on commit 8c383c9

Please sign in to comment.