Fix /dev populating during image building

It turns out that /dev has got broken links during image building.
This leads to fail of installing tricky packages such as dkms.

Having /dev/fd -> /proc/self/fd totally resolves that issue.

Change-Id: I72865f2b2adcb431d959fa2a73b51d9abad5914b
Closes-Bug: #1485565
This commit is contained in:
Alexander Gordeev 2015-08-18 17:43:10 +03:00
parent 57145b1d88
commit 4e8b19380e
4 changed files with 21 additions and 0 deletions

View File

@ -652,6 +652,8 @@ class Manager(object):
utils.makedirs_if_not_exists(proc_path)
fu.mount_bind(chroot, '/proc')
bu.populate_basic_dev(chroot)
LOG.debug('Installing packages using apt-get: %s',
' '.join(packages))
bu.run_apt_get(chroot, packages=packages,

View File

@ -471,6 +471,16 @@ class BuildUtilsTestCase(unittest2.TestCase):
'fake_force_ipv4')]
self.assertEqual(expected_join_calls, mock_path.join.call_args_list)
@mock.patch.object(bu.utils, 'execute')
def test_populate_basic_dev(self, mock_execute):
bu.populate_basic_dev('fake_chroot')
expected_execute_calls = [
mock.call('chroot', 'fake_chroot', 'rm', '-fr', '/dev/fd'),
mock.call('chroot', 'fake_chroot', 'ln', '-s', '/proc/self/fd',
'/dev/fd'),
]
self.assertEqual(expected_execute_calls, mock_execute.call_args_list)
@mock.patch('gzip.open')
@mock.patch.object(os, 'remove')
def test_containerize_gzip(self, mock_remove, mock_gzip):

View File

@ -872,6 +872,7 @@ class TestImageBuild(unittest2.TestCase):
mock.call('tune2fs', '-O', 'has_journal', '/dev/loop0')],
mock_utils.execute.call_args_list)
mock_fu.mount_bind.assert_called_once_with('/tmp/imgdir', '/proc')
mock_bu.populate_basic_dev.assert_called_once_with('/tmp/imgdir')
mock_bu.run_apt_get.assert_called_once_with(
'/tmp/imgdir', packages=['fakepackage1', 'fakepackage2'],
attempts=CONF.fetch_packages_attempts)

View File

@ -258,6 +258,14 @@ def get_free_loop_device(loop_device_major_number=7,
raise errors.NoFreeLoopDevices('Free loop device not found')
def populate_basic_dev(chroot):
"""Populates /dev with basic files, links, device nodes."""
# prevent failures related with /dev/fd/62
utils.execute('chroot', chroot, 'rm', '-fr', '/dev/fd')
utils.execute('chroot', chroot,
'ln', '-s', '/proc/self/fd', '/dev/fd')
def create_sparse_tmp_file(dir, suffix, size=8192):
"""Creates sparse file.