=== modified file 'linaro-media-create'
@@ -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'
@@ -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'
@@ -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'
@@ -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'