summaryrefslogtreecommitdiff
path: root/cbuildbot/metadata_lib.py
diff options
context:
space:
mode:
authorAviv Keshet <akeshet@chromium.org>2014-08-13 16:06:08 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-08-15 17:54:20 +0000
commitbd1694f28ac82a13062f96359c1eb64a5b0a550d (patch)
tree16513e148f8668fc08d345d34792b8156c5f0d57 /cbuildbot/metadata_lib.py
parent9176aa2be392c557c8089a84b3dedb3c68b2551d (diff)
downloadchromite-bd1694f28ac82a13062f96359c1eb64a5b0a550d.tar.gz
metadata: refactor cl action methods
This CL pulls the _GetChangeAsSmallDictionary method out of CBuildbotMetadata and into its own module level helper function, and creates the GetCLActionTuple helper function. BUG=chromium:387755 TEST=Existing unit tests pass (verified that existing tests cover new code) Change-Id: Ibd09706dca591476f43975770799afda5225fb5c Reviewed-on: https://chromium-review.googlesource.com/212344 Reviewed-by: Aviv Keshet <akeshet@chromium.org> Tested-by: Aviv Keshet <akeshet@chromium.org> Commit-Queue: Aviv Keshet <akeshet@chromium.org>
Diffstat (limited to 'cbuildbot/metadata_lib.py')
-rw-r--r--cbuildbot/metadata_lib.py79
1 files changed, 48 insertions, 31 deletions
diff --git a/cbuildbot/metadata_lib.py b/cbuildbot/metadata_lib.py
index 5c247d9d1..08ecdb7af 100644
--- a/cbuildbot/metadata_lib.py
+++ b/cbuildbot/metadata_lib.py
@@ -32,6 +32,52 @@ METADATA_URL_GLOB = os.path.join(ARCHIVE_ROOT,
'R%(milestone)s**//metadata.json')
LATEST_URL = os.path.join(ARCHIVE_ROOT, 'LATEST-master')
+
+GerritPatchTuple = collections.namedtuple('GerritPatchTuple',
+ ['gerrit_number', 'patch_number',
+ 'internal'])
+GerritChangeTuple = collections.namedtuple('GerritChangeTuple',
+ ['gerrit_number', 'internal'])
+CLActionTuple = collections.namedtuple('CLActionTuple',
+ ['change', 'action', 'timestamp',
+ 'reason'])
+CLActionWithBuildTuple = collections.namedtuple('CLActionWithBuildTuple',
+ ['change', 'action', 'timestamp', 'reason', 'bot_type', 'build'])
+
+
+def GetChangeAsSmallDictionary(change):
+ """Returns a small dictionary representation of a gerrit change.
+
+ Args:
+ change: A GerritPatch or GerritPatchTuple object.
+
+ Returns:
+ A dictionary of the form {'gerrit_number': change.gerrit_number,
+ 'patch_number': change.patch_number,
+ 'internal': change.internal}
+ """
+ return {'gerrit_number': change.gerrit_number,
+ 'patch_number': change.patch_number,
+ 'internal': change.internal}
+
+
+def GetCLActionTuple(change, action, timestamp=None, reason=None):
+ """Returns a CLActionTuple suitable for recording in metadata or cidb.
+
+ Args:
+ change: A GerritPatch or GerritPatchTuple object.
+ action: The action taken, should be one of constants.CL_ACTIONS
+ timestamp: An integer timestamp such as int(time.time()) at which
+ the action was taken. Default: Now.
+ reason: Description of the reason the action was taken. Default: ''
+ """
+ return CLActionTuple(
+ GetChangeAsSmallDictionary(change),
+ action,
+ timestamp or int(time.time()),
+ reason)
+
+
class _DummyLock(object):
"""A Dummy clone of RLock that does nothing."""
def acquire(self, blocking=1):
@@ -201,31 +247,11 @@ class CBuildbotMetadata(object):
Returns:
self
"""
- cl_action = (self._ChangeAsSmallDictionary(change),
- action,
- timestamp or int(time.time()),
- reason or '')
-
- self._cl_action_list.append(cl_action)
+ self._cl_action_list.append(
+ GetCLActionTuple(change, action, timestamp, reason))
return self
@staticmethod
- def _ChangeAsSmallDictionary(change):
- """Returns a small dictionary representation of a gerrit change.
-
- Args:
- change: A GerritPatch or GerritPatchTuple object.
-
- Returns:
- A dictionary of the form {'gerrit_number': change.gerrit_number,
- 'patch_number': change.patch_number,
- 'internal': change.internal}
- """
- return {'gerrit_number': change.gerrit_number,
- 'patch_number': change.patch_number,
- 'internal': change.internal}
-
- @staticmethod
def GetReportMetadataDict(builder_run, get_changes_from_pool,
get_statuses_from_slaves, config=None, stage=None,
final_status=None, sync_instance=None,
@@ -835,12 +861,3 @@ def GetMetadataURLsSince(target, start_date):
return urls
-GerritPatchTuple = collections.namedtuple('GerritPatchTuple',
- 'gerrit_number patch_number internal')
-GerritChangeTuple = collections.namedtuple('GerritChangeTuple',
- 'gerrit_number internal')
-CLActionTuple = collections.namedtuple('CLActionTuple',
- 'change action timestamp reason')
-CLActionWithBuildTuple = collections.namedtuple('CLActionWithBuildTuple',
- 'change action timestamp '
- 'reason bot_type build')