提交 c0aeb39d 编写于 作者: L Lucas Meneghel Rodrigues 提交者: Lucas Meneghel Rodrigues

Merge pull request #187 from adereis/job_id_refactoring

Refactoring unique job ID generation
......@@ -219,7 +219,7 @@ def get_job_logs_dir(args=None, unique_id=None):
logdir = get_logs_dir()
# Stand alone tests handling
if unique_id is None:
unique_id = job_id.get_job_id()
unique_id = job_id.create_unique_job_id()
debugbase = 'job-%s-%s' % (start_time, unique_id[:7])
debugdir = path.init_dir(logdir, debugbase)
......
......@@ -12,25 +12,19 @@
# Copyright: Red Hat Inc. 2013-2014
# Authors: Lucas Meneghel Rodrigues <lmr@redhat.com>
import hashlib
import random
import socket
import time
_RAND_POOL = random.SystemRandom()
_HOSTNAME = socket.gethostname()
def get_job_id():
def create_unique_job_id():
"""
Create a job ID SHA1.
Create a 40 digit hex number to be used as a job ID string.
(similar to SHA1)
:return: SHA1 string
:return: 40 digit hex number 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()
n = _RAND_POOL.getrandbits(160)
return str(hex(n))[2:-1]
......@@ -287,9 +287,9 @@ class Job(object):
"""
self.args = args
if args is not None:
self.unique_id = args.unique_job_id or job_id.get_job_id()
self.unique_id = args.unique_job_id or job_id.create_unique_job_id()
else:
self.unique_id = job_id.get_job_id()
self.unique_id = job_id.create_unique_job_id()
self.logdir = data_dir.get_job_logs_dir(self.args, self.unique_id)
self.logfile = os.path.join(self.logdir, "job.log")
self.idfile = os.path.join(self.logdir, "id")
......
......@@ -200,6 +200,14 @@ class RunnerOperationTest(unittest.TestCase):
self.assertNotIn('needs to be a 40 digit hex', result.stderr)
self.assertIn('SKIP', result.stderr)
def test_automatic_unique_id(self):
cmd_line = './scripts/avocado run skiptest --json -'
result = process.run(cmd_line, ignore_status=True)
self.assertEqual(0, result.exit_status)
r = json.loads(result.stdout)
int(r['job_id'], 16) # it's an hex number
self.assertEqual(len(r['job_id']), 40)
class RunnerDropinTest(unittest.TestCase):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册