From 8b6e610147e31286381e86cc93c98c5db554a92a Mon Sep 17 00:00:00 2001 From: Nick Hurley Date: Mon, 24 Sep 2012 14:10:32 -0700 Subject: [PATCH] Add code to create unique buildid/netconfig pairs --- stoneridge_info_gatherer.py | 11 ++++++++- tools/fix_buildids.py | 46 +++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 tools/fix_buildids.py diff --git a/stoneridge_info_gatherer.py b/stoneridge_info_gatherer.py index 993e625..bee5875 100644 --- a/stoneridge_info_gatherer.py +++ b/stoneridge_info_gatherer.py @@ -25,7 +25,16 @@ class StoneRidgeInfoGatherer(object): build_info['version'] = cp.get('App', 'Version') build_info['revision'] = cp.get('App', 'SourceStamp') build_info['branch'] = stoneridge.current_netconfig - build_info['id'] = cp.get('App', 'BuildID') + + # Due to the way the graph server works, we need to create a unique + # build id for each build/netconfig combination. We also want to keep + # the unmodified build ID around for posterity. + build_info['original_buildid'] = cp.get('App', 'BuildID') + # Cut off the century and the seconds from the date in the build id, as + # they are relatively useless bits of information. + buildid_base = build_info['original_buildid'][2:-2] + # Build ID is limited to 16 characters in the receiving database. + build_info['id'] = (buildid_base + stoneridge.current_netconfig)[:16] machine_info = {} machine_info['name'] = platform.node() diff --git a/tools/fix_buildids.py b/tools/fix_buildids.py new file mode 100644 index 0000000..d5639d9 --- /dev/null +++ b/tools/fix_buildids.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +# This Source Code Form is subject to the terms of the Mozilla Public License, +# v. 2.0. If a copy of the MPL was not distributed with this file, You can +# obtain one at http://mozilla.org/MPL/2.0/. + +"""This is a script to fix build ids on test runs created before the changes +were made that make the build ids we send be compatible with what the graph +server expects. +""" + +import json +import os +import sys + +for fname in sys.argv[1:]: + try: + with file(fname) as f: + info = json.load(f) + except OSError, e: + print 'Error opening %s: %s' % (fname, e) + continue + except Exception, e: + print 'Error reading %s: %s' % (fname, e) + continue + + try: + os.rename(fname, '%s.orig' % (fname,)) + except Exception, e: + print 'Error renaming %s: %s' % (fname, e) + continue + + # See stoneridge_info_gatherer.py for why the buildid is the way it is. + netconfig = info['test_build']['branch'] + original_buildid = info['test_build']['id'] + new_buildid = (original_buildid[2:-2] + netconfig)[:16] + + info['test_build']['original_buildid'] = original_buildid + info['test_build']['id'] = new_buildid + + try: + with file(fname, 'w') as f: + json.dump(info, f) + except OSError, e: + print 'Error opening %s for writing: %s' % (fname, e) + except Exception, e: + print 'Error writing %s: %s' % (fname, e)