From patchwork Wed Jun 6 14:05:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milo Casagrande X-Patchwork-Id: 9143 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 4427823EB4 for ; Wed, 6 Jun 2012 14:05:20 +0000 (UTC) Received: from mail-gh0-f180.google.com (mail-gh0-f180.google.com [209.85.160.180]) by fiordland.canonical.com (Postfix) with ESMTP id E64A5A18A21 for ; Wed, 6 Jun 2012 14:05:19 +0000 (UTC) Received: by ghbz12 with SMTP id z12so5603715ghb.11 for ; Wed, 06 Jun 2012 07:05:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :content-type:mime-version:x-launchpad-project:x-launchpad-branch :x-launchpad-message-rationale:x-launchpad-branch-revision-number :x-launchpad-notification-type:to:from:subject:message-id:date :reply-to:sender:errors-to:precedence:x-generated-by :x-launchpad-hash:x-gm-message-state; bh=4zxCO/mxez7ylrf3EmsalV0Ipj49aEs5JQjb2WAsOqs=; b=XQoH61V8XbUI5rx7kdaf2A+moQJcOXwXsu2DTtEtl7xXMvFYRQKu33kVnpOxPe72S3 kudiLSFxbdZ0mcKvvT+bs5n9Ld6HFvO9yXTZooKkxdvpgtNjKT1fi7HCl8kGp6legun5 /zqBb7X1DU6jJ0suQtPC5J3XGn5RhQ+lrIzsp9TneGsaG+9F6IMsw93sn2s5/zNqGG7o gjIcO3qj/1m9GruIDE7uUG8t/uQUUlFAbP0yDVYp1K/ckDvE+UJ+OdnVVZs7CXtcVlyY QlYjw62cW3rc1xAmFmjxdUTqvfxRroUXt2rRHtV2bMkgK6LFBaRYGh666i5PYjfjWU46 ub4Q== Received: by 10.50.57.167 with SMTP id j7mr6567250igq.53.1338991517676; Wed, 06 Jun 2012 07:05:17 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.24.148 with SMTP id v20csp87513ibb; Wed, 6 Jun 2012 07:05:16 -0700 (PDT) Received: by 10.14.37.199 with SMTP id y47mr9836549eea.111.1338991515302; Wed, 06 Jun 2012 07:05:15 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id l4si2522092wiy.7.2012.06.06.07.05.14 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 06 Jun 2012 07:05:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1ScGrK-0002e9-LF for ; Wed, 06 Jun 2012 14:05:14 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 9704DE0023 for ; Wed, 6 Jun 2012 14:05:14 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: linaro-image-tools X-Launchpad-Branch: ~linaro-image-tools/linaro-image-tools/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 522 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-image-tools/linaro-image-tools/trunk] Rev 522: Merged Milo's fixes for bug 727776. Message-Id: <20120606140514.20913.51525.launchpad@ackee.canonical.com> Date: Wed, 06 Jun 2012 14:05:14 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="15353"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: 4c6d996c7087d9d1919a2c424937e9aaf8613d8b X-Gm-Message-State: ALoCoQkLYYwuImNaXF1d6sCsuJnJTh4XOerO8TtDVgDJr44LYV8aQuOMXTKyCKWrWmZmFjLnsRT4 Merge authors: Milo Casagrande (milo) ------------------------------------------------------------ revno: 522 [merge] committer: Milo Casagrande branch nick: trunk timestamp: Wed 2012-06-06 16:01:52 +0200 message: Merged Milo's fixes for bug 727776. modified: linaro_image_tools/tests/test_utils.py linaro_image_tools/utils.py --- lp:linaro-image-tools https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk You are subscribed to branch lp:linaro-image-tools. To unsubscribe from this branch go to https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk/+edit-subscription === modified file 'linaro_image_tools/tests/test_utils.py' --- linaro_image_tools/tests/test_utils.py 2012-04-18 13:26:25 +0000 +++ linaro_image_tools/tests/test_utils.py 2012-05-31 04:30:32 +0000 @@ -33,19 +33,21 @@ MockSomethingFixture, ) from linaro_image_tools.utils import ( + IncompatibleOptions, + InvalidHwpackFile, + UnableToFindPackageProvidingCommand, + additional_option_checks, + check_file_integrity_and_log_errors, ensure_command, find_command, install_package_providing, + path_in_tarfile_exists, preferred_tools_dir, - UnableToFindPackageProvidingCommand, + prep_media_path, verify_file_integrity, - check_file_integrity_and_log_errors, - path_in_tarfile_exists, - IncompatibleOptions, - prep_media_path, - additional_option_checks, ) + sudo_args = " ".join(cmd_runner.SUDO_ARGS) @@ -77,7 +79,7 @@ self.returncode = 0 return self - def communicate(self, input=None): + def communicate(self, input = None): self.wait() return ': OK\n'.join( TestVerifyFileIntegrity.filenames_in_shafile) + ': OK\n', '' @@ -91,7 +93,7 @@ self.returncode = 0 return self - def communicate(self, input=None): + def communicate(self, input = None): self.wait() return ': ERROR\n'.join( TestVerifyFileIntegrity.filenames_in_shafile) + ': ERROR\n', '' @@ -105,7 +107,7 @@ self.returncode = 0 return self - def communicate(self, input=None): + def communicate(self, input = None): self.wait() return ': OK\n'.join( TestVerifyFileIntegrity.filenames_in_shafile) + ': OK\n', '' @@ -136,7 +138,7 @@ signature_filename), 'sha1sum -c %s' % hash_filename], fixture.mock.commands_executed) - + def test_verify_files_returns_files(self): self.useFixture(MockSomethingFixture(cmd_runner, 'Popen', self.MockCmdRunnerPopen())) @@ -236,7 +238,7 @@ if prefer_dir is None: expected, _ = cmd_runner.run( ['which', lmc, ], - stdout=subprocess.PIPE).communicate() + stdout = subprocess.PIPE).communicate() expected = expected.strip() else: expected = os.path.join(prefer_dir, lmc) @@ -277,14 +279,15 @@ self.useFixture(MockSomethingFixture(os, "makedirs", lambda x: x)) self.assertEqual("testdevice", - prep_media_path(Args(directory=None, - device="testdevice", - board="testboard"))) + prep_media_path(Args(directory = None, + device = "testdevice", + board = "testboard"))) self.assertEqual("/foo/bar/testdevice", - prep_media_path(Args(directory="/foo/bar", - device="testdevice", - board="testboard"))) + prep_media_path(Args(directory = "/foo/bar", + device = "testdevice", + board = "testboard"))) + class TestPrepMediaPath(TestCaseWithFixtures): @@ -293,13 +296,55 @@ self.useFixture(MockSomethingFixture(os, "makedirs", lambda x: x)) self.assertRaises(IncompatibleOptions, additional_option_checks, - Args(directory="/foo/bar", - device="/testdevice", - board="testboard")) + Args(directory = "/foo/bar", + device = "/testdevice", + board = "testboard")) sys.argv.append("--mmc") self.assertRaises(IncompatibleOptions, additional_option_checks, - Args(directory="/foo/bar", - device="testdevice", - board="testboard")) + Args(directory = "/foo/bar", + device = "testdevice", + board = "testboard")) sys.argv.remove("--mmc") + + +class TestHwpackIsFile(TestCaseWithFixtures): + + """Testing '--hwpack' option only allows regular files.""" + + def test_hwpack_is_file(self): + class HwPackArgs: + def __init__(self, hwpack): + self.hwpacks = [hwpack] + self.directory = None + + try: + tmpdir = tempfile.mkdtemp() + self.assertRaises(InvalidHwpackFile, additional_option_checks, + HwPackArgs(hwpack = tmpdir)) + finally: + os.rmdir(tmpdir) + + + def test_hwpacks_are_files(self): + + """ + Tests that multiple hwpacks are regular files. + + Tests against a file and a directory, to avoid circumstances in which + 'additional_option_checks' is tweaked. + """ + + class HwPacksArgs: + def __init__(self, hwpacks): + self.hwpacks = hwpacks + self.directory = None + + try: + tmpdir = tempfile.mkdtemp() + _, tmpfile = tempfile.mkstemp() + self.assertRaises(InvalidHwpackFile, additional_option_checks, + HwPacksArgs([tmpfile, tmpdir])) + finally: + os.rmdir(tmpdir) + os.remove(tmpfile) === modified file 'linaro_image_tools/utils.py' --- linaro_image_tools/utils.py 2012-04-18 13:26:25 +0000 +++ linaro_image_tools/utils.py 2012-05-31 04:30:32 +0000 @@ -3,7 +3,7 @@ # Author: Guilherme Salgado # # This file is part of Linaro Image Tools. -# +# # Linaro Image Tools is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or @@ -147,20 +147,20 @@ if not gpg_sig_pass: logging.error("GPG signature verification failed.") return False, [] - + if not os.path.basename(binary) in verified_files: logging.error("OS Binary verification failed") return False, [] - + for hwpack in hwpacks: if not os.path.basename(hwpack) in verified_files: logging.error("Hwpack {0} verification failed".format(hwpack)) return False, [] - + for verified_file in verified_files: logging.info('Hash verification of file {0} OK.'.format( verified_file)) - + return True, verified_files def install_package_providing(command): @@ -266,6 +266,10 @@ """We can't find a package which provides the given command.""" +class InvalidHwpackFile(Exception): + """The hwpack parameter is not a regular file.""" + + class IncompatibleOptions(Exception): def __init__(self, value): self.value = value @@ -277,11 +281,17 @@ if args.directory is not None: # If args.device is a path to a device (/dev/) then this is an error if "--mmc" in sys.argv: - raise IncompatibleOptions("--directory option incompatable with " + raise IncompatibleOptions("--directory option incompatible with " "option --mmc") # If directory is used as well as having a full path (rather than just # a file name or relative path) in args.device, this is an error. if re.search(r"^/", args.device): - raise IncompatibleOptions("--directory option incompatable with " + raise IncompatibleOptions("--directory option incompatible with " "a full path in --image-file") + + for hwpack in args.hwpacks: + if not os.path.isfile(hwpack): + raise InvalidHwpackFile( + "--hwpack argument (%s) is not a regular file" % hwpack) +