From patchwork Thu Oct 20 07:01:10 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattias Backman X-Patchwork-Id: 4744 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 1960623EFA for ; Thu, 20 Oct 2011 07:01:12 +0000 (UTC) Received: from mail-ey0-f180.google.com (mail-ey0-f180.google.com [209.85.215.180]) by fiordland.canonical.com (Postfix) with ESMTP id F346EA18A13 for ; Thu, 20 Oct 2011 07:01:11 +0000 (UTC) Received: by eyg5 with SMTP id 5so3214909eyg.11 for ; Thu, 20 Oct 2011 00:01:11 -0700 (PDT) Received: by 10.223.85.139 with SMTP id o11mr16511729fal.0.1319094071637; Thu, 20 Oct 2011 00:01:11 -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.152.1.71 with SMTP id 7cs110918lak; Thu, 20 Oct 2011 00:01:11 -0700 (PDT) Received: by 10.216.156.202 with SMTP id m52mr456090wek.7.1319094070572; Thu, 20 Oct 2011 00:01:10 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com. [91.189.90.7]) by mx.google.com with ESMTPS id s49si6248817wec.91.2011.10.20.00.01.10 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 20 Oct 2011 00:01:10 -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 1RGmco-0006qg-8u for ; Thu, 20 Oct 2011 07:01:10 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 3A360F5FCE for ; Thu, 20 Oct 2011 07:01:10 +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: 450 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-image-tools/linaro-image-tools/trunk] Rev 450: Update rootfs /etc/network/interfaces with interfaces specified in the hwpack. Message-Id: <20111020070110.31412.37006.launchpad@ackee.canonical.com> Date: Thu, 20 Oct 2011 07:01:10 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="14165"; Instance="launchpad-lazr.conf" X-Launchpad-Hash: ee8d2b268c65339e6ba2c0b1b2162341ebd26f9c Merge authors: Mattias Backman (mabac) Related merge proposals: https://code.launchpad.net/~mabac/linaro-image-tools/bug-629049-interfaces/+merge/79822 proposed by: Mattias Backman (mabac) review: Approve - Ricardo Salveti (rsalveti) review: Approve - James Westby (james-w) ------------------------------------------------------------ revno: 450 [merge] committer: Mattias Backman branch nick: linaro-image-tools timestamp: Thu 2011-10-20 08:55:24 +0200 message: Update rootfs /etc/network/interfaces with interfaces specified in the hwpack. modified: linaro-media-create linaro_image_tools/media_create/boards.py linaro_image_tools/media_create/rootfs.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-media-create' --- linaro-media-create 2011-10-12 09:54:29 +0000 +++ linaro-media-create 2011-10-19 12:19:33 +0000 @@ -181,6 +181,6 @@ create_swap = True populate_rootfs(ROOTFS_DIR, ROOT_DISK, root_partition, args.rootfs, rootfs_uuid, create_swap, str(args.swap_file), - board_config.mmc_part_offset) + board_config.mmc_part_offset, board_config) print "Done creating Linaro image on %s" % args.device === modified file 'linaro_image_tools/media_create/boards.py' --- linaro_image_tools/media_create/boards.py 2011-10-06 09:15:07 +0000 +++ linaro_image_tools/media_create/boards.py 2011-10-19 12:19:33 +0000 @@ -313,9 +313,13 @@ cls.load_addr = cls.get_metadata_field('load_addr') cls.dtb_addr = cls.get_metadata_field('dtb_addr') cls.serial_tty = cls.get_metadata_field('serial_tty') - cls.wired_interfaces = cls.get_metadata_field('wired_interfaces') - cls.wireless_interfaces = cls.get_metadata_field( + wired_interfaces = cls.get_metadata_field('wired_interfaces') + if wired_interfaces is not None: + cls.wired_interfaces = wired_interfaces.split(' ') + wireless_interfaces = cls.get_metadata_field( 'wireless_interfaces') + if wireless_interfaces is not None: + cls.wireless_interfaces = wireless_interfaces.split(' ') cls.vmlinuz = cls.get_metadata_field('kernel_file') cls.initrd = cls.get_metadata_field('initrd_file') cls.dtb_file = cls.get_metadata_field('dtb_file') === modified file 'linaro_image_tools/media_create/rootfs.py' --- linaro_image_tools/media_create/rootfs.py 2011-07-25 16:48:37 +0000 +++ linaro_image_tools/media_create/rootfs.py 2011-10-19 13:59:30 +0000 @@ -43,7 +43,7 @@ def populate_rootfs(content_dir, root_disk, partition, rootfs_type, rootfs_uuid, should_create_swap, swap_size, - partition_offset): + partition_offset, board_config=None): """Populate the rootfs and make the necessary tweaks to make it usable. This consists of: @@ -89,6 +89,30 @@ print "\nCreating /etc/flash-kernel.conf\n" create_flash_kernel_config(root_disk, 1 + partition_offset) + if board_config is not None: + print "\nUpdating /etc/network/interfaces\n" + update_network_interfaces(root_disk, board_config) + + +def update_network_interfaces(root_disk, board_config): + interfaces = [] + if board_config.wired_interfaces is not None: + interfaces.extend(board_config.wired_interfaces) + if board_config.wireless_interfaces is not None: + interfaces.extend(board_config.wireless_interfaces) + + if_path = os.path.join(root_disk, 'etc', 'network', 'interfaces') + if os.path.exists(if_path): + with open(if_path) as if_file: + config = if_file.read() + else: + config = '' + for interface in interfaces: + if interface not in config: + config += "auto %(if)s\niface %(if)s inet dhcp\n" % ({ 'if': interface }) + if config != '': + write_data_to_protected_file(if_path, config) + def create_flash_kernel_config(root_disk, boot_partition_number): """Create a flash-kernel.conf file under root_disk/etc. === modified file 'linaro_image_tools/media_create/tests/test_media_create.py' --- linaro_image_tools/media_create/tests/test_media_create.py 2011-10-04 15:21:57 +0000 +++ linaro_image_tools/media_create/tests/test_media_create.py 2011-10-19 13:59:30 +0000 @@ -101,6 +101,7 @@ populate_rootfs, rootfs_mount_options, write_data_to_protected_file, + update_network_interfaces, ) from linaro_image_tools.media_create.tests.fixtures import ( CreateTarballFixture, @@ -355,7 +356,7 @@ class config(BoardConfig): pass config.set_metadata('ahwpack.tar.gz') - self.assertEquals(data_to_set, config.wired_interfaces) + self.assertEquals(data_to_set.split(' '), config.wired_interfaces) def test_sets_wireless_interfaces(self): self.useFixture(MockSomethingFixture( @@ -369,7 +370,7 @@ class config(BoardConfig): pass config.set_metadata('ahwpack.tar.gz') - self.assertEquals(data_to_set, config.wireless_interfaces) + self.assertEquals(data_to_set.split(' '), config.wireless_interfaces) def test_sets_mmc_id(self): self.useFixture(MockSomethingFixture( @@ -2389,6 +2390,59 @@ self.assertFalse( has_space_left_for_swap('/', swap_size_in_megs)) + def test_update_interfaces_no_interfaces_no_update(self): + tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir() + os.makedirs(os.path.join(tempdir, 'etc', 'network')) + if_path = os.path.join(tempdir, 'etc', 'network', 'interfaces') + class board_config(boards.BoardConfig): + pass + + update_network_interfaces(tempdir, board_config) + self.assertFalse(os.path.exists(if_path)) + + def test_update_interfaces_creates_entry(self): + tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir() + os.makedirs(os.path.join(tempdir, 'etc', 'network')) + if_path = os.path.join(tempdir, 'etc', 'network', 'interfaces') + class board_config(boards.BoardConfig): + wired_interfaces = ['eth0'] + + expected = 'auto eth0\n' \ + 'iface eth0 inet dhcp\n' + update_network_interfaces(tempdir, board_config) + self.assertEqual(expected, open(if_path).read()) + + def test_update_interfaces_creates_entries(self): + tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir() + os.makedirs(os.path.join(tempdir, 'etc', 'network')) + if_path = os.path.join(tempdir, 'etc', 'network', 'interfaces') + class board_config(boards.BoardConfig): + wired_interfaces = ['eth0', 'eth1'] + wireless_interfaces = ['wlan0'] + + expected = 'auto %(if)s\n' \ + 'iface %(if)s inet dhcp\n' + + update_network_interfaces(tempdir, board_config) + self.assertIn(expected % {'if': 'eth1'}, open(if_path).read()) + self.assertIn(expected % {'if': 'eth0'}, open(if_path).read()) + self.assertIn(expected % {'if': 'wlan0'}, open(if_path).read()) + + def test_update_interfaces_leaves_original(self): + tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir() + os.makedirs(os.path.join(tempdir, 'etc', 'network')) + if_path = os.path.join(tempdir, 'etc', 'network', 'interfaces') + with open(if_path, 'w') as interfaces: + interfaces.write('Original contents of file.\n') + class board_config(boards.BoardConfig): + wired_interfaces = ['eth0'] + + expected = 'Original contents of file.\n' \ + 'auto eth0\n' \ + 'iface eth0 inet dhcp\n' + update_network_interfaces(tempdir, board_config) + self.assertEqual(expected, open(if_path).read()) + def test_write_data_to_protected_file(self): fixture = self.useFixture(MockCmdRunnerPopenFixture()) data = 'foo'