From patchwork Tue Sep 4 17:23:13 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Sokolovsky X-Patchwork-Id: 11168 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 CE3AC23F27 for ; Tue, 4 Sep 2012 17:23:17 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 7DF2AA191FC for ; Tue, 4 Sep 2012 17:22:26 +0000 (UTC) Received: by ieak11 with SMTP id k11so5068408iea.11 for ; Tue, 04 Sep 2012 10:23:16 -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=I0Pxk6k4jgtT2TWWdHdxpwwM/OAIAdlyqHp1us09SaU=; b=QUOOrMLYW/j8MkxvS7OQt5Mx6OJLPl8VOYtzaQ+nYfDKlamW+zmxF9uqGx+1AiV5Aw 3du4/a05KcUs/Qr+7vQ4ZshVZymLXn180LaCuhWmr2gZYCVAVlYxD97XTJHWSeLqR2xQ VlAyb4IC1Us2BDUBaCJ5vNXhDmSUOASuDqTijt4rtCNd1TO3ozWlccgwbqA4IBTbf1eC 15mFisoEsqVjQbuuAp50LST1WMueBf7M5DS28j0DXfVU12nEkrZEGrn2/CTTvcktDHsR 9/jcYHK7DERWHNwZ6kOm8nYyy9WCtunzpe7eIwdxXwXk/ZDiofJMtRh3dIElz+9afUGe UWrw== Received: by 10.50.242.3 with SMTP id wm3mr3065068igc.0.1346779396689; Tue, 04 Sep 2012 10:23:16 -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.50.184.232 with SMTP id ex8csp203617igc; Tue, 4 Sep 2012 10:23:15 -0700 (PDT) Received: by 10.180.20.11 with SMTP id j11mr32090672wie.12.1346779394373; Tue, 04 Sep 2012 10:23:14 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id ds8si29969569wib.33.2012.09.04.10.23.13 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 04 Sep 2012 10:23:14 -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 1T8wqH-0006PL-3e for ; Tue, 04 Sep 2012 17:23:13 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 0E761E2BA1 for ; Tue, 4 Sep 2012 17:23:13 +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: 558 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-image-tools/linaro-image-tools/trunk] Rev 558: [merge] Implement 'copy_files' field support in linaro-media-create. Message-Id: <20120904172313.23808.17024.launchpad@ackee.canonical.com> Date: Tue, 04 Sep 2012 17:23:13 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="15901"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: f95acc577f6ed9fba3511ae0ef04c802813823eb X-Gm-Message-State: ALoCoQlKbXYE2D/RW1v8Vo4vOn9ZVsN7Wpy24hcpGzK75HK4sTx+abl1yyDRgATsgSUw6HtvO13K Merge authors: Paul Sokolovsky (pfalcon) Related merge proposals: https://code.launchpad.net/~pfalcon/linaro-image-tools/copy_files-lmc/+merge/122686 proposed by: Paul Sokolovsky (pfalcon) review: Approve - James Tunnicliffe (dooferlad) ------------------------------------------------------------ revno: 558 [merge] committer: Paul Sokolovsky branch nick: trunk timestamp: Tue 2012-09-04 20:22:04 +0300 message: [merge] Implement 'copy_files' field support in linaro-media-create. modified: linaro_image_tools/media_create/boards.py linaro_image_tools/media_create/tests/test_media_create.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/media_create/boards.py' --- linaro_image_tools/media_create/boards.py 2012-09-03 08:25:05 +0000 +++ linaro_image_tools/media_create/boards.py 2012-09-04 14:38:45 +0000 @@ -202,11 +202,26 @@ return format def get_file(self, file_alias): - file_name, hwpack_tarfile = self.get_field(file_alias) - if file_name is not None: - hwpack_tarfile.extract(file_name, self.tempdir) - file_name = os.path.join(self.tempdir, file_name) - return file_name + """Get file(s) from a hwpack. + :param file_alias: Property name (not field name) which contains + file reference(s) + :return: path to a file or list of paths to files + """ + file_names, hwpack_tarfile = self.get_field(file_alias) + if not file_names: + return file_names + single = False + if not isinstance(args, list): + single = True + file_names = [file_names] + out_files = [] + for f in file_names: + hwpack_tarfile.extract(f, self.tempdir) + f = os.path.join(self.tempdir, f) + out_files.append(f) + if single: + return out_files[0] + return out_files class BoardConfig(object): @@ -778,8 +793,9 @@ bootloader_parts_dir = os.path.join(chroot_dir, parts_dir) cmd_runner.run(['mkdir', '-p', boot_disk]).wait() with partition_mounted(boot_partition, boot_disk): - if cls.bootloader_file_in_boot_part: - with cls.hardwarepack_handler: + boot_files = [] + with cls.hardwarepack_handler: + if cls.bootloader_file_in_boot_part: # if cls.bootloader_flavor is not None: default = os.path.join( @@ -797,8 +813,15 @@ assert bootloader_bin is not None, ( "bootloader binary could not be found") + boot_files.append(bootloader_bin) + + copy_files = cls.get_file('boot_copy_files') + if copy_files: + boot_files.extend(copy_files) + + for f in boot_files: proc = cmd_runner.run( - ['cp', '-v', bootloader_bin, boot_disk], as_root=True) + ['cp', '-v', f, boot_disk], as_root=True) proc.wait() cls.make_boot_files( === modified file 'linaro_image_tools/media_create/tests/test_media_create.py' --- linaro_image_tools/media_create/tests/test_media_create.py 2012-08-05 09:22:32 +0000 +++ linaro_image_tools/media_create/tests/test_media_create.py 2012-09-04 13:53:43 +0000 @@ -309,6 +309,37 @@ test_file = hp.get_file('bootloader_file') self.assertEquals(data, open(test_file, 'r').read()) + def test_get_file_v3(self): + # Test that get_file() works as expected with hwpackv3 and + # supports its new file fields. + metadata = textwrap.dedent("""\ + format: 3.0 + name: ahwpack + version: 4 + architecture: armel + origin: linaro + bootloaders: + u_boot: + file: a_file + copy_files: + - file1 + - file2 + uefi: + file: b_file + """) + files = {'FORMAT': '3.0\n', 'metadata': metadata, + 'a_file': 'a_file content', 'file1': 'file1 content', + 'file2': 'file2 content'} + tarball = self.add_to_tarball(files.items()) + hp = HardwarepackHandler([tarball], bootloader='u_boot') + with hp: + test_file = hp.get_file('bootloader_file') + self.assertEquals(files['a_file'], open(test_file, 'r').read()) + test_files = hp.get_file('boot_copy_files') + self.assertEquals(len(test_files), 2) + self.assertEquals(files['file1'], open(test_files[0], 'r').read()) + self.assertEquals(files['file2'], open(test_files[1], 'r').read()) + class TestSetMetadata(TestCaseWithFixtures): @@ -2907,6 +2938,21 @@ self.useFixture(MockSomethingFixture( self.config, 'make_boot_files', self.save_args)) + def prepare_config_v3(self, config): + class c(config): + pass + + self.config = c + self.config.boot_script = 'boot_script' + self.config.hardwarepack_handler = \ + TestSetMetadata.MockHardwarepackHandler('ahwpack.tar.gz') + self.config.hardwarepack_handler.get_format = lambda: '3.0' + self.config.hardwarepack_handler.get_file = \ + lambda file_alias: ['file1', 'file2'] + self.popen_fixture = self.useFixture(MockCmdRunnerPopenFixture()) + self.useFixture(MockSomethingFixture( + self.config, 'make_boot_files', self.save_args)) + def call_populate_boot(self, config, is_live=False): config.populate_boot( 'chroot_dir', 'rootfs_id', 'boot_partition', 'boot_disk', @@ -2957,6 +3003,24 @@ expected_calls, self.popen_fixture.mock.commands_executed) self.assertEquals(self.expected_args, self.saved_args) + def test_populate_boot_copy_files(self): + self.prepare_config_v3(boards.BoardConfig) + self.config.bootloader_flavor = "bootloader_flavor" + # Test that copy_files works per spec (puts stuff in boot partition) + # even if bootloader not in_boot_part. + self.config.bootloader_file_in_boot_part = False + self.call_populate_boot(self.config) + expected_calls = self.expected_calls[:] + expected_calls.insert(2, + '%s cp -v file1 ' + 'boot_disk' % sudo_args) + expected_calls.insert(3, + '%s cp -v file2 ' + 'boot_disk' % sudo_args) + self.assertEquals( + expected_calls, self.popen_fixture.mock.commands_executed) + self.assertEquals(self.expected_args, self.saved_args) + def test_populate_boot_no_bootloader_flavor(self): self.prepare_config(boards.BoardConfig) self.config.bootloader_file_in_boot_part = True