summaryrefslogtreecommitdiff
path: root/tko
diff options
context:
space:
mode:
authorjamesren <jamesren@592f7852-d20e-0410-864c-8624ca9c26a4>2010-06-16 23:28:23 +0000
committerjamesren <jamesren@592f7852-d20e-0410-864c-8624ca9c26a4>2010-06-16 23:28:23 +0000
commitb65cace8f5cef246cb67058fe7b67c73d8ba1431 (patch)
tree3814cd338ac60532385d12523afb9d6a90c06373 /tko
parentb8c21c1d357f44e4e5c3957bb2d75199df7cb4e3 (diff)
Added more fields to support all the field in the test view.
Signed-off-by: Darren Kuo <darrenkuo@google.com> git-svn-id: svn://test.kernel.org/autotest/trunk@4624 592f7852-d20e-0410-864c-8624ca9c26a4
Diffstat (limited to 'tko')
-rw-r--r--tko/db.py7
-rw-r--r--tko/job_serializer.py37
-rw-r--r--tko/job_serializer_unittest.py22
-rw-r--r--tko/tko.proto14
-rw-r--r--tko/utils.py18
5 files changed, 75 insertions, 23 deletions
diff --git a/tko/db.py b/tko/db.py
index 9b9f456d..72c897fb 100644
--- a/tko/db.py
+++ b/tko/db.py
@@ -2,6 +2,7 @@ import re, os, sys, types, time, random
import common
from autotest_lib.client.common_lib import global_config
+from autotest_lib.tko import utils
class MySQLTooManyRows(Exception):
@@ -327,11 +328,7 @@ class db_sql(object):
else:
self.update_machine_information(job, commit=commit)
- afe_job_id = None
- pattern = re.compile('^([0-9]+)-.+/.+$')
- match = pattern.match(tag)
- if match:
- afe_job_id = match.group(1)
+ afe_job_id = utils.get_afe_job_id(tag)
data = {'tag':tag,
'label': job.label,
diff --git a/tko/job_serializer.py b/tko/job_serializer.py
index 5f0fcf7e..4fff8e93 100644
--- a/tko/job_serializer.py
+++ b/tko/job_serializer.py
@@ -14,10 +14,12 @@ import os
import datetime
import time
import random
+import re
# import autotest libraries
from autotest_lib.tko import models
from autotest_lib.tko import tko_pb2
+from autotest_lib.tko import utils
__author__ = 'darrenkuo@google.com (Darren Kuo)'
@@ -88,7 +90,7 @@ class JobSerializer(object):
return self.get_tko_job(job_pb)
- def serialize_to_binary(self, the_job, binaryfilename):
+ def serialize_to_binary(self, the_job, tag, binaryfilename):
"""Serializes the tko job object into a binary by using a
protocol buffer.
@@ -103,22 +105,34 @@ class JobSerializer(object):
@param
the_job: the tko job object that will be serialized.
+ tag: contains the job name and the afe_job_id
binaryfilename: the name of the file that will be written to
@return the filename of the file that contains the
binary of the serialized object.
"""
- job_pb = tko_pb2.Job()
- self.set_pb_job(the_job, job_pb)
+ pb_job = tko_pb2.Job()
+ self.set_pb_job(the_job, pb_job, tag)
out = open(binaryfilename, 'wb')
try:
- out.write(job_pb.SerializeToString())
+ out.write(pb_job.SerializeToString())
finally:
out.close()
+ def set_afe_job_id_and_tag(self, pb_job, tag):
+ """Sets the pb job's afe_job_id and tag field.
+
+ @param
+ pb_job: the pb job that will have it's fields set.
+ tag: used to set pb_job.tag and pb_job.afe_job_id.
+ """
+ pb_job.tag = tag
+ pb_job.afe_job_id = utils.get_afe_job_id(tag)
+
+
# getter setter methods
def get_tko_job(self, job):
"""Creates a a new tko job object from the pb job object.
@@ -157,7 +171,7 @@ class JobSerializer(object):
return newjob
- def set_pb_job(self, tko_job, pb_job):
+ def set_pb_job(self, tko_job, pb_job, tag):
"""Set the fields for the new job object.
Method takes in a tko job and an empty protocol buffer job
@@ -169,10 +183,11 @@ class JobSerializer(object):
transfered to the new job
pb_job: a new instance of the job class provided in the
protocol buffer.
-
+ tag: used to set pb_job.tag and pb_job.afe_job_id.
"""
self.set_trivial_attr(tko_job, pb_job, self.job_type_dict)
+ self.set_afe_job_id_and_tag(pb_job, tag)
for test in tko_job.tests:
newtest = pb_job.tests.add()
@@ -185,6 +200,16 @@ class JobSerializer(object):
def get_tko_test(self, test):
+ """Creates a tko test from pb_test.
+
+ Extracts data from pb_test by calling helper methods and
+ creates a tko test using the models.test constructor.
+
+ @param:
+ test: a pb_test where fields will be extracted from.
+
+ @return a new instance of models.test
+ """
fields_dict = self.get_trivial_attr(test, self.test_type_dict)
fields_dict['kernel'] = self.get_tko_kernel(test.kernel)
diff --git a/tko/job_serializer_unittest.py b/tko/job_serializer_unittest.py
index eec22e5f..222cc657 100644
--- a/tko/job_serializer_unittest.py
+++ b/tko/job_serializer_unittest.py
@@ -7,10 +7,11 @@ Mostly test if the serialized object has the expected content.
"""
import common
-import time
-import os
import datetime
+import os
+import re
import tempfile
+import time
from autotest_lib.tko import tko_pb2
from autotest_lib.tko import job_serializer
@@ -32,7 +33,7 @@ class JobSerializerUnittest(unittest.TestCase):
tko_kernel = models.kernel('My Computer', tko_patches, '1234567')
tko_time = datetime.now()
- tko_job = models.job('/tmp/', 'root', 'test', 'My Computer',
+ tko_job = models.job('/tmp/', 'autotest', 'test', 'My Computer',
tko_time, tko_time, tko_time, 'root',
'www', 'No one', tko_time, {'1+1':2})
@@ -51,8 +52,20 @@ class JobSerializerUnittest(unittest.TestCase):
self.tko_job.tests = [tko_test, tko_test, tko_test]
self.pb_job = tko_pb2.Job()
+ self.tag = '1-abc./.'
+ self.expected_afe_job_id = '1'
+
js = job_serializer.JobSerializer()
- js.set_pb_job(self.tko_job, self.pb_job)
+ js.set_pb_job(self.tko_job, self.pb_job, self.tag)
+
+
+ def test_tag(self):
+ self.assertEqual(self.tag, self.pb_job.tag)
+
+
+ def test_afe_job_id(self):
+ self.assertEqual(self.expected_afe_job_id,
+ self.pb_job.afe_job_id)
def test_job_dir(self):
@@ -208,7 +221,6 @@ class JobSerializerUnittest(unittest.TestCase):
def check_kernel(self, kernel, newkernel):
"""Check if the kernels are the same.
"""
-
self.assertEqual(kernel.base, newkernel.base)
self.assertEqual(kernel.kernel_hash, newkernel.kernel_hash)
diff --git a/tko/tko.proto b/tko/tko.proto
index 8e775810..b51cd541 100644
--- a/tko/tko.proto
+++ b/tko/tko.proto
@@ -42,13 +42,15 @@ message Job {
repeated Test tests = 2;
required string user = 3;
required string label = 4;
- required string machine = 5;
+ required string tag = 5;
required int64 queued_time = 6;
required int64 started_time = 7;
required int64 finished_time = 8;
- required string machine_owner = 9;
- required string machine_group = 10;
- required string aborted_by = 11;
- required int64 aborted_on = 12;
- repeated KeyVal keyval_dict = 13;
+ required string machine = 9;
+ required string machine_owner = 10;
+ required string machine_group = 11;
+ required string aborted_by = 12;
+ required int64 aborted_on = 13;
+ required string afe_job_id = 14;
+ repeated KeyVal keyval_dict = 15;
}
diff --git a/tko/utils.py b/tko/utils.py
index 1bd1bf46..7399c90b 100644
--- a/tko/utils.py
+++ b/tko/utils.py
@@ -1,4 +1,4 @@
-import os, sys, datetime
+import os, sys, datetime, re
_debug_logger = sys.stderr
@@ -49,3 +49,19 @@ def drop_redundant_messages(messages):
else:
filtered_messages.add(message)
return filtered_messages
+
+
+def get_afe_job_id(tag):
+ """ Given a tag return the afe_job_id (if any).
+
+ @param
+ tag: afe_job_id is extracted from this tag
+
+ @return
+ returns the afe_job_id if regex matches, else return ''
+ """
+
+ match = re.search('^([0-9]+)-.+/.+$', tag)
+ if match:
+ return match.group(1)
+ return ''