From 6dcff28caec8e050f85a2a0b51d76a568735f58f Mon Sep 17 00:00:00 2001 From: Lucas Meneghel Rodrigues Date: Mon, 11 Aug 2014 17:52:30 -0300 Subject: [PATCH] avocado.core: Introduce job_id library Separate the code that generates a job SHA1 on its own library. It'll make things easier for unittesting and other needs. Signed-off-by: Lucas Meneghel Rodrigues --- avocado/core/job_id.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 avocado/core/job_id.py diff --git a/avocado/core/job_id.py b/avocado/core/job_id.py new file mode 100644 index 00000000..192eb167 --- /dev/null +++ b/avocado/core/job_id.py @@ -0,0 +1,36 @@ +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +# See LICENSE for more details. +# +# Copyright: Red Hat Inc. 2013-2014 +# Authors: Lucas Meneghel Rodrigues + +import hashlib +import random +import socket +import time + +_RAND_POOL = random.SystemRandom() +_HOSTNAME = socket.gethostname() + + +def get_job_id(): + """ + Create a job ID SHA1. + + :return: SHA1 string + :rtype: str + """ + info = '%s-%s-%s' % (_HOSTNAME, + time.strftime('%Y-%m-%dT%H:%M:%S'), + _RAND_POOL.getrandbits(64)) + h = hashlib.sha1() + h.update(info) + return h.hexdigest() -- GitLab