cros_install_debug_symbols: handle URI field
Packages index generated by the cq set the URI field with an explicit PATH for
each package in order to reuse packages previously uploaded.
URI was not handled correctly which lead to wrong urls.
I added unittests for the binhost parsing to avoid getting bit a second time and
added some input verification.
BUG=chromium:426494
TEST=Handle the file:// scheme - generate binpkg without debug symbols for gizmo
and copy them to /foo.
* building with PORTAGE_BINHOST=/foo works.
* building with PORTAGE_BINHOST=file:///foo works
* building with PORTAGE_BINHOST=file://localhost/foo
TEST=copy /foo/Packages to /bar/Packages and add a URI field.
* building with PORTAGE_BINHOST=file://localhost/bar works
TEST=trybot run on beaglebone-release-group with no preflight binpkg and
separatedebug enabled. beaglebone produces debug symbols separately.
beaglebone_servo reuse the binpkg from beagle bone and install debug symbols
correctly.
Change-Id: I49a848779850cdbcf7cf667fc71546b37ffdd6ff
Reviewed-on: https://chromium-review.googlesource.com/234857
Reviewed-by: Bertrand Simonnet <bsimonnet@chromium.org>
Tested-by: Bertrand Simonnet <bsimonnet@chromium.org>
Commit-Queue: Bertrand Simonnet <bsimonnet@chromium.org>
diff --git a/scripts/cros_install_debug_syms_unittest.py b/scripts/cros_install_debug_syms_unittest.py
new file mode 100755
index 0000000..b1fa3f8
--- /dev/null
+++ b/scripts/cros_install_debug_syms_unittest.py
@@ -0,0 +1,88 @@
+#!/usr/bin/python
+# Copyright 2014 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Unittests for cros_install_debug_syms.py"""
+
+from __future__ import print_function
+
+from collections import namedtuple
+import os
+import sys
+
+sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)),
+ '..', '..'))
+
+from chromite.lib import cros_test_lib
+from chromite.scripts import cros_install_debug_syms
+
+
+SimpleIndex = namedtuple('SimpleIndex', 'header packages')
+
+
+class InstallDebugSymsTest(cros_test_lib.MockTestCase):
+ """Test the parsing of package index"""
+
+ def setUp(self):
+ self.local_binhosts = ['/build/something/packages/',
+ 'file:///build/somethingelse/packages',
+ 'file://localhost/build/another/packages']
+
+ self.remote_binhosts = ['http://domain.com/binhost',
+ 'gs://chromeos-stuff/binhost']
+
+ def testGetLocalPackageIndex(self):
+ """Check that local binhosts are fetched correctly."""
+ self.PatchObject(cros_install_debug_syms.binpkg, "GrabLocalPackageIndex",
+ return_value=SimpleIndex({}, {}))
+ self.PatchObject(cros_install_debug_syms.os.path, 'isdir',
+ return_value=True)
+ for binhost in self.local_binhosts:
+ cros_install_debug_syms.GetPackageIndex(binhost)
+
+ def testGetRemotePackageIndex(self):
+ """Check that remote binhosts are fetched correctly."""
+ self.PatchObject(cros_install_debug_syms.binpkg, "GrabRemotePackageIndex",
+ return_value=SimpleIndex({}, {}))
+ for binhost in self.remote_binhosts:
+ cros_install_debug_syms.GetPackageIndex(binhost)
+
+ def testListRemoteBinhost(self):
+ """Check that urls are generated correctly for remote binhosts."""
+ chaps_cpv = 'chromeos-base/chaps-0-r2'
+ metrics_cpv = 'chromeos-base/metrics-0-r4'
+
+ index = SimpleIndex({}, [{'CPV': 'chromeos-base/shill-0-r1'},
+ {'CPV': chaps_cpv,
+ 'DEBUG_SYMBOLS': 'yes'},
+ {'CPV': metrics_cpv,
+ 'DEBUG_SYMBOLS': 'yes',
+ 'PATH': 'path/to/binpkg.tbz2'}])
+ self.PatchObject(cros_install_debug_syms, 'GetPackageIndex',
+ return_value=index)
+
+ for binhost in self.remote_binhosts:
+ expected = {chaps_cpv: os.path.join(binhost, chaps_cpv + '.debug.tbz2'),
+ metrics_cpv: os.path.join(binhost,
+ 'path/to/binpkg.debug.tbz2')}
+ self.assertEquals(cros_install_debug_syms.ListBinhost(binhost), expected)
+
+ def testListRemoteBinhostWithURI(self):
+ """Check that urls are generated correctly when URI is defined."""
+ index = SimpleIndex({'URI': 'gs://chromeos-prebuilts'},
+ [{'CPV': 'chromeos-base/shill-0-r1',
+ 'DEBUG_SYMBOLS': 'yes',
+ 'PATH': 'amd64-generic/paladin1234/shill-0-r1.tbz2'}])
+ self.PatchObject(cros_install_debug_syms, 'GetPackageIndex',
+ return_value=index)
+
+ binhost = 'gs://chromeos-prebuilts/gizmo-paladin/'
+ debug_symbols_url = ('gs://chromeos-prebuilts/amd64-generic'
+ '/paladin1234/shill-0-r1.debug.tbz2')
+ self.assertEquals(cros_install_debug_syms.ListBinhost(binhost),
+ {'chromeos-base/shill-0-r1': debug_symbols_url})
+
+
+if __name__ == '__main__':
+ cros_test_lib.main()